about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2022-06-12 23:22:00 +0530
committerArun Isaac2022-06-12 23:23:23 +0530
commit0143af1c0b538b7c5ae008966e5d3cf73dd68c16 (patch)
tree3a10db3c035e1222ee0dd61ae79b98e2225b2fa9
parent9c833e0e420e64cbb2292958bca5913300528cc0 (diff)
downloadthogai-0143af1c0b538b7c5ae008966e5d3cf73dd68c16.tar.gz
thogai-0143af1c0b538b7c5ae008966e5d3cf73dd68c16.tar.lz
thogai-0143af1c0b538b7c5ae008966e5d3cf73dd68c16.zip
Abstract out insertion of literal translations.
* thogai.el (thogai-insert-translation): Abstract out literal
translation insertion logic into ...
(thogai-insert-literal): ... new function.
-rw-r--r--thogai.el40
1 files 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)))))