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