453 elif text: |
453 elif text: |
454 # step 1: guess based on filename and text |
454 # step 1: guess based on filename and text |
455 if self.editor is not None: |
455 if self.editor is not None: |
456 fn = self.editor.getFileName() |
456 fn = self.editor.getFileName() |
457 if fn: |
457 if fn: |
458 with contextlib.suppress(ClassNotFound): |
458 with contextlib.suppress(ClassNotFound, AttributeError): |
459 lexer = guess_lexer_for_filename(fn, text) |
459 lexer = guess_lexer_for_filename(fn, text) |
460 |
460 |
461 # step 2: guess on text only |
461 # step 2: guess on text only |
462 if lexer is None: |
462 if lexer is None: |
463 with contextlib.suppress(ClassNotFound): |
463 with contextlib.suppress(ClassNotFound, AttributeError): |
464 lexer = guess_lexer(text) |
464 lexer = guess_lexer(text) |
465 |
465 |
466 return lexer |
466 return lexer |
467 |
467 |
468 def canStyle(self): |
468 def canStyle(self): |