summaryrefslogtreecommitdiff
path: root/scripts/get_vimkw.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/get_vimkw.py')
-rw-r--r--scripts/get_vimkw.py43
1 files changed, 37 insertions, 6 deletions
diff --git a/scripts/get_vimkw.py b/scripts/get_vimkw.py
index 153c88c3..fc4d5ec6 100644
--- a/scripts/get_vimkw.py
+++ b/scripts/get_vimkw.py
@@ -1,13 +1,42 @@
+from __future__ import print_function
+
import re
-from pprint import pprint
+
+from pygments.util import format_lines
r_line = re.compile(r"^(syn keyword vimCommand contained|syn keyword vimOption "
r"contained|syn keyword vimAutoEvent contained)\s+(.*)")
r_item = re.compile(r"(\w+)(?:\[(\w+)\])?")
+HEADER = '''\
+# -*- coding: utf-8 -*-
+"""
+ pygments.lexers._vim_builtins
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ This file is autogenerated by scripts/get_vimkw.py
+
+ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+# Split up in multiple functions so it's importable by jython, which has a
+# per-method size limit.
+'''
+
+METHOD = '''\
+def _get%(key)s():
+%(body)s
+ return var
+%(key)s = _get%(key)s()
+'''
+
def getkw(input, output):
out = file(output, 'w')
+ # Copy template from an existing file.
+ print(HEADER, file=out)
+
output_info = {'command': [], 'option': [], 'auto': []}
for line in file(input):
m = r_line.match(line)
@@ -29,15 +58,17 @@ def getkw(input, output):
output_info['option'].append("('inoremap','inoremap')")
output_info['option'].append("('vnoremap','vnoremap')")
- for a, b in output_info.items():
- b.sort()
- print >>out, '%s=[%s]' % (a, ','.join(b))
+ for key, keywordlist in output_info.items():
+ keywordlist.sort()
+ body = format_lines('var', keywordlist, raw=True, indent_level=1)
+ print(METHOD % locals(), file=out)
def is_keyword(w, keywords):
for i in range(len(w), 0, -1):
if w[:i] in keywords:
- return signals[w[:i]][:len(w)] == w
+ return keywords[w[:i]][:len(w)] == w
return False
if __name__ == "__main__":
- getkw("/usr/share/vim/vim73/syntax/vim.vim", "temp.py")
+ getkw("/usr/share/vim/vim74/syntax/vim.vim",
+ "pygments/lexers/_vim_builtins.py")