emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using `save-window-excursion' instead of `save-excursion' for `comme


From: Aaron Ecay
Subject: Re: Using `save-window-excursion' instead of `save-excursion' for `comment-region'?
Date: Thu, 05 Dec 2013 14:05:37 -0500
User-agent: Notmuch/0.16+154~g96c0ce2 (http://notmuchmail.org) Emacs/24.3.50.1 (x86_64-unknown-linux-gnu)

2013ko abenudak 5an, Bastien-ek idatzi zuen:
> 
> This is how it works:
> 
> comment-region calls comment-region-function within save-excursion
> (assuming there is no window change.)
> 
> comment-region-function calls org-babel-do-in-edit-buffer which
> inserts the source code in another buffer, then calls back again
> comment-region with comment-region-function bound to the correct
> mode-dependent function.
> 
> The "outward" comment-region does not restore the point position
> correctly.
> 
> So I'm not sure why save-window-excursion would only works "by
> accident" here.  I cannot think of a better fix right now, I'll
> continue to travel through the Babel maze.

I think the problem is that org-babel-do-in-edit-buffer deletes the
whole contents of the source code block, and re-inserts it.  This means
that the marker that save-excursion uses (pointing to somewhere in the
deleted and re-inserted span) no longer points to the desired position,
but rather to just before the span.

Org babel has its own point-restoration functionality (which works by
counting lines and columns), but this is executed inside of the scope of
comment-region’s save-excursion, so exiting the latter restores the
point to a bogus position (from the POV of the user).

-- 
Aaron Ecay



reply via email to

[Prev in Thread] Current Thread [Next in Thread]