branch: externals/ergoemacs-mode
commit 8cfa4717ce2cc9cefe2ce17e64cb3dae7431c132
Author: Matthew Fidler <[email protected]>
Commit: Matthew Fidler <[email protected]>
Use nadvice, as requested by Stephan Monnier
---
ergoemacs-advice.el | 87 +++++++----------------------------------------------
ergoemacs-mode.el | 14 +++++++--
2 files changed, 23 insertions(+), 78 deletions(-)
diff --git a/ergoemacs-advice.el b/ergoemacs-advice.el
index 523590d..feb7724 100644
--- a/ergoemacs-advice.el
+++ b/ergoemacs-advice.el
@@ -34,21 +34,13 @@
(require 'ergoemacs-macros))
(require 'mouse)
+(require 'nadvice)
(defvar ergoemacs-mode)
(defvar ergoemacs-keymap)
(defvar ergoemacs-map--unbound-keys)
(defvar ergoemacs-user-keymap)
-(declare-function ergoemacs-map-- "ergoemacs-map")
-
-(declare-function ergoemacs-map-properties--hook-define-key
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--installed-p
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--label "ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--map-fixed-plist
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--original
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--original-user
"ergoemacs-map-properties")
-
(declare-function ergoemacs-key-description--substitute-command-keys
"ergoemacs-key-description")
(declare-function ergoemacs-translate--define-key "ergoemacs-translate")
@@ -62,64 +54,11 @@
(declare-function ergoemacs-command-loop--temp-message
"ergoemacs-command-loop")
(declare-function ergoemacs-key-description "ergoemacs-key-description")
-(defvar ergoemacs-advice--temp-replace-functions nil
- "List of `ergoemacs-mode' temporary replacement functions.
-
-These replacement functions are are turned on when
-`ergoemacs-mode' is turned on.")
-
-(defvar ergoemacs-advice--permanent-replace-functions nil
- "List of `ergoemacs-mode' permanent replacement functions.
-
-These replacement functinos are turned on after `ergoemacs-mode'
-is loaded, but not turned off.")
-
-(defun ergoemacs-advice--enable-replacement (ad &optional disable)
- "Enable ergoemacs-c advice AD (or optionally DISABLE)."
- (cond
- (disable
- (when (fboundp (intern (concat "ergoemacs-advice--real-" (symbol-name
ad))))
- (defalias ad (intern (concat "ergoemacs-advice--real-" (symbol-name ad)))
- (documentation (intern (concat "ergoemacs-advice--real-" (symbol-name
ad)))))))
- (t
- (when (fboundp (intern (concat "ergoemacs-advice--" (symbol-name ad))))
- (defalias ad (intern (concat "ergoemacs-advice--" (symbol-name ad)))
- (documentation (intern (concat "ergoemacs-advice--" (symbol-name
ad)))))))))
-
-(defun ergoemacs-advice--enable-replacements (&optional disable permanent)
- "Enable the function replacements.
-
-When DISABLE is non-nil, disable the replacements.
-
-When PERMANENT is non-nil, these replacements are permanent, not temporary."
- (dolist (ad (or (and permanent ergoemacs-advice--permanent-replace-functions)
- ergoemacs-advice--temp-replace-functions))
- (ergoemacs-advice--enable-replacement ad disable)))
-
-(add-hook 'ergoemacs-mode-startup-hook 'ergoemacs-advice--enable-replacements)
-
-(defun ergoemacs-advice--disable-replacements ()
- "Disable the function replacements."
- (ergoemacs-advice--enable-replacements t))
-
-(add-hook 'ergoemacs-mode-shutdown-hook
'ergoemacs-advice--disable-replacements)
-
-(defun ergoemacs-advice--enable-permanent-replacements ()
- "Enable permanent replacements."
- (ergoemacs-advice--enable-replacements nil t))
-
-(add-hook 'ergoemacs-mode-intialize-hook
'ergoemacs-advice--enable-permanent-replacements)
-
-(defvar ergoemacs--original-local-map nil
- "Original keymap used with `use-local-map'.")
-
-;; FIXME for emacs 25
-(ergoemacs-advice substitute-command-keys (string)
+(defun ergoemacs-advice-substitute-command-keys (orig-fun &rest args)
"Use `ergoemacs-substitute-command-keys' when `ergoemacs-mode' is enabled"
- :type :replace
(if ergoemacs-mode
- (ergoemacs-key-description--substitute-command-keys string)
- (ergoemacs-advice--real-substitute-command-keys string)))
+ (ergoemacs-key-description--substitute-command-keys (nth 0 args))
+ (funcall orig-fun args)))
(defun ergoemacs-mode--undefined-advice (&optional type)
@@ -155,25 +94,21 @@ TYPE is the type of translation installed."
(when (memq 'down (event-modifiers last-command-event))
current-prefix-arg)))))
-(ergoemacs-advice undefined ()
+(defun ergoemacs-advice-undefined (orig-fun)
"Allow `ergoemacs-mode' to display keys, and intercept ending <apps> keys."
- :type :around
- (if (not ergoemacs-mode)
- ad-do-it
- (ergoemacs-mode--undefined-advice)))
-
-(ergoemacs-advice handle-shift-selection ()
+ (if ergoemacs-mode
+ (ergoemacs-mode--undefined-advice)
+ (call-interactively orig-fun)))
+
+ (defun ergoemacs-advice-handle-shift-selection ()
"Allow `ergoemacs-mode' to do shift selection on keys like Alt+# to Alt+3."
- :type :before
(when (eq 'ergoemacs-command-loop--shift-translate (key-binding
(this-single-command-keys)))
(setq this-command-keys-shift-translated t)))
-(ergoemacs-advice read-key (&optional prompt)
+(defun ergoemacs-advice-read-key ()
"Drop single command keys for read-key." ; For compataiblity with emacs 25.5
- :type :before
(setq ergoemacs-command-loop--single-command-keys nil))
-
(provide 'ergoemacs-advice)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ergoemacs-advice.el ends here
diff --git a/ergoemacs-mode.el b/ergoemacs-mode.el
index 2451438..295a2e1 100644
--- a/ergoemacs-mode.el
+++ b/ergoemacs-mode.el
@@ -394,6 +394,8 @@ after initializing ergoemacs-mode.
(defvar ergoemacs-minor-alist nil
"ErgoEmacs minor mode keymap.")
+(declare-function ergoemacs-advice-undefined "ergoemacs-advice")
+
(defun ergoemacs-setup-override-keymap ()
"Setup `ergoemacs-mode' keymaps."
(setq ergoemacs-override-alist `((ergoemacs-mode . ,ergoemacs-user-keymap)
@@ -401,12 +403,20 @@ after initializing ergoemacs-mode.
(ergoemacs-mode . ,ergoemacs-keymap))
ergoemacs-minor-alist `((mark-active . ,ergoemacs-mark-active-keymap)))
(add-hook 'emulation-mode-map-alists ergoemacs-override-alist)
- (add-hook 'minor-mode-map-alist ergoemacs-minor-alist))
+ (add-hook 'minor-mode-map-alist ergoemacs-minor-alist)
+ (advice-add 'undefined :around #'ergoemacs-advice-undefined)
+ (advice-add 'substitute-command-keys :around
#'ergoemacs-advice-substitute-command-keys)
+ (advice-add 'handle-shift-selection :before
#'ergoemacs-advice-handle-shift-selection)
+ (advice-add 'read-key :before #'ergoemacs-advice-read-key))
(defun ergoemacs-remove-override-keymap ()
"Remove `ergoemacs-mode' keymaps."
(remove-hook 'emulation-mode-map-alists 'ergoemacs-override-alist)
- (remove-hook 'minor-mode-map-alist ergoemacs-minor-alist))
+ (remove-hook 'minor-mode-map-alist ergoemacs-minor-alist)
+ (advice-remove 'undefined #'ergoemacs-advice-undefined)
+ (advice-remove 'substitute-command-keys
#'ergoemacs-advice-substitute-command-keys)
+ (advice-remove 'handle-shift-selection
#'ergoemacs-advice-handle-shift-selection)
+ (advice-remove 'read-key #'ergoemacs-advice-read-key))
;;; Frequently used commands as aliases