diff options
Diffstat (limited to 'thogai.el')
-rw-r--r-- | thogai.el | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -46,6 +46,8 @@ (require 'subr-x) (require 'term) +(require 'thogai-english-orthography) + (defvar thogai-dictionary-files (list "~/.config/plover/main.json" "~/.config/plover/commands.json") @@ -288,6 +290,35 @@ Insert LITERAL-TRANSLATION at point, respecting (setq thogai-attach-next nil thogai-glue nil)) +(defun thogai-insert-orthography-aware-suffix (suffix) + "Insert orthography aware SUFFIX for current word." + (let ((word (current-word t))) + (backward-kill-word 1) + (insert (or (seq-some (pcase-lambda (`(,pattern . ,replacement)) + (save-match-data + (let ((string (concat word " ^ " suffix))) + (and (string-match pattern string) + (replace-match replacement nil nil string))))) + thogai-english-orthography-rules) + ;; We deleted a negative lookbehind assertion from + ;; Plover's English orthography rules since elisp does + ;; not support that in regular expressions. Implement + ;; it here without regular expressions. + ;; + ;; The following examples illustrate this rule: + ;; oligarch + s = oligarchs + ;; patriarch + s = patriarchs + ;; monarch + s = monarchs + ;; birch + s = birches + (and (string= suffix "s") + (string-suffix-p "rch" word) + (not (string-suffix-p "garch" word)) + (not (string-suffix-p "iarch" word)) + (not (string-suffix-p "narch" word)) + (concat word "es")) + ;; As a last resort, simply append the suffix. + (concat word suffix))))) + (defun thogai-insert-translation (translation &optional non-first-part-p) "Insert TRANSLATION at point. @@ -341,6 +372,11 @@ External callers should always pass nil as the value." (string-prefix-p "{^~|" str))) (thogai-insert-translation (concat "{^}{" (string-remove-prefix "{^" translation)))) + ;; Orthography aware suffix + ((pred (lambda (str) + (string-prefix-p "{^" str))) + (thogai-insert-orthography-aware-suffix + (string-remove-prefix "{^" (string-remove-suffix "}" translation)))) ;; Glue operator ((pred (lambda (str) (string-prefix-p "{&" str))) |