changeset 72940:c2b72b555fc4

(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.
author Richard M. Stallman <rms@gnu.org>
date Sat, 16 Sep 2006 18:43:57 +0000
parents 980586804d04
children 9c3b1f40669d
files lisp/textmodes/conf-mode.el
diffstat 1 files changed, 33 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/textmodes/conf-mode.el	Sat Sep 16 18:23:05 2006 +0000
+++ b/lisp/textmodes/conf-mode.el	Sat Sep 16 18:43:57 2006 +0000
@@ -75,8 +75,8 @@
     (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 @@
     ("/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 @@
 		'(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 @@
   (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 @@
   (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 @@
   (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 @@
 	     (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
-	`(,@(cdr imenu-generic-expression)
-	  ("Parameters"
-	   ,(if conf-space-keywords
-		(concat "^[ \t]*\\(?:" conf-space-keywords
-			"\\)[ \t]+\\([^ \t\n]+\\)\\(?:[ \t]\\|$\\)")
-	      "^[ \t]*\\([^ \t\n[]+\\)\\(?:[ \t]\\|$\\)")
-	   1))))
+	(delq (assoc "Parameters" imenu-generic-expression)
+	      imenu-generic-expression))
+  ;; Add a new one based on conf-space-keywords.
+  (setq imenu-generic-expression
+	(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]"