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