From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Francesco Potorti` Newsgroups: gmane.emacs.devel Subject: Re: etags.el tags-search use global syntax table Date: Thu, 19 Jul 2007 18:49:20 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org X-Trace: sea.gmane.org 1184867168 20881 80.91.229.12 (19 Jul 2007 17:46:08 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 19 Jul 2007 17:46:08 +0000 (UTC) Cc: emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 19 19:46:00 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 1IBa4b-0005Gg-WE for ged-emacs-devel@m.gmane.org; Thu, 19 Jul 2007 19:45:58 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IBa4b-0008Dd-Dc for ged-emacs-devel@m.gmane.org; Thu, 19 Jul 2007 13:45:57 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IBa4Z-0008DP-7y for emacs-devel@gnu.org; Thu, 19 Jul 2007 13:45:55 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IBa4Y-0008D3-8Q for emacs-devel@gnu.org; Thu, 19 Jul 2007 13:45:54 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IBa4Y-0008D0-2p for emacs-devel@gnu.org; Thu, 19 Jul 2007 13:45:54 -0400 Original-Received: from mx2.isti.cnr.it ([194.119.192.4]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IBa4W-0007n5-9P; Thu, 19 Jul 2007 13:45:52 -0400 Original-Received: from conversionlocal.isti.cnr.it by mx.isti.cnr.it (PMDF V6.3 #31251) id <01MJ5DCIV6GGAC2VYL@mx.isti.cnr.it>; Thu, 19 Jul 2007 19:43:07 +0200 Original-Received: from tucano.isti.cnr.it (tucano.isti.cnr.it [146.48.81.102]) by mx.isti.cnr.it (PMDF V6.3 #31251) with ESMTPSA id <01MJ5BH3L87QAAVOPD@mx.isti.cnr.it>; Thu, 19 Jul 2007 18:49:20 +0200 Original-Received: from pot by tucano.isti.cnr.it with local (Exim 4.67) (envelope-from ) id 1IBZBo-0004mI-G6; Thu, 19 Jul 2007 18:49:20 +0200 In-reply-to: X-INSM-ip-source: 146.48.81.102 Auth Done X-fingerprint: 4B02 6187 5C03 D6B1 2E31 7666 09DF 2DC9 BE21 6115 X-detected-kernel: OpenVMS 7.2 (Multinet 4.3-4.4 stack) 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:75130 Archived-At: This is a first try at applying the major mode to files that are loaded by etags.el's next-file. It works in the single test case I tried. If I am following the correct road, I will check that nothing is broken by these changes and I will make speed tests, so please comment. ================================================================ --- etags.el 25 Feb 2007 15:54:43 +0100 1.194 +++ etags.el 19 Jul 2007 18:40:46 +0200 @@ -1701,10 +1701,11 @@ if the file was newly read in, the value (set-buffer (find-file-noselect next novisit)) ;; Like find-file, but avoids random warning messages. (set-buffer (get-buffer-create " *next-file*")) - (kill-all-local-variables) (erase-buffer) (setq new next) - (insert-file-contents new nil)) + (insert-file-contents new nil) + (let ((buffer-file-name new)) + (set-auto-mode t (list 'special)))) new)) (defvar tags-loop-operate nil ================================================================ The above works because I modified set-auto-mode to accept one more optional argument, as detailed in the following addition to the help string: +The optional argument KEEP-IF-CLASS is a list of symbols. If the +major mode has any of these symbols in its mode-class property, or if +one the symbols in the list is t, we do not set the major mode." ================================================================ --- files.el 19 Jul 2007 18:00:42 +0200 1.913 +++ files.el 19 Jul 2007 18:46:14 +0200 @@ -2218,8 +2218,8 @@ If FUNCTION is nil, then it is not calle "Upper limit on `magic-mode-alist' regexp matches. Also applies to `magic-fallback-mode-alist'.") -(defun set-auto-mode (&optional keep-mode-if-same) - "Select major mode appropriate for current buffer. +(defun set-auto-mode (&optional keep-if-same keep-if-class) + "Select major mode appropriate for current buffer and return it. To find the right major mode, this function checks for a -*- mode tag, checks if it uses an interpreter listed in `interpreter-mode-alist', @@ -2233,9 +2233,13 @@ Local Variables section of the file; for If `enable-local-variables' is nil, this function does not check for a -*- mode tag. -If the optional argument KEEP-MODE-IF-SAME is non-nil, then we +If the optional argument KEEP-IF-SAME is non-nil, then we set the major mode only if that would change it. In other words -we don't actually set it to the same mode the buffer already has." +we don't actually set it to the same mode the buffer already has. + +The optional argument KEEP-IF-CLASS is a list of symbols. If the +major mode has any of these symbols in its mode-class property, or if +one the symbols in the list is t, we do not set the major mode." ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- (let (end done mode modes) ;; Find a -*- mode tag @@ -2270,7 +2274,7 @@ we don't actually set it to the same mod (if (not (functionp mode)) (message "Ignoring unknown mode `%s'" mode) (setq done t) - (or (set-auto-mode-0 mode keep-mode-if-same) + (or (setq mode (set-auto-mode-0 mode keep-if-same keep-if-class)) ;; continuing would call minor modes again, toggling them off (throw 'nop nil)))))) ;; If we didn't, look for an interpreter specified in the first line. @@ -2287,11 +2291,11 @@ we don't actually set it to the same mod done (assoc (file-name-nondirectory mode) interpreter-mode-alist)) ;; If we found an interpreter mode to use, invoke it now. - (if done - (set-auto-mode-0 (cdr done) keep-mode-if-same))) + (when done + (setq mode (set-auto-mode-0 (cdr done) keep-if-same keep-if-class)))) ;; Next try matching the buffer beginning against magic-mode-alist. (unless done - (if (setq done (save-excursion + (when (setq done (save-excursion (goto-char (point-min)) (save-restriction (narrow-to-region (point-min) @@ -2302,7 +2306,7 @@ we don't actually set it to the same mod (if (functionp re) (funcall re) (looking-at re))))))) - (set-auto-mode-0 done keep-mode-if-same))) + (setq mode (set-auto-mode-0 done keep-if-same keep-if-class)))) ;; Next compare the filename against the entries in auto-mode-alist. (unless done (if buffer-file-name @@ -2335,11 +2339,11 @@ we don't actually set it to the same mod name (substring name 0 (match-beginning 0))) (setq name)) (when mode - (set-auto-mode-0 mode keep-mode-if-same) + (setq mode (set-auto-mode-0 mode keep-if-same keep-if-class)) (setq done t)))))) ;; Next try matching the buffer beginning against magic-fallback-mode-alist. (unless done - (if (setq done (save-excursion + (when (setq done (save-excursion (goto-char (point-min)) (save-restriction (narrow-to-region (point-min) @@ -2350,20 +2354,28 @@ we don't actually set it to the same mod (if (functionp re) (funcall re) (looking-at re))))))) - (set-auto-mode-0 done keep-mode-if-same))))) + (setq mode (set-auto-mode-0 done keep-if-same keep-if-class)))) + mode)) -;; When `keep-mode-if-same' is set, we are working on behalf of +;; When `keep-if-same' is set, we are working on behalf of ;; set-visited-file-name. In that case, if the major mode specified is the ;; same one we already have, don't actually reset it. We don't want to lose ;; minor modes such as Font Lock. -(defun set-auto-mode-0 (mode &optional keep-mode-if-same) +(defun set-auto-mode-0 (mode &optional keep-if-same keep-if-class) "Apply MODE and return it. -If optional arg KEEP-MODE-IF-SAME is non-nil, MODE is chased of +If optional arg KEEP-IF-SAME is non-nil, MODE is chased of any aliases and compared to current major mode. If they are the -same, do nothing and return nil." - (unless (and keep-mode-if-same +same, do nothing and return nil. + +The optional argument KEEP-IF-CLASS is a list of symbols. If the +major mode has any of these symbols in its mode-class property, or if +one the symbols in the list is t, we do not set the major mode." + (unless (or + (and keep-if-same (eq (indirect-function mode) (indirect-function major-mode))) + (memq t keep-if-class) + (memq (get mode 'mode-class) keep-if-class)) (when mode (funcall mode) mode))) ================================================================