From a41eea11d25178a1802cad07d6ec25bf36ae1744 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Thu, 12 May 2022 12:00:11 +0200 Subject: [PATCH] fix(syntax coloring): load all lexers, even those without aliases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some Pygments’ lexers are registered without any alias, just with their long name. This ensure that they are loaded, along with the others. --- colout/colout.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/colout/colout.py b/colout/colout.py index 39e8a0f..8c64d68 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -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")