* lisp/gnus/nnimap.el (nnimap-open-connection-1): Don't leave an "opening..."
[bpt/emacs.git] / lisp / cus-edit.el
CommitLineData
e8af40ee 1;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
d543e20b 2;;
acaf905b 3;; Copyright (C) 1996-1997, 1999-2012 Free Software Foundation, Inc.
d543e20b
PA
4;;
5;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
c942535f 6;; Maintainer: FSF
d543e20b 7;; Keywords: help, faces
bd78fa1d 8;; Package: emacs
d543e20b 9
f2b98a56
RS
10;; This file is part of GNU Emacs.
11
eb3fa2cf 12;; GNU Emacs is free software: you can redistribute it and/or modify
f2b98a56 13;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
f2b98a56
RS
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
eb3fa2cf 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
f2b98a56 24
d543e20b
PA
25;;; Commentary:
26;;
6d528fc5 27;; This file implements the code to create and edit customize buffers.
c942535f 28;;
d543e20b
PA
29;; See `custom.el'.
30
ab678382
RS
31;; No commands should have names starting with `custom-' because
32;; that interferes with completion. Use `customize-' for commands
33;; that the user will run with M-x, and `Custom-' for interactive commands.
34
9f5d3236 35;; The identity of a customize option is represented by a Lisp symbol.
62bf2fd1 36;; The following values are associated with an option.
9f5d3236
RS
37
38;; 0. The current value.
39
40;; This is the value of the option as seen by "the rest of Emacs".
41
42;; Usually extracted by 'default-value', but can be extracted with
43;; different means if the option symbol has the 'custom-get'
44;; property. Similarly, set-default (or the 'custom-set' property)
45;; can set it.
46
47;; 1. The widget value.
48
62bf2fd1 49;; This is the value shown in the widget in a customize buffer.
9f5d3236
RS
50
51;; 2. The customized value.
52
53;; This is the last value given to the option through customize.
54
55;; It is stored in the 'customized-value' property of the option, in a
62bf2fd1 56;; cons-cell whose car evaluates to the customized value.
9f5d3236
RS
57
58;; 3. The saved value.
59
60;; This is last value saved from customize.
61
62;; It is stored in the 'saved-value' property of the option, in a
62bf2fd1 63;; cons-cell whose car evaluates to the saved value.
9f5d3236
RS
64
65;; 4. The standard value.
66
67;; This is the value given in the 'defcustom' declaration.
68
69;; It is stored in the 'standard-value' property of the option, in a
62bf2fd1 70;; cons-cell whose car evaluates to the standard value.
9f5d3236
RS
71
72;; 5. The "think" value.
62bf2fd1
LT
73
74;; This is what customize thinks the current value should be.
75
76;; This is the customized value, if any such value exists, otherwise
9f5d3236 77;; the saved value, if that exists, and as a last resort the standard
62bf2fd1 78;; value.
9f5d3236
RS
79
80;; The reason for storing values unevaluated: This is so you can have
81;; values that depend on the environment. For example, you can have a
62bf2fd1 82;; variable that has one value when Emacs is running under a window
9f5d3236 83;; system, and another value on a tty. Since the evaluation is only done
62bf2fd1 84;; when the variable is first initialized, this is only relevant for the
9f5d3236
RS
85;; saved (and standard) values, but affect others values for
86;; compatibility.
87
88;; You can see (and modify and save) this unevaluated value by selecting
70482877 89;; "Show Saved Lisp Expression" from the Lisp interface. This will
9f5d3236
RS
90;; give you the unevaluated saved value, if any, otherwise the
91;; unevaluated standard value.
92
93;; The possible states for a customize widget are:
94
95;; 0. unknown
96
97;; The state has not been determined yet.
98
99;; 1. modified
100
101;; The widget value is different from the current value.
102
103;; 2. changed
62bf2fd1
LT
104
105;; The current value is different from the "think" value.
9f5d3236
RS
106
107;; 3. set
108
109;; The "think" value is the customized value.
110
111;; 4. saved
112
113;; The "think" value is the saved value.
114
115;; 5. standard
116
117;; The "think" value is the standard value.
118
119;; 6. rogue
120
62bf2fd1 121;; There is no standard value. This means that the variable was
f63d5a0e
LT
122;; not defined with defcustom, nor handled in cus-start.el. Most
123;; standard interactive Custom commands do not let you create a
124;; Custom buffer containing such variables. However, such Custom
125;; buffers can be created, for instance, by calling
126;; `customize-apropos' with a prefix arg or by calling
f32a1cb5 127;; `customize-option' non-interactively.
9f5d3236
RS
128
129;; 7. hidden
130
131;; There is no widget value.
132
133;; 8. mismatch
134
135;; The widget value is not valid member of the :type specified for the
62bf2fd1 136;; option.
9f5d3236 137
d543e20b
PA
138;;; Code:
139
140(require 'cus-face)
141(require 'wid-edit)
a0247dcf
SM
142
143(defvar custom-versions-load-alist) ; from cus-load
144(defvar recentf-exclude) ; from recentf.el
6d528fc5
PA
145
146(condition-case nil
147 (require 'cus-load)
148 (error nil))
d543e20b 149
9097aeb7
PA
150(condition-case nil
151 (require 'cus-start)
152 (error nil))
153
bd042c03 154(put 'custom-define-hook 'custom-type 'hook)
25ac13b5 155(put 'custom-define-hook 'standard-value '(nil))
bd042c03
PA
156(custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
157
d543e20b
PA
158;;; Customization Groups.
159
160(defgroup emacs nil
161 "Customization of the One True Editor."
162 :link '(custom-manual "(emacs)Top"))
163
164;; Most of these groups are stolen from `finder.el',
165(defgroup editing nil
166 "Basic text editing facilities."
167 :group 'emacs)
168
647f9993
CY
169(defgroup convenience nil
170 "Convenience features for faster editing."
171 :group 'emacs)
172
173(defgroup files nil
174 "Support for editing files."
175 :group 'emacs)
176
177(defgroup wp nil
178 "Support for editing text files."
179 :tag "Text"
180 :group 'emacs)
181
182(defgroup data nil
183 "Support for editing binary data files."
184 :group 'emacs)
185
d543e20b
PA
186(defgroup abbrev nil
187 "Abbreviation handling, typing shortcuts, macros."
188 :tag "Abbreviations"
eba5b4dd 189 :group 'convenience)
d543e20b
PA
190
191(defgroup matching nil
192 "Various sorts of searching and matching."
193 :group 'editing)
194
195(defgroup emulations nil
196 "Emulations of other editors."
6ea2832e 197 :link '(custom-manual "(emacs)Emulation")
d543e20b
PA
198 :group 'editing)
199
200(defgroup mouse nil
201 "Mouse support."
202 :group 'editing)
203
204(defgroup outlines nil
205 "Support for hierarchical outlining."
eba5b4dd 206 :group 'wp)
d543e20b
PA
207
208(defgroup external nil
209 "Interfacing to external utilities."
210 :group 'emacs)
211
26f4b8ab
CY
212(defgroup comm nil
213 "Communications, networking, and remote access to files."
214 :tag "Communication"
eba5b4dd
CY
215 :group 'emacs)
216
d543e20b
PA
217(defgroup processes nil
218 "Process, subshell, compilation, and job control support."
eba5b4dd 219 :group 'external)
d543e20b
PA
220
221(defgroup programming nil
222 "Support for programming in other languages."
223 :group 'emacs)
224
225(defgroup languages nil
cf20dee0 226 "Modes for editing programming languages."
d543e20b
PA
227 :group 'programming)
228
229(defgroup lisp nil
230 "Lisp support, including Emacs Lisp."
3e721a14 231 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
d543e20b
PA
232 :group 'languages
233 :group 'development)
234
235(defgroup c nil
236 "Support for the C language and related languages."
3e721a14 237 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
6ea2832e 238 :link '(custom-manual "(ccmode)")
d543e20b
PA
239 :group 'languages)
240
241(defgroup tools nil
242 "Programming tools."
243 :group 'programming)
244
d543e20b
PA
245(defgroup applications nil
246 "Applications written in Emacs."
247 :group 'emacs)
248
249(defgroup calendar nil
250 "Calendar and time management support."
251 :group 'applications)
252
253(defgroup mail nil
254 "Modes for electronic-mail handling."
255 :group 'applications)
256
257(defgroup news nil
cf20dee0 258 "Reading and posting to newsgroups."
6ea2832e 259 :link '(custom-manual "(gnus)")
d543e20b
PA
260 :group 'applications)
261
262(defgroup games nil
263 "Games, jokes and amusements."
264 :group 'applications)
265
266(defgroup development nil
267 "Support for further development of Emacs."
268 :group 'emacs)
269
270(defgroup docs nil
271 "Support for Emacs documentation."
272 :group 'development)
273
274(defgroup extensions nil
275 "Emacs Lisp language extensions."
276 :group 'development)
277
278(defgroup internal nil
279 "Code for Emacs internals, build process, defaults."
280 :group 'development)
281
282(defgroup maint nil
283 "Maintenance aids for the Emacs development group."
284 :tag "Maintenance"
285 :group 'development)
286
287(defgroup environment nil
288 "Fitting Emacs with its environment."
289 :group 'emacs)
290
d543e20b 291(defgroup hardware nil
ff90f4b0 292 "Support for interfacing with miscellaneous hardware."
d543e20b
PA
293 :group 'environment)
294
295(defgroup terminals nil
296 "Support for terminal types."
297 :group 'environment)
298
299(defgroup unix nil
cf20dee0 300 "Interfaces, assistants, and emulators for UNIX features."
d543e20b
PA
301 :group 'environment)
302
d543e20b
PA
303(defgroup i18n nil
304 "Internationalization and alternate character-set support."
6ea2832e 305 :link '(custom-manual "(emacs)International")
d543e20b
PA
306 :group 'environment
307 :group 'editing)
308
86bd10bc
PA
309(defgroup x nil
310 "The X Window system."
311 :group 'environment)
312
d543e20b
PA
313(defgroup frames nil
314 "Support for Emacs frames and window systems."
315 :group 'environment)
316
d543e20b
PA
317(defgroup tex nil
318 "Code related to the TeX formatter."
3e721a14 319 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
d543e20b
PA
320 :group 'wp)
321
322(defgroup faces nil
323 "Support for multiple fonts."
324 :group 'emacs)
325
d543e20b
PA
326(defgroup help nil
327 "Support for on-line help systems."
328 :group 'emacs)
329
d3d4df42
DL
330(defgroup multimedia nil
331 "Non-textual support, specifically images and sound."
332 :group 'emacs)
333
d543e20b
PA
334(defgroup local nil
335 "Code local to your site."
336 :group 'emacs)
337
338(defgroup customize '((widgets custom-group))
339 "Customization of the Customization support."
d543e20b 340 :prefix "custom-"
bd042c03
PA
341 :group 'help)
342
343(defgroup custom-faces nil
344 "Faces used by customize."
345 :group 'customize
d543e20b
PA
346 :group 'faces)
347
da5ec617
PA
348(defgroup custom-browse nil
349 "Control customize browser."
350 :prefix "custom-"
351 :group 'customize)
352
6aaedd12 353(defgroup custom-buffer nil
da5ec617 354 "Control customize buffers."
6aaedd12
PA
355 :prefix "custom-"
356 :group 'customize)
357
358(defgroup custom-menu nil
da5ec617 359 "Control customize menus."
6aaedd12
PA
360 :prefix "custom-"
361 :group 'customize)
362
bd042c03
PA
363(defgroup alloc nil
364 "Storage allocation and gc for GNU Emacs Lisp interpreter."
365 :tag "Storage Allocation"
366 :group 'internal)
367
368(defgroup undo nil
369 "Undoing changes in buffers."
6ea2832e 370 :link '(custom-manual "(emacs)Undo")
bd042c03
PA
371 :group 'editing)
372
0518917a 373(defgroup mode-line nil
bd042c03
PA
374 "Content of the modeline."
375 :group 'environment)
376
bd042c03
PA
377(defgroup editing-basics nil
378 "Most basic editing facilities."
379 :group 'editing)
380
381(defgroup display nil
382 "How characters are displayed in buffers."
383 :group 'environment)
384
385(defgroup execute nil
386 "Executing external commands."
387 :group 'processes)
388
389(defgroup installation nil
390 "The Emacs installation."
391 :group 'environment)
392
393(defgroup dired nil
394 "Directory editing."
395 :group 'environment)
396
397(defgroup limits nil
398 "Internal Emacs limits."
399 :group 'internal)
400
401(defgroup debug nil
402 "Debugging Emacs itself."
403 :group 'development)
404
bd042c03
PA
405(defgroup keyboard nil
406 "Input from the keyboard."
407 :group 'environment)
408
409(defgroup mouse nil
410 "Input from the mouse."
411 :group 'environment)
412
413(defgroup menu nil
414 "Input from the menus."
415 :group 'environment)
416
153bd017
JD
417(defgroup dnd nil
418 "Handling data from drag and drop."
419 :group 'environment)
420
bd042c03 421(defgroup auto-save nil
040ee34f 422 "Preventing accidental loss of data."
482e54f3 423 :group 'files)
bd042c03
PA
424
425(defgroup processes-basics nil
426 "Basic stuff dealing with processes."
427 :group 'processes)
428
25ac13b5
PA
429(defgroup mule nil
430 "MULE Emacs internationalization."
70bc91bc 431 :group 'i18n)
25ac13b5 432
bd042c03
PA
433(defgroup windows nil
434 "Windows within a frame."
6ea2832e 435 :link '(custom-manual "(emacs)Windows")
86bd10bc 436 :group 'environment)
bd042c03 437
f3093f77
CY
438;;; Custom mode keymaps
439
440(defvar custom-mode-map
f3093f77
CY
441 (let ((map (make-keymap)))
442 (set-keymap-parent map widget-keymap)
443 (define-key map [remap self-insert-command] 'Custom-no-edit)
444 (define-key map "\^m" 'Custom-newline)
ce3cefcc
CY
445 (define-key map " " 'scroll-up-command)
446 (define-key map "\177" 'scroll-down-command)
f3093f77
CY
447 (define-key map "\C-c\C-c" 'Custom-set)
448 (define-key map "\C-x\C-s" 'Custom-save)
449 (define-key map "q" 'Custom-buffer-done)
450 (define-key map "u" 'Custom-goto-parent)
451 (define-key map "n" 'widget-forward)
452 (define-key map "p" 'widget-backward)
453 map)
6aec3b9d 454 "Keymap for `Custom-mode'.")
f3093f77
CY
455
456(defvar custom-mode-link-map
457 (let ((map (make-keymap)))
458 (set-keymap-parent map custom-mode-map)
459 (define-key map [down-mouse-2] nil)
460 (define-key map [down-mouse-1] 'mouse-drag-region)
461 (define-key map [mouse-2] 'widget-move-and-invoke)
462 map)
6aec3b9d 463 "Local keymap for links in `Custom-mode'.")
f3093f77 464
34cf517c
MR
465(defvar custom-field-keymap
466 (let ((map (copy-keymap widget-field-keymap)))
467 (define-key map "\C-c\C-c" 'Custom-set)
468 (define-key map "\C-x\C-s" 'Custom-save)
469 map)
470 "Keymap used inside editable fields in customization buffers.")
471
472(widget-put (get 'editable-field 'widget-type) :keymap custom-field-keymap)
f3093f77 473
d543e20b
PA
474;;; Utilities.
475
d543e20b
PA
476(defun custom-split-regexp-maybe (regexp)
477 "If REGEXP is a string, split it to a list at `\\|'.
12bafdaa 478You can get the original back from the result with:
d543e20b
PA
479 (mapconcat 'identity result \"\\|\")
480
481IF REGEXP is not a string, return it unchanged."
482 (if (stringp regexp)
12bafdaa 483 (split-string regexp "\\\\|")
d543e20b
PA
484 regexp))
485
bd042c03 486(defun custom-variable-prompt ()
3a495e15 487 "Prompt for a custom variable, defaulting to the variable at point.
bd042c03 488Return a list suitable for use in `interactive'."
3e721a14
JL
489 (let* ((v (variable-at-point))
490 (default (and (symbolp v) (custom-variable-p v) (symbol-name v)))
491 (enable-recursive-minibuffers t)
492 val)
493 (setq val (completing-read
0a57ffed
RS
494 (if default (format "Customize variable (default %s): " default)
495 "Customize variable: ")
3e721a14 496 obarray 'custom-variable-p t nil nil default))
bd042c03 497 (list (if (equal val "")
5b5cdd97
RS
498 (if (symbolp v) v nil)
499 (intern val)))))
bd042c03 500
6d528fc5
PA
501(defun custom-menu-filter (menu widget)
502 "Convert MENU to the form used by `widget-choose'.
503MENU should be in the same format as `custom-variable-menu'.
504WIDGET is the widget to apply the filter entries of MENU on."
505 (let ((result nil)
506 current name action filter)
d3d4df42 507 (while menu
6d528fc5
PA
508 (setq current (car menu)
509 name (nth 0 current)
510 action (nth 1 current)
511 filter (nth 2 current)
512 menu (cdr menu))
513 (if (or (null filter) (funcall filter widget))
514 (push (cons name action) result)
515 (push name result)))
516 (nreverse result)))
517
bd042c03
PA
518;;; Unlispify.
519
d543e20b 520(defvar custom-prefix-list nil
2365594b 521 "List of prefixes that should be ignored by `custom-unlispify'.")
d543e20b
PA
522
523(defcustom custom-unlispify-menu-entries t
10cb6e7b 524 "Display menu entries as words instead of symbols if non-nil."
6aaedd12 525 :group 'custom-menu
d543e20b
PA
526 :type 'boolean)
527
cda987f4
RS
528(defcustom custom-unlispify-remove-prefixes nil
529 "Non-nil means remove group prefixes from option names in buffer."
530 :group 'custom-menu
42b4edc5 531 :group 'custom-buffer
cda987f4
RS
532 :type 'boolean)
533
d543e20b 534(defun custom-unlispify-menu-entry (symbol &optional no-suffix)
2365594b 535 "Convert SYMBOL into a menu entry."
d543e20b
PA
536 (cond ((not custom-unlispify-menu-entries)
537 (symbol-name symbol))
538 ((get symbol 'custom-tag)
539 (if no-suffix
540 (get symbol 'custom-tag)
541 (concat (get symbol 'custom-tag) "...")))
542 (t
d9f67134 543 (with-current-buffer (get-buffer-create " *Custom-Work*")
d543e20b
PA
544 (erase-buffer)
545 (princ symbol (current-buffer))
546 (goto-char (point-min))
cda987f4
RS
547 (if custom-unlispify-remove-prefixes
548 (let ((prefixes custom-prefix-list)
549 prefix)
550 (while prefixes
551 (setq prefix (car prefixes))
552 (if (search-forward prefix (+ (point) (length prefix)) t)
d3d4df42 553 (progn
cda987f4
RS
554 (setq prefixes nil)
555 (delete-region (point-min) (point)))
556 (setq prefixes (cdr prefixes))))))
d543e20b
PA
557 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
558 (capitalize-region (point-min) (point-max))
d3d4df42 559 (unless no-suffix
d543e20b
PA
560 (goto-char (point-max))
561 (insert "..."))
562 (buffer-string)))))
563
564(defcustom custom-unlispify-tag-names t
10cb6e7b 565 "Display tag names as words instead of symbols if non-nil."
6aaedd12 566 :group 'custom-buffer
d543e20b
PA
567 :type 'boolean)
568
569(defun custom-unlispify-tag-name (symbol)
2365594b 570 "Convert SYMBOL into a menu entry."
d543e20b
PA
571 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
572 (custom-unlispify-menu-entry symbol t)))
573
574(defun custom-prefix-add (symbol prefixes)
2365594b 575 "Add SYMBOL to list of ignored PREFIXES."
d543e20b
PA
576 (cons (or (get symbol 'custom-prefix)
577 (concat (symbol-name symbol) "-"))
578 prefixes))
579
bd042c03
PA
580;;; Guess.
581
582(defcustom custom-guess-name-alist
583 '(("-p\\'" boolean)
11f0cdf8 584 ("-flag\\'" boolean)
bd042c03
PA
585 ("-hook\\'" hook)
586 ("-face\\'" face)
587 ("-file\\'" file)
588 ("-function\\'" function)
589 ("-functions\\'" (repeat function))
590 ("-list\\'" (repeat sexp))
5bedb26c 591 ("-alist\\'" (alist :key-type sexp :value-type sexp)))
bd042c03
PA
592 "Alist of (MATCH TYPE).
593
d3d4df42 594MATCH should be a regexp matching the name of a symbol, and TYPE should
bd042c03
PA
595be a widget suitable for editing the value of that symbol. The TYPE
596of the first entry where MATCH matches the name of the symbol will be
d3d4df42 597used.
bd042c03
PA
598
599This is used for guessing the type of variables not declared with
600customize."
601 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
3ee07367 602 :group 'custom-buffer)
d543e20b 603
bd042c03
PA
604(defcustom custom-guess-doc-alist
605 '(("\\`\\*?Non-nil " boolean))
606 "Alist of (MATCH TYPE).
d543e20b 607
bd042c03
PA
608MATCH should be a regexp matching a documentation string, and TYPE
609should be a widget suitable for editing the value of a variable with
610that documentation string. The TYPE of the first entry where MATCH
611matches the name of the symbol will be used.
d543e20b 612
bd042c03
PA
613This is used for guessing the type of variables not declared with
614customize."
615 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
3ee07367 616 :group 'custom-buffer)
d543e20b 617
bd042c03
PA
618(defun custom-guess-type (symbol)
619 "Guess a widget suitable for editing the value of SYMBOL.
d3d4df42 620This is done by matching SYMBOL with `custom-guess-name-alist' and
bd042c03
PA
621if that fails, the doc string with `custom-guess-doc-alist'."
622 (let ((name (symbol-name symbol))
623 (names custom-guess-name-alist)
624 current found)
625 (while names
626 (setq current (car names)
627 names (cdr names))
628 (when (string-match (nth 0 current) name)
629 (setq found (nth 1 current)
630 names nil)))
631 (unless found
632 (let ((doc (documentation-property symbol 'variable-documentation))
633 (docs custom-guess-doc-alist))
d3d4df42 634 (when doc
bd042c03
PA
635 (while docs
636 (setq current (car docs)
637 docs (cdr docs))
638 (when (string-match (nth 0 current) doc)
639 (setq found (nth 1 current)
640 docs nil))))))
641 found))
d543e20b 642
25ac13b5
PA
643;;; Sorting.
644
ba5b643e 645;;;###autoload
da5ec617 646(defcustom custom-browse-sort-alphabetically nil
ba5b643e 647 "If non-nil, sort customization group alphabetically in `custom-browse'."
da5ec617
PA
648 :type 'boolean
649 :group 'custom-browse)
650
651(defcustom custom-browse-order-groups nil
652 "If non-nil, order group members within each customization group.
653If `first', order groups before non-groups.
654If `last', order groups after non-groups."
655 :type '(choice (const first)
656 (const last)
657 (const :tag "none" nil))
658 :group 'custom-browse)
659
c953515e
PA
660(defcustom custom-browse-only-groups nil
661 "If non-nil, show group members only within each customization group."
662 :type 'boolean
663 :group 'custom-browse)
664
ba5b643e 665;;;###autoload
647f9993
CY
666(defcustom custom-buffer-sort-alphabetically t
667 "Whether to sort customization groups alphabetically in Custom buffer."
944c91b6 668 :type 'boolean
1625d379
CY
669 :group 'custom-buffer
670 :version "24.1")
25ac13b5 671
da5ec617
PA
672(defcustom custom-buffer-order-groups 'last
673 "If non-nil, order group members within each customization group.
674If `first', order groups before non-groups.
675If `last', order groups after non-groups."
676 :type '(choice (const first)
677 (const last)
678 (const :tag "none" nil))
6aaedd12 679 :group 'custom-buffer)
25ac13b5 680
ba5b643e 681;;;###autoload
944c91b6 682(defcustom custom-menu-sort-alphabetically nil
ba5b643e 683 "If non-nil, sort each customization group alphabetically in menus."
944c91b6 684 :type 'boolean
6aaedd12 685 :group 'custom-menu)
25ac13b5 686
da5ec617
PA
687(defcustom custom-menu-order-groups 'first
688 "If non-nil, order group members within each customization group.
689If `first', order groups before non-groups.
690If `last', order groups after non-groups."
691 :type '(choice (const first)
692 (const last)
693 (const :tag "none" nil))
6aaedd12
PA
694 :group 'custom-menu)
695
da5ec617
PA
696(defun custom-sort-items (items sort-alphabetically order-groups)
697 "Return a sorted copy of ITEMS.
698ITEMS should be a `custom-group' property.
699If SORT-ALPHABETICALLY non-nil, sort alphabetically.
700If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
701groups after non-groups, if nil do not order groups at all."
702 (sort (copy-sequence items)
703 (lambda (a b)
704 (let ((typea (nth 1 a)) (typeb (nth 1 b))
359476e0 705 (namea (nth 0 a)) (nameb (nth 0 b)))
da5ec617
PA
706 (cond ((not order-groups)
707 ;; Since we don't care about A and B order, maybe sort.
708 (when sort-alphabetically
709 (string-lessp namea nameb)))
710 ((eq typea 'custom-group)
711 ;; If B is also a group, maybe sort. Otherwise, order A and B.
712 (if (eq typeb 'custom-group)
713 (when sort-alphabetically
714 (string-lessp namea nameb))
715 (eq order-groups 'first)))
716 ((eq typeb 'custom-group)
717 ;; Since A cannot be a group, order A and B.
718 (eq order-groups 'last))
719 (sort-alphabetically
720 ;; Since A and B cannot be groups, sort.
721 (string-lessp namea nameb)))))))
25ac13b5 722
d543e20b
PA
723;;; Custom Mode Commands.
724
9db1942d 725;; This variable is used by `custom-tool-bar-map', or directly by
f6542587 726;; `custom-buffer-create-internal' if `custom-buffer-verbose-help' is non-nil.
9db1942d
CY
727
728(defvar custom-commands
cf20dee0
CY
729 '((" Apply " Custom-set t
730 "Apply settings (for the current session only)"
f904c0f9
JD
731 "index"
732 "Apply")
cf20dee0 733 (" Apply and Save " Custom-save
9db1942d 734 (or custom-file user-init-file)
cf20dee0 735 "Apply settings and save for future sessions."
f904c0f9
JD
736 "save"
737 "Save")
cf20dee0
CY
738 (" Undo Edits " Custom-reset-current t
739 "Restore customization buffer to reflect existing settings."
f904c0f9
JD
740 "refresh"
741 "Undo")
cf20dee0
CY
742 (" Reset Customizations " Custom-reset-saved t
743 "Undo any settings applied only for the current session."
f904c0f9
JD
744 "undo"
745 "Reset")
cf20dee0 746 (" Erase Customizations " Custom-reset-standard
9db1942d 747 (or custom-file user-init-file)
cf20dee0 748 "Un-customize settings in this and future sessions."
f904c0f9
JD
749 "delete"
750 "Uncustomize")
587faadd 751 (" Help for Customize " Custom-help t
9db1942d 752 "Get help for using Customize."
f904c0f9
JD
753 "help"
754 "Help")
587faadd 755 (" Exit " Custom-buffer-done t "Exit Customize." "exit" "Exit")))
9db1942d
CY
756
757(defun Custom-help ()
758 "Read the node on Easy Customization in the Emacs manual."
d543e20b 759 (interactive)
9db1942d 760 (info "(emacs)Easy Customization"))
d543e20b 761
d3d4df42 762(defvar custom-reset-menu
cf20dee0
CY
763 '(("Undo Edits in Customization Buffer" . Custom-reset-current)
764 ("Revert This Session's Customizations" . Custom-reset-saved)
765 ("Erase Customizations" . Custom-reset-standard))
d543e20b
PA
766 "Alist of actions for the `Reset' button.
767The key is a string containing the name of the action, the value is a
2365594b 768Lisp function taking the widget as an element which will be called
d543e20b
PA
769when the action is chosen.")
770
9db1942d
CY
771(defvar custom-options nil
772 "Customization widgets in the current buffer.")
773
774(defun custom-command-apply (fun query &optional strong-query)
775 "Call function FUN on all widgets in `custom-options'.
776If there is more than one widget, ask user for confirmation using
777the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
778and `yes-or-no-p' otherwise."
779 (if (or (and (= 1 (length custom-options))
780 (memq (widget-type (car custom-options))
781 '(custom-variable custom-face)))
782 (funcall (if strong-query 'yes-or-no-p 'y-or-n-p) query))
783 (progn (mapc fun custom-options) t)
784 (message "Aborted")
785 nil))
786
06b60517 787(defun Custom-set (&rest _ignore)
9db1942d
CY
788 "Set the current value of all edited settings in the buffer."
789 (interactive)
790 (custom-command-apply
791 (lambda (child)
792 (when (eq (widget-get child :custom-state) 'modified)
793 (widget-apply child :custom-set)))
794 "Set all values according to this buffer? "))
795
06b60517 796(defun Custom-save (&rest _ignore)
9db1942d 797 "Set all edited settings, then save all settings that have been set.
5ae87ed4
MR
798If a setting was edited and set before, this saves it. If a
799setting was merely edited before, this sets it then saves it."
9db1942d 800 (interactive)
5ae87ed4
MR
801 (when (custom-command-apply
802 (lambda (child)
803 (when (memq (widget-get child :custom-state)
804 '(modified set changed rogue))
805 (widget-apply child :custom-mark-to-save)))
806 "Save all settings in this buffer? " t)
807 ;; Save changes to buffer and redraw.
808 (custom-save-all)
809 (dolist (child custom-options)
810 (widget-apply child :custom-state-set-and-redraw))))
9db1942d 811
06b60517 812(defun custom-reset (_widget &optional event)
d543e20b
PA
813 "Select item from reset menu."
814 (let* ((completion-ignore-case t)
eaa99205 815 (answer (widget-choose "Reset settings"
d543e20b
PA
816 custom-reset-menu
817 event)))
818 (if answer
819 (funcall answer))))
820
06b60517 821(defun Custom-reset-current (&rest _ignore)
67177975 822 "Reset all edited settings in the buffer to show their current values."
d543e20b 823 (interactive)
9db1942d
CY
824 (custom-command-apply
825 (lambda (widget)
826 (if (memq (widget-get widget :custom-state) '(modified changed))
827 (widget-apply widget :custom-reset-current)))
828 "Reset all settings' buffer text to show current values? "))
d543e20b 829
06b60517 830(defun Custom-reset-saved (&rest _ignore)
67177975
RS
831 "Reset all edited or set settings in the buffer to their saved value.
832This also shows the saved values in the buffer."
d543e20b 833 (interactive)
9db1942d
CY
834 (custom-command-apply
835 (lambda (widget)
836 (if (memq (widget-get widget :custom-state) '(modified set changed rogue))
837 (widget-apply widget :custom-reset-saved)))
838 "Reset all settings (current values and buffer text) to saved values? "))
d543e20b 839
5ae87ed4
MR
840;; The next two variables are bound to '(t) by `Custom-reset-standard'
841;; and `custom-group-reset-standard'. If these variables are nil, both
842;; `custom-variable-reset-standard' and `custom-face-reset-standard'
843;; save, reset and redraw the handled widget immediately. Otherwise,
844;; they add the widget to the corresponding list and leave it to
845;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
846(defvar custom-reset-standard-variables-list nil)
847(defvar custom-reset-standard-faces-list nil)
848
849;; The next function was excerpted from `custom-variable-reset-standard'
850;; and `custom-face-reset-standard' and is used to avoid calling
851;; `custom-save-all' repeatedly (and thus saving settings to file one by
852;; one) when erasing all customizations.
853(defun custom-reset-standard-save-and-update ()
854 "Save settings and redraw after erasing customizations."
855 (when (or (and custom-reset-standard-variables-list
856 (not (eq custom-reset-standard-variables-list '(t))))
857 (and custom-reset-standard-faces-list
858 (not (eq custom-reset-standard-faces-list '(t)))))
859 ;; Save settings to file.
860 (custom-save-all)
861 ;; Set state of and redraw variables.
862 (dolist (widget custom-reset-standard-variables-list)
863 (unless (eq widget t)
864 (widget-put widget :custom-state 'unknown)
865 (custom-redraw widget)))
866 ;; Set state of and redraw faces.
867 (dolist (widget custom-reset-standard-faces-list)
868 (unless (eq widget t)
869 (let* ((symbol (widget-value widget))
870 (child (car (widget-get widget :children)))
5ae87ed4
MR
871 (comment-widget (widget-get widget :comment-widget)))
872 (put symbol 'face-comment nil)
873 (widget-value-set child
874 (custom-pre-filter-face-spec
875 (list (list t (custom-face-attributes-get
876 symbol nil)))))
877 ;; This call manages the comment visibility
878 (widget-value-set comment-widget "")
879 (custom-face-state-set widget)
880 (custom-redraw-magic widget))))))
881
06b60517 882(defun Custom-reset-standard (&rest _ignore)
5ae87ed4 883 "Erase all customizations (either current or saved) in current buffer.
50137744
RS
884The immediate result is to restore them to their standard values.
885This operation eliminates any saved values for the group members,
19d63704 886making them as if they had never been customized at all."
d543e20b 887 (interactive)
5ae87ed4
MR
888 ;; Bind these temporarily.
889 (let ((custom-reset-standard-variables-list '(t))
890 (custom-reset-standard-faces-list '(t)))
891 (custom-command-apply
892 (lambda (widget)
893 (and (or (null (widget-get widget :custom-standard-value))
894 (widget-apply widget :custom-standard-value))
895 (memq (widget-get widget :custom-state)
896 '(modified set changed saved rogue))
897 (widget-apply widget :custom-mark-to-reset-standard)))
cf20dee0
CY
898 "The settings will revert to their default values, in this
899and future sessions. Really erase customizations? " t)
5ae87ed4 900 (custom-reset-standard-save-and-update)))
d543e20b
PA
901
902;;; The Customize Commands
903
d3d4df42 904(defun custom-prompt-variable (prompt-var prompt-val &optional comment)
6d528fc5
PA
905 "Prompt for a variable and a value and return them as a list.
906PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
907prompt for the value. The %s escape in PROMPT-VAL is replaced with
908the name of the variable.
909
910If the variable has a `variable-interactive' property, that is used as if
911it were the arg to `interactive' (which see) to interactively read the value.
912
913If the variable has a `custom-type' property, it must be a widget and the
d3d4df42 914`:prompt-value' property of that widget will be used for reading the value.
06b60517 915If the variable also has a `custom-get' property, that is used for finding
da0275f8 916the current value of the variable, otherwise `symbol-value' is used.
d3d4df42 917
10cb6e7b 918If optional COMMENT argument is non-nil, also prompt for a comment and return
d3d4df42 919it as the third element in the list."
6d528fc5 920 (let* ((var (read-variable prompt-var))
d3d4df42
DL
921 (minibuffer-help-form '(describe-variable var))
922 (val
6d528fc5
PA
923 (let ((prop (get var 'variable-interactive))
924 (type (get var 'custom-type))
925 (prompt (format prompt-val var)))
926 (unless (listp type)
927 (setq type (list type)))
928 (cond (prop
929 ;; Use VAR's `variable-interactive' property
930 ;; as an interactive spec for prompting.
9db1942d
CY
931 (call-interactively `(lambda (arg)
932 (interactive ,prop)
933 arg)))
6d528fc5
PA
934 (type
935 (widget-prompt-value type
936 prompt
937 (if (boundp var)
06b60517
JB
938 (funcall
939 (or (get var 'custom-get) 'symbol-value)
da0275f8 940 var))
6d528fc5
PA
941 (not (boundp var))))
942 (t
d3d4df42
DL
943 (eval-minibuffer prompt))))))
944 (if comment
945 (list var val
946 (read-string "Comment: " (get var 'variable-comment)))
947 (list var val))))
6d528fc5
PA
948
949;;;###autoload
7ec8d2c6 950(defun customize-set-value (variable value &optional comment)
4f9b9060 951 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
6d528fc5
PA
952
953If VARIABLE has a `variable-interactive' property, that is used as if
954it were the arg to `interactive' (which see) to interactively read the value.
955
956If VARIABLE has a `custom-type' property, it must be a widget and the
d3d4df42
DL
957`:prompt-value' property of that widget will be used for reading the value.
958
959If given a prefix (or a COMMENT argument), also prompt for a comment."
6d528fc5 960 (interactive (custom-prompt-variable "Set variable: "
d3d4df42
DL
961 "Set %s to value: "
962 current-prefix-arg))
ee1f522d 963
d3d4df42 964 (cond ((string= comment "")
7ec8d2c6 965 (put variable 'variable-comment nil))
d3d4df42 966 (comment
7ec8d2c6
PJ
967 (put variable 'variable-comment comment)))
968 (set variable value))
6d528fc5
PA
969
970;;;###autoload
2365594b 971(defun customize-set-variable (variable value &optional comment)
4f9b9060
PA
972 "Set the default for VARIABLE to VALUE, and return VALUE.
973VALUE is a Lisp object.
6d528fc5
PA
974
975If VARIABLE has a `custom-set' property, that is used for setting
976VARIABLE, otherwise `set-default' is used.
977
6d528fc5
PA
978If VARIABLE has a `variable-interactive' property, that is used as if
979it were the arg to `interactive' (which see) to interactively read the value.
980
981If VARIABLE has a `custom-type' property, it must be a widget and the
d3d4df42
DL
982`:prompt-value' property of that widget will be used for reading the value.
983
984If given a prefix (or a COMMENT argument), also prompt for a comment."
6d528fc5 985 (interactive (custom-prompt-variable "Set variable: "
d3d4df42
DL
986 "Set customized value for %s to: "
987 current-prefix-arg))
4f9b9060 988 (custom-load-symbol variable)
8ed50a66 989 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
2365594b
DL
990 (funcall (or (get variable 'custom-set) 'set-default) variable value)
991 (put variable 'customized-value (list (custom-quote value)))
d3d4df42 992 (cond ((string= comment "")
2365594b
DL
993 (put variable 'variable-comment nil)
994 (put variable 'customized-variable-comment nil))
d3d4df42 995 (comment
2365594b 996 (put variable 'variable-comment comment)
4f9b9060
PA
997 (put variable 'customized-variable-comment comment)))
998 value)
6d528fc5 999
4ee1cf9f 1000;;;###autoload
7ec8d2c6 1001(defun customize-save-variable (variable value &optional comment)
4ee1cf9f 1002 "Set the default for VARIABLE to VALUE, and save it for future sessions.
4f9b9060
PA
1003Return VALUE.
1004
4ee1cf9f
PA
1005If VARIABLE has a `custom-set' property, that is used for setting
1006VARIABLE, otherwise `set-default' is used.
1007
4ee1cf9f
PA
1008If VARIABLE has a `variable-interactive' property, that is used as if
1009it were the arg to `interactive' (which see) to interactively read the value.
1010
1011If VARIABLE has a `custom-type' property, it must be a widget and the
d3d4df42
DL
1012`:prompt-value' property of that widget will be used for reading the value.
1013
1014If given a prefix (or a COMMENT argument), also prompt for a comment."
901cd78b 1015 (interactive (custom-prompt-variable "Set and save variable: "
d3d4df42
DL
1016 "Set and save value for %s as: "
1017 current-prefix-arg))
7ec8d2c6
PJ
1018 (funcall (or (get variable 'custom-set) 'set-default) variable value)
1019 (put variable 'saved-value (list (custom-quote value)))
c5d290fb 1020 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
d3d4df42 1021 (cond ((string= comment "")
7ec8d2c6
PJ
1022 (put variable 'variable-comment nil)
1023 (put variable 'saved-variable-comment nil))
d3d4df42 1024 (comment
7ec8d2c6
PJ
1025 (put variable 'variable-comment comment)
1026 (put variable 'saved-variable-comment comment)))
fe4acc60
CY
1027 (put variable 'customized-value nil)
1028 (put variable 'customized-variable-comment nil)
eab5dc07
LMI
1029 (if (custom-file t)
1030 (custom-save-all)
1031 (message "Setting `%s' temporarily since \"emacs -q\" would overwrite customizations"
1032 variable)
1033 (set variable value))
4f9b9060 1034 value)
4ee1cf9f 1035
658d8eb8
CY
1036;; Some parts of Emacs might prompt the user to save customizations,
1037;; during startup before customizations are loaded. This function
1038;; handles this corner case by avoiding calling `custom-save-variable'
1039;; too early, which could wipe out existing customizations.
1040
1041;;;###autoload
1042(defun customize-push-and-save (list-var elts)
1043 "Add ELTS to LIST-VAR and save for future sessions, safely.
1044ELTS should be a list. This function adds each entry to the
1045value of LIST-VAR using `add-to-list'.
1046
1047If Emacs is initialized, call `customize-save-variable' to save
1048the resulting list value now. Otherwise, add an entry to
1049`after-init-hook' to save it after initialization."
1050 (dolist (entry elts)
1051 (add-to-list list-var entry))
1052 (if after-init-time
1053 (let ((coding-system-for-read nil))
1054 (customize-save-variable list-var (eval list-var)))
1055 (add-hook 'after-init-hook
1056 `(lambda ()
1057 (customize-push-and-save ',list-var ',elts)))))
1058
d543e20b 1059;;;###autoload
5dd0cad0
RS
1060(defun customize ()
1061 "Select a customization buffer which you can use to set user options.
1062User options are structured into \"groups\".
1063Initially the top-level group `Emacs' and its immediate subgroups
1064are shown; the contents of those subgroups are initially hidden."
1065 (interactive)
dc2e979f 1066 (customize-group 'emacs))
5dd0cad0 1067
87434e7a
SM
1068;;;###autoload
1069(defun customize-mode (mode)
1070 "Customize options related to the current major mode.
1071If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1072then prompt for the MODE to customize."
1073 (interactive
1074 (list
1075 (let ((completion-regexp-list '("-mode\\'"))
1076 (group (custom-group-of-mode major-mode)))
1077 (if (and group (not current-prefix-arg))
1078 major-mode
1079 (intern
1080 (completing-read (if group
1081 (format "Major mode (default %s): " major-mode)
1082 "Major mode: ")
1083 obarray
1084 'custom-group-of-mode
1085 t nil nil (if group (symbol-name major-mode))))))))
1086 (customize-group (custom-group-of-mode mode)))
1087
a0247dcf
SM
1088(defun customize-read-group ()
1089 (let ((completion-ignore-case t))
1090 (completing-read "Customize group (default emacs): "
1091 obarray
1092 (lambda (symbol)
1093 (or (and (get symbol 'custom-loads)
1094 (not (get symbol 'custom-autoload)))
1095 (get symbol 'custom-group)))
1096 t)))
87434e7a 1097
5dd0cad0 1098;;;###autoload
919a69aa
CY
1099(defun customize-group (&optional group other-window)
1100 "Customize GROUP, which must be a customization group.
1101If OTHER-WINDOW is non-nil, display in another window."
a0247dcf 1102 (interactive (list (customize-read-group)))
5dd0cad0
RS
1103 (when (stringp group)
1104 (if (string-equal "" group)
1105 (setq group 'emacs)
1106 (setq group (intern group))))
241d3080
RS
1107 (let ((name (format "*Customize Group: %s*"
1108 (custom-unlispify-tag-name group))))
72258fe5
CY
1109 (cond
1110 ((null (get-buffer name))
919a69aa
CY
1111 (funcall (if other-window
1112 'custom-buffer-create-other-window
1113 'custom-buffer-create)
1114 (list (list group 'custom-group))
1115 name
1116 (concat " for group "
72258fe5
CY
1117 (custom-unlispify-tag-name group))))
1118 (other-window
1119 (switch-to-buffer-other-window name))
1120 (t
1121 (pop-to-buffer-same-window name)))))
d543e20b 1122
6d528fc5 1123;;;###autoload
9db1942d
CY
1124(defun customize-group-other-window (&optional group)
1125 "Customize GROUP, which must be a customization group, in another window."
a0247dcf 1126 (interactive (list (customize-read-group)))
919a69aa 1127 (customize-group group t))
6d528fc5 1128
9097aeb7
PA
1129;;;###autoload
1130(defalias 'customize-variable 'customize-option)
38d58078 1131
d543e20b 1132;;;###autoload
38d58078 1133(defun customize-option (symbol)
775c916b 1134 "Customize SYMBOL, which must be a user option."
bd042c03 1135 (interactive (custom-variable-prompt))
161c7127
RS
1136 (unless symbol
1137 (error "No variable specified"))
dcb380c0
LT
1138 (let ((basevar (indirect-variable symbol)))
1139 (custom-buffer-create (list (list basevar 'custom-variable))
1140 (format "*Customize Option: %s*"
1141 (custom-unlispify-tag-name basevar)))
1142 (unless (eq symbol basevar)
1143 (message "`%s' is an alias for `%s'" symbol basevar))))
d543e20b 1144
ffec8c5a
MR
1145;;;###autoload
1146(defalias 'customize-variable-other-window 'customize-option-other-window)
1147
1148;;;###autoload
1149(defun customize-option-other-window (symbol)
775c916b 1150 "Customize SYMBOL, which must be a user option.
ffec8c5a
MR
1151Show the buffer in another window, but don't select it."
1152 (interactive (custom-variable-prompt))
161c7127
RS
1153 (unless symbol
1154 (error "No variable specified"))
dcb380c0
LT
1155 (let ((basevar (indirect-variable symbol)))
1156 (custom-buffer-create-other-window
1157 (list (list basevar 'custom-variable))
1158 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar)))
1159 (unless (eq symbol basevar)
1160 (message "`%s' is an alias for `%s'" symbol basevar))))
ffec8c5a 1161
0dcf7d7e 1162(defvar customize-changed-options-previous-release "23.1"
e418be26
KH
1163 "Version for `customize-changed-options' to refer back to by default.")
1164
4e9c705e
BW
1165;; Packages will update this variable, so make it available.
1166;;;###autoload
1167(defvar customize-package-emacs-version-alist nil
7eb944cf
RS
1168 "Alist mapping versions of a package to Emacs versions.
1169We use this for packages that have their own names, but are released
1170as part of Emacs itself.
1171
1172Each elements looks like this:
994019df
BW
1173
1174 (PACKAGE (PVERSION . EVERSION)...)
1175
7eb944cf
RS
1176Here PACKAGE is the name of a package, as a symbol. After
1177PACKAGE come one or more elements, each associating a
1178package version PVERSION with the first Emacs version
1179EVERSION in which it (or a subsequent version of PACKAGE)
1180was first released. Both PVERSION and EVERSION are strings.
1181PVERSION should be a string that this package used in
1182the :package-version keyword for `defcustom', `defgroup',
1183and `defface'.
1184
1185For example, the MH-E package updates this alist as follows:
994019df
BW
1186
1187 (add-to-list 'customize-package-emacs-version-alist
1188 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1189 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1190 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1191 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1192
1193The value of PACKAGE needs to be unique and it needs to match the
1194PACKAGE value appearing in the :package-version keyword. Since
1195the user might see the value in a error message, a good choice is
1196the official name of the package, such as MH-E or Gnus.")
4e9c705e 1197
bba50f8a
RS
1198;;;###autoload
1199(defalias 'customize-changed 'customize-changed-options)
1200
c32de15e 1201;;;###autoload
8c89fb87 1202(defun customize-changed-options (&optional since-version)
bba50f8a 1203 "Customize all settings whose meanings have changed in Emacs itself.
775c916b
CY
1204This includes new user options and faces, and new customization
1205groups, as well as older options and faces whose meanings or
1206default values have changed since the previous major Emacs
1207release.
e418be26 1208
bba50f8a
RS
1209With argument SINCE-VERSION (a string), customize all settings
1210that were added or redefined since that version."
e418be26 1211
2071d184
LT
1212 (interactive
1213 (list
1214 (read-from-minibuffer
1215 (format "Customize options changed, since version (default %s): "
1216 customize-changed-options-previous-release))))
f50dc5d2 1217 (if (equal since-version "")
26c67de8
DL
1218 (setq since-version nil)
1219 (unless (condition-case nil
1220 (numberp (read since-version))
1221 (error nil))
1222 (signal 'wrong-type-argument (list 'numberp since-version))))
e418be26
KH
1223 (unless since-version
1224 (setq since-version customize-changed-options-previous-release))
cba752d0
MR
1225
1226 ;; Load the information for versions since since-version. We use
1227 ;; custom-load-symbol for this.
1228 (put 'custom-versions-load-alist 'custom-loads nil)
1229 (dolist (elt custom-versions-load-alist)
2ee398c4
MR
1230 (if (customize-version-lessp since-version (car elt))
1231 (dolist (load (cdr elt))
1232 (custom-add-load 'custom-versions-load-alist load))))
cba752d0
MR
1233 (custom-load-symbol 'custom-versions-load-alist)
1234 (put 'custom-versions-load-alist 'custom-loads nil)
1235
1236 (let (found)
1237 (mapatoms
1238 (lambda (symbol)
4e9c705e
BW
1239 (let* ((package-version (get symbol 'custom-package-version))
1240 (version
1241 (or (and package-version
1242 (customize-package-emacs-version symbol
1243 package-version))
1244 (get symbol 'custom-version))))
cba752d0
MR
1245 (if version
1246 (when (customize-version-lessp since-version version)
1247 (if (or (get symbol 'custom-group)
1248 (get symbol 'group-documentation))
1249 (push (list symbol 'custom-group) found))
1250 (if (custom-variable-p symbol)
1251 (push (list symbol 'custom-variable) found))
1252 (if (custom-facep symbol)
1253 (push (list symbol 'custom-face) found)))))))
1254 (if found
1255 (custom-buffer-create (custom-sort-items found t 'first)
1256 "*Customize Changed Options*")
1257 (error "No user option defaults have been changed since Emacs %s"
1258 since-version))))
f50dc5d2 1259
4e9c705e 1260(defun customize-package-emacs-version (symbol package-version)
7eb944cf
RS
1261 "Return the Emacs version in which SYMBOL's meaning last changed.
1262PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
4e9c705e 1263`customize-package-emacs-version-alist' to find the version of
7eb944cf 1264Emacs that is associated with version VERSION of PACKAGE."
4e9c705e
BW
1265 (let (package-versions emacs-version)
1266 ;; Use message instead of error since we want user to be able to
1267 ;; see the rest of the symbols even if a package author has
1268 ;; botched things up.
1269 (cond ((not (listp package-version))
1270 (message "Invalid package-version value for %s" symbol))
1271 ((setq package-versions (assq (car package-version)
1272 customize-package-emacs-version-alist))
1273 (setq emacs-version
994019df 1274 (cdr (assoc (cdr package-version) package-versions)))
4e9c705e 1275 (unless emacs-version
994019df
BW
1276 (message "%s version %s not found in %s" symbol
1277 (cdr package-version)
4e9c705e
BW
1278 "customize-package-emacs-version-alist")))
1279 (t
7eb944cf 1280 (message "Package %s version %s lists no corresponding Emacs version"
4e9c705e 1281 (car package-version)
7eb944cf 1282 (cdr package-version))))
4e9c705e
BW
1283 emacs-version))
1284
f50dc5d2 1285(defun customize-version-lessp (version1 version2)
26c67de8
DL
1286 ;; Why are the versions strings, and given that they are, why aren't
1287 ;; they converted to numbers and compared as such here? -- fx
1288
e418be26
KH
1289 ;; In case someone made a mistake and left out the quotes
1290 ;; in the :version value.
1291 (if (numberp version2)
1292 (setq version2 (prin1-to-string version2)))
f50dc5d2 1293 (let (major1 major2 minor1 minor2)
26c67de8
DL
1294 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1295 (setq major1 (read (or (match-string 1 version1)
1296 "0")))
1297 (setq minor1 (read (or (match-string 3 version1)
1298 "0")))
1299 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1300 (setq major2 (read (or (match-string 1 version2)
1301 "0")))
1302 (setq minor2 (read (or (match-string 3 version2)
1303 "0")))
f50dc5d2
KH
1304 (or (< major1 major2)
1305 (and (= major1 major2)
1306 (< minor1 minor2)))))
c942535f 1307
d543e20b 1308;;;###autoload
919a69aa 1309(defun customize-face (&optional face other-window)
3127aa13 1310 "Customize FACE, which should be a face name or nil.
c40f3193
GM
1311If FACE is nil, customize all faces. If FACE is actually a
1312face-alias, customize the face it is aliased to.
d29a536a 1313
919a69aa
CY
1314If OTHER-WINDOW is non-nil, display in another window.
1315
d29a536a 1316Interactively, when point is on text which has a face specified,
3127aa13 1317suggest to customize that face, if it's customizable."
a0247dcf 1318 (interactive (list (read-face-name "Customize face" "all faces" t)))
cdd50dea
RS
1319 (if (member face '(nil ""))
1320 (setq face (face-list)))
1321 (if (and (listp face) (null (cdr face)))
1322 (setq face (car face)))
919a69aa
CY
1323 (let ((display-fun (if other-window
1324 'custom-buffer-create-other-window
1325 'custom-buffer-create)))
1326 (if (listp face)
1327 (funcall display-fun
1328 (custom-sort-items
1329 (mapcar (lambda (s) (list s 'custom-face)) face)
1330 t nil)
1331 "*Customize Faces*")
1332 ;; If FACE is actually an alias, customize the face it is aliased to.
1333 (if (get face 'face-alias)
1334 (setq face (get face 'face-alias)))
1335 (unless (facep face)
1336 (error "Invalid face %S" face))
1337 (funcall display-fun
1338 (list (list face 'custom-face))
1339 (format "*Customize Face: %s*"
1340 (custom-unlispify-tag-name face))))))
d543e20b 1341
bd042c03 1342;;;###autoload
701f49d2 1343(defun customize-face-other-window (&optional face)
3127aa13 1344 "Show customization buffer for face FACE in other window.
c40f3193 1345If FACE is actually a face-alias, customize the face it is aliased to.
d29a536a
GM
1346
1347Interactively, when point is on text which has a face specified,
3127aa13 1348suggest to customize that face, if it's customizable."
a0247dcf 1349 (interactive (list (read-face-name "Customize face" "all faces" t)))
919a69aa 1350 (customize-face face t))
bd042c03 1351
0b97da8f
RS
1352(defalias 'customize-customized 'customize-unsaved)
1353
d543e20b 1354;;;###autoload
0b97da8f 1355(defun customize-unsaved ()
2ae01800 1356 "Customize all options and faces set in this session but not saved."
6d528fc5
PA
1357 (interactive)
1358 (let ((found nil))
1359 (mapatoms (lambda (symbol)
d3d4df42
DL
1360 (and (or (get symbol 'customized-face)
1361 (get symbol 'customized-face-comment))
6d528fc5 1362 (custom-facep symbol)
a1a4fa22 1363 (push (list symbol 'custom-face) found))
d3d4df42
DL
1364 (and (or (get symbol 'customized-value)
1365 (get symbol 'customized-variable-comment))
6d528fc5 1366 (boundp symbol)
a1a4fa22 1367 (push (list symbol 'custom-variable) found))))
da5ec617 1368 (if (not found)
0b97da8f 1369 (error "No user options are set but unsaved")
da5ec617 1370 (custom-buffer-create (custom-sort-items found t nil)
0b97da8f 1371 "*Customize Unsaved*"))))
6d528fc5
PA
1372
1373;;;###autoload
963c2e09 1374(defun customize-rogue ()
c111d7ae 1375 "Customize all user variables modified outside customize."
963c2e09
PA
1376 (interactive)
1377 (let ((found nil))
1378 (mapatoms (lambda (symbol)
1379 (let ((cval (or (get symbol 'customized-value)
1380 (get symbol 'saved-value)
1381 (get symbol 'standard-value))))
1382 (when (and cval ;Declared with defcustom.
1383 (default-boundp symbol) ;Has a value.
3127aa13 1384 (not (equal (eval (car cval))
963c2e09
PA
1385 ;; Which does not match customize.
1386 (default-value symbol))))
1387 (push (list symbol 'custom-variable) found)))))
1388 (if (not found)
1389 (error "No rogue user options")
1390 (custom-buffer-create (custom-sort-items found t nil)
1391 "*Customize Rogue*"))))
1392;;;###autoload
6d528fc5 1393(defun customize-saved ()
2ae01800 1394 "Customize all saved options and faces."
d543e20b
PA
1395 (interactive)
1396 (let ((found nil))
1397 (mapatoms (lambda (symbol)
d3d4df42
DL
1398 (and (or (get symbol 'saved-face)
1399 (get symbol 'saved-face-comment))
d543e20b 1400 (custom-facep symbol)
a1a4fa22 1401 (push (list symbol 'custom-face) found))
d3d4df42
DL
1402 (and (or (get symbol 'saved-value)
1403 (get symbol 'saved-variable-comment))
d543e20b 1404 (boundp symbol)
a1a4fa22 1405 (push (list symbol 'custom-variable) found))))
da5ec617
PA
1406 (if (not found )
1407 (error "No saved user options")
1408 (custom-buffer-create (custom-sort-items found t nil)
1409 "*Customize Saved*"))))
d543e20b 1410
647f9993
CY
1411(declare-function apropos-parse-pattern "apropos" (pattern))
1412
d543e20b 1413;;;###autoload
647f9993 1414(defun customize-apropos (pattern &optional type)
775c916b 1415 "Customize loaded options, faces and groups matching PATTERN.
647f9993
CY
1416PATTERN can be a word, a list of words (separated by spaces),
1417or a regexp (using some regexp special characters). If it is a word,
1418search for matches for that word as a substring. If it is a list of words,
1419search for matches for any two (or more) of those words.
1420
1421If TYPE is `options', include only options.
1422If TYPE is `faces', include only faces.
775c916b
CY
1423If TYPE is `groups', include only groups."
1424 (interactive (list (apropos-read-pattern "symbol") nil))
647f9993 1425 (require 'apropos)
775c916b
CY
1426 (unless (memq type '(nil options faces groups))
1427 (error "Invalid setting type %s" (symbol-name type)))
647f9993 1428 (apropos-parse-pattern pattern)
06b60517 1429 (let (found)
647f9993
CY
1430 (mapatoms
1431 `(lambda (symbol)
1432 (when (string-match apropos-regexp (symbol-name symbol))
775c916b 1433 ,(if (memq type '(nil groups))
647f9993
CY
1434 '(if (get symbol 'custom-group)
1435 (push (list symbol 'custom-group) found)))
775c916b 1436 ,(if (memq type '(nil faces))
647f9993
CY
1437 '(if (custom-facep symbol)
1438 (push (list symbol 'custom-face) found)))
775c916b 1439 ,(if (memq type '(nil options))
647f9993
CY
1440 `(if (and (boundp symbol)
1441 (eq (indirect-variable symbol) symbol)
1442 (or (get symbol 'saved-value)
775c916b 1443 (custom-variable-p symbol)))
647f9993 1444 (push (list symbol 'custom-variable) found))))))
775c916b
CY
1445 (unless found
1446 (error "No customizable %s matching %s" (symbol-name type) pattern))
1447 (custom-buffer-create
1448 (custom-sort-items found t custom-buffer-order-groups)
1449 "*Customize Apropos*")))
a1a4fa22
PA
1450
1451;;;###autoload
775c916b
CY
1452(defun customize-apropos-options (regexp &optional ignored)
1453 "Customize all loaded customizable options matching REGEXP."
1454 (interactive (list (apropos-read-pattern "options")))
1455 (customize-apropos regexp 'options))
a1a4fa22
PA
1456
1457;;;###autoload
1458(defun customize-apropos-faces (regexp)
0322b9c3 1459 "Customize all loaded faces matching REGEXP."
775c916b 1460 (interactive (list (apropos-read-pattern "faces")))
a1a4fa22
PA
1461 (customize-apropos regexp 'faces))
1462
1463;;;###autoload
1464(defun customize-apropos-groups (regexp)
0322b9c3 1465 "Customize all loaded groups matching REGEXP."
775c916b 1466 (interactive (list (apropos-read-pattern "groups")))
a1a4fa22 1467 (customize-apropos regexp 'groups))
d543e20b 1468
6d528fc5
PA
1469;;; Buffer.
1470
944c91b6
PA
1471(defcustom custom-buffer-style 'links
1472 "Control the presentation style for customization buffers.
1473The value should be a symbol, one of:
1474
1475brackets: groups nest within each other with big horizontal brackets.
1476links: groups have links to subgroups."
1477 :type '(radio (const brackets)
1478 (const links))
1479 :group 'custom-buffer)
1480
97733c3d 1481(defcustom custom-buffer-done-kill nil
6cda144f 1482 "Non-nil means exiting a Custom buffer should kill it."
97733c3d 1483 :type 'boolean
bf247b6e 1484 :version "22.1"
d3d4df42
DL
1485 :group 'custom-buffer)
1486
944c91b6
PA
1487(defcustom custom-buffer-indent 3
1488 "Number of spaces to indent nested groups."
1489 :type 'integer
1490 :group 'custom-buffer)
1491
40627755
SM
1492(defun custom-get-fresh-buffer (name)
1493 "Get a fresh new buffer with name NAME.
a153acb7
SM
1494If the buffer already exist, clean it up to be like new.
1495Beware: it's not quite like new. Good enough for custom, but maybe
1496not for everybody."
1497 ;; To be more complete, we should also kill all permanent-local variables,
1498 ;; but it's not needed for custom.
40627755 1499 (let ((buf (get-buffer name)))
fd1c38f4 1500 (when (and buf (buffer-local-value 'buffer-file-name buf))
a153acb7
SM
1501 ;; This will check if the file is not saved.
1502 (kill-buffer buf)
1503 (setq buf nil))
40627755
SM
1504 (if (null buf)
1505 (get-buffer-create name)
1506 (with-current-buffer buf
1507 (kill-all-local-variables)
a153acb7 1508 (run-hooks 'kill-buffer-hook)
f5a9b180
SM
1509 ;; Delete overlays before erasing the buffer so the overlay hooks
1510 ;; don't get run spuriously when we erase the buffer.
40627755
SM
1511 (let ((ols (overlay-lists)))
1512 (dolist (ol (nconc (car ols) (cdr ols)))
1513 (delete-overlay ol)))
f5a9b180 1514 (erase-buffer)
40627755
SM
1515 buf))))
1516
d543e20b 1517;;;###autoload
3aec85bf 1518(defun custom-buffer-create (options &optional name description)
d543e20b 1519 "Create a buffer containing OPTIONS.
86bd10bc 1520Optional NAME is the name of the buffer.
d543e20b
PA
1521OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1522SYMBOL is a customization option, and WIDGET is a widget for editing
1523that option."
72258fe5 1524 (pop-to-buffer-same-window (custom-get-fresh-buffer (or name "*Customization*")))
3aec85bf 1525 (custom-buffer-create-internal options description))
bd042c03 1526
6d528fc5 1527;;;###autoload
3aec85bf 1528(defun custom-buffer-create-other-window (options &optional name description)
5f97a49d
RS
1529 "Create a buffer containing OPTIONS, and display it in another window.
1530The result includes selecting that window.
86bd10bc 1531Optional NAME is the name of the buffer.
bd042c03
PA
1532OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1533SYMBOL is a customization option, and WIDGET is a widget for editing
1534that option."
86bd10bc 1535 (unless name (setq name "*Customization*"))
37ac18a3 1536 (switch-to-buffer-other-window (custom-get-fresh-buffer name))
919a69aa 1537 (custom-buffer-create-internal options description))
9097aeb7 1538
cf20dee0 1539(defcustom custom-reset-button-menu t
9097aeb7
PA
1540 "If non-nil, only show a single reset button in customize buffers.
1541This button will have a menu with all three reset operations."
1542 :type 'boolean
cf20dee0
CY
1543 :group 'custom-buffer
1544 :version "24.2")
bd042c03 1545
c42c5c7c
KS
1546(defcustom custom-buffer-verbose-help t
1547 "If non-nil, include explanatory text in the customization buffer."
1548 :type 'boolean
1549 :group 'custom-buffer)
1550
06b60517 1551(defun Custom-buffer-done (&rest _ignore)
97733c3d 1552 "Exit current Custom buffer according to `custom-buffer-done-kill'."
d3d4df42 1553 (interactive)
97733c3d 1554 (quit-window custom-buffer-done-kill))
d3d4df42 1555
87911bdb
CY
1556(defvar custom-button nil
1557 "Face used for buttons in customization buffers.")
1558
85a5eb0e
CY
1559(defvar custom-button-mouse nil
1560 "Mouse face used for buttons in customization buffers.")
1561
87911bdb
CY
1562(defvar custom-button-pressed nil
1563 "Face used for pressed buttons in customization buffers.")
1564
647f9993
CY
1565(defcustom custom-search-field t
1566 "If non-nil, show a search field in Custom buffers."
1567 :type 'boolean
1568 :version "24.1"
1569 :group 'custom-buffer)
1570
d3d4df42
DL
1571(defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1572 '(("unspecified" . unspecified))))
1573 "If non-nil, indicate active buttons in a `raised-button' style.
1574Otherwise use brackets."
1575 :type 'boolean
1576 :version "21.1"
87911bdb
CY
1577 :group 'custom-buffer
1578 :set (lambda (variable value)
1579 (custom-set-default variable value)
1580 (setq custom-button
1581 (if value 'custom-button 'custom-button-unraised))
85a5eb0e
CY
1582 (setq custom-button-mouse
1583 (if value 'custom-button-mouse 'highlight))
87911bdb
CY
1584 (setq custom-button-pressed
1585 (if value
1586 'custom-button-pressed
1587 'custom-button-pressed-unraised))))
d3d4df42 1588
06b60517 1589(defun custom-buffer-create-internal (options &optional _description)
6aec3b9d 1590 (Custom-mode)
9db1942d
CY
1591 (let ((init-file (or custom-file user-init-file)))
1592 ;; Insert verbose help at the top of the custom buffer.
1593 (when custom-buffer-verbose-help
1fc6097b
CY
1594 (unless init-file
1595 (widget-insert "Custom settings cannot be saved; maybe you started Emacs with `-q'.\n"))
1596 (widget-insert "For help using this buffer, see ")
9db1942d 1597 (widget-create 'custom-manual
1fc6097b
CY
1598 :tag "Easy Customization"
1599 "(emacs)Easy Customization")
9db1942d
CY
1600 (widget-insert " in the ")
1601 (widget-create 'custom-manual
1602 :tag "Emacs manual"
1603 :help-echo "Read the Emacs manual."
1604 "(emacs)Top")
1605 (widget-insert "."))
9db1942d 1606 (widget-insert "\n")
647f9993
CY
1607
1608 ;; Insert the search field.
1609 (when custom-search-field
1610 (widget-insert "\n")
983b9602
CY
1611 (let* ((echo "Search for custom items.
1612You can enter one or more words separated by spaces,
1613or a regular expression.")
647f9993
CY
1614 (search-widget
1615 (widget-create
1616 'editable-field
1617 :size 40 :help-echo echo
1618 :action `(lambda (widget &optional event)
d8c8743b 1619 (customize-apropos (split-string (widget-value widget)))))))
647f9993
CY
1620 (widget-insert " ")
1621 (widget-create-child-and-convert
1622 search-widget 'push-button
587faadd 1623 :tag " Search "
647f9993 1624 :help-echo echo :action
06b60517 1625 (lambda (widget &optional _event)
2e7f3bea 1626 (customize-apropos (split-string (widget-value (widget-get widget :parent))))))
647f9993
CY
1627 (widget-insert "\n")))
1628
f6542587
GM
1629 ;; The custom command buttons are also in the toolbar, so for a
1630 ;; time they were not inserted in the buffer if the toolbar was in use.
1631 ;; But it can be a little confusing for the buffer layout to
1632 ;; change according to whether or nor the toolbar is on, not to
1633 ;; mention that a custom buffer can in theory be created in a
1634 ;; frame with a toolbar, then later viewed in one without.
1635 ;; So now the buttons are always inserted in the buffer. (Bug#1326)
f6542587 1636 (if custom-buffer-verbose-help
647f9993 1637 (widget-insert "
cf20dee0 1638Operate on all settings in this buffer:\n"))
06b60517 1639 (let ((button (lambda (tag action active help _icon _label)
f6542587
GM
1640 (widget-insert " ")
1641 (if (eval active)
1642 (widget-create 'push-button :tag tag
1643 :help-echo help :action action))))
1644 (commands custom-commands))
f6542587
GM
1645 (if custom-reset-button-menu
1646 (progn
f6542587 1647 (widget-create 'push-button
cf20dee0 1648 :tag " Revert... "
f6542587
GM
1649 :help-echo "Show a menu with reset operations."
1650 :mouse-down-action 'ignore
cf20dee0
CY
1651 :action 'custom-reset)
1652 (apply button (pop commands)) ; Apply
1653 (apply button (pop commands))) ; Apply and Save
1654 (apply button (pop commands)) ; Apply
1655 (apply button (pop commands)) ; Apply and Save
f6542587 1656 (widget-insert "\n")
cf20dee0
CY
1657 (apply button (pop commands)) ; Undo
1658 (apply button (pop commands)) ; Reset
1659 (apply button (pop commands)) ; Erase
f6542587 1660 (widget-insert " ")
cf20dee0 1661 (pop commands) ; Help (omitted)
f6542587 1662 (apply button (pop commands)))) ; Exit
9db1942d
CY
1663 (widget-insert "\n\n"))
1664
1665 ;; Now populate the custom buffer.
25ac13b5 1666 (message "Creating customization items...")
fadbdfea 1667 (buffer-disable-undo)
d3d4df42 1668 (setq custom-options
d543e20b
PA
1669 (if (= (length options) 1)
1670 (mapcar (lambda (entry)
1671 (widget-create (nth 1 entry)
c32de15e 1672 :documentation-shown t
d543e20b
PA
1673 :custom-state 'unknown
1674 :tag (custom-unlispify-tag-name
1675 (nth 0 entry))
1676 :value (nth 0 entry)))
1677 options)
1678 (let ((count 0)
1679 (length (length options)))
1680 (mapcar (lambda (entry)
6b292312
DL
1681 (prog2
1682 (message "Creating customization items ...%2d%%"
1683 (/ (* 100.0 count) length))
1684 (widget-create (nth 1 entry)
d543e20b
PA
1685 :tag (custom-unlispify-tag-name
1686 (nth 0 entry))
1687 :value (nth 0 entry))
6b292312
DL
1688 (setq count (1+ count))
1689 (unless (eq (preceding-char) ?\n)
1690 (widget-insert "\n"))
1691 (widget-insert "\n")))
1692 options))))
d543e20b
PA
1693 (unless (eq (preceding-char) ?\n)
1694 (widget-insert "\n"))
a9bcbf3f 1695 (message "Creating customization items ...done")
1833b7b3 1696 (message "Resetting customization items...")
944c91b6 1697 (unless (eq custom-buffer-style 'tree)
fadbdfea 1698 (mapc 'custom-magic-reset custom-options))
1833b7b3 1699 (message "Resetting customization items...done")
d543e20b
PA
1700 (message "Creating customization setup...")
1701 (widget-setup)
fadbdfea 1702 (buffer-enable-undo)
d543e20b 1703 (goto-char (point-min))
1833b7b3 1704 (message "Creating customization setup...done"))
d543e20b 1705
944c91b6
PA
1706;;; The Tree Browser.
1707
1708;;;###autoload
4ee1cf9f 1709(defun customize-browse (&optional group)
944c91b6 1710 "Create a tree browser for the customize hierarchy."
cda987f4 1711 (interactive)
4ee1cf9f
PA
1712 (unless group
1713 (setq group 'emacs))
1714 (let ((name "*Customize Browser*"))
72258fe5 1715 (pop-to-buffer-same-window (custom-get-fresh-buffer name)))
6aec3b9d 1716 (Custom-mode)
b758ae9a
RS
1717 (widget-insert (format "\
1718%s buttons; type RET or click mouse-1
1719on a button to invoke its action.
1720Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1721 (if custom-raised-buttons
1722 "`Raised' text indicates"
1723 "Square brackets indicate")))
1724
1725
4ee1cf9f
PA
1726 (if custom-browse-only-groups
1727 (widget-insert "\
c953515e 1728Invoke the [Group] button below to edit that item in another window.\n\n")
d3d4df42
DL
1729 (widget-insert "Invoke the ")
1730 (widget-create 'item
4ee1cf9f
PA
1731 :format "%t"
1732 :tag "[Group]"
1733 :tag-glyph "folder")
1734 (widget-insert ", ")
d3d4df42 1735 (widget-create 'item
4ee1cf9f
PA
1736 :format "%t"
1737 :tag "[Face]"
1738 :tag-glyph "face")
1739 (widget-insert ", and ")
d3d4df42 1740 (widget-create 'item
4ee1cf9f
PA
1741 :format "%t"
1742 :tag "[Option]"
1743 :tag-glyph "option")
1744 (widget-insert " buttons below to edit that
c953515e 1745item in another window.\n\n"))
4ee1cf9f 1746 (let ((custom-buffer-style 'tree))
d3d4df42 1747 (widget-create 'custom-group
4ee1cf9f
PA
1748 :custom-last t
1749 :custom-state 'unknown
1750 :tag (custom-unlispify-tag-name group)
1751 :value group))
f134b461 1752 (widget-setup)
4ee1cf9f 1753 (goto-char (point-min)))
944c91b6 1754
c953515e 1755(define-widget 'custom-browse-visibility 'item
1edec9cf 1756 "Control visibility of items in the customize tree browser."
da5ec617 1757 :format "%[[%t]%]"
c953515e 1758 :action 'custom-browse-visibility-action)
944c91b6 1759
06b60517 1760(defun custom-browse-visibility-action (widget &rest _ignore)
944c91b6
PA
1761 (let ((custom-buffer-style 'tree))
1762 (custom-toggle-parent widget)))
1763
192e44fc 1764(define-widget 'custom-browse-group-tag 'custom-group-link
944c91b6 1765 "Show parent in other window when activated."
cd6c0940 1766 :tag "Group"
da5ec617 1767 :tag-glyph "folder"
c953515e 1768 :action 'custom-browse-group-tag-action)
944c91b6 1769
06b60517 1770(defun custom-browse-group-tag-action (widget &rest _ignore)
944c91b6
PA
1771 (let ((parent (widget-get widget :parent)))
1772 (customize-group-other-window (widget-value parent))))
1773
192e44fc 1774(define-widget 'custom-browse-variable-tag 'custom-group-link
944c91b6 1775 "Show parent in other window when activated."
cd6c0940 1776 :tag "Option"
da5ec617 1777 :tag-glyph "option"
c953515e 1778 :action 'custom-browse-variable-tag-action)
944c91b6 1779
06b60517 1780(defun custom-browse-variable-tag-action (widget &rest _ignore)
944c91b6
PA
1781 (let ((parent (widget-get widget :parent)))
1782 (customize-variable-other-window (widget-value parent))))
1783
192e44fc 1784(define-widget 'custom-browse-face-tag 'custom-group-link
944c91b6 1785 "Show parent in other window when activated."
cd6c0940 1786 :tag "Face"
da5ec617 1787 :tag-glyph "face"
c953515e 1788 :action 'custom-browse-face-tag-action)
944c91b6 1789
06b60517 1790(defun custom-browse-face-tag-action (widget &rest _ignore)
944c91b6
PA
1791 (let ((parent (widget-get widget :parent)))
1792 (customize-face-other-window (widget-value parent))))
1793
c953515e 1794(defconst custom-browse-alist '((" " "space")
da5ec617
PA
1795 (" | " "vertical")
1796 ("-\\ " "top")
1797 (" |-" "middle")
1798 (" `-" "bottom")))
1799
c953515e 1800(defun custom-browse-insert-prefix (prefix)
da5ec617 1801 "Insert PREFIX. On XEmacs convert it to line graphics."
d3d4df42 1802 ;; Fixme: do graphics.
a7f58f4b 1803 (if nil ; (featurep 'xemacs)
d3d4df42 1804 (progn
da5ec617
PA
1805 (insert "*")
1806 (while (not (string-equal prefix ""))
1807 (let ((entry (substring prefix 0 3)))
1808 (setq prefix (substring prefix 3))
1809 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
c953515e 1810 (name (nth 1 (assoc entry custom-browse-alist))))
da5ec617
PA
1811 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1812 (overlay-put overlay 'start-open t)
1813 (overlay-put overlay 'end-open t)))))
1814 (insert prefix)))
1815
d543e20b
PA
1816;;; Modification of Basic Widgets.
1817;;
1818;; We add extra properties to the basic widgets needed here. This is
62a918ca 1819;; fine, as long as we are careful to stay within our own namespace.
d543e20b
PA
1820;;
1821;; We want simple widgets to be displayed by default, but complex
1822;; widgets to be hidden.
1823
af0905c8 1824;; This widget type is obsolete as of Emacs 24.1.
d543e20b
PA
1825(widget-put (get 'item 'widget-type) :custom-show t)
1826(widget-put (get 'editable-field 'widget-type)
06b60517 1827 :custom-show (lambda (_widget value)
d543e20b
PA
1828 (let ((pp (pp-to-string value)))
1829 (cond ((string-match "\n" pp)
1830 nil)
1831 ((> (length pp) 40)
1832 nil)
1833 (t t)))))
1834(widget-put (get 'menu-choice 'widget-type) :custom-show t)
1835
1836;;; The `custom-manual' Widget.
1837
1838(define-widget 'custom-manual 'info-link
1839 "Link to the manual entry for this customization option."
1840 :help-echo "Read the manual entry for this option."
f3093f77
CY
1841 :keymap custom-mode-link-map
1842 :follow-link 'mouse-face
73e60f53
CY
1843 :button-face 'custom-link
1844 :mouse-face 'highlight
e1ec62a5 1845 :pressed-face 'highlight
d543e20b
PA
1846 :tag "Manual")
1847
1848;;; The `custom-magic' Widget.
1849
6aaedd12
PA
1850(defgroup custom-magic-faces nil
1851 "Faces used by the magic button."
1852 :group 'custom-faces
1853 :group 'custom-buffer)
1854
d478e69d
MB
1855(defface custom-invalid '((((class color))
1856 (:foreground "yellow1" :background "red1"))
1857 (t
1858 (:weight bold :slant italic :underline t)))
6aaedd12
PA
1859 "Face used when the customize item is invalid."
1860 :group 'custom-magic-faces)
c4f6e489 1861(define-obsolete-face-alias 'custom-invalid-face 'custom-invalid "22.1")
d543e20b 1862
d478e69d
MB
1863(defface custom-rogue '((((class color))
1864 (:foreground "pink" :background "black"))
1865 (t
1866 (:underline t)))
6aaedd12
PA
1867 "Face used when the customize item is not defined for customization."
1868 :group 'custom-magic-faces)
c4f6e489 1869(define-obsolete-face-alias 'custom-rogue-face 'custom-rogue "22.1")
d543e20b 1870
d478e69d
MB
1871(defface custom-modified '((((min-colors 88) (class color))
1872 (:foreground "white" :background "blue1"))
ea81d57e 1873 (((class color))
d478e69d 1874 (:foreground "white" :background "blue"))
2dfa4c57 1875 (t
d478e69d
MB
1876 (:slant italic :bold)))
1877 "Face used when the customize item has been modified."
1878 :group 'custom-magic-faces)
c4f6e489 1879(define-obsolete-face-alias 'custom-modified-face 'custom-modified "22.1")
d478e69d
MB
1880
1881(defface custom-set '((((min-colors 88) (class color))
1882 (:foreground "blue1" :background "white"))
1883 (((class color))
1884 (:foreground "blue" :background "white"))
1885 (t
1886 (:slant italic)))
6aaedd12
PA
1887 "Face used when the customize item has been set."
1888 :group 'custom-magic-faces)
c4f6e489 1889(define-obsolete-face-alias 'custom-set-face 'custom-set "22.1")
d478e69d
MB
1890
1891(defface custom-changed '((((min-colors 88) (class color))
1892 (:foreground "white" :background "blue1"))
1893 (((class color))
1894 (:foreground "white" :background "blue"))
1895 (t
1896 (:slant italic)))
6aaedd12
PA
1897 "Face used when the customize item has been changed."
1898 :group 'custom-magic-faces)
c4f6e489 1899(define-obsolete-face-alias 'custom-changed-face 'custom-changed "22.1")
d543e20b 1900
d820f1fb
CY
1901(defface custom-themed '((((min-colors 88) (class color))
1902 (:foreground "white" :background "blue1"))
1903 (((class color))
1904 (:foreground "white" :background "blue"))
1905 (t
1906 (:slant italic)))
1907 "Face used when the customize item has been set by a theme."
1908 :group 'custom-magic-faces)
1909
d478e69d 1910(defface custom-saved '((t (:underline t)))
6aaedd12
PA
1911 "Face used when the customize item has been saved."
1912 :group 'custom-magic-faces)
c4f6e489 1913(define-obsolete-face-alias 'custom-saved-face 'custom-saved "22.1")
d543e20b 1914
2dfa4c57
RS
1915(defconst custom-magic-alist
1916 '((nil "#" underline "\
167eefc5 1917UNINITIALIZED, you should not see this.")
2dfa4c57 1918 (unknown "?" italic "\
167eefc5 1919UNKNOWN, you should not see this.")
2dfa4c57 1920 (hidden "-" default "\
167eefc5 1921HIDDEN, invoke \"Show\" in the previous line to show." "\
cbc7d892 1922group now hidden, invoke \"Show\", above, to show contents.")
d478e69d 1923 (invalid "x" custom-invalid "\
167eefc5 1924INVALID, the displayed value cannot be set.")
d478e69d 1925 (modified "*" custom-modified "\
167eefc5 1926EDITED, shown value does not take effect until you set or save it." "\
1833b7b3 1927something in this group has been edited but not set.")
d478e69d 1928 (set "+" custom-set "\
167eefc5 1929SET for current session only." "\
1833b7b3 1930something in this group has been set but not saved.")
d478e69d 1931 (changed ":" custom-changed "\
61328d7c 1932CHANGED outside Customize." "\
25ac13b5 1933something in this group has been changed outside customize.")
d478e69d 1934 (saved "!" custom-saved "\
167eefc5 1935SAVED and set." "\
5dd0cad0 1936something in this group has been set and saved.")
d820f1fb
CY
1937 (themed "o" custom-themed "\
1938THEMED." "\
1939visible group members are all at standard values.")
d478e69d 1940 (rogue "@" custom-rogue "\
f63d5a0e 1941NO CUSTOMIZATION DATA; not intended to be customized." "\
25ac13b5 1942something in this group is not prepared for customization.")
2dfa4c57 1943 (standard " " nil "\
167eefc5 1944STANDARD." "\
50137744 1945visible group members are all at standard values."))
d543e20b 1946 "Alist of customize option states.
d3d4df42 1947Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
d543e20b
PA
1948
1949STATE is one of the following symbols:
1950
1951`nil'
1952 For internal use, should never occur.
1953`unknown'
1954 For internal use, should never occur.
1955`hidden'
d3d4df42 1956 This item is not being displayed.
d543e20b
PA
1957`invalid'
1958 This item is modified, but has an invalid form.
1959`modified'
1960 This item is modified, and has a valid form.
1961`set'
1962 This item has been set but not saved.
1963`changed'
167eefc5 1964 The current value of this item has been changed outside Customize.
d543e20b
PA
1965`saved'
1966 This item is marked for saving.
1967`rogue'
1968 This item has no customization information.
25ac13b5 1969`standard'
5dd0cad0 1970 This item is unchanged from the standard setting.
d543e20b
PA
1971
1972MAGIC is a string used to present that state.
1973
1974FACE is a face used to present the state.
1975
25ac13b5
PA
1976ITEM-DESC is a string describing the state for options.
1977
1978GROUP-DESC is a string describing the state for groups. If this is
1979left out, ITEM-DESC will be used.
1980
9097aeb7
PA
1981The string %c in either description will be replaced with the
1982category of the item. These are `group'. `option', and `face'.
1983
25ac13b5 1984The list should be sorted most significant first.")
d543e20b
PA
1985
1986(defcustom custom-magic-show 'long
3acab5ef 1987 "If non-nil, show textual description of the state.
b62c92bb 1988If `long', show a full-line description, not just one word."
d543e20b 1989 :type '(choice (const :tag "no" nil)
c992338c
AS
1990 (const long)
1991 (other :tag "short" short))
6aaedd12 1992 :group 'custom-buffer)
d543e20b 1993
9097aeb7 1994(defcustom custom-magic-show-hidden '(option face)
b62c92bb
RS
1995 "Control whether the State button is shown for hidden items.
1996The value should be a list with the custom categories where the State
9097aeb7
PA
1997button should be visible. Possible categories are `group', `option',
1998and `face'."
1999 :type '(set (const group) (const option) (const face))
6aaedd12 2000 :group 'custom-buffer)
3acab5ef 2001
25ac13b5 2002(defcustom custom-magic-show-button nil
b62c92bb 2003 "Show a \"magic\" button indicating the state of each customization option."
d543e20b 2004 :type 'boolean
6aaedd12 2005 :group 'custom-buffer)
d543e20b
PA
2006
2007(define-widget 'custom-magic 'default
2008 "Show and manipulate state for a customization option."
2009 :format "%v"
86bd10bc 2010 :action 'widget-parent-action
6d528fc5 2011 :notify 'ignore
d543e20b
PA
2012 :value-get 'ignore
2013 :value-create 'custom-magic-value-create
2014 :value-delete 'widget-children-value-delete)
2015
06b60517 2016(defun widget-magic-mouse-down-action (widget &optional _event)
86bd10bc 2017 ;; Non-nil unless hidden.
d3d4df42 2018 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
86bd10bc
PA
2019 :custom-state)
2020 'hidden)))
2021
d543e20b 2022(defun custom-magic-value-create (widget)
2365594b 2023 "Create compact status report for WIDGET."
d543e20b
PA
2024 (let* ((parent (widget-get widget :parent))
2025 (state (widget-get parent :custom-state))
3acab5ef 2026 (hidden (eq state 'hidden))
25ac13b5 2027 (entry (assq state custom-magic-alist))
d543e20b
PA
2028 (magic (nth 1 entry))
2029 (face (nth 2 entry))
9097aeb7
PA
2030 (category (widget-get parent :custom-category))
2031 (text (or (and (eq category 'group)
25ac13b5
PA
2032 (nth 4 entry))
2033 (nth 3 entry)))
f985c5f7 2034 (form (widget-get parent :custom-form))
d543e20b 2035 children)
647f9993
CY
2036 (unless (eq state 'hidden)
2037 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
2038 (setq text (concat (match-string 1 text)
2039 (symbol-name category)
2040 (match-string 2 text))))
2041 (when (and custom-magic-show
2042 (or (not hidden)
2043 (memq category custom-magic-show-hidden)))
2044 (insert " ")
2045 (when (and (eq category 'group)
2046 (not (and (eq custom-buffer-style 'links)
2047 (> (widget-get parent :custom-level) 1))))
2048 (insert-char ?\ (* custom-buffer-indent
2049 (widget-get parent :custom-level))))
2050 (push (widget-create-child-and-convert
2051 widget 'choice-item
2052 :help-echo "Change the state of this item."
2053 :format (if hidden "%t" "%[%t%]")
2054 :button-prefix 'widget-push-button-prefix
2055 :button-suffix 'widget-push-button-suffix
2056 :mouse-down-action 'widget-magic-mouse-down-action
587faadd 2057 :tag " State ")
647f9993
CY
2058 children)
2059 (insert ": ")
2060 (let ((start (point)))
2061 (if (eq custom-magic-show 'long)
2062 (insert text)
2063 (insert (symbol-name state)))
2064 (cond ((eq form 'lisp)
2065 (insert " (lisp)"))
2066 ((eq form 'mismatch)
2067 (insert " (mismatch)")))
2068 (put-text-property start (point) 'face 'custom-state))
2069 (insert "\n"))
26c7b3ef
RS
2070 (when (and (eq category 'group)
2071 (not (and (eq custom-buffer-style 'links)
2072 (> (widget-get parent :custom-level) 1))))
944c91b6
PA
2073 (insert-char ?\ (* custom-buffer-indent
2074 (widget-get parent :custom-level))))
647f9993
CY
2075 (when custom-magic-show-button
2076 (when custom-magic-show
2077 (let ((indent (widget-get parent :indent)))
2078 (when indent
2079 (insert-char ? indent))))
2080 (push (widget-create-child-and-convert
2081 widget 'choice-item
2082 :mouse-down-action 'widget-magic-mouse-down-action
2083 :button-face face
2084 :button-prefix ""
2085 :button-suffix ""
2086 :help-echo "Change the state."
2087 :format (if hidden "%t" "%[%t%]")
2088 :tag (if (memq form '(lisp mismatch))
2089 (concat "(" magic ")")
2090 (concat "[" magic "]")))
2091 children)
2092 (insert " "))
2093 (widget-put widget :children children))))
d543e20b
PA
2094
2095(defun custom-magic-reset (widget)
2096 "Redraw the :custom-magic property of WIDGET."
2097 (let ((magic (widget-get widget :custom-magic)))
647bc502
CY
2098 (when magic
2099 (widget-value-set magic (widget-value magic)))))
d543e20b 2100
d543e20b
PA
2101;;; The `custom' Widget.
2102
d478e69d 2103(defface custom-button
9e2a2647 2104 '((((type x w32 ns) (class color)) ; Like default modeline
1a578e9b
AC
2105 (:box (:line-width 2 :style released-button)
2106 :background "lightgrey" :foreground "black"))
d3d4df42
DL
2107 (t
2108 nil))
87911bdb 2109 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
d3d4df42
DL
2110 :version "21.1"
2111 :group 'custom-faces)
c4f6e489 2112(define-obsolete-face-alias 'custom-button-face 'custom-button "22.1")
d3d4df42 2113
85a5eb0e 2114(defface custom-button-mouse
9e2a2647 2115 '((((type x w32 ns) (class color))
85a5eb0e
CY
2116 (:box (:line-width 2 :style released-button)
2117 :background "grey90" :foreground "black"))
2118 (t
746abd4d
EZ
2119 ;; This is for text terminals that support mouse, like GPM mouse
2120 ;; or the MS-DOS terminal: inverse-video makes the button stand
2121 ;; out on mouse-over.
19758b95 2122 (:inverse-video t)))
85a5eb0e
CY
2123 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2124 :version "22.1"
2125 :group 'custom-faces)
2126
87911bdb 2127(defface custom-button-unraised
192e44fc 2128 '((t :inherit underline))
87911bdb
CY
2129 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2130 :version "22.1"
2131 :group 'custom-faces)
2132
2133(setq custom-button
2134 (if custom-raised-buttons 'custom-button 'custom-button-unraised))
2135
85a5eb0e
CY
2136(setq custom-button-mouse
2137 (if custom-raised-buttons 'custom-button-mouse 'highlight))
2138
d478e69d 2139(defface custom-button-pressed
9e2a2647 2140 '((((type x w32 ns) (class color))
1a578e9b
AC
2141 (:box (:line-width 2 :style pressed-button)
2142 :background "lightgrey" :foreground "black"))
d3d4df42
DL
2143 (t
2144 (:inverse-video t)))
87911bdb 2145 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
d3d4df42 2146 :version "21.1"
b62c92bb 2147 :group 'custom-faces)
c4f6e489
GM
2148(define-obsolete-face-alias 'custom-button-pressed-face
2149 'custom-button-pressed "22.1")
b62c92bb 2150
87911bdb
CY
2151(defface custom-button-pressed-unraised
2152 '((default :inherit custom-button-unraised)
2153 (((class color) (background light)) :foreground "magenta4")
2154 (((class color) (background dark)) :foreground "violet"))
2155 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2156 :version "22.1"
2157 :group 'custom-faces)
2158
2159(setq custom-button-pressed
2160 (if custom-raised-buttons
2161 'custom-button-pressed
2162 'custom-button-pressed-unraised))
2163
dbc1f997 2164(defface custom-documentation '((t nil))
b62c92bb
RS
2165 "Face used for documentation strings in customization buffers."
2166 :group 'custom-faces)
c4f6e489
GM
2167(define-obsolete-face-alias 'custom-documentation-face
2168 'custom-documentation "22.1")
d478e69d
MB
2169
2170(defface custom-state '((((class color)
2171 (background dark))
2172 (:foreground "lime green"))
2173 (((class color)
2174 (background light))
2175 (:foreground "dark green"))
2176 (t nil))
b62c92bb
RS
2177 "Face used for State descriptions in the customize buffer."
2178 :group 'custom-faces)
c4f6e489 2179(define-obsolete-face-alias 'custom-state-face 'custom-state "22.1")
b62c92bb 2180
73e60f53 2181(defface custom-link
192e44fc
JL
2182 '((t :inherit link))
2183 "Face for links in customization buffers."
2184 :version "22.1"
2185 :group 'custom-faces)
73e60f53 2186
d543e20b
PA
2187(define-widget 'custom 'default
2188 "Customize a user option."
944c91b6 2189 :format "%v"
d543e20b 2190 :convert-widget 'custom-convert-widget
d543e20b 2191 :notify 'custom-notify
944c91b6 2192 :custom-prefix ""
d543e20b
PA
2193 :custom-level 1
2194 :custom-state 'hidden
2195 :documentation-property 'widget-subclass-responsibility
2196 :value-create 'widget-subclass-responsibility
2197 :value-delete 'widget-children-value-delete
86bd10bc
PA
2198 :value-get 'widget-value-value-get
2199 :validate 'widget-children-validate
06b60517 2200 :match (lambda (_widget value) (symbolp value)))
d543e20b
PA
2201
2202(defun custom-convert-widget (widget)
2365594b 2203 "Initialize :value and :tag from :args in WIDGET."
d543e20b 2204 (let ((args (widget-get widget :args)))
d3d4df42 2205 (when args
d543e20b
PA
2206 (widget-put widget :value (widget-apply widget
2207 :value-to-internal (car args)))
2208 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
2209 (widget-put widget :args nil)))
2210 widget)
2211
d543e20b
PA
2212(defun custom-notify (widget &rest args)
2213 "Keep track of changes."
0a3a0b56
PA
2214 (let ((state (widget-get widget :custom-state)))
2215 (unless (eq state 'modified)
2216 (unless (memq state '(nil unknown hidden))
2217 (widget-put widget :custom-state 'modified))
2218 (custom-magic-reset widget)
2219 (apply 'widget-default-notify widget args))))
d543e20b
PA
2220
2221(defun custom-redraw (widget)
2222 "Redraw WIDGET with current settings."
6d528fc5
PA
2223 (let ((line (count-lines (point-min) (point)))
2224 (column (current-column))
2225 (pos (point))
d543e20b
PA
2226 (from (marker-position (widget-get widget :from)))
2227 (to (marker-position (widget-get widget :to))))
2228 (save-excursion
2229 (widget-value-set widget (widget-value widget))
2230 (custom-redraw-magic widget))
2231 (when (and (>= pos from) (<= pos to))
6d528fc5 2232 (condition-case nil
d3d4df42 2233 (progn
e6ce8c42
GM
2234 (goto-char (point-min))
2235 (forward-line (if (> column 0)
2236 (1- line)
2237 line))
6d528fc5
PA
2238 (move-to-column column))
2239 (error nil)))))
d543e20b
PA
2240
2241(defun custom-redraw-magic (widget)
2242 "Redraw WIDGET state with current settings."
d3d4df42 2243 (while widget
d543e20b 2244 (let ((magic (widget-get widget :custom-magic)))
d3d4df42 2245 (cond (magic
944c91b6
PA
2246 (widget-value-set magic (widget-value magic))
2247 (when (setq widget (widget-get widget :group))
2248 (custom-group-state-update widget)))
2249 (t
2250 (setq widget nil)))))
d543e20b
PA
2251 (widget-setup))
2252
af0905c8 2253(make-obsolete 'custom-show "this widget type is no longer supported." "24.1")
d543e20b
PA
2254(defun custom-show (widget value)
2255 "Non-nil if WIDGET should be shown with VALUE by default."
2256 (let ((show (widget-get widget :custom-show)))
647f9993
CY
2257 (if (functionp show)
2258 (funcall show widget value)
2259 show)))
d543e20b 2260
d543e20b
PA
2261(defun custom-load-widget (widget)
2262 "Load all dependencies for WIDGET."
2263 (custom-load-symbol (widget-value widget)))
2264
c953515e 2265(defun custom-unloaded-symbol-p (symbol)
3127aa13 2266 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
c953515e
PA
2267 (let ((found nil)
2268 (loads (get symbol 'custom-loads))
2269 load)
2270 (while loads
2271 (setq load (car loads)
2272 loads (cdr loads))
2273 (cond ((symbolp load)
2274 (unless (featurep load)
2275 (setq found t)))
2276 ((assoc load load-history))
2277 ((assoc (locate-library load) load-history)
2278 (message nil))
2279 (t
2280 (setq found t))))
2281 found))
2282
2283(defun custom-unloaded-widget-p (widget)
3127aa13 2284 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
c953515e
PA
2285 (custom-unloaded-symbol-p (widget-value widget)))
2286
6d528fc5
PA
2287(defun custom-toggle-hide (widget)
2288 "Toggle visibility of WIDGET."
c953515e 2289 (custom-load-widget widget)
6d528fc5 2290 (let ((state (widget-get widget :custom-state)))
fdbdd068
CY
2291 (cond ((memq state '(invalid modified set))
2292 (error "There are unsaved changes"))
6d528fc5
PA
2293 ((eq state 'hidden)
2294 (widget-put widget :custom-state 'unknown))
d3d4df42 2295 (t
3acab5ef 2296 (widget-put widget :documentation-shown nil)
6d528fc5 2297 (widget-put widget :custom-state 'hidden)))
8697863a
PA
2298 (custom-redraw widget)
2299 (widget-setup)))
6d528fc5 2300
06b60517 2301(defun custom-toggle-parent (widget &rest _ignore)
b62c92bb 2302 "Toggle visibility of parent of WIDGET."
3acab5ef
PA
2303 (custom-toggle-hide (widget-get widget :parent)))
2304
944c91b6
PA
2305(defun custom-add-see-also (widget &optional prefix)
2306 "Add `See also ...' to WIDGET if there are any links.
2307Insert PREFIX first if non-nil."
2308 (let* ((symbol (widget-get widget :value))
2309 (links (get symbol 'custom-links))
2310 (many (> (length links) 2))
2311 (buttons (widget-get widget :buttons))
2312 (indent (widget-get widget :indent)))
2313 (when links
2314 (when indent
2315 (insert-char ?\ indent))
2316 (when prefix
2317 (insert prefix))
2318 (insert "See also ")
2319 (while links
83dc149d
EZ
2320 (push (widget-create-child-and-convert
2321 widget (car links)
2322 :button-face 'custom-link
e1ec62a5
CY
2323 :mouse-face 'highlight
2324 :pressed-face 'highlight)
944c91b6
PA
2325 buttons)
2326 (setq links (cdr links))
2327 (cond ((null links)
2328 (insert ".\n"))
2329 ((null (cdr links))
2330 (if many
2331 (insert ", and ")
2332 (insert " and ")))
d3d4df42 2333 (t
944c91b6
PA
2334 (insert ", "))))
2335 (widget-put widget :buttons buttons))))
2336
06b60517 2337(defun custom-add-parent-links (widget &optional initial-string _doc-initial-string)
cd6c0940 2338 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
08adfdbb 2339The value is non-nil if any parents were found.
cd6c0940 2340If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
944c91b6
PA
2341 (let ((name (widget-value widget))
2342 (type (widget-type widget))
2343 (buttons (widget-get widget :buttons))
d377bee9 2344 (start (point))
ac00d71c 2345 (parents nil))
f1201e3a 2346 (insert (or initial-string "Groups:"))
944c91b6 2347 (mapatoms (lambda (symbol)
08adfdbb
LT
2348 (when (member (list name type) (get symbol 'custom-group))
2349 (insert " ")
2350 (push (widget-create-child-and-convert
2351 widget 'custom-group-link
2352 :tag (custom-unlispify-tag-name symbol)
2353 symbol)
2354 buttons)
2355 (setq parents (cons symbol parents)))))
ac00d71c
PA
2356 (if parents
2357 (insert "\n")
d377bee9 2358 (delete-region start (point)))
ac00d71c
PA
2359 (widget-put widget :buttons buttons)
2360 parents))
944c91b6 2361
d3d4df42
DL
2362;;; The `custom-comment' Widget.
2363
2364;; like the editable field
ee5137b3
JPW
2365(defface custom-comment '((((type tty))
2366 :background "yellow3"
2367 :foreground "black")
2368 (((class grayscale color)
d478e69d 2369 (background light))
ee5137b3 2370 :background "gray85")
d478e69d
MB
2371 (((class grayscale color)
2372 (background dark))
ee5137b3 2373 :background "dim gray")
d478e69d 2374 (t
ee5137b3 2375 :slant italic))
6cda144f 2376 "Face used for comments on variables or faces."
d3d4df42
DL
2377 :version "21.1"
2378 :group 'custom-faces)
c4f6e489 2379(define-obsolete-face-alias 'custom-comment-face 'custom-comment "22.1")
d3d4df42
DL
2380
2381;; like font-lock-comment-face
d478e69d 2382(defface custom-comment-tag
d3d4df42
DL
2383 '((((class color) (background dark)) (:foreground "gray80"))
2384 (((class color) (background light)) (:foreground "blue4"))
2385 (((class grayscale) (background light))
b5555381 2386 (:foreground "DimGray" :weight bold :slant italic))
d3d4df42 2387 (((class grayscale) (background dark))
b5555381
RS
2388 (:foreground "LightGray" :weight bold :slant italic))
2389 (t (:weight bold)))
6200ac6c 2390 "Face used for the comment tag on variables or faces."
d3d4df42 2391 :group 'custom-faces)
c4f6e489 2392(define-obsolete-face-alias 'custom-comment-tag-face 'custom-comment-tag "22.1")
d3d4df42
DL
2393
2394(define-widget 'custom-comment 'string
164cfaeb 2395 "User comment."
d3d4df42 2396 :tag "Comment"
164cfaeb 2397 :help-echo "Edit a comment here."
6200ac6c
GM
2398 :sample-face 'custom-comment-tag
2399 :value-face 'custom-comment
164cfaeb
DL
2400 :shown nil
2401 :create 'custom-comment-create)
d3d4df42
DL
2402
2403(defun custom-comment-create (widget)
164cfaeb 2404 (let* ((null-comment (equal "" (widget-value widget))))
6171a945
DL
2405 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2406 (not null-comment))
2407 (widget-default-create widget)
2408 ;; `widget-default-delete' expects markers in these slots --
2409 ;; maybe it shouldn't.
2410 (widget-put widget :from (point-marker))
2411 (widget-put widget :to (point-marker)))))
164cfaeb
DL
2412
2413(defun custom-comment-hide (widget)
2414 (widget-put (widget-get widget :parent) :comment-shown nil))
d3d4df42
DL
2415
2416;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2417;; the global custom one
2418(defun custom-comment-show (widget)
164cfaeb
DL
2419 (widget-put widget :comment-shown t)
2420 (custom-redraw widget)
2421 (widget-setup))
d3d4df42
DL
2422
2423(defun custom-comment-invisible-p (widget)
164cfaeb
DL
2424 (let ((val (widget-value (widget-get widget :comment-widget))))
2425 (and (equal "" val)
2426 (not (widget-get widget :comment-shown)))))
d3d4df42 2427
d543e20b
PA
2428;;; The `custom-variable' Widget.
2429
d478e69d 2430(defface custom-variable-tag
16b20ed9
GM
2431 `((((class color)
2432 (background dark))
9db1942d 2433 (:foreground "light blue" :weight bold))
ea81d57e
DN
2434 (((min-colors 88) (class color)
2435 (background light))
9db1942d 2436 (:foreground "blue1" :weight bold))
16b20ed9
GM
2437 (((class color)
2438 (background light))
9db1942d 2439 (:foreground "blue" :weight bold))
b5555381 2440 (t (:weight bold)))
d543e20b 2441 "Face used for unpushable variable tags."
bd042c03 2442 :group 'custom-faces)
c4f6e489
GM
2443(define-obsolete-face-alias 'custom-variable-tag-face
2444 'custom-variable-tag "22.1")
d543e20b 2445
d478e69d 2446(defface custom-variable-button '((t (:underline t :weight bold)))
d543e20b 2447 "Face used for pushable variable tags."
bd042c03 2448 :group 'custom-faces)
c4f6e489
GM
2449(define-obsolete-face-alias 'custom-variable-button-face
2450 'custom-variable-button "22.1")
d543e20b 2451
d64478da
KH
2452(defcustom custom-variable-default-form 'edit
2453 "Default form of displaying variable values."
2454 :type '(choice (const edit)
2455 (const lisp))
cd32a7ba
DN
2456 :group 'custom-buffer
2457 :version "20.3")
d64478da 2458
a075569a
LT
2459(defun custom-variable-documentation (variable)
2460 "Return documentation of VARIABLE for use in Custom buffer.
2461Normally just return the docstring. But if VARIABLE automatically
2462becomes buffer local when set, append a message to that effect."
2463 (if (and (local-variable-if-set-p variable)
2464 (or (not (local-variable-p variable))
2465 (with-temp-buffer
2466 (local-variable-if-set-p variable))))
2467 (concat (documentation-property variable 'variable-documentation)
2468 "\n
2469This variable automatically becomes buffer-local when set outside Custom.
2470However, setting it through Custom sets the default value.")
2471 (documentation-property variable 'variable-documentation)))
2472
d543e20b 2473(define-widget 'custom-variable 'custom
647f9993 2474 "A widget for displaying a Custom variable.
61328d7c
CY
2475The following properties have special meanings for this widget:
2476
2477:hidden-states should be a list of widget states for which the
2478 widget's initial contents are to be hidden.
2479
2480:custom-form should be a symbol describing how to display and
2481 edit the variable---either `edit' (using edit widgets),
2482 `lisp' (as a Lisp sexp), or `mismatch' (should not happen);
da16abfc
CY
2483 if nil, use the return value of `custom-variable-default-form'.
2484
2485:shown-value, if non-nil, should be a list whose `car' is the
2486 variable value to display in place of the current value.
2487
647bc502
CY
2488:custom-style describes the widget interface style; nil is the
2489 default style, while `simple' means a simpler interface that
2490 inhibits the magic custom-state widget."
944c91b6 2491 :format "%v"
d543e20b 2492 :help-echo "Set or reset this variable."
a075569a 2493 :documentation-property #'custom-variable-documentation
9097aeb7 2494 :custom-category 'option
d543e20b
PA
2495 :custom-state nil
2496 :custom-menu 'custom-variable-menu-create
61328d7c 2497 :custom-form nil
d543e20b
PA
2498 :value-create 'custom-variable-value-create
2499 :action 'custom-variable-action
647f9993 2500 :hidden-states '(standard)
d543e20b 2501 :custom-set 'custom-variable-set
5ae87ed4 2502 :custom-mark-to-save 'custom-variable-mark-to-save
d543e20b
PA
2503 :custom-reset-current 'custom-redraw
2504 :custom-reset-saved 'custom-variable-reset-saved
4f985043 2505 :custom-reset-standard 'custom-variable-reset-standard
5ae87ed4
MR
2506 :custom-mark-to-reset-standard 'custom-variable-mark-to-reset-standard
2507 :custom-standard-value 'custom-variable-standard-value
2508 :custom-state-set-and-redraw 'custom-variable-state-set-and-redraw)
d543e20b 2509
bd042c03
PA
2510(defun custom-variable-type (symbol)
2511 "Return a widget suitable for editing the value of SYMBOL.
d3d4df42 2512If SYMBOL has a `custom-type' property, use that.
f0fc8583
RS
2513Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2514try matching its doc string against `custom-guess-doc-alist'."
bd042c03 2515 (let* ((type (or (get symbol 'custom-type)
25ac13b5 2516 (and (not (get symbol 'standard-value))
bd042c03
PA
2517 (custom-guess-type symbol))
2518 'sexp))
2519 (options (get symbol 'custom-options))
2520 (tmp (if (listp type)
46fa5a83 2521 (copy-sequence type)
bd042c03
PA
2522 (list type))))
2523 (when options
2524 (widget-put tmp :options options))
2525 tmp))
2526
d543e20b 2527(defun custom-variable-value-create (widget)
164cfaeb 2528 "Here is where you edit the variable's value."
d543e20b 2529 (custom-load-widget widget)
d64478da
KH
2530 (unless (widget-get widget :custom-form)
2531 (widget-put widget :custom-form custom-variable-default-form))
d543e20b
PA
2532 (let* ((buttons (widget-get widget :buttons))
2533 (children (widget-get widget :children))
2534 (form (widget-get widget :custom-form))
d543e20b 2535 (symbol (widget-get widget :value))
d543e20b 2536 (tag (widget-get widget :tag))
bd042c03 2537 (type (custom-variable-type symbol))
d543e20b 2538 (conv (widget-convert type))
6d528fc5 2539 (get (or (get symbol 'custom-get) 'default-value))
944c91b6
PA
2540 (prefix (widget-get widget :custom-prefix))
2541 (last (widget-get widget :custom-last))
29a4c45b 2542 (style (widget-get widget :custom-style))
da16abfc
CY
2543 (value (let ((shown-value (widget-get widget :shown-value)))
2544 (cond (shown-value
2545 (car shown-value))
2546 ((default-boundp symbol)
2547 (funcall get symbol))
2548 (t (widget-get conv :value)))))
647f9993
CY
2549 (state (or (widget-get widget :custom-state)
2550 (if (memq (custom-variable-state symbol value)
2551 (widget-get widget :hidden-states))
2552 'hidden))))
2553
d543e20b 2554 ;; If we don't know the state, see if we need to edit it in lisp form.
647f9993
CY
2555 (unless state
2556 (setq state (if (custom-show type value) 'unknown 'hidden)))
d543e20b
PA
2557 (when (eq state 'unknown)
2558 (unless (widget-apply conv :match value)
f985c5f7 2559 (setq form 'mismatch)))
d543e20b 2560 ;; Now we can create the child widget.
944c91b6 2561 (cond ((eq custom-buffer-style 'tree)
da5ec617 2562 (insert prefix (if last " `--- " " |--- "))
944c91b6 2563 (push (widget-create-child-and-convert
c953515e 2564 widget 'custom-browse-variable-tag)
944c91b6
PA
2565 buttons)
2566 (insert " " tag "\n")
2567 (widget-put widget :buttons buttons))
2568 ((eq state 'hidden)
d543e20b 2569 ;; Indicate hidden value.
d3d4df42 2570 (push (widget-create-child-and-convert
647f9993 2571 widget 'custom-visibility
8697863a 2572 :help-echo "Show the value of this option."
895123f5 2573 :on-glyph "down"
647f9993 2574 :on "Hide"
895123f5 2575 :off-glyph "right"
7f663295 2576 :off "Show Value"
647bc502 2577 :action 'custom-toggle-hide-variable
3acab5ef 2578 nil)
647f9993
CY
2579 buttons)
2580 (insert " ")
2581 (push (widget-create-child-and-convert
2582 widget 'item
2583 :format "%{%t%} "
2584 :sample-face 'custom-variable-tag
2585 :tag tag
2586 :parent widget)
3acab5ef 2587 buttons))
f985c5f7 2588 ((memq form '(lisp mismatch))
647f9993
CY
2589 (push (widget-create-child-and-convert
2590 widget 'custom-visibility
2591 :help-echo "Hide the value of this option."
2592 :on "Hide"
2593 :off "Show"
895123f5
CY
2594 :on-glyph "down"
2595 :off-glyph "right"
647bc502 2596 :action 'custom-toggle-hide-variable
647f9993
CY
2597 t)
2598 buttons)
2599 (insert " ")
eeb6cc88
CY
2600 ;; This used to try presenting the saved value or the
2601 ;; standard value, but it seems more intuitive to present
2602 ;; the current value (Bug#7600).
2603 (let* ((value (cond ((default-boundp symbol)
6d528fc5 2604 (custom-quote (funcall get symbol)))
d543e20b
PA
2605 (t
2606 (custom-quote (widget-get conv :value))))))
3acab5ef 2607 (insert (symbol-name symbol) ": ")
d3d4df42
DL
2608 (push (widget-create-child-and-convert
2609 widget 'sexp
d543e20b 2610 :button-face 'custom-variable-button-face
3acab5ef 2611 :format "%v"
d543e20b
PA
2612 :tag (symbol-name symbol)
2613 :parent widget
2614 :value value)
2615 children)))
2616 (t
2617 ;; Edit mode.
647f9993
CY
2618 (push (widget-create-child-and-convert
2619 widget 'custom-visibility
2620 :help-echo "Hide or show this option."
2621 :on "Hide"
2622 :off "Show"
895123f5
CY
2623 :on-glyph "down"
2624 :off-glyph "right"
647bc502 2625 :action 'custom-toggle-hide-variable
647f9993
CY
2626 t)
2627 buttons)
2628 (insert " ")
3acab5ef
PA
2629 (let* ((format (widget-get type :format))
2630 tag-format value-format)
2631 (unless (string-match ":" format)
896a6a5d 2632 (error "Bad format"))
3acab5ef
PA
2633 (setq tag-format (substring format 0 (match-end 0)))
2634 (setq value-format (substring format (match-end 0)))
2635 (push (widget-create-child-and-convert
d3d4df42 2636 widget 'item
3acab5ef
PA
2637 :format tag-format
2638 :action 'custom-tag-action
8697863a 2639 :help-echo "Change value of this option."
3acab5ef 2640 :mouse-down-action 'custom-tag-mouse-down-action
ee108e88
GM
2641 :button-face 'custom-variable-button
2642 :sample-face 'custom-variable-tag
3acab5ef
PA
2643 tag)
2644 buttons)
3acab5ef 2645 (push (widget-create-child-and-convert
d3d4df42 2646 widget type
3acab5ef
PA
2647 :format value-format
2648 :value value)
2649 children))))
944c91b6 2650 (unless (eq custom-buffer-style 'tree)
944c91b6
PA
2651 (unless (eq (preceding-char) ?\n)
2652 (widget-insert "\n"))
944c91b6 2653 ;; Create the magic button.
29a4c45b 2654 (unless (eq style 'simple)
da16abfc
CY
2655 (let ((magic (widget-create-child-and-convert
2656 widget 'custom-magic nil)))
2657 (widget-put widget :custom-magic magic)
2658 (push magic buttons)))
944c91b6 2659 (widget-put widget :buttons buttons)
944c91b6 2660 ;; Insert documentation.
9db1942d 2661 (widget-put widget :documentation-indent 3)
29a4c45b
CY
2662 (unless (and (eq style 'simple)
2663 (eq state 'hidden))
2664 (widget-add-documentation-string-button
2665 widget :visibility-widget 'custom-visibility))
d3d4df42
DL
2666
2667 ;; The comment field
2668 (unless (eq state 'hidden)
2669 (let* ((comment (get symbol 'variable-comment))
2670 (comment-widget
2671 (widget-create-child-and-convert
2672 widget 'custom-comment
2673 :parent widget
2674 :value (or comment ""))))
2675 (widget-put widget :comment-widget comment-widget)
2676 ;; Don't push it !!! Custom assumes that the first child is the
2677 ;; value one.
2678 (setq children (append children (list comment-widget)))))
647f9993 2679 ;; Update the rest of the properties.
d3d4df42
DL
2680 (widget-put widget :custom-form form)
2681 (widget-put widget :children children)
2682 ;; Now update the state.
2683 (if (eq state 'hidden)
2684 (widget-put widget :custom-state state)
2685 (custom-variable-state-set widget))
944c91b6
PA
2686 ;; See also.
2687 (unless (eq state 'hidden)
2688 (when (eq (widget-get widget :custom-level) 1)
2689 (custom-add-parent-links widget))
2690 (custom-add-see-also widget)))))
d543e20b 2691
06b60517 2692(defun custom-toggle-hide-variable (visibility-widget &rest _ignore)
647bc502
CY
2693 "Toggle the visibility of a `custom-variable' parent widget.
2694By default, this signals an error if the parent has unsaved
2695changes. If the parent has a `simple' :custom-style property,
2696the present value is saved to its :shown-value property instead."
2697 (let ((widget (widget-get visibility-widget :parent)))
2698 (unless (eq (widget-type widget) 'custom-variable)
2699 (error "Invalid widget type"))
2700 (custom-load-widget widget)
2701 (let ((state (widget-get widget :custom-state)))
2702 (if (eq state 'hidden)
2703 (widget-put widget :custom-state 'unknown)
2704 ;; In normal interface, widget can't be hidden if modified.
2705 (when (memq state '(invalid modified set))
2706 (if (eq (widget-get widget :custom-style) 'simple)
2707 (widget-put widget :shown-value
2708 (list (widget-value
2709 (car-safe
2710 (widget-get widget :children)))))
2711 (error "There are unsaved changes")))
2712 (widget-put widget :documentation-shown nil)
2713 (widget-put widget :custom-state 'hidden))
2714 (custom-redraw widget)
2715 (widget-setup))))
2716
3acab5ef
PA
2717(defun custom-tag-action (widget &rest args)
2718 "Pass :action to first child of WIDGET's parent."
2719 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2720 :action args))
2721
2722(defun custom-tag-mouse-down-action (widget &rest args)
2723 "Pass :mouse-down-action to first child of WIDGET's parent."
2724 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2725 :mouse-down-action args))
2726
647f9993
CY
2727(defun custom-variable-state (symbol val)
2728 "Return the state of SYMBOL if its value is VAL.
2729If SYMBOL has a non-nil `custom-get' property, it overrides VAL.
2730Possible return values are `standard', `saved', `set', `themed',
2731`changed', and `rogue'."
2732 (let* ((get (or (get symbol 'custom-get) 'default-value))
d543e20b 2733 (value (if (default-boundp symbol)
6d528fc5 2734 (funcall get symbol)
647f9993 2735 val))
d3d4df42 2736 (comment (get symbol 'variable-comment))
d543e20b 2737 tmp
647f9993
CY
2738 temp)
2739 (cond ((progn (setq tmp (get symbol 'customized-value))
2740 (setq temp
2741 (get symbol 'customized-variable-comment))
2742 (or tmp temp))
2743 (if (condition-case nil
2744 (and (equal value (eval (car tmp)))
2745 (equal comment temp))
2746 (error nil))
2747 'set
2748 'changed))
2749 ((progn (setq tmp (get symbol 'theme-value))
2750 (setq temp (get symbol 'saved-variable-comment))
2751 (or tmp temp))
2752 (if (condition-case nil
2753 (and (equal comment temp)
2754 (equal value
2755 (eval
2756 (car (custom-variable-theme-value
2757 symbol)))))
2758 (error nil))
2759 (cond
2760 ((eq (caar tmp) 'user) 'saved)
2761 ((eq (caar tmp) 'changed)
2762 (if (condition-case nil
2763 (and (null comment)
2764 (equal value
2765 (eval
2766 (car (get symbol 'standard-value)))))
2767 (error nil))
2768 ;; The value was originally set outside
2769 ;; custom, but it was set to the standard
2770 ;; value (probably an autoloaded defcustom).
2771 'standard
2772 'changed))
2773 (t 'themed))
2774 'changed))
2775 ((setq tmp (get symbol 'standard-value))
2776 (if (condition-case nil
2777 (and (equal value (eval (car tmp)))
2778 (equal comment nil))
2779 (error nil))
2780 'standard
2781 'changed))
2782 (t 'rogue))))
2783
2784(defun custom-variable-state-set (widget &optional state)
2785 "Set the state of WIDGET to STATE.
2786If STATE is nil, the value is computed by `custom-variable-state'."
2787 (widget-put widget :custom-state
2788 (or state (custom-variable-state (widget-value widget)
2789 (widget-get widget :value)))))
d543e20b 2790
4f985043
RS
2791(defun custom-variable-standard-value (widget)
2792 (get (widget-value widget) 'standard-value))
2793
d3d4df42 2794(defvar custom-variable-menu
70482877 2795 `(("Set for Current Session" custom-variable-set
0c731046 2796 (lambda (widget)
eaa99205 2797 (eq (widget-get widget :custom-state) 'modified)))
9b5007e7
GM
2798 ;; Note that in all the backquoted code in this file, we test
2799 ;; init-file-user rather than user-init-file. This is in case
2800 ;; cus-edit is loaded by something in site-start.el, because
2801 ;; user-init-file is not set at that stage.
2802 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2803 ,@(when (or custom-file init-file-user)
70482877 2804 '(("Save for Future Sessions" custom-variable-save
eaa99205
CY
2805 (lambda (widget)
2806 (memq (widget-get widget :custom-state)
2807 '(modified set changed rogue))))))
70482877 2808 ("Undo Edits" custom-redraw
6d528fc5
PA
2809 (lambda (widget)
2810 (and (default-boundp (widget-value widget))
86bd10bc 2811 (memq (widget-get widget :custom-state) '(modified changed)))))
cf20dee0 2812 ("Revert This Session's Customization" custom-variable-reset-saved
6d528fc5 2813 (lambda (widget)
c2d1019e
CY
2814 (memq (widget-get widget :custom-state)
2815 '(modified set changed rogue))))
9b5007e7 2816 ,@(when (or custom-file init-file-user)
70482877 2817 '(("Erase Customization" custom-variable-reset-standard
73e60f53
CY
2818 (lambda (widget)
2819 (and (get (widget-value widget) 'standard-value)
2820 (memq (widget-get widget :custom-state)
2821 '(modified set changed saved rogue)))))))
70482877
LT
2822 ("Set to Backup Value" custom-variable-reset-backup
2823 (lambda (widget)
2824 (get (widget-value widget) 'backup-value)))
2825 ("---" ignore ignore)
2826 ("Add Comment" custom-comment-show custom-comment-invisible-p)
eaa99205 2827 ("---" ignore ignore)
70482877 2828 ("Show Current Value" custom-variable-edit
73e60f53 2829 (lambda (widget)
eaa99205 2830 (eq (widget-get widget :custom-form) 'lisp)))
70482877 2831 ("Show Saved Lisp Expression" custom-variable-edit-lisp
eaa99205
CY
2832 (lambda (widget)
2833 (eq (widget-get widget :custom-form) 'edit))))
d543e20b 2834 "Alist of actions for the `custom-variable' widget.
6d528fc5
PA
2835Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2836the menu entry, ACTION is the function to call on the widget when the
2837menu is selected, and FILTER is a predicate which takes a `custom-variable'
2838widget as an argument, and returns non-nil if ACTION is valid on that
19d63704 2839widget. If FILTER is nil, ACTION is always valid.")
d543e20b
PA
2840
2841(defun custom-variable-action (widget &optional event)
2842 "Show the menu for `custom-variable' WIDGET.
2843Optional EVENT is the location for the menu."
2844 (if (eq (widget-get widget :custom-state) 'hidden)
6d528fc5 2845 (custom-toggle-hide widget)
86bd10bc
PA
2846 (unless (eq (widget-get widget :custom-state) 'modified)
2847 (custom-variable-state-set widget))
2848 (custom-redraw-magic widget)
d543e20b 2849 (let* ((completion-ignore-case t)
25ac13b5
PA
2850 (answer (widget-choose (concat "Operation on "
2851 (custom-unlispify-tag-name
2852 (widget-get widget :value)))
6d528fc5
PA
2853 (custom-menu-filter custom-variable-menu
2854 widget)
d543e20b
PA
2855 event)))
2856 (if answer
2857 (funcall answer widget)))))
2858
2859(defun custom-variable-edit (widget)
2860 "Edit value of WIDGET."
2861 (widget-put widget :custom-state 'unknown)
2862 (widget-put widget :custom-form 'edit)
2863 (custom-redraw widget))
2864
2865(defun custom-variable-edit-lisp (widget)
2365594b 2866 "Edit the Lisp representation of the value of WIDGET."
d543e20b
PA
2867 (widget-put widget :custom-state 'unknown)
2868 (widget-put widget :custom-form 'lisp)
2869 (custom-redraw widget))
2870
2871(defun custom-variable-set (widget)
2872 "Set the current value for the variable being edited by WIDGET."
6d528fc5
PA
2873 (let* ((form (widget-get widget :custom-form))
2874 (state (widget-get widget :custom-state))
2875 (child (car (widget-get widget :children)))
2876 (symbol (widget-value widget))
2877 (set (or (get symbol 'custom-set) 'set-default))
d3d4df42
DL
2878 (comment-widget (widget-get widget :comment-widget))
2879 (comment (widget-value comment-widget))
2880 val)
d543e20b 2881 (cond ((eq state 'hidden)
896a6a5d 2882 (error "Cannot set hidden variable"))
d543e20b
PA
2883 ((setq val (widget-apply child :validate))
2884 (goto-char (widget-get val :from))
2885 (error "%s" (widget-get val :error)))
f985c5f7 2886 ((memq form '(lisp mismatch))
d3d4df42
DL
2887 (when (equal comment "")
2888 (setq comment nil)
2889 ;; Make the comment invisible by hand if it's empty
164cfaeb 2890 (custom-comment-hide comment-widget))
bde4f354 2891 (custom-variable-backup-value widget)
25c6d447 2892 (custom-push-theme 'theme-value symbol 'user
c5d290fb 2893 'set (custom-quote (widget-value child)))
6d528fc5 2894 (funcall set symbol (eval (setq val (widget-value child))))
d3d4df42
DL
2895 (put symbol 'customized-value (list val))
2896 (put symbol 'variable-comment comment)
2897 (put symbol 'customized-variable-comment comment))
d543e20b 2898 (t
d3d4df42
DL
2899 (when (equal comment "")
2900 (setq comment nil)
2901 ;; Make the comment invisible by hand if it's empty
164cfaeb 2902 (custom-comment-hide comment-widget))
bde4f354 2903 (custom-variable-backup-value widget)
25c6d447 2904 (custom-push-theme 'theme-value symbol 'user
c5d290fb 2905 'set (custom-quote (widget-value child)))
6d528fc5 2906 (funcall set symbol (setq val (widget-value child)))
d3d4df42
DL
2907 (put symbol 'customized-value (list (custom-quote val)))
2908 (put symbol 'variable-comment comment)
2909 (put symbol 'customized-variable-comment comment)))
d543e20b
PA
2910 (custom-variable-state-set widget)
2911 (custom-redraw-magic widget)))
2912
5ae87ed4
MR
2913(defun custom-variable-mark-to-save (widget)
2914 "Set value and mark for saving the variable edited by WIDGET."
6d528fc5
PA
2915 (let* ((form (widget-get widget :custom-form))
2916 (state (widget-get widget :custom-state))
2917 (child (car (widget-get widget :children)))
2918 (symbol (widget-value widget))
2919 (set (or (get symbol 'custom-set) 'set-default))
d3d4df42
DL
2920 (comment-widget (widget-get widget :comment-widget))
2921 (comment (widget-value comment-widget))
6d528fc5 2922 val)
d543e20b 2923 (cond ((eq state 'hidden)
896a6a5d 2924 (error "Cannot set hidden variable"))
d543e20b
PA
2925 ((setq val (widget-apply child :validate))
2926 (goto-char (widget-get val :from))
6b292312 2927 (error "Saving %s: %s" symbol (widget-get val :error)))
f985c5f7 2928 ((memq form '(lisp mismatch))
d3d4df42
DL
2929 (when (equal comment "")
2930 (setq comment nil)
2931 ;; Make the comment invisible by hand if it's empty
164cfaeb 2932 (custom-comment-hide comment-widget))
d543e20b 2933 (put symbol 'saved-value (list (widget-value child)))
c942535f 2934 (custom-push-theme 'theme-value symbol 'user
c5d290fb 2935 'set (custom-quote (widget-value child)))
d3d4df42
DL
2936 (funcall set symbol (eval (widget-value child)))
2937 (put symbol 'variable-comment comment)
2938 (put symbol 'saved-variable-comment comment))
d543e20b 2939 (t
d3d4df42
DL
2940 (when (equal comment "")
2941 (setq comment nil)
2942 ;; Make the comment invisible by hand if it's empty
164cfaeb 2943 (custom-comment-hide comment-widget))
d3d4df42
DL
2944 (put symbol 'saved-value
2945 (list (custom-quote (widget-value child))))
c942535f 2946 (custom-push-theme 'theme-value symbol 'user
c5d290fb 2947 'set (custom-quote (widget-value child)))
d3d4df42
DL
2948 (funcall set symbol (widget-value child))
2949 (put symbol 'variable-comment comment)
2950 (put symbol 'saved-variable-comment comment)))
d543e20b 2951 (put symbol 'customized-value nil)
5ae87ed4
MR
2952 (put symbol 'customized-variable-comment nil)))
2953
2954(defsubst custom-variable-state-set-and-redraw (widget)
2955 "Set state of variable widget WIDGET and redraw with current settings."
2956 (custom-variable-state-set widget)
2957 (custom-redraw-magic widget))
2958
2959(defun custom-variable-save (widget)
2960 "Save value of variable edited by widget WIDGET."
2961 (custom-variable-mark-to-save widget)
2962 (custom-save-all)
2963 (custom-variable-state-set-and-redraw widget))
d543e20b
PA
2964
2965(defun custom-variable-reset-saved (widget)
c2d1019e
CY
2966 "Restore the value of the variable being edited by WIDGET.
2967If there is a saved value, restore it; otherwise reset to the
2968uncustomized (themed or standard) value.
2969
2970Update the widget to show that value. The value that was current
2971before this operation becomes the backup value."
6d528fc5 2972 (let* ((symbol (widget-value widget))
c2d1019e 2973 (saved-value (get symbol 'saved-value))
d3d4df42 2974 (comment (get symbol 'saved-variable-comment)))
c2d1019e
CY
2975 (custom-variable-backup-value widget)
2976 (if (not (or saved-value comment))
2977 ;; If there is no saved value, remove the setting.
2978 (custom-push-theme 'theme-value symbol 'user 'reset)
2979 ;; Otherwise, apply the saved value.
2980 (put symbol 'variable-comment comment)
2981 (custom-push-theme 'theme-value symbol 'user 'set (car-safe saved-value))
2982 (ignore-errors
2983 (funcall (or (get symbol 'custom-set) 'set-default)
2984 symbol (eval (car saved-value)))))
d543e20b 2985 (put symbol 'customized-value nil)
d3d4df42 2986 (put symbol 'customized-variable-comment nil)
d543e20b 2987 (widget-put widget :custom-state 'unknown)
d3d4df42 2988 ;; This call will possibly make the comment invisible
d543e20b
PA
2989 (custom-redraw widget)))
2990
5ae87ed4
MR
2991(defun custom-variable-mark-to-reset-standard (widget)
2992 "Mark to restore standard setting for the variable edited by widget WIDGET.
2993If `custom-reset-standard-variables-list' is nil, save, reset and
2994redraw the widget immediately."
d358aa10 2995 (let* ((symbol (widget-value widget)))
25ac13b5 2996 (if (get symbol 'standard-value)
25c6d447 2997 (custom-variable-backup-value widget)
5dd0cad0 2998 (error "No standard setting known for %S" symbol))
164cfaeb 2999 (put symbol 'variable-comment nil)
d543e20b 3000 (put symbol 'customized-value nil)
d3d4df42 3001 (put symbol 'customized-variable-comment nil)
d358aa10 3002 (custom-push-theme 'theme-value symbol 'user 'reset)
25c6d447 3003 (custom-theme-recalc-variable symbol)
5ae87ed4
MR
3004 (if (and custom-reset-standard-variables-list
3005 (or (get symbol 'saved-value) (get symbol 'saved-variable-comment)))
3006 (progn
3007 (put symbol 'saved-value nil)
3008 (put symbol 'saved-variable-comment nil)
3009 ;; Append this to `custom-reset-standard-variables-list' to
3010 ;; have `custom-reset-standard-save-and-update' save setting
3011 ;; to the file, update the widget's state, and redraw it.
3012 (setq custom-reset-standard-variables-list
3013 (cons widget custom-reset-standard-variables-list)))
3014 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
3015 (put symbol 'saved-value nil)
3016 (put symbol 'saved-variable-comment nil)
3017 (custom-save-all))
3018 (widget-put widget :custom-state 'unknown)
3019 ;; This call will possibly make the comment invisible
3020 (custom-redraw widget))))
3021
3022(defun custom-variable-reset-standard (widget)
3023 "Restore standard setting for the variable edited by WIDGET.
3024This operation eliminates any saved setting for the variable,
3025restoring it to the state of a variable that has never been customized.
3026The value that was current before this operation
3027becomes the backup value, so you can get it again."
3028 (let (custom-reset-standard-variables-list)
3029 (custom-variable-mark-to-reset-standard widget)))
d543e20b 3030
bde4f354
RS
3031(defun custom-variable-backup-value (widget)
3032 "Back up the current value for WIDGET's variable.
3033The backup value is kept in the car of the `backup-value' property."
3034 (let* ((symbol (widget-value widget))
3035 (get (or (get symbol 'custom-get) 'default-value))
3036 (type (custom-variable-type symbol))
3037 (conv (widget-convert type))
3038 (value (if (default-boundp symbol)
3039 (funcall get symbol)
3040 (widget-get conv :value))))
3041 (put symbol 'backup-value (list value))))
3042
3043(defun custom-variable-reset-backup (widget)
3044 "Restore the backup value for the variable being edited by WIDGET.
3045The value that was current before this operation
3046becomes the backup value, so you can use this operation repeatedly
3047to switch between two values."
3048 (let* ((symbol (widget-value widget))
3049 (set (or (get symbol 'custom-set) 'set-default))
3050 (value (get symbol 'backup-value))
3051 (comment-widget (widget-get widget :comment-widget))
3052 (comment (widget-value comment-widget)))
3053 (if value
3054 (progn
3055 (custom-variable-backup-value widget)
25c6d447 3056 (custom-push-theme 'theme-value symbol 'user 'set value)
bde4f354
RS
3057 (condition-case nil
3058 (funcall set symbol (car value))
3059 (error nil)))
3060 (error "No backup value for %s" symbol))
5c2a252f 3061 (put symbol 'customized-value (list (custom-quote (car value))))
bde4f354
RS
3062 (put symbol 'variable-comment comment)
3063 (put symbol 'customized-variable-comment comment)
3064 (custom-variable-state-set widget)
3065 ;; This call will possibly make the comment invisible
3066 (custom-redraw widget)))
3067
12bafdaa
CY
3068;;; The `custom-visibility' Widget
3069
3070(define-widget 'custom-visibility 'visibility
3071 "Show or hide a documentation string."
3072 :button-face 'custom-visibility
3073 :pressed-face 'custom-visibility
3074 :mouse-face 'highlight
647f9993 3075 :pressed-face 'highlight
895123f5
CY
3076 :on-glyph nil
3077 :off-glyph nil)
12bafdaa
CY
3078
3079(defface custom-visibility
3080 '((t :height 0.8 :inherit link))
3081 "Face for the `custom-visibility' widget."
3082 :version "23.1"
3083 :group 'custom-faces)
3084
d543e20b
PA
3085;;; The `custom-face-edit' Widget.
3086
3087(define-widget 'custom-face-edit 'checklist
587faadd
CY
3088 "Widget for editing face attributes.
3089The following properties have special meanings for this widget:
3090
3091:value is a plist of face attributes.
3092
3093:default-face-attributes, if non-nil, is a plist of defaults for
3094face attributes (as specified by a `default' defface entry)."
61328d7c
CY
3095 :format "%v"
3096 :extra-offset 3
d3d4df42 3097 :button-args '(:help-echo "Control whether this attribute has any effect.")
d75fa08f
RS
3098 :value-to-internal 'custom-face-edit-fix-value
3099 :match (lambda (widget value)
ee1f522d 3100 (widget-checklist-match widget
d75fa08f 3101 (custom-face-edit-fix-value widget value)))
61328d7c 3102 :value-create 'custom-face-edit-value-create
3ea051cb 3103 :convert-widget 'custom-face-edit-convert-widget
d543e20b 3104 :args (mapcar (lambda (att)
61328d7c 3105 (list 'group :inline t
d543e20b 3106 :sibling-args (widget-get (nth 1 att) :sibling-args)
d3d4df42 3107 (list 'const :format "" :value (nth 0 att))
d543e20b
PA
3108 (nth 1 att)))
3109 custom-face-attributes))
3110
61328d7c 3111(defun custom-face-edit-value-create (widget)
587faadd
CY
3112 (let* ((alist (widget-checklist-match-find
3113 widget (widget-get widget :value)))
61328d7c
CY
3114 (args (widget-get widget :args))
3115 (show-all (widget-get widget :show-all-attributes))
587faadd
CY
3116 (buttons (widget-get widget :buttons))
3117 (defaults (widget-checklist-match-find
3118 widget
3119 (widget-get widget :default-face-attributes)))
61328d7c
CY
3120 entry)
3121 (unless (looking-back "^ *")
3122 (insert ?\n))
3123 (insert-char ?\s (widget-get widget :extra-offset))
587faadd 3124 (if (or alist defaults show-all)
61328d7c 3125 (dolist (prop args)
587faadd
CY
3126 (setq entry (or (assq prop alist)
3127 (assq prop defaults)))
61328d7c
CY
3128 (if (or entry show-all)
3129 (widget-checklist-add-item widget prop entry)))
3130 (insert (propertize "-- Empty face --" 'face 'shadow) ?\n))
3131 (let ((indent (widget-get widget :indent)))
3132 (if indent (insert-char ?\s (widget-get widget :indent))))
3133 (push (widget-create-child-and-convert
3134 widget 'visibility
3135 :help-echo "Show or hide all face attributes."
3136 :button-face 'custom-visibility
3137 :pressed-face 'custom-visibility
3138 :mouse-face 'highlight
3139 :on "Hide Unused Attributes" :off "Show All Attributes"
895123f5 3140 :on-glyph nil :off-glyph nil
61328d7c
CY
3141 :always-active t
3142 :action 'custom-face-edit-value-visibility-action
3143 show-all)
3144 buttons)
3145 (insert ?\n)
3146 (widget-put widget :buttons buttons)
3147 (widget-put widget :children (nreverse (widget-get widget :children)))))
3148
06b60517 3149(defun custom-face-edit-value-visibility-action (widget &rest _ignore)
61328d7c
CY
3150 ;; Toggle hiding of face attributes.
3151 (let ((parent (widget-get widget :parent)))
3152 (widget-put parent :show-all-attributes
3153 (not (widget-get parent :show-all-attributes)))
3154 (custom-redraw parent)))
3155
06b60517 3156(defun custom-face-edit-fix-value (_widget value)
0bbe869a
AS
3157 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3158Also change :reverse-video to :inverse-video."
05d22d02 3159 (custom-fix-face-spec value))
d75fa08f 3160
3ea051cb
MB
3161(defun custom-face-edit-convert-widget (widget)
3162 "Convert :args as widget types in WIDGET."
3163 (widget-put
3164 widget
3165 :args (mapcar (lambda (arg)
3166 (widget-convert arg
3167 :deactivate 'custom-face-edit-deactivate
3168 :activate 'custom-face-edit-activate
3169 :delete 'custom-face-edit-delete))
3170 (widget-get widget :args)))
3171 widget)
3172
587faadd
CY
3173(defconst custom-face-edit (widget-convert 'custom-face-edit)
3174 "Converted version of the `custom-face-edit' widget.")
3175
3ea051cb
MB
3176(defun custom-face-edit-deactivate (widget)
3177 "Make face widget WIDGET inactive for user modifications."
3178 (unless (widget-get widget :inactive)
3179 (let ((tag (custom-face-edit-attribute-tag widget))
3180 (from (copy-marker (widget-get widget :from)))
3ea051cb
MB
3181 (value (widget-value widget))
3182 (inhibit-read-only t)
3183 (inhibit-modification-hooks t))
3184 (save-excursion
3185 (goto-char from)
3186 (widget-default-delete widget)
61328d7c 3187 (insert tag ": " (propertize "--" 'face 'shadow) "\n")
3ea051cb
MB
3188 (widget-put widget :inactive
3189 (cons value (cons from (- (point) from))))))))
3190
3191(defun custom-face-edit-activate (widget)
47fdaab8 3192 "Make face widget WIDGET active for user modifications."
3ea051cb
MB
3193 (let ((inactive (widget-get widget :inactive))
3194 (inhibit-read-only t)
3195 (inhibit-modification-hooks t))
3196 (when (consp inactive)
3197 (save-excursion
3198 (goto-char (car (cdr inactive)))
3199 (delete-region (point) (+ (point) (cdr (cdr inactive))))
3200 (widget-put widget :inactive nil)
3201 (widget-apply widget :create)
3202 (widget-value-set widget (car inactive))
3203 (widget-setup)))))
3204
3205(defun custom-face-edit-delete (widget)
3127aa13 3206 "Remove WIDGET from the buffer."
3ea051cb
MB
3207 (let ((inactive (widget-get widget :inactive))
3208 (inhibit-read-only t)
3209 (inhibit-modification-hooks t))
3210 (if (not inactive)
3211 ;; Widget is alive, we don't have to do anything special
3212 (widget-default-delete widget)
e9a452d9 3213 ;; WIDGET is already deleted because we did so to deactivate it;
3ea051cb
MB
3214 ;; now just get rid of the label we put in its place.
3215 (delete-region (car (cdr inactive))
3216 (+ (car (cdr inactive)) (cdr (cdr inactive))))
3217 (widget-put widget :inactive nil))))
ee1f522d 3218
3ea051cb
MB
3219
3220(defun custom-face-edit-attribute-tag (widget)
6cda144f 3221 "Return the first :tag property in WIDGET or one of its children."
3ea051cb
MB
3222 (let ((tag (widget-get widget :tag)))
3223 (or (and (not (equal tag "")) tag)
3224 (let ((children (widget-get widget :children)))
3225 (while (and (null tag) children)
3226 (setq tag (custom-face-edit-attribute-tag (pop children))))
3227 tag))))
3228
d543e20b
PA
3229;;; The `custom-display' Widget.
3230
3231(define-widget 'custom-display 'menu-choice
3232 "Select a display type."
3233 :tag "Display"
3234 :value t
3235 :help-echo "Specify frames where the face attributes should be used."
3236 :args '((const :tag "all" t)
b9afd6dd 3237 (const :tag "defaults" default)
d543e20b 3238 (checklist
4aab9006 3239 :tag "specific display"
d543e20b
PA
3240 :offset 0
3241 :extra-offset 9
3242 :args ((group :sibling-args (:help-echo "\
3243Only match the specified window systems.")
3244 (const :format "Type: "
3245 type)
3246 (checklist :inline t
3247 :offset 0
3248 (const :format "X "
3249 :sibling-args (:help-echo "\
3250The X11 Window System.")
3251 x)
3252 (const :format "PM "
3253 :sibling-args (:help-echo "\
3254OS/2 Presentation Manager.")
3255 pm)
b97aca27 3256 (const :format "W32 "
d543e20b 3257 :sibling-args (:help-echo "\
b97aca27
GV
3258Windows NT/9X.")
3259 w32)
edfda783
AR
3260 (const :format "NS "
3261 :sibling-args (:help-echo "\
3262GNUstep or Macintosh OS Cocoa interface.")
3263 ns)
d543e20b
PA
3264 (const :format "DOS "
3265 :sibling-args (:help-echo "\
3266Plain MS-DOS.")
3267 pc)
3268 (const :format "TTY%n"
3269 :sibling-args (:help-echo "\
3270Plain text terminals.")
3271 tty)))
3272 (group :sibling-args (:help-echo "\
3273Only match the frames with the specified color support.")
3274 (const :format "Class: "
3275 class)
3276 (checklist :inline t
3277 :offset 0
3278 (const :format "Color "
3279 :sibling-args (:help-echo "\
3280Match color frames.")
3281 color)
3282 (const :format "Grayscale "
3283 :sibling-args (:help-echo "\
3284Match grayscale frames.")
3285 grayscale)
3286 (const :format "Monochrome%n"
3287 :sibling-args (:help-echo "\
3288Match frames with no color support.")
3289 mono)))
3290 (group :sibling-args (:help-echo "\
c4d9734c
JL
3291The minimum number of colors the frame should support.")
3292 (const :format "" min-colors)
3293 (integer :tag "Minimum number of colors" ))
3294 (group :sibling-args (:help-echo "\
d543e20b
PA
3295Only match frames with the specified intensity.")
3296 (const :format "\
3297Background brightness: "
3298 background)
3299 (checklist :inline t
3300 :offset 0
3301 (const :format "Light "
3302 :sibling-args (:help-echo "\
3303Match frames with light backgrounds.")
3304 light)
3305 (const :format "Dark\n"
3306 :sibling-args (:help-echo "\
3307Match frames with dark backgrounds.")
2b32d1a7
MB
3308 dark)))
3309 (group :sibling-args (:help-echo "\
3310Only match frames that support the specified face attributes.")
3311 (const :format "Supports attributes:" supports)
4abe16b5 3312 (custom-face-edit :inline t :format "%n%v"))))))
d543e20b
PA
3313
3314;;; The `custom-face' Widget.
3315
d478e69d 3316(defface custom-face-tag
01b38d61 3317 `((t :inherit custom-variable-tag))
d543e20b 3318 "Face used for face tags."
bd042c03 3319 :group 'custom-faces)
c4f6e489 3320(define-obsolete-face-alias 'custom-face-tag-face 'custom-face-tag "22.1")
d543e20b 3321
d64478da
KH
3322(defcustom custom-face-default-form 'selected
3323 "Default form of displaying face definition."
3324 :type '(choice (const all)
3325 (const selected)
3326 (const lisp))
cd32a7ba
DN
3327 :group 'custom-buffer
3328 :version "20.3")
d64478da 3329
d543e20b 3330(define-widget 'custom-face 'custom
61328d7c 3331 "Widget for customizing a face.
61328d7c
CY
3332The following properties have special meanings for this widget:
3333
587faadd
CY
3334:value is the face name (a symbol).
3335
61328d7c
CY
3336:custom-form should be a symbol describing how to display and
3337 edit the face attributes---either `selected' (attributes for
3338 selected display only), `all' (all attributes), `lisp' (as a
3339 Lisp sexp), or `mismatch' (should not happen); if nil, use
587faadd
CY
3340 the return value of `custom-face-default-form'.
3341
647bc502
CY
3342:custom-style describes the widget interface style; nil is the
3343 default style, while `simple' means a simpler interface that
3344 inhibits the magic custom-state widget.
da16abfc
CY
3345
3346:sample-indent, if non-nil, is the number of columns to which to
3347 indent the face sample (an integer).
587faadd 3348
da16abfc 3349:shown-value, if non-nil, is the face spec to display as the value
647bc502 3350 of the widget, instead of the current face spec."
ee108e88 3351 :sample-face 'custom-face-tag
d543e20b 3352 :help-echo "Set or reset this face."
23c0fb21 3353 :documentation-property #'face-doc-string
d543e20b
PA
3354 :value-create 'custom-face-value-create
3355 :action 'custom-face-action
9097aeb7 3356 :custom-category 'face
61328d7c 3357 :custom-form nil
d543e20b 3358 :custom-set 'custom-face-set
5ae87ed4 3359 :custom-mark-to-save 'custom-face-mark-to-save
d543e20b
PA
3360 :custom-reset-current 'custom-redraw
3361 :custom-reset-saved 'custom-face-reset-saved
25ac13b5 3362 :custom-reset-standard 'custom-face-reset-standard
5ae87ed4 3363 :custom-mark-to-reset-standard 'custom-face-mark-to-reset-standard
4f985043 3364 :custom-standard-value 'custom-face-standard-value
5ae87ed4 3365 :custom-state-set-and-redraw 'custom-face-state-set-and-redraw
d543e20b
PA
3366 :custom-menu 'custom-face-menu-create)
3367
d3d4df42 3368(define-widget 'custom-face-all 'editable-list
d543e20b
PA
3369 "An editable list of display specifications and attributes."
3370 :entry-format "%i %d %v"
3371 :insert-button-args '(:help-echo "Insert new display specification here.")
3372 :append-button-args '(:help-echo "Append new display specification here.")
3373 :delete-button-args '(:help-echo "Delete this display specification.")
3374 :args '((group :format "%v" custom-display custom-face-edit)))
3375
3376(defconst custom-face-all (widget-convert 'custom-face-all)
3377 "Converted version of the `custom-face-all' widget.")
3378
3ea051cb 3379(defun custom-filter-face-spec (spec filter-index &optional default-filter)
f5b50baa
MB
3380 "Return a canonicalized version of SPEC using.
3381FILTER-INDEX is the index in the entry for each attribute in
3382`custom-face-attributes' at which the appropriate filter function can be
3383found, and DEFAULT-FILTER is the filter to apply for attributes that
3384don't specify one."
3385 (mapcar (lambda (entry)
3386 ;; Filter a single face-spec entry
3387 (let ((tests (car entry))
3388 (unfiltered-attrs
3389 ;; Handle both old- and new-style attribute syntax
3390 (if (listp (car (cdr entry)))
3391 (car (cdr entry))
3392 (cdr entry)))
3393 (filtered-attrs nil))
3394 ;; Filter each face attribute
3395 (while unfiltered-attrs
3396 (let* ((attr (pop unfiltered-attrs))
3397 (pre-filtered-value (pop unfiltered-attrs))
3398 (filter
3399 (or (nth filter-index (assq attr custom-face-attributes))
3400 default-filter))
3401 (filtered-value
3402 (if filter
3403 (funcall filter pre-filtered-value)
3404 pre-filtered-value)))
3405 (push filtered-value filtered-attrs)
3406 (push attr filtered-attrs)))
3407 ;;
3408 (list tests filtered-attrs)))
3409 spec))
3410
3411(defun custom-pre-filter-face-spec (spec)
3412 "Return SPEC changed as necessary for editing by the face customization widget.
3413SPEC must be a full face spec."
3ea051cb 3414 (custom-filter-face-spec spec 2))
f5b50baa
MB
3415
3416(defun custom-post-filter-face-spec (spec)
3417 "Return the customized SPEC in a form suitable for setting the face."
3ea051cb 3418 (custom-filter-face-spec spec 3))
f5b50baa 3419
76c16af8
CY
3420(defun custom-face-widget-to-spec (widget)
3421 "Return a face spec corresponding to WIDGET.
3422WIDGET should be a `custom-face' widget."
3423 (unless (eq (widget-type widget) 'custom-face)
3424 (error "Invalid widget"))
3425 (let ((child (car (widget-get widget :children))))
3426 (custom-post-filter-face-spec
3427 (if (eq (widget-type child) 'custom-face-edit)
3428 `((t ,(widget-value child)))
3429 (widget-value child)))))
3430
3431(defun custom-face-get-current-spec (face)
3432 (let ((spec (or (get face 'customized-face)
3433 (get face 'saved-face)
3434 (get face 'face-defface-spec)
3435 ;; Attempt to construct it.
3436 `((t ,(custom-face-attributes-get
3437 face (selected-frame)))))))
3438 ;; If the user has changed this face in some other way,
3439 ;; edit it as the user has specified it.
3440 (if (not (face-spec-match-p face spec (selected-frame)))
3441 (setq spec `((t ,(face-attr-construct face (selected-frame))))))
3442 (custom-pre-filter-face-spec spec)))
3443
06b60517 3444(defun custom-toggle-hide-face (visibility-widget &rest _ignore)
647bc502
CY
3445 "Toggle the visibility of a `custom-face' parent widget.
3446By default, this signals an error if the parent has unsaved
3447changes. If the parent has a `simple' :custom-style property,
3448the present value is saved to its :shown-value property instead."
3449 (let ((widget (widget-get visibility-widget :parent)))
3450 (unless (eq (widget-type widget) 'custom-face)
3451 (error "Invalid widget type"))
3452 (custom-load-widget widget)
3453 (let ((state (widget-get widget :custom-state)))
3454 (if (eq state 'hidden)
3455 (widget-put widget :custom-state 'unknown)
3456 ;; In normal interface, widget can't be hidden if modified.
3457 (when (memq state '(invalid modified set))
3458 (if (eq (widget-get widget :custom-style) 'simple)
3459 (widget-put widget :shown-value
3460 (custom-face-widget-to-spec widget))
3461 (error "There are unsaved changes")))
3462 (widget-put widget :documentation-shown nil)
3463 (widget-put widget :custom-state 'hidden))
3464 (custom-redraw widget)
3465 (widget-setup))))
3466
d543e20b 3467(defun custom-face-value-create (widget)
944c91b6 3468 "Create a list of the display specifications for WIDGET."
61328d7c
CY
3469 (let* ((buttons (widget-get widget :buttons))
3470 (symbol (widget-get widget :value))
3471 (tag (or (widget-get widget :tag)
3472 (prin1-to-string symbol)))
3473 (hiddenp (eq (widget-get widget :custom-state) 'hidden))
647bc502 3474 (style (widget-get widget :custom-style))
61328d7c
CY
3475 children)
3476
3477 (if (eq custom-buffer-style 'tree)
3478
3479 ;; Draw a tree-style `custom-face' widget
3480 (progn
3481 (insert (widget-get widget :custom-prefix)
3482 (if (widget-get widget :custom-last) " `--- " " |--- "))
3483 (push (widget-create-child-and-convert
3484 widget 'custom-browse-face-tag)
3485 buttons)
3486 (insert " " tag "\n")
3487 (widget-put widget :buttons buttons))
3488
3489 ;; Draw an ordinary `custom-face' widget
3490 (let ((opoint (point)))
3491 ;; Visibility indicator.
3492 (push (widget-create-child-and-convert
3493 widget 'custom-visibility
3494 :help-echo "Hide or show this face."
3495 :on "Hide" :off "Show"
895123f5 3496 :on-glyph "down" :off-glyph "right"
647bc502 3497 :action 'custom-toggle-hide-face
61328d7c
CY
3498 (not hiddenp))
3499 buttons)
3500 ;; Face name (tag).
3501 (insert " " tag)
3502 (widget-specify-sample widget opoint (point)))
3503 (insert
3504 (cond ((eq custom-buffer-style 'face) " ")
3505 ((string-match "face\\'" tag) ":")
3506 (t " face: ")))
3507
3508 ;; Face sample.
587faadd
CY
3509 (let ((sample-indent (widget-get widget :sample-indent))
3510 (indent-tabs-mode nil))
3511 (and sample-indent
3512 (<= (current-column) sample-indent)
3513 (indent-to-column sample-indent)))
61328d7c
CY
3514 (push (widget-create-child-and-convert
3515 widget 'item
da16abfc
CY
3516 :format "[%{%t%}]"
3517 :sample-face (let ((spec (widget-get widget :shown-value)))
3518 (if spec (face-spec-choose spec) symbol))
3519 :tag "sample")
61328d7c 3520 buttons)
61328d7c 3521 (insert "\n")
da16abfc
CY
3522
3523 ;; Magic.
647bc502 3524 (unless (eq (widget-get widget :custom-style) 'simple)
da16abfc
CY
3525 (let ((magic (widget-create-child-and-convert
3526 widget 'custom-magic nil)))
3527 (widget-put widget :custom-magic magic)
3528 (push magic buttons)))
61328d7c
CY
3529
3530 ;; Update buttons.
3531 (widget-put widget :buttons buttons)
3532
3533 ;; Insert documentation.
647bc502 3534 (unless (and hiddenp (eq style 'simple))
587faadd
CY
3535 (widget-put widget :documentation-indent 3)
3536 (widget-add-documentation-string-button
3537 widget :visibility-widget 'custom-visibility)
3538 ;; The comment field
3539 (unless hiddenp
3540 (let* ((comment (get symbol 'face-comment))
3541 (comment-widget
3542 (widget-create-child-and-convert
3543 widget 'custom-comment
3544 :parent widget
3545 :value (or comment ""))))
3546 (widget-put widget :comment-widget comment-widget)
3547 (push comment-widget children))))
61328d7c
CY
3548
3549 ;; Editor.
3550 (unless (eq (preceding-char) ?\n)
3551 (insert "\n"))
3552 (unless hiddenp
3553 (custom-load-widget widget)
3554 (unless (widget-get widget :custom-form)
3555 (widget-put widget :custom-form custom-face-default-form))
3556
da16abfc
CY
3557 (let* ((spec (or (widget-get widget :shown-value)
3558 (custom-face-get-current-spec symbol)))
61328d7c
CY
3559 (form (widget-get widget :custom-form))
3560 (indent (widget-get widget :indent))
587faadd 3561 face-alist face-entry spec-default spec-match editor)
61328d7c 3562
587faadd
CY
3563 ;; Find a display in SPEC matching the selected display.
3564 ;; This will use the usual face customization interface.
3565 (setq face-alist spec)
3566 (when (eq (car-safe (car-safe face-alist)) 'default)
3567 (setq spec-default (pop face-alist)))
3568
3569 (while (and face-alist (listp face-alist) (null spec-match))
3570 (setq face-entry (car face-alist))
3571 (and (listp face-entry)
3572 (face-spec-set-match-display (car face-entry)
3573 (selected-frame))
3574 (widget-apply custom-face-edit :match (cadr face-entry))
3575 (setq spec-match face-entry))
3576 (setq face-alist (cdr face-alist)))
3577
3578 ;; Insert the appropriate editing widget.
3579 (setq editor
3580 (cond
3581 ((and (eq form 'selected)
3582 (or spec-match spec-default))
3583 (when indent (insert-char ?\s indent))
3584 (widget-create-child-and-convert
3585 widget 'custom-face-edit
3586 :value (cadr spec-match)
3587 :default-face-attributes (cadr spec-default)))
3588 ((and (not (eq form 'lisp))
3589 (widget-apply custom-face-all :match spec))
3590 (widget-create-child-and-convert
3591 widget 'custom-face-all :value spec))
3592 (t
3593 (when indent
3594 (insert-char ?\s indent))
3595 (widget-create-child-and-convert
3596 widget 'sexp :value spec))))
61328d7c 3597 (custom-face-state-set widget)
587faadd 3598 (push editor children)
61328d7c 3599 (widget-put widget :children children))))))
d543e20b 3600
d3d4df42 3601(defvar custom-face-menu
70482877 3602 `(("Set for Current Session" custom-face-set)
9b5007e7 3603 ,@(when (or custom-file init-file-user)
633bb8a9 3604 '(("Save for Future Sessions" custom-face-save)))
70482877
LT
3605 ("Undo Edits" custom-redraw
3606 (lambda (widget)
3607 (memq (widget-get widget :custom-state) '(modified changed))))
cf20dee0 3608 ("Revert This Session's Customization" custom-face-reset-saved
0c731046 3609 (lambda (widget)
c2d1019e 3610 (memq (widget-get widget :custom-state) '(modified set changed))))
9b5007e7 3611 ,@(when (or custom-file init-file-user)
70482877 3612 '(("Erase Customization" custom-face-reset-standard
73e60f53
CY
3613 (lambda (widget)
3614 (get (widget-value widget) 'face-defface-spec)))))
eaa99205 3615 ("---" ignore ignore)
70482877
LT
3616 ("Add Comment" custom-comment-show custom-comment-invisible-p)
3617 ("---" ignore ignore)
3618 ("For Current Display" custom-face-edit-selected
eaa99205
CY
3619 (lambda (widget)
3620 (not (eq (widget-get widget :custom-form) 'selected))))
70482877
LT
3621 ("For All Kinds of Displays" custom-face-edit-all
3622 (lambda (widget)
3623 (not (eq (widget-get widget :custom-form) 'all))))
3624 ("Show Lisp Expression" custom-face-edit-lisp
eaa99205
CY
3625 (lambda (widget)
3626 (not (eq (widget-get widget :custom-form) 'lisp)))))
d543e20b 3627 "Alist of actions for the `custom-face' widget.
6d528fc5
PA
3628Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3629the menu entry, ACTION is the function to call on the widget when the
3630menu is selected, and FILTER is a predicate which takes a `custom-face'
3631widget as an argument, and returns non-nil if ACTION is valid on that
19d63704 3632widget. If FILTER is nil, ACTION is always valid.")
d543e20b
PA
3633
3634(defun custom-face-edit-selected (widget)
3635 "Edit selected attributes of the value of WIDGET."
3636 (widget-put widget :custom-state 'unknown)
3637 (widget-put widget :custom-form 'selected)
3638 (custom-redraw widget))
3639
3640(defun custom-face-edit-all (widget)
3641 "Edit all attributes of the value of WIDGET."
3642 (widget-put widget :custom-state 'unknown)
3643 (widget-put widget :custom-form 'all)
3644 (custom-redraw widget))
3645
3646(defun custom-face-edit-lisp (widget)
2365594b 3647 "Edit the Lisp representation of the value of WIDGET."
d543e20b
PA
3648 (widget-put widget :custom-state 'unknown)
3649 (widget-put widget :custom-form 'lisp)
3650 (custom-redraw widget))
3651
76c16af8
CY
3652(defun custom-face-state (face)
3653 "Return the current state of the face FACE.
3654This is one of `set', `saved', `changed', `themed', or `rogue'."
3655 (let* ((comment (get face 'face-comment))
a4992f73 3656 (state
76c16af8
CY
3657 (cond
3658 ((or (get face 'customized-face)
3659 (get face 'customized-face-comment))
3660 (if (equal (get face 'customized-face-comment) comment)
3661 'set
3662 'changed))
3663 ((or (get face 'saved-face)
3664 (get face 'saved-face-comment))
c2d1019e
CY
3665 (cond ((not (equal (get face 'saved-face-comment) comment))
3666 'changed)
3667 ((eq 'user (caar (get face 'theme-face)))
3668 'saved)
3669 ((eq 'changed (caar (get face 'theme-face)))
3670 'changed)
3671 (t 'themed)))
76c16af8 3672 ((get face 'face-defface-spec)
c2d1019e
CY
3673 (cond (comment 'changed)
3674 ((get face 'theme-face) 'themed)
3675 (t 'standard)))
76c16af8
CY
3676 (t 'rogue))))
3677 ;; If the user called set-face-attribute to change the default for
3678 ;; new frames, this face is "set outside of Customize".
a4992f73 3679 (if (and (not (eq state 'rogue))
76c16af8
CY
3680 (get face 'face-modified))
3681 'changed
3682 state)))
3683
3684(defun custom-face-state-set (widget)
3685 "Set the state of WIDGET."
3686 (widget-put widget :custom-state
3687 (custom-face-state (widget-value widget))))
d543e20b
PA
3688
3689(defun custom-face-action (widget &optional event)
3690 "Show the menu for `custom-face' WIDGET.
3691Optional EVENT is the location for the menu."
3692 (if (eq (widget-get widget :custom-state) 'hidden)
6d528fc5 3693 (custom-toggle-hide widget)
d543e20b
PA
3694 (let* ((completion-ignore-case t)
3695 (symbol (widget-get widget :value))
25ac13b5
PA
3696 (answer (widget-choose (concat "Operation on "
3697 (custom-unlispify-tag-name symbol))
6d528fc5
PA
3698 (custom-menu-filter custom-face-menu
3699 widget)
3700 event)))
d543e20b
PA
3701 (if answer
3702 (funcall answer widget)))))
3703
3704(defun custom-face-set (widget)
3705 "Make the face attributes in WIDGET take effect."
3706 (let* ((symbol (widget-value widget))
76c16af8 3707 (value (custom-face-widget-to-spec widget))
d3d4df42
DL
3708 (comment-widget (widget-get widget :comment-widget))
3709 (comment (widget-value comment-widget)))
3710 (when (equal comment "")
3711 (setq comment nil)
3712 ;; Make the comment invisible by hand if it's empty
164cfaeb 3713 (custom-comment-hide comment-widget))
d543e20b 3714 (put symbol 'customized-face value)
e02577b7 3715 (custom-push-theme 'theme-face symbol 'user 'set value)
f5b50baa 3716 (if (face-spec-choose value)
d50e9d5b 3717 (face-spec-set symbol value t)
f5b50baa
MB
3718 ;; face-set-spec ignores empty attribute lists, so just give it
3719 ;; something harmless instead.
d50e9d5b 3720 (face-spec-set symbol '((t :foreground unspecified)) t))
d3d4df42
DL
3721 (put symbol 'customized-face-comment comment)
3722 (put symbol 'face-comment comment)
d543e20b
PA
3723 (custom-face-state-set widget)
3724 (custom-redraw-magic widget)))
3725
5ae87ed4
MR
3726(defun custom-face-mark-to-save (widget)
3727 "Mark for saving the face edited by WIDGET."
d543e20b 3728 (let* ((symbol (widget-value widget))
76c16af8 3729 (value (custom-face-widget-to-spec widget))
d3d4df42
DL
3730 (comment-widget (widget-get widget :comment-widget))
3731 (comment (widget-value comment-widget)))
3732 (when (equal comment "")
3733 (setq comment nil)
3734 ;; Make the comment invisible by hand if it's empty
164cfaeb 3735 (custom-comment-hide comment-widget))
b76747af 3736 (custom-push-theme 'theme-face symbol 'user 'set value)
e475612a 3737 (if (face-spec-choose value)
d50e9d5b 3738 (face-spec-set symbol value t)
e475612a
MB
3739 ;; face-set-spec ignores empty attribute lists, so just give it
3740 ;; something harmless instead.
d50e9d5b 3741 (face-spec-set symbol '((t :foreground unspecified)) t))
4f985043
RS
3742 (unless (eq (widget-get widget :custom-state) 'standard)
3743 (put symbol 'saved-face value))
d543e20b 3744 (put symbol 'customized-face nil)
d3d4df42
DL
3745 (put symbol 'face-comment comment)
3746 (put symbol 'customized-face-comment nil)
5ae87ed4
MR
3747 (put symbol 'saved-face-comment comment)))
3748
3749(defsubst custom-face-state-set-and-redraw (widget)
3750 "Set state of face widget WIDGET and redraw with current settings."
3751 (custom-face-state-set widget)
3752 (custom-redraw-magic widget))
3753
3754(defun custom-face-save (widget)
3755 "Save the face edited by WIDGET."
3756 (custom-face-mark-to-save widget)
3757 (custom-save-all)
3758 (custom-face-state-set-and-redraw widget))
d543e20b 3759
633bb8a9
LT
3760;; For backward compatibility.
3761(define-obsolete-function-alias 'custom-face-save-command 'custom-face-save
3762 "22.1")
3763
d543e20b 3764(defun custom-face-reset-saved (widget)
c2d1019e
CY
3765 "Restore WIDGET to the face's default attributes.
3766If there is a saved face, restore it; otherwise reset to the
3767uncustomized (themed or standard) face."
3768 (let* ((face (widget-value widget))
d543e20b 3769 (child (car (widget-get widget :children)))
c2d1019e
CY
3770 (saved-face (get face 'saved-face))
3771 (comment (get face 'saved-face-comment))
d3d4df42 3772 (comment-widget (widget-get widget :comment-widget)))
c2d1019e
CY
3773 (put face 'customized-face nil)
3774 (put face 'customized-face-comment nil)
3775 (custom-push-theme 'theme-face face 'user
3776 (if saved-face 'set 'reset)
3777 saved-face)
3778 (face-spec-set face saved-face t)
3779 (put face 'face-comment comment)
3780 (widget-value-set child saved-face)
d3d4df42
DL
3781 ;; This call manages the comment visibility
3782 (widget-value-set comment-widget (or comment ""))
d543e20b 3783 (custom-face-state-set widget)
c2d1019e 3784 (custom-redraw widget)))
d543e20b 3785
4f985043
RS
3786(defun custom-face-standard-value (widget)
3787 (get (widget-value widget) 'face-defface-spec))
3788
5ae87ed4
MR
3789(defun custom-face-mark-to-reset-standard (widget)
3790 "Restore widget WIDGET to the face's standard attribute values.
3791If `custom-reset-standard-faces-list' is nil, save, reset and
3792redraw the widget immediately."
d543e20b
PA
3793 (let* ((symbol (widget-value widget))
3794 (child (car (widget-get widget :children)))
d3d4df42
DL
3795 (value (get symbol 'face-defface-spec))
3796 (comment-widget (widget-get widget :comment-widget)))
d543e20b 3797 (unless value
5dd0cad0 3798 (error "No standard setting for this face"))
d543e20b 3799 (put symbol 'customized-face nil)
d3d4df42 3800 (put symbol 'customized-face-comment nil)
d358aa10 3801 (custom-push-theme 'theme-face symbol 'user 'reset)
d50e9d5b 3802 (face-spec-set symbol value t)
25c6d447 3803 (custom-theme-recalc-face symbol)
5ae87ed4
MR
3804 (if (and custom-reset-standard-faces-list
3805 (or (get symbol 'saved-face) (get symbol 'saved-face-comment)))
3806 ;; Do this later.
3807 (progn
3808 (put symbol 'saved-face nil)
3809 (put symbol 'saved-face-comment nil)
3810 ;; Append this to `custom-reset-standard-faces-list' and have
3811 ;; `custom-reset-standard-save-and-update' save setting to the
3812 ;; file, update the widget's state, and redraw it.
3813 (setq custom-reset-standard-faces-list
3814 (cons widget custom-reset-standard-faces-list)))
3815 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3816 (put symbol 'saved-face nil)
3817 (put symbol 'saved-face-comment nil)
3818 (custom-save-all))
3819 (put symbol 'face-comment nil)
3820 (widget-value-set child
3821 (custom-pre-filter-face-spec
3822 (list (list t (custom-face-attributes-get
3823 symbol nil)))))
3824 ;; This call manages the comment visibility
3825 (widget-value-set comment-widget "")
3826 (custom-face-state-set widget)
3827 (custom-redraw-magic widget))))
3828
3829(defun custom-face-reset-standard (widget)
3830 "Restore WIDGET to the face's standard attribute values.
3831This operation eliminates any saved attributes for the face,
3832restoring it to the state of a face that has never been customized."
3833 (let (custom-reset-standard-faces-list)
3834 (custom-face-mark-to-reset-standard widget)))
d543e20b
PA
3835
3836;;; The `face' Widget.
3837
1833b7b3
RS
3838(defvar widget-face-prompt-value-history nil
3839 "History of input to `widget-face-prompt-value'.")
3840
0e739597
DP
3841(define-widget 'face 'symbol
3842 "A Lisp face name (with sample)."
49698bb7 3843 :format "%{%t%}: (%{sample%}) %v"
0e739597
DP
3844 :tag "Face"
3845 :value 'default
3846 :sample-face-get 'widget-face-sample-face-get
3847 :notify 'widget-face-notify
06b60517 3848 :match (lambda (_widget value) (facep value))
bcd70d97
SM
3849 :completions (apply-partially #'completion-table-with-predicate
3850 obarray #'facep 'strict)
1833b7b3
RS
3851 :prompt-match 'facep
3852 :prompt-history 'widget-face-prompt-value-history
1833b7b3
RS
3853 :validate (lambda (widget)
3854 (unless (facep (widget-value widget))
0e739597
DP
3855 (widget-put widget
3856 :error (format "Invalid face: %S"
3857 (widget-value widget)))
3858 widget)))
3859
3860(defun widget-face-sample-face-get (widget)
3861 (let ((value (widget-value widget)))
3862 (if (facep value)
3863 value
3864 'default)))
3865
3866(defun widget-face-notify (widget child &optional event)
3867 "Update the sample, and notify the parent."
3868 (overlay-put (widget-get widget :sample-overlay)
3869 'face (widget-apply widget :sample-face-get))
3870 (widget-default-notify widget child event))
1833b7b3 3871
d543e20b
PA
3872
3873;;; The `hook' Widget.
3874
3875(define-widget 'hook 'list
c8c9333c 3876 "An Emacs Lisp hook."
06b60517 3877 :value-to-internal (lambda (_widget value)
5aa3f181 3878 (if (and value (symbolp value))
f985c5f7
PA
3879 (list value)
3880 value))
3881 :match (lambda (widget value)
3882 (or (symbolp value)
4743fc91 3883 (widget-group-match widget value)))
2365594b
DL
3884 ;; Avoid adding undefined functions to the hook, especially for
3885 ;; things like `find-file-hook' or even more basic ones, to avoid
3886 ;; chaos.
3887 :set (lambda (symbol value)
d4881668
SM
3888 (dolist (elt value)
3889 (if (fboundp elt)
3890 (add-hook symbol elt))))
d543e20b
PA
3891 :convert-widget 'custom-hook-convert-widget
3892 :tag "Hook")
3893
3894(defun custom-hook-convert-widget (widget)
3c708e98 3895 ;; Handle `:options'.
d543e20b 3896 (let* ((options (widget-get widget :options))
d3d4df42 3897 (other `(editable-list :inline t
d543e20b
PA
3898 :entry-format "%i %d%v"
3899 (function :format " %v")))
3900 (args (if options
3901 (list `(checklist :inline t
3902 ,@(mapcar (lambda (entry)
3903 `(function-item ,entry))
3904 options))
3905 other)
3906 (list other))))
3907 (widget-put widget :args args)
3908 widget))
3909
944c91b6
PA
3910;;; The `custom-group-link' Widget.
3911
3912(define-widget 'custom-group-link 'link
3913 "Show parent in other window when activated."
192e44fc
JL
3914 :button-face 'custom-link
3915 :mouse-face 'highlight
e1ec62a5 3916 :pressed-face 'highlight
b62c92bb 3917 :help-echo "Create customization buffer for this group."
f3093f77
CY
3918 :keymap custom-mode-link-map
3919 :follow-link 'mouse-face
944c91b6
PA
3920 :action 'custom-group-link-action)
3921
06b60517 3922(defun custom-group-link-action (widget &rest _ignore)
944c91b6
PA
3923 (customize-group (widget-value widget)))
3924
d543e20b
PA
3925;;; The `custom-group' Widget.
3926
b62c92bb 3927(defcustom custom-group-tag-faces nil
d543e20b
PA
3928 "Face used for group tags.
3929The first member is used for level 1 groups, the second for level 2,
d478e69d 3930and so forth. The remaining group tags are shown with `custom-group-tag'."
d543e20b 3931 :type '(repeat face)
bd042c03 3932 :group 'custom-faces)
d543e20b 3933
d478e69d 3934(defface custom-group-tag-1
16b20ed9
GM
3935 `((((class color)
3936 (background dark))
b5555381 3937 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
ea81d57e
DN
3938 (((min-colors 88) (class color)
3939 (background light))
3940 (:foreground "red1" :weight bold :height 1.2 :inherit variable-pitch))
16b20ed9
GM
3941 (((class color)
3942 (background light))
b5555381
RS
3943 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3944 (t (:weight bold)))
16b20ed9
GM
3945 "Face used for group tags."
3946 :group 'custom-faces)
c4f6e489 3947(define-obsolete-face-alias 'custom-group-tag-face-1 'custom-group-tag-1 "22.1")
16b20ed9 3948
d478e69d 3949(defface custom-group-tag
16b20ed9
GM
3950 `((((class color)
3951 (background dark))
9db1942d 3952 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
ea81d57e
DN
3953 (((min-colors 88) (class color)
3954 (background light))
9db1942d 3955 (:foreground "blue1" :weight bold :height 1.2 :inherit variable-pitch))
16b20ed9
GM
3956 (((class color)
3957 (background light))
9db1942d 3958 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
b5555381 3959 (t (:weight bold)))
d543e20b 3960 "Face used for low level group tags."
bd042c03 3961 :group 'custom-faces)
c4f6e489 3962(define-obsolete-face-alias 'custom-group-tag-face 'custom-group-tag "22.1")
d543e20b 3963
cf20dee0
CY
3964(defface custom-group-subtitle
3965 `((t (:weight bold)))
3966 "Face for the \"Subgroups:\" subtitle in Custom buffers."
3967 :group 'custom-faces)
3968
3969(defvar custom-group-doc-align-col 20)
3970
d543e20b
PA
3971(define-widget 'custom-group 'custom
3972 "Customize group."
944c91b6 3973 :format "%v"
d543e20b
PA
3974 :sample-face-get 'custom-group-sample-face-get
3975 :documentation-property 'group-documentation
3976 :help-echo "Set or reset all members of this group."
3977 :value-create 'custom-group-value-create
3978 :action 'custom-group-action
9097aeb7 3979 :custom-category 'group
d543e20b 3980 :custom-set 'custom-group-set
5ae87ed4 3981 :custom-mark-to-save 'custom-group-mark-to-save
d543e20b
PA
3982 :custom-reset-current 'custom-group-reset-current
3983 :custom-reset-saved 'custom-group-reset-saved
25ac13b5 3984 :custom-reset-standard 'custom-group-reset-standard
5ae87ed4
MR
3985 :custom-mark-to-reset-standard 'custom-group-mark-to-reset-standard
3986 :custom-state-set-and-redraw 'custom-group-state-set-and-redraw
d543e20b
PA
3987 :custom-menu 'custom-group-menu-create)
3988
3989(defun custom-group-sample-face-get (widget)
3990 ;; Use :sample-face.
3991 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
d478e69d 3992 'custom-group-tag))
d543e20b 3993
8691cfa7
RS
3994(define-widget 'custom-group-visibility 'visibility
3995 "An indicator and manipulator for hidden group contents."
3996 :create 'custom-group-visibility-create)
3997
3998(defun custom-group-visibility-create (widget)
3999 (let ((visible (widget-value widget)))
4000 (if visible
4001 (insert "--------")))
4002 (widget-default-create widget))
4003
4ee1cf9f
PA
4004(defun custom-group-members (symbol groups-only)
4005 "Return SYMBOL's custom group members.
4006If GROUPS-ONLY non-nil, return only those members that are groups."
4007 (if (not groups-only)
4008 (get symbol 'custom-group)
4009 (let (members)
4010 (dolist (entry (get symbol 'custom-group))
4011 (when (eq (nth 1 entry) 'custom-group)
4012 (push entry members)))
4013 (nreverse members))))
4014
d543e20b 4015(defun custom-group-value-create (widget)
944c91b6 4016 "Insert a customize group for WIDGET in the current buffer."
2de2cb02 4017 (unless (eq (widget-get widget :custom-state) 'hidden)
2ee398c4 4018 (custom-load-widget widget))
4ee1cf9f
PA
4019 (let* ((state (widget-get widget :custom-state))
4020 (level (widget-get widget :custom-level))
f985c5f7 4021 ;; (indent (widget-get widget :indent))
4ee1cf9f
PA
4022 (prefix (widget-get widget :custom-prefix))
4023 (buttons (widget-get widget :buttons))
4024 (tag (widget-get widget :tag))
4025 (symbol (widget-value widget))
4026 (members (custom-group-members symbol
4027 (and (eq custom-buffer-style 'tree)
c19aae89
MR
4028 custom-browse-only-groups)))
4029 (doc (widget-docstring widget)))
944c91b6 4030 (cond ((and (eq custom-buffer-style 'tree)
c953515e 4031 (eq state 'hidden)
4ee1cf9f 4032 (or members (custom-unloaded-widget-p widget)))
c953515e 4033 (custom-browse-insert-prefix prefix)
944c91b6 4034 (push (widget-create-child-and-convert
d3d4df42 4035 widget 'custom-browse-visibility
df816618 4036 :tag "+")
944c91b6
PA
4037 buttons)
4038 (insert "-- ")
4039 (push (widget-create-child-and-convert
c953515e 4040 widget 'custom-browse-group-tag)
944c91b6
PA
4041 buttons)
4042 (insert " " tag "\n")
4043 (widget-put widget :buttons buttons))
4044 ((and (eq custom-buffer-style 'tree)
4ee1cf9f 4045 (zerop (length members)))
c953515e 4046 (custom-browse-insert-prefix prefix)
da5ec617 4047 (insert "[ ]-- ")
d3d4df42 4048 (push (widget-create-child-and-convert
c953515e 4049 widget 'custom-browse-group-tag)
944c91b6
PA
4050 buttons)
4051 (insert " " tag "\n")
4052 (widget-put widget :buttons buttons))
4053 ((eq custom-buffer-style 'tree)
c953515e 4054 (custom-browse-insert-prefix prefix)
4ee1cf9f 4055 (if (zerop (length members))
d3d4df42 4056 (progn
c953515e 4057 (custom-browse-insert-prefix prefix)
da5ec617
PA
4058 (insert "[ ]-- ")
4059 ;; (widget-glyph-insert nil "[ ]" "empty")
4060 ;; (widget-glyph-insert nil "-- " "horizontal")
d3d4df42 4061 (push (widget-create-child-and-convert
c953515e 4062 widget 'custom-browse-group-tag)
944c91b6
PA
4063 buttons)
4064 (insert " " tag "\n")
4065 (widget-put widget :buttons buttons))
d3d4df42
DL
4066 (push (widget-create-child-and-convert
4067 widget 'custom-browse-visibility
da5ec617
PA
4068 ;; :tag-glyph "minus"
4069 :tag "-")
944c91b6 4070 buttons)
da5ec617
PA
4071 (insert "-\\ ")
4072 ;; (widget-glyph-insert nil "-\\ " "top")
d3d4df42 4073 (push (widget-create-child-and-convert
c953515e 4074 widget 'custom-browse-group-tag)
944c91b6
PA
4075 buttons)
4076 (insert " " tag "\n")
4077 (widget-put widget :buttons buttons)
4078 (message "Creating group...")
647f9993
CY
4079 (let* ((members (custom-sort-items
4080 members
4081 ;; Never sort the top-level custom group.
4082 (unless (eq symbol 'emacs)
4083 custom-browse-sort-alphabetically)
da5ec617 4084 custom-browse-order-groups))
944c91b6
PA
4085 (prefixes (widget-get widget :custom-prefixes))
4086 (custom-prefix-list (custom-prefix-add symbol prefixes))
944c91b6
PA
4087 (extra-prefix (if (widget-get widget :custom-last)
4088 " "
4089 " | "))
4090 (prefix (concat prefix extra-prefix))
4091 children entry)
4092 (while members
4093 (setq entry (car members)
4094 members (cdr members))
4ee1cf9f
PA
4095 (push (widget-create-child-and-convert
4096 widget (nth 1 entry)
4097 :group widget
4098 :tag (custom-unlispify-tag-name (nth 0 entry))
4099 :custom-prefixes custom-prefix-list
4100 :custom-level (1+ level)
4101 :custom-last (null members)
4102 :value (nth 0 entry)
4103 :custom-prefix prefix)
4104 children))
944c91b6
PA
4105 (widget-put widget :children (reverse children)))
4106 (message "Creating group...done")))
4107 ;; Nested style.
4108 ((eq state 'hidden)
4109 ;; Create level indicator.
944c91b6 4110 ;; Create tag.
944c91b6
PA
4111 (if (eq custom-buffer-style 'links)
4112 (push (widget-create-child-and-convert
d3d4df42 4113 widget 'custom-group-link
9db1942d 4114 :tag tag
944c91b6
PA
4115 symbol)
4116 buttons)
9db1942d
CY
4117 (insert-char ?\ (* custom-buffer-indent (1- level)))
4118 (insert "-- ")
d3d4df42 4119 (push (widget-create-child-and-convert
98d5aafe 4120 widget 'custom-group-visibility
944c91b6
PA
4121 :help-echo "Show members of this group."
4122 :action 'custom-toggle-parent
4123 (not (eq state 'hidden)))
4124 buttons))
cf20dee0
CY
4125 (if (>= (current-column) custom-group-doc-align-col)
4126 (insert " "))
944c91b6
PA
4127 ;; Create magic button.
4128 (let ((magic (widget-create-child-and-convert
4129 widget 'custom-magic nil)))
4130 (widget-put widget :custom-magic magic)
4131 (push magic buttons))
4132 ;; Update buttons.
4133 (widget-put widget :buttons buttons)
4134 ;; Insert documentation.
26c7b3ef 4135 (if (and (eq custom-buffer-style 'links) (> level 1))
cf20dee0
CY
4136 (widget-put widget :documentation-indent
4137 custom-group-doc-align-col))
12bafdaa
CY
4138 (widget-add-documentation-string-button
4139 widget :visibility-widget 'custom-visibility))
4140
944c91b6
PA
4141 ;; Nested style.
4142 (t ;Visible.
647f9993
CY
4143 ;; Draw a horizontal line (this works for both graphical
4144 ;; and text displays):
4145 (let ((p (point)))
4146 (insert "\n")
4147 (put-text-property p (1+ p) 'face '(:underline t))
4148 (overlay-put (make-overlay p (1+ p))
4149 'before-string
4150 (propertize "\n" 'face '(:underline t)
4151 'display '(space :align-to 999))))
4152
d377bee9 4153 ;; Add parent groups references above the group.
647f9993
CY
4154 (when (eq level 1)
4155 (if (custom-add-parent-links widget "Parent groups:")
4156 (insert "\n")))
944c91b6 4157 (insert-char ?\ (* custom-buffer-indent (1- level)))
944c91b6
PA
4158 ;; Create tag.
4159 (let ((start (point)))
9db1942d 4160 (insert tag " group: ")
944c91b6 4161 (widget-specify-sample widget start (point)))
1e3d9386
MR
4162 (cond
4163 ((not doc)
4164 (insert " Group definition missing. "))
4165 ((< (length doc) 50)
4166 (insert doc)))
944c91b6
PA
4167 ;; Create visibility indicator.
4168 (unless (eq custom-buffer-style 'links)
4169 (insert "--------")
d3d4df42 4170 (push (widget-create-child-and-convert
944c91b6
PA
4171 widget 'visibility
4172 :help-echo "Hide members of this group."
4173 :action 'custom-toggle-parent
4174 (not (eq state 'hidden)))
4175 buttons)
4176 (insert " "))
647f9993 4177 (insert "\n")
944c91b6
PA
4178 ;; Create magic button.
4179 (let ((magic (widget-create-child-and-convert
d3d4df42 4180 widget 'custom-magic
944c91b6
PA
4181 :indent 0
4182 nil)))
4183 (widget-put widget :custom-magic magic)
4184 (push magic buttons))
4185 ;; Update buttons.
4186 (widget-put widget :buttons buttons)
4187 ;; Insert documentation.
c19aae89
MR
4188 (when (and doc (>= (length doc) 50))
4189 (widget-add-documentation-string-button
4190 widget :visibility-widget 'custom-visibility))
12bafdaa 4191
d377bee9
RS
4192 ;; Parent groups.
4193 (if nil ;;; This should test that the buffer
4194 ;;; was not made to display a group.
4195 (when (eq level 1)
4196 (insert-char ?\ custom-buffer-indent)
4197 (custom-add-parent-links widget)))
d3d4df42 4198 (custom-add-see-also widget
944c91b6
PA
4199 (make-string (* custom-buffer-indent level)
4200 ?\ ))
4201 ;; Members.
4202 (message "Creating group...")
647f9993
CY
4203 (let* ((members (custom-sort-items
4204 members
4205 ;; Never sort the top-level custom group.
4206 (unless (eq symbol 'emacs)
4207 custom-buffer-sort-alphabetically)
4208 custom-buffer-order-groups))
944c91b6
PA
4209 (prefixes (widget-get widget :custom-prefixes))
4210 (custom-prefix-list (custom-prefix-add symbol prefixes))
647f9993 4211 (len (length members))
944c91b6 4212 (count 0)
647f9993
CY
4213 (reporter (make-progress-reporter
4214 "Creating group entries..." 0 len))
cf20dee0
CY
4215 (have-subtitle (and (not (eq symbol 'emacs))
4216 (eq custom-buffer-order-groups 'last)))
4217 prev-type
647f9993 4218 children)
cf20dee0
CY
4219
4220 (dolist (entry members)
4221 (unless (eq prev-type 'custom-group)
4222 (widget-insert "\n"))
4223 (progress-reporter-update reporter (setq count (1+ count)))
4224 (let ((sym (nth 0 entry))
4225 (type (nth 1 entry)))
4226 (when (and have-subtitle (eq type 'custom-group))
4227 (setq have-subtitle nil)
4228 (widget-insert
4229 (propertize "Subgroups:\n" 'face 'custom-group-subtitle)))
4230 (setq prev-type type)
4231 (push (widget-create-child-and-convert
4232 widget type
4233 :group widget
4234 :tag (custom-unlispify-tag-name sym)
4235 :custom-prefixes custom-prefix-list
4236 :custom-level (1+ level)
4237 :value sym)
4238 children)
4239 (unless (eq (preceding-char) ?\n)
4240 (widget-insert "\n"))))
4241
4242 (setq children (nreverse children))
fadbdfea 4243 (mapc 'custom-magic-reset children)
944c91b6
PA
4244 (widget-put widget :children children)
4245 (custom-group-state-update widget)
647f9993 4246 (progress-reporter-done reporter))
944c91b6 4247 ;; End line
d64b8a68
CY
4248 (let ((p (1+ (point))))
4249 (insert "\n\n")
647f9993
CY
4250 (put-text-property p (1+ p) 'face '(:underline t))
4251 (overlay-put (make-overlay p (1+ p))
4252 'before-string
4253 (propertize "\n" 'face '(:underline t)
4254 'display '(space :align-to 999))))))))
d543e20b 4255
d3d4df42 4256(defvar custom-group-menu
70482877 4257 `(("Set for Current Session" custom-group-set
eaa99205
CY
4258 (lambda (widget)
4259 (eq (widget-get widget :custom-state) 'modified)))
9b5007e7 4260 ,@(when (or custom-file init-file-user)
70482877 4261 '(("Save for Future Sessions" custom-group-save
eaa99205
CY
4262 (lambda (widget)
4263 (memq (widget-get widget :custom-state) '(modified set))))))
70482877 4264 ("Undo Edits" custom-group-reset-current
6d528fc5 4265 (lambda (widget)
86bd10bc 4266 (memq (widget-get widget :custom-state) '(modified))))
cf20dee0 4267 ("Revert This Session's Customizations" custom-group-reset-saved
6d528fc5 4268 (lambda (widget)
86bd10bc 4269 (memq (widget-get widget :custom-state) '(modified set))))
9b5007e7 4270 ,@(when (or custom-file init-file-user)
70482877 4271 '(("Erase Customization" custom-group-reset-standard
73e60f53 4272 (lambda (widget)
eaa99205 4273 (memq (widget-get widget :custom-state) '(modified set saved)))))))
d543e20b 4274 "Alist of actions for the `custom-group' widget.
6d528fc5
PA
4275Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4276the menu entry, ACTION is the function to call on the widget when the
4277menu is selected, and FILTER is a predicate which takes a `custom-group'
4278widget as an argument, and returns non-nil if ACTION is valid on that
d3d4df42 4279widget. If FILTER is nil, ACTION is always valid.")
d543e20b
PA
4280
4281(defun custom-group-action (widget &optional event)
4282 "Show the menu for `custom-group' WIDGET.
4283Optional EVENT is the location for the menu."
4284 (if (eq (widget-get widget :custom-state) 'hidden)
6d528fc5 4285 (custom-toggle-hide widget)
d543e20b 4286 (let* ((completion-ignore-case t)
25ac13b5
PA
4287 (answer (widget-choose (concat "Operation on "
4288 (custom-unlispify-tag-name
4289 (widget-get widget :value)))
6d528fc5
PA
4290 (custom-menu-filter custom-group-menu
4291 widget)
d543e20b
PA
4292 event)))
4293 (if answer
4294 (funcall answer widget)))))
4295
4296(defun custom-group-set (widget)
4297 "Set changes in all modified group members."
9db1942d
CY
4298 (dolist (child (widget-get widget :children))
4299 (when (eq (widget-get child :custom-state) 'modified)
4300 (widget-apply child :custom-set))))
d543e20b 4301
5ae87ed4
MR
4302(defun custom-group-mark-to-save (widget)
4303 "Mark all modified group members for saving."
ed8c9cf1 4304 (dolist (child (widget-get widget :children))
9db1942d 4305 (when (memq (widget-get child :custom-state) '(modified set))
5ae87ed4
MR
4306 (widget-apply child :custom-mark-to-save))))
4307
4308(defsubst custom-group-state-set-and-redraw (widget)
4309 "Set state of group widget WIDGET and redraw with current settings."
4310 (dolist (child (widget-get widget :children))
4311 (when (memq (widget-get child :custom-state) '(modified set))
4312 (widget-apply child :custom-state-set-and-redraw))))
4313
4314(defun custom-group-save (widget)
4315 "Save all modified group members."
4316 (custom-group-mark-to-save widget)
4317 (custom-save-all)
4318 (custom-group-state-set-and-redraw widget))
d543e20b
PA
4319
4320(defun custom-group-reset-current (widget)
4321 "Reset all modified group members."
9db1942d
CY
4322 (dolist (child (widget-get widget :children))
4323 (when (eq (widget-get child :custom-state) 'modified)
4324 (widget-apply child :custom-reset-current))))
d543e20b
PA
4325
4326(defun custom-group-reset-saved (widget)
4327 "Reset all modified or set group members."
9db1942d
CY
4328 (dolist (child (widget-get widget :children))
4329 (when (memq (widget-get child :custom-state) '(modified set))
4330 (widget-apply child :custom-reset-saved))))
d543e20b 4331
25ac13b5 4332(defun custom-group-reset-standard (widget)
d543e20b 4333 "Reset all modified, set, or saved group members."
5ae87ed4
MR
4334 (let ((custom-reset-standard-variables-list '(t))
4335 (custom-reset-standard-faces-list '(t)))
4336 (custom-group-mark-to-reset-standard widget)
4337 (custom-reset-standard-save-and-update)))
4338
4339(defun custom-group-mark-to-reset-standard (widget)
4340 "Mark to reset all modified, set, or saved group members."
9db1942d
CY
4341 (dolist (child (widget-get widget :children))
4342 (when (memq (widget-get child :custom-state)
4343 '(modified set saved))
5ae87ed4 4344 (widget-apply child :custom-mark-to-reset-standard))))
d543e20b
PA
4345
4346(defun custom-group-state-update (widget)
4347 "Update magic."
4348 (unless (eq (widget-get widget :custom-state) 'hidden)
4349 (let* ((children (widget-get widget :children))
4350 (states (mapcar (lambda (child)
4351 (widget-get child :custom-state))
4352 children))
25ac13b5
PA
4353 (magics custom-magic-alist)
4354 (found 'standard))
d543e20b
PA
4355 (while magics
4356 (let ((magic (car (car magics))))
4357 (if (and (not (eq magic 'hidden))
4358 (memq magic states))
4359 (setq found magic
4360 magics nil)
4361 (setq magics (cdr magics)))))
4362 (widget-put widget :custom-state found)))
4363 (custom-magic-reset widget))
f8d869d1
RS
4364\f
4365;;; Reading and writing the custom file.
d543e20b 4366
a1a4fa22 4367;;;###autoload
1e4ed6df 4368(defcustom custom-file nil
d543e20b 4369 "File used for storing customization information.
1e4ed6df 4370The default is nil, which means to use your init file
09b73f49
RS
4371as specified by `user-init-file'. If the value is not nil,
4372it should be an absolute file name.
4373
5aa971e3
LT
4374You can set this option through Custom, if you carefully read the
4375last paragraph below. However, usually it is simpler to write
4376something like the following in your init file:
4377
4378\(setq custom-file \"~/.emacs-custom.el\")
4379\(load custom-file)
4380
4381Note that both lines are necessary: the first line tells Custom to
4382save all customizations in this file, but does not load it.
4383
4384When you change this variable outside Custom, look in the
4385previous custom file \(usually your init file) for the
4386forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4387and copy them (whichever ones you find) to the new custom file.
4388This will preserve your existing customizations.
4389
4390If you save this option using Custom, Custom will write all
4391currently saved customizations, including the new one for this
4392option itself, into the file you specify, overwriting any
4393`custom-set-variables' and `custom-set-faces' forms already
4394present in that file. It will not delete any customizations from
4395the old custom file. You should do that manually if that is what you
4396want. You also have to put something like `\(load \"CUSTOM-FILE\")
4397in your init file, where CUSTOM-FILE is the actual name of the
4398file. Otherwise, Emacs will not load the file when it starts up,
4399and hence will not set `custom-file' to that file either."
4400 :type '(choice (const :tag "Your Emacs init file" nil)
4401 (file :format "%t:%v%d"
4402 :doc
4403 "Please read entire docstring below before setting \
4404this through Custom.
6cda144f 4405Click on \"More\" \(or position point there and press RETURN)
5aa971e3 4406if only the first line of the docstring is shown."))
d543e20b
PA
4407 :group 'customize)
4408
eab5dc07 4409(defun custom-file (&optional no-error)
176eb8cb 4410 "Return the file name for saving customizations."
98cd6c18
LMI
4411 (if (null user-init-file)
4412 ;; Started with -q, i.e. the file containing Custom settings
4413 ;; hasn't been read. Saving settings there won't make much
4414 ;; sense.
4415 (if no-error
4416 nil
4417 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4418 (file-chase-links (or custom-file user-init-file))))
176eb8cb 4419
b581d2ea
GM
4420;; If recentf-mode is non-nil, this is defined.
4421(declare-function recentf-expand-file-name "recentf" (name))
4422
f8d869d1
RS
4423;;;###autoload
4424(defun custom-save-all ()
4425 "Save all customizations in `custom-file'."
e29e9065
RS
4426 (when (and (null custom-file) init-file-had-error)
4427 (error "Cannot save customizations; init file was not fully loaded"))
f8d869d1 4428 (let* ((filename (custom-file))
c34a8a87
EZ
4429 (recentf-exclude
4430 (if recentf-mode
4431 (cons (concat "\\`"
4432 (regexp-quote
4433 (recentf-expand-file-name (custom-file)))
4434 "\\'")
4435 recentf-exclude)))
ac183163
CY
4436 (old-buffer (find-buffer-visiting filename))
4437 old-buffer-name)
4438
9e2f5050
RS
4439 (with-current-buffer (let ((find-file-visit-truename t))
4440 (or old-buffer (find-file-noselect filename)))
ac183163
CY
4441 ;; We'll save using file-precious-flag, so avoid destroying
4442 ;; symlinks. (If we're not already visiting the buffer, this is
4443 ;; handled by find-file-visit-truename, above.)
4444 (when old-buffer
4445 (setq old-buffer-name (buffer-file-name))
4446 (set-visited-file-name (file-chase-links filename)))
4447
31b7fa51
CY
4448 (unless (eq major-mode 'emacs-lisp-mode)
4449 (emacs-lisp-mode))
478834e6
TB
4450 (let ((inhibit-read-only t)
4451 (print-length nil)
4452 (print-level nil))
f8d869d1
RS
4453 (custom-save-variables)
4454 (custom-save-faces))
4455 (let ((file-precious-flag t))
4456 (save-buffer))
ac183163
CY
4457 (if old-buffer
4458 (progn
4459 (set-visited-file-name old-buffer-name)
4460 (set-buffer-modified-p nil))
f8d869d1 4461 (kill-buffer (current-buffer))))))
16ecd4c5
RS
4462
4463;;;###autoload
4464(defun customize-save-customized ()
4465 "Save all user options which have been set in this session."
4466 (interactive)
4467 (mapatoms (lambda (symbol)
4468 (let ((face (get symbol 'customized-face))
4469 (value (get symbol 'customized-value))
4470 (face-comment (get symbol 'customized-face-comment))
4471 (variable-comment
4472 (get symbol 'customized-variable-comment)))
4473 (when face
4474 (put symbol 'saved-face face)
4475 (custom-push-theme 'theme-face symbol 'user 'set value)
4476 (put symbol 'customized-face nil))
4477 (when value
4478 (put symbol 'saved-value value)
4479 (custom-push-theme 'theme-value symbol 'user 'set value)
4480 (put symbol 'customized-value nil))
4481 (when variable-comment
4482 (put symbol 'saved-variable-comment variable-comment)
4483 (put symbol 'customized-variable-comment nil))
4484 (when face-comment
4485 (put symbol 'saved-face-comment face-comment)
4486 (put symbol 'customized-face-comment nil)))))
4487 ;; We really should update all custom buffers here.
4488 (custom-save-all))
f8d869d1
RS
4489\f
4490;; Editing the custom file contents in a buffer.
4491
d543e20b 4492(defun custom-save-delete (symbol)
f8d869d1 4493 "Delete all calls to SYMBOL from the contents of the current buffer.
a34511a1 4494Leave point at the old location of the first such call,
f8d869d1
RS
4495or (if there were none) at the end of the buffer.
4496
4497This function does not save the buffer."
d543e20b 4498 (goto-char (point-min))
cbe8bb8e
KH
4499 ;; Skip all whitespace and comments.
4500 (while (forward-comment 1))
4501 (or (eobp)
4502 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
a34511a1
RS
4503 (let (first)
4504 (catch 'found
4505 (while t ;; We exit this loop only via throw.
4506 ;; Skip all whitespace and comments.
4507 (while (forward-comment 1))
4508 (let ((start (point))
4509 (sexp (condition-case nil
4510 (read (current-buffer))
4511 (end-of-file (throw 'found nil)))))
4512 (when (and (listp sexp)
4513 (eq (car sexp) symbol))
4514 (delete-region start (point))
4515 (unless first
4516 (setq first (point)))))))
4517 (if first
4518 (goto-char first)
189638d5
GM
4519 ;; Move in front of local variables, otherwise long Custom
4520 ;; entries would make them ineffective.
4521 (let ((pos (point-max))
4522 (case-fold-search t))
4523 (save-excursion
4524 (goto-char (point-max))
4525 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4526 'move)
4527 (when (search-forward "Local Variables:" nil t)
4528 (setq pos (line-beginning-position))))
4529 (goto-char pos)))))
d543e20b 4530
06b60517
JB
4531(defvar sort-fold-case) ; defined in sort.el
4532
d543e20b
PA
4533(defun custom-save-variables ()
4534 "Save all customized variables in `custom-file'."
4535 (save-excursion
4536 (custom-save-delete 'custom-set-variables)
d151422c
MR
4537 (let ((standard-output (current-buffer))
4538 (saved-list (make-list 1 0))
4539 sort-fold-case)
4540 ;; First create a sorted list of saved variables.
4541 (mapatoms
4542 (lambda (symbol)
d358aa10 4543 (if (and (get symbol 'saved-value)
2d656942
CY
4544 ;; ignore theme values
4545 (or (null (get symbol 'theme-value))
4546 (eq 'user (caar (get symbol 'theme-value)))))
d151422c
MR
4547 (nconc saved-list (list symbol)))))
4548 (setq saved-list (sort (cdr saved-list) 'string<))
d543e20b
PA
4549 (unless (bolp)
4550 (princ "\n"))
aec2bb63 4551 (princ "(custom-set-variables
61b6abbd
AL
4552 ;; custom-set-variables was added by Custom.
4553 ;; If you edit it by hand, you could mess it up, so be careful.
4554 ;; Your init file should contain only one such instance.
4555 ;; If there is more than one, they won't work right.\n")
d9f67134
SM
4556 (dolist (symbol saved-list)
4557 (let ((spec (car-safe (get symbol 'theme-value)))
4558 (value (get symbol 'saved-value))
4559 (requests (get symbol 'custom-requests))
adcc7a37
RS
4560 (now (and (not (custom-variable-p symbol))
4561 (or (boundp symbol)
4562 (eq (get symbol 'force-value)
4563 'rogue))))
40627755 4564 (comment (get symbol 'saved-variable-comment)))
c8c9333c 4565 ;; Check REQUESTS for validity.
d9f67134
SM
4566 (dolist (request requests)
4567 (when (and (symbolp request) (not (featurep request)))
4568 (message "Unknown requested feature: %s" request)
4569 (setq requests (delq request requests))))
adcc7a37 4570 ;; Is there anything customized about this variable?
d358aa10 4571 (when (or (and spec (eq (car spec) 'user))
d9f67134
SM
4572 comment
4573 (and (null spec) (get symbol 'saved-value)))
adcc7a37
RS
4574 ;; Output an element for this variable.
4575 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4576 ;; SYMBOL is the variable name.
4577 ;; VALUE-FORM is an expression to return the customized value.
4578 ;; NOW if non-nil means always set the variable immediately
4579 ;; when the customizations are reloaded. This is used
4580 ;; for rogue variables
4581 ;; REQUESTS is a list of packages to load before setting the
4582 ;; variable. Each element of it will be passed to `require'.
4583 ;; COMMENT is whatever comment the user has specified
4584 ;; with the customize facility.
d9f67134
SM
4585 (unless (bolp)
4586 (princ "\n"))
4587 (princ " '(")
4588 (prin1 symbol)
4589 (princ " ")
4590 (prin1 (car value))
4591 (when (or now requests comment)
4592 (princ " ")
4593 (prin1 now)
4594 (when (or requests comment)
4595 (princ " ")
4596 (prin1 requests)
4597 (when comment
4598 (princ " ")
4599 (prin1 comment))))
4600 (princ ")"))))
a34511a1
RS
4601 (if (bolp)
4602 (princ " "))
d543e20b
PA
4603 (princ ")")
4604 (unless (looking-at "\n")
4605 (princ "\n")))))
4606
4607(defun custom-save-faces ()
4608 "Save all customized faces in `custom-file'."
4609 (save-excursion
c942535f 4610 (custom-save-delete 'custom-reset-faces)
d543e20b 4611 (custom-save-delete 'custom-set-faces)
d151422c
MR
4612 (let ((standard-output (current-buffer))
4613 (saved-list (make-list 1 0))
4614 sort-fold-case)
4615 ;; First create a sorted list of saved faces.
4616 (mapatoms
4617 (lambda (symbol)
d358aa10
CY
4618 (if (and (get symbol 'saved-face)
4619 (eq 'user (car (car-safe (get symbol 'theme-face)))))
d151422c
MR
4620 (nconc saved-list (list symbol)))))
4621 (setq saved-list (sort (cdr saved-list) 'string<))
4622 ;; The default face must be first, since it affects the others.
4623 (if (memq 'default saved-list)
4624 (setq saved-list (cons 'default (delq 'default saved-list))))
d543e20b
PA
4625 (unless (bolp)
4626 (princ "\n"))
aec2bb63 4627 (princ "(custom-set-faces
61b6abbd
AL
4628 ;; custom-set-faces was added by Custom.
4629 ;; If you edit it by hand, you could mess it up, so be careful.
4630 ;; Your init file should contain only one such instance.
4631 ;; If there is more than one, they won't work right.\n")
d9f67134
SM
4632 (dolist (symbol saved-list)
4633 (let ((spec (car-safe (get symbol 'theme-face)))
4634 (value (get symbol 'saved-face))
4635 (now (not (or (get symbol 'face-defface-spec)
4636 (and (not (custom-facep symbol))
4637 (not (get symbol 'force-face))))))
4638 (comment (get symbol 'saved-face-comment)))
d358aa10 4639 (when (or (and spec (eq (nth 0 spec) 'user))
d9f67134
SM
4640 comment
4641 (and (null spec) (get symbol 'saved-face)))
4642 ;; Don't print default face here.
4643 (unless (bolp)
4644 (princ "\n"))
4645 (princ " '(")
4646 (prin1 symbol)
4647 (princ " ")
4648 (prin1 value)
4649 (when (or now comment)
4650 (princ " ")
4651 (prin1 now)
4652 (when comment
4653 (princ " ")
4654 (prin1 comment)))
4655 (princ ")"))))
a34511a1
RS
4656 (if (bolp)
4657 (princ " "))
d543e20b
PA
4658 (princ ")")
4659 (unless (looking-at "\n")
08b4ae6c 4660 (princ "\n")))))
f8d869d1 4661\f
d543e20b
PA
4662;;; The Customize Menu.
4663
bd042c03
PA
4664;;; Menu support
4665
25ac13b5
PA
4666(defcustom custom-menu-nesting 2
4667 "Maximum nesting in custom menus."
4668 :type 'integer
6aaedd12 4669 :group 'custom-menu)
d543e20b 4670
06b60517 4671(defun custom-face-menu-create (_widget symbol)
d543e20b
PA
4672 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4673 (vector (custom-unlispify-menu-entry symbol)
86bd10bc 4674 `(customize-face ',symbol)
d543e20b
PA
4675 t))
4676
06b60517 4677(defun custom-variable-menu-create (_widget symbol)
d543e20b
PA
4678 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4679 (let ((type (get symbol 'custom-type)))
4680 (unless (listp type)
4681 (setq type (list type)))
4682 (if (and type (widget-get type :custom-menu))
4683 (widget-apply type :custom-menu symbol)
4684 (vector (custom-unlispify-menu-entry symbol)
86bd10bc 4685 `(customize-variable ',symbol)
d543e20b
PA
4686 t))))
4687
bd042c03 4688;; Add checkboxes to boolean variable entries.
d543e20b 4689(widget-put (get 'boolean 'widget-type)
06b60517 4690 :custom-menu (lambda (_widget symbol)
d543e20b 4691 (vector (custom-unlispify-menu-entry symbol)
86bd10bc 4692 `(customize-variable ',symbol)
d543e20b
PA
4693 ':style 'toggle
4694 ':selected symbol)))
4695
06b60517 4696(defun custom-group-menu-create (_widget symbol)
d04a3972
DL
4697 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4698 `( ,(custom-unlispify-menu-entry symbol t)
4699 :filter (lambda (&rest junk)
809f0c35 4700 (let* ((menu (custom-menu-create ',symbol)))
3b2f3d30 4701 (if (consp menu) (cdr menu) menu)))))
d543e20b 4702
bd042c03
PA
4703;;;###autoload
4704(defun custom-menu-create (symbol)
d543e20b 4705 "Create menu for customization group SYMBOL.
d543e20b 4706The menu is in a format applicable to `easy-menu-define'."
809f0c35
RS
4707 (let* ((deactivate-mark nil)
4708 (item (vector (custom-unlispify-menu-entry symbol)
86bd10bc 4709 `(customize-group ',symbol)
bd042c03
PA
4710 t)))
4711 (if (and (or (not (boundp 'custom-menu-nesting))
4712 (>= custom-menu-nesting 0))
2de2cb02
MR
4713 (progn
4714 (custom-load-symbol symbol)
4715 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
d543e20b 4716 (let ((custom-prefix-list (custom-prefix-add symbol
25ac13b5 4717 custom-prefix-list))
da5ec617
PA
4718 (members (custom-sort-items (get symbol 'custom-group)
4719 custom-menu-sort-alphabetically
4720 custom-menu-order-groups)))
d543e20b
PA
4721 `(,(custom-unlispify-menu-entry symbol t)
4722 ,item
4723 "--"
4724 ,@(mapcar (lambda (entry)
4725 (widget-apply (if (listp (nth 1 entry))
4726 (nth 1 entry)
4727 (list (nth 1 entry)))
4728 :custom-menu (nth 0 entry)))
25ac13b5 4729 members)))
d543e20b
PA
4730 item)))
4731
4732;;;###autoload
bd042c03
PA
4733(defun customize-menu-create (symbol &optional name)
4734 "Return a customize menu for customization group SYMBOL.
d3d4df42 4735If optional NAME is given, use that as the name of the menu.
bd042c03
PA
4736Otherwise the menu will be named `Customize'.
4737The format is suitable for use with `easy-menu-define'."
4738 (unless name
4739 (setq name "Customize"))
d04a3972
DL
4740 `(,name
4741 :filter (lambda (&rest junk)
3b2f3d30
SM
4742 (let ((menu (custom-menu-create ',symbol)))
4743 (if (consp menu) (cdr menu) menu)))))
d543e20b 4744
9db1942d
CY
4745;;; Toolbar and menubar support
4746
4747(easy-menu-define
34cf517c 4748 Custom-mode-menu (list custom-mode-map custom-field-keymap)
9db1942d
CY
4749 "Menu used in customization buffers."
4750 (nconc (list "Custom"
4751 (customize-menu-create 'customize))
4752 (mapcar (lambda (arg)
4753 (let ((tag (nth 0 arg))
4754 (command (nth 1 arg))
4755 (active (nth 2 arg))
4756 (help (nth 3 arg)))
4757 (vector tag command :active (eval active) :help help)))
4758 custom-commands)))
4759
4760(defvar tool-bar-map)
2614ccc3
MR
4761
4762;;; `custom-tool-bar-map' used to be set up here. This will fail to
4763;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
6aec3b9d 4764;;; we set this up lazily in `Custom-mode'.
2614ccc3
MR
4765(defvar custom-tool-bar-map nil
4766 "Keymap for toolbar in Custom mode.")
9db1942d 4767
bd042c03
PA
4768;;; The Custom Mode.
4769
06b60517 4770(defun Custom-no-edit (_pos &optional _event)
7eb944cf
RS
4771 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4772 (interactive "@d")
a8da2abd 4773 (error "You can't edit this part of the Custom buffer"))
0ce026b1 4774
adcc7a37 4775(defun Custom-newline (pos &optional event)
19f0515a
RS
4776 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4777 (interactive "@d")
4778 (let ((button (get-char-property pos 'button)))
5772caab
GM
4779 ;; If there is no button at point, then use the one at the start
4780 ;; of the line, if it is a custom-group-link (bug#2298).
4781 (or button
4782 (if (setq button (get-char-property (line-beginning-position) 'button))
4783 (or (eq (widget-type button) 'custom-group-link)
4784 (setq button nil))))
19f0515a
RS
4785 (if button
4786 (widget-apply-action button event)
4787 (error "You can't edit this part of the Custom buffer"))))
4788
b62c92bb
RS
4789(defun Custom-goto-parent ()
4790 "Go to the parent group listed at the top of this buffer.
4791If several parents are listed, go to the first of them."
4792 (interactive)
4793 (save-excursion
4794 (goto-char (point-min))
d84fcc30 4795 (if (search-forward "\nParent groups: " nil t)
b62c92bb
RS
4796 (let* ((button (get-char-property (point) 'button))
4797 (parent (downcase (widget-get button :tag))))
4798 (customize-group parent)))))
4799
6aec3b9d 4800(defcustom Custom-mode-hook nil
d3d4df42 4801 "Hook called when entering Custom mode."
bd042c03 4802 :type 'hook
6aec3b9d 4803 :group 'custom-buffer)
bd042c03 4804
b62c92bb
RS
4805(defun custom-state-buffer-message (widget)
4806 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4807 (message "To install your edits, invoke [State] and choose the Set operation")))
8691cfa7 4808
6b09b5d1
CY
4809(defun custom--initialize-widget-variables ()
4810 (set (make-local-variable 'widget-documentation-face) 'custom-documentation)
4811 (set (make-local-variable 'widget-button-face) custom-button)
4812 (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed)
4813 (set (make-local-variable 'widget-mouse-face) custom-button-mouse)
4814 ;; We need this because of the "More" button on docstrings.
4815 ;; Otherwise clicking on "More" can push point offscreen, which
4816 ;; causes the window to recenter on point, which pushes the
4817 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4818 (set (make-local-variable 'widget-button-click-moves-point) t)
4819 ;; When possible, use relief for buttons, not bracketing. This test
4820 ;; may not be optimal.
4821 (when custom-raised-buttons
4822 (set (make-local-variable 'widget-push-button-prefix) "")
4823 (set (make-local-variable 'widget-push-button-suffix) "")
4824 (set (make-local-variable 'widget-link-prefix) "")
4825 (set (make-local-variable 'widget-link-suffix) ""))
4826 (setq show-trailing-whitespace nil))
4827
6aec3b9d 4828(define-derived-mode Custom-mode nil "Custom"
bd042c03
PA
4829 "Major mode for editing customization buffers.
4830
4831The following commands are available:
4832
192e44fc
JL
4833\\<widget-keymap>\
4834Move to next button, link or editable field. \\[widget-forward]
fd40bad4 4835Move to previous button, link or editable field. \\[widget-backward]
192e44fc 4836\\<custom-field-keymap>\
4ee1cf9f
PA
4837Complete content of editable text field. \\[widget-complete]
4838\\<custom-mode-map>\
9ca66103 4839Invoke button under the mouse pointer. \\[widget-button-click]
192e44fc 4840Invoke button under point. \\[widget-button-press]
107736a2
RS
4841Set all options from current text. \\[Custom-set]
4842Make values in current text permanent. \\[Custom-save]
192e44fc
JL
4843Make text match actual option values. \\[Custom-reset-current]
4844Reset options to permanent settings. \\[Custom-reset-saved]
107736a2
RS
4845Erase customizations; set options
4846 and buffer text to the standard values. \\[Custom-reset-standard]
bd042c03 4847
6aec3b9d 4848Entry to this mode calls the value of `Custom-mode-hook'
bd042c03 4849if that value is non-nil."
bd042c03 4850 (use-local-map custom-mode-map)
ab678382 4851 (easy-menu-add Custom-mode-menu)
8db5a4fe
CY
4852 (set (make-local-variable 'tool-bar-map)
4853 (or custom-tool-bar-map
4854 ;; Set up `custom-tool-bar-map'.
4855 (let ((map (make-sparse-keymap)))
4856 (mapc
4857 (lambda (arg)
4858 (tool-bar-local-item-from-menu
f904c0f9
JD
4859 (nth 1 arg) (nth 4 arg) map custom-mode-map
4860 :label (nth 5 arg)))
8db5a4fe
CY
4861 custom-commands)
4862 (setq custom-tool-bar-map map))))
bd042c03 4863 (make-local-variable 'custom-options)
9b7826f4 4864 (make-local-variable 'custom-local-buffer)
6b09b5d1 4865 (custom--initialize-widget-variables)
d1a3873f 4866 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t))
d543e20b 4867
6aec3b9d
JL
4868(put 'Custom-mode 'mode-class 'special)
4869
4870;; backward-compatibility
4871(defun custom-mode ()
4872 "Non-interactive variant of `Custom-mode'."
4873 (Custom-mode))
82c02591 4874(make-obsolete 'custom-mode 'Custom-mode "23.1")
7f352f86 4875(put 'custom-mode 'mode-class 'special)
82c02591 4876(define-obsolete-variable-alias 'custom-mode-hook 'Custom-mode-hook "23.1")
7f352f86 4877
81711dba
EZ
4878(dolist (regexp
4879 '("^No user option defaults have been changed since Emacs "
4880 "^Invalid face:? "
4881 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4882 "^No customizable items matching "
4883 "^There are unset changes"
4884 "^Cannot set hidden variable"
4885 "^No \\(?:saved\\|backup\\) value for "
4886 "^No standard setting known for "
4887 "^No standard setting for this face"
4888 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4889 (add-to-list 'debug-ignored-errors regexp))
2365594b 4890
d543e20b
PA
4891;;; The End.
4892
4893(provide 'cus-edit)
4894
d3d4df42 4895;;; cus-edit.el ends here