aboutsummaryrefslogtreecommitdiff
path: root/thogai.el
diff options
context:
space:
mode:
Diffstat (limited to 'thogai.el')
-rw-r--r--thogai.el24
1 files 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.