move language priorities into separate file
This commit is contained in:
parent
723dd42fa9
commit
0f02aa91b7
2 changed files with 21 additions and 8 deletions
18
wakatime/language_priorities.py
Normal file
18
wakatime/language_priorities.py
Normal 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,
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ import sys
|
||||||
|
|
||||||
from .compat import u, open
|
from .compat import u, open
|
||||||
from .dependencies import DependencyParser
|
from .dependencies import DependencyParser
|
||||||
|
from .language_priorities import LANGUAGES
|
||||||
|
|
||||||
from .packages.pygments.lexers import (
|
from .packages.pygments.lexers import (
|
||||||
_iter_lexerclasses,
|
_iter_lexerclasses,
|
||||||
|
@ -307,15 +308,9 @@ def custom_pygments_guess_lexer_for_filename(_fn, _text, **options):
|
||||||
return result[-1][1](**options)
|
return result[-1][1](**options)
|
||||||
|
|
||||||
|
|
||||||
CUSTOM_PRIORITIES = {
|
|
||||||
'typescript': 0.11,
|
|
||||||
'perl': 0.1,
|
|
||||||
'perl6': 0.1,
|
|
||||||
'f#': 0.1,
|
|
||||||
}
|
|
||||||
def customize_priority(lexer):
|
def customize_priority(lexer):
|
||||||
"""Return an integer priority for the given lexer object."""
|
"""Return an integer priority for the given lexer object."""
|
||||||
|
|
||||||
if lexer.name.lower() in CUSTOM_PRIORITIES:
|
if lexer.name.lower() in LANGUAGES:
|
||||||
lexer.priority = CUSTOM_PRIORITIES[lexer.name.lower()]
|
lexer.priority = LANGUAGES[lexer.name.lower()]
|
||||||
return lexer
|
return lexer
|
||||||
|
|
Loading…
Reference in a new issue