From a35b72046d2c6f3f3e83bd995d2c1769d44d2f4c Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sun, 12 Jun 2022 22:56:08 +0530 Subject: Abstract out insertion of space into a separate function. * thogai.el (thogai-insert-translation): Abstract out space insertion logic into ... (thogai-insert-space): ... new function. --- thogai.el | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/thogai.el b/thogai.el index 7933ed1..6a0dbc6 100644 --- a/thogai.el +++ b/thogai.el @@ -172,6 +172,16 @@ The last function in FUNCTIONS is applied first." functions arg))) +(defun thogai-insert-space () + "Insert space at point if necessary. + +Insert space at point unless at the beginning of a line or +`thogai-attach-next' is non-nil." + (unless (or (= (line-beginning-position) + (point)) + thogai-attach-next) + (insert " "))) + (defun thogai-insert-translation (translation &optional subtranslation) "Insert TRANSLATION at point. @@ -217,14 +227,8 @@ callers should never pass non-nil SUBTRANSLATION." (delete-char -1))) ;; Simple literal translation (_ - ;; Insert a space unless at the beginning of line. - (unless (or subtranslation - (= (line-beginning-position) - (point)) - thogai-attach-next) - (insert " ")) - ;; Reset `thogai-attach-next'. - (setq thogai-attach-next nil) + (unless subtranslation + (thogai-insert-space)) (insert (funcall (thogai-compose ;; Capitalize first letter. (if thogai-capitalize-next-word -- cgit v1.2.3