0

I want to add advice to `describe-function'. However, when I try to do so, I get an error due to wrong number of arguments. Function:

(defun describe-function-advice (function)                                                                                                                                                                         
  (interactive)                                                                                                                                                                                                    
    (setq-local help-buffer-type "describe-function")                                                                                                                                                                
    (setq-local help-buffer-arg function))

(advice-add 'describe-function :after #'describe-function-advice)

Error:

Debugger entered--Lisp error: (wrong-number-of-arguments (1 . 1) 0)
  #f(compiled-function (function) "Display the full documentation of 
    FUNCTION (a symbol).\nWhen called from lisp, FUNCTION may also be
    a function object." (interactive #f(compiled-function ()    
    #<bytecode 0x12b6b$
 apply(#f(compiled-function (function) "Display the full documentation 
   of FUNCTION (a symbol).\nWhen called from lisp, FUNCTION may also 
   be a function object." (interactive #f(compiled-function () 
   #<bytecode 0$
 describe-function()
 funcall-interactively(describe-function)
 #<subr call-interactively>(describe-function nil nil)
 apply(#<subr call-interactively> describe-function (nil nil))
 call-interactively@ido-cr+-record-current-command(
    #<subr call-interactively> describe-function nil nil)
 apply(call-interactively@ido-cr+-record-current-command 
    #<subr call-interactively> (describe-function nil nil))
 call-interactively(describe-function nil nil)
 command-execute(describe-function)

For the given problem, I can probably use `help-fns-describe-function-functions', but I would still like to understand how to use advice-add with interactive functions.

Realraptor
  • 1,253
  • 6
  • 17

2 Answers2

1

Untested, but your (interactive) form doesn't tell Emacs how to obtain the FUNCTION argument, so that's presumably your problem.

phils
  • 48,657
  • 3
  • 76
  • 115
0

When you advice a function with :after your function is called after the original function with the same arguments. So setq-local take effect in the buffer where you call the function.

See: https://www.gnu.org/software/emacs/manual/html_node/elisp/Advice-Combinators.html

This works but probably doesn't give the result you expect:

(defun describe-function-advice (&rest args)
  (setq-local help-buffer-type "describe-function"))

(advice-add 'describe-function :after #'describe-function-advice)
Balaïtous
  • 173
  • 7