annotate lisp/custom/custom.el @ 120:cca96a509cfe r20-1b12

Import from CVS: tag r20-1b12
author cvs
date Mon, 13 Aug 2007 09:25:29 +0200
parents 7d55a9ba150c
children 9b50b4588a93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1 ;;; custom.el -- Tools for declaring and initializing options.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6 ;; Keywords: help, faces
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
7 ;; Version: 1.74
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
9
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
10 ;;; Commentary:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
11 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
12 ;; If you want to use this code, please visit the URL above.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
13 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
14 ;; This file only contain the code needed to declare and initialize
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
15 ;; user options. The code to customize options is autoloaded from
106
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
16 ;; `cus-edit.el'.
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
17
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
18 ;; The code implementing face declarations is in `cus-face.el'
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
19
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
20 ;;; Code:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
21
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
22 (require 'widget)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
23
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
24 (define-widget-keywords :prefix :tag :load :link :options :type :group)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
25
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
26 (defvar custom-define-hook nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
27 "Hook called after defining each customize option.")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
28
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
29 ;; These autoloads should be deleted when the file is added to Emacs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
30
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
31 (unless (fboundp 'load-gc)
106
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
32 ;; From cus-edit.el
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
33 (autoload 'customize "cus-edit" nil t)
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
34 (autoload 'customize-variable "cus-edit" nil t)
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
35 (autoload 'customize-face "cus-edit" nil t)
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
36 (autoload 'customize-apropos "cus-edit" nil t)
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
37 (autoload 'customize-customized "cus-edit" nil t)
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
38 (autoload 'custom-buffer-create "cus-edit")
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
39 (autoload 'custom-make-dependencies "cus-edit")
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
40 ;; From cus-face.el
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
41 (autoload 'custom-declare-face "cus-face")
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
42 (autoload 'custom-set-faces "cus-face"))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
43
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
44 ;;; The `defcustom' Macro.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
45
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
46 (defun custom-declare-variable (symbol value doc &rest args)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
47 "Like `defcustom', but SYMBOL and VALUE are evaluated as normal arguments."
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
48 ;; Bind this variable unless it already is bound.
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
49 (unless (default-boundp symbol)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
50 ;; Use the saved value if it exists, otherwise the factory setting.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
51 (set-default symbol (if (get symbol 'saved-value)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
52 (eval (car (get symbol 'saved-value)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
53 (eval value))))
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
54 ;; Remember the factory setting.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
55 (put symbol 'factory-value (list value))
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
56 ;; Maybe this option was rogue in an earlier version. It no longer is.
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
57 (when (get symbol 'force-value)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
58 ;; It no longer is.
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
59 (put symbol 'force-value nil))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
60 (when doc
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
61 (put symbol 'variable-documentation doc))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
62 (while args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
63 (let ((arg (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
64 (setq args (cdr args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
65 (unless (symbolp arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
66 (error "Junk in args %S" args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
67 (let ((keyword arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
68 (value (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
69 (unless args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
70 (error "Keyword %s is missing an argument" keyword))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
71 (setq args (cdr args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
72 (cond ((eq keyword :type)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
73 (put symbol 'custom-type value))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
74 ((eq keyword :options)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
75 (if (get symbol 'custom-options)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
76 ;; Slow safe code to avoid duplicates.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
77 (mapcar (lambda (option)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
78 (custom-add-option symbol option))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
79 value)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
80 ;; Fast code for the common case.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
81 (put symbol 'custom-options (copy-list value))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
82 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
83 (custom-handle-keyword symbol keyword value
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
84 'custom-variable))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
85 (run-hooks 'custom-define-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
86 symbol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
87
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
88 (defmacro defcustom (symbol value doc &rest args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
89 "Declare SYMBOL as a customizable variable that defaults to VALUE.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
90 DOC is the variable documentation.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
91
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
92 Neither SYMBOL nor VALUE needs to be quoted.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
93 If SYMBOL is not already bound, initialize it to VALUE.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
94 The remaining arguments should have the form
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
95
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
96 [KEYWORD VALUE]...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
97
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
98 The following KEYWORD's are defined:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
99
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
100 :type VALUE should be a widget type.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
101 :options VALUE should be a list of valid members of the widget type.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
102 :group VALUE should be a customization group.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
103 Add SYMBOL to that group.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
104
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
105 Read the section about customization in the emacs lisp manual for more
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
106 information."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
107 `(eval-and-compile
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
108 (custom-declare-variable (quote ,symbol) (quote ,value) ,doc ,@args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
109
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
110 ;;; The `defface' Macro.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
111
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
112 (defmacro defface (face spec doc &rest args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
113 "Declare FACE as a customizable face that defaults to SPEC.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
114 FACE does not need to be quoted.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
115
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
116 Third argument DOC is the face documentation.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
117
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
118 If FACE has been set with `custom-set-face', set the face attributes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
119 as specified by that function, otherwise set the face attributes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
120 according to SPEC.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
121
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
122 The remaining arguments should have the form
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
123
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
124 [KEYWORD VALUE]...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
125
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
126 The following KEYWORD's are defined:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
127
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
128 :group VALUE should be a customization group.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
129 Add FACE to that group.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
130
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
131 SPEC should be an alist of the form ((DISPLAY ATTS)...).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
132
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
133 ATTS is a list of face attributes and their values. The possible
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
134 attributes are defined in the variable `custom-face-attributes'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
135 Alternatively, ATTS can be a face in which case the attributes of that
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
136 face is used.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
137
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
138 The ATTS of the first entry in SPEC where the DISPLAY matches the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
139 frame should take effect in that frame. DISPLAY can either be the
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
140 symbol t, which will match all frames, or an alist of the form
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
141 \((REQ ITEM...)...)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
142
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
143 For the DISPLAY to match a FRAME, the REQ property of the frame must
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
144 match one of the ITEM. The following REQ are defined:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
145
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
146 `type' (the value of `window-system')
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
147 Should be one of `x' or `tty'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
148
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
149 `class' (the frame's color support)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
150 Should be one of `color', `grayscale', or `mono'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
151
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
152 `background' (what color is used for the background text)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
153 Should be one of `light' or `dark'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
154
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
155 Read the section about customization in the emacs lisp manual for more
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
156 information."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
157 `(custom-declare-face (quote ,face) ,spec ,doc ,@args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
158
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
159 ;;; The `defgroup' Macro.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
160
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
161 (defun custom-declare-group (symbol members doc &rest args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
162 "Like `defgroup', but SYMBOL is evaluated as a normal argument."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
163 (put symbol 'custom-group (nconc members (get symbol 'custom-group)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
164 (when doc
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
165 (put symbol 'group-documentation doc))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
166 (while args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
167 (let ((arg (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
168 (setq args (cdr args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
169 (unless (symbolp arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
170 (error "Junk in args %S" args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
171 (let ((keyword arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
172 (value (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
173 (unless args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
174 (error "Keyword %s is missing an argument" keyword))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
175 (setq args (cdr args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
176 (cond ((eq keyword :prefix)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
177 (put symbol 'custom-prefix value))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
178 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
179 (custom-handle-keyword symbol keyword value
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
180 'custom-group))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
181 (run-hooks 'custom-define-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
182 symbol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
183
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
184 (defmacro defgroup (symbol members doc &rest args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
185 "Declare SYMBOL as a customization group containing MEMBERS.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
186 SYMBOL does not need to be quoted.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
187
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
188 Third arg DOC is the group documentation.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
189
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
190 MEMBERS should be an alist of the form ((NAME WIDGET)...) where
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
191 NAME is a symbol and WIDGET is a widget is a widget for editing that
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
192 symbol. Useful widgets are `custom-variable' for editing variables,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
193 `custom-face' for edit faces, and `custom-group' for editing groups.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
194
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
195 The remaining arguments should have the form
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
196
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
197 [KEYWORD VALUE]...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
198
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
199 The following KEYWORD's are defined:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
200
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
201 :group VALUE should be a customization group.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
202 Add SYMBOL to that group.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
203
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
204 Read the section about customization in the emacs lisp manual for more
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
205 information."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
206 `(custom-declare-group (quote ,symbol) ,members ,doc ,@args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
207
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
208 (defun custom-add-to-group (group option widget)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
209 "To existing GROUP add a new OPTION of type WIDGET.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
210 If there already is an entry for that option, overwrite it."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
211 (let* ((members (get group 'custom-group))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
212 (old (assq option members)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
213 (if old
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
214 (setcar (cdr old) widget)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
215 (put group 'custom-group (nconc members (list (list option widget)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
216
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
217 ;;; Properties.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
218
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
219 (defun custom-handle-all-keywords (symbol args type)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
220 "For customization option SYMBOL, handle keyword arguments ARGS.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
221 Third argument TYPE is the custom option type."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
222 (while args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
223 (let ((arg (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
224 (setq args (cdr args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
225 (unless (symbolp arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
226 (error "Junk in args %S" args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
227 (let ((keyword arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
228 (value (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
229 (unless args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
230 (error "Keyword %s is missing an argument" keyword))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
231 (setq args (cdr args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
232 (custom-handle-keyword symbol keyword value type)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
233
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
234 (defun custom-handle-keyword (symbol keyword value type)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
235 "For customization option SYMBOL, handle KEYWORD with VALUE.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
236 Fourth argument TYPE is the custom option type."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
237 (cond ((eq keyword :group)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
238 (custom-add-to-group value symbol type))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
239 ((eq keyword :link)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
240 (custom-add-link symbol value))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
241 ((eq keyword :load)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
242 (custom-add-load symbol value))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
243 ((eq keyword :tag)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
244 (put symbol 'custom-tag value))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
245 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
246 (error "Unknown keyword %s" symbol))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
247
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
248 (defun custom-add-option (symbol option)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
249 "To the variable SYMBOL add OPTION.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
250
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
251 If SYMBOL is a hook variable, OPTION should be a hook member.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
252 For other types variables, the effect is undefined."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
253 (let ((options (get symbol 'custom-options)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
254 (unless (member option options)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
255 (put symbol 'custom-options (cons option options)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
256
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
257 (defun custom-add-link (symbol widget)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
258 "To the custom option SYMBOL add the link WIDGET."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
259 (let ((links (get symbol 'custom-links)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
260 (unless (member widget links)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
261 (put symbol 'custom-links (cons widget links)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
262
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
263 (defun custom-add-load (symbol load)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
264 "To the custom option SYMBOL add the dependency LOAD.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
265 LOAD should be either a library file name, or a feature name."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
266 (let ((loads (get symbol 'custom-loads)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
267 (unless (member load loads)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
268 (put symbol 'custom-loads (cons load loads)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
269
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
270 ;;; Initializing.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
271
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
272 (defun custom-set-variables (&rest args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
273 "Initialize variables according to user preferences.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
274
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
275 The arguments should be a list where each entry has the form:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
276
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
277 (SYMBOL VALUE [NOW])
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
278
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
279 The unevaluated VALUE is stored as the saved value for SYMBOL.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
280 If NOW is present and non-nil, VALUE is also evaluated and bound as
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
281 the default value for the SYMBOL."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
282 (while args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
283 (let ((entry (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
284 (if (listp entry)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
285 (let ((symbol (nth 0 entry))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
286 (value (nth 1 entry))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
287 (now (nth 2 entry)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
288 (put symbol 'saved-value (list value))
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
289 (cond (now
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
290 ;; Rogue variable, set it now.
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
291 (put symbol 'force-value t)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
292 (set-default symbol (eval value)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
293 ((default-boundp symbol)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
294 ;; Something already set this, overwrite it.
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
295 (set-default symbol (eval value))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
296 (setq args (cdr args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
297 ;; Old format, a plist of SYMBOL VALUE pairs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
298 (let ((symbol (nth 0 args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
299 (value (nth 1 args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
300 (put symbol 'saved-value (list value)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
301 (setq args (cdr (cdr args)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
302
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
303 ;;; The End.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
304
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
305 (provide 'custom)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
306
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
307 ;; custom.el ends here