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"))
5
  • 1
    Does this answer your question? Change doc string summary of a function on the fly
    – Drew
    Commented Jul 1, 2022 at 0: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
    Commented Jul 1, 2022 at 0: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
    Commented Jul 1, 2022 at 0: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
    Commented Jul 1, 2022 at 1: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
    Commented Jul 1, 2022 at 1:04

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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