aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--thogai.el42
1 files changed, 35 insertions, 7 deletions
diff --git a/thogai.el b/thogai.el
index 0ab579e..b30fdde 100644
--- a/thogai.el
+++ b/thogai.el
@@ -161,13 +161,41 @@ and the variable is reset to nil.")
(message "Loaded %d dictionary entries"
(hash-table-count thogai-dictionary)))
+(defun thogai-mode-map (mode)
+ "Return thogai map specific to the MODE.
+
+MODE should be a symbol representing either a major mode or a
+minor mode. The thogai map specific to foo-mode is the value of
+the symbol thogai-foo-mode-map. The return value is an
+association list with the same structure as `thogai-global-map'."
+ (let ((major-mode-map (intern (concat "thogai-" (symbol-name mode) "-map"))))
+ (and (boundp major-mode-map)
+ (symbol-value major-mode-map))))
+
+(defun thogai-current-map ()
+ "Return the union of all currently active thogai maps.
+
+This includes, from highest precedence to lowest, the thogai maps
+of all current minor modes, the thogai map of the current major
+mode, and the global thogai map specified in `thogai-global-map'.
+The return value is an association list with the same structure
+as `thogai-global-map'."
+ (append (seq-reduce (lambda (result minor-mode)
+ (append (thogai-mode-map minor-mode)
+ result))
+ local-minor-modes
+ nil)
+ (thogai-mode-map major-mode)
+ thogai-global-map))
+
(defun thogai-lookup (stroke)
"Lookup STROKE in dictionary.
-STROKE is looked up in `thogai-global-map' and
-`thogai-dictionary' with `thogai-global-map' having higher
-precedence. If STROKE is in neither, nil is returned."
- (or (map-elt thogai-global-map stroke)
+STROKE is looked up in the result of `thogai-current-map' and
+`thogai-dictionary' with the result of `thogai-current-map'
+having higher precedence. If STROKE is in neither, nil is
+returned."
+ (or (map-elt (thogai-current-map) stroke)
(map-elt thogai-dictionary stroke)))
(defun thogai-filter-map (function sequence)
@@ -182,13 +210,13 @@ only the non-nil results."
"Lookup TRANSLATION in reverse dictionary.
A list of all strokes producing TRANSLATION is returned.
-TRANSLATION is looked up in `thogai-global-map' and
-`thogai-reverse-dictionary'."
+TRANSLATION is looked up in the result of `thogai-current-map'
+and `thogai-reverse-dictionary'."
(append
(thogai-filter-map (pcase-lambda (`(,key . ,value))
(and (equal value translation)
key))
- thogai-global-map)
+ (thogai-current-map))
(gethash translation thogai-reverse-dictionary)))
(defun thogai-longest-match (state)