From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Herbert Euler" Newsgroups: gmane.emacs.devel Subject: Re: find-file-noselect needs save-match-data Date: Sun, 17 Jun 2007 11:19:50 +0800 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-Trace: sea.gmane.org 1182050407 14889 80.91.229.12 (17 Jun 2007 03:20:07 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 17 Jun 2007 03:20:07 +0000 (UTC) Cc: juri@jurta.org, schwab@suse.de, miles@gnu.org, miles.bader@necel.com, emacs-devel@gnu.org To: rms@gnu.org, monnier@iro.umontreal.ca Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jun 17 05:20:05 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HzlJ7-0003R2-Hg for ged-emacs-devel@m.gmane.org; Sun, 17 Jun 2007 05:20:05 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HzlJ6-0000am-Sc for ged-emacs-devel@m.gmane.org; Sat, 16 Jun 2007 23:20:04 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HzlJ2-0000X0-0R for emacs-devel@gnu.org; Sat, 16 Jun 2007 23:20:00 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HzlJ0-0000UJ-6A for emacs-devel@gnu.org; Sat, 16 Jun 2007 23:19:59 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HzlJ0-0000UC-0E for emacs-devel@gnu.org; Sat, 16 Jun 2007 23:19:58 -0400 Original-Received: from bay0-omc3-s40.bay0.hotmail.com ([65.54.246.240]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HzlIx-0006wj-Tm; Sat, 16 Jun 2007 23:19:56 -0400 Original-Received: from hotmail.com ([65.55.154.119]) by bay0-omc3-s40.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Sat, 16 Jun 2007 20:19:54 -0700 Original-Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Sat, 16 Jun 2007 20:19:53 -0700 Original-Received: from 65.55.154.123 by by143fd.bay143.hotmail.msn.com with HTTP; Sun, 17 Jun 2007 03:19:50 GMT X-Originating-IP: [221.223.221.87] X-Originating-Email: [herberteuler@hotmail.com] X-Sender: herberteuler@hotmail.com In-Reply-To: X-OriginalArrivalTime: 17 Jun 2007 03:19:53.0857 (UTC) FILETIME=[5F919710:01C7B08E] X-detected-kernel: Windows 2000 SP4, XP SP1+ X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:73132 Archived-At: > > This function is good because it will enable programmers to DTRT in >a > > simpler way in many cases. > > I fail to see the simplicity. All the difficulty comes from having to >think > about when to be careful about the match-data. > >Yes, but if people get in the habit of using a new function >whenever they don't actually want to use the match data, >which I expect is most of the time, that need to think carefully >will be much less frequent. No, they would think carefully as frequently as now. I mean, when they would think carefully now they would think carefully after adding such a function; when they don't need to think carefully now they wouldn't think carefully after adding such a function. Please take a look at the following case, in `c-electric-brace': ;; cc-cmds.el, line 749 ;; `}': compact to a one-liner defun? (save-match-data (when (and (eq last-command-char ?\}) (memq 'one-liner-defun c-cleanup-list) (c-intersect-lists '(defun-close) syntax) (c-try-one-liner)) (setq here (- (point-max) pos)))) `save-match-data' is used here, but nothing implies directly that match-data will be changed in its body. Some functions change it, but is called _indirectly_. One would need to check the source of each function in its body to see where the match-data is changed. This is the only case that the problems caused by unexpected match-data changes happen. If one writes the following code: ;; dired.el, line 2207, in function `dired-build-subdir-alist' (while (re-search-forward dired-subdir-regexp nil t) ;; Avoid taking a file name ending in a colon ;; as a subdir name. (unless (save-excursion (goto-char (match-beginning 0)) (beginning-of-line) (forward-char 2) (save-match-data (looking-at dired-re-perms))) one will know that `looking-at' changes match-data, and so uses `save-match-data' properly to avoid the problem. And if match-data needs to be preserved, the programmer would pay attention to it, no matter whether there are some functions that won't change match-data exist. When they think about which function to use, they've already thought about whether the match-data should be preserved. Regards, Guanpeng Xu _________________________________________________________________ Don't just search. Find. Check out the new MSN Search! http://search.msn.com/