2

I am an Emacs (and Stack Exchange) newbie, but I think I did my reading. I don't know why Emacs shows an inconsistent indentation in documents longer than one screen. My relevant settings are:

(setq org-hide-leading-stars nil)
(setq org-startup-folded 0)
(setq org-startup-indented t)
(setq org-adapt-indentation nil)
(add-hook 'org-mode-hook (lambda () (electric-indent-mode -1)))
(add-hook 'org-mode-hook 'visual-line-mode)
(add-hook 'org-mode-hook 'adaptive-wrap-prefix-mode)

I use vanilla Emacs with a minimal (~100 lines) config. It seems that the indentation looks correct on the page which is visible when I load org-mode, but incorrect on other pages. When I use PgDn or PgUp to get to those pages, the incorrect indentation is revealed. If I change to text-mode and back to org-mode, the indentation will be okay on the screen I currently see.

I would like to have indentation like in the top paragraph, not that strange first-line indentation in the bottom paragraph. Is it possible to fix this? Thanks for any help!

SOLUTION: I had this problem with Emacs 26, but an upgrade to Emacs 28 solved everything.

Screenshot of the problem

1 Answer 1

0

Turn on visual-line-mode.

According to info entry

Org Indent mode also sets wrap-prefix correctly for indenting and wrapping long lines of headlines or text. This minor mode also handles Visual Line mode and directly applied settings through word-wrap.


The Org Ind in your mode-line is the give away ... Try turning org-indent-mode OFF.

org-indent-mode is an autoloaded interactive Lisp function in org-indent.el.


(org-indent-mode &optional ARG)

When active, indent text according to outline structure.

Internally this works by adding line-prefix and wrap-prefix properties, after each buffer modification, on the modified zone.

The process is synchronous. Though, initial indentation of buffer, which can take a few seconds on large buffers, is done during idle time.

This is a minor mode. If called interactively, toggle the Org-Indent mode mode. If the prefix argument is positive, enable the mode, and if it is zero or negative, disable the mode.

If called from Lisp, toggle the mode if ARG is toggle. Enable the mode if ARG is nil, omitted, or is a positive number. Disable the mode if ARG is a negative number.

To check whether the minor mode is enabled in the current buffer, evaluate org-indent-mode.

The mode`s hook is called both when the mode is enabled and when it is disabled.


From

(info "(org) Org Indent Mode")

or

16.4.1 Org Indent Mode | Emacs Docs

17.4.1 Org Indent Mode

To display the buffer in the indented view, activate Org Indent minor mode, using ``M-x org-indent-mode. Text lines that are not headlines are prefixed with virtual spaces to vertically align with the headline text(1).

(1) Org Indent mode also sets wrap-prefix correctly for indenting and wrapping long lines of headlines or text. This minor mode also handles Visual Line mode and directly applied settings through word-wrap.

To make more horizontal space, the headlines are shifted by two characters. Configure org-indent-indentation-per-level variable for a different number.

By default, Org Indent mode turns off org-adapt-indentation and does hide leading stars by locally setting org-hide-leading-stars to t: only one star on each headline is visible, the rest are masked with the same font color as the background. If you want to customize this default behavior, see org-indent-mode-turns-on-hiding-stars and org-indent-mode-turns-off-org-adapt-indentation.

To globally turn on Org Indent mode for all files, customize the variable org-startup-indented. To control it for individual files, use STARTUP keyword as follows:

 #+`STARTUP`: indent
 #+`STARTUP`: noindent
4
  • Thanks! I think I wasn't clear. I like the indentation. I would like the contents of lower-level headings to be more indented on display (but not in the file, hence org-indent-mode and not org-adapt-indentation). And it works. If I type, Org indents everything nicely as seen on the top paragraph. The bottom paragraph, however, has a first-line-indent, but its second line is not indented. What might be the reason for this? Oct 19, 2022 at 9:23
  • Please update your question. I have updated the answer. See the first few paragraphs of emacs.stackexchange.com/a/74158/31220
    – user31220
    Oct 19, 2022 at 12:05
  • I apologize for the trouble, but I have read these things before and I think I understand them. As you can see from the question, visual-line-mode is currently enabled in my Emacs config. But why is the paragraph after the first heading correctly indented, and the second one not? If you are wondering: the file itself does not contain any hard indentation, and the error appears in all files. Oct 19, 2022 at 14:07
  • The solution was quite simple. I am using Ubuntu GNU/Linux, and it only had Emacs 26.3. After installing 28.2 from Snap, the Org indentation behavior suddenly became flawless. So it seems I stepped on a long-repaired bug. Thanks! Oct 19, 2022 at 21:01

Your Answer

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

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