1

In the documentation, two ways are suggested for accessing arguments in an advice: by the name of the argument in the original function and by using special functions. I cannot get the second way to work. Here is my attempt:

(defun my-insert-for-yank(orig-fun &rest args)
  (insert (ad-get-arg 1)))

(advice-add 'insert-for-yank :around #'my-insert-for-yank)

When I run (insert-for-yank "aa bb"), I get a message about ad-get-arg being a void function.

What am I missing?

Drew
  • 77,472
  • 10
  • 114
  • 243
AlwaysLearning
  • 779
  • 4
  • 15
  • An up-to-date link: https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html, also accessible from your Emacs with <f1> i d m elisp g advising functions – npostavs Jun 29 '17 at 14:56

1 Answers1

4

You're reading the doc for Emacs-21's advice (i.e. defadvice) and use it with Emacs-25's advice (i.e. advice-add).

All th ad-* thingies are specific to defadvice. So your example code should be written using "normal" Elisp functionality, such as:

(defun my-insert-for-yank (_orig-fun &rest args)
  (insert (nth 0 args)))

or

(defun my-insert-for-yank (_orig-fun string)
  (insert string))
Stefan
  • 26,404
  • 3
  • 48
  • 85