diff --git a/examples/config/pyvimrc b/examples/config/pyvimrc index 6de61de..9302589 100644 --- a/examples/config/pyvimrc +++ b/examples/config/pyvimrc @@ -53,7 +53,7 @@ def configure(editor): editor_buffer = editor.current_editor_buffer if editor_buffer is not None: - if editor_buffer.filename is None: + if editor_buffer.get_display_name() is None: editor.show_message("File doesn't have a filename. Please save first.") return else: @@ -63,7 +63,7 @@ def configure(editor): # `CommandLineInterface.run_in_terminal` to go to the background and # not destroy the window layout. def execute(): - call(['python', editor_buffer.filename]) + call(['python', editor_buffer.get_display_name()]) six.moves.input('Press enter to continue...') editor.cli.run_in_terminal(execute) diff --git a/pyvim/lexer.py b/pyvim/lexer.py index 9454b40..b2e8f55 100644 --- a/pyvim/lexer.py +++ b/pyvim/lexer.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from prompt_toolkit.layout.lexers import Lexer +from pygments.lexers import get_lexer_for_mimetype from pygments.lexers import get_lexer_for_filename from pygments.token import Token from pygments.util import ClassNotFound @@ -28,7 +29,14 @@ def get_tokens(self, cli, text): try: lexer = get_lexer_for_filename(location, stripnl=False, stripall=False, ensurenl=False) except ClassNotFound: - pass + try: + import magic + mimetype = magic.from_file(location, mime=True) + lexer = get_lexer_for_mimetype(mimetype) + except ClassNotFound: + pass + else: + return lexer.get_tokens(text) else: return lexer.get_tokens(text)