emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "David Lukeš" <dafydd.lukes@gmail.com>
To: emacs-orgmode@gnu.org
Subject: org-indent-indentation-per-level may be broken
Date: Wed, 11 Aug 2021 10:48:04 +0200	[thread overview]
Message-ID: <CAEPTPEzp2d6AUJ_NCoqTy7X_twoDHOFgPBvBcaPGt_hMNbg7Nw@mail.gmail.com> (raw)

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).

[1]: https://www.reddit.com/r/emacs/comments/97naje/what_is_everyones_org_mode_indentation_preferences/e4a6qqt?utm_source=share&utm_medium=web2x&context=3

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)
  org-indent--compute-prefixes()
  org-indent-mode(toggle)
  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"
"org-indent-m")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

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
         n
         (org-add-props
         (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 @
/Users/david/.emacs.d/elpa/org-20210809/)

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

Best,

David


             reply	other threads:[~2021-08-11  8:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-11  8:48 David Lukeš [this message]
2021-08-11 10:31 ` org-indent-indentation-per-level may be broken David Lukeš
2021-08-31 13:49   ` Timothy
2021-08-31 15:24     ` David Lukeš
2021-08-31 15:30       ` Timothy
2021-08-31 22:50         ` David Lukeš

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEPTPEzp2d6AUJ_NCoqTy7X_twoDHOFgPBvBcaPGt_hMNbg7Nw@mail.gmail.com \
    --to=dafydd.lukes@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).