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