Skip to main content
Share Your Experience: Take the 2024 Developer Survey
16 votes

Is it possible to attach generated doc string to a lambda?

In Emacs-25, there's a new feature exactly for that purpose: (let ((foo 1) (bar 2)) (lambda () (:documentation (format "Return the sum of %d and %d." foo bar)) (+ foo bar)))
Stefan's user avatar
  • 26.5k
13 votes
Accepted

Is it possible to attach generated doc string to a lambda?

Well lambdas can have regular docstrings just like any other function definition: (lambda () "I'm a docstring!" (+ foo bar)) So you could use: (let ((foo 1) (bar 2)) `(lambda () ,...
phils's user avatar
  • 51.5k
10 votes
Accepted

What is the logic behind the weird lisp docstring (left) indentation?

It's so the docstring will look normal when the user views it in the help system. The first line of the docstring is indented. Since the G directly follows the double quote " there is no indentation ...
Sue D. Nymme's user avatar
  • 1,456
6 votes

Change doc string summary of a function on the fly

In addition to @Tobias's answer, refer to C-hig (elisp)Accessing Documentation The other notable aspect of dynamic documentation via the function-documentation symbol property (amongst others), is ...
phils's user avatar
  • 51.5k
6 votes
Accepted

Change doc string summary of a function on the fly

You can access the raw documentation string of a function foo with (documentation 'foo t). You can set the documentation string of foo with (put 'foo 'function-documentation "My new docstring."). ...
Tobias's user avatar
  • 33.2k
5 votes
Accepted

Disabling quote conversion in docstrings

Basil's answer covers the needs of the end-user. If you're writing elisp docstrings for other people, however, you (unfortunately) can't rely on everyone configuring text-quoting-style to grave, so ...
phils's user avatar
  • 51.5k
5 votes
Accepted

Docstring - quotes or semicolons?

That is NOT a comment: that's the doc string of the function. The doc string of the function is what you get when you ask for help on the function: C-h f org-before-change-function will show some ...
NickD's user avatar
  • 30.5k
5 votes

What is \= in doc strings?

From scrounging the commit history it seems that this "escape" or "literal" prefix is not \= -- instead it is \\=. So in my example of doc string text (put SYMBOL 'my-mode-indent-...
Greg Hendershott's user avatar
5 votes
Accepted

Emacs 29 docstring single quote escaping rules, compiler level event?

Documentation is: C-hig (elisp)Keys in Documentation C-hig (elisp)Text Quoting Style In short, the text-quoting-style feature introduced in Emacs 25 made it impossible to use certain characters in ...
phils's user avatar
  • 51.5k
4 votes
Accepted

Documenting keyboard macros Can I have a doc string for fset the same way as defun

You can use defalias instead of fset. You use it like fset but it takes a docstring as third argument. eg: (defalias 'pastebelow (kmacro-lambda-form [?y ?y ?p] 0 "%d") "This is my ...
dalanicolai's user avatar
  • 7,855
4 votes

Emacs 29 docstring single quote escaping rules, compiler level event?

From Emacs 29 etc/NEWS (slightly paraphrased) Byte compilation will now warn about some quoting mistakes in docstrings. When writing code that contains the ' character (APOSTROPHE), that quote ...
ocodo's user avatar
  • 1,222
4 votes
Accepted

display eldoc help info behind point

As with the comment, pos-tip-show works fine for me too. I did hack together a better (but not perfect) version of the momentary-string-display version. I just rewrote the display function so that it ...
justbur's user avatar
  • 1,510
4 votes

Disabling quote conversion in docstrings

TL;DR (setq text-quoting-style 'grave) and see the answer by phils. Is it possible to have them displayed in their original form? Yes, see (elisp) Text Quoting Style, specifically the ...
Basil's user avatar
  • 12.4k
3 votes

Evaluate docstring in macros

(defun foo () (:documentation (concat "does a, then " (getenv "<some-shell-variable>") " , then c")) ...BODY...) This is effectively a duplicate of Is it ...
phils's user avatar
  • 51.5k
3 votes

How can I record where a function is defined if it's done indirectly?

I think, you can do one of two things: Define your own type to search for via find-func.el. This is how it's done in ert.el (Search for current-load-list and find-function-regexp-alist.) But I don't ...
politza's user avatar
  • 3,346
2 votes

How can I disable indentation rules within docstrings in python-mode?

Is there any way I can advise python-mode to ignore indentation rules within docstrings? Yes, in Emacs 25.1 or greater (before that python-indent-context didn't distinguish string from docstring). ...
npostavs's user avatar
  • 9,203
2 votes
Accepted

Lisp Mode Documentation Syntax color change?

(This applies to Emacs generally. Dunno whether Doom overrides something and requires you to customize faces differently.) Put your cursor on the doc string, and use C-u C-x =. That will show you the *...
Drew's user avatar
  • 77.9k
1 vote
Accepted

Appending to function documentation

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 ...
Fran Burstall's user avatar
1 vote
Accepted

Minor Mode / Description

The syntax of constructs like defun and define-minor-mode requires that a string literal is used. If you want to generate the doc string programmatically, you can use (at least) two methods: Create ...
Lindydancer's user avatar
  • 6,170
1 vote
Accepted

python-docstring-fill does not align properly

As @nega refers following issue solves the problem I was having: Broken formatting with new python.el (0.28). The Fix and the patch that solves it could be seen here: https://github.com/glyph/python-...
alper's user avatar
  • 1,380
1 vote
Accepted

Evaluate docstring in macros

You can set the doc string of any function, variable, or face to any string you want, whether (generated dynamically or not). For a function foo, put the string you want on symbol foo as the value of ...
Drew's user avatar
  • 77.9k
1 vote

(Company) Doc Buffer ignoring scroll-other-window

I finally figured out the culprit: company-quickhelp-mode was enabled in my setup which evidently triggered the doc-buffer all the time to reload. After disabling, everything works as expected. I'll ...
knusprjg's user avatar
1 vote
Accepted

`which-key` or similar, to show doc strings of commands bound to keys?

If you use Icicles then you have key completion. This is similar to which-key behavior, but there are differences. You can use key completion anytime, whether you have already pressed a prefix key ...
Drew's user avatar
  • 77.9k
1 vote

How to evaluate a defun with square brackets in column 0 of its docstring?

AFAIU fixing this would require a hack around of SPECPDL_INDEX in C-source. However, ar-backward-defun,ar-forward-defun jumps to start and end of a defun also in these cases: https://github.com/...
Andreas Röhler's user avatar
1 vote
Accepted

How can I define the syntax of a C-defined function with with module_make_function?

The use of (fn ARGS) syntax is described in (elisp) Function Documentation: The last line of the documentation string can specify calling conventions different from the actual function arguments. ...
npostavs's user avatar
  • 9,203

Only top scored, non community-wiki answers of a minimum length are eligible