(defadvice debug-on-entry (around advise-primitive activate) "If an error is signalled because FUNCTION is a primitive, query the user whether to debug Lisp calls via `defadvice'." (condition-case condition-data ad-do-it (error (let ((error-message (format "Function %s is a primitive" (ad-get-arg 0)))) (if (and (equal (car (cdr condition-data)) error-message) (interactive-p) (yes-or-no-p (concat error-message "; debug Lisp calls via defadvice? "))) (eval `(defadvice ,(ad-get-arg 0) (before debug activate) "Debug (when called from an Emacs Lisp function)." (debug))) (signal 'error (cdr condition-data))))))) ;; (defadvice cancel-debug-on-entry (around advise-primitive activate) ;; ...)