-;;; 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.
+;; Copyright (C) 1997, 1999, 2004 Free Software Foundation, Inc.
;;
;; Author: Peter Breton <pbreton@cs.umb.edu>
;; Created: Fri Sep 27 1996
;;
;; * Additional expressions to font-lock. This should be a list of
;; expressions, each of which should be of the same form
-;; as those in `font-lock-defaults-alist'.
+;; as those in `font-lock-keywords'.
;;
;; * List of regular expressions to be placed in auto-mode-alist.
;;
(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
)
+(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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
&optional description)
"Create a new generic mode with NAME.
-Args: (NAME COMMENT-LIST KEYWORD-LIST FONT-LOCK-LIST AUTO-MODE-LIST
- FUNCTION-LIST &optional DESCRIPTION)
-
NAME should be a symbol; its string representation is used as the function
name. If DESCRIPTION is provided, it is used as the docstring for the new
function.
or a one-character string, it is added to the mode's syntax table with
`comment-start' syntax. If the entry is a cons pair, the elements of the
pair are considered to be `comment-start' and `comment-end' respectively.
+\(The latter should be nil if you want comments to end at end of line.)
Note that Emacs has limitations regarding comment characters.
KEYWORD-LIST is a list of keywords to highlight with `font-lock-keyword-face'.
Each keyword should be a string.
FONT-LOCK-LIST is a list of additional expressions to highlight. Each entry
-in the list should have the same form as an entry in `font-lock-defaults-alist'
+in the list should have the same form as an entry in `font-lock-keywords'.
AUTO-MODE-LIST is a list of regular expressions to add to `auto-mode-alist'.
These regexps are added to `auto-mode-alist' as soon as `define-generic-mode'
;; Go through all the comments
(dolist (start comment-list)
- (let ((end ?\n) (comstyle ""))
+ (let ((end nil) (comstyle ""))
;; Normalize
(when (consp start)
(setq end (or (cdr start) end))
(setq start (car start)))
(when (char-valid-p start) (setq start (char-to-string start)))
- (when (char-valid-p end) (setq end (char-to-string end)))
+ (cond
+ ((char-valid-p end) (setq end (char-to-string end)))
+ ((zerop (length end)) (setq end "\n")))
;; Setup the vars for `comment-region'
(if comment-start
(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
(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
The regexp is highlighted with FACE."
(unless (listp keywords-list)
(error "Keywords argument must be a list of strings"))
- (list (concat prefix "\\<"
+ (list (concat prefix "\\_<"
;; Use an optimized regexp.
(regexp-opt keywords-list t)
- "\\>" suffix)
+ "\\_>" suffix)
1
face))
(provide 'generic)
+;; arch-tag: 239c1fc4-1303-48d9-9ac0-657d655669ea
;;; generic.el ends here