-
-
Save tmdemelo/993fb9a1615e627c8bb0bd10208be0c3 to your computer and use it in GitHub Desktop.
minor and major mode handling for boon.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar boon-minor-mode-command-map-alist nil | |
"Keymaps for minor modes in boon command state.") | |
(defvar-local boon-minor-mode-map-alist nil | |
"Active boon keymaps for minor modes.") | |
(defvar-local boon-major-mode-map-alist nil | |
"Active boon keymaps for major mode.") | |
(add-to-list 'emulation-mode-map-alists 'boon-major-mode-map-alist) | |
(add-to-list 'emulation-mode-map-alists 'boon-minor-mode-map-alist) | |
(defun boon-boonify-major-name (mode) | |
"Setup extra boon keymaps for major MODE." | |
(let ((command-map (intern (format "boon-%s-command-map" mode))) | |
(map-alist (intern (format "boon-%s-map-alist" mode)))) | |
(set command-map (make-sparse-keymap)) | |
(set map-alist | |
(list (cons 'boon-command-state | |
(symbol-value command-map)))) | |
(put mode 'boon-map-alist map-alist) | |
;; update map alist just to be safe | |
(boon-update-major-mode-map-alist))) | |
(defun boon-boonify-minor-name (mode) | |
"Setup extra boon keymaps for minor MODE." | |
(let ((command-map (intern (format "boon-%s-command-map" mode)))) | |
(set command-map (make-sparse-keymap)) | |
(add-to-list 'boon-minor-mode-command-map-alist | |
(cons mode (symbol-value command-map))) | |
;; update map alists just to be safe | |
(boon-update-minor-mode-map-alist))) | |
(defun boon-update-minor-mode-map-alist (&rest args) | |
"Update `boon-minor-mode-map-alist' for current boon state." | |
(setq boon-minor-mode-map-alist nil) | |
(when boon-command-state | |
(setq boon-minor-mode-map-alist boon-minor-mode-command-map-alist))) | |
(advice-add 'boon-set-state :after 'boon-update-minor-mode-map-alist) | |
(defun boon-update-major-mode-map-alist (&rest args) | |
"Update `boon-major-mode-map-alist' for active major-mode." | |
(setq boon-major-mode-map-alist | |
(if-let ((map-alist (get major-mode 'boon-map-alist))) | |
(symbol-value map-alist)))) | |
(add-hook 'after-change-major-mode-hook 'boon-update-major-mode-map-alist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment