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: Bastien
Subject: Re: Using `save-window-excursion' instead of `save-excursion' for `comment-region'?
Date: Thu, 05 Dec 2013 19:43:59 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> In Org buffer, you can comment code within source blocks.  This opens
>> a new buffer, insert the code there, comment it, and insert the buffer
>> contents back into Org's buffer.
>
>> With the current `comment-region' function, point is lost when Org
>> goes back to the org buffer.  Using `save-window-excursion' instead
>> of `save-excursion' fixes the problem.
>
> I'm not sure exactly what means "point is lost" in this case, but if
> using save-window-excursion solves the problem, it's only by
> accident.

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.

-- 
 Bastien



reply via email to

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