Commit 4eea26a9 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(generic): Added defgroup declaration.

(generic-make-keywords-list): Uses regexp-opt.
(generic-mode-set-font-lock): Uses regexp-opt.
parent 3d5b2234
...@@ -162,6 +162,11 @@ instead (which see).") ...@@ -162,6 +162,11 @@ instead (which see).")
;; Customization Variables ;; Customization Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defgroup generic nil
"Define simple major modes with comment and font-lock support."
:prefix "generic-"
:group 'extensions)
(defcustom generic-use-find-file-hook t (defcustom generic-use-find-file-hook t
"*If non-nil, add a hook to enter default-generic-mode automatically "*If non-nil, add a hook to enter default-generic-mode automatically
if the first few lines of a file in fundamental mode start with a hash if the first few lines of a file in fundamental mode start with a hash
...@@ -499,13 +504,10 @@ Some generic modes are defined in `generic-x.el'." ...@@ -499,13 +504,10 @@ Some generic modes are defined in `generic-x.el'."
(setq (setq
generic-font-lock-expressions generic-font-lock-expressions
(append (append
(list (list (let ((regexp (regexp-opt keywords)))
(list (list (concat "\\<\\(" regexp "\\)\\>")
(concat 1
"\\(\\<" 'font-lock-keyword-face)))
(mapconcat 'identity keywords "\\>\\|\\<")
"\\>\\)")
1 'font-lock-keyword-face))
generic-font-lock-expressions))) generic-font-lock-expressions)))
;; Other font-lock expressions ;; Other font-lock expressions
(and font-lock-expressions (and font-lock-expressions
...@@ -570,21 +572,17 @@ This hook is NOT installed by default." ...@@ -570,21 +572,17 @@ This hook is NOT installed by default."
(defun generic-make-keywords-list (keywords-list face &optional prefix suffix) (defun generic-make-keywords-list (keywords-list face &optional prefix suffix)
"Return a regular expression matching the specified keywords. "Return a regular expression matching the specified keywords.
The regexp is highlighted with FACE." The regexp is highlighted with FACE."
;; Sanity checks
;; Don't check here; face may not be defined yet
;; (if (not (facep face))
;; (error "Face %s is not defined" (princ face)))
(and (not (listp keywords-list)) (and (not (listp keywords-list))
(error "Keywords argument must be a list of strings")) (error "Keywords argument must be a list of strings"))
(list (list (concat (or prefix "")
(concat "\\<\\("
(or prefix "") ;; Use an optimized regexp.
"\\(\\<" (regexp-opt keywords-list t)
(mapconcat 'identity keywords-list "\\>\\|\\<") "\\)\\>"
"\\>\\)" (or suffix ""))
(or suffix "") 1
) 1 face)) face)))
(provide 'generic) (provide 'generic)
;;; generic.el ends here ;;; generic.el ends here
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment