summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorTim Hatch <tim@timhatch.com>2014-10-03 23:10:07 -0700
committerTim Hatch <tim@timhatch.com>2014-10-03 23:10:07 -0700
commitbe3f4a6110e1dbd460980d866f0b31a4e7ece597 (patch)
treee62d1b1dd5bfc542c2f0fa8c87c2fbc3c523b432 /scripts
parent71b90a50f9f95ece57eba099acc0138add1085ae (diff)
downloadpygments-be3f4a6110e1dbd460980d866f0b31a4e7ece597.tar.gz
New version of the vim keyword script, using format_lines
Diffstat (limited to 'scripts')
-rw-r--r--scripts/get_vimkw.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/scripts/get_vimkw.py b/scripts/get_vimkw.py
index 4ea302f4..7bf2f1c5 100644
--- a/scripts/get_vimkw.py
+++ b/scripts/get_vimkw.py
@@ -1,13 +1,33 @@
from __future__ import print_function
+
import re
+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 = '''\
+# This file is autogenerated by scripts/get_vimkw.py
+
+# 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,9 +49,10 @@ 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('%s=[%s]' % (a, ','.join(b)), file=out)
+ 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):
@@ -40,4 +61,5 @@ def is_keyword(w, keywords):
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/_vimbuiltins.py")