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