move language priorities into separate file

This commit is contained in:
Alan Hamlett 2017-03-04 13:11:40 -08:00
parent 723dd42fa9
commit 0f02aa91b7
2 changed files with 21 additions and 8 deletions

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
"""
wakatime.language_priorities
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Overwrite pygments Lexer.priority attribute for specific languages.
:copyright: (c) 2017 Alan Hamlett.
:license: BSD, see LICENSE for more details.
"""
LANGUAGES = {
'typescript': 0.11,
'perl': 0.1,
'perl6': 0.1,
'f#': 0.1,
}

View file

@ -16,6 +16,7 @@ import sys
from .compat import u, open
from .dependencies import DependencyParser
from .language_priorities import LANGUAGES
from .packages.pygments.lexers import (
_iter_lexerclasses,
@ -307,15 +308,9 @@ def custom_pygments_guess_lexer_for_filename(_fn, _text, **options):
return result[-1][1](**options)
CUSTOM_PRIORITIES = {
'typescript': 0.11,
'perl': 0.1,
'perl6': 0.1,
'f#': 0.1,
}
def customize_priority(lexer):
"""Return an integer priority for the given lexer object."""
if lexer.name.lower() in CUSTOM_PRIORITIES:
lexer.priority = CUSTOM_PRIORITIES[lexer.name.lower()]
if lexer.name.lower() in LANGUAGES:
lexer.priority = LANGUAGES[lexer.name.lower()]
return lexer