13

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)))


12

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 () ,(format "Function which sums foo=%s and bar=%s" foo bar) (+ foo bar))) Why you want a docstring on an anonymous function is another question, which might ...


11

If the goal is to get information about functions and variables already in the environment: For docstrings of functions and macros, see the documentation function. For variable docstrings, use documentation-property; for example: (documentation-property 'user-init-file 'variable-documentation) For function arity and the argument list, see this Emacs.SE ...


10

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 in first line of the printed version of the string. The newline at the end of the first line of the string is part of the string. If you would add indentation ...


9

I use the package called yasnippet for something similar to this. After some minor changes I adapted it to use the the Google docstring style instead: Do note however that it requires some setup: The snippet itself needs to execute some utility elisp code to generate the text. This is typically solved by creating a file called .yas-setup.el with the code ...


7

Of course a my-defun macro is the easy way out. But a simpler solution would be (advice-add 'eval-when-compile :filter-return (lambda (exp) (if (and (eq 'quote (car-safe exp)) (stringp (cadr exp))) (cadr exp) exp))) Which should make your trick work, at least in all the ...


6

You could use a macro like this: (defmacro my-defun (name arglist &rest forms) "Like `defun', but concatenates strings." (declare (indent defun)) (let (doc-lines) (while (and (stringp (car-safe forms)) (> (length forms) 1)) (setq doc-lines (append doc-lines (list (pop forms))))) `(defun ,name ,arglist ...


6

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 that it can be generated on-demand. If FUNCTION is a symbol, this function first looks for the ‘function-documentation’ property of that symbol; if that has ...


6

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."). The following example shows you how you can exchange the first line of the documentation string: (defun change-description-line (symbol new-description) "...


4

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 when you need to ensure that quotes are not converted, you have to use an escaping syntax: (defun foo () "Something about \\='foo") Will ensure that, ...


4

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 description of the user option text-quoting-style: text-quoting-style is a variable defined in ‘doc.c’. Its value is nil Probably introduced at or before Emacs ...


4

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 deleted the overlay passively through a hook instead of waiting for an exit-char, which doesn't seem appropriate for what you are trying to do. The display ...


3

There are two issues here. On the one hand, when a function is called, the arguments are evaluated first. But when you evaluate a macro, the arguments are not evaluated. Instead, they are used to expand the macro into a form, which is subsequently evaluated. On the other hand, a form is just a single lisp object that is going to be evaluated, while a body ...


3

As lunaryorn mentioned that style is not popular and there aren't any packages. However there is a package called sphinx-doc which will generate doc string in sphinx format(demo). You can modify that package to generate strings as per your requirement.


3

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 think that this will work with help-mode buffers, i.e. no linkage. Or extend find-function-regexp: Ordinarily this variable evaluates to a regexp to search ...


2

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). Indentation works by setting indent-line-function to a mode-specific value: indent-line-function is a variable defined in ‘indent.el’. Its value is ‘python-...


1

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 try to solve this issue also with company-quickhelp and add my results here later.


1

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 or not. To initiate key completion just hit S-TAB (or M-S-TAB if in the minibuffer) when you are not otherwise in the middle of completing something. (When you ...


1

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-roehler/thingatpt-utils-core/blob/master/ar-subr.el Wherefrom a command to escape opening parens in column 0 might be provided: (defun ar-auto-escape () (...


1

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. Write text like this: \(fn ARGLIST) following a blank line, at the beginning of the line, with no newline following it inside the documentation string. ...


1

One way to disambiguate: (defun foo-all-the-bars () "Foo all the bars. Starts by fooing some bars by enabling the command `prettify-symbols-mode', then manually foos any remaining bars." (prettify-symbols-mode)) Instead of command, you can use function, variable, option, or symbol as the checkdoc string suggests. In any case, this is not a lisp ...


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