From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Using `save-window-excursion' instead of `save-excursion' for `comment-region'? Date: Thu, 05 Dec 2013 14:45:29 -0500 Message-ID: References: <87y53zk3dx.fsf@bzg.ath.cx> <87ob4vuoi8.fsf@bzg.ath.cx> <87fvq7dsou.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1386272753 20863 80.91.229.3 (5 Dec 2013 19:45:53 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Dec 2013 19:45:53 +0000 (UTC) Cc: Bastien , emacs-devel@gnu.org To: Aaron Ecay Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 05 20:45:58 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Voes0-0001ZD-4Y for ged-emacs-devel@m.gmane.org; Thu, 05 Dec 2013 20:45:56 +0100 Original-Received: from localhost ([::1]:55399 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Voerz-0005LQ-RJ for ged-emacs-devel@m.gmane.org; Thu, 05 Dec 2013 14:45:55 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Voerq-0005L9-5a for emacs-devel@gnu.org; Thu, 05 Dec 2013 14:45:53 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Voeri-0004EN-Rk for emacs-devel@gnu.org; Thu, 05 Dec 2013 14:45:46 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:11744) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Voera-0004D8-Ia; Thu, 05 Dec 2013 14:45:30 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8EABK/CFFFxL6g/2dsb2JhbABEhke4Rxdzgh4BAQQBIzMjBQsLGgIYDgICFBgNJIgeBq5fkk6BI45UgRMDiGGcGYFegxU X-IPAS-Result: Av8EABK/CFFFxL6g/2dsb2JhbABEhke4Rxdzgh4BAQQBIzMjBQsLGgIYDgICFBgNJIgeBq5fkk6BI45UgRMDiGGcGYFegxU X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="41237363" Original-Received: from 69-196-190-160.dsl.teksavvy.com (HELO pastel.home) ([69.196.190.160]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 05 Dec 2013 14:45:29 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 4B57E602B1; Thu, 5 Dec 2013 14:45:29 -0500 (EST) In-Reply-To: <87fvq7dsou.fsf@gmail.com> (Aaron Ecay's message of "Thu, 05 Dec 2013 14:05:37 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:166135 Archived-At: > 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=E2=80=99s save-excursion, so exiting the latter restores t= he > point to a bogus position (from the POV of the user). I think your analysis is exactly right, and the reason why save-window-excursion doesn't exhibit the problem is because save-window-excursion does not save-excursion in the current buffer. I.e. paradoxically it's because it "preserves less" rather than because it "preserves more". Replacing the save-excursion with save-current-buffer would probably work as well. Stefan