0

I posted this question on stackoverflow earlier, but perhaps this is a better place for it?

I am looking for a way to left-align text in Org-mode so that the paragraphs line up like in FoldingText. Here is an example:

  * Headline number 1
 ** Headline number 2 [0/2]

    Here is some text
    before our first unordered list:

  - List item 1
  - List item 2

    And here is a checklist:

  - [ ] Do this first
  - [ ] Do this next

 ** Headline number 4

I've tried using align-regexp but I am having trouble figuring the correct regex string... any ideas?

Here's an update

I got this working with the following code:

(defun align-ft (p1 p2)
  "Align outlines like FoldingText"
  (interactive "r")
  (align-regexp p1 p2 "\\(^\\*+\\s-\\|^-\\s-\\|^\\)." -1 0 nil)
)

The only problem is that it aligns text by adding spaces, and I don't want spaces hard-coded into the document. I just want it to display, as if the spaces were there (like in org-indent-mode). Also, this code requires the region to be highlighted and ultimately, I just want it to auto-align the entire document, as I type.

Any ideas?

5
  • Looks like an xy problem.. may be you need to just enable org-indent-mode? Or are you aware of that, and that's not what you need? On top on that, may be (setq org-hide-leading-stars t)? Commented Jul 25, 2016 at 20:57
  • Thanks. I'm using org-indent-mode now. But this gives me more of an outline view. What I would like to find is a way to shift all the markup characters (stars and hyphens) into the margin area, so that the text stays nicely aligned.
    – Adam
    Commented Jul 25, 2016 at 21:13
  • I don't think this exists. It will probably be non-trivial and will require rewriting the org indent functions.
    – Dan
    Commented Jul 26, 2016 at 2:25
  • I'm pretty sure that this can be done with align-regexp. What I'm looking for is the regular expression to identify the delimiters.
    – Adam
    Commented Jul 26, 2016 at 10:17
  • 2
    The alignment could be done with align-regexp, but this will almost certainly break those parts of org that expect headlines stars (*) to start at the left margin, not at a variable number of spaces in from the margin. Given how fundamental headlines are, that's probably most of org mode.
    – Tyler
    Commented Mar 24, 2017 at 15:23

1 Answer 1

0

org-indent-mode adds the line-prefix and wrap-prefix special text properties. I'm not sure it's worth the hassle, but if you want to align your org buffer the desired way once, this may be for you:

(save-excursion
  (goto-char (point-min))
  (while (not (eobp))
    (let ((ind (make-string
                (- 4 (if (org-at-heading-p)
                         (org-current-level)
                       -1))
                ?\s)))
      (add-text-properties (point-at-bol) (point-at-eol)
                           `(line-prefix ,ind wrap-prefix ,ind)))
    (forward-line)))

Obviously you should deactivate org-indent-mode before.

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.