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