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?

2

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))
  • I want to accept the answer, but for some reason the "V" for doing that does not appear. – AlwaysLearning Jun 30 '17 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.