diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-10-13 13:31:51 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-10-13 13:31:51 -0700 |
commit | 353a3958e42d52862a48b5871a8acedcbf04eaf6 (patch) | |
tree | 09c9792fbbee0373b49c1fa448afe2885f480248 | |
parent | 74f1b72891965cd4803e0d372c72d1a56ecb8de8 (diff) | |
download | mnpgr-353a3958e42d52862a48b5871a8acedcbf04eaf6.tar.gz mnpgr-353a3958e42d52862a48b5871a8acedcbf04eaf6.tar.bz2 mnpgr-353a3958e42d52862a48b5871a8acedcbf04eaf6.zip |
Filter overstrikes to Vim help convention.
This allows us to just :set syntax help, and all the
highlighted items are searchable.
-rwxr-xr-x | mnpgr.tl | 38 |
1 files changed, 28 insertions, 10 deletions
@@ -5,14 +5,31 @@ (defvarl mnpgr-dir (path-cat home-dir ".mnpgr-dir")) (defvarl vim-commands - (join-with "|" - '("hi def link CtrlHUnderline Special" - "hi def link CtrlHBold Keyword" - "set syntax=ctrlh" - "syntax match CtrlHHide /.\\b/ contained conceal" - "set conceallevel=2" - "set concealcursor=nc" - "map q :q!\r"))) + (join-with "|" '("set syntax=help" + "map q :q!\r"))) + +(defun make-overstrike-filter (put-string-fn) + (let ((cur-mode :norm) + (closer "")) + (flet ((output-text (str mode) + (when (neq mode cur-mode) + [put-string-fn closer] + (caseq (set cur-mode mode) + (:bold [put-string-fn "*"] + (set closer "*")) + (:ital [put-string-fn "|"] + (set closer "|")) + (:norm (set closer "")))) + [put-string-fn str])) + (lambda (line) + (each ((tok (tok #/.\b./ t line))) + (match-case tok + ("") + (`@{x #/ +/}` (output-text x :norm)) + (`@x\b@x` (output-text x :bold)) + (`_\b@x` (output-text x :ital)) + (@else (output-text else :norm)))) + (output-text "\n" :norm))))) (ensure-dir mnpgr-dir) @@ -22,6 +39,7 @@ (with-resources ((rendered-file (path-cat mnpgr-dir `@page.@section`) (remove-path rendered-file))) (with-stream (s (open-file rendered-file "w")) - (whilet ((line (get-line))) - (put-line line s))) + (let ((ofilt (make-overstrike-filter (lambda (str) (put-string str s))))) + (whilet ((line (get-line))) + [ofilt line]))) (sh `vim +'@{vim-commands}' '@{rendered-file}' < /dev/tty`))) |