From 31119d6305a37ded482d4d6c6660f4ed7b439ccb Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 11 Jun 2013 17:26:00 -0400 Subject: * lisp/emacs-lisp/generic.el (generic--normalise-comments) (generic-set-comment-syntax, generic-set-comment-vars): New functions. (generic-mode-set-comments): Use them. (generic-bracket-support): Use setq-local. (generic-make-keywords-list): Declare obsolete. --- lisp/emacs-lisp/generic.el | 89 +++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 36 deletions(-) (limited to 'lisp/emacs-lisp/generic.el') diff --git a/lisp/emacs-lisp/generic.el b/lisp/emacs-lisp/generic.el index dd5ff0ec694..cb86a554335 100644 --- a/lisp/emacs-lisp/generic.el +++ b/lisp/emacs-lisp/generic.el @@ -93,6 +93,8 @@ ;;; Code: +(eval-when-compile (require 'pcase)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Internal Variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -224,18 +226,11 @@ Some generic modes are defined in `generic-x.el'." (funcall (intern mode))) ;;; Comment Functionality -(defun generic-mode-set-comments (comment-list) - "Set up comment functionality for generic mode." - (let ((st (make-syntax-table)) - (chars nil) - (comstyles)) - (make-local-variable 'comment-start) - (make-local-variable 'comment-start-skip) - (make-local-variable 'comment-end) - ;; Go through all the comments +(defun generic--normalise-comments (comment-list) + (let ((normalized '())) (dolist (start comment-list) - (let (end (comstyle "")) + (let (end) ;; Normalize (when (consp start) (setq end (cdr start)) @@ -244,58 +239,79 @@ Some generic modes are defined in `generic-x.el'." (cond ((characterp end) (setq end (char-to-string end))) ((zerop (length end)) (setq end "\n"))) + (push (cons start end) normalized))) + (nreverse normalized))) - ;; Setup the vars for `comment-region' - (if comment-start - ;; We have already setup a comment-style, so use style b - (progn - (setq comstyle "b") - (setq comment-start-skip - (concat comment-start-skip "\\|" (regexp-quote start) "+\\s-*"))) - ;; First comment-style - (setq comment-start start) - (setq comment-end (if (string-equal end "\n") "" end)) - (setq comment-start-skip (concat (regexp-quote start) "+\\s-*"))) - - ;; Reuse comstyles if necessary - (setq comstyle +(defun generic-set-comment-syntax (st comment-list) + "Set up comment functionality for generic mode." + (let ((chars nil) + (comstyles) + (comstyle "") + (comment-start nil)) + + ;; Go through all the comments. + (pcase-dolist (`(,start . ,end) comment-list) + (let ((comstyle + ;; Reuse comstyles if necessary. (or (cdr (assoc start comstyles)) (cdr (assoc end comstyles)) - comstyle)) + ;; Otherwise, use a style not yet in use. + (if (not (rassoc "" comstyles)) "") + (if (not (rassoc "b" comstyles)) "b") + "c"))) (push (cons start comstyle) comstyles) (push (cons end comstyle) comstyles) - ;; Setup the syntax table + ;; Setup the syntax table. (if (= (length start) 1) - (modify-syntax-entry (string-to-char start) + (modify-syntax-entry (aref start 0) (concat "< " comstyle) st) - (let ((c0 (elt start 0)) (c1 (elt start 1))) - ;; Store the relevant info but don't update yet + (let ((c0 (aref start 0)) (c1 (aref start 1))) + ;; Store the relevant info but don't update yet. (push (cons c0 (concat (cdr (assoc c0 chars)) "1")) chars) (push (cons c1 (concat (cdr (assoc c1 chars)) (concat "2" comstyle))) chars))) (if (= (length end) 1) - (modify-syntax-entry (string-to-char end) + (modify-syntax-entry (aref end 0) (concat ">" comstyle) st) - (let ((c0 (elt end 0)) (c1 (elt end 1))) - ;; Store the relevant info but don't update yet + (let ((c0 (aref end 0)) (c1 (aref end 1))) + ;; Store the relevant info but don't update yet. (push (cons c0 (concat (cdr (assoc c0 chars)) (concat "3" comstyle))) chars) (push (cons c1 (concat (cdr (assoc c1 chars)) "4")) chars))))) ;; Process the chars that were part of a 2-char comment marker + (with-syntax-table st ;For `char-syntax'. (dolist (cs (nreverse chars)) (modify-syntax-entry (car cs) (concat (char-to-string (char-syntax (car cs))) " " (cdr cs)) - st)) + st))))) + +(defun generic-set-comment-vars (comment-list) + (when comment-list + (setq-local comment-start (caar comment-list)) + (setq-local comment-end + (let ((end (cdar comment-list))) + (if (string-equal end "\n") "" end))) + (setq-local comment-start-skip + (concat (regexp-opt (mapcar #'car comment-list)) + "+[ \t]*")) + (setq-local comment-end-skip + (concat "[ \t]*" (regexp-opt (mapcar #'cdr comment-list)))))) + +(defun generic-mode-set-comments (comment-list) + "Set up comment functionality for generic mode." + (let ((st (make-syntax-table)) + (comment-list (generic--normalise-comments comment-list))) + (generic-set-comment-syntax st comment-list) + (generic-set-comment-vars comment-list) (set-syntax-table st))) (defun generic-bracket-support () "Imenu support for [KEYWORD] constructs found in INF, INI and Samba files." - (setq imenu-generic-expression - '((nil "^\\[\\(.*\\)\\]" 1)) - imenu-case-fold-search t)) + (setq-local imenu-generic-expression '((nil "^\\[\\(.*\\)\\]" 1))) + (setq-local imenu-case-fold-search t)) ;;;###autoload (defun generic-make-keywords-list (keyword-list face &optional prefix suffix) @@ -306,6 +322,7 @@ expression that matches these keywords and concatenates it with PREFIX and SUFFIX. Then it returns a construct based on this regular expression that can be used as an element of `font-lock-keywords'." + (declare (obsolete regexp-opt "24.4")) (unless (listp keyword-list) (error "Keywords argument must be a list of strings")) (list (concat prefix "\\_<" -- cgit v1.2.3 From 9445f99bd69192de4a1d0f86f33410f4f7d64c4c Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Tue, 18 Jun 2013 00:43:46 -0700 Subject: Replace obsolete generic-make-keywords calls * lisp/generic-x.el (bat-generic-mode, rc-generic-mode, rul-generic-mode): Replace obsolete function generic-make-keywords with its expansion. * lisp/emacs-lisp/generic.el: Update commentary. --- lisp/ChangeLog | 3 ++ lisp/emacs-lisp/generic.el | 7 +--- lisp/generic-x.el | 101 +++++++++++++++++++++------------------------ 3 files changed, 51 insertions(+), 60 deletions(-) (limited to 'lisp/emacs-lisp/generic.el') diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 793f470493c..ab8868d600c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,8 @@ 2013-06-18 Glenn Morris + * generic-x.el (bat-generic-mode, rc-generic-mode, rul-generic-mode): + Replace obsolete function generic-make-keywords with its expansion. + * progmodes/python.el (ffap-alist): Declare. * textmodes/reftex.el (bibtex-mode-map): Declare. diff --git a/lisp/emacs-lisp/generic.el b/lisp/emacs-lisp/generic.el index cb86a554335..3eb64f9f7f0 100644 --- a/lisp/emacs-lisp/generic.el +++ b/lisp/emacs-lisp/generic.el @@ -44,11 +44,8 @@ ;; end at the end of the line.) Emacs does not support comment ;; strings of more than two characters in length. ;; -;; * List of keywords to font-lock. Each keyword should be a string. -;; If you have additional keywords which should be highlighted in a -;; face different from `font-lock-keyword-face', you can use the -;; convenience function `generic-make-keywords-list' (which see), -;; and add the result to the following list: +;; * List of keywords to font-lock in `font-lock-keyword-face'. +;; Each keyword should be a string. ;; ;; * Additional expressions to font-lock. This should be a list of ;; expressions, each of which should be of the same form as those in diff --git a/lisp/generic-x.el b/lisp/generic-x.el index 946b81992f8..1867759b549 100644 --- a/lisp/generic-x.el +++ b/lisp/generic-x.el @@ -483,38 +483,30 @@ like an INI file. You can add this hook to `find-file-hook'." ;; are frequently used in simple text, we punt.) ;; In `generic-bat-mode-setup-function' we make the keywords ;; case-insensitive - (generic-make-keywords-list - '("for" - "if") - font-lock-keyword-face "^[@ \t]*") + '("^[@ \t]*\\_<\\(for\\|if\\)\\_>" 1 font-lock-keyword-face) ;; These keywords can be anywhere on a line ;; In `generic-bat-mode-setup-function' we make the keywords ;; case-insensitive - (generic-make-keywords-list - '("do" - "exist" - "errorlevel" - "goto" - "not") - font-lock-keyword-face) + (list (regexp-opt '("do" "exist" "errorlevel" "goto" "not") 'symbols) + 1 font-lock-keyword-face) ;; These are built-in commands. Only frequently-used ones are listed. - (generic-make-keywords-list - '("CALL" "call" "Call" - "CD" "cd" "Cd" - "CLS" "cls" "Cls" - "COPY" "copy" "Copy" - "DEL" "del" "Del" - "ECHO" "echo" "Echo" - "MD" "md" "Md" - "PATH" "path" "Path" - "PAUSE" "pause" "Pause" - "PROMPT" "prompt" "Prompt" - "RD" "rd" "Rd" - "REN" "ren" "Ren" - "SET" "set" "Set" - "START" "start" "Start" - "SHIFT" "shift" "Shift") - font-lock-builtin-face "[ \t|\n]") + (list (concat "[ \t|\n]" + (regexp-opt '("CALL" "call" "Call" + "CD" "cd" "Cd" + "CLS" "cls" "Cls" + "COPY" "copy" "Copy" + "DEL" "del" "Del" + "ECHO" "echo" "Echo" + "MD" "md" "Md" + "PATH" "path" "Path" + "PAUSE" "pause" "Pause" + "PROMPT" "prompt" "Prompt" + "RD" "rd" "Rd" + "REN" "ren" "Ren" + "SET" "set" "Set" + "START" "start" "Start" + "SHIFT" "shift" "Shift") 'symbols)) + 1 font-lock-builtin-face) '("^[ \t]*\\(:\\sw+\\)" 1 font-lock-function-name-face t) '("\\(%\\sw+%\\)" 1 font-lock-variable-name-face t) '("\\(%[0-9]\\)" 1 font-lock-variable-name-face t) @@ -841,21 +833,16 @@ like an INI file. You can add this hook to `find-file-hook'." ;; the choice of face for each token group (eval-when-compile (list - (generic-make-keywords-list - '("FILEFLAGSMASK" - "FILEFLAGS" - "FILEOS" - "FILESUBTYPE" - "FILETYPE" - "FILEVERSION" - "PRODUCTVERSION") - font-lock-type-face) - (generic-make-keywords-list - '("BEGIN" - "BLOCK" - "END" - "VALUE") - font-lock-function-name-face) + (list (regexp-opt '("FILEFLAGSMASK" + "FILEFLAGS" + "FILEOS" + "FILESUBTYPE" + "FILETYPE" + "FILEVERSION" + "PRODUCTVERSION") 'symbols) + 1 font-lock-type-face) + (list (regexp-opt '("BEGIN" "BLOCK" "END" "VALUE") 'symbols) + 1 font-lock-function-name-face) '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face) '("^#[ \t]*define[ \t]+\\(\\sw+\\)(" 1 font-lock-function-name-face) '("^#[ \t]*\\(elif\\|if\\)\\>" @@ -1470,21 +1457,25 @@ like an INI file. You can add this hook to `find-file-hook'." (1 font-lock-keyword-face) (2 font-lock-constant-face nil t)) ;; system variables - (generic-make-keywords-list - installshield-system-variables-list - font-lock-variable-name-face "[^_]" "[^_]") + (list (concat "[^_]" + (regexp-opt installshield-system-variables-list 'symbols) + "[^_]") + 1 font-lock-variable-name-face) ;; system functions - (generic-make-keywords-list - installshield-system-functions-list - font-lock-function-name-face "[^_]" "[^_]") + (list (concat "[^_]" + (regexp-opt installshield-system-functions-list 'symbols) + "[^_]") + 1 font-lock-function-name-face) ;; type keywords - (generic-make-keywords-list - installshield-types-list - font-lock-type-face "[^_]" "[^_]") + (list (concat "[^_]" + (regexp-opt installshield-types-list 'symbols) + "[^_]") + 1 font-lock-type-face) ;; function argument constants - (generic-make-keywords-list - installshield-funarg-constants-list - font-lock-variable-name-face "[^_]" "[^_]"))) ; is this face the best choice? + (list (concat "[^_]" + (regexp-opt installshield-funarg-constants-list 'symbols) + "[^_]") + 1 font-lock-variable-name-face))) ; is this face the best choice? '("\\.[rR][uU][lL]\\'") '(generic-rul-mode-setup-function) "Generic mode for InstallShield RUL files.") -- cgit v1.2.3