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