Advising an interactive emacs feature: up to

I want some advice before the board that uses interactive arguments, for example. find-dired:

(defadvice find-dired (before eab-find-dired activate)
  (message "before!")
  (setq find-args '("-iname '**'" . 10)))

But emacs only fulfills this advice after find-diredan interactive session, and I cannot configure it find-argsbefore. How to resolve the contradiction?

Upd. Note that the macro is defadvice deprecated .

+5
source share
5 answers

artscan , . 'interactive, , , , - , - ( 'interactive...)

, , : advice.el. @ Foo games: An advice tutorial. Emacs M-x find-library advice RET.

, advice.el @@ Advising interactive behavior: - , .

, , around, before, after - . , interactive ( ) .

, ( before):

(defadvice find-dired (before eab-find-dired (dir args) activate)
  "ignore find-args, hard code \"-iname '**'\""
  (interactive
   (list (read-directory-name "Run find in directory: " nil "" t)
         (read-string "Run find (with args): " '("-iname '**'" . 10)
                      '(find-args-history . 1)))))

, , , , , Lindydancer .

- , . , , . , , - , , , . , , ( ).

+8

Emacs interactive .

, defadvice, . :

(defun my-find-dired ()
  (interactive)
  (let ((find-args '("-iname '**'" . 10)))
    (call-interactively 'find-dired)))

, , , find-dired:

(setq find-args '("-iname '**'" . 10))
+4

?

(defun find-dired-my-defaults (dir args)
  "just like `find-dired' but with defaults."
  (interactive
   (list (read-directory-name "Run find in directory: " nil "" t)
         (read-string "Run find (with args): " '("-iname '**'" . 1)
                      '(find-args-history . 1))))
  (find-dired dir args))

, :

(define-key foo-mode-map [remap find-dired] 'find-dired-my-defaults)

defadvice, , .

EDIT: @Lindydancer , , defadvice .

+2

:

(defadvice find-dired (around eab-find-dired (dir args) activate)
  (interactive
   (list (read-directory-name "Run find in directory: " nil "" t)
         (read-string "Run find (with args): " '("-iname '**'" . 10)
                      '(find-args-history . 1))))
  ad-do-it)

interactive form find-dired : '("-iname '**'" . 10) find-args find-args . around-advice (dir args) before-advice.

+1

, eval-last-sexp, describe-function . toggle-debug-on-error (defun x () (interactive (list :interactiveform (error "Int")))).

  • call-interactively.
  • , command-execute, call-interactively.
  • M-x COMMAND, execute-extended-command ( , M-x), command-execute,...

, interactive M-x, , . nadvice.el:

(defun setup-var-advice (oldfun command &rest r)
  (if (eq command 'save-buffer)
      (let ((myvar t)) (apply oldfun command r)) ;; Advice sets up variable
    (apply oldfun command r))) ;; Advice has no effect

(advice-add #'call-interactively :around #'setup-var-advice)

, , , , , , , .

0

All Articles