changeset 61241:3f688bd09fa4

(define-generic-mode): Add argument to specify keywords for defcustom. (default-generic-mode): Specify :group.
author Lute Kamstra <lute@gnu.org>
date Sun, 03 Apr 2005 20:32:22 +0000
parents 7f013d492723
children 564aa8c276ca
files lisp/generic.el
diffstat 1 files changed, 23 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/generic.el	Sun Apr 03 17:03:15 2005 +0000
+++ b/lisp/generic.el	Sun Apr 03 20:32:22 2005 +0000
@@ -185,7 +185,8 @@
 ;;;###autoload
 (defmacro define-generic-mode (mode comment-list keyword-list
 				    font-lock-list auto-mode-list
-				    function-list &optional docstring)
+				    function-list &optional docstring
+				    &rest custom-keyword-args)
   "Create a new generic mode MODE.
 
 MODE is the name of the command for the generic mode; it need not
@@ -216,6 +217,11 @@
 FUNCTION-LIST is a list of functions to call to do some
 additional setup.
 
+The optional CUSTOM-KEYWORD-ARGS are pairs of keywords and
+values.  They will be passed to the generated `defcustom' form of
+the mode hook variable MODE-hook.  You can specify keyword
+arguments without specifying a docstring.
+
 See the file generic-x.el for some examples of `define-generic-mode'."
   (declare (debug (sexp def-form def-form def-form form def-form
 			&optional stringp))
@@ -224,11 +230,25 @@
   ;; Backward compatibility.
   (when (eq (car-safe mode) 'quote)
     (setq mode (eval mode)))
+
+  (when (and docstring (not (stringp docstring)))
+    ;; DOCSTRING is not a string so we assume that it's actually the
+    ;; first keyword of CUSTOM-KEYWORD-ARGS.
+    (push docstring custom-keyword-args)
+    (setq docstring nil))
+
   (let* ((mode-name (symbol-name mode))
 	 (pretty-name (capitalize (replace-regexp-in-string
 				   "-mode\\'" "" mode-name)))
 	 (mode-hook (intern (concat mode-name "-hook"))))
 
+    (unless (plist-get custom-keyword-args :group)
+      (setq custom-keyword-args
+	    (plist-put custom-keyword-args 
+		       :group `(or (custom-current-group)
+				   ',(intern (replace-regexp-in-string
+					      "-mode\\'" "" mode-name))))))
+
     `(progn
        ;; Add a new entry.
        (add-to-list 'generic-mode-list ,mode-name)
@@ -240,9 +260,7 @@
        (defcustom ,mode-hook nil
 	 ,(concat "Hook run when entering " pretty-name " mode.")
 	 :type 'hook
-	 :group (or (custom-current-group)
-		    ',(intern (replace-regexp-in-string
-			       "-mode\\'" "" mode-name))))
+	 ,@custom-keyword-args)
 
        (defun ,mode ()
 	 ,(or docstring
@@ -373,7 +391,7 @@
         imenu-case-fold-search t))
 
 ;; This generic mode is always defined
-(define-generic-mode default-generic-mode (list ?#) nil nil nil nil)
+(define-generic-mode default-generic-mode (list ?#) nil nil nil nil :group 'generic)
 
 ;; A more general solution would allow us to enter generic-mode for
 ;; *any* comment character, but would require us to synthesize a new