[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

org-indent-indentation-per-level may be broken

From: David Lukeš
Subject: org-indent-indentation-per-level may be broken
Date: Wed, 11 Aug 2021 10:48:04 +0200

Hi all,

I'd like to use visual-line-mode to soft-wrap lines in Org files, while
keeping continuation lines in list items properly indented:

- long line that goes on to the edge of the screen and soft wraps
  like I want it to

Instead of this:

- long line that goes on to the edge of the screen and soft wraps
like I *don't* want it to

I figured it should be possible to achieve this with org-indent-mode.
However, that mode also adds visual pre-indentation for each heading
level, which I'd rather avoid, I'd like the content under the headings
to start flush with the left margin. So the overall result should look
like this:

* Heading
- long line that goes on to the edge of the screen and soft wraps
  like I want it to

Not like this:

* Heading
  - long line that goes on to the edge of the screen and soft wraps
    like I want it to

I thought I could achieve this by setting
org-indent-indentation-per-level to 0, and historically, people seem to
have been able to use it for this purpose [1] (if I understand the
comment correctly).


However, when I set the option to 0 and start org-indent-mode, I
currently get the following error:

Debugger entered--Lisp error: (wrong-type-argument wholenump -1)
  make-string(-1 42)
  funcall-interactively(org-indent-mode toggle)
  call-interactively(org-indent-mode record nil)
  command-execute(org-indent-mode record)
  execute-extended-command(nil "org-indent-mode" "org-indent-m")
  funcall-interactively(execute-extended-command nil "org-indent-mode"
  call-interactively(execute-extended-command nil nil)

So it seems like the logic that computes the actual indentation based on
org-indent-indentation-per-level is broken? And maybe in more than one
way, because when I set it to e.g. 5, I would expect the amount of
indentation when I run org-indent-mode to increase appropriately, but it
doesn't, it's the same as with the default value of 2.

FWIW, I can avoid the error and get the effect that I was originally
looking for by applying the following patch:

--- a/org-indent.el    2021-08-11 09:30:45.000000000 +0200
+++ b/org-indent.el    2021-08-11 10:45:13.000000000 +0200
@@ -130,8 +130,9 @@
     (make-vector org-indent--deepest-level nil))
   (dotimes (n org-indent--deepest-level)
     (let ((indentation (if (<= n 1) 0
+             (max 0
              (* (1- org-indent-indentation-per-level)
-                (1- n)))))
+                (1- n))))))
       ;; Headlines line prefixes.
       (let ((heading-prefix (make-string indentation ?*)))
     (aset org-indent--heading-line-prefixes
@@ -146,13 +147,14 @@
                  (substring heading-prefix 1)))
             (t (org-add-props heading-prefix nil 'face 'org-indent)))))
       ;; Text line prefixes.
+      (if (> org-indent-indentation-per-level 0)
       (aset org-indent--text-line-prefixes
         (concat (make-string (+ n indentation) ?\s)
             (and (> n 0)
                  (char-to-string org-indent-boundary-char)))
-        nil 'face 'org-indent)))))
+        nil 'face 'org-indent))))))

 (defsubst org-indent-remove-properties (beg end)
   "Remove indentations between BEG and END."

But that's just a workaround for my particular case, setting
org-indent-indentation-per-level to values greater than 2 still has no
discernible effect after these changes.

Here are the contents of the init.el file I'm testing this with:

(setq org-indent-indentation-per-level 0
      org-adapt-indentation nil
      debug-on-error t)
(global-visual-line-mode 1)

And here's my version info:

GNU Emacs 27.2 (build 1, aarch64-apple-darwin20.3.0, Carbon Version
164 AppKit 2022.3) of 2021-06-11
Org mode version 9.4.6 (9.4.6-12-gdcc3a8-elpa @

(Please let me know if I should provide some more!)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]