0

Can one append to a function documentation by calling some function or string in the documentation part?

With the following I do not get anything from get.

(defun myfunc 
  "Brief description"
...)

(put 'myfunc 'function-documentation
     (concat
      (get 'myfunc 'function-documentation)
      "Line 1
Line 2"))
Dilna
  • 1,173
  • 3
  • 10
  • 1
    Does this answer your question? [Change doc string summary of a function on the fly](https://emacs.stackexchange.com/questions/50121/change-doc-string-summary-of-a-function-on-the-fly) – Drew Jul 01 '22 at 00:55
  • @Tobias's answer there tells you how to change a function's doc string with Elisp, including how to prepend or append or replace part or all of it. – Drew Jul 01 '22 at 00:56
  • Reading it, it was about changing the first line of a docstring of a function. I want something different. Have one line from the function, then append a usage part defined before the function declaration. – Dilna Jul 01 '22 at 00:58
  • It's the same thing. Replace the doc string with whatever string you want. Appending to the existing string is about the easiest change possible: `concat`. – Drew Jul 01 '22 at 01:00
  • Would be more useful for me to define the text before defining the function. I would need some examples as I am struggling with Tobias 's answer. I know about `concat` but not in what I got to de here. – Dilna Jul 01 '22 at 01:04

1 Answers1

1

Change doc string summary of a function on the fly tells the whole story but maybe one point could do with a bit more emphasis: Emacs looks for documentation of the function foo in two different places:

  1. The original doc-string in the definition of foo. This is available from elisp as (documentation 'foo t).
  2. The contents of the function-documentation property of the symbol foo.

The second overrides the first when it is non-nil and the second is not initialised from the first. Thus

(defun foo ()
  "Foo's original doc.")

(documentation 'foo t)  ;=> "Foo's original doc."

(get 'foo 'function-documentation)  ;=> nil

The OP wants to append to the original documentation so this will do the trick:

(put 'foo 'function-documentation
     (concat
      (documentation 'foo t)
      "Line 1
Line 2"))

Thus use documentation to pull out the original doc-string, concat stuff to it and store the result in the function-documentation property.

Fran Burstall
  • 3,665
  • 10
  • 18