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