1

enter image description here

When I'm writing docstrings in elisp, only the second line from docstring starts from beginning of the line (because I press C-j after first line to be nice in apropos buffer) , the next lines starts with tab space from auto-fill-mode. I saw Emacs builtin files and only first line from docstring has tab space, the others start with no space.

The buffer has auto-fill-mode on and fill-column variable set to 70.

How can I change the behavior of auto-fill so that it doesn't indent the second and subsequent lines?

enter image description here

EDIT: the problem is not only with docstring. I made a docstring without C-j, and two free text, not code. It aligns next lines with the first line in elisp buffers.

10
  • 1
    This must be something else in your configuration or an installed package causing this. I can't reproduce it running emacs -Q, with or without auto-fill-mode enabled. 70 is the default value for fill-column, so that's also the same. Commented Jun 12 at 0:58
  • Yes 70 is default value, auto-fill-mode breaks the line correctly but the next line start with tab, but only in docstrings, simple text is written correctly. Commented Jun 12 at 12:33
  • The comment at the top seems to say that you are typing this into the *scratch* buffer. Are you? That buffer is in lisp-interaction mode which interprets C-j differently than most other buffers. Please specify the mode of the buffer that you are typing this in. Commented Jun 12 at 13:05
  • No, The docstrings are the same in any buffer. I typed it in scratch buffer because it was opened at that moment and I wanted to not lose time. It moves the cursor at the start of next line in scratch in docstrings. Commented Jun 12 at 13:21
  • In scratch is "Lisp Interaction mode defined in 'elisp-mode.el'. In non scratch buffer is "Emacs-Lisp mode defined in 'elisp-mode.el". But the problem is in any elisp buffer. Commented Jun 12 at 13:33

1 Answer 1

1

The prefix can be customized using the variable adaptive-fill-function. The value of this is ignore by default (a function that does nothing, throws away any arguments and returns nil), but modes can set it to an arbitrary function that will calculate the prefix. In lisp-mode, this variable has the value lisp-adaptive-fill which is a one-line function:

(defun lisp-adaptive-fill () "Return fill prefix found at point. Value for `adaptive-fill-function'." ;; Adaptive fill mode gets the fill wrong for a one-line paragraph made of ;; a single docstring. Let's fix it here. (if (looking-at "\\s-+\"[^\n\"]+\"\\s-*$") "")) 

This makes sure that the prefix is the empty string in the case described: a one-line paragraph consisting of a single docstring.

So you can expand the range of applicability of this function: make it return the empty string in all cases:

(defun my/lisp-adaptive-fill () "Return the empty string as the adaptive fill prefix in all cases, not just in the one-line paragraph made of a single docstring case." "") (setq adaptive-fill-function #'my/lisp-adaptive-fill) 

Try this and let me know if you run into problems. I've tested it a bit but it is quite conceivable that it breaks something that I have not tested.

1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.