Mercurial > hg > xemacs-beta
annotate lisp/custom.el @ 5461:568ec109e73d
Check types (unless `byte-compile-delete-errors' is t), #'char<, #'char=, etc.
src/ChangeLog addition:
2011-04-23 Aidan Kehoe <kehoea@parhasard.net>
* editfns.c:
* editfns.c (syms_of_editfns):
Implement #'char= in cl-extra.el, not here, accepting more than
two arguments as Common Lisp specifies.
lisp/ChangeLog addition:
2011-04-23 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (define-char-comparisons):
Add type-checking when the various character-specific comparison
predicates are used; don't check types if
byte-compile-delete-errors is non-nil at compile-time, instead use
the corresponding built-in numeric byte codes.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 23 Apr 2011 22:42:10 +0100 |
parents | 294ab9180fad |
children | 4dee0387b9de |
rev | line source |
---|---|
2544 | 1 ;;; custom.el --- tools for declaring and initializing options |
2 ;; | |
3 ;; Copyright (C) 1996, 1997, 1999, 2001, 2002 Free Software Foundation, Inc. | |
4 ;; | |
428 | 5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> |
2544 | 6 ;; Maintainer: XEmacs Development Group |
428 | 7 ;; Keywords: help, faces, dumped |
8 | |
9 ;; This file is part of XEmacs. | |
10 | |
11 ;; XEmacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; XEmacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with XEmacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
2544 | 26 ;;; Synched with: FSF 21.3. |
1333 | 27 |
428 | 28 ;;; Commentary: |
29 | |
30 ;; This file is dumped with XEmacs. | |
31 | |
2544 | 32 ;; |
33 ;; This file only contains the code needed to declare and initialize | |
428 | 34 ;; user options. The code to customize options is autoloaded from |
2544 | 35 ;; `cus-edit.el' and is documented in the XEmacs Lisp Reference manual. |
36 | |
37 ;; The code implementing face declarations is in `cus-face.el'. | |
428 | 38 |
39 ;;; Code: | |
40 | |
771 | 41 ;; it is now safe to put the `provide' anywhere. if an error occurs while |
42 ;; loading, all provides (and fsets) will be undone. put it first to | |
43 ;; prevent require/provide loop with custom and cus-face. | |
44 (provide 'custom) | |
45 | |
428 | 46 (eval-when-compile |
771 | 47 ;; To elude warnings. |
48 (require 'cus-face)) | |
428 | 49 |
442 | 50 (autoload 'custom-declare-face "cus-face") |
428 | 51 |
52 (require 'widget) | |
53 | |
54 (defvar custom-define-hook nil | |
55 ;; Customize information for this option is in `cus-edit.el'. | |
56 "Hook called after defining each customize option.") | |
57 | |
2544 | 58 (defvar custom-dont-initialize nil |
59 "Non-nil means `defcustom' should not initialize the variable. | |
60 That is used for the sake of `custom-make-dependencies'. | |
61 Users should not set it.") | |
62 | |
63 (defvar custom-current-group-alist nil | |
64 "Alist of (FILE . GROUP) indicating the current group to use for FILE.") | |
65 | |
428 | 66 ;;; The `defcustom' Macro. |
67 | |
68 (defun custom-initialize-default (symbol value) | |
69 "Initialize SYMBOL with VALUE. | |
70 This will do nothing if symbol already has a default binding. | |
71 Otherwise, if symbol has a `saved-value' property, it will evaluate | |
72 the car of that and used as the default binding for symbol. | |
73 Otherwise, VALUE will be evaluated and used as the default binding for | |
74 symbol." | |
75 (unless (default-boundp symbol) | |
76 ;; Use the saved value if it exists, otherwise the standard setting. | |
77 (set-default symbol (if (get symbol 'saved-value) | |
78 (eval (car (get symbol 'saved-value))) | |
79 (eval value))))) | |
80 | |
81 (defun custom-initialize-set (symbol value) | |
82 "Initialize SYMBOL with VALUE. | |
1333 | 83 If the symbol doesn't have a default binding already, |
84 then set it using its `:set' function (or `set-default' if it has none). | |
85 The value is either the value in the symbol's `saved-value' property, | |
86 if any, or VALUE. | |
87 | |
88 This is like `custom-initialize-default', but uses the function specified by | |
428 | 89 `:set' to initialize SYMBOL." |
90 (unless (default-boundp symbol) | |
91 (funcall (or (get symbol 'custom-set) 'set-default) | |
92 symbol | |
93 (if (get symbol 'saved-value) | |
94 (eval (car (get symbol 'saved-value))) | |
95 (eval value))))) | |
96 | |
97 (defun custom-initialize-reset (symbol value) | |
98 "Initialize SYMBOL with VALUE. | |
1333 | 99 Set the symbol, using its `:set' function (or `set-default' if it has none). |
100 The value is either the symbol's current value | |
101 \(as obtained using the `:get' function), if any, | |
102 or the value in the symbol's `saved-value' property if any, | |
103 or (last of all) VALUE. | |
104 | |
428 | 105 Like `custom-initialize-set', but use the function specified by |
106 `:get' to reinitialize SYMBOL if it is already bound." | |
107 (funcall (or (get symbol 'custom-set) 'set-default) | |
108 symbol | |
109 (cond ((default-boundp symbol) | |
110 (funcall (or (get symbol 'custom-get) 'default-value) | |
111 symbol)) | |
112 ((get symbol 'saved-value) | |
113 (eval (car (get symbol 'saved-value)))) | |
114 (t | |
115 (eval value))))) | |
116 | |
4289 | 117 ;; XEmacs change; move to defsubst, since this is only called in one place |
118 ;; and usage of it clusters. | |
119 (defsubst custom-initialize-changed (symbol value) | |
428 | 120 "Initialize SYMBOL with VALUE. |
4289 | 121 Like `custom-initialize-reset', but only use the `:set' function if |
1333 | 122 not using the standard setting. |
123 For the standard setting, use `set-default'." | |
428 | 124 (cond ((default-boundp symbol) |
125 (funcall (or (get symbol 'custom-set) 'set-default) | |
126 symbol | |
127 (funcall (or (get symbol 'custom-get) 'default-value) | |
128 symbol))) | |
129 ((get symbol 'saved-value) | |
130 (funcall (or (get symbol 'custom-set) 'set-default) | |
131 symbol | |
132 (eval (car (get symbol 'saved-value))))) | |
133 (t | |
134 (set-default symbol (eval value))))) | |
135 | |
1333 | 136 (defun custom-declare-variable (symbol default doc &rest args) |
137 "Like `defcustom', but SYMBOL and DEFAULT are evaluated as normal arguments. | |
138 DEFAULT should be an expression to evaluate to compute the default value, | |
2544 | 139 not the default value itself. |
140 | |
141 DEFAULT is stored as SYMBOL's value in the standard theme. See | |
142 `custom-known-themes' for a list of known themes. For backwards | |
143 compatibility, DEFAULT is also stored in SYMBOL's property | |
144 `standard-value'. At the same time, SYMBOL's property `force-value' is | |
4289 | 145 set to nil, as the value is no longer rogue. |
146 | |
147 The byte compiler adds an XEmacs-specific :default keyword and value to | |
148 `custom-declare-variable' calls when it byte-compiles the DEFAULT argument. | |
149 These describe what the custom UI shows when editing a customizable | |
150 variable's associated Lisp expression. We don't encourage use of this | |
151 keyword in your own programs. " | |
2544 | 152 ;; Remember the standard setting. The value should be in the standard |
4289 | 153 ;; theme, not in this property. However, this would require changing |
2544 | 154 ;; the C source of defvar and others as well... |
1333 | 155 (put symbol 'standard-value (list default)) |
428 | 156 ;; Maybe this option was rogue in an earlier version. It no longer is. |
157 (when (eq (get symbol 'force-value) 'rogue) | |
158 ;; It no longer is. | |
159 (put symbol 'force-value nil)) | |
160 (when doc | |
161 (put symbol 'variable-documentation doc)) | |
162 (let ((initialize 'custom-initialize-reset) | |
2544 | 163 (requests nil)) |
164 (unless (memq :group args) | |
165 (custom-add-to-group (custom-current-group) symbol 'custom-variable)) | |
428 | 166 (while args |
167 (let ((arg (car args))) | |
2544 | 168 (setq args (cdr args)) |
428 | 169 (check-argument-type 'keywordp arg) |
2544 | 170 (let ((keyword arg) |
171 (value (car args))) | |
172 (unless args | |
428 | 173 (signal 'error (list "Keyword is missing an argument" keyword))) |
2544 | 174 (setq args (cdr args)) |
175 (cond ((eq keyword :initialize) | |
176 (setq initialize value)) | |
177 ((eq keyword :set) | |
178 (put symbol 'custom-set value)) | |
179 ((eq keyword :get) | |
180 (put symbol 'custom-get value)) | |
181 ((eq keyword :require) | |
182 (push value requests)) | |
183 ((eq keyword :type) | |
5229
7d06a8bf47d2
Move #'purecopy from alloc.c to being an obsolete alias for #'identity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4744
diff
changeset
|
184 (put symbol 'custom-type value)) |
2544 | 185 ((eq keyword :options) |
186 (if (get symbol 'custom-options) | |
187 ;; Slow safe code to avoid duplicates. | |
188 (mapc (lambda (option) | |
189 (custom-add-option symbol option)) | |
190 value) | |
191 ;; Fast code for the common case. | |
192 (put symbol 'custom-options (copy-sequence value)))) | |
4289 | 193 ;; In the event that the byte compile has compiled the init |
194 ;; value, we want the value the UI sees to be uncompiled. | |
195 ((eq keyword :default) | |
196 (put symbol 'standard-value (list value))) | |
2544 | 197 (t |
198 (custom-handle-keyword symbol keyword value | |
199 'custom-variable)))))) | |
428 | 200 (put symbol 'custom-requests requests) |
201 ;; Do the actual initialization. | |
2544 | 202 (unless custom-dont-initialize |
203 (funcall initialize symbol default))) | |
4539
061e030e3270
Fix some bugs in load-history construction, built-in symbol file names.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4502
diff
changeset
|
204 (push symbol current-load-list) |
428 | 205 (run-hooks 'custom-define-hook) |
206 symbol) | |
207 | |
208 (defmacro defcustom (symbol value doc &rest args) | |
209 "Declare SYMBOL as a customizable variable that defaults to VALUE. | |
210 DOC is the variable documentation. | |
211 | |
212 Neither SYMBOL nor VALUE needs to be quoted. | |
213 If SYMBOL is not already bound, initialize it to VALUE. | |
214 The remaining arguments should have the form | |
215 | |
216 [KEYWORD VALUE]... | |
217 | |
1333 | 218 The following keywords are meaningful: |
428 | 219 |
2544 | 220 :type VALUE should be a widget type for editing the symbol's value. |
428 | 221 The default is `sexp'. |
222 :options VALUE should be a list of valid members of the widget type. | |
223 :group VALUE should be a customization group. | |
224 Add SYMBOL to that group. | |
2544 | 225 :link LINK-DATA |
226 Include an external link after the documentation string for this | |
227 item. This is a sentence containing an active field which | |
228 references some other documentation. | |
229 | |
230 There are three alternatives you can use for LINK-DATA: | |
231 | |
232 (custom-manual INFO-NODE) | |
233 Link to an Info node; INFO-NODE is a string which specifies | |
234 the node name, as in \"(emacs)Top\". The link appears as | |
235 `[manual]' in the customization buffer. | |
236 | |
237 (info-link INFO-NODE) | |
238 Like `custom-manual' except that the link appears in the | |
239 customization buffer with the Info node name. | |
240 | |
241 (url-link URL) | |
242 Link to a web page; URL is a string which specifies the URL. | |
243 The link appears in the customization buffer as URL. | |
244 | |
245 You can specify the text to use in the customization buffer by | |
246 adding `:tag NAME' after the first element of the LINK-DATA; for | |
247 example, (info-link :tag \"foo\" \"(emacs)Top\") makes a link to the | |
248 Emacs manual which appears in the buffer as `foo'. | |
249 | |
250 An item can have more than one external link; however, most items | |
251 have none at all. | |
1333 | 252 :initialize |
2544 | 253 VALUE should be a function used to initialize the |
254 variable. It takes two arguments, the symbol and value | |
255 given in the `defcustom' call. The default is | |
256 `custom-initialize-reset'. | |
1333 | 257 :set VALUE should be a function to set the value of the symbol. |
258 It takes two arguments, the symbol to set and the value to | |
259 give it. The default choice of function is `custom-set-default'. | |
428 | 260 :get VALUE should be a function to extract the value of symbol. |
1333 | 261 The function takes one argument, a symbol, and should return |
262 the current value for that symbol. The default choice of function | |
263 is `custom-default-value'. #### XEmacs used to say `default-value'; | |
264 is that right? | |
265 :require | |
266 VALUE should be a feature symbol. If you save a value | |
267 for this option, then when your custom init file loads the value, | |
268 it does (require VALUE) first. | |
269 :version | |
270 VALUE should be a string specifying that the variable was | |
903 | 271 first introduced, or its default value was changed, in Emacs |
272 version VERSION. | |
2544 | 273 :tag LABEL |
274 Use LABEL, a string, instead of the item's name, to label the item | |
275 in customization menus and buffers. | |
276 :load FILE | |
277 Load file FILE (a string) before displaying this customization | |
278 item. Loading is done with `load', and only if the file is | |
279 not already loaded. | |
280 :set-after VARIABLES | |
281 Specifies that SYMBOL should be set after the list of variables | |
282 VARIABLES when both have been customized. | |
428 | 283 |
284 Read the section about customization in the Emacs Lisp manual for more | |
285 information." | |
286 `(custom-declare-variable (quote ,symbol) (quote ,value) ,doc ,@args)) | |
287 | |
288 ;;; The `defface' Macro. | |
289 | |
290 (defmacro defface (face spec doc &rest args) | |
291 "Declare FACE as a customizable face that defaults to SPEC. | |
292 FACE does not need to be quoted. | |
293 | |
294 Third argument DOC is the face documentation. | |
295 | |
296 If FACE has been set with `custom-set-face', set the face attributes | |
297 as specified by that function, otherwise set the face attributes | |
298 according to SPEC. | |
299 | |
300 The remaining arguments should have the form | |
301 | |
302 [KEYWORD VALUE]... | |
303 | |
304 The following KEYWORDs are defined: | |
305 | |
306 :group VALUE should be a customization group. | |
307 Add FACE to that group. | |
308 | |
309 SPEC should be an alist of the form ((DISPLAY ATTS)...). | |
310 | |
311 ATTS is a list of face attributes and their values. The possible | |
312 attributes are defined in the variable `custom-face-attributes'. | |
313 | |
314 The ATTS of the first entry in SPEC where the DISPLAY matches the | |
315 frame should take effect in that frame. DISPLAY can either be the | |
316 symbol t, which will match all frames, or an alist of the form | |
317 \((REQ ITEM...)...) | |
318 | |
319 For the DISPLAY to match a FRAME, the REQ property of the frame must | |
320 match one of the ITEM. The following REQ are defined: | |
321 | |
322 `type' (the value of `window-system') | |
442 | 323 Should be one of `x', `mswindows', or `tty'. |
428 | 324 |
325 `class' (the frame's color support) | |
326 Should be one of `color', `grayscale', or `mono'. | |
327 | |
5373
b6e59ea11533
Add min-colors specifier to defface, and document it.
Jeff Sparkes <jsparkes@gmail.com>
parents:
5284
diff
changeset
|
328 `min-colors' (the minimum number of colors the frame supports) |
b6e59ea11533
Add min-colors specifier to defface, and document it.
Jeff Sparkes <jsparkes@gmail.com>
parents:
5284
diff
changeset
|
329 Should be in integer which is compared to `display-color-cells' |
b6e59ea11533
Add min-colors specifier to defface, and document it.
Jeff Sparkes <jsparkes@gmail.com>
parents:
5284
diff
changeset
|
330 |
428 | 331 `background' (what color is used for the background text) |
332 Should be one of `light' or `dark'. | |
333 | |
334 Read the section about customization in the Emacs Lisp manual for more | |
335 information." | |
336 `(custom-declare-face (quote ,face) ,spec ,doc ,@args)) | |
337 | |
338 ;;; The `defgroup' Macro. | |
339 | |
2544 | 340 (defun custom-current-group () |
341 (cdr (assoc load-file-name custom-current-group-alist))) | |
342 | |
428 | 343 (defun custom-declare-group (symbol members doc &rest args) |
344 "Like `defgroup', but SYMBOL is evaluated as a normal argument." | |
345 (while members | |
346 (apply 'custom-add-to-group symbol (car members)) | |
347 (pop members)) | |
348 (when doc | |
349 (put symbol 'group-documentation doc)) | |
350 (while args | |
351 (let ((arg (car args))) | |
352 (setq args (cdr args)) | |
353 (check-argument-type 'keywordp arg) | |
354 (let ((keyword arg) | |
2544 | 355 (value (car args))) |
428 | 356 (unless args |
357 (signal 'error (list "Keyword is missing an argument" keyword))) | |
2544 | 358 (setq args (cdr args)) |
359 (cond ((eq keyword :prefix) | |
360 (put symbol 'custom-prefix value)) | |
361 (t | |
362 (custom-handle-keyword symbol keyword value | |
363 'custom-group)))))) | |
364 ;; Record the group on the `current' list. | |
365 (let ((elt (assoc load-file-name custom-current-group-alist))) | |
366 (if elt (setcdr elt symbol) | |
367 (push (cons load-file-name symbol) custom-current-group-alist))) | |
428 | 368 (run-hooks 'custom-define-hook) |
369 symbol) | |
370 | |
371 (defmacro defgroup (symbol members doc &rest args) | |
372 "Declare SYMBOL as a customization group containing MEMBERS. | |
373 SYMBOL does not need to be quoted. | |
374 | |
375 Third arg DOC is the group documentation. | |
376 | |
377 MEMBERS should be an alist of the form ((NAME WIDGET)...) where NAME | |
378 is a symbol and WIDGET is a widget for editing that symbol. Useful | |
379 widgets are `custom-variable' for editing variables, `custom-face' for | |
380 edit faces, and `custom-group' for editing groups. | |
381 | |
382 The remaining arguments should have the form | |
383 | |
384 [KEYWORD VALUE]... | |
385 | |
2544 | 386 The following KEYWORDs are defined: |
428 | 387 |
388 :group VALUE should be a customization group. | |
389 Add SYMBOL to that group. | |
390 | |
391 Read the section about customization in the Emacs Lisp manual for more | |
392 information." | |
2544 | 393 |
394 ;; XEmacs: Evidently a purposeful omission from the docs: | |
395 ;:version VALUE should be a string specifying that the group was introduced | |
396 ; in Emacs version VERSION. | |
397 ; | |
398 | |
399 ;; FSF: (not a problem for XEmacs) | |
400 ;; It is better not to use backquote in this file, | |
401 ;; because that makes a bootstrapping problem | |
402 ;; if you need to recompile all the Lisp files using interpreted code. | |
403 ; (nconc (list 'custom-declare-group (list 'quote symbol) members doc) args)) | |
428 | 404 `(custom-declare-group (quote ,symbol) ,members ,doc ,@args)) |
405 | |
406 (defvar custom-group-hash-table (make-hash-table :size 300 :test 'eq) | |
407 "Hash-table of non-empty groups.") | |
408 | |
409 (defun custom-add-to-group (group option widget) | |
410 "To existing GROUP add a new OPTION of type WIDGET. | |
2544 | 411 If there already is an entry for OPTION and WIDGET, nothing is done." |
5383
294ab9180fad
#'custom-add-to-group: warn if GROUP is nil.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5373
diff
changeset
|
412 (or group (display-warning 'custom |
294ab9180fad
#'custom-add-to-group: warn if GROUP is nil.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5373
diff
changeset
|
413 (format "custom: widget %s, option %s has no associated group" |
294ab9180fad
#'custom-add-to-group: warn if GROUP is nil.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5373
diff
changeset
|
414 widget option))) |
2544 | 415 (let ((members (get group 'custom-group)) |
416 (entry (list option widget))) | |
417 (unless (member entry members) | |
418 (put group 'custom-group (nconc members (list entry))))) | |
428 | 419 (puthash group t custom-group-hash-table)) |
420 | |
2544 | 421 (defun custom-group-of-mode (mode) |
422 "Return the custom group corresponding to the major or minor MODE. | |
423 If no such group is found, return nil." | |
424 (or (get mode 'custom-mode-group) | |
425 (if (or (get mode 'custom-group) | |
426 (and (string-match "-mode\\'" (symbol-name mode)) | |
427 (get (setq mode (intern (substring (symbol-name mode) | |
428 0 (match-beginning 0)))) | |
429 'custom-group))) | |
430 mode))) | |
431 | |
428 | 432 ;;; Properties. |
433 | |
434 (defun custom-handle-all-keywords (symbol args type) | |
435 "For customization option SYMBOL, handle keyword arguments ARGS. | |
436 Third argument TYPE is the custom option type." | |
2544 | 437 (unless (memq :group args) |
438 (custom-add-to-group (custom-current-group) symbol type)) | |
428 | 439 (while args |
440 (let ((arg (car args))) | |
441 (setq args (cdr args)) | |
442 (check-argument-type 'keywordp arg) | |
443 (let ((keyword arg) | |
444 (value (car args))) | |
445 (unless args | |
446 (signal 'error (list "Keyword is missing an argument" keyword))) | |
447 (setq args (cdr args)) | |
448 (custom-handle-keyword symbol keyword value type))))) | |
449 | |
450 (defun custom-handle-keyword (symbol keyword value type) | |
451 "For customization option SYMBOL, handle KEYWORD with VALUE. | |
452 Fourth argument TYPE is the custom option type." | |
453 (cond ((eq keyword :group) | |
903 | 454 (custom-add-to-group value symbol type)) |
455 ((eq keyword :version) | |
456 (custom-add-version symbol value)) | |
457 ((eq keyword :link) | |
458 (custom-add-link symbol value)) | |
459 ((eq keyword :load) | |
460 (custom-add-load symbol value)) | |
461 ((eq keyword :tag) | |
462 (put symbol 'custom-tag value)) | |
463 ((eq keyword :set-after) | |
464 (custom-add-dependencies symbol value)) | |
465 (t | |
466 (signal 'error (list "Unknown keyword" keyword))))) | |
467 | |
468 (defun custom-add-dependencies (symbol value) | |
469 "To the custom option SYMBOL, add dependencies specified by VALUE. | |
470 VALUE should be a list of symbols. For each symbol in that list, | |
471 this specifies that SYMBOL should be set after the specified symbol, if | |
472 both appear in constructs like `custom-set-variables'." | |
473 (unless (listp value) | |
474 (error "Invalid custom dependency `%s'" value)) | |
475 (let* ((deps (get symbol 'custom-dependencies)) | |
476 (new-deps deps)) | |
477 (while value | |
478 (let ((dep (car value))) | |
479 (unless (symbolp dep) | |
480 (error "Invalid custom dependency `%s'" dep)) | |
481 (unless (memq dep new-deps) | |
482 (setq new-deps (cons dep new-deps))) | |
483 (setq value (cdr value)))) | |
484 (unless (eq deps new-deps) | |
485 (put symbol 'custom-dependencies new-deps)))) | |
428 | 486 |
487 (defun custom-add-option (symbol option) | |
488 "To the variable SYMBOL add OPTION. | |
489 | |
490 If SYMBOL is a hook variable, OPTION should be a hook member. | |
491 For other types variables, the effect is undefined." | |
492 (let ((options (get symbol 'custom-options))) | |
493 (unless (member option options) | |
494 (put symbol 'custom-options (cons option options))))) | |
495 | |
496 (defun custom-add-link (symbol widget) | |
497 "To the custom option SYMBOL add the link WIDGET." | |
498 (let ((links (get symbol 'custom-links))) | |
499 (unless (member widget links) | |
500 (put symbol 'custom-links (cons widget links))))) | |
501 | |
502 (defun custom-add-version (symbol version) | |
503 "To the custom option SYMBOL add the version VERSION." | |
504 (put symbol 'custom-version version)) | |
505 | |
506 (defun custom-add-load (symbol load) | |
507 "To the custom option SYMBOL add the dependency LOAD. | |
508 LOAD should be either a library file name, or a feature name." | |
509 (puthash symbol t custom-group-hash-table) | |
510 (let ((loads (get symbol 'custom-loads))) | |
511 (unless (member load loads) | |
512 (put symbol 'custom-loads (cons load loads))))) | |
513 | |
2544 | 514 (defun custom-autoload (symbol load) |
515 "Mark SYMBOL as autoloaded custom variable and add dependency LOAD." | |
516 (put symbol 'custom-autoload t) | |
517 (custom-add-load symbol load)) | |
518 | |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4441
diff
changeset
|
519 ;; XEmacs; |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4441
diff
changeset
|
520 ;; #'custom-variable-p is in symbols.c, since it's called from |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4441
diff
changeset
|
521 ;; #'user-variable-p. |
2544 | 522 |
523 ;;; Loading files needed to customize a symbol. | |
524 ;;; This is in custom.el because menu-bar.el needs it for toggle cmds. | |
525 | |
526 (defvar custom-load-recursion nil | |
527 "Hack to avoid recursive dependencies.") | |
528 | |
529 (defun custom-load-symbol (symbol) | |
530 "Load all dependencies for SYMBOL." | |
531 (unless custom-load-recursion | |
532 (let ((custom-load-recursion t)) | |
533 (dolist (load (get symbol 'custom-loads)) | |
534 (cond ((symbolp load) (condition-case nil (require load) (error nil))) | |
535 ;; This is subsumed by the test below, but it's much faster. | |
536 ((assoc load load-history)) | |
537 ;; This was just (assoc (locate-library load) load-history) | |
538 ;; but has been optimized not to load locate-library | |
539 ;; if not necessary. | |
540 ((let ((regexp (concat "\\(\\`\\|/\\)" (regexp-quote load) | |
541 "\\(\\'\\|\\.\\)")) | |
542 (found nil)) | |
543 (dolist (loaded load-history) | |
544 (and (stringp (car loaded)) | |
545 (string-match regexp (car loaded)) | |
546 (setq found t))) | |
547 found)) | |
548 ;; Without this, we would load cus-edit recursively. | |
549 ;; We are still loading it when we call this, | |
550 ;; and it is not in load-history yet. | |
551 ((equal load "cus-edit")) | |
552 (t (condition-case nil (load load) (error nil)))))))) | |
428 | 553 |
554 (defvar custom-known-themes '(user standard) | |
2544 | 555 "Themes that have been define with `deftheme'. |
556 The default value is the list (user standard). The theme `standard' | |
557 contains the Emacs standard settings from the original Lisp files. The | |
558 theme `user' contains all the the settings the user customized and saved. | |
559 Additional themes declared with the `deftheme' macro will be added to | |
560 the front of this list.") | |
428 | 561 |
2544 | 562 (defun custom-declare-theme (theme feature &optional doc &rest args) |
563 "Like `deftheme', but THEME is evaluated as a normal argument. | |
564 FEATURE is the feature this theme provides. This symbol is created | |
565 from THEME by `custom-make-theme-feature'." | |
566 (add-to-list 'custom-known-themes theme) | |
428 | 567 (put theme 'theme-feature feature) |
2544 | 568 (when doc |
569 (put theme 'theme-documentation doc)) | |
570 (while args | |
571 (let ((arg (car args))) | |
572 (setq args (cdr args)) | |
573 (check-argument-type 'keywordp arg) | |
574 (let ((keyword arg) | |
575 (value (car args))) | |
576 (unless args | |
577 (signal 'error (list "Keyword is missing an argument" keyword))) | |
578 (setq args (cdr args)) | |
579 (cond ((eq keyword :short-description) | |
580 (put theme 'theme-short-description value)) | |
581 ((eq keyword :immediate) | |
582 (put theme 'theme-immediate value)) | |
583 ((eq keyword :variable-set-string) | |
584 (put theme 'theme-variable-set-string value)) | |
585 ((eq keyword :variable-reset-string) | |
586 (put theme 'theme-variable-reset-string value)) | |
587 ((eq keyword :face-set-string) | |
588 (put theme 'theme-face-set-string value)) | |
589 ((eq keyword :face-reset-string) | |
590 (put theme 'theme-face-reset-string value))))))) | |
591 | |
592 (defmacro deftheme (theme &optional doc &rest args) | |
593 "Declare custom theme THEME. | |
594 The optional argument DOC is a doc string describing the theme. | |
595 The remaining arguments should have the form | |
596 | |
597 [KEYWORD VALUE]... | |
598 | |
599 The following KEYWORD's are defined: | |
600 | |
601 :short-description | |
602 VALUE is a short (one line) description of the theme. If not | |
603 given, DOC is used. | |
604 :immediate | |
605 If VALUE is non-nil, variables specified in this theme are set | |
606 immediately when loading the theme. | |
607 :variable-set-string | |
608 VALUE is a string used to indicate that a variable takes its | |
609 setting from this theme. It is passed to FORMAT with the name | |
610 of the theme as an additional argument. If not given, a | |
611 generic description is used. | |
612 :variable-reset-string | |
613 VALUE is a string used in the case a variable has been forced | |
614 to its value in this theme. It is passed to FORMAT with the | |
615 name of the theme as an additional argument. If not given, a | |
616 generic description is used. | |
617 :face-set-string | |
618 VALUE is a string used to indicate that a face takes its | |
619 setting from this theme. It is passed to FORMAT with the name | |
620 of the theme as an additional argument. If not given, a | |
621 generic description is used. | |
622 :face-reset-string | |
623 VALUE is a string used in the case a face has been forced to | |
624 its value in this theme. It is passed to FORMAT with the name | |
625 of the theme as an additional argument. If not given, a | |
626 generic description is used. | |
627 | |
628 Any theme `foo' should be defined in a file called `foo-theme.el'; | |
629 see `custom-make-theme-feature' for more information." | |
630 (let ((feature (custom-make-theme-feature theme))) | |
631 ;; It is better not to use backquote in this file, | |
632 ;; because that makes a bootstrapping problem | |
633 ;; if you need to recompile all the Lisp files using interpreted code. | |
634 (nconc (list 'custom-declare-theme | |
635 (list 'quote theme) | |
636 (list 'quote feature) | |
637 doc) args))) | |
428 | 638 |
639 (defun custom-make-theme-feature (theme) | |
2544 | 640 "Given a symbol THEME, create a new symbol by appending \"-theme\". |
641 Store this symbol in the `theme-feature' property of THEME. | |
642 Calling `provide-theme' to provide THEME actually puts `THEME-theme' | |
643 into `features'. | |
428 | 644 |
2544 | 645 This allows for a file-name convention for autoloading themes: |
646 Every theme X has a property `provide-theme' whose value is \"X-theme\". | |
647 \(require-theme X) then attempts to load the file `X-theme.el'." | |
648 (intern (concat (symbol-name theme) "-theme"))) | |
428 | 649 |
650 (defsubst custom-theme-p (theme) | |
651 "Non-nil when THEME has been defined." | |
652 (memq theme custom-known-themes)) | |
653 | |
654 (defsubst custom-check-theme (theme) | |
2544 | 655 "Check whether THEME is valid, and signal an error if it is not." |
428 | 656 (unless (custom-theme-p theme) |
657 (error "Unknown theme `%s'" theme))) | |
658 | |
659 ;;; Initializing. | |
660 | |
661 (defun custom-push-theme (prop symbol theme mode value) | |
2544 | 662 "Add (THEME MODE VALUE) to the list in property PROP of SYMBOL. |
663 If the first element in that list is already (THEME ...), | |
664 discard it first. | |
665 | |
666 MODE can be either the symbol `set' or the symbol `reset'. If it is the | |
667 symbol `set', then VALUE is the value to use. If it is the symbol | |
668 `reset', then VALUE is the mode to query instead. | |
669 | |
670 In the following example for the variable `goto-address-url-face', the | |
671 theme `subtle-hacker' uses the same value for the variable as the theme | |
672 `gnome2': | |
673 | |
674 \((standard set bold) | |
675 \(gnome2 set info-xref) | |
676 \(jonadab set underline) | |
677 \(subtle-hacker reset gnome2)) | |
678 | |
679 | |
680 If a value has been stored for themes A B and C, and a new value | |
681 is to be stored for theme C, then the old value of C is discarded. | |
682 If a new value is to be stored for theme B, however, the old value | |
683 of B is not discarded because B is not the car of the list. | |
684 | |
685 For variables, list property PROP is `theme-value'. | |
686 For faces, list property PROP is `theme-face'. | |
687 This is used in `custom-do-theme-reset', for example. | |
688 | |
689 The list looks the same in any case; the examples shows a possible | |
690 value of the `theme-face' property for the face `region': | |
691 | |
692 \((gnome2 set ((t (:foreground \"cyan\" :background \"dark cyan\")))) | |
693 \(standard set ((((class color) (background dark)) | |
694 \(:background \"blue\")) | |
695 \(t (:background \"gray\"))))) | |
696 | |
697 This records values for the `standard' and the `gnome2' themes. | |
698 The user has not customized the face; had he done that, | |
699 the list would contain an entry for the `user' theme, too. | |
700 See `custom-known-themes' for a list of known themes." | |
428 | 701 (let ((old (get symbol prop))) |
702 (if (eq (car-safe (car-safe old)) theme) | |
703 (setq old (cdr old))) | |
704 (put symbol prop (cons (list theme mode value) old)))) | |
705 | |
988 | 706 (defvar custom-local-buffer nil |
707 "Non-nil, in a Customization buffer, means customize a specific buffer. | |
708 If this variable is non-nil, it should be a buffer, | |
709 and it means customize the local bindings of that buffer. | |
710 This variable is a permanent local, and it normally has a local binding | |
711 in every Customization buffer.") | |
712 (put 'custom-local-buffer 'permanent-local t) | |
713 | |
428 | 714 (defun custom-set-variables (&rest args) |
715 "Initialize variables according to user preferences. | |
716 The settings are registered as theme `user'. | |
2544 | 717 The arguments should each be a list of the form: |
428 | 718 |
719 (SYMBOL VALUE [NOW [REQUEST [COMMENT]]]) | |
720 | |
721 The unevaluated VALUE is stored as the saved value for SYMBOL. | |
722 If NOW is present and non-nil, VALUE is also evaluated and bound as | |
723 the default value for the SYMBOL. | |
2544 | 724 |
428 | 725 REQUEST is a list of features we must 'require for SYMBOL. |
726 COMMENT is a comment string about SYMBOL." | |
727 (apply 'custom-theme-set-variables 'user args)) | |
728 | |
729 (defun custom-theme-set-variables (theme &rest args) | |
730 "Initialize variables according to settings specified by args. | |
731 Records the settings as belonging to THEME. | |
732 | |
2544 | 733 The arguments should be a list where each entry has the form: |
734 | |
735 (SYMBOL VALUE [NOW [REQUEST [COMMENT]]]) | |
736 | |
737 The unevaluated VALUE is stored as the saved value for SYMBOL. | |
738 If NOW is present and non-nil, VALUE is also evaluated and bound as | |
739 the default value for the SYMBOL. | |
740 REQUEST is a list of features we must 'require for SYMBOL. | |
741 COMMENT is a comment string about SYMBOL. | |
742 | |
743 Several properties of THEME and SYMBOL are used in the process: | |
744 | |
745 If THEME property `theme-immediate' is non-nil, this is equivalent of | |
746 providing the NOW argument to all symbols in the argument list: SYMBOL | |
747 is bound to the evaluated VALUE. The only difference is SYMBOL property | |
748 `force-value': if NOW is non-nil, SYMBOL's property `force-value' is set to | |
749 the symbol `rogue', else if THEME's property `theme-immediate' is non-nil, | |
750 FACE's property `force-face' is set to the symbol `immediate'. | |
751 | |
752 VALUE itself is saved unevaluated as SYMBOL property `saved-value' and | |
753 in SYMBOL's list property `theme-value' \(using `custom-push-theme')." | |
428 | 754 (custom-check-theme theme) |
755 (let ((immediate (get theme 'theme-immediate))) | |
2544 | 756 (setq args |
757 (sort args | |
758 (lambda (a1 a2) | |
759 (let* ((sym1 (car a1)) | |
760 (sym2 (car a2)) | |
761 (1-then-2 (memq sym1 (get sym2 'custom-dependencies))) | |
762 (2-then-1 (memq sym2 (get sym1 'custom-dependencies)))) | |
763 (cond ((and 1-then-2 2-then-1) | |
764 (error "Circular custom dependency between `%s' and `%s'" | |
765 sym1 sym2)) | |
766 (2-then-1 nil) | |
767 ;; Put symbols with :require last. The macro | |
768 ;; define-minor-mode generates a defcustom | |
769 ;; with a :require and a :set, where the | |
770 ;; setter function calls the mode function. | |
771 ;; Putting symbols with :require last ensures | |
772 ;; that the mode function will see other | |
773 ;; customized values rather than default | |
774 ;; values. | |
775 (t (nth 3 a2))))))) | |
988 | 776 (while args |
428 | 777 (let ((entry (car args))) |
2544 | 778 (if (listp entry) |
779 (let* ((symbol (nth 0 entry)) | |
780 (value (nth 1 entry)) | |
781 (now (nth 2 entry)) | |
782 (requests (nth 3 entry)) | |
783 (comment (nth 4 entry)) | |
784 set) | |
785 (when requests | |
786 (put symbol 'custom-requests requests) | |
787 (mapc 'require requests)) | |
788 (setq set (or (get symbol 'custom-set) 'custom-set-default)) | |
789 (put symbol 'saved-value (list value)) | |
790 (put symbol 'saved-variable-comment comment) | |
428 | 791 (custom-push-theme 'theme-value symbol theme 'set value) |
2544 | 792 ;; Allow for errors in the case where the setter has |
793 ;; changed between versions, say, but let the user know. | |
794 (condition-case data | |
795 (cond ((or now immediate) | |
796 ;; Rogue variable, set it now. | |
797 (put symbol 'force-value (if now 'rogue 'immediate)) | |
798 (funcall set symbol (eval value))) | |
799 ((default-boundp symbol) | |
800 ;; Something already set this, overwrite it. | |
801 (funcall set symbol (eval value)))) | |
802 (error | |
988 | 803 (message "Error setting %s: %s" symbol data))) |
2544 | 804 (setq args (cdr args)) |
805 (and (or now (default-boundp symbol)) | |
806 (put symbol 'variable-comment comment))) | |
807 ;; Old format, a plist of SYMBOL VALUE pairs. | |
808 (message "Warning: old format `custom-set-variables'") | |
809 (ding) | |
810 (sit-for 2) | |
811 (let ((symbol (nth 0 args)) | |
812 (value (nth 1 args))) | |
813 (put symbol 'saved-value (list value)) | |
428 | 814 (custom-push-theme 'theme-value symbol theme 'set value)) |
2544 | 815 (setq args (cdr (cdr args)))))))) |
428 | 816 |
988 | 817 (defun custom-set-default (variable value) |
818 "Default :set function for a customizable variable. | |
819 Normally, this sets the default value of VARIABLE to VALUE, | |
820 but if `custom-local-buffer' is non-nil, | |
821 this sets the local binding in that buffer instead." | |
822 (if custom-local-buffer | |
823 (with-current-buffer custom-local-buffer | |
824 (set variable value)) | |
825 (set-default variable value))) | |
428 | 826 |
4744
17f7e9191c0b
Rationalise duplicated functionality, #'custom-quote, #'quote-maybe.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
827 ;; Now in C, but the old name is still used by some packages: |
17f7e9191c0b
Rationalise duplicated functionality, #'custom-quote, #'quote-maybe.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
828 (defalias 'custom-quote 'quote-maybe) |
2544 | 829 |
830 (defun customize-mark-to-save (symbol) | |
831 "Mark SYMBOL for later saving. | |
832 | |
833 If the default value of SYMBOL is different from the standard value, | |
834 set the `saved-value' property to a list whose car evaluates to the | |
835 default value. Otherwise, set it to nil. | |
836 | |
837 To actually save the value, call `custom-save-all'. | |
838 | |
839 Return non-nil iff the `saved-value' property actually changed." | |
840 (let* ((get (or (get symbol 'custom-get) 'default-value)) | |
841 (value (funcall get symbol)) | |
842 (saved (get symbol 'saved-value)) | |
843 (standard (get symbol 'standard-value)) | |
844 (comment (get symbol 'customized-variable-comment))) | |
845 ;; Save default value iff different from standard value. | |
846 (if (or (null standard) | |
847 (not (equal value (condition-case nil | |
848 (eval (car standard)) | |
849 (error nil))))) | |
4744
17f7e9191c0b
Rationalise duplicated functionality, #'custom-quote, #'quote-maybe.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
850 (put symbol 'saved-value (list (quote-maybe value))) |
2544 | 851 (put symbol 'saved-value nil)) |
852 ;; Clear customized information (set, but not saved). | |
853 (put symbol 'customized-value nil) | |
854 ;; Save any comment that might have been set. | |
855 (when comment | |
856 (put symbol 'saved-variable-comment comment)) | |
857 (not (equal saved (get symbol 'saved-value))))) | |
858 | |
859 (defun customize-mark-as-set (symbol) | |
860 "Mark current value of SYMBOL as being set from customize. | |
861 | |
862 If the default value of SYMBOL is different from the saved value if any, | |
863 or else if it is different from the standard value, set the | |
864 `customized-value' property to a list whose car evaluates to the | |
865 default value. Otherwise, set it to nil. | |
866 | |
867 Return non-nil iff the `customized-value' property actually changed." | |
868 (let* ((get (or (get symbol 'custom-get) 'default-value)) | |
869 (value (funcall get symbol)) | |
870 (customized (get symbol 'customized-value)) | |
871 (old (or (get symbol 'saved-value) (get symbol 'standard-value)))) | |
872 ;; Mark default value as set iff different from old value. | |
873 (if (or (null old) | |
874 (not (equal value (condition-case nil | |
875 (eval (car old)) | |
876 (error nil))))) | |
4744
17f7e9191c0b
Rationalise duplicated functionality, #'custom-quote, #'quote-maybe.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
877 (put symbol 'customized-value (list (quote-maybe value))) |
2544 | 878 (put symbol 'customized-value nil)) |
879 ;; Changed? | |
880 (not (equal customized (get symbol 'customized-value))))) | |
881 | |
882 ;;; Theme Manipulation | |
883 | |
884 (defvar custom-loaded-themes nil | |
885 "Themes in the order they are loaded.") | |
886 | |
887 (defun custom-theme-loaded-p (theme) | |
888 "Return non-nil when THEME has been loaded." | |
889 (memq theme custom-loaded-themes)) | |
890 | |
891 (defun provide-theme (theme) | |
892 "Indicate that this file provides THEME. | |
893 Add THEME to `custom-loaded-themes' and `provide' whatever | |
894 is stored in THEME's property `theme-feature'. | |
895 | |
896 Usually the theme-feature property contains a symbol created | |
897 by `custom-make-theme-feature'." | |
898 (custom-check-theme theme) | |
899 (provide (get theme 'theme-feature)) | |
900 (setq custom-loaded-themes (nconc (list theme) custom-loaded-themes))) | |
901 | |
902 (defun require-theme (theme) | |
903 "Try to load a theme by requiring its feature. | |
904 THEME's feature is stored in THEME's `theme-feature' property. | |
905 | |
906 Usually the `theme-feature' property contains a symbol created | |
907 by `custom-make-theme-feature'." | |
908 ;; Note we do no check for validity of the theme here. | |
909 ;; This allows to pull in themes by a file-name convention | |
910 (require (or (get theme 'theme-feature) | |
911 (custom-make-theme-feature theme)))) | |
912 | |
913 (defun custom-remove-theme (spec-alist theme) | |
914 "Delete all elements from SPEC-ALIST whose car is THEME." | |
915 (let ((elt (assoc theme spec-alist))) | |
916 (while elt | |
917 (setq spec-alist (delete elt spec-alist) | |
918 elt (assoc theme spec-alist)))) | |
919 spec-alist) | |
920 | |
921 (defun custom-do-theme-reset (theme) | |
922 "Undo all settings defined by THEME. | |
923 | |
924 A variable remains unchanged if its property `theme-value' does not | |
925 contain a value for THEME. A face remains unchanged if its property | |
926 `theme-face' does not contain a value for THEME. In either case, all | |
927 settings for THEME are removed from the property and the variable or | |
928 face is set to the `user' theme. | |
428 | 929 |
2544 | 930 See `custom-known-themes' for a list of known themes." |
931 (let (spec-list) | |
932 (mapatoms (lambda (symbol) | |
933 ;; This works even if symbol is both a variable and a | |
934 ;; face. | |
935 (setq spec-list (get symbol 'theme-value)) | |
936 (when spec-list | |
937 (put symbol 'theme-value (custom-remove-theme spec-list theme)) | |
938 (custom-theme-reset-internal symbol 'user)) | |
939 (setq spec-list (get symbol 'theme-face)) | |
940 (when spec-list | |
941 (put symbol 'theme-face (custom-remove-theme spec-list theme)) | |
942 (custom-theme-reset-internal-face symbol 'user)))))) | |
943 | |
944 (defun custom-theme-load-themes (by-theme &rest body) | |
945 "Load the themes specified by BODY. | |
946 Record them as required by theme BY-THEME. BODY is a sequence of either | |
947 | |
948 THEME | |
949 BY-THEME requires THEME | |
950 \(reset THEME) | |
951 Undo all the settings made by THEME | |
952 \(hidden THEME) | |
953 Require THEME but hide it from the user | |
954 | |
955 All the themes loaded for BY-THEME are recorded in BY-THEME's property | |
956 `theme-loads-themes'. Any theme loaded with the hidden predicate will | |
957 be given the property `theme-hidden' unless it has been loaded before. | |
958 Whether a theme has been loaded before is determined by the function | |
959 `custom-theme-loaded-p'." | |
960 (custom-check-theme by-theme) | |
961 (let ((theme) | |
962 (themes-loaded (get by-theme 'theme-loads-themes))) | |
963 (while theme | |
964 (setq theme (car body) | |
965 body (cdr body)) | |
966 (cond ((and (consp theme) (eq (car theme) 'reset)) | |
967 (custom-do-theme-reset (cadr theme))) | |
968 ((and (consp theme) (eq (car theme) 'hidden)) | |
969 (require-theme (cadr theme)) | |
970 (unless (custom-theme-loaded-p (cadr theme)) | |
971 (put (cadr theme) 'theme-hidden t))) | |
972 (t | |
973 (require-theme theme) | |
974 (put theme 'theme-hidden nil))) | |
975 (setq themes-loaded (nconc (list theme) themes-loaded))) | |
976 (put by-theme 'theme-loads-themes themes-loaded))) | |
977 | |
978 (defun custom-load-themes (&rest body) | |
979 "Load themes for the USER theme as specified by BODY. | |
980 | |
981 See `custom-theme-load-themes' for more information on BODY." | |
982 (apply 'custom-theme-load-themes 'user body)) | |
983 | |
984 ; (defsubst copy-upto-last (elt list) | |
985 ; "Copy all the elements of the list upto the last occurrence of elt" | |
986 ; ;; Is it faster to do more work in C than to do less in elisp? | |
987 ; (nreverse (cdr (member elt (reverse list))))) | |
988 | |
989 (defun custom-theme-value (theme theme-spec-list) | |
990 "Determine the value for THEME defined by THEME-SPEC-LIST. | |
991 Returns a list with the original value if found; nil otherwise. | |
992 | |
993 THEME-SPEC-LIST is an alist with themes as its key. As new themes are | |
994 installed, these are added to the front of THEME-SPEC-LIST. | |
995 Each element has the form | |
996 | |
997 \(THEME MODE VALUE) | |
998 | |
999 MODE is either the symbol `set' or the symbol `reset'. See | |
1000 `custom-push-theme' for more information on the format of | |
1001 THEME-SPEC-LIST." | |
1002 ;; Note we do _NOT_ signal an error if the theme is unknown | |
1003 ;; it might have gone away without the user knowing. | |
1004 (let ((value (cdr (assoc theme theme-spec-list)))) | |
1005 (if value | |
1006 (if (eq (car value) 'set) | |
1007 (cdr value) | |
1008 (custom-theme-value (cadr value) theme-spec-list))))) | |
1009 | |
1010 (defun custom-theme-variable-value (variable theme) | |
1011 "Return (list value) indicating value of VARIABLE in THEME. | |
1012 If THEME does not define a value for VARIABLE, return nil. The value | |
1013 definitions per theme are stored in VARIABLE's property `theme-value'. | |
1014 The actual work is done by function `custom-theme-value', which see. | |
1015 See `custom-push-theme' for more information on how these definitions | |
1016 are stored." | |
1017 (custom-theme-value theme (get variable 'theme-value))) | |
1018 | |
1019 (defun custom-theme-reset-internal (symbol to-theme) | |
1020 "Reset SYMBOL to the value defined by TO-THEME. | |
1021 If SYMBOL is not defined in TO-THEME, reset SYMBOL to the standard | |
1022 value. See `custom-theme-variable-value'. The standard value is | |
1023 stored in SYMBOL's property `standard-value'." | |
1024 (let ((value (custom-theme-variable-value symbol to-theme)) | |
1025 was-in-theme) | |
1026 (setq was-in-theme value) | |
1027 (setq value (or value (get symbol 'standard-value))) | |
1028 (when value | |
1029 (put symbol 'saved-value was-in-theme) | |
4441
1d7faae1080c
Fix call to get in custom-theme-reset-internal.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4289
diff
changeset
|
1030 (if (or (get symbol 'force-value) (default-boundp symbol)) |
2544 | 1031 (funcall (or (get symbol 'custom-set) 'set-default) symbol |
1032 (eval (car value))))) | |
1033 value)) | |
1034 | |
1035 (defun custom-theme-reset-variables (theme &rest args) | |
1036 "Reset the value of the variables to values previously defined. | |
1037 Associate this setting with THEME. | |
1038 | |
1039 ARGS is a list of lists of the form | |
1040 | |
1041 (VARIABLE TO-THEME) | |
1042 | |
1043 This means reset VARIABLE to its value in TO-THEME." | |
1044 (custom-check-theme theme) | |
4021 | 1045 (mapcar #'(lambda (arg) |
1046 (apply 'custom-theme-reset-internal arg) | |
1047 (custom-push-theme 'theme-value (car arg) theme 'reset (cadr arg))) | |
2544 | 1048 args)) |
1049 | |
1050 (defun custom-reset-variables (&rest args) | |
1051 "Reset the value of the variables to values previously saved. | |
1052 This is the setting associated the `user' theme. | |
1053 | |
1054 ARGS is a list of lists of the form | |
1055 | |
1056 (VARIABLE TO-THEME) | |
1057 | |
1058 This means reset VARIABLE to its value in TO-THEME." | |
1059 (apply 'custom-theme-reset-variables 'user args)) | |
1060 | |
1061 ;;; The End. | |
1333 | 1062 |
5284
d27c1ee1943b
Make the order of preloaded-file-list more sane.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1063 ;; XEmacs; we order preloaded-file-list such that there's no need for |
d27c1ee1943b
Make the order of preloaded-file-list more sane.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1064 ;; custom-declare-variable-list. |
1333 | 1065 |
428 | 1066 ;; custom.el ends here |