-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvar-table.py
executable file
·72 lines (60 loc) · 2.02 KB
/
var-table.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
72
#!/usr/bin/env python3
import os
import sys
this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
var_list = []
pkg_specific_list = []
def main():
with open(os.path.join(this_dir, "init.el"), "r") as f:
init_lines = f.readlines()
for line in init_lines:
if "EMACS_NO_" in line:
varname = line.split('"')[1]
filename = line.split('"')[3]
var_list.append({"var": varname, "file": filename})
for var_dict in var_list:
el_file = os.path.join(this_dir, "lib", var_dict["file"] + ".el")
pkg_list = []
try:
with open(el_file, "r") as f:
lines = f.readlines()
except FileNotFoundError:
break
var_dict.update({"comment": lines[0].split("---")[-1].strip().rstrip()})
for line in lines:
if "EMACS_NO_" in line:
pkg_specific_list.append(
{
"var": line.split('"')[1],
"file": el_file,
"comment": line.split(" ;; ")[-1].rstrip().strip(),
}
)
if "(use-package " in line:
pkg_list.append(
line.split("(use-package ")[1]
.split(" ")[0]
.strip()
.rstrip()
.rstrip(")")
)
var_dict.update({"packages": pkg_list})
for v in var_list:
if "packages" in v.keys():
print(
"`{var}` | Packages: {desc}".format(
var=v["var"], desc=", ".join(v["packages"])
)
)
else:
try:
print("`{var}` | {desc}".format(var=v["var"], desc=v["comment"]))
except KeyError:
pass
for v in pkg_specific_list:
try:
print("`{var}` | {desc}".format(var=v["var"], desc=v["comment"]))
except KeyError:
pass
if __name__ == "__main__":
main()