aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2022-06-18 23:58:34 +0530
committerArun Isaac2022-06-19 00:00:34 +0530
commit99e44f9de05ec8785eee4128de2c27ea91ecf133 (patch)
tree23904cd70cb9be84fe24b518202e1f4aa90eb8af
parent9360b5a607147e0af3151b659e933e72423357e3 (diff)
downloadthogai-99e44f9de05ec8785eee4128de2c27ea91ecf133.tar.gz
thogai-99e44f9de05ec8785eee4128de2c27ea91ecf133.tar.lz
thogai-99e44f9de05ec8785eee4128de2c27ea91ecf133.zip
Introduce mode-specific maps.
* thogai.el (thogai-mode-map, thogai-current-map): New functions. (thogai-lookup, thogai-reverse-lookup): Use thogai-mode-map.
-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)