aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-10-13 13:31:51 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-10-13 13:31:51 -0700
commit353a3958e42d52862a48b5871a8acedcbf04eaf6 (patch)
tree09c9792fbbee0373b49c1fa448afe2885f480248
parent74f1b72891965cd4803e0d372c72d1a56ecb8de8 (diff)
downloadmnpgr-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-xmnpgr.tl38
1 files changed, 28 insertions, 10 deletions
diff --git a/mnpgr.tl b/mnpgr.tl
index af3541b..72a87b0 100755
--- a/mnpgr.tl
+++ b/mnpgr.tl
@@ -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`)))