prompt-toolkit / pyvim

Pure Python Vim clone.
BSD 3-Clause "New" or "Revised" License
2.52k stars 161 forks source link

if i just omit the suffix of python file, the editor won't recognize the file correctly #74

Open smileboywtu opened 8 years ago

smileboywtu commented 8 years ago

when edit the source file, like example.py it work well, but when i rename the name to example with no suffix but the grammar is python, the editor with no highlight color. atom and vim plugin works well.

smileboywtu commented 8 years ago

it seems the editor use the lexer to decide the file type:

        return BufferControl(lexer=DocumentLexer(editor_buffer),
                             input_processors=input_processors,
                             highlighters=highlighters,
                             buffer_name=buffer_name,
                             preview_search=preview_search,
                             wrap_lines=wrap_lines,
                             focus_on_click=True)

lexer.py


    def get_tokens(self, cli, text):
        """
        Call the lexer and return the tokens.
        """
        location = self.editor_buffer.location

        if location:
            # Create an instance of the correct lexer class.
            try:
                lexer = get_lexer_for_filename(location, stripnl=False, stripall=False, ensurenl=False)
            except ClassNotFound:
                pass
            else:
                return lexer.get_tokens(text)

        return [(Token, text)]

how to change the lexer dynamically with key binding? anyone who can help me ?