Changeset - d10caf435170
[Not reviewed]
default
0 1 0
Mads Kiilerich - 6 years ago 2019-11-23 21:42:11
mads@kiilerich.com
Grafted from: 6edefe941a0c
pygmentsutils: simplify get_index_filenames
1 file changed with 3 insertions and 8 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/pygmentsutils.py
Show inline comments
 
@@ -17,25 +17,24 @@ kallithea.lib.pygmentsutils
 

	
 
Functions for extracting internal Pygments data.
 

	
 
This file was forked by the Kallithea project in July 2014.
 
Original author and date, and relevant copyright and licensing information is below:
 
:created_on: Jan 5, 2011
 
:author: marcink
 
:copyright: (c) 2013 RhodeCode GmbH, and others.
 
:license: GPLv3, see LICENSE.md for more details.
 
"""
 

	
 
from collections import defaultdict
 
from itertools import ifilter
 

	
 
from pygments import lexers
 

	
 

	
 
def get_extension_descriptions():
 
    """
 
    Based on what's inside pygments lexers, return a mapping from lowercase
 
    extensions to lists of very brief descriptions.
 
    """
 
    ext_descs = defaultdict(list)
 

	
 
    for lx, t in sorted(lexers.LEXERS.items()):
 
@@ -50,33 +49,29 @@ def get_extension_descriptions():
 
                    ext_descs[prefix + char].append(desc)
 
            else:
 
                # use stripped glob as extension
 
                ext_descs[s].append(desc)
 

	
 
    return dict(ext_descs)
 

	
 

	
 
def get_index_filenames():
 
    """
 
    Get list of known indexable filenames from pygment lexer internals
 
    """
 

	
 
    filenames = []
 

	
 
    def likely_filename(s):
 
        return s.find('*') == -1 and s.find('[') == -1
 

	
 
    for lx, t in sorted(lexers.LEXERS.items()):
 
        for f in ifilter(likely_filename, t[-2]):
 
            filenames.append(f)
 
        for f in t[-2]:
 
            if '*' not in f and '[' not in f:
 
                filenames.append(f)
 

	
 
    return filenames
 

	
 

	
 
def get_custom_lexer(extension):
 
    """
 
    returns a custom lexer if it's defined in rcextensions module, or None
 
    if there's no custom lexer defined
 
    """
 
    import kallithea
 
    lexer_name = getattr(kallithea.EXTENSIONS, 'EXTRA_LEXERS', {}).get(extension)
 
    if lexer_name is None:
0 comments (0 inline, 0 general)