From 353a3958e42d52862a48b5871a8acedcbf04eaf6 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 13 Oct 2023 13:31:51 -0700 Subject: Filter overstrikes to Vim help convention. This allows us to just :set syntax help, and all the highlighted items are searchable. --- mnpgr.tl | 38 ++++++++++++++++++++++++++++---------- 1 file 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`))) -- cgit v1.2.3