From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bastien Newsgroups: gmane.emacs.devel Subject: Re: Using `save-window-excursion' instead of `save-excursion' for `comment-region'? Date: Thu, 05 Dec 2013 19:43:59 +0100 Message-ID: <87ob4vuoi8.fsf@bzg.ath.cx> References: <87y53zk3dx.fsf@bzg.ath.cx> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1386269070 9162 80.91.229.3 (5 Dec 2013 18:44:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Dec 2013 18:44:30 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 05 19:44:35 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 1Voduc-0000hm-QV for ged-emacs-devel@m.gmane.org; Thu, 05 Dec 2013 19:44:34 +0100 Original-Received: from localhost ([::1]:55214 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Voduc-0000LW-CZ for ged-emacs-devel@m.gmane.org; Thu, 05 Dec 2013 13:44:34 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52986) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoduF-0008Hg-0Z for emacs-devel@gnu.org; Thu, 05 Dec 2013 13:44:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vodu9-00039I-WD for emacs-devel@gnu.org; Thu, 05 Dec 2013 13:44:10 -0500 Original-Received: from mail-wi0-x234.google.com ([2a00:1450:400c:c05::234]:55978) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vodu9-00038L-QA for emacs-devel@gnu.org; Thu, 05 Dec 2013 13:44:05 -0500 Original-Received: by mail-wi0-f180.google.com with SMTP id hn9so116398wib.1 for ; Thu, 05 Dec 2013 10:44:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type; bh=5TlJ33vSdV9AXsB9uajnk+nxRAY7FmagCsznqqueros=; b=tAYjhF94BGRyRWYFqge+U2KEHqKD9lk0s+nljOCsZ3X20JWqBJDGnI5O3S79meAPrC v7BD+XafJIlazwl7FxAAMemT35MfMo79nf9knYqG3PVR4U6VzzOnQJmJNqS9bmt2xaAU 1i0E+zvXynJ8kkMD8WKFeKMvcfLP0hxIzdGDzXmH+v3fTwFMSS9kHdoFnc9aKvXMlZF3 MaUGGJVMGm6fEvbG3Uvj6YxrPK/8pj8Vwo/H0OpG9fNOKkhIxhiLVzk1AjtrUMR5lCW5 hPn7xRQmqM1S/2ITbIOnKaHCXdhlRHlJIXhYhKI3F1dgXw4GL+Vd6W9KDd4FgsYFu0Wk ARHA== X-Received: by 10.194.78.179 with SMTP id c19mr212535wjx.84.1386269044243; Thu, 05 Dec 2013 10:44:04 -0800 (PST) Original-Received: from bzg.localdomain (mar75-2-81-56-68-112.fbx.proxad.net. [81.56.68.112]) by mx.google.com with ESMTPSA id y20sm8823320wib.0.2013.12.05.10.44.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Dec 2013 10:44:03 -0800 (PST) Original-Received: by bzg.localdomain (Postfix, from userid 1000) id 5CF1D1C208D0; Thu, 5 Dec 2013 19:43:59 +0100 (CET) In-Reply-To: (Stefan Monnier's message of "Thu, 05 Dec 2013 13:29:49 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::234 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:166131 Archived-At: Stefan Monnier 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