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: Wed, 06 Jun 2007 08:25:53 +0800 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_7f14_41eb_7c6a" X-Trace: sea.gmane.org 1181089568 22157 80.91.229.12 (6 Jun 2007 00:26:08 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 6 Jun 2007 00:26:08 +0000 (UTC) Cc: emacs-devel@gnu.org To: rudalics@gmx.at Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jun 06 02:26:06 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 1HvjLi-0004Xc-1m for ged-emacs-devel@m.gmane.org; Wed, 06 Jun 2007 02:26:06 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HvjLh-0005Hp-FU for ged-emacs-devel@m.gmane.org; Tue, 05 Jun 2007 20:26:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HvjLd-0005Hk-OI for emacs-devel@gnu.org; Tue, 05 Jun 2007 20:26:01 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HvjLb-0005HY-7W for emacs-devel@gnu.org; Tue, 05 Jun 2007 20:26:00 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HvjLb-0005HV-2v for emacs-devel@gnu.org; Tue, 05 Jun 2007 20:25:59 -0400 Original-Received: from bay0-omc1-s17.bay0.hotmail.com ([65.54.246.89]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HvjLa-0002gd-F1 for emacs-devel@gnu.org; Tue, 05 Jun 2007 20:25:58 -0400 Original-Received: from hotmail.com ([65.55.154.106]) by bay0-omc1-s17.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Tue, 5 Jun 2007 17:25:57 -0700 Original-Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Tue, 5 Jun 2007 17:25:57 -0700 Original-Received: from 65.55.154.123 by by143fd.bay143.hotmail.msn.com with HTTP; Wed, 06 Jun 2007 00:25:53 GMT X-Originating-IP: [222.130.207.178] X-Originating-Email: [herberteuler@hotmail.com] X-Sender: herberteuler@hotmail.com X-OriginalArrivalTime: 06 Jun 2007 00:25:57.0017 (UTC) FILETIME=[402EF090:01C7A7D1] 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:72302 Archived-At: This is a multi-part message in MIME format. ------=_NextPart_000_7f14_41eb_7c6a Content-Type: text/plain; format=flowed > > I just got a possibly wrong idea today morning. The error happens in > > the case that some command, which changes the match data, is added > > into a hook. When the hook is executed, the match data is also > > changed. Now, if we could assume that _hooks shall not change the > > match data_, we can save and restore the match data automatically when > > we run hooks. I am not sure about this assumption, though. > >`save-match-data' is not cheap. I suppose it's not advisable to >automatically wrap every hook into it. > > > Adding `save-match-data' to functions one by one works, but it is > > difficult to check all of the functions, and it is not the overall > > solution. > >I think that `find-file-noselect' and `file-truename' should not change >match-data regardless of whether they run in a hook or not (though a >number of hooks should probably not run `find-file-noselect' in the >first place). Ok. So I wrote a script to find out all such defuns. I found many defuns are possible needing `save-match-data' with it. The script is attached, and to start finding, first load the file and then execute `list-possible-wrong-match-defuns-in-dir'. An exception in the executing is for some files a question about whether to apply local variables list. Should we check all these defuns and add `save-match-data' to some of them? Regards, Guanpeng Xu _________________________________________________________________ FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/ ------=_NextPart_000_7f14_41eb_7c6a Content-Type: text/plain; name="ss.el"; format=flowed Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="ss.el" (defvar change-match-data-calling (regexp-opt '("(search-forward " "(search-backward " "(word-search-forward " "(word-search-backward " "(re-search-forward " "(re-search-backward " "(string-match " "(looking-at " "(looking-back " "(search-spaces-regexp " "(posix-search-forward " "(posix-search-backward " "(posix-looking-at " "(posix-string-match " "(set-match-data "))) (defvar defun-form (regexp-opt '("(defun " "(define-minor-mode " "(define-derived-mode "))) (defun find-possible-wrong-match-defuns-in-buffer (buffer) (let (possible-wrong-functions) (catch 'skip-this-file (with-current-buffer buffer (goto-char (point-min)) ;; Find a calling. (while (re-search-forward change-match-data-calling nil t) (let ((valid t) func-name) (catch 'not-a-defun (condition-case nil (progn (let ((last-pos (point))) (mark-defun) (unless (looking-at (concat "\n" defun-form)) (goto-char last-pos) (throw 'not-a-defun t))) (setq func-name (save-excursion (down-list) (forward-sexp) (skip-syntax-forward " ") (buffer-substring-no-properties (point) (save-excursion (forward-sexp) (point))))) (save-restriction (narrow-to-region (region-beginning) (region-end)) ;; Check each calling. (while (and valid (re-search-forward change-match-data-calling nil t)) (save-excursion (backward-up-list) (catch 'found-save-match-data (condition-case nil (while t (backward-up-list) (if (looking-at "(save-match-data") (throw 'found-save-match-data t))) (error (setq valid nil)))))) (unless valid (setq possible-wrong-functions (cons func-name possible-wrong-functions)) (while (re-search-forward change-match-data-calling nil t) nil)))) (error (throw 'skip-this-file t)))))))) possible-wrong-functions)) (defun find-possible-wrong-match-defuns-in-file (file) (when (file-exists-p file) (let* ((buffer (find-file-noselect file)) (possible-wrong-functions (find-possible-wrong-match-defuns-in-buffer buffer))) (kill-buffer buffer) (cons file possible-wrong-functions)))) (defun find-possible-wrong-match-defuns-in-dir (dir) (when (file-exists-p dir) (let (functions-list) (dolist (file (directory-files dir)) (when (not (or (string= file ".") (string= file "..") (string-match "elc$" file))) (let* ((fullname (concat dir (if (not (string-match "/$" dir)) "/" "") file)) (isdir (car (file-attributes fullname))) functions sub-functions-list) (if isdir (progn (setq sub-functions-list (find-possible-wrong-match-defuns-in-dir fullname)) (when sub-functions-list (setq functions-list (append sub-functions-list functions-list)))) (setq functions (find-possible-wrong-match-defuns-in-file fullname)) (if (> (length functions) 1) (setq functions-list (cons functions functions-list))))))) functions-list))) (defun list-possible-wrong-match-defuns-in-dir (dir) (interactive "DDirectory: ") (let ((functions-list (find-possible-wrong-match-defuns-in-dir dir)) (buffer (get-buffer-create "*possible wrong match defuns*"))) (with-current-buffer buffer (dolist (functions functions-list) (insert "In " (car functions) ":\n") (dolist (function (cdr functions)) (insert "\t" function "\n")) (insert "\n"))) (delete-other-windows) (split-window-vertically) (other-window 1) (switch-to-buffer buffer) (goto-char (point-min)))) ------=_NextPart_000_7f14_41eb_7c6a Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel ------=_NextPart_000_7f14_41eb_7c6a--