Need a function to remove an advice, when point is on the code, where the advice is added

编辑调试的 elisp configuration 时候,假如光标在下面这一行,

(advice-add 'kill-new :around #'my-kill-new)

How to make an interactive command to achieve the following behaviour when executed:

(advice-remove 'kill-new #'my-kill-new)

更进一步,如果事先没有这个advice则 act like advice-add, 有则如上所述,那就更好了。

(defun my-goto-left-paren ()
  "a(...|....) => a|(...)"
  (or (eq (char-after) ?\()
      (let ((innermost-paren (nth 1 (syntax-ppss))))
        (if innermost-paren
            (goto-char innermost-paren)

(defun rm-at-point:hook|advice|alist ()
    (let ((form (read (progn
                        (buffer-substring-no-properties (point)
      (pcase (car form)
         (pcase (length form)
            ;; (add-hook 'x-hook 'fn nil-or-append :local)
            (eval `(remove-hook ,(cadr form)
                                ,(nth 2 form)
           (_ (eval `(remove-hook ,(cadr form)
                                  ,(nth 2 form)))))
         (prin1 (symbol-value (eval (cadr form)))))
        ;; (advice-add 'ffx :before 'f1)
         (eval `(advice-remove ,(cadr form) ,(nth 3 form)))
         (message "rm %S advice => %S" (cadr form) (nth 3 form)))
        ;; (add-to-list 'xx-alist '("a" . 1))
         (cl-symbol-macrolet ((al (eval (cadr form))))
           (eval `(setq ,al
                        (delete ,(nth 2 form) ,al)))
           (prin1 (eval al))))
         (error "unkown %S" form))))))
1 个赞