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