mlf176f2 pushed a commit to branch externals/ergoemacs-mode in repository elpa.
commit 8963c6c34a3e78bf14370e551eefd8bb3f061a27 Author: Matthew L. Fidler <[email protected]> Date: Wed Jun 4 09:47:04 2014 -0500 Push shortcuts to the bottom. Should allow overrides. --- ergoemacs-modal.el | 37 +++++++++++++------------- ergoemacs-mode.el | 63 ++++++++++++++++++++++----------------------- ergoemacs-shortcuts.el | 10 ++----- ergoemacs-theme-engine.el | 26 ++++++------------ 4 files changed, 61 insertions(+), 75 deletions(-) diff --git a/ergoemacs-modal.el b/ergoemacs-modal.el index 94b9cbd..94c5acb 100644 --- a/ergoemacs-modal.el +++ b/ergoemacs-modal.el @@ -325,12 +325,15 @@ Typically function keys") (defvar ergoemacs-modal-keymap nil "`ergoemacs-mode' modal keymap. Attempts to capture ALL keystrokes.") -(defun ergoemacs-modal-keymap (&optional map) +(defvar ergoemacs-modal-base-keymap nil + "`ergoemacs-mode' modal keymap. Attempts to capture ALL keystrokes.") + +(defun ergoemacs-modal-base-keymap (&optional map) "Returns the ergoemacs-modal keymap" - (if ergoemacs-modal-keymap + (if ergoemacs-modal-base-keymap (if map - (make-composed-keymap (list map ergoemacs-modal-keymap)) - ergoemacs-modal-keymap) + (make-composed-keymap (list map ergoemacs-modal-base-keymap)) + ergoemacs-modal-base-keymap) (let ((ret (make-sparse-keymap))) (unless ret (setq ret (make-sparse-keymap))) @@ -377,30 +380,27 @@ Typically function keys") "<end>" "<insert>" "<deletechar>")) - (setq ergoemacs-modal-keymap ret)) - (ergoemacs-modal-keymap map))) + (setq ergoemacs-modal-base-keymap ret)) + (ergoemacs-modal-base-keymap map))) (defvar ergoemacs-modal-list '()) (defun ergoemacs-modal-toggle (type) "Toggle ergoemacs command modes." - (let* ((x (assq 'ergoemacs-modal ergoemacs-emulation-mode-map-alist)) - (help-list (gethash type ergoemacs-translation-text)) + (let* ((help-list (gethash type ergoemacs-translation-text)) keymap (type type) tmp (ergoemacs-ignore-advice t)) - (setq ergoemacs-emulation-mode-map-alist - (delq x ergoemacs-emulation-mode-map-alist)) (cond ((or (not ergoemacs-modal-list) ;; First time to turn on (not (eq (nth 0 ergoemacs-modal-list) type)) ;; New modal ) (push type ergoemacs-modal-list) - (setq keymap (make-composed-keymap - (list (ergoemacs-local-map type t) - (ergoemacs-modal-keymap)))) - (push (cons 'ergoemacs-modal keymap) - ergoemacs-emulation-mode-map-alist) + (setq ergoemacs-modal-keymap + (make-composed-keymap + (list (ergoemacs-local-map type t) + (ergoemacs-modal-base-keymap)))) + (ergoemacs-add-emulation) (set-default 'ergoemacs-modal type) (setq ergoemacs-modal type) (unless ergoemacs-default-cursor @@ -428,12 +428,11 @@ Typically function keys") (if type (progn ;; Turn off current modal, turn on last modal. (setq help-list (gethash type ergoemacs-translation-text)) - (setq keymap + (setq ergoemacs-modal-keymap (make-composed-keymap (list (ergoemacs-local-map type t) - (ergoemacs-modal-keymap)))) - (push (cons 'ergoemacs-modal keymap) - ergoemacs-emulation-mode-map-alist) + (ergoemacs-modal-base-keymap)))) + (ergoemacs-add-emulation) (set-default 'ergoemacs-modal type) (setq ergoemacs-modal type) (unless ergoemacs-default-cursor diff --git a/ergoemacs-mode.el b/ergoemacs-mode.el index c770bac..94d99eb 100644 --- a/ergoemacs-mode.el +++ b/ergoemacs-mode.el @@ -598,15 +598,7 @@ bindings the keymap is: (progn ;; add key (define-key ergoemacs-local-keymap key command) - (let ((x (assq major ergoemacs-emulation-mode-map-alist))) - ;; Delete keymap. - (if x - (setq ergoemacs-emulation-mode-map-alist (delq x ergoemacs-emulation-mode-map-alist))) - ;; Put at the top of the list - (setq ergoemacs-emulation-mode-map-alist - (append ergoemacs-emulation-mode-map-alist - (list (cons major ergoemacs-local-keymap)))) - (ergoemacs-shuffle-keys))))) + (ergoemacs-add-emulation major ergoemacs-local-keymap)))) (defun ergoemacs-local-unset-key (key) "Unset a key in the ergoemacs local map." @@ -706,30 +698,37 @@ However instead of using M-a `eval-buffer', you could use M-a `eb'" (setq ergoemacs-shortcut-keys nil) (ergoemacs-debug "WARNING: ergoemacs-shortcut-keys was turned on; Turning off.")))) +(defun ergoemacs-add-emulation (&optional var keymap keymap-list) + "Add emulation map +VAR is the emulation map variable +KEYMAP is the emulation map keymap +KEYMAP-LIST is a list of emulation maps. +This is added to `ergoemacs-emulation-mode-map-alist' while keeping the order correct." + (let ((small-emulation ergoemacs-emulation-mode-map-alist)) + (while (memq (car (car small-emulation)) + '(ergoemacs-modal + ergoemacs-repeat-keys + ergoemacs-read-input-keys)) + (pop small-emulation)) + (when (eq (car (nth (- (length small-emulation) 1) small-emulation)) + 'ergoemacs-shortcut-keys) + (setq small-emulation (nbutlast small-emulation 1))) + (when (and var keymap) + (setq x (assq var small-emulation)) + (when x + (delq x small-emulation)) + (push (cons var keymap) small-emulation)) + (when (listp keymap-list) + (setq small-emulation (append keymap-list small-emulation))) + (setq ergoemacs-emulation-mode-map-alist + `((ergoemacs-modal ,@(or ergoemacs-modal-keymap (make-sparse-keymap))) + (ergoemacs-repeat-keys ,@(or ergoemacs-repeat-keymap (make-sparse-keymap))) + (ergoemacs-read-input-keys ,@(or ergoemacs-read-input-keymap (make-sparse-keymap))) + ,@small-emulation + (ergoemacs-shortcut-keys ,@(or ergoemacs-shortcut-keymap (make-sparse-keymap))))))) + (defun ergoemacs-shuffle-keys (&optional var keymap keymap-list) - "Shuffle ergoemacs keymaps. -When VAR and KEYMAP are specified, replace the keymap in the -`ergoemacs-emulation-mode-map-alist'." - ;; Promotes keymaps in `ergoemacs-emulation-mode-map-alist' - (mapc - (lambda(what) - (if (and keymap (eq var what)) - (let ((x (assq what ergoemacs-emulation-mode-map-alist))) - (when x - (delq x ergoemacs-emulation-mode-map-alist)) - (push (cons var keymap) ergoemacs-emulation-mode-map-alist)) - (let ((x (assq what ergoemacs-emulation-mode-map-alist))) - (and x (setq ergoemacs-emulation-mode-map-alist - (cons x (delq x ergoemacs-emulation-mode-map-alist))))))) - ;; Promoted from least to most important - '(ergoemacs-shortcut-keys - ergoemacs-modal - ergoemacs-repeat-keys - ergoemacs-read-input-keys)) - ;; - ;; ergoemacs-shortcut-keys should be at the bottom of the list - - ;; Demote + "Shuffle ergoemacs keymaps in `minor-mode-map-alist'." (let ((x (assq 'ergoemacs-unbind-keys minor-mode-map-alist))) (setq minor-mode-map-alist (append (delq x minor-mode-map-alist) (list x))))) diff --git a/ergoemacs-shortcuts.el b/ergoemacs-shortcuts.el index 54d4a1d..3602f26 100644 --- a/ergoemacs-shortcuts.el +++ b/ergoemacs-shortcuts.el @@ -1440,13 +1440,9 @@ Basically, this gets the keys called and passes the arguments to`ergoemacs-read- (defvar ergoemacs-repeat-keymap nil) (defun ergoemacs-install-repeat-keymap (keymap &optional mode-line) "Installs repeat KEYMAP." - (let* ((x (assq 'ergoemacs-repeat-keys ergoemacs-emulation-mode-map-alist))) - (setq ergoemacs-repeat-keymap keymap) - (setq ergoemacs-repeat-keys t) - (when x - (setq ergoemacs-emulation-mode-map-alist (delq x ergoemacs-emulation-mode-map-alist))) - (push (cons 'ergoemacs-repeat-keys ergoemacs-repeat-keymap) - ergoemacs-emulation-mode-map-alist)) + (setq ergoemacs-repeat-keymap keymap) + (ergoemacs-add-emulation) + (setq ergoemacs-repeat-keys t) (when mode-line (ergoemacs-mode-line mode-line))) diff --git a/ergoemacs-theme-engine.el b/ergoemacs-theme-engine.el index 66205e6..9074be3 100644 --- a/ergoemacs-theme-engine.el +++ b/ergoemacs-theme-engine.el @@ -826,7 +826,7 @@ ergoemacs-get-keymaps-for-hook OBJ HOOK") (set (make-local-variable emulation-var) t) (setq x (assq emulation-var ergoemacs-emulation-mode-map-alist)) (when (or (not x) always) - (ergoemacs-shuffle-keys + (ergoemacs-add-emulation emulation-var (oref (ergoemacs-get-fixed-map obj map-name) map)))))))))) (defgeneric ergoemacs-create-hooks () @@ -1356,14 +1356,12 @@ DONT-COLLAPSE doesn't collapse empty keymaps" (and (not (eq nil theme))(symbolp theme) (symbol-name theme)) (and (stringp ergoemacs-theme) ergoemacs-theme) (and (not (eq nil ergoemacs-theme)) (symbolp ergoemacs-theme) (symbol-name ergoemacs-theme)))) - (setq ergoemacs-emulation-mode-map-alist - `(,(cons 'ergoemacs-read-input-keys read-map) - ,() - ,(cons 'ergoemacs-shortcut-keys shortcut-map) - ,@(mapcar - (lambda(remap) - (cons remap (oref (ergoemacs-get-fixed-map theme-obj remap) map))) - (ergoemacs-get-hooks theme-obj "-mode\\'"))))))) + (ergoemacs-add-emulation + nil nil + (mapcar + (lambda(remap) + (cons remap (oref (ergoemacs-get-fixed-map theme-obj remap) map))) + (ergoemacs-get-hooks theme-obj "-mode\\'")))))) @@ -2499,12 +2497,7 @@ Returns list of: read-keymap shortcut-keymap keymap shortcut-list unbind-keymap (unless (boundp emulation-var) (set-default emulation-var nil) (set (make-local-variable emulation-var) t)) - (setq x (assq emulation-var ergoemacs-emulation-mode-map-alist)) - (when x - (setq ergoemacs-emulation-mode-map-alist (delq x ergoemacs-emulation-mode-map-alist))) - (setq ergoemacs-emulation-mode-map-alist - (append ergoemacs-emulation-mode-map-alist - (list (cons emulation-var replace)))) + (ergoemacs-add-emulation emulation-var replace) (if always-modify-p (setq all-always-p nil) (push (list hook map-name) ergoemacs-theme-hook-installed))) @@ -3400,8 +3393,7 @@ This also: ;; `ergoemacs-read-input-keymap', then `ergoemacs-shortcut-keymap' ;; in `ergoemacs-emulation-mode-map-alist' - (push (cons 'ergoemacs-shortcut-keys ergoemacs-shortcut-keymap) ergoemacs-emulation-mode-map-alist) - (push (cons 'ergoemacs-read-input-keys ergoemacs-read-input-keymap) ergoemacs-emulation-mode-map-alist) + (ergoemacs-add-emulation) (add-hook 'emulation-mode-map-alists 'ergoemacs-emulation-mode-map-alist) (ergoemacs-theme-make-hooks ergoemacs-theme) (set-default 'ergoemacs-mode t)
