From d36326319a53963859045b4adb5ca6f0e33a2206 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Sat, 9 Sep 2006 23:20:39 +0000 Subject: (conf-space-mode): Use hack-local-variables-hook instead of calling hack-local-variables. (conf-space-keywords-override): New variable. --- lisp/textmodes/conf-mode.el | 65 +++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 26 deletions(-) (limited to 'lisp/textmodes/conf-mode.el') diff --git a/lisp/textmodes/conf-mode.el b/lisp/textmodes/conf-mode.el index e762f87f328..a44eeefa56a 100644 --- a/lisp/textmodes/conf-mode.el +++ b/lisp/textmodes/conf-mode.el @@ -442,6 +442,9 @@ x.2.y.1.z.2.zz =" (setq imenu-generic-expression '(("Parameters" "^[ \t]*\\(.+?\\)[=: \t]" 1)))) +(defvar conf-space-keywords-override nil + "Value to be put in `conf-space-keywords' after `conf-space-mode'.") + ;;;###autoload (define-derived-mode conf-space-mode conf-unix-mode "Conf[Space]" "Conf Mode starter for space separated conf files. @@ -465,34 +468,44 @@ class desktop add /dev/audio desktop add /dev/mixer desktop" (conf-mode-initialize "#" 'conf-space-font-lock-keywords) - (set (make-local-variable 'conf-assignment-sign) - nil) - ;; This doesn't seem right, but the next two depend on conf-space-keywords - ;; being set, while after-change-major-mode-hook might set up imenu, needing - ;; the following result: - (hack-local-variables-prop-line) - (hack-local-variables) + (make-local-variable 'conf-assignment-sign) + (setq conf-assignment-sign nil) (cond (current-prefix-arg - (set (make-local-variable 'conf-space-keywords) - (if (> (prefix-numeric-value current-prefix-arg) 0) - (read-string "Regexp to match keywords: ")))) - (conf-space-keywords) + (make-local-variable 'conf-space-keywords-override) + ;; By setting conf-space-keywords-override + ;; we arrange for the hook function below + ;; to override any value of conf-space-keywords + ;; specified in a local variables list. + (setq conf-space-keywords-override + (if (> (prefix-numeric-value current-prefix-arg) 0) + (read-string "Regexp to match keywords: ")))) (buffer-file-name - (set (make-local-variable 'conf-space-keywords) - (assoc-default buffer-file-name conf-space-keywords-alist - 'string-match)))) - (set (make-local-variable 'conf-assignment-regexp) - (if conf-space-keywords - (concat "\\(?:" conf-space-keywords "\\)[ \t]+.+?\\([ \t]+\\|$\\)") - ".+?\\([ \t]+\\|$\\)")) - (setq imenu-generic-expression - `(,@(cdr imenu-generic-expression) - ("Parameters" - ,(if conf-space-keywords - (concat "^[ \t]*\\(?:" conf-space-keywords - "\\)[ \t]+\\([^ \t\n]+\\)\\(?:[ \t]\\|$\\)") - "^[ \t]*\\([^ \t\n[]+\\)\\(?:[ \t]\\|$\\)") - 1)))) + ;; By setting conf-space-keywords directly, + ;; we let a value in the local variables list take precedence. + (make-local-variable 'conf-space-keywords) + (setq conf-space-keywords + (assoc-default buffer-file-name conf-space-keywords-alist + 'string-match)))) + ;; This is stuff to be done after parsing the local variables, once + ;; any local variable spec fo rconf-space-keywords is already in effect. + (push (lambda () + (when conf-space-keywords-override + (setq conf-space-keywords + conf-space-keywords-override)) + (make-local-variable 'conf-assignment-regexp) + (setq conf-assignment-regexp + (if conf-space-keywords + (concat "\\(?:" conf-space-keywords "\\)[ \t]+.+?\\([ \t]+\\|$\\)") + ".+?\\([ \t]+\\|$\\)")) + (setq imenu-generic-expression + `(,@(cdr imenu-generic-expression) + ("Parameters" + ,(if conf-space-keywords + (concat "^[ \t]*\\(?:" conf-space-keywords + "\\)[ \t]+\\([^ \t\n]+\\)\\(?:[ \t]\\|$\\)") + "^[ \t]*\\([^ \t\n[]+\\)\\(?:[ \t]\\|$\\)") + 1)))) + hack-local-variables-hook)) ;;;###autoload (define-derived-mode conf-colon-mode conf-unix-mode "Conf[Colon]" -- cgit v1.2.3 From dd3a63bf1a7b799d25c932fbb6a1bbced7470eee Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Sun, 10 Sep 2006 00:30:52 +0000 Subject: (conf-space-mode-internal): New subroutine. Reinit Font Lock mode. (conf-space-mode): Always make conf-space-keywords and conf-space-keywords-override local. Call conf-space-mode-internal directly as well as via hook. --- lisp/ChangeLog | 4 ++++ lisp/textmodes/conf-mode.el | 55 ++++++++++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 21 deletions(-) (limited to 'lisp/textmodes/conf-mode.el') diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5f94fa6f83a..c9aa615145e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -3,6 +3,10 @@ * textmodes/conf-mode.el (conf-space-mode): Use hack-local-variables-hook instead of calling hack-local-variables. (conf-space-keywords-override): New variable. + (conf-space-mode-internal): New subroutine. Reinit Font Lock mode. + (conf-space-mode): Always make conf-space-keywords and + conf-space-keywords-override local. + Call conf-space-mode-internal directly as well as via hook. 2006-09-09 Slawomir Nowaczyk (tiny change) diff --git a/lisp/textmodes/conf-mode.el b/lisp/textmodes/conf-mode.el index a44eeefa56a..a3471f16480 100644 --- a/lisp/textmodes/conf-mode.el +++ b/lisp/textmodes/conf-mode.el @@ -470,15 +470,19 @@ add /dev/mixer desktop" (conf-mode-initialize "#" 'conf-space-font-lock-keywords) (make-local-variable 'conf-assignment-sign) (setq conf-assignment-sign nil) + (make-local-variable 'conf-space-keywords) + (make-local-variable 'conf-space-keywords-override) + (setq conf-space-keywords-override nil) (cond (current-prefix-arg - (make-local-variable 'conf-space-keywords-override) ;; By setting conf-space-keywords-override - ;; we arrange for the hook function below + ;; we arrange for conf-space-mode-internal ;; to override any value of conf-space-keywords ;; specified in a local variables list. (setq conf-space-keywords-override (if (> (prefix-numeric-value current-prefix-arg) 0) (read-string "Regexp to match keywords: ")))) + ;; If this is already set, don't replace it with the default. + (conf-space-keywords) (buffer-file-name ;; By setting conf-space-keywords directly, ;; we let a value in the local variables list take precedence. @@ -486,27 +490,36 @@ add /dev/mixer desktop" (setq conf-space-keywords (assoc-default buffer-file-name conf-space-keywords-alist 'string-match)))) - ;; This is stuff to be done after parsing the local variables, once - ;; any local variable spec fo rconf-space-keywords is already in effect. - (push (lambda () - (when conf-space-keywords-override - (setq conf-space-keywords - conf-space-keywords-override)) - (make-local-variable 'conf-assignment-regexp) - (setq conf-assignment-regexp - (if conf-space-keywords - (concat "\\(?:" conf-space-keywords "\\)[ \t]+.+?\\([ \t]+\\|$\\)") - ".+?\\([ \t]+\\|$\\)")) - (setq imenu-generic-expression - `(,@(cdr imenu-generic-expression) - ("Parameters" - ,(if conf-space-keywords - (concat "^[ \t]*\\(?:" conf-space-keywords - "\\)[ \t]+\\([^ \t\n]+\\)\\(?:[ \t]\\|$\\)") - "^[ \t]*\\([^ \t\n[]+\\)\\(?:[ \t]\\|$\\)") - 1)))) + (conf-space-mode-internal) + ;; In case the local variables list specifies conf-space-keywords, + ;; recompute other things from that afterward. + (push 'conf-space-mode-internal hack-local-variables-hook)) +(defun conf-space-mode-internal () + (when conf-space-keywords-override + (setq conf-space-keywords + conf-space-keywords-override)) + (make-local-variable 'conf-assignment-regexp) + (setq conf-assignment-regexp + (if conf-space-keywords + (concat "\\(?:" conf-space-keywords "\\)[ \t]+.+?\\([ \t]+\\|$\\)") + ".+?\\([ \t]+\\|$\\)")) + ;; If Font Lock is already enabled, reenable it with new + ;; conf-assignment-regexp. + (when (and font-lock-mode + (boundp 'font-lock-keywords)) ;see `normal-mode' + (font-lock-add-keywords nil nil) + (font-lock-mode 1)) + (setq imenu-generic-expression + `(,@(cdr imenu-generic-expression) + ("Parameters" + ,(if conf-space-keywords + (concat "^[ \t]*\\(?:" conf-space-keywords + "\\)[ \t]+\\([^ \t\n]+\\)\\(?:[ \t]\\|$\\)") + "^[ \t]*\\([^ \t\n[]+\\)\\(?:[ \t]\\|$\\)") + 1)))) + ;;;###autoload (define-derived-mode conf-colon-mode conf-unix-mode "Conf[Colon]" "Conf Mode starter for Colon files. -- cgit v1.2.3 From 8969e90653c1d7feaa0599c21c4b6e84165cb3f7 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Sat, 16 Sep 2006 18:43:57 +0000 Subject: (conf-mode-map): Use conf-space-keywords cmd. (conf-space-mode): Don't handle prefix arg. Delete conf-space-keywords-override code. Use add-hook. (conf-space-keywords): New command. (conf-space-mode-internal): Be careful with imenu-generic-expression. Delete conf-space-keywords-override code. (conf-space-keywords-alist): Doc fix. (conf-space-font-lock-keywords): Doc fix. (conf-space-keywords-override): Var deleted. --- lisp/textmodes/conf-mode.el | 66 ++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'lisp/textmodes/conf-mode.el') diff --git a/lisp/textmodes/conf-mode.el b/lisp/textmodes/conf-mode.el index a3471f16480..98a81831dd4 100644 --- a/lisp/textmodes/conf-mode.el +++ b/lisp/textmodes/conf-mode.el @@ -75,8 +75,8 @@ not align (only setting space according to `conf-assignment-space')." (define-key map "\C-c\C-u" 'conf-unix-mode) (define-key map "\C-c\C-w" 'conf-windows-mode) (define-key map "\C-c\C-j" 'conf-javaprop-mode) - (define-key map "\C-c\C-s" 'conf-space-mode) - (define-key map "\C-c " 'conf-space-mode) + (define-key map "\C-c\C-s" 'conf-space-keywords) + (define-key map "\C-c " 'conf-space-keywords) (define-key map "\C-c\C-c" 'conf-colon-mode) (define-key map "\C-c:" 'conf-colon-mode) (define-key map "\C-c\C-x" 'conf-xdefaults-mode) @@ -168,7 +168,7 @@ not align (only setting space according to `conf-assignment-space')." ("/resmgr\\.conf" . "class\\|add\\|allow\\|deny") ("/dictionary\\.lst\\'" . "DICT\\|HYPH\\|THES") ("/tuxracer/options" . "set")) - "File name based settings for `conf-space-keywords'.") + "File-name-based settings for the variable `conf-space-keywords'.") (defvar conf-space-keywords nil "Regexps for functions that may come before a space assignment. @@ -188,7 +188,7 @@ This variable is best set in the file local variables, or through '(1 'font-lock-keyword-face) '(2 'font-lock-variable-name-face)) '("^[ \t]*\\([^\000- ]+\\)" 1 'font-lock-variable-name-face))) - "Keywords to hilight in Conf Space mode.") + "Keywords to highlight in Conf Space mode.") (defvar conf-colon-font-lock-keywords `(;; [section] (do this first because it may look like a parameter) @@ -442,14 +442,11 @@ x.2.y.1.z.2.zz =" (setq imenu-generic-expression '(("Parameters" "^[ \t]*\\(.+?\\)[=: \t]" 1)))) -(defvar conf-space-keywords-override nil - "Value to be put in `conf-space-keywords' after `conf-space-mode'.") - ;;;###autoload (define-derived-mode conf-space-mode conf-unix-mode "Conf[Space]" "Conf Mode starter for space separated conf files. \"Assignments\" are with ` '. Keywords before the parameters are -recognized according to `conf-space-keywords'. Interactively +recognized according to the variable `conf-space-keywords'. Interactively with a prefix ARG of `0' no keywords will be recognized. With any other prefix arg you will be prompted for a regexp to match the keywords. @@ -471,19 +468,7 @@ add /dev/mixer desktop" (make-local-variable 'conf-assignment-sign) (setq conf-assignment-sign nil) (make-local-variable 'conf-space-keywords) - (make-local-variable 'conf-space-keywords-override) - (setq conf-space-keywords-override nil) - (cond (current-prefix-arg - ;; By setting conf-space-keywords-override - ;; we arrange for conf-space-mode-internal - ;; to override any value of conf-space-keywords - ;; specified in a local variables list. - (setq conf-space-keywords-override - (if (> (prefix-numeric-value current-prefix-arg) 0) - (read-string "Regexp to match keywords: ")))) - ;; If this is already set, don't replace it with the default. - (conf-space-keywords) - (buffer-file-name + (cond (buffer-file-name ;; By setting conf-space-keywords directly, ;; we let a value in the local variables list take precedence. (make-local-variable 'conf-space-keywords) @@ -493,13 +478,21 @@ add /dev/mixer desktop" (conf-space-mode-internal) ;; In case the local variables list specifies conf-space-keywords, ;; recompute other things from that afterward. - (push 'conf-space-mode-internal - hack-local-variables-hook)) + (add-hook 'hack-local-variables-hook 'conf-space-mode-internal nil t)) + +(defun conf-space-keywords (keywords) + "Enter Conf Space mode using regexp KEYWORDS to match the keywords. +See `conf-space-mode'." + (interactive "sConf Space keyword regexp: ") + (delay-mode-hooks + (conf-space-mode)) + (if (string-equal keyword "") + (setq keywords nil)) + (setq conf-space-keywords keywords) + (conf-space-mode-internal) + (run-mode-hooks)) (defun conf-space-mode-internal () - (when conf-space-keywords-override - (setq conf-space-keywords - conf-space-keywords-override)) (make-local-variable 'conf-assignment-regexp) (setq conf-assignment-regexp (if conf-space-keywords @@ -511,14 +504,21 @@ add /dev/mixer desktop" (boundp 'font-lock-keywords)) ;see `normal-mode' (font-lock-add-keywords nil nil) (font-lock-mode 1)) + ;; Copy so that we don't destroy shared structure. + (setq imenu-generic-expression (copy-sequence imenu-generic-expression)) + ;; Get rid of any existing Parameters element. + (setq imenu-generic-expression + (delq (assoc "Parameters" imenu-generic-expression) + imenu-generic-expression)) + ;; Add a new one based on conf-space-keywords. (setq imenu-generic-expression - `(,@(cdr imenu-generic-expression) - ("Parameters" - ,(if conf-space-keywords - (concat "^[ \t]*\\(?:" conf-space-keywords - "\\)[ \t]+\\([^ \t\n]+\\)\\(?:[ \t]\\|$\\)") - "^[ \t]*\\([^ \t\n[]+\\)\\(?:[ \t]\\|$\\)") - 1)))) + (cons `("Parameters" + ,(if conf-space-keywords + (concat "^[ \t]*\\(?:" conf-space-keywords + "\\)[ \t]+\\([^ \t\n]+\\)\\(?:[ \t]\\|$\\)") + "^[ \t]*\\([^ \t\n[]+\\)\\(?:[ \t]\\|$\\)") + 1) + imenu-generic-expression))) ;;;###autoload (define-derived-mode conf-colon-mode conf-unix-mode "Conf[Colon]" -- cgit v1.2.3 From e5e0a7db2646824a6231feb06d2a690757a391ad Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Mon, 18 Sep 2006 17:19:16 +0000 Subject: (conf-space-mode): Doc fix. Delete duplicate make-local-variable form. (conf-space-keywords): Add autoload cookie. Fix typo (`keywords', not `keyword'). --- lisp/textmodes/conf-mode.el | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'lisp/textmodes/conf-mode.el') diff --git a/lisp/textmodes/conf-mode.el b/lisp/textmodes/conf-mode.el index 98a81831dd4..f7a725242ed 100644 --- a/lisp/textmodes/conf-mode.el +++ b/lisp/textmodes/conf-mode.el @@ -446,10 +446,11 @@ x.2.y.1.z.2.zz =" (define-derived-mode conf-space-mode conf-unix-mode "Conf[Space]" "Conf Mode starter for space separated conf files. \"Assignments\" are with ` '. Keywords before the parameters are -recognized according to the variable `conf-space-keywords'. Interactively -with a prefix ARG of `0' no keywords will be recognized. With -any other prefix arg you will be prompted for a regexp to match -the keywords. +recognized according to the variable `conf-space-keywords-alist'. +Alternatively, you can specify a value for the file local variable +`conf-space-keywords'. +Use the function `conf-space-keywords' if you want to specify keywords +in an interactive fashion instead. For details see `conf-mode'. Example: @@ -469,9 +470,9 @@ add /dev/mixer desktop" (setq conf-assignment-sign nil) (make-local-variable 'conf-space-keywords) (cond (buffer-file-name - ;; By setting conf-space-keywords directly, - ;; we let a value in the local variables list take precedence. - (make-local-variable 'conf-space-keywords) + ;; We set conf-space-keywords directly, but a value which is + ;; in the local variables list or interactively specified + ;; (see the function conf-space-keywords) takes precedence. (setq conf-space-keywords (assoc-default buffer-file-name conf-space-keywords-alist 'string-match)))) @@ -480,13 +481,14 @@ add /dev/mixer desktop" ;; recompute other things from that afterward. (add-hook 'hack-local-variables-hook 'conf-space-mode-internal nil t)) +;;;###autoload (defun conf-space-keywords (keywords) "Enter Conf Space mode using regexp KEYWORDS to match the keywords. See `conf-space-mode'." (interactive "sConf Space keyword regexp: ") (delay-mode-hooks (conf-space-mode)) - (if (string-equal keyword "") + (if (string-equal keywords "") (setq keywords nil)) (setq conf-space-keywords keywords) (conf-space-mode-internal) @@ -517,7 +519,7 @@ See `conf-space-mode'." (concat "^[ \t]*\\(?:" conf-space-keywords "\\)[ \t]+\\([^ \t\n]+\\)\\(?:[ \t]\\|$\\)") "^[ \t]*\\([^ \t\n[]+\\)\\(?:[ \t]\\|$\\)") - 1) + 1) imenu-generic-expression))) ;;;###autoload -- cgit v1.2.3