From 0143af1c0b538b7c5ae008966e5d3cf73dd68c16 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sun, 12 Jun 2022 23:22:00 +0530 Subject: Abstract out insertion of literal translations. * thogai.el (thogai-insert-translation): Abstract out literal translation insertion logic into ... (thogai-insert-literal): ... new function. --- thogai.el | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/thogai.el b/thogai.el index 73fd118..425edf1 100644 --- a/thogai.el +++ b/thogai.el @@ -190,6 +190,29 @@ Insert space at point unless at the beginning of a line or thogai-attach-next) (insert " "))) +(defun thogai-insert-literal (literal-translation) + "Insert LITERAL-TRANSLATION at point. + +Insert LITERAL-TRANSLATION at point, respecting +`thogai-capitalize-next-word' and +`thogai-uncapitalize-next-word'." + (insert (funcall (thogai-compose + ;; Capitalize first letter. + (if thogai-capitalize-next-word + (lambda (str) + (setq thogai-capitalize-next-word nil) + (concat (upcase (substring str 0 1)) + (substring str 1))) + 'identity) + ;; Uncapitalize first letter. + (if thogai-uncapitalize-next-word + (lambda (str) + (setq thogai-uncapitalize-next-word nil) + (concat (downcase (substring str 0 1)) + (substring str 1))) + 'identity)) + literal-translation))) + (defun thogai-insert-translation (translation &optional subtranslation) "Insert TRANSLATION at point. @@ -248,22 +271,7 @@ callers should never pass non-nil SUBTRANSLATION." ;; 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 - (lambda (str) - (setq thogai-capitalize-next-word nil) - (concat (upcase (substring str 0 1)) - (substring str 1))) - 'identity) - ;; Uncapitalize first letter. - (if thogai-uncapitalize-next-word - (lambda (str) - (setq thogai-uncapitalize-next-word nil) - (concat (downcase (substring str 0 1)) - (substring str 1))) - 'identity)) - translation)))) + (thogai-insert-literal translation))) ;; Recurse for rest of translation. (unless (string= rest-of-translation "") (thogai-insert-translation rest-of-translation t))))) -- cgit v1.2.3