all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Showing hidden subtree automatically if point is hidden when the buffer is opened
@ 2009-07-27 14:00 User
  2009-07-27 20:45 ` Bastien
  0 siblings, 1 reply; 8+ messages in thread
From: User @ 2009-07-27 14:00 UTC (permalink / raw)
  To: emacs-orgmode

I use folded view by default, but I also use saveplace.el,
because it's nice to continue from the point I left off in the
buffer, instead of navigating there again manually.

The problem is the restored point can be in an automatically
folded section when the buffer is opened, so I added this little
code to my org-mode hook which opens the subtree automatically if
point is hidden:

  (run-with-idle-timer 0 nil
                       (lambda ()
                         (when (outline-invisible-p)
                           (save-excursion
                             (outline-previous-visible-heading 1)
                             (org-show-subtree)))))

I haven't seen an option for this in org, so I post the code
here if someone has a similar problem.

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

* Re: Showing hidden subtree automatically if point is hidden when the buffer is opened
  2009-07-27 14:00 Showing hidden subtree automatically if point is hidden when the buffer is opened User
@ 2009-07-27 20:45 ` Bastien
  2009-07-28  4:19   ` User
  0 siblings, 1 reply; 8+ messages in thread
From: Bastien @ 2009-07-27 20:45 UTC (permalink / raw)
  To: User; +Cc: emacs-orgmode

User <spamfilteraccount@gmail.com> writes:

> I use folded view by default, but I also use saveplace.el,
> because it's nice to continue from the point I left off in the
> buffer, instead of navigating there again manually.
>
> The problem is the restored point can be in an automatically
> folded section when the buffer is opened, so I added this little
> code to my org-mode hook which opens the subtree automatically if
> point is hidden:
>
>   (run-with-idle-timer 0 nil
>                        (lambda ()
>                          (when (outline-invisible-p)
>                            (save-excursion
>                              (outline-previous-visible-heading 1)
>                              (org-show-subtree)))))
>
> I haven't seen an option for this in org, so I post the code
> here if someone has a similar problem.

I added this entry on org-hacks.org (Worg):

Fix a problem with saveplace.el putting you back in a folded position: 

#+begin_src emacs-lisp
(add-hook 'org-mode-hook
          (lambda ()
	    (when (outline-invisible-p)
	      (save-excursion
		(outline-previous-visible-heading 1)
		(org-show-subtree)))))
#+end_src

Note that I removed the timer - no sure why it was useful.  Feel free to
modify this hack the way you want on Worg.

-- 
 Bastien

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

* Re: Showing hidden subtree automatically if point is hidden when the buffer is opened
  2009-07-27 20:45 ` Bastien
@ 2009-07-28  4:19   ` User
  2009-07-28 11:59     ` Bastien
  0 siblings, 1 reply; 8+ messages in thread
From: User @ 2009-07-28  4:19 UTC (permalink / raw)
  To: emacs-orgmode

Bastien <bastienguerry <at> googlemail.com> writes:
> 
> #+begin_src emacs-lisp
> (add-hook 'org-mode-hook
>           (lambda ()
> 	    (when (outline-invisible-p)
> 	      (save-excursion
> 		(outline-previous-visible-heading 1)
> 		(org-show-subtree)))))
> #+end_src
> 
> Note that I removed the timer - no sure why it was useful.  Feel free to
> modify this hack the way you want on Worg.
> 


I added the timer, because I didn't know in which order the hooks
are run. If org-mode hook runs first and then saveplace's hook
which restores point then the above code has no effect.

The null timer guarantees the code runs when all the hooks are
executed.

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

* Re: Re: Showing hidden subtree automatically if point is hidden when the buffer is opened
  2009-07-28  4:19   ` User
@ 2009-07-28 11:59     ` Bastien
  2009-07-28 18:27       ` Bastien
  0 siblings, 1 reply; 8+ messages in thread
From: Bastien @ 2009-07-28 11:59 UTC (permalink / raw)
  To: User; +Cc: emacs-orgmode

User <spamfilteraccount@gmail.com> writes:

> I added the timer, because I didn't know in which order the hooks
> are run. If org-mode hook runs first and then saveplace's hook
> which restores point then the above code has no effect.

saveplace adds the hook at the end of the hooks list, by calling
add-hook like this:

  (add-hook 'find-file-hook 'save-place-find-file-hook t)
                                                       ^

The `t' means put this hook at the end.

So your org-mode hook will be safely called *before* saveplace's.

-- 
 Bastien

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

* Re: Re: Showing hidden subtree automatically if point is hidden when the buffer is opened
  2009-07-28 11:59     ` Bastien
@ 2009-07-28 18:27       ` Bastien
  2009-07-28 18:46         ` User
  0 siblings, 1 reply; 8+ messages in thread
From: Bastien @ 2009-07-28 18:27 UTC (permalink / raw)
  To: Bastien; +Cc: User, emacs-orgmode

Bastien <bzg@gnu.org> writes:

> User <spamfilteraccount@gmail.com> writes:
>
>> I added the timer, because I didn't know in which order the hooks
>> are run. If org-mode hook runs first and then saveplace's hook
>> which restores point then the above code has no effect.
>
> saveplace adds the hook at the end of the hooks list, by calling
> add-hook like this:
>
>   (add-hook 'find-file-hook 'save-place-find-file-hook t)
>                                                        ^
>
> The `t' means put this hook at the end.
>
> So your org-mode hook will be safely called *before* saveplace's.

Sorry, I mixed up the logic here -- the following hook is okay:

--8<---------------cut here---------------start------------->8---
(add-hook 'org-mode-hook
          (lambda ()
	    (when (outline-invisible-p)
	      (save-excursion
		(outline-previous-visible-heading 1)
		(org-show-subtree))))
          t)  ;; this makes sure this hook is run last
--8<---------------cut here---------------end--------------->8---

If you load this *after* loading the saveplace hook then it should 
be okay.  Thanks to Nick Dokos for shaking my brain on this :)

-- 
 Bastien

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

* Re: Showing hidden subtree automatically if point is hidden when the buffer is opened
  2009-07-28 18:27       ` Bastien
@ 2009-07-28 18:46         ` User
       [not found]           ` <8035.1248807278@alphaville.usa.hp.com>
  2009-07-29  5:41           ` Bastien
  0 siblings, 2 replies; 8+ messages in thread
From: User @ 2009-07-28 18:46 UTC (permalink / raw)
  To: emacs-orgmode

Bastien <bastienguerry <at> googlemail.com> writes:
> 
> If you load this *after* loading the saveplace hook then it should 
> be okay.  Thanks to Nick Dokos for shaking my brain on this :)
> 

Well, wasn't my original solution with the null timer much nicer?
You didn't have to worry about making sure you put org-mode hook
last and that it loads after saveplace hook.

Now the user has to pay attention to where he sets
up the org-mode hook, instead of simply pasting the code
anywhere in .emacs. :-o I tend to favor solutions which avoid
such potential problems. :)

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

* Re: Re: Showing hidden subtree automatically if point is hidden when the buffer is opened
       [not found]             ` <9cf79dfd0907281208r7e43fdfbn17af4d9e521e6fc8@mail.gmail.com>
@ 2009-07-28 19:18               ` Nick Dokos
  0 siblings, 0 replies; 8+ messages in thread
From: Nick Dokos @ 2009-07-28 19:18 UTC (permalink / raw)
  To: PT (emacs user); +Cc: emacs-orgmode

PT (emacs user) <spamfilteraccount@gmail.com> wrote:

> On Tue, Jul 28, 2009 at 8:54 PM, Nick Dokos<nicholas.dokos@hp.com> wrote:
> >
> > If they don't cost anything, yes. But I'm not sure I want an idle
> > timer running all the time just to detect the (rare) occasions
> > when I want to fold a tree.
> 
> You misunderstand how it works. The idle timer doesn't run all the time.
> It's started when the org buffer is opened, it does its thing and then
> it stops running and it is disposed .
> 
> It's a one-shot timer. Doesn't cost anything.
> 

Oh, right: I didn't notice the REPEAT arg in the doc.

I still think that getting the configuration right in the first place
is "better", but I guess you have reduced it to an aesthetic choice.

Thanks,
Nick

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

* Re: Re: Showing hidden subtree automatically if point is hidden when the buffer is opened
  2009-07-28 18:46         ` User
       [not found]           ` <8035.1248807278@alphaville.usa.hp.com>
@ 2009-07-29  5:41           ` Bastien
  1 sibling, 0 replies; 8+ messages in thread
From: Bastien @ 2009-07-29  5:41 UTC (permalink / raw)
  To: User; +Cc: emacs-orgmode

User <spamfilteraccount@gmail.com> writes:

> Bastien <bastienguerry <at> googlemail.com> writes:
>> 
>> If you load this *after* loading the saveplace hook then it should 
>> be okay.  Thanks to Nick Dokos for shaking my brain on this :)
>
> Well, wasn't my original solution with the null timer much nicer?
> You didn't have to worry about making sure you put org-mode hook
> last and that it loads after saveplace hook.

Yes, but it's not straightforward to understand.  

To me, "running a task when Emacs is idle for 0 seconds" is very similar
to "run immediately" - that's why I didn't understand why you'd put this
first.

Why not checking if this run-with-idle-timer trick is necessary?  My
understanding is that org-mode hooks will be called *after* saveplace
restores the point.

(I just want to avoid unnecessary tricks for people who use Worg as a
place to learn things.)

> I tend to favor solutions which avoid such potential problems. :)

If it ain't broken, don't fix it ;)

-- 
 Bastien

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

end of thread, other threads:[~2009-07-29  5:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-27 14:00 Showing hidden subtree automatically if point is hidden when the buffer is opened User
2009-07-27 20:45 ` Bastien
2009-07-28  4:19   ` User
2009-07-28 11:59     ` Bastien
2009-07-28 18:27       ` Bastien
2009-07-28 18:46         ` User
     [not found]           ` <8035.1248807278@alphaville.usa.hp.com>
     [not found]             ` <9cf79dfd0907281208r7e43fdfbn17af4d9e521e6fc8@mail.gmail.com>
2009-07-28 19:18               ` Nick Dokos
2009-07-29  5:41           ` Bastien

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.