On 17.3.2011, at 07:20, Le Wang wrote:

> On Thu, Mar 17, 2011 at 12:27 AM, Le Wang <l26w...@gmail.com> wrote:
> Yes, I didn't know about `org-reveal'.  That could work.  But how do I figure 
> out if I need to expand the heading?  The last change could be to a folded 
> heading itself, in which case, it shouldn't be expanded.
> 
> Is there a org-goto-char type of function that always goes to that location 
> in the buffer, expanding sections along the way?
> 
> I've solved it by advising goto-char like so:
> 
> (defadvice goto-char (around org-expand activate compile)
>   (if (eq major-mode 'org-mode)
>       (progn
>         ad-do-it
>         (org-reveal)
>         ad-do-it)
>     ad-do-it))
>  
> Can anyone see any problems with advising such a fundamental function?

Yes, this is certainly a very bad idea.  goto-char is used many times in lisp 
programs, also in Org, so executing normal Org functions will be slowed down 
and reveal parts that should not be revealed.

Instead you should be advising session-jump-to-last-change itself.
If you do not want to expand a full entry if the change was in 
a headline, you can check for invisibility:


(defadvice session-jump-to-last-change (after org-expand activate compile)
  "Reveal hidden point after jumping."
  (when (and (eq major-mode 'org-mode)
             (outline-invisible-p))
    (org-reveal)))

HTH

- Carsten

Reply via email to