[Top][All Lists]

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

Re: [O] Special alignment in org-mode

From: David Cao
Subject: Re: [O] Special alignment in org-mode
Date: Thu, 28 Apr 2016 02:56:52 +0000


This solution works fairly well with the headers themselves, but the actual content beneath the headers stays to the side of the buffer (as pictured: http://i.imgur.com/nGv8XBI.png).
Would there be any way to fix this?


On Wed, Apr 27, 2016 at 9:47 AM John Kitchin <address@hidden> wrote:
I think this does approximately what you want:

#+BEGIN_SRC emacs-lisp :results none
(require 'ov)

(defun org-max-heading-depth ()
  "Get maximum depth of a heading."
  (let ((max-depth 0)
    (org-map-entries (lambda ()
                       (when (> (setq depth (car (org-heading-components))) max-depth)
                         (setq max-depth depth))))

(defun org-right-align-overlay ()
  "Put an overlay on headline * to right align to maximum depth.
Should be run while on the headline."
  (let* ((diff (- (org-max-heading-depth) (car (org-heading-components))))
    (while (and (setq ov (ov-at (match-beginning 1)))
               (overlay-get ov 'right-align))
      (delete-overlay ov))

    ;; (setq ov (make-overlay (line-beginning-position) (+ 1 (line-beginning-position))))
    (setq ov (make-overlay (match-beginning 1) (+ 1 (match-beginning 1))))
    (overlay-put ov 'before-string (make-string diff ? ))
    (overlay-put ov 'right-align t)))

(defun org-right-align-clear ()
  (ov-clear 'right-align))

(defun align-matcher (&optional limit)
  (while (re-search-forward org-heading-regexp limit t)

(add-to-list 'org-font-lock-hook 'align-matcher)

Its only light tested, and may be slow on a long document because it is
checking the maximum depth each time. You could set this to a constant,
e.g. 8 if it is too slow.

David Cao writes:

> Hello,
> I was wondering if there is any way to right-align the header indicators
> while left-aligning the actual content. Unfortunately I haven't been able
> to find any mention of such a feature online.
> For example:
>   * My fancy org file
>  ** Header 2
>     Some content here
> *** Header 3
> Thanks in advance!
> David

Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213

reply via email to

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