From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Cao Subject: Re: Special alignment in org-mode Date: Fri, 29 Apr 2016 02:24:07 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1136a7f0ee9ac705319656c6 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46239) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avy6N-0000ak-CT for emacs-orgmode@gnu.org; Thu, 28 Apr 2016 22:24:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avy6L-0005lR-TG for emacs-orgmode@gnu.org; Thu, 28 Apr 2016 22:24:19 -0400 Received: from mail-ob0-x229.google.com ([2607:f8b0:4003:c01::229]:34793) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avy6L-0005lK-NY for emacs-orgmode@gnu.org; Thu, 28 Apr 2016 22:24:17 -0400 Received: by mail-ob0-x229.google.com with SMTP id bg3so48737520obb.1 for ; Thu, 28 Apr 2016 19:24:17 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: John Kitchin Cc: emacs-orgmode@gnu.org --001a1136a7f0ee9ac705319656c6 Content-Type: text/plain; charset=UTF-8 Alright, I will try this solution out. Thanks for the advice! On Thu, Apr 28, 2016 at 10:40 AM John Kitchin 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 > > 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 > --001a1136a7f0ee9ac705319656c6 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Alright, I will try this solution out. Th= anks for the advice!

<= div dir=3D"ltr">On Thu, Apr 28, 2016 at 10:40 AM John Kitchin <jkitchin@andrew.cmu.e= du> wrote:
In this case thou= gh 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 a= ctual
> content beneath the headers stays to the side of the buffer (as pictur= ed:
> 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 ()
>>=C2=A0 =C2=A0"Get maximum depth of a heading."
>>=C2=A0 =C2=A0(let ((max-depth 0)
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0depth)
>>=C2=A0 =C2=A0 =C2=A0(org-map-entries (lambda ()
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 (when (> (setq depth (car
>> (org-heading-components))) max-depth)
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 (setq max-depth depth))))
>>=C2=A0 =C2=A0 =C2=A0max-depth))
>>
>>
>> (defun org-right-align-overlay ()
>>=C2=A0 =C2=A0"Put an overlay on headline * to right align to m= aximum depth.
>> Should be run while on the headline."
>>=C2=A0 =C2=A0(interactive)
>>=C2=A0 =C2=A0(let* ((diff (- (org-max-heading-depth) (car (org-head= ing-components))))
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ov)
>>=C2=A0 =C2=A0 =C2=A0(while (and (setq ov (ov-at (match-beginning 1)= ))
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (overlay-ge= t ov 'right-align))
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0(delete-overlay ov))
>>
>>=C2=A0 =C2=A0 =C2=A0;; (setq ov (make-overlay (line-beginning-posit= ion) (+ 1
>> (line-beginning-position))))
>>=C2=A0 =C2=A0 =C2=A0(setq ov (make-overlay (match-beginning 1) (+ 1= (match-beginning 1))))
>>=C2=A0 =C2=A0 =C2=A0(overlay-put ov 'before-string (make-string= diff ? ))
>>=C2=A0 =C2=A0 =C2=A0(overlay-put ov 'right-align t)))
>>
>> (defun org-right-align-clear ()
>>=C2=A0 =C2=A0(interactive)
>>=C2=A0 =C2=A0(ov-clear 'right-align))
>>
>> (defun align-matcher (&optional limit)
>>=C2=A0 =C2=A0(while (re-search-forward org-heading-regexp limit t)<= br> >>=C2=A0 =C2=A0 =C2=A0(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 cons= tant,
>> 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:
>> >
>> >=C2=A0 =C2=A0* My fancy org file
>> >=C2=A0 ** Header 2
>> >=C2=A0 =C2=A0 =C2=A0Some 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
--001a1136a7f0ee9ac705319656c6--