From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.devel Subject: Re: find-file-noselect needs save-match-data Date: Fri, 15 Jun 2007 08:31:16 +0200 Message-ID: <46723234.2090704@gmx.at> References: <46665AD7.7040706@gmx.at> <87k5ueq23m.fsf@kfs-lx.testafd.dk> <87myz8c10t.fsf@jurta.org> <18030.3441.204697.244518@rgrjr.dyndns.org> <87zm3515r4.fsf@jurta.org> <85k5u8x2gm.fsf@lola.goethe.zz> <87r6og6czf.fsf@catnip.gol.com> <85bqfkx0i5.fsf@lola.goethe.zz> <87odjjzaoz.fsf@catnip.gol.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1181889934 23324 80.91.229.12 (15 Jun 2007 06:45:34 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 15 Jun 2007 06:45:34 +0000 (UTC) Cc: rms@gnu.org, miles.bader@necel.com, schwab@suse.de, emacs-devel@gnu.org, juri@jurta.org, Miles Bader To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jun 15 08:45:32 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 1Hz5Yp-0005Qe-VN for ged-emacs-devel@m.gmane.org; Fri, 15 Jun 2007 08:45:32 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Hz5Yp-0005MO-4I for ged-emacs-devel@m.gmane.org; Fri, 15 Jun 2007 02:45:31 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Hz5Yl-0005MH-Qp for emacs-devel@gnu.org; Fri, 15 Jun 2007 02:45:27 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Hz5Yl-0005M0-Eh for emacs-devel@gnu.org; Fri, 15 Jun 2007 02:45:27 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Hz5Yl-0005Ls-4j for emacs-devel@gnu.org; Fri, 15 Jun 2007 02:45:27 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1Hz5Yk-0004RJ-EO for emacs-devel@gnu.org; Fri, 15 Jun 2007 02:45:26 -0400 Original-Received: (qmail invoked by alias); 15 Jun 2007 06:45:25 -0000 Original-Received: from N880P009.adsl.highway.telekom.at (EHLO [62.47.53.233]) [62.47.53.233] by mail.gmx.net (mp032) with SMTP; 15 Jun 2007 08:45:25 +0200 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX18CQ9RM6KoC9wSVaIZxyOy+hzoyy40thgr5uek4da MQAjXx7OBp34i6 User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en In-Reply-To: X-Y-GMX-Trusted: 0 X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) 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:72921 Archived-At: > Actually, I'd even argue against any such new function, How about adding another optional argument then? string-match is a built-in function in `C source code'. (string-match regexp string &optional start preserve-match-data)) Return index of start of first match for REGEXP in STRING, or nil. Matching ignores case if `case-fold-search' is non-nil. If third arg START is non-nil, start search at that index in string. For index of first char beyond the match, do (match-end 0). `match-end' and `match-beginning' also give indices of substrings matched by parenthesis constructs in the pattern. You can use the function `match-string' to extract the substrings matched by the parenthesis constructions in REGEXP. Fourth argument PRESERVE-MATCH-DATA non-nil means do not modify match data. This means you cannot use `match-beginning', `match-end', or `match-string' to extract further details of the current match. On the other hand, you don't have to use `save-match-data' in order to preserve data of a previous match. > on the grounds that > it's solving a non-problem, i.e. it will just add new functions, new code, > new complexity for no real benefit. Consider `abbreviate-file-name'. It has the following construct: (if (and (string-match abbreviated-home-dir filename) ;; If the home dir is just /, don't change it. (not (and (= (match-end 0) 1) (= (aref filename 0) ?/))) ;; MS-DOS root directories can come with a drive letter; ;; Novell Netware allows drive letters beyond `Z:'. (not (and (or (eq system-type 'ms-dos) (eq system-type 'cygwin) (eq system-type 'windows-nt)) (save-match-data (string-match "^[a-zA-`]:/$" filename))))) (setq filename (concat "~" (match-string 1 filename) (substring filename (match-end 0))))) How would you eliminate the call to `save-match-data' without introducing new variables and complexity? I could simply write: (if (and (string-match abbreviated-home-dir filename) ;; If the home dir is just /, don't change it. (not (and (= (match-end 0) 1) (= (aref filename 0) ?/))) ;; MS-DOS root directories can come with a drive letter; ;; Novell Netware allows drive letters beyond `Z:'. (not (and (or (eq system-type 'ms-dos) (eq system-type 'cygwin) (eq system-type 'windows-nt)) (string-match "^[a-zA-`]:/$" filename nil t)))) (setq filename (concat "~" (match-string 1 filename) (substring filename (match-end 0)))))