From 9c833e0e420e64cbb2292958bca5913300528cc0 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sun, 12 Jun 2022 22:57:33 +0530 Subject: Implement glue operator. * thogai.el (thogai-glue): New variable. (thogai-insert-translation): Implement glue operator. --- thogai.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/thogai.el b/thogai.el index 6a0dbc6..73fd118 100644 --- a/thogai.el +++ b/thogai.el @@ -91,6 +91,14 @@ to.") If non-nil, the next part of the translation is attached without a space, and the variable is reset to nil.") +(defvar thogai-glue + nil + "Flag indicating whether to glue the next translation. + +If non-nil and the next part of the translation also starts with +a glue operator, it is attached without a space, and the variable +is reset to nil.") + (defvar thogai-capitalize-next-word nil "Flag indicating whether to capitalize the next word. @@ -204,6 +212,14 @@ callers should never pass non-nil SUBTRANSLATION." (string-suffix-p "^}" str))) (insert (string-remove-prefix "{" (string-remove-suffix "^}" translation))) (setq thogai-attach-next t)) + ;; Glue operator + ((pred (lambda (str) + (and (string-prefix-p "{&" str) + (string-suffix-p "}" str)))) + (unless thogai-glue + (thogai-insert-space)) + (insert (string-remove-prefix "{&" (string-remove-suffix "}" translation))) + (setq thogai-glue t)) ;; Capitalize next word. ("{-|}" (setq thogai-capitalize-next-word t)) @@ -229,6 +245,9 @@ callers should never pass non-nil SUBTRANSLATION." (_ (unless subtranslation (thogai-insert-space)) + ;; Reset `thogai-attach-next' and `thogai-glue'. + (setq thogai-attach-next nil + thogai-glue nil) (insert (funcall (thogai-compose ;; Capitalize first letter. (if thogai-capitalize-next-word -- cgit v1.2.3