From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Roland Winkler" Newsgroups: gmane.emacs.bugs Subject: Re: nesting of unwind-protect and atomic-change-group Date: Sun, 3 Feb 2008 23:53:15 +0100 Message-ID: <18342.17883.831798.646291@tfkp07.physik.uni-erlangen.de> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1202079225 2852 80.91.229.12 (3 Feb 2008 22:53:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 3 Feb 2008 22:53:45 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org To: rms@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Feb 03 23:54:06 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JLnis-0001tq-Nv for geb-bug-gnu-emacs@m.gmane.org; Sun, 03 Feb 2008 23:54:03 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JLniQ-0000C9-Sb for geb-bug-gnu-emacs@m.gmane.org; Sun, 03 Feb 2008 17:53:34 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JLniL-00009q-W2 for bug-gnu-emacs@gnu.org; Sun, 03 Feb 2008 17:53:30 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JLniH-0008WV-Ax for bug-gnu-emacs@gnu.org; Sun, 03 Feb 2008 17:53:29 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JLniH-0008WK-6g for bug-gnu-emacs@gnu.org; Sun, 03 Feb 2008 17:53:25 -0500 Original-Received: from tfkpsv.physik.uni-erlangen.de ([131.188.164.197]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JLniD-0004Jv-Cx; Sun, 03 Feb 2008 17:53:21 -0500 Original-Received: from tfkp07.physik.uni-erlangen.de (tfkp07.physik.uni-erlangen.de [131.188.164.207]) by tfkpsv.physik.uni-erlangen.de (Postfix) with ESMTP id 87F2686829; Sun, 3 Feb 2008 23:53:19 +0100 (CET) In-Reply-To: X-Mailer: VM 8.0.x-xemacs-522 under Emacs 22.1.2 (i686-pc-linux-gnu) X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:17461 Archived-At: On Sat Feb 2 2008 Richard Stallman wrote: > When combining unwind-protect and atomic-change-group I found that > putting unwind-protect outermost worked for me (i.e., an unwindform > moving point to the buffer location where the error occured was > obeyed), whereas doing it the other way round didn't work for me > (the unwindform was ignored). > > An unwind-protect will _work_ either inside or outside > of atomic-change-group. Whatever problem you encountered > must be more specific. I can't guess what it might be. OK, here is a test case, more or less similar to what I really want to do, tested with emacs -q for GNU Emacs 22.1.2 (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars) When I run fun1 in a buffer containing the following lines of text hello world bar hello world bar hello world foo hello world bar hello world bar fun1 throws an error and puts point at the buffer location the error refers to. fun2 does not put point at the buffer location that corresponds to the error. The only difference between fun1 and fun2 is the order of unwind-protect and atomic-change-group. (I find it counterintuitive that both functions put the message "search "foo"" in the *Messages* buffer before the error message, but I expect that this has to do with how the error is handled.) Roland (defun fun1 () "In current buffer replace word \"bar\" by \"baz\". Throw error for word \"foo\" and move point to malicious word. Works" (interactive) (let (error-word) ;; `atomic-change-group' inside `unwind-protect' (unwind-protect (atomic-change-group (save-excursion (goto-char (point-min)) (while (re-search-forward "\\<\\w+\\>" nil t) (let ((word (match-string 0))) (cond ((string= word "foo") (setq error-word word) (error "word \"foo\" in text")) ((string= word "bar") (replace-match "baz"))))))) (when error-word (message "search \"foo\"") ;; move point to where error occured (goto-char (point-min)) (re-search-forward "foo") (goto-char (match-beginning 0)))))) (defun fun2 () "In current buffer replace word \"bar\" by \"baz\". Throw error for word \"foo\". Code does not move point to malicious word" (interactive) (let (error-word) ;; `unwind-protect' inside `atomic-change-group' (atomic-change-group (unwind-protect (save-excursion (goto-char (point-min)) (while (re-search-forward "\\<\\w+\\>" nil t) (let ((word (match-string 0))) (cond ((string= word "foo") (setq error-word word) (error "word \"foo\" in text")) ((string= word "bar") (replace-match "baz")))))) (when error-word (message "search \"foo\"") ;; move point to where error occured (goto-char (point-min)) (re-search-forward "foo") (goto-char (match-beginning 0)))))))