From: John Kitchin <jkitchin@andrew.cmu.edu>
To: David Cao <duhpster@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Special alignment in org-mode
Date: Thu, 28 Apr 2016 13:39:58 -0400 [thread overview]
Message-ID: <m27ffhaaz5.fsf@Johns-MacBook-Air.local> (raw)
In-Reply-To: <CADvADoWg9THGqpUmUgFbVXYdSdejCQjmwTMaBT7kEmx1bW_AzA@mail.gmail.com>
In this case though you probably want to specify a fixed
column, and consider using something like indent-rigidly on the heading
body so you don't have an overlay on every single line.
David Cao writes:
> Hi!
>
> 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?
>
> David
>
> On Wed, Apr 27, 2016 at 9:47 AM John Kitchin <jkitchin@andrew.cmu.edu>
> 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)
>> depth)
>> (org-map-entries (lambda ()
>> (when (> (setq depth (car
>> (org-heading-components))) max-depth)
>> (setq max-depth depth))))
>> max-depth))
>>
>>
>> (defun org-right-align-overlay ()
>> "Put an overlay on headline * to right align to maximum depth.
>> Should be run while on the headline."
>> (interactive)
>> (let* ((diff (- (org-max-heading-depth) (car (org-heading-components))))
>> ov)
>> (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 ()
>> (interactive)
>> (ov-clear 'right-align))
>>
>> (defun align-matcher (&optional limit)
>> (while (re-search-forward org-heading-regexp limit t)
>> (org-right-align-overlay)))
>>
>> (add-to-list 'org-font-lock-hook 'align-matcher)
>> #+END_SRC
>>
>> 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
>> 412-268-7803
>> @johnkitchin
>> http://kitchingroup.cheme.cmu.edu
>>
--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
next prev parent reply other threads:[~2016-04-28 17:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-27 5:01 Special alignment in org-mode David Cao
2016-04-27 16:47 ` John Kitchin
2016-04-28 2:56 ` David Cao
2016-04-28 17:34 ` Georgiy Tugai
2016-04-28 17:39 ` John Kitchin [this message]
2016-04-29 2:24 ` David Cao
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=m27ffhaaz5.fsf@Johns-MacBook-Air.local \
--to=jkitchin@andrew.cmu.edu \
--cc=duhpster@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).