[vim] docstrings and readme generator

This commit is contained in:
2023-02-13 18:12:23 +03:00
parent 3633c5bf6a
commit d66e7899d4
3 changed files with 79 additions and 19 deletions

45
vim/readme.py Normal file
View File

@@ -0,0 +1,45 @@
import re
config = [line.strip() for line in open("coc.vim", "r").readlines()]
def string_to_reject(string):
result = False
if string in ["\""]:
result = True
return result
def string_to_accept(string):
result = False
accepted_keywords = ["nnoremap", "nmap", "noremap", "\""]
result = any(subs in string for subs in accepted_keywords)
return result
def header(string):
string = re.sub(r"^\" \[docs\]", "###", string)
return f"\n{string}\n"
doc_block_started = False
doc_lines = []
for line in config:
if "[docs]" in line:
doc_block_started = True
doc_lines.append(header(line))
continue
elif line == "":
doc_block_started = False
continue
if doc_block_started and string_to_accept(line) and not string_to_reject(line):
if not line.startswith("\"") and not line.startswith("#"):
line = f" {line}"
else:
line = re.sub(r"^\"\s*", "", line)
line = f"{line}\n"
doc_lines.append(line)
print("\n".join(doc_lines))