I want this: ** This is a heading This is a logical line. But, because I have visual-line-mode on, lines will wrap at the edge, as is just and godly. But, such elegant formatting as you see here is but a fleeting fantasy. Various indentation schemes in my Emacs Org-mode installation compete for dominance, so even though my org-mode text looks like this when I’m first typing a file, if I do any kind of function on the subtree, like opening, closing, promoting, etc., or reload the buffer, I’m left with text formatted like the following abomination:

No matter what I try, I get this: ** This is a heading This is Tina’s cruel Emacs installation, which, no matter what combination of settings and minor-modes she tries, will constantly attempt to indent visual lines as well as logical lines, which makes sense for programming but is an absolute eyesore when dealing with long stretches of text. She wants to have only logical lines indented in org-mode, preferably in the text itself but she will settle for having it happen at display-time. But, I steadfastly prevent her from doing this, because I enjoy taunting her with visions of what could be and never will. BWA HA HA HA HAAAA

Seriously, how do I do this? Ordinarily I’m using org-indent-mode, but I’ve tried turning that off and relying on the org-adapt-indentation, I’ve tried using adaptive-wrap-prefix-mode, I’ve tried using aggressive-indent-mode (which doesn’t even seem to work with org-mode)… nothing produces the desired behavior. I’ve looked into other StackExchange questions, even: this one specifically relates to org-export, not editing while in org-mode, while this person seems to want the opposite of what I want (I think? It’s not clear). I just want to know how to get the behavior above: logical lines are automatically indented (preferably by adding spaces in the file itself) to the heading level, while wrapped visual lines are not. (I can get close to this behavior if I have other indenting modes turned off and org-adapt-indentation set to t, but it’s not automatic, which is a dealbreaker.)


  • Your description is a little hard to follow, but I can't reproduce this with emacs -Q, emacs version 27.0.50. Does the problem persist with emacs -Q? If not, then work through your config to find the source of the problem. For hints see: emacs.stackexchange.com/questions/28429/…
    – Tyler
    Commented Oct 24, 2018 at 19:29
  • regarding your last remark: would it help to set up things with an ordinary hook?
    – jue
    Commented Oct 24, 2018 at 19:29
  • I suppose I could use a hook, but which hook would I use? What function should I add to it? Commented Oct 25, 2018 at 16:33
  • Turn off org-indent-mode, turn on visual-line-mode and indent using TAB perhaps?
    – NickD
    Commented Oct 26, 2018 at 20:05
  • Tyler: I don’t think you understand what I’m saying. Running Emacs with no settings would result in no auto-indentation at all, right? What I want is to know the combination of settings that will result in the auto-indentation style i want. Commented Oct 28, 2018 at 2:28

1 Answer 1


I figured out how to do this. The relevant function is in org-indent.el, line 287:

(defun org-indent-set-line-properties (level indentation &optional heading)
  "Set prefix properties on current line an move to next one.

LEVEL is the current level of heading.  INDENTATION is the
expected indentation when wrapping line.

When optional argument HEADING is non-nil, assume line is at
a heading.  Moreover, if is is `inlinetask', the first star will
have `org-warning' face."
  (let* ((line (aref (pcase heading
               (`nil org-indent--text-line-prefixes)
               (`inlinetask org-indent--inlinetask-line-prefixes)
               (_ org-indent--heading-line-prefixes))
          (concat line
              (if heading (concat (make-string level ?*) " ")
            (make-string indentation ?\s)))
          nil 'face 'org-indent)))
    ;; Add properties down to the next line to indent empty lines.
    (add-text-properties (line-beginning-position) (line-beginning-position 2)
             `(line-prefix ,line wrap-prefix ,wrap)))

So I put the following advice in my init file:

(define-advice org-indent-set-line-properties (:override (level indentation &optional heading) sensible-indentation)
  (let* ((line (aref (pcase heading
               (`nil org-indent--text-line-prefixes)
               (`inlinetask org-indent--inlinetask-line-prefixes)
               (_ org-indent--heading-line-prefixes))
    ;; Add properties down to the next line to indent empty lines.
    (add-text-properties (line-beginning-position) (line-beginning-position 2)
             `(line-prefix ,line)))

All it took was removing the part that sets wrap-prefix (and the associated local variable). Now I have my preferred indentation style!

Your Answer

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

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