forked from OriolAbril/MESAstro-vim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvim-list.py
71 lines (62 loc) · 2.24 KB
/
vim-list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import re,os
keypat=re.compile(r'\s*!?([^!\s#-]+)',re.IGNORECASE)
elempat=re.compile(r'\s*([0-9]{1,3})([a-z]{1,2})',re.IGNORECASE)
folder=os.environ['MESA_DIR']
keys=set()
els=set()
fd=open('list.vim','w')
# Write start of .vim file
fd.write('if exists("b:current_syntax")\n finish\nendif\n\n"Known elements\nsyntax case ignore\n')
# get and write all known elements
f1=open('all_known_elements.txt','r')
for line in f1:
raw_els=line.split(',')
writeln='syntax keyword listElement'
pint=False
for el in raw_els:
m=elempat.match(el)
if m:
pint=True
nice_el=m.groups(1)[1].lower()+m.groups(1)[0]
els.add(nice_el)
writeln+=' '+nice_el
if pint:
fd.write(writeln+'\n')
f1.close()
## get keywords for histroy files
f1=open(folder+'/star/defaults/history_columns.list','r')
for line in f1:
m=keypat.match(line)
if m:
key=m.groups(1)[0]
if (key!='mixing_regions' and key!='mix_relr_regions' and key!='burning_regions' and
key not in els):
keys.add(key)
f1.close()
## get keywords for profile files
f1=open(folder+'/star/defaults/profile_columns.list','r')
for line in f1:
m=keypat.match(line)
if m:
key=m.groups(1)[0]
if (key!='mixing_regions' and key!='mix_relr_regions' and key!='burning_regions' and
key not in els):
keys.add(key)
f1.close()
# write keywords in list.vim
fd.write('\n"Keywords\nsyntax case ignore\n')
for key in keys:
string='syntax keyword listKeyword '+key+'\n'
fd.write(string)
#Add special keywords, comments and integers
fd.write('syntax match listKeyword /\zsmixing_regions\ze\s\+[0-9]\+/\n')
fd.write('syntax match listKeyword /\zsmix_relr_regions\ze\s\+[0-9]\+/\n')
fd.write('syntax match listKeyword /\zsburning_regions\ze\s\+[0-9]\+/\n')
fd.write('\n"Comments\nsyntax match listComment "'+r'\v'+'!.*$"\n')
fd.write('\n"Integers\nsyntax match listNumber /\s\+[0-9]\+/\n')
fd.write('\n"Set higlight type to the defined keywords\nhighlight link listElement Special\n')
fd.write('highlight link listKeyword Keyword\n')
fd.write('highlight link listComment Comment\n')
fd.write('highlight link listNumber Number\n')
fd.write('let b:current_syntax = "list"')
fd.close()