emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Special alignment in org-mode
@ 2016-04-27  5:01 David Cao
  2016-04-27 16:47 ` John Kitchin
  0 siblings, 1 reply; 6+ messages in thread
From: David Cao @ 2016-04-27  5:01 UTC (permalink / raw)
  To: emacs-orgmode

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

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

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Special alignment in org-mode
  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
  0 siblings, 1 reply; 6+ messages in thread
From: John Kitchin @ 2016-04-27 16:47 UTC (permalink / raw)
  To: David Cao; +Cc: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Special alignment in org-mode
  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
  0 siblings, 2 replies; 6+ messages in thread
From: David Cao @ 2016-04-28  2:56 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode

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

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
>

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Special alignment in org-mode
  2016-04-28  2:56   ` David Cao
@ 2016-04-28 17:34     ` Georgiy Tugai
  2016-04-28 17:39     ` John Kitchin
  1 sibling, 0 replies; 6+ messages in thread
From: Georgiy Tugai @ 2016-04-28 17:34 UTC (permalink / raw)
  To: emacs-orgmode

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

I believe that org-indent-mode (#+STARTUP: indent) might do what you
want with the content, although I expect that it will interfere with the
specialized overlays for right-aligning the *'s.

On 28 Apr, David Cao wrote:
> 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
> >

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Special alignment in org-mode
  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
  1 sibling, 1 reply; 6+ messages in thread
From: John Kitchin @ 2016-04-28 17:39 UTC (permalink / raw)
  To: David Cao; +Cc: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Special alignment in org-mode
  2016-04-28 17:39     ` John Kitchin
@ 2016-04-29  2:24       ` David Cao
  0 siblings, 0 replies; 6+ messages in thread
From: David Cao @ 2016-04-29  2:24 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-04-29  2:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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