Subject: bug#57441: indent-according-to-mode indents incorrectly if previous line is blank

From: Lojze Gačnik <[email-masked]>
Date: Fri, 26 Aug 2022 22:58:41 +0000

The documentation of indent-according-to-mode claims that, if
indent-line-function is set to indent-relative-first-indent-point, it
will indent the line the same as the previous non-blank line.

But this is not the case - it only works if the immediately preceding
line is non-blank. If line 1 is indented 4 spaces, and line 2 is
blank, then indent-according-to-mode on line 3 will indent 0 spaces,
instead of the expected 4.

Calling indent-according-to-line on line 2, or calling
indent-relative-first-indent-point directly on line 2 or 3, behaves
correctly.

I reproduced this issue on emacs 29.0.50, using the following init.el file:

(electric-indent-mode -1)
(defun my/plain-indent ()
  (setq indent-line-function 'indent-relative-first-indent-point))
; Have to set it in a hook, otherwise it gets overrriden.
(add-hook 'prog-mode-hook 'my/plain-indent)
(add-hook 'text-mode-hook 'my/plain-indent)