diff options
author | ilezhankin <ilezhankin@yandex-team.ru> | 2022-02-10 16:45:56 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:56 +0300 |
commit | 62a805381e41500fbc7914c37c71ab040a098f4e (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /contrib/python/Pygments/py2/pygments/modeline.py | |
parent | 1d125034f06575234f83f24f08677955133f140e (diff) | |
download | ydb-62a805381e41500fbc7914c37c71ab040a098f4e.tar.gz |
Restoring authorship annotation for <ilezhankin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/Pygments/py2/pygments/modeline.py')
-rw-r--r-- | contrib/python/Pygments/py2/pygments/modeline.py | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/contrib/python/Pygments/py2/pygments/modeline.py b/contrib/python/Pygments/py2/pygments/modeline.py index ec3b9e7a5f..31b2e7fb0d 100644 --- a/contrib/python/Pygments/py2/pygments/modeline.py +++ b/contrib/python/Pygments/py2/pygments/modeline.py @@ -1,44 +1,44 @@ -# -*- coding: utf-8 -*- -""" - pygments.modeline - ~~~~~~~~~~~~~~~~~ - - A simple modeline parser (based on pymodeline). - +# -*- coding: utf-8 -*- +""" + pygments.modeline + ~~~~~~~~~~~~~~~~~ + + A simple modeline parser (based on pymodeline). + :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. - :license: BSD, see LICENSE for details. -""" - -import re - -__all__ = ['get_filetype_from_buffer'] - - -modeline_re = re.compile(r''' - (?: vi | vim | ex ) (?: [<=>]? \d* )? : - .* (?: ft | filetype | syn | syntax ) = ( [^:\s]+ ) -''', re.VERBOSE) - - -def get_filetype_from_line(l): - m = modeline_re.search(l) - if m: - return m.group(1) - - -def get_filetype_from_buffer(buf, max_lines=5): - """ - Scan the buffer for modelines and return filetype if one is found. - """ - lines = buf.splitlines() - for l in lines[-1:-max_lines-1:-1]: - ret = get_filetype_from_line(l) - if ret: - return ret + :license: BSD, see LICENSE for details. +""" + +import re + +__all__ = ['get_filetype_from_buffer'] + + +modeline_re = re.compile(r''' + (?: vi | vim | ex ) (?: [<=>]? \d* )? : + .* (?: ft | filetype | syn | syntax ) = ( [^:\s]+ ) +''', re.VERBOSE) + + +def get_filetype_from_line(l): + m = modeline_re.search(l) + if m: + return m.group(1) + + +def get_filetype_from_buffer(buf, max_lines=5): + """ + Scan the buffer for modelines and return filetype if one is found. + """ + lines = buf.splitlines() + for l in lines[-1:-max_lines-1:-1]: + ret = get_filetype_from_line(l) + if ret: + return ret for i in range(max_lines, -1, -1): if i < len(lines): ret = get_filetype_from_line(lines[i]) if ret: return ret - - return None + + return None |