aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--thogai.el39
1 files changed, 38 insertions, 1 deletions
diff --git a/thogai.el b/thogai.el
index af392a8..efcc506 100644
--- a/thogai.el
+++ b/thogai.el
@@ -480,6 +480,42 @@ STROKES is injected first."
(ring-insert stroke-ring stroke)
(thogai-process-stroke stroke-ring))))
+(defun thogai-suggest ()
+ "Suggest strokes for current word.
+
+Suggest strokes for current word in the *thogai-suggestions*
+buffer. Suggestions are sorted shortest first."
+ ;; TODO: Don't cheat by picking up the current word. The current
+ ;; word may be a multi-word phrase.
+ (let ((word (current-word))
+ (suggestions-buffer (get-buffer-create "*thogai-suggestions*")))
+ (when word
+ (with-current-buffer suggestions-buffer
+ ;; Explicitly go to end of buffer, just in case someone messed
+ ;; up the point.
+ (goto-char (point-max))
+ (insert word)
+ (insert "\n")
+ ;; TODO: Suggest orthography-aware suffixes. For example,
+ ;; suggest "SUFBGS/-S" for the word "suffixes", even though
+ ;; "SUFBGS/-S" does not occur in the dictionary.
+ (dolist (stroke (sort (thogai-reverse-lookup word)
+ (lambda (strokes1 strokes2)
+ ;; Sort by number of strokes, falling back
+ ;; to string length.
+ (let ((count1 (length (split-string strokes1 "/")))
+ (count2 (length (split-string strokes2 "/"))))
+ (if (= count1 count2)
+ (< (length strokes1)
+ (length strokes2))
+ (< count1 count2))))))
+ (insert (concat "\t" stroke "\n")))
+ (insert "\n")
+ ;; Scroll to the end of windows showing the suggestions
+ ;; buffer.
+ (dolist (window (get-buffer-window-list suggestions-buffer nil t))
+ (set-window-point window (point-max)))))))
+
(defun thogai-process-stroke (stroke-ring)
"Process the most recent stroke.
@@ -508,7 +544,8 @@ current state, and should typically be `thogai-stroke-ring'."
(let ((translation (thogai-lookup (string-join matched-strokes "/"))))
(cond
((stringp translation)
- (thogai-insert-translation translation))
+ (thogai-insert-translation translation)
+ (thogai-suggest))
((commandp translation)
(call-interactively translation))))))))