emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: David Cao <duhpster@gmail.com>
To: John Kitchin <jkitchin@andrew.cmu.edu>
Cc: emacs-orgmode@gnu.org
Subject: Re: Special alignment in org-mode
Date: Fri, 29 Apr 2016 02:24:07 +0000	[thread overview]
Message-ID: <CADvADoV9ihndYFptDuRaM3W=TURNFYTjJi4EjRHsn8xwQgVUvg@mail.gmail.com> (raw)
In-Reply-To: <m27ffhaaz5.fsf@Johns-MacBook-Air.local>

[-- Attachment #1: Type: text/plain, Size: 3310 bytes --]

Alright, I will try this solution out. Thanks for the advice!

On Thu, Apr 28, 2016 at 10:40 AM John Kitchin <jkitchin@andrew.cmu.edu>
wrote:

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

[-- Attachment #2: Type: text/html, Size: 4924 bytes --]

      reply	other threads:[~2016-04-29  2:24 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
2016-04-29  2:24       ` David Cao [this message]

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='CADvADoV9ihndYFptDuRaM3W=TURNFYTjJi4EjRHsn8xwQgVUvg@mail.gmail.com' \
    --to=duhpster@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=jkitchin@andrew.cmu.edu \
    /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).