From 4cee01cc6298add2ab39508c58c76ac4d90486bd Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 13 Jun 2022 01:03:41 +0530 Subject: Carry through non-first-part-p on command translations. * thogai.el (thogai-insert-translation): Rename argument subtranslation to non-first-part-p and carry it through when command translations are processed. --- thogai.el | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/thogai.el b/thogai.el index 195c914..faca653 100644 --- a/thogai.el +++ b/thogai.el @@ -216,12 +216,14 @@ Insert LITERAL-TRANSLATION at point, respecting (setq thogai-attach-next nil thogai-glue nil)) -(defun thogai-insert-translation (translation &optional subtranslation) +(defun thogai-insert-translation (translation &optional non-first-part-p) "Insert TRANSLATION at point. -TRANSLATION is a string mapped to in a steno dictionary. If -SUBTRANSLATION is non-nil, this is a recursive call. External -callers should never pass non-nil SUBTRANSLATION." +TRANSLATION is a string mapped to in a steno dictionary. + +If NON-FIRST-PART-P is non-nil, no literal parts of TRANSLATION +have been processed yet. This is an internal recursion variable. +External callers should always pass nil as the value." (pcase (save-match-data (string-match (rx string-start (or (one-or-more (not ?{)) (sequence ?{ (one-or-more (not ?{)) ?}))) @@ -243,7 +245,7 @@ callers should never pass non-nil SUBTRANSLATION." ;; Prefix ((pred (lambda (str) (string-suffix-p "^}" str))) - (unless subtranslation + (unless non-first-part-p (thogai-insert-space)) (thogai-insert-literal (string-remove-prefix "{" (string-remove-suffix "^}" translation))) @@ -252,7 +254,7 @@ callers should never pass non-nil SUBTRANSLATION." ((pred (lambda (str) (and (string-prefix-p "{&" str) (string-suffix-p "}" str)))) - (unless (or subtranslation thogai-glue) + (unless (or non-first-part-p thogai-glue) (thogai-insert-space)) (thogai-insert-literal (string-remove-prefix "{&" (string-remove-suffix "}" translation))) @@ -280,12 +282,18 @@ callers should never pass non-nil SUBTRANSLATION." (delete-char -1))) ;; Simple literal translation (_ - (unless subtranslation + (unless non-first-part-p (thogai-insert-space)) (thogai-insert-literal translation))) ;; Recurse for rest of translation. (unless (string= rest-of-translation "") - (thogai-insert-translation rest-of-translation t))))) + (thogai-insert-translation + rest-of-translation + ;; Carry through non-first-part-p on pure command translation + ;; parts that do not insert anything. + (if (member translation (list "{^}" "{-|}" "{*-|}" "{>}" "{*>}" "{*!}")) + non-first-part-p + t)))))) (defun thogai-reverse-strokes (strokes) "Reverse the effects of STROKES. -- cgit v1.2.3