aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/generate.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/generate.py')
-rwxr-xr-xscripts/generate.py45
1 files changed, 42 insertions, 3 deletions
diff --git a/scripts/generate.py b/scripts/generate.py
index f317534..e8b0dad 100755
--- a/scripts/generate.py
+++ b/scripts/generate.py
@@ -5,9 +5,18 @@ from dataclasses import dataclass
from functools import lru_cache
from typing import Dict, List
-from nvim_doc_tools import (Vimdoc, VimdocSection, generate_md_toc, indent,
- parse_functions, read_nvim_json, render_md_api,
- render_vimdoc_api, replace_section, wrap)
+from nvim_doc_tools import (
+ Vimdoc,
+ VimdocSection,
+ generate_md_toc,
+ indent,
+ parse_functions,
+ read_nvim_json,
+ render_md_api,
+ render_vimdoc_api,
+ replace_section,
+ wrap,
+)
HERE = os.path.dirname(__file__)
ROOT = os.path.abspath(os.path.join(HERE, os.path.pardir))
@@ -15,6 +24,7 @@ README = os.path.join(ROOT, "README.md")
DOC = os.path.join(ROOT, "doc")
VIMDOC = os.path.join(DOC, "conform.txt")
OPTIONS = os.path.join(ROOT, "tests", "options_doc.lua")
+AUTOFORMAT = os.path.join(ROOT, "tests", "autoformat_doc.lua")
@dataclass
@@ -66,6 +76,19 @@ def update_options():
)
+def update_autocmd_md():
+ example_lines = ["\n", "```lua\n"]
+ with open(AUTOFORMAT, "r", encoding="utf-8") as f:
+ example_lines.extend(f.readlines())
+ example_lines.extend(["```\n", "\n"])
+ replace_section(
+ README,
+ r"^<!-- AUTOFORMAT -->$",
+ r"^<!-- /AUTOFORMAT -->$",
+ example_lines,
+ )
+
+
def add_md_link_path(path: str, lines: List[str]) -> List[str]:
ret = []
for line in lines:
@@ -102,6 +125,20 @@ def gen_options_vimdoc() -> VimdocSection:
return section
+def gen_autocmd_vimdoc() -> VimdocSection:
+ section = VimdocSection("Autoformat", "conform-autoformat", ["\n"])
+ section.body.extend(
+ wrap(
+ "If you want more complex logic than the `format_on_save` option allows, you can write it yourself using your own autocmd. For example:"
+ )
+ )
+ section.body.append(">lua\n")
+ with open(AUTOFORMAT, "r", encoding="utf-8") as f:
+ section.body.extend(indent(f.readlines(), 4))
+ section.body.append("<\n")
+ return section
+
+
def gen_formatter_vimdoc() -> VimdocSection:
section = VimdocSection("Formatters", "conform-formatters", ["\n"])
for formatter in get_all_formatters():
@@ -118,6 +155,7 @@ def generate_vimdoc():
gen_options_vimdoc(),
VimdocSection("API", "conform-api", render_vimdoc_api("conform", funcs)),
gen_formatter_vimdoc(),
+ gen_autocmd_vimdoc(),
]
)
@@ -129,6 +167,7 @@ def main() -> None:
"""Update the README"""
update_formatter_list()
update_options()
+ update_autocmd_md()
update_md_api()
update_readme_toc()
generate_vimdoc()