From c1c2cd4faa0adc87f9334ec92ace8bcf5ae8333e Mon Sep 17 00:00:00 2001 From: Michael Heerdegen Date: Thu, 14 Nov 2019 17:47:51 +0100 Subject: [PATCH] WIP: Try to fix edebug-remove-instrumentation for advised funs --- lisp/emacs-lisp/edebug.el | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el index 6b55d7cff0..e94adeb64b 100644 --- a/lisp/emacs-lisp/edebug.el +++ b/lisp/emacs-lisp/edebug.el @@ -56,6 +56,7 @@ (require 'macroexp) (require 'cl-lib) (eval-when-compile (require 'pcase)) +(eval-when-compile (require 'subr-x)) ;;; Options @@ -4571,6 +4572,20 @@ edebug-unload-function ;; Continue standard unloading. nil) +(defun edebug--advised-p (symbol) + ;; Non-nil when SYMBOL's `symbol-function' is advised. The non-nil + ;; return value is the unwrapped base function if it was wrapped, + ;; and the symbol t else. + (pcase (symbol-function symbol) + ((and (pred advice--p) + (app advice--cd*r orig-f) + (let unwrapped (edebug-unwrap* orig-f))) + (if (equal unwrapped orig-f) t unwrapped)) + (`(macro . ,(and (pred advice--p) + (app advice--cd*r orig-f) + (let unwrapped (edebug-unwrap* orig-f)))) + (if (equal unwrapped orig-f) t `(macro . ,unwrapped))))) + (defun edebug-remove-instrumentation (functions) "Remove Edebug instrumentation from FUNCTIONS. Interactively, the user is prompted for the function to remove @@ -4582,9 +4597,13 @@ edebug-remove-instrumentation (lambda (symbol) (when (and (functionp symbol) (get symbol 'edebug)) - (let ((unwrapped (edebug-unwrap* (symbol-function symbol)))) - (unless (equal unwrapped (symbol-function symbol)) - (push symbol functions))))) + (if-let ((advised (edebug--advised-p symbol))) + (unless (eq advised t) + (push symbol functions)) + (let ((unwrapped (edebug-unwrap* + (symbol-function symbol)))) + (unless (equal unwrapped (symbol-function symbol)) + (push symbol functions)))))) obarray) (unless functions (error "Found no functions to remove instrumentation from")) @@ -4598,8 +4617,12 @@ edebug-remove-instrumentation functions))))) ;; Remove instrumentation. (dolist (symbol functions) - (setf (symbol-function symbol) - (edebug-unwrap* (symbol-function symbol)))) + (if-let ((advised (edebug--advised-p symbol))) + (unless (eq advised t) + (funcall (or (get symbol 'defalias-fset-function) #'fset) + symbol advised)) + (setf (symbol-function symbol) + (edebug-unwrap* (symbol-function symbol))))) (message "Removed edebug instrumentation from %s" (mapconcat #'symbol-name functions ", "))) -- 2.24.0