Mercurial > hg > xemacs-beta
annotate lisp/custom.el @ 5887:6eca500211f4
Prototype for X509_check_host() has changed, detect this in configure.ac
ChangeLog addition:
2015-04-09 Aidan Kehoe <kehoea@parhasard.net>
* configure.ac:
If X509_check_host() is available, check the number of arguments
it takes. Don't use it if it takes any number of arguments other
than five. Also don't use it if <openssl/x509v3.h> does not
declare it, since if that is so there is no portable way to tell
how many arguments it should take, and so we would end up smashing
the stack.
* configure: Regenerate.
src/ChangeLog addition:
2015-04-09 Aidan Kehoe <kehoea@parhasard.net>
* tls.c:
#include <openssl/x509v3.h> for its prototype for
X509_check_host().
* tls.c (tls_open):
Pass the new fifth argument to X509_check_host().
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Thu, 09 Apr 2015 14:27:02 +0100 |
parents | a3234d587dc2 |
children |
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)) | |
5787
10395934b99e
Add :risky and :safe options to defcustom.
Mike Sperber <sperber@deinprogramm.de>
parents:
5474
diff
changeset
|
181 ((eq keyword :risky) |
10395934b99e
Add :risky and :safe options to defcustom.
Mike Sperber <sperber@deinprogramm.de>
parents:
5474
diff
changeset
|
182 (put symbol 'risky-local-variable value)) |
10395934b99e
Add :risky and :safe options to defcustom.
Mike Sperber <sperber@deinprogramm.de>
parents:
5474
diff
changeset
|
183 ((eq keyword :safe) |
10395934b99e
Add :risky and :safe options to defcustom.
Mike Sperber <sperber@deinprogramm.de>
parents:
5474
diff
changeset
|
184 (put symbol 'safe-local-variable value)) |
2544 | 185 ((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
|
186 (put symbol 'custom-type value)) |
2544 | 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. | |
5787
10395934b99e
Add :risky and :safe options to defcustom.
Mike Sperber <sperber@deinprogramm.de>
parents:
5474
diff
changeset
|
271 :risky Set SYMBOL's `risky-local-variable' property to VALUE. |
10395934b99e
Add :risky and :safe options to defcustom.
Mike Sperber <sperber@deinprogramm.de>
parents:
5474
diff
changeset
|
272 :safe Set SYMBOL's `safe-local-variable' property to VALUE. |
1333 | 273 :version |
274 VALUE should be a string specifying that the variable was | |
903 | 275 first introduced, or its default value was changed, in Emacs |
276 version VERSION. | |
5812
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
277 :package-version |
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
278 VALUE should be a list with the form (PACKAGE . VERSION), |
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
279 where PACKAGE and VERSION are strings. |
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
280 |
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
281 This specifies that the variable was first introduced, or its |
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
282 default value was changed, in PACKAGE version VERSION. This |
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
283 keyword takes priority over :version. |
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
284 |
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
285 Since PACKAGE must be unique and the user might see it in an |
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
286 error message, a good choice is the official name of the |
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
287 package, such as MH-E or Gnus. |
2544 | 288 :tag LABEL |
289 Use LABEL, a string, instead of the item's name, to label the item | |
290 in customization menus and buffers. | |
291 :load FILE | |
292 Load file FILE (a string) before displaying this customization | |
293 item. Loading is done with `load', and only if the file is | |
294 not already loaded. | |
295 :set-after VARIABLES | |
296 Specifies that SYMBOL should be set after the list of variables | |
297 VARIABLES when both have been customized. | |
428 | 298 |
299 Read the section about customization in the Emacs Lisp manual for more | |
300 information." | |
301 `(custom-declare-variable (quote ,symbol) (quote ,value) ,doc ,@args)) | |
302 | |
303 ;;; The `defface' Macro. | |
304 | |
305 (defmacro defface (face spec doc &rest args) | |
306 "Declare FACE as a customizable face that defaults to SPEC. | |
307 FACE does not need to be quoted. | |
308 | |
309 Third argument DOC is the face documentation. | |
310 | |
311 If FACE has been set with `custom-set-face', set the face attributes | |
312 as specified by that function, otherwise set the face attributes | |
313 according to SPEC. | |
314 | |
315 The remaining arguments should have the form | |
316 | |
317 [KEYWORD VALUE]... | |
318 | |
319 The following KEYWORDs are defined: | |
320 | |
321 :group VALUE should be a customization group. | |
322 Add FACE to that group. | |
323 | |
324 SPEC should be an alist of the form ((DISPLAY ATTS)...). | |
325 | |
326 ATTS is a list of face attributes and their values. The possible | |
327 attributes are defined in the variable `custom-face-attributes'. | |
328 | |
329 The ATTS of the first entry in SPEC where the DISPLAY matches the | |
330 frame should take effect in that frame. DISPLAY can either be the | |
331 symbol t, which will match all frames, or an alist of the form | |
332 \((REQ ITEM...)...) | |
333 | |
334 For the DISPLAY to match a FRAME, the REQ property of the frame must | |
335 match one of the ITEM. The following REQ are defined: | |
336 | |
337 `type' (the value of `window-system') | |
442 | 338 Should be one of `x', `mswindows', or `tty'. |
428 | 339 |
340 `class' (the frame's color support) | |
341 Should be one of `color', `grayscale', or `mono'. | |
342 | |
5373
b6e59ea11533
Add min-colors specifier to defface, and document it.
Jeff Sparkes <jsparkes@gmail.com>
parents:
5284
diff
changeset
|
343 `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
|
344 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
|
345 |
428 | 346 `background' (what color is used for the background text) |
347 Should be one of `light' or `dark'. | |
348 | |
349 Read the section about customization in the Emacs Lisp manual for more | |
350 information." | |
351 `(custom-declare-face (quote ,face) ,spec ,doc ,@args)) | |
352 | |
353 ;;; The `defgroup' Macro. | |
354 | |
2544 | 355 (defun custom-current-group () |
356 (cdr (assoc load-file-name custom-current-group-alist))) | |
357 | |
428 | 358 (defun custom-declare-group (symbol members doc &rest args) |
359 "Like `defgroup', but SYMBOL is evaluated as a normal argument." | |
360 (while members | |
361 (apply 'custom-add-to-group symbol (car members)) | |
362 (pop members)) | |
363 (when doc | |
364 (put symbol 'group-documentation doc)) | |
365 (while args | |
366 (let ((arg (car args))) | |
367 (setq args (cdr args)) | |
368 (check-argument-type 'keywordp arg) | |
369 (let ((keyword arg) | |
2544 | 370 (value (car args))) |
428 | 371 (unless args |
372 (signal 'error (list "Keyword is missing an argument" keyword))) | |
2544 | 373 (setq args (cdr args)) |
374 (cond ((eq keyword :prefix) | |
375 (put symbol 'custom-prefix value)) | |
376 (t | |
377 (custom-handle-keyword symbol keyword value | |
378 'custom-group)))))) | |
379 ;; Record the group on the `current' list. | |
380 (let ((elt (assoc load-file-name custom-current-group-alist))) | |
381 (if elt (setcdr elt symbol) | |
382 (push (cons load-file-name symbol) custom-current-group-alist))) | |
428 | 383 (run-hooks 'custom-define-hook) |
384 symbol) | |
385 | |
386 (defmacro defgroup (symbol members doc &rest args) | |
387 "Declare SYMBOL as a customization group containing MEMBERS. | |
388 SYMBOL does not need to be quoted. | |
389 | |
390 Third arg DOC is the group documentation. | |
391 | |
392 MEMBERS should be an alist of the form ((NAME WIDGET)...) where NAME | |
393 is a symbol and WIDGET is a widget for editing that symbol. Useful | |
394 widgets are `custom-variable' for editing variables, `custom-face' for | |
395 edit faces, and `custom-group' for editing groups. | |
396 | |
397 The remaining arguments should have the form | |
398 | |
399 [KEYWORD VALUE]... | |
400 | |
2544 | 401 The following KEYWORDs are defined: |
428 | 402 |
403 :group VALUE should be a customization group. | |
404 Add SYMBOL to that group. | |
405 | |
406 Read the section about customization in the Emacs Lisp manual for more | |
407 information." | |
2544 | 408 |
409 ;; XEmacs: Evidently a purposeful omission from the docs: | |
410 ;:version VALUE should be a string specifying that the group was introduced | |
411 ; in Emacs version VERSION. | |
412 ; | |
413 | |
414 ;; FSF: (not a problem for XEmacs) | |
415 ;; It is better not to use backquote in this file, | |
416 ;; because that makes a bootstrapping problem | |
417 ;; if you need to recompile all the Lisp files using interpreted code. | |
418 ; (nconc (list 'custom-declare-group (list 'quote symbol) members doc) args)) | |
428 | 419 `(custom-declare-group (quote ,symbol) ,members ,doc ,@args)) |
420 | |
421 (defvar custom-group-hash-table (make-hash-table :size 300 :test 'eq) | |
422 "Hash-table of non-empty groups.") | |
423 | |
424 (defun custom-add-to-group (group option widget) | |
425 "To existing GROUP add a new OPTION of type WIDGET. | |
2544 | 426 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
|
427 (or group (display-warning 'custom |
294ab9180fad
#'custom-add-to-group: warn if GROUP is nil.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5373
diff
changeset
|
428 (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
|
429 widget option))) |
2544 | 430 (let ((members (get group 'custom-group)) |
431 (entry (list option widget))) | |
432 (unless (member entry members) | |
433 (put group 'custom-group (nconc members (list entry))))) | |
428 | 434 (puthash group t custom-group-hash-table)) |
435 | |
2544 | 436 (defun custom-group-of-mode (mode) |
437 "Return the custom group corresponding to the major or minor MODE. | |
438 If no such group is found, return nil." | |
439 (or (get mode 'custom-mode-group) | |
440 (if (or (get mode 'custom-group) | |
441 (and (string-match "-mode\\'" (symbol-name mode)) | |
442 (get (setq mode (intern (substring (symbol-name mode) | |
443 0 (match-beginning 0)))) | |
444 'custom-group))) | |
445 mode))) | |
446 | |
428 | 447 ;;; Properties. |
448 | |
449 (defun custom-handle-all-keywords (symbol args type) | |
450 "For customization option SYMBOL, handle keyword arguments ARGS. | |
451 Third argument TYPE is the custom option type." | |
2544 | 452 (unless (memq :group args) |
453 (custom-add-to-group (custom-current-group) symbol type)) | |
428 | 454 (while args |
455 (let ((arg (car args))) | |
456 (setq args (cdr args)) | |
457 (check-argument-type 'keywordp arg) | |
458 (let ((keyword arg) | |
459 (value (car args))) | |
460 (unless args | |
461 (signal 'error (list "Keyword is missing an argument" keyword))) | |
462 (setq args (cdr args)) | |
463 (custom-handle-keyword symbol keyword value type))))) | |
464 | |
465 (defun custom-handle-keyword (symbol keyword value type) | |
466 "For customization option SYMBOL, handle KEYWORD with VALUE. | |
467 Fourth argument TYPE is the custom option type." | |
468 (cond ((eq keyword :group) | |
903 | 469 (custom-add-to-group value symbol type)) |
470 ((eq keyword :version) | |
471 (custom-add-version symbol value)) | |
5812
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
472 ((eq keyword :package-version) |
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
473 (custom-add-package-version symbol value)) |
903 | 474 ((eq keyword :link) |
475 (custom-add-link symbol value)) | |
476 ((eq keyword :load) | |
477 (custom-add-load symbol value)) | |
478 ((eq keyword :tag) | |
479 (put symbol 'custom-tag value)) | |
480 ((eq keyword :set-after) | |
481 (custom-add-dependencies symbol value)) | |
482 (t | |
483 (signal 'error (list "Unknown keyword" keyword))))) | |
484 | |
485 (defun custom-add-dependencies (symbol value) | |
486 "To the custom option SYMBOL, add dependencies specified by VALUE. | |
487 VALUE should be a list of symbols. For each symbol in that list, | |
488 this specifies that SYMBOL should be set after the specified symbol, if | |
489 both appear in constructs like `custom-set-variables'." | |
490 (unless (listp value) | |
491 (error "Invalid custom dependency `%s'" value)) | |
492 (let* ((deps (get symbol 'custom-dependencies)) | |
493 (new-deps deps)) | |
494 (while value | |
495 (let ((dep (car value))) | |
496 (unless (symbolp dep) | |
497 (error "Invalid custom dependency `%s'" dep)) | |
498 (unless (memq dep new-deps) | |
499 (setq new-deps (cons dep new-deps))) | |
500 (setq value (cdr value)))) | |
501 (unless (eq deps new-deps) | |
502 (put symbol 'custom-dependencies new-deps)))) | |
428 | 503 |
504 (defun custom-add-option (symbol option) | |
505 "To the variable SYMBOL add OPTION. | |
506 | |
507 If SYMBOL is a hook variable, OPTION should be a hook member. | |
508 For other types variables, the effect is undefined." | |
509 (let ((options (get symbol 'custom-options))) | |
510 (unless (member option options) | |
511 (put symbol 'custom-options (cons option options))))) | |
512 | |
513 (defun custom-add-link (symbol widget) | |
514 "To the custom option SYMBOL add the link WIDGET." | |
515 (let ((links (get symbol 'custom-links))) | |
516 (unless (member widget links) | |
517 (put symbol 'custom-links (cons widget links))))) | |
518 | |
519 (defun custom-add-version (symbol version) | |
520 "To the custom option SYMBOL add the version VERSION." | |
521 (put symbol 'custom-version version)) | |
522 | |
5812
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
523 (defun custom-add-package-version (symbol version) |
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
524 "To the custom option SYMBOL add the package version VERSION." |
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
525 (unless (and (consp version) |
5828
a3234d587dc2
Make :package-version in customize right.
Mike Sperber <sperber@deinprogramm.de>
parents:
5812
diff
changeset
|
526 (symbolp (car version)) |
5812
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
527 (stringp (cdr version))) |
5828
a3234d587dc2
Make :package-version in customize right.
Mike Sperber <sperber@deinprogramm.de>
parents:
5812
diff
changeset
|
528 (error "Invalid package version `%s'" version)) |
5812
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
529 (put symbol 'custom-package-version version)) |
7b42a97af782
Don't bail out on :package-version in `defcustom'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5787
diff
changeset
|
530 |
428 | 531 (defun custom-add-load (symbol load) |
532 "To the custom option SYMBOL add the dependency LOAD. | |
533 LOAD should be either a library file name, or a feature name." | |
534 (puthash symbol t custom-group-hash-table) | |
535 (let ((loads (get symbol 'custom-loads))) | |
536 (unless (member load loads) | |
537 (put symbol 'custom-loads (cons load loads))))) | |
538 | |
2544 | 539 (defun custom-autoload (symbol load) |
540 "Mark SYMBOL as autoloaded custom variable and add dependency LOAD." | |
541 (put symbol 'custom-autoload t) | |
542 (custom-add-load symbol load)) | |
543 | |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4441
diff
changeset
|
544 ;; XEmacs; |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4441
diff
changeset
|
545 ;; #'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
|
546 ;; #'user-variable-p. |
2544 | 547 |
548 ;;; Loading files needed to customize a symbol. | |
549 ;;; This is in custom.el because menu-bar.el needs it for toggle cmds. | |
550 | |
551 (defvar custom-load-recursion nil | |
552 "Hack to avoid recursive dependencies.") | |
553 | |
554 (defun custom-load-symbol (symbol) | |
555 "Load all dependencies for SYMBOL." | |
556 (unless custom-load-recursion | |
557 (let ((custom-load-recursion t)) | |
558 (dolist (load (get symbol 'custom-loads)) | |
559 (cond ((symbolp load) (condition-case nil (require load) (error nil))) | |
560 ;; This is subsumed by the test below, but it's much faster. | |
561 ((assoc load load-history)) | |
562 ;; This was just (assoc (locate-library load) load-history) | |
563 ;; but has been optimized not to load locate-library | |
564 ;; if not necessary. | |
565 ((let ((regexp (concat "\\(\\`\\|/\\)" (regexp-quote load) | |
566 "\\(\\'\\|\\.\\)")) | |
567 (found nil)) | |
568 (dolist (loaded load-history) | |
569 (and (stringp (car loaded)) | |
570 (string-match regexp (car loaded)) | |
571 (setq found t))) | |
572 found)) | |
573 ;; Without this, we would load cus-edit recursively. | |
574 ;; We are still loading it when we call this, | |
575 ;; and it is not in load-history yet. | |
576 ((equal load "cus-edit")) | |
577 (t (condition-case nil (load load) (error nil)))))))) | |
428 | 578 |
579 (defvar custom-known-themes '(user standard) | |
2544 | 580 "Themes that have been define with `deftheme'. |
581 The default value is the list (user standard). The theme `standard' | |
582 contains the Emacs standard settings from the original Lisp files. The | |
583 theme `user' contains all the the settings the user customized and saved. | |
584 Additional themes declared with the `deftheme' macro will be added to | |
585 the front of this list.") | |
428 | 586 |
2544 | 587 (defun custom-declare-theme (theme feature &optional doc &rest args) |
588 "Like `deftheme', but THEME is evaluated as a normal argument. | |
589 FEATURE is the feature this theme provides. This symbol is created | |
590 from THEME by `custom-make-theme-feature'." | |
591 (add-to-list 'custom-known-themes theme) | |
428 | 592 (put theme 'theme-feature feature) |
2544 | 593 (when doc |
594 (put theme 'theme-documentation doc)) | |
595 (while args | |
596 (let ((arg (car args))) | |
597 (setq args (cdr args)) | |
598 (check-argument-type 'keywordp arg) | |
599 (let ((keyword arg) | |
600 (value (car args))) | |
601 (unless args | |
602 (signal 'error (list "Keyword is missing an argument" keyword))) | |
603 (setq args (cdr args)) | |
604 (cond ((eq keyword :short-description) | |
605 (put theme 'theme-short-description value)) | |
606 ((eq keyword :immediate) | |
607 (put theme 'theme-immediate value)) | |
608 ((eq keyword :variable-set-string) | |
609 (put theme 'theme-variable-set-string value)) | |
610 ((eq keyword :variable-reset-string) | |
611 (put theme 'theme-variable-reset-string value)) | |
612 ((eq keyword :face-set-string) | |
613 (put theme 'theme-face-set-string value)) | |
614 ((eq keyword :face-reset-string) | |
615 (put theme 'theme-face-reset-string value))))))) | |
616 | |
617 (defmacro deftheme (theme &optional doc &rest args) | |
618 "Declare custom theme THEME. | |
619 The optional argument DOC is a doc string describing the theme. | |
620 The remaining arguments should have the form | |
621 | |
622 [KEYWORD VALUE]... | |
623 | |
624 The following KEYWORD's are defined: | |
625 | |
626 :short-description | |
627 VALUE is a short (one line) description of the theme. If not | |
628 given, DOC is used. | |
629 :immediate | |
630 If VALUE is non-nil, variables specified in this theme are set | |
631 immediately when loading the theme. | |
632 :variable-set-string | |
633 VALUE is a string used to indicate that a variable takes its | |
634 setting from this theme. It is passed to FORMAT with the name | |
635 of the theme as an additional argument. If not given, a | |
636 generic description is used. | |
637 :variable-reset-string | |
638 VALUE is a string used in the case a variable has been forced | |
639 to its value in this theme. It is passed to FORMAT with the | |
640 name of the theme as an additional argument. If not given, a | |
641 generic description is used. | |
642 :face-set-string | |
643 VALUE is a string used to indicate that a face takes its | |
644 setting from this theme. It is passed to FORMAT with the name | |
645 of the theme as an additional argument. If not given, a | |
646 generic description is used. | |
647 :face-reset-string | |
648 VALUE is a string used in the case a face has been forced to | |
649 its value in this theme. It is passed to FORMAT with the name | |
650 of the theme as an additional argument. If not given, a | |
651 generic description is used. | |
652 | |
653 Any theme `foo' should be defined in a file called `foo-theme.el'; | |
654 see `custom-make-theme-feature' for more information." | |
655 (let ((feature (custom-make-theme-feature theme))) | |
656 ;; It is better not to use backquote in this file, | |
657 ;; because that makes a bootstrapping problem | |
658 ;; if you need to recompile all the Lisp files using interpreted code. | |
659 (nconc (list 'custom-declare-theme | |
660 (list 'quote theme) | |
661 (list 'quote feature) | |
662 doc) args))) | |
428 | 663 |
664 (defun custom-make-theme-feature (theme) | |
2544 | 665 "Given a symbol THEME, create a new symbol by appending \"-theme\". |
666 Store this symbol in the `theme-feature' property of THEME. | |
667 Calling `provide-theme' to provide THEME actually puts `THEME-theme' | |
668 into `features'. | |
428 | 669 |
2544 | 670 This allows for a file-name convention for autoloading themes: |
671 Every theme X has a property `provide-theme' whose value is \"X-theme\". | |
672 \(require-theme X) then attempts to load the file `X-theme.el'." | |
673 (intern (concat (symbol-name theme) "-theme"))) | |
428 | 674 |
675 (defsubst custom-theme-p (theme) | |
676 "Non-nil when THEME has been defined." | |
677 (memq theme custom-known-themes)) | |
678 | |
679 (defsubst custom-check-theme (theme) | |
2544 | 680 "Check whether THEME is valid, and signal an error if it is not." |
428 | 681 (unless (custom-theme-p theme) |
682 (error "Unknown theme `%s'" theme))) | |
683 | |
684 ;;; Initializing. | |
685 | |
686 (defun custom-push-theme (prop symbol theme mode value) | |
2544 | 687 "Add (THEME MODE VALUE) to the list in property PROP of SYMBOL. |
688 If the first element in that list is already (THEME ...), | |
689 discard it first. | |
690 | |
691 MODE can be either the symbol `set' or the symbol `reset'. If it is the | |
692 symbol `set', then VALUE is the value to use. If it is the symbol | |
693 `reset', then VALUE is the mode to query instead. | |
694 | |
695 In the following example for the variable `goto-address-url-face', the | |
696 theme `subtle-hacker' uses the same value for the variable as the theme | |
697 `gnome2': | |
698 | |
699 \((standard set bold) | |
700 \(gnome2 set info-xref) | |
701 \(jonadab set underline) | |
702 \(subtle-hacker reset gnome2)) | |
703 | |
704 | |
705 If a value has been stored for themes A B and C, and a new value | |
706 is to be stored for theme C, then the old value of C is discarded. | |
707 If a new value is to be stored for theme B, however, the old value | |
708 of B is not discarded because B is not the car of the list. | |
709 | |
710 For variables, list property PROP is `theme-value'. | |
711 For faces, list property PROP is `theme-face'. | |
712 This is used in `custom-do-theme-reset', for example. | |
713 | |
714 The list looks the same in any case; the examples shows a possible | |
715 value of the `theme-face' property for the face `region': | |
716 | |
717 \((gnome2 set ((t (:foreground \"cyan\" :background \"dark cyan\")))) | |
718 \(standard set ((((class color) (background dark)) | |
719 \(:background \"blue\")) | |
720 \(t (:background \"gray\"))))) | |
721 | |
722 This records values for the `standard' and the `gnome2' themes. | |
723 The user has not customized the face; had he done that, | |
724 the list would contain an entry for the `user' theme, too. | |
725 See `custom-known-themes' for a list of known themes." | |
428 | 726 (let ((old (get symbol prop))) |
727 (if (eq (car-safe (car-safe old)) theme) | |
728 (setq old (cdr old))) | |
729 (put symbol prop (cons (list theme mode value) old)))) | |
730 | |
988 | 731 (defvar custom-local-buffer nil |
732 "Non-nil, in a Customization buffer, means customize a specific buffer. | |
733 If this variable is non-nil, it should be a buffer, | |
734 and it means customize the local bindings of that buffer. | |
735 This variable is a permanent local, and it normally has a local binding | |
736 in every Customization buffer.") | |
737 (put 'custom-local-buffer 'permanent-local t) | |
738 | |
428 | 739 (defun custom-set-variables (&rest args) |
740 "Initialize variables according to user preferences. | |
741 The settings are registered as theme `user'. | |
2544 | 742 The arguments should each be a list of the form: |
428 | 743 |
744 (SYMBOL VALUE [NOW [REQUEST [COMMENT]]]) | |
745 | |
746 The unevaluated VALUE is stored as the saved value for SYMBOL. | |
747 If NOW is present and non-nil, VALUE is also evaluated and bound as | |
748 the default value for the SYMBOL. | |
2544 | 749 |
428 | 750 REQUEST is a list of features we must 'require for SYMBOL. |
751 COMMENT is a comment string about SYMBOL." | |
752 (apply 'custom-theme-set-variables 'user args)) | |
753 | |
754 (defun custom-theme-set-variables (theme &rest args) | |
755 "Initialize variables according to settings specified by args. | |
756 Records the settings as belonging to THEME. | |
757 | |
2544 | 758 The arguments should be a list where each entry has the form: |
759 | |
760 (SYMBOL VALUE [NOW [REQUEST [COMMENT]]]) | |
761 | |
762 The unevaluated VALUE is stored as the saved value for SYMBOL. | |
763 If NOW is present and non-nil, VALUE is also evaluated and bound as | |
764 the default value for the SYMBOL. | |
765 REQUEST is a list of features we must 'require for SYMBOL. | |
766 COMMENT is a comment string about SYMBOL. | |
767 | |
768 Several properties of THEME and SYMBOL are used in the process: | |
769 | |
770 If THEME property `theme-immediate' is non-nil, this is equivalent of | |
771 providing the NOW argument to all symbols in the argument list: SYMBOL | |
772 is bound to the evaluated VALUE. The only difference is SYMBOL property | |
773 `force-value': if NOW is non-nil, SYMBOL's property `force-value' is set to | |
774 the symbol `rogue', else if THEME's property `theme-immediate' is non-nil, | |
775 FACE's property `force-face' is set to the symbol `immediate'. | |
776 | |
777 VALUE itself is saved unevaluated as SYMBOL property `saved-value' and | |
778 in SYMBOL's list property `theme-value' \(using `custom-push-theme')." | |
428 | 779 (custom-check-theme theme) |
780 (let ((immediate (get theme 'theme-immediate))) | |
2544 | 781 (setq args |
782 (sort args | |
783 (lambda (a1 a2) | |
784 (let* ((sym1 (car a1)) | |
785 (sym2 (car a2)) | |
786 (1-then-2 (memq sym1 (get sym2 'custom-dependencies))) | |
787 (2-then-1 (memq sym2 (get sym1 'custom-dependencies)))) | |
788 (cond ((and 1-then-2 2-then-1) | |
789 (error "Circular custom dependency between `%s' and `%s'" | |
790 sym1 sym2)) | |
791 (2-then-1 nil) | |
792 ;; Put symbols with :require last. The macro | |
793 ;; define-minor-mode generates a defcustom | |
794 ;; with a :require and a :set, where the | |
795 ;; setter function calls the mode function. | |
796 ;; Putting symbols with :require last ensures | |
797 ;; that the mode function will see other | |
798 ;; customized values rather than default | |
799 ;; values. | |
800 (t (nth 3 a2))))))) | |
988 | 801 (while args |
428 | 802 (let ((entry (car args))) |
2544 | 803 (if (listp entry) |
804 (let* ((symbol (nth 0 entry)) | |
805 (value (nth 1 entry)) | |
806 (now (nth 2 entry)) | |
807 (requests (nth 3 entry)) | |
808 (comment (nth 4 entry)) | |
809 set) | |
810 (when requests | |
811 (put symbol 'custom-requests requests) | |
812 (mapc 'require requests)) | |
813 (setq set (or (get symbol 'custom-set) 'custom-set-default)) | |
814 (put symbol 'saved-value (list value)) | |
815 (put symbol 'saved-variable-comment comment) | |
428 | 816 (custom-push-theme 'theme-value symbol theme 'set value) |
2544 | 817 ;; Allow for errors in the case where the setter has |
818 ;; changed between versions, say, but let the user know. | |
819 (condition-case data | |
820 (cond ((or now immediate) | |
821 ;; Rogue variable, set it now. | |
822 (put symbol 'force-value (if now 'rogue 'immediate)) | |
823 (funcall set symbol (eval value))) | |
824 ((default-boundp symbol) | |
825 ;; Something already set this, overwrite it. | |
826 (funcall set symbol (eval value)))) | |
827 (error | |
988 | 828 (message "Error setting %s: %s" symbol data))) |
2544 | 829 (setq args (cdr args)) |
830 (and (or now (default-boundp symbol)) | |
831 (put symbol 'variable-comment comment))) | |
832 ;; Old format, a plist of SYMBOL VALUE pairs. | |
833 (message "Warning: old format `custom-set-variables'") | |
834 (ding) | |
835 (sit-for 2) | |
836 (let ((symbol (nth 0 args)) | |
837 (value (nth 1 args))) | |
838 (put symbol 'saved-value (list value)) | |
428 | 839 (custom-push-theme 'theme-value symbol theme 'set value)) |
2544 | 840 (setq args (cdr (cdr args)))))))) |
428 | 841 |
988 | 842 (defun custom-set-default (variable value) |
843 "Default :set function for a customizable variable. | |
844 Normally, this sets the default value of VARIABLE to VALUE, | |
845 but if `custom-local-buffer' is non-nil, | |
846 this sets the local binding in that buffer instead." | |
847 (if custom-local-buffer | |
848 (with-current-buffer custom-local-buffer | |
849 (set variable value)) | |
850 (set-default variable value))) | |
428 | 851 |
4744
17f7e9191c0b
Rationalise duplicated functionality, #'custom-quote, #'quote-maybe.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
852 ;; 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
|
853 (defalias 'custom-quote 'quote-maybe) |
2544 | 854 |
855 (defun customize-mark-to-save (symbol) | |
856 "Mark SYMBOL for later saving. | |
857 | |
858 If the default value of SYMBOL is different from the standard value, | |
859 set the `saved-value' property to a list whose car evaluates to the | |
860 default value. Otherwise, set it to nil. | |
861 | |
862 To actually save the value, call `custom-save-all'. | |
863 | |
864 Return non-nil iff the `saved-value' property actually changed." | |
865 (let* ((get (or (get symbol 'custom-get) 'default-value)) | |
866 (value (funcall get symbol)) | |
867 (saved (get symbol 'saved-value)) | |
868 (standard (get symbol 'standard-value)) | |
869 (comment (get symbol 'customized-variable-comment))) | |
870 ;; Save default value iff different from standard value. | |
871 (if (or (null standard) | |
872 (not (equal value (condition-case nil | |
873 (eval (car standard)) | |
874 (error nil))))) | |
4744
17f7e9191c0b
Rationalise duplicated functionality, #'custom-quote, #'quote-maybe.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
875 (put symbol 'saved-value (list (quote-maybe value))) |
2544 | 876 (put symbol 'saved-value nil)) |
877 ;; Clear customized information (set, but not saved). | |
878 (put symbol 'customized-value nil) | |
879 ;; Save any comment that might have been set. | |
880 (when comment | |
881 (put symbol 'saved-variable-comment comment)) | |
882 (not (equal saved (get symbol 'saved-value))))) | |
883 | |
884 (defun customize-mark-as-set (symbol) | |
885 "Mark current value of SYMBOL as being set from customize. | |
886 | |
887 If the default value of SYMBOL is different from the saved value if any, | |
888 or else if it is different from the standard value, set the | |
889 `customized-value' property to a list whose car evaluates to the | |
890 default value. Otherwise, set it to nil. | |
891 | |
892 Return non-nil iff the `customized-value' property actually changed." | |
893 (let* ((get (or (get symbol 'custom-get) 'default-value)) | |
894 (value (funcall get symbol)) | |
895 (customized (get symbol 'customized-value)) | |
896 (old (or (get symbol 'saved-value) (get symbol 'standard-value)))) | |
897 ;; Mark default value as set iff different from old value. | |
898 (if (or (null old) | |
899 (not (equal value (condition-case nil | |
900 (eval (car old)) | |
901 (error nil))))) | |
4744
17f7e9191c0b
Rationalise duplicated functionality, #'custom-quote, #'quote-maybe.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
902 (put symbol 'customized-value (list (quote-maybe value))) |
2544 | 903 (put symbol 'customized-value nil)) |
904 ;; Changed? | |
905 (not (equal customized (get symbol 'customized-value))))) | |
906 | |
907 ;;; Theme Manipulation | |
908 | |
909 (defvar custom-loaded-themes nil | |
910 "Themes in the order they are loaded.") | |
911 | |
912 (defun custom-theme-loaded-p (theme) | |
913 "Return non-nil when THEME has been loaded." | |
914 (memq theme custom-loaded-themes)) | |
915 | |
916 (defun provide-theme (theme) | |
917 "Indicate that this file provides THEME. | |
918 Add THEME to `custom-loaded-themes' and `provide' whatever | |
919 is stored in THEME's property `theme-feature'. | |
920 | |
921 Usually the theme-feature property contains a symbol created | |
922 by `custom-make-theme-feature'." | |
923 (custom-check-theme theme) | |
924 (provide (get theme 'theme-feature)) | |
925 (setq custom-loaded-themes (nconc (list theme) custom-loaded-themes))) | |
926 | |
927 (defun require-theme (theme) | |
928 "Try to load a theme by requiring its feature. | |
929 THEME's feature is stored in THEME's `theme-feature' property. | |
930 | |
931 Usually the `theme-feature' property contains a symbol created | |
932 by `custom-make-theme-feature'." | |
933 ;; Note we do no check for validity of the theme here. | |
934 ;; This allows to pull in themes by a file-name convention | |
935 (require (or (get theme 'theme-feature) | |
936 (custom-make-theme-feature theme)))) | |
937 | |
938 (defun custom-remove-theme (spec-alist theme) | |
939 "Delete all elements from SPEC-ALIST whose car is THEME." | |
940 (let ((elt (assoc theme spec-alist))) | |
941 (while elt | |
942 (setq spec-alist (delete elt spec-alist) | |
943 elt (assoc theme spec-alist)))) | |
944 spec-alist) | |
945 | |
946 (defun custom-do-theme-reset (theme) | |
947 "Undo all settings defined by THEME. | |
948 | |
949 A variable remains unchanged if its property `theme-value' does not | |
950 contain a value for THEME. A face remains unchanged if its property | |
951 `theme-face' does not contain a value for THEME. In either case, all | |
952 settings for THEME are removed from the property and the variable or | |
953 face is set to the `user' theme. | |
428 | 954 |
2544 | 955 See `custom-known-themes' for a list of known themes." |
956 (let (spec-list) | |
957 (mapatoms (lambda (symbol) | |
958 ;; This works even if symbol is both a variable and a | |
959 ;; face. | |
960 (setq spec-list (get symbol 'theme-value)) | |
961 (when spec-list | |
962 (put symbol 'theme-value (custom-remove-theme spec-list theme)) | |
963 (custom-theme-reset-internal symbol 'user)) | |
964 (setq spec-list (get symbol 'theme-face)) | |
965 (when spec-list | |
966 (put symbol 'theme-face (custom-remove-theme spec-list theme)) | |
967 (custom-theme-reset-internal-face symbol 'user)))))) | |
968 | |
969 (defun custom-theme-load-themes (by-theme &rest body) | |
970 "Load the themes specified by BODY. | |
971 Record them as required by theme BY-THEME. BODY is a sequence of either | |
972 | |
973 THEME | |
974 BY-THEME requires THEME | |
975 \(reset THEME) | |
976 Undo all the settings made by THEME | |
977 \(hidden THEME) | |
978 Require THEME but hide it from the user | |
979 | |
980 All the themes loaded for BY-THEME are recorded in BY-THEME's property | |
981 `theme-loads-themes'. Any theme loaded with the hidden predicate will | |
982 be given the property `theme-hidden' unless it has been loaded before. | |
983 Whether a theme has been loaded before is determined by the function | |
984 `custom-theme-loaded-p'." | |
985 (custom-check-theme by-theme) | |
986 (let ((theme) | |
987 (themes-loaded (get by-theme 'theme-loads-themes))) | |
988 (while theme | |
989 (setq theme (car body) | |
990 body (cdr body)) | |
991 (cond ((and (consp theme) (eq (car theme) 'reset)) | |
992 (custom-do-theme-reset (cadr theme))) | |
993 ((and (consp theme) (eq (car theme) 'hidden)) | |
994 (require-theme (cadr theme)) | |
995 (unless (custom-theme-loaded-p (cadr theme)) | |
996 (put (cadr theme) 'theme-hidden t))) | |
997 (t | |
998 (require-theme theme) | |
999 (put theme 'theme-hidden nil))) | |
1000 (setq themes-loaded (nconc (list theme) themes-loaded))) | |
1001 (put by-theme 'theme-loads-themes themes-loaded))) | |
1002 | |
1003 (defun custom-load-themes (&rest body) | |
1004 "Load themes for the USER theme as specified by BODY. | |
1005 | |
1006 See `custom-theme-load-themes' for more information on BODY." | |
1007 (apply 'custom-theme-load-themes 'user body)) | |
1008 | |
1009 ; (defsubst copy-upto-last (elt list) | |
1010 ; "Copy all the elements of the list upto the last occurrence of elt" | |
1011 ; ;; Is it faster to do more work in C than to do less in elisp? | |
1012 ; (nreverse (cdr (member elt (reverse list))))) | |
1013 | |
1014 (defun custom-theme-value (theme theme-spec-list) | |
1015 "Determine the value for THEME defined by THEME-SPEC-LIST. | |
1016 Returns a list with the original value if found; nil otherwise. | |
1017 | |
1018 THEME-SPEC-LIST is an alist with themes as its key. As new themes are | |
1019 installed, these are added to the front of THEME-SPEC-LIST. | |
1020 Each element has the form | |
1021 | |
1022 \(THEME MODE VALUE) | |
1023 | |
1024 MODE is either the symbol `set' or the symbol `reset'. See | |
1025 `custom-push-theme' for more information on the format of | |
1026 THEME-SPEC-LIST." | |
1027 ;; Note we do _NOT_ signal an error if the theme is unknown | |
1028 ;; it might have gone away without the user knowing. | |
1029 (let ((value (cdr (assoc theme theme-spec-list)))) | |
1030 (if value | |
1031 (if (eq (car value) 'set) | |
1032 (cdr value) | |
1033 (custom-theme-value (cadr value) theme-spec-list))))) | |
1034 | |
1035 (defun custom-theme-variable-value (variable theme) | |
1036 "Return (list value) indicating value of VARIABLE in THEME. | |
1037 If THEME does not define a value for VARIABLE, return nil. The value | |
1038 definitions per theme are stored in VARIABLE's property `theme-value'. | |
1039 The actual work is done by function `custom-theme-value', which see. | |
1040 See `custom-push-theme' for more information on how these definitions | |
1041 are stored." | |
1042 (custom-theme-value theme (get variable 'theme-value))) | |
1043 | |
1044 (defun custom-theme-reset-internal (symbol to-theme) | |
1045 "Reset SYMBOL to the value defined by TO-THEME. | |
1046 If SYMBOL is not defined in TO-THEME, reset SYMBOL to the standard | |
1047 value. See `custom-theme-variable-value'. The standard value is | |
1048 stored in SYMBOL's property `standard-value'." | |
1049 (let ((value (custom-theme-variable-value symbol to-theme)) | |
1050 was-in-theme) | |
1051 (setq was-in-theme value) | |
1052 (setq value (or value (get symbol 'standard-value))) | |
1053 (when value | |
1054 (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
|
1055 (if (or (get symbol 'force-value) (default-boundp symbol)) |
2544 | 1056 (funcall (or (get symbol 'custom-set) 'set-default) symbol |
1057 (eval (car value))))) | |
1058 value)) | |
1059 | |
1060 (defun custom-theme-reset-variables (theme &rest args) | |
1061 "Reset the value of the variables to values previously defined. | |
1062 Associate this setting with THEME. | |
1063 | |
1064 ARGS is a list of lists of the form | |
1065 | |
1066 (VARIABLE TO-THEME) | |
1067 | |
1068 This means reset VARIABLE to its value in TO-THEME." | |
1069 (custom-check-theme theme) | |
4021 | 1070 (mapcar #'(lambda (arg) |
1071 (apply 'custom-theme-reset-internal arg) | |
1072 (custom-push-theme 'theme-value (car arg) theme 'reset (cadr arg))) | |
2544 | 1073 args)) |
1074 | |
1075 (defun custom-reset-variables (&rest args) | |
1076 "Reset the value of the variables to values previously saved. | |
1077 This is the setting associated the `user' theme. | |
1078 | |
1079 ARGS is a list of lists of the form | |
1080 | |
1081 (VARIABLE TO-THEME) | |
1082 | |
1083 This means reset VARIABLE to its value in TO-THEME." | |
1084 (apply 'custom-theme-reset-variables 'user args)) | |
1085 | |
1086 ;;; The End. | |
1333 | 1087 |
5284
d27c1ee1943b
Make the order of preloaded-file-list more sane.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1088 ;; 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
|
1089 ;; custom-declare-variable-list. |
1333 | 1090 |
428 | 1091 ;; custom.el ends here |