]> code.delx.au - gnu-emacs/blobdiff - lisp/generic.el
(rmail-convert-to-babyl-format): Display a message while converting to Babyl.
[gnu-emacs] / lisp / generic.el
index f17e2c0814d9c00fca032915c9646fb538778a8e..8f13dc375e7977c111eb167542fd90a3150366a0 100644 (file)
@@ -1,4 +1,4 @@
-;;; generic.el --- Defining simple major modes with comment and font-lock.
+;;; generic.el --- defining simple major modes with comment and font-lock
 ;;
 ;; Copyright (C) 1997, 1999 Free Software Foundation, Inc.
 ;;
@@ -160,21 +160,23 @@ This variable should be set to a small positive number."
 
 (defcustom generic-find-file-regexp "^#"
   "*Regular expression used by `generic-mode-find-file-hook'.
-Used to determine if files in fundamental mode should be put into
-`default-generic-mode' instead."
+Files in fundamental mode whose first few lines contain a match for
+this regexp, should be put into `default-generic-mode' instead.
+The number of lines tested for the matches is specified by the value
+of the variable `generic-lines-to-scan', which see."
   :group 'generic
   :type  'regexp
   )
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Inline functions
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-(defsubst generic-read-type ()
-  (completing-read
-   "Generic Type: "
-   (mapcar (lambda (elt) (list (symbol-name (car elt))))
-   nil t))
+(defcustom generic-ignore-files-regexp "[Tt][Aa][Gg][Ss]\\'"
+  "*Regular expression used by `generic-mode-find-file-hook'.
+Files whose names match this regular expression should not be put
+into `default-generic-mode', even if they have lines which match the
+regexp in `generic-find-file-regexp'.  If the value is nil,
+`generic-mode-find-file-hook' does not check the file names."
+  :group 'generic
+  :type  '(choice (const :tag "Don't check file names" nil) regexp)
+  )
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Functions
@@ -216,7 +218,7 @@ See the file generic-x.el for some examples of `define-generic-mode'."
 
   ;; Add a new entry
   (unless (assq name generic-mode-list)
-    (push (list name) generic-mode-list))
+    (push (list (symbol-name name)) generic-mode-list))
 
   ;; Add it to auto-mode-alist
   (dolist (re auto-mode-list)
@@ -275,7 +277,7 @@ comment characters, keywords, and the like.)
 To define a generic-mode, use the function `define-generic-mode'.
 Some generic modes are defined in `generic-x.el'."
   (interactive
-   (list (generic-read-type)))
+   (list (completing-read "Generic Type: " generic-mode-list nil t)))
   (funcall (intern type)))
 
 ;;; Comment Functionality
@@ -307,7 +309,7 @@ Some generic modes are defined in `generic-x.el'."
                    (concat comment-start-skip "\\|" (regexp-quote start) "+\\s-*")))
          ;; First comment-style
          (setq comment-start start)
-         (setq comment-end (unless (string-equal end "\n") end))
+         (setq comment-end (if (string-equal end "\n") "" end))
          (setq comment-start-skip (concat (regexp-quote start) "+\\s-*")))
 
        ;; Reuse comstyles if necessary
@@ -368,10 +370,17 @@ Some generic modes are defined in `generic-x.el'."
 (defun generic-mode-find-file-hook ()
   "Hook function to enter `default-generic-mode' automatically.
 Done if the first few lines of a file in `fundamental-mode' start with
-a hash comment character.  This hook will be installed if the variable
+a match for the regexp in `generic-find-file-regexp', unless the
+file's name matches the regexp which is the value of the variable
+`generic-ignore-files-regexp'.
+This hook will be installed if the variable
 `generic-use-find-file-hook' is non-nil.  The variable
 `generic-lines-to-scan' determines the number of lines to look at."
-  (when (eq major-mode 'fundamental-mode)
+  (when (and (eq major-mode 'fundamental-mode)
+            (or (null generic-ignore-files-regexp)
+                (not (string-match
+                      generic-ignore-files-regexp
+                      (file-name-sans-versions buffer-file-name)))))
     (save-excursion
       (goto-char (point-min))
       (when (re-search-forward generic-find-file-regexp
@@ -408,4 +417,5 @@ The regexp is highlighted with FACE."
 
 (provide 'generic)
 
+;;; arch-tag: 239c1fc4-1303-48d9-9ac0-657d655669ea
 ;;; generic.el ends here