Skip to content

Commit

Permalink
fix(syntax coloring): load all lexers, even those without aliases
Browse files Browse the repository at this point in the history
Some Pygments’ lexers are registered without any alias, just with their long name.
This ensure that they are loaded, along with the others.
  • Loading branch information
jdreo committed May 12, 2022
1 parent 438838d commit a41eea1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions colout/colout.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,21 @@ def load_lexers():
from pygments.lexers import get_all_lexers
try:
for lexer in get_all_lexers():
try:
lexers.append(lexer[1][0])
except IndexError:
l = None
# If the tuple has one-word aliases
# (which are usually a better option than the long names
# for a command line argument).
if lexer[1]:
l = lexer[1][0] # Take the first one.
else:
assert(lexer[0])
l = lexer[0] # Take the long name, which should alway exists.
if not l:
logging.warning("cannot load lexer: %s" % lexer[1][0])
pass
pass # Forget about this lexer.
else:
assert(" " not in l) # Should be very rare, but probably a source of bugs.
lexers.append(l)
except:
logging.warning("error while executing the pygment module, syntax coloring is not available")

Expand Down

0 comments on commit a41eea1

Please sign in to comment.