emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: etags.el tags-search use global syntax table


From: Francesco Potorti`
Subject: Re: etags.el tags-search use global syntax table
Date: Thu, 19 Jul 2007 18:49:20 +0200

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)))
================================================================




reply via email to

[Prev in Thread] Current Thread [Next in Thread]