diff options
author | Georg Brandl <georg@python.org> | 2015-08-08 07:10:22 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2015-08-08 07:10:22 +0200 |
commit | 02929b2728c4d21d1c7f0748e987efef7bc567ab (patch) | |
tree | c588fe293f2bb2719c74d9c659a67cf026103e15 | |
parent | 97a868c27c5e365dee3e830cd9dc0ca010cbab80 (diff) | |
download | pygments-02929b2728c4d21d1c7f0748e987efef7bc567ab.tar.gz |
fix modeline parsing (PR#477 fixed)
-rw-r--r-- | pygments/modeline.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/pygments/modeline.py b/pygments/modeline.py index 54df90c4..2200f1cf 100644 --- a/pygments/modeline.py +++ b/pygments/modeline.py @@ -13,16 +13,19 @@ 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. @@ -32,7 +35,7 @@ def get_filetype_from_buffer(buf, max_lines=5): ret = get_filetype_from_line(l) if ret: return ret - for l in lines[max_lines:0:-1]: + for l in lines[max_lines:-1:-1]: ret = get_filetype_from_line(l) if ret: return ret |