filtering lexer guesses by filename

This commit is contained in:
Alan Hamlett 2013-09-22 16:28:09 -07:00
parent 1cf6a34ed5
commit 8de2be936b

View file

@ -17,7 +17,7 @@ if sys.version_info[0] == 2:
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'packages', 'pygments2')) sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'packages', 'pygments2'))
else: else:
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'packages', 'pygments3')) sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'packages', 'pygments3'))
from pygments.lexers import guess_lexer from pygments.lexers import guess_lexer_for_filename
from pygments.util import ClassNotFound from pygments.util import ClassNotFound
@ -28,7 +28,7 @@ def guess_language(file_name):
lexer = None lexer = None
try: try:
with open(file_name) as f: with open(file_name) as f:
lexer = guess_lexer(f.read(512000)) lexer = guess_lexer_for_filename(file_name, f.read(512000))
except (ClassNotFound, IOError): except (ClassNotFound, IOError):
pass pass
if lexer: if lexer: