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