* src/fileio.c (Fmake_temp_name): Doc tweaks.
[emacs.git] / lisp / cus-edit.el
blob4a5a9bfa7d953458d1a1e400a84ddde9590fbb7f
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 (defalias 'customize-customized 'customize-unsaved)
1361 ;;;###autoload
1362 (defun customize-unsaved ()
1363 "Customize all options and faces set in this session but not saved."
1364 (interactive)
1365 (let ((found nil))
1366 (mapatoms (lambda (symbol)
1367 (and (or (get symbol 'customized-face)
1368 (get symbol 'customized-face-comment))
1369 (custom-facep symbol)
1370 (push (list symbol 'custom-face) found))
1371 (and (or (get symbol 'customized-value)
1372 (get symbol 'customized-variable-comment))
1373 (boundp symbol)
1374 (push (list symbol 'custom-variable) found))))
1375 (if (not found)
1376 (error "No user options are set but unsaved")
1377 (custom-buffer-create (custom-sort-items found t nil)
1378 "*Customize Unsaved*"))))
1380 ;;;###autoload
1381 (defun customize-rogue ()
1382 "Customize all user variables modified outside customize."
1383 (interactive)
1384 (let ((found nil))
1385 (mapatoms (lambda (symbol)
1386 (let ((cval (or (get symbol 'customized-value)
1387 (get symbol 'saved-value)
1388 (get symbol 'standard-value))))
1389 (when (and cval ;Declared with defcustom.
1390 (default-boundp symbol) ;Has a value.
1391 (not (equal (eval (car cval))
1392 ;; Which does not match customize.
1393 (default-value symbol))))
1394 (push (list symbol 'custom-variable) found)))))
1395 (if (not found)
1396 (user-error "No rogue user options")
1397 (custom-buffer-create (custom-sort-items found t nil)
1398 "*Customize Rogue*"))))
1399 ;;;###autoload
1400 (defun customize-saved ()
1401 "Customize all saved options and faces."
1402 (interactive)
1403 (let ((found nil))
1404 (mapatoms (lambda (symbol)
1405 (and (or (get symbol 'saved-face)
1406 (get symbol 'saved-face-comment))
1407 (custom-facep symbol)
1408 (push (list symbol 'custom-face) found))
1409 (and (or (get symbol 'saved-value)
1410 (get symbol 'saved-variable-comment))
1411 (boundp symbol)
1412 (push (list symbol 'custom-variable) found))))
1413 (if (not found)
1414 (user-error "No saved user options")
1415 (custom-buffer-create (custom-sort-items found t nil)
1416 "*Customize Saved*"))))
1418 (declare-function apropos-parse-pattern "apropos" (pattern))
1419 (defvar apropos-regexp)
1421 ;;;###autoload
1422 (defun customize-apropos (pattern &optional type)
1423 "Customize loaded options, faces and groups matching PATTERN.
1424 PATTERN can be a word, a list of words (separated by spaces),
1425 or a regexp (using some regexp special characters). If it is a word,
1426 search for matches for that word as a substring. If it is a list of
1427 words, search for matches for any two (or more) of those words.
1429 If TYPE is `options', include only options.
1430 If TYPE is `faces', include only faces.
1431 If TYPE is `groups', include only groups."
1432 (interactive (list (apropos-read-pattern "symbol") nil))
1433 (require 'apropos)
1434 (unless (memq type '(nil options faces groups))
1435 (error "Invalid setting type %s" (symbol-name type)))
1436 (apropos-parse-pattern pattern) ;Sets apropos-regexp by side-effect: Yuck!
1437 (let (found)
1438 (mapatoms
1439 (lambda (symbol)
1440 (when (string-match-p apropos-regexp (symbol-name symbol))
1441 (if (memq type '(nil groups))
1442 (if (get symbol 'custom-group)
1443 (push (list symbol 'custom-group) found)))
1444 (if (memq type '(nil faces))
1445 (if (custom-facep symbol)
1446 (push (list symbol 'custom-face) found)))
1447 (if (memq type '(nil options))
1448 (if (and (boundp symbol)
1449 (eq (indirect-variable symbol) symbol)
1450 (or (get symbol 'saved-value)
1451 (custom-variable-p symbol)))
1452 (push (list symbol 'custom-variable) found))))))
1453 (unless found
1454 (error "No customizable %s matching %s" (if (not type)
1455 "group, face, or option"
1456 (symbol-name type))
1457 pattern))
1458 (custom-buffer-create
1459 (custom-sort-items found t custom-buffer-order-groups)
1460 "*Customize Apropos*")))
1462 ;;;###autoload
1463 (defun customize-apropos-options (regexp &optional ignored)
1464 "Customize all loaded customizable options matching REGEXP."
1465 (interactive (list (apropos-read-pattern "options")))
1466 (customize-apropos regexp 'options))
1468 ;;;###autoload
1469 (defun customize-apropos-faces (regexp)
1470 "Customize all loaded faces matching REGEXP."
1471 (interactive (list (apropos-read-pattern "faces")))
1472 (customize-apropos regexp 'faces))
1474 ;;;###autoload
1475 (defun customize-apropos-groups (regexp)
1476 "Customize all loaded groups matching REGEXP."
1477 (interactive (list (apropos-read-pattern "groups")))
1478 (customize-apropos regexp 'groups))
1480 ;;; Buffer.
1482 (defcustom custom-buffer-style 'links
1483 "Control the presentation style for customization buffers.
1484 The value should be a symbol, one of:
1486 brackets: groups nest within each other with big horizontal brackets.
1487 links: groups have links to subgroups."
1488 :type '(radio (const brackets)
1489 (const links))
1490 :group 'custom-buffer)
1492 (defcustom custom-buffer-done-kill nil
1493 "Non-nil means exiting a Custom buffer should kill it."
1494 :type 'boolean
1495 :version "22.1"
1496 :group 'custom-buffer)
1498 (defcustom custom-buffer-indent 3
1499 "Number of spaces to indent nested groups."
1500 :type 'integer
1501 :group 'custom-buffer)
1503 (defun custom-get-fresh-buffer (name)
1504 "Get a fresh new buffer with name NAME.
1505 If the buffer already exist, clean it up to be like new.
1506 Beware: it's not quite like new. Good enough for custom, but maybe
1507 not for everybody."
1508 ;; To be more complete, we should also kill all permanent-local variables,
1509 ;; but it's not needed for custom.
1510 (let ((buf (get-buffer name)))
1511 (when (and buf (buffer-local-value 'buffer-file-name buf))
1512 ;; This will check if the file is not saved.
1513 (kill-buffer buf)
1514 (setq buf nil))
1515 (if (null buf)
1516 (get-buffer-create name)
1517 (with-current-buffer buf
1518 (kill-all-local-variables)
1519 (run-hooks 'kill-buffer-hook)
1520 ;; Delete overlays before erasing the buffer so the overlay hooks
1521 ;; don't get run spuriously when we erase the buffer.
1522 (let ((ols (overlay-lists)))
1523 (dolist (ol (nconc (car ols) (cdr ols)))
1524 (delete-overlay ol)))
1525 (erase-buffer)
1526 buf))))
1528 ;;;###autoload
1529 (defun custom-buffer-create (options &optional name description)
1530 "Create a buffer containing OPTIONS.
1531 Optional NAME is the name of the buffer.
1532 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1533 SYMBOL is a customization option, and WIDGET is a widget for editing
1534 that option.
1535 DESCRIPTION is unused."
1536 (pop-to-buffer-same-window (custom-get-fresh-buffer (or name "*Customization*")))
1537 (custom-buffer-create-internal options description))
1539 ;;;###autoload
1540 (defun custom-buffer-create-other-window (options &optional name description)
1541 "Create a buffer containing OPTIONS, and display it in another window.
1542 The result includes selecting that window.
1543 Optional NAME is the name of the buffer.
1544 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1545 SYMBOL is a customization option, and WIDGET is a widget for editing
1546 that option."
1547 (unless name (setq name "*Customization*"))
1548 (switch-to-buffer-other-window (custom-get-fresh-buffer name))
1549 (custom-buffer-create-internal options description))
1551 (defcustom custom-reset-button-menu t
1552 "If non-nil, only show a single reset button in customize buffers.
1553 This button will have a menu with all three reset operations."
1554 :type 'boolean
1555 :group 'custom-buffer
1556 :version "24.3")
1558 (defcustom custom-buffer-verbose-help t
1559 "If non-nil, include explanatory text in the customization buffer."
1560 :type 'boolean
1561 :group 'custom-buffer)
1563 (defun Custom-buffer-done (&rest _ignore)
1564 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1565 (interactive)
1566 (quit-window custom-buffer-done-kill))
1568 (defvar custom-button nil
1569 "Face used for buttons in customization buffers.")
1571 (defvar custom-button-mouse nil
1572 "Mouse face used for buttons in customization buffers.")
1574 (defvar custom-button-pressed nil
1575 "Face used for pressed buttons in customization buffers.")
1577 (defcustom custom-search-field t
1578 "If non-nil, show a search field in Custom buffers."
1579 :type 'boolean
1580 :version "24.1"
1581 :group 'custom-buffer)
1583 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1584 '(("unspecified" . unspecified))))
1585 "If non-nil, indicate active buttons in a `raised-button' style.
1586 Otherwise use brackets."
1587 :type 'boolean
1588 :version "21.1"
1589 :group 'custom-buffer
1590 :set (lambda (variable value)
1591 (custom-set-default variable value)
1592 (setq custom-button
1593 (if value 'custom-button 'custom-button-unraised))
1594 (setq custom-button-mouse
1595 (if value 'custom-button-mouse 'highlight))
1596 (setq custom-button-pressed
1597 (if value
1598 'custom-button-pressed
1599 'custom-button-pressed-unraised))))
1601 (defun custom-buffer-create-internal (options &optional _description)
1602 (Custom-mode)
1603 (let ((init-file (or custom-file user-init-file)))
1604 ;; Insert verbose help at the top of the custom buffer.
1605 (when custom-buffer-verbose-help
1606 (unless init-file
1607 (widget-insert "Custom settings cannot be saved; maybe you started Emacs with `-q'.\n"))
1608 (widget-insert "For help using this buffer, see ")
1609 (widget-create 'custom-manual
1610 :tag "Easy Customization"
1611 "(emacs)Easy Customization")
1612 (widget-insert " in the ")
1613 (widget-create 'custom-manual
1614 :tag "Emacs manual"
1615 :help-echo "Read the Emacs manual."
1616 "(emacs)Top")
1617 (widget-insert "."))
1618 (widget-insert "\n")
1620 ;; Insert the search field.
1621 (when custom-search-field
1622 (widget-insert "\n")
1623 (let* ((echo "Search for custom items.
1624 You can enter one or more words separated by spaces,
1625 or a regular expression.")
1626 (search-widget
1627 (widget-create
1628 'editable-field
1629 :size 40 :help-echo echo
1630 :action (lambda (widget &optional _event)
1631 (customize-apropos (split-string (widget-value widget)))))))
1632 (widget-insert " ")
1633 (widget-create-child-and-convert
1634 search-widget 'push-button
1635 :tag " Search "
1636 :help-echo echo :action
1637 (lambda (widget &optional _event)
1638 (customize-apropos (split-string (widget-value (widget-get widget :parent))))))
1639 (widget-insert "\n")))
1641 ;; The custom command buttons are also in the toolbar, so for a
1642 ;; time they were not inserted in the buffer if the toolbar was in use.
1643 ;; But it can be a little confusing for the buffer layout to
1644 ;; change according to whether or nor the toolbar is on, not to
1645 ;; mention that a custom buffer can in theory be created in a
1646 ;; frame with a toolbar, then later viewed in one without.
1647 ;; So now the buttons are always inserted in the buffer. (Bug#1326)
1648 (if custom-buffer-verbose-help
1649 (widget-insert "
1650 Operate on all settings in this buffer:\n"))
1651 (let ((button (lambda (tag action active help _icon _label)
1652 (widget-insert " ")
1653 (if (eval active)
1654 (widget-create 'push-button :tag tag
1655 :help-echo help :action action))))
1656 (commands custom-commands))
1657 (if custom-reset-button-menu
1658 (progn
1659 (widget-create 'push-button
1660 :tag " Revert... "
1661 :help-echo "Show a menu with reset operations."
1662 :mouse-down-action 'ignore
1663 :action 'custom-reset)
1664 (apply button (pop commands)) ; Apply
1665 (apply button (pop commands))) ; Apply and Save
1666 (apply button (pop commands)) ; Apply
1667 (apply button (pop commands)) ; Apply and Save
1668 (widget-insert "\n")
1669 (apply button (pop commands)) ; Undo
1670 (apply button (pop commands)) ; Reset
1671 (apply button (pop commands)) ; Erase
1672 (widget-insert " ")
1673 (pop commands) ; Help (omitted)
1674 (apply button (pop commands)))) ; Exit
1675 (widget-insert "\n\n"))
1677 ;; Now populate the custom buffer.
1678 (message "Creating customization items...")
1679 (buffer-disable-undo)
1680 (setq custom-options
1681 (if (= (length options) 1)
1682 (mapcar (lambda (entry)
1683 (widget-create (nth 1 entry)
1684 :documentation-shown t
1685 :custom-state 'unknown
1686 :tag (custom-unlispify-tag-name
1687 (nth 0 entry))
1688 :value (nth 0 entry)))
1689 options)
1690 (let ((count 0)
1691 (length (length options)))
1692 (mapcar (lambda (entry)
1693 (prog2
1694 (message "Creating customization items ...%2d%%"
1695 (/ (* 100.0 count) length))
1696 (widget-create (nth 1 entry)
1697 :tag (custom-unlispify-tag-name
1698 (nth 0 entry))
1699 :value (nth 0 entry))
1700 (setq count (1+ count))
1701 (unless (eq (preceding-char) ?\n)
1702 (widget-insert "\n"))
1703 (widget-insert "\n")))
1704 options))))
1705 (unless (eq (preceding-char) ?\n)
1706 (widget-insert "\n"))
1707 (message "Creating customization items ...done")
1708 (message "Resetting customization items...")
1709 (unless (eq custom-buffer-style 'tree)
1710 (mapc 'custom-magic-reset custom-options))
1711 (message "Resetting customization items...done")
1712 (message "Creating customization setup...")
1713 (widget-setup)
1714 (buffer-enable-undo)
1715 (goto-char (point-min))
1716 (message "Creating customization setup...done"))
1718 ;;; The Tree Browser.
1720 ;;;###autoload
1721 (defun customize-browse (&optional group)
1722 "Create a tree browser for the customize hierarchy."
1723 (interactive)
1724 (unless group
1725 (setq group 'emacs))
1726 (let ((name "*Customize Browser*"))
1727 (pop-to-buffer-same-window (custom-get-fresh-buffer name)))
1728 (Custom-mode)
1729 (widget-insert (format "\
1730 %s buttons; type RET or click mouse-1
1731 on a button to invoke its action.
1732 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1733 (if custom-raised-buttons
1734 "`Raised' text indicates"
1735 "Square brackets indicate")))
1738 (if custom-browse-only-groups
1739 (widget-insert "\
1740 Invoke the [Group] button below to edit that item in another window.\n\n")
1741 (widget-insert "Invoke the ")
1742 (widget-create 'item
1743 :format "%t"
1744 :tag "[Group]"
1745 :tag-glyph "folder")
1746 (widget-insert ", ")
1747 (widget-create 'item
1748 :format "%t"
1749 :tag "[Face]"
1750 :tag-glyph "face")
1751 (widget-insert ", and ")
1752 (widget-create 'item
1753 :format "%t"
1754 :tag "[Option]"
1755 :tag-glyph "option")
1756 (widget-insert " buttons below to edit that
1757 item in another window.\n\n"))
1758 (let ((custom-buffer-style 'tree))
1759 (widget-create 'custom-group
1760 :custom-last t
1761 :custom-state 'unknown
1762 :tag (custom-unlispify-tag-name group)
1763 :value group))
1764 (widget-setup)
1765 (goto-char (point-min)))
1767 (define-widget 'custom-browse-visibility 'item
1768 "Control visibility of items in the customize tree browser."
1769 :format "%[[%t]%]"
1770 :action 'custom-browse-visibility-action)
1772 (defun custom-browse-visibility-action (widget &rest _ignore)
1773 (let ((custom-buffer-style 'tree))
1774 (custom-toggle-parent widget)))
1776 (define-widget 'custom-browse-group-tag 'custom-group-link
1777 "Show parent in other window when activated."
1778 :tag "Group"
1779 :tag-glyph "folder"
1780 :action 'custom-browse-group-tag-action)
1782 (defun custom-browse-group-tag-action (widget &rest _ignore)
1783 (let ((parent (widget-get widget :parent)))
1784 (customize-group-other-window (widget-value parent))))
1786 (define-widget 'custom-browse-variable-tag 'custom-group-link
1787 "Show parent in other window when activated."
1788 :tag "Option"
1789 :tag-glyph "option"
1790 :action 'custom-browse-variable-tag-action)
1792 (defun custom-browse-variable-tag-action (widget &rest _ignore)
1793 (let ((parent (widget-get widget :parent)))
1794 (customize-variable-other-window (widget-value parent))))
1796 (define-widget 'custom-browse-face-tag 'custom-group-link
1797 "Show parent in other window when activated."
1798 :tag "Face"
1799 :tag-glyph "face"
1800 :action 'custom-browse-face-tag-action)
1802 (defun custom-browse-face-tag-action (widget &rest _ignore)
1803 (let ((parent (widget-get widget :parent)))
1804 (customize-face-other-window (widget-value parent))))
1806 (defconst custom-browse-alist '((" " "space")
1807 (" | " "vertical")
1808 ("-\\ " "top")
1809 (" |-" "middle")
1810 (" `-" "bottom")))
1812 (defun custom-browse-insert-prefix (prefix)
1813 "Insert PREFIX. On XEmacs convert it to line graphics."
1814 ;; Fixme: do graphics.
1815 (if nil ; (featurep 'xemacs)
1816 (progn
1817 (insert "*")
1818 (while (not (string-equal prefix ""))
1819 (let ((entry (substring prefix 0 3)))
1820 (setq prefix (substring prefix 3))
1821 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1822 (name (nth 1 (assoc entry custom-browse-alist))))
1823 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1824 (overlay-put overlay 'start-open t)
1825 (overlay-put overlay 'end-open t)))))
1826 (insert prefix)))
1828 ;;; Modification of Basic Widgets.
1830 ;; We add extra properties to the basic widgets needed here. This is
1831 ;; fine, as long as we are careful to stay within our own namespace.
1833 ;; We want simple widgets to be displayed by default, but complex
1834 ;; widgets to be hidden.
1836 ;; This widget type is obsolete as of Emacs 24.1.
1837 (widget-put (get 'item 'widget-type) :custom-show t)
1838 (widget-put (get 'editable-field 'widget-type)
1839 :custom-show (lambda (_widget value)
1840 (let ((pp (pp-to-string value)))
1841 (cond ((string-match-p "\n" pp)
1842 nil)
1843 ((> (length pp) 40)
1844 nil)
1845 (t t)))))
1846 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1848 ;;; The `custom-manual' Widget.
1850 (define-widget 'custom-manual 'info-link
1851 "Link to the manual entry for this customization option."
1852 :help-echo "Read the manual entry for this option."
1853 :keymap custom-mode-link-map
1854 :follow-link 'mouse-face
1855 :button-face 'custom-link
1856 :mouse-face 'highlight
1857 :pressed-face 'highlight
1858 :tag "Manual")
1860 ;;; The `custom-magic' Widget.
1862 (defgroup custom-magic-faces nil
1863 "Faces used by the magic button."
1864 :group 'custom-faces
1865 :group 'custom-buffer)
1867 (defface custom-invalid '((((class color))
1868 :foreground "yellow1" :background "red1")
1869 (t :weight bold :slant italic :underline t))
1870 "Face used when the customize item is invalid."
1871 :group 'custom-magic-faces)
1873 (defface custom-rogue '((((class color))
1874 :foreground "pink" :background "black")
1875 (t :underline t))
1876 "Face used when the customize item is not defined for customization."
1877 :group 'custom-magic-faces)
1879 (defface custom-modified '((((min-colors 88) (class color))
1880 :foreground "white" :background "blue1")
1881 (((class color))
1882 :foreground "white" :background "blue")
1883 (t :slant italic))
1884 "Face used when the customize item has been modified."
1885 :group 'custom-magic-faces)
1887 (defface custom-set '((((min-colors 88) (class color))
1888 :foreground "blue1" :background "white")
1889 (((class color))
1890 :foreground "blue" :background "white")
1891 (t :slant italic))
1892 "Face used when the customize item has been set."
1893 :group 'custom-magic-faces)
1895 (defface custom-changed '((((min-colors 88) (class color))
1896 :foreground "white" :background "blue1")
1897 (((class color))
1898 :foreground "white" :background "blue")
1899 (t :slant italic))
1900 "Face used when the customize item has been changed."
1901 :group 'custom-magic-faces)
1903 (defface custom-themed '((((min-colors 88) (class color))
1904 :foreground "white" :background "blue1")
1905 (((class color))
1906 :foreground "white" :background "blue")
1907 (t :slant italic))
1908 "Face used when the customize item has been set by a theme."
1909 :group 'custom-magic-faces)
1911 (defface custom-saved '((t :underline t))
1912 "Face used when the customize item has been saved."
1913 :group 'custom-magic-faces)
1915 (defconst custom-magic-alist
1916 '((nil "#" underline "\
1917 UNINITIALIZED, you should not see this.")
1918 (unknown "?" italic "\
1919 UNKNOWN, you should not see this.")
1920 (hidden "-" default "\
1921 HIDDEN, invoke \"Show\" in the previous line to show." "\
1922 group now hidden, invoke \"Show\", above, to show contents.")
1923 (invalid "x" custom-invalid "\
1924 INVALID, the displayed value cannot be set.")
1925 (modified "*" custom-modified "\
1926 EDITED, shown value does not take effect until you set or save it." "\
1927 something in this group has been edited but not set.")
1928 (set "+" custom-set "\
1929 SET for current session only." "\
1930 something in this group has been set but not saved.")
1931 (changed ":" custom-changed "\
1932 CHANGED outside Customize." "\
1933 something in this group has been changed outside customize.")
1934 (saved "!" custom-saved "\
1935 SAVED and set." "\
1936 something in this group has been set and saved.")
1937 (themed "o" custom-themed "\
1938 THEMED." "\
1939 visible group members are set by enabled themes.")
1940 (rogue "@" custom-rogue "\
1941 NO CUSTOMIZATION DATA; not intended to be customized." "\
1942 something in this group is not prepared for customization.")
1943 (standard " " nil "\
1944 STANDARD." "\
1945 visible group members are all at standard values."))
1946 "Alist of customize option states.
1947 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1949 STATE is one of the following symbols:
1951 `nil'
1952 For internal use, should never occur.
1953 `unknown'
1954 For internal use, should never occur.
1955 `hidden'
1956 This item is not being displayed.
1957 `invalid'
1958 This item is modified, but has an invalid form.
1959 `modified'
1960 This item is modified, and has a valid form.
1961 `set'
1962 This item has been set but not saved.
1963 `changed'
1964 The current value of this item has been changed outside Customize.
1965 `saved'
1966 This item is marked for saving.
1967 `rogue'
1968 This item has no customization information.
1969 `themed'
1970 This item was set by an enabled Custom theme.
1971 `standard'
1972 This item is unchanged from the standard setting.
1974 MAGIC is a string used to present that state.
1976 FACE is a face used to present the state.
1978 ITEM-DESC is a string describing the state for options.
1980 GROUP-DESC is a string describing the state for groups. If this is
1981 left out, ITEM-DESC will be used.
1983 The string %c in either description will be replaced with the
1984 category of the item. These are `group', `option', and `face'.
1986 The list should be sorted most significant first.")
1988 (defcustom custom-magic-show 'long
1989 "If non-nil, show textual description of the state.
1990 If `long', show a full-line description, not just one word."
1991 :type '(choice (const :tag "no" nil)
1992 (const long)
1993 (other :tag "short" short))
1994 :group 'custom-buffer)
1996 (defcustom custom-magic-show-hidden '(option face)
1997 "Control whether the State button is shown for hidden items.
1998 The value should be a list with the custom categories where the State
1999 button should be visible. Possible categories are `group', `option',
2000 and `face'."
2001 :type '(set (const group) (const option) (const face))
2002 :group 'custom-buffer)
2004 (defcustom custom-magic-show-button nil
2005 "Show a \"magic\" button indicating the state of each customization option."
2006 :type 'boolean
2007 :group 'custom-buffer)
2009 (define-widget 'custom-magic 'default
2010 "Show and manipulate state for a customization option."
2011 :format "%v"
2012 :action 'widget-parent-action
2013 :notify 'ignore
2014 :value-get 'ignore
2015 :value-create 'custom-magic-value-create
2016 :value-delete 'widget-children-value-delete)
2018 (defun widget-magic-mouse-down-action (widget &optional _event)
2019 ;; Non-nil unless hidden.
2020 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
2021 :custom-state)
2022 'hidden)))
2024 (defun custom-magic-value-create (widget)
2025 "Create compact status report for WIDGET."
2026 (let* ((parent (widget-get widget :parent))
2027 (state (widget-get parent :custom-state))
2028 (hidden (eq state 'hidden))
2029 (entry (assq state custom-magic-alist))
2030 (magic (nth 1 entry))
2031 (face (nth 2 entry))
2032 (category (widget-get parent :custom-category))
2033 (text (or (and (eq category 'group)
2034 (nth 4 entry))
2035 (nth 3 entry)))
2036 (form (widget-get parent :custom-form))
2037 children)
2038 (unless (eq state 'hidden)
2039 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
2040 (setq text (concat (match-string 1 text)
2041 (symbol-name category)
2042 (match-string 2 text))))
2043 (when (and custom-magic-show
2044 (or (not hidden)
2045 (memq category custom-magic-show-hidden)))
2046 (insert " ")
2047 (when (and (eq category 'group)
2048 (not (and (eq custom-buffer-style 'links)
2049 (> (widget-get parent :custom-level) 1))))
2050 (insert-char ?\s (* custom-buffer-indent
2051 (widget-get parent :custom-level))))
2052 (push (widget-create-child-and-convert
2053 widget 'choice-item
2054 :help-echo "Change the state of this item."
2055 :format (if hidden "%t" "%[%t%]")
2056 :button-prefix 'widget-push-button-prefix
2057 :button-suffix 'widget-push-button-suffix
2058 :mouse-down-action 'widget-magic-mouse-down-action
2059 :tag " State ")
2060 children)
2061 (insert ": ")
2062 (let ((start (point)))
2063 (if (eq custom-magic-show 'long)
2064 (insert text)
2065 (insert (symbol-name state)))
2066 (cond ((eq form 'lisp)
2067 (insert " (lisp)"))
2068 ((eq form 'mismatch)
2069 (insert " (mismatch)")))
2070 (put-text-property start (point) 'face 'custom-state))
2071 (insert "\n"))
2072 (when (and (eq category 'group)
2073 (not (and (eq custom-buffer-style 'links)
2074 (> (widget-get parent :custom-level) 1))))
2075 (insert-char ?\s (* custom-buffer-indent
2076 (widget-get parent :custom-level))))
2077 (when custom-magic-show-button
2078 (when custom-magic-show
2079 (let ((indent (widget-get parent :indent)))
2080 (when indent
2081 (insert-char ? indent))))
2082 (push (widget-create-child-and-convert
2083 widget 'choice-item
2084 :mouse-down-action 'widget-magic-mouse-down-action
2085 :button-face face
2086 :button-prefix ""
2087 :button-suffix ""
2088 :help-echo "Change the state."
2089 :format (if hidden "%t" "%[%t%]")
2090 :tag (if (memq form '(lisp mismatch))
2091 (concat "(" magic ")")
2092 (concat "[" magic "]")))
2093 children)
2094 (insert " "))
2095 (widget-put widget :children children))))
2097 (defun custom-magic-reset (widget)
2098 "Redraw the :custom-magic property of WIDGET."
2099 (let ((magic (widget-get widget :custom-magic)))
2100 (when magic
2101 (widget-value-set magic (widget-value magic)))))
2103 ;;; The `custom' Widget.
2105 (defface custom-button
2106 '((((type x w32 ns) (class color)) ; Like default mode line
2107 :box (:line-width 2 :style released-button)
2108 :background "lightgrey" :foreground "black"))
2109 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2110 :version "21.1"
2111 :group 'custom-faces)
2113 (defface custom-button-mouse
2114 '((((type x w32 ns) (class color))
2115 :box (:line-width 2 :style released-button)
2116 :background "grey90" :foreground "black")
2118 ;; This is for text terminals that support mouse, like GPM mouse
2119 ;; or the MS-DOS terminal: inverse-video makes the button stand
2120 ;; out on mouse-over.
2121 :inverse-video t))
2122 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2123 :version "22.1"
2124 :group 'custom-faces)
2126 (defface custom-button-unraised
2127 '((t :inherit underline))
2128 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2129 :version "22.1"
2130 :group 'custom-faces)
2132 (setq custom-button
2133 (if custom-raised-buttons 'custom-button 'custom-button-unraised))
2135 (setq custom-button-mouse
2136 (if custom-raised-buttons 'custom-button-mouse 'highlight))
2138 (defface custom-button-pressed
2139 '((((type x w32 ns) (class color))
2140 :box (:line-width 2 :style pressed-button)
2141 :background "lightgrey" :foreground "black")
2142 (t :inverse-video t))
2143 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2144 :version "21.1"
2145 :group 'custom-faces)
2147 (defface custom-button-pressed-unraised
2148 '((default :inherit custom-button-unraised)
2149 (((class color) (background light)) :foreground "magenta4")
2150 (((class color) (background dark)) :foreground "violet"))
2151 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2152 :version "22.1"
2153 :group 'custom-faces)
2155 (setq custom-button-pressed
2156 (if custom-raised-buttons
2157 'custom-button-pressed
2158 'custom-button-pressed-unraised))
2160 (defface custom-documentation '((t nil))
2161 "Face used for documentation strings in customization buffers."
2162 :group 'custom-faces)
2164 (defface custom-state '((((class color) (background dark))
2165 :foreground "lime green")
2166 (((class color) (background light))
2167 :foreground "dark green"))
2168 "Face used for State descriptions in the customize buffer."
2169 :group 'custom-faces)
2171 (defface custom-link '((t :inherit link))
2172 "Face for links in customization buffers."
2173 :version "22.1"
2174 :group 'custom-faces)
2176 (define-widget 'custom 'default
2177 "Customize a user option."
2178 :format "%v"
2179 :convert-widget 'custom-convert-widget
2180 :notify 'custom-notify
2181 :custom-prefix ""
2182 :custom-level 1
2183 :custom-state 'hidden
2184 :documentation-property 'widget-subclass-responsibility
2185 :value-create 'widget-subclass-responsibility
2186 :value-delete 'widget-children-value-delete
2187 :value-get 'widget-value-value-get
2188 :validate 'widget-children-validate
2189 :match (lambda (_widget value) (symbolp value)))
2191 (defun custom-convert-widget (widget)
2192 "Initialize :value and :tag from :args in WIDGET."
2193 (let ((args (widget-get widget :args)))
2194 (when args
2195 (widget-put widget :value (widget-apply widget
2196 :value-to-internal (car args)))
2197 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
2198 (widget-put widget :args nil)))
2199 widget)
2201 (defun custom-notify (widget &rest args)
2202 "Keep track of changes."
2203 (let ((state (widget-get widget :custom-state)))
2204 (unless (eq state 'modified)
2205 (unless (memq state '(nil unknown hidden))
2206 (widget-put widget :custom-state 'modified))
2207 (custom-magic-reset widget)
2208 (apply 'widget-default-notify widget args))))
2210 (defun custom-redraw (widget)
2211 "Redraw WIDGET with current settings."
2212 (let ((line (count-lines (point-min) (point)))
2213 (column (current-column))
2214 (pos (point))
2215 (from (marker-position (widget-get widget :from)))
2216 (to (marker-position (widget-get widget :to))))
2217 (save-excursion
2218 (widget-value-set widget (widget-value widget))
2219 (custom-redraw-magic widget))
2220 (when (and (>= pos from) (<= pos to))
2221 (condition-case nil
2222 (progn
2223 (goto-char (point-min))
2224 (forward-line (if (> column 0)
2225 (1- line)
2226 line))
2227 (move-to-column column))
2228 (error nil)))))
2230 (defun custom-redraw-magic (widget)
2231 "Redraw WIDGET state with current settings."
2232 (while widget
2233 (let ((magic (widget-get widget :custom-magic)))
2234 (cond (magic
2235 (widget-value-set magic (widget-value magic))
2236 (when (setq widget (widget-get widget :group))
2237 (custom-group-state-update widget)))
2239 (setq widget nil)))))
2240 (widget-setup))
2242 (defun custom-show (widget value)
2243 "Non-nil if WIDGET should be shown with VALUE by default."
2244 (declare (obsolete "this widget type is no longer supported." "24.1"))
2245 (let ((show (widget-get widget :custom-show)))
2246 (if (functionp show)
2247 (funcall show widget value)
2248 show)))
2250 (defun custom-load-widget (widget)
2251 "Load all dependencies for WIDGET."
2252 (custom-load-symbol (widget-value widget)))
2254 (defun custom-unloaded-symbol-p (symbol)
2255 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2256 (let ((found nil)
2257 (loads (get symbol 'custom-loads))
2258 load)
2259 (while loads
2260 (setq load (car loads)
2261 loads (cdr loads))
2262 (cond ((symbolp load)
2263 (unless (featurep load)
2264 (setq found t)))
2265 ((assoc load load-history))
2266 ((assoc (locate-library load) load-history)
2267 (message nil))
2269 (setq found t))))
2270 found))
2272 (defun custom-unloaded-widget-p (widget)
2273 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2274 (custom-unloaded-symbol-p (widget-value widget)))
2276 (defun custom-toggle-hide (widget)
2277 "Toggle visibility of WIDGET."
2278 (custom-load-widget widget)
2279 (let ((state (widget-get widget :custom-state)))
2280 (cond ((memq state '(invalid modified set))
2281 (error "There are unsaved changes"))
2282 ((eq state 'hidden)
2283 (widget-put widget :custom-state 'unknown))
2285 (widget-put widget :documentation-shown nil)
2286 (widget-put widget :custom-state 'hidden)))
2287 (custom-redraw widget)
2288 (widget-setup)))
2290 (defun custom-toggle-parent (widget &rest _ignore)
2291 "Toggle visibility of parent of WIDGET."
2292 (custom-toggle-hide (widget-get widget :parent)))
2294 (defun custom-add-see-also (widget &optional prefix)
2295 "Add `See also ...' to WIDGET if there are any links.
2296 Insert PREFIX first if non-nil."
2297 (let* ((symbol (widget-get widget :value))
2298 (links (get symbol 'custom-links))
2299 (many (> (length links) 2))
2300 (buttons (widget-get widget :buttons))
2301 (indent (widget-get widget :indent)))
2302 (when links
2303 (when indent
2304 (insert-char ?\s indent))
2305 (when prefix
2306 (insert prefix))
2307 (insert "See also ")
2308 (while links
2309 (push (widget-create-child-and-convert
2310 widget (car links)
2311 :button-face 'custom-link
2312 :mouse-face 'highlight
2313 :pressed-face 'highlight)
2314 buttons)
2315 (setq links (cdr links))
2316 (cond ((null links)
2317 (insert ".\n"))
2318 ((null (cdr links))
2319 (if many
2320 (insert ", and ")
2321 (insert " and ")))
2323 (insert ", "))))
2324 (widget-put widget :buttons buttons))))
2326 (defun custom-add-parent-links (widget &optional initial-string _doc-initial-string)
2327 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2328 The value is non-nil if any parents were found.
2329 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2330 (let ((name (widget-value widget))
2331 (type (widget-type widget))
2332 (buttons (widget-get widget :buttons))
2333 (start (point))
2334 (parents nil))
2335 (insert (or initial-string "Groups:"))
2336 (mapatoms (lambda (symbol)
2337 (when (member (list name type) (get symbol 'custom-group))
2338 (insert " ")
2339 (push (widget-create-child-and-convert
2340 widget 'custom-group-link
2341 :tag (custom-unlispify-tag-name symbol)
2342 symbol)
2343 buttons)
2344 (setq parents (cons symbol parents)))))
2345 (if parents
2346 (insert "\n")
2347 (delete-region start (point)))
2348 (widget-put widget :buttons buttons)
2349 parents))
2351 ;;; The `custom-comment' Widget.
2353 ;; like the editable field
2354 (defface custom-comment '((((type tty))
2355 :background "yellow3"
2356 :foreground "black")
2357 (((class grayscale color)
2358 (background light))
2359 :background "gray85")
2360 (((class grayscale color)
2361 (background dark))
2362 :background "dim gray")
2364 :slant italic))
2365 "Face used for comments on variables or faces."
2366 :version "21.1"
2367 :group 'custom-faces)
2369 ;; like font-lock-comment-face
2370 (defface custom-comment-tag
2371 '((((class color) (background dark)) :foreground "gray80")
2372 (((class color) (background light)) :foreground "blue4")
2373 (((class grayscale) (background light))
2374 :foreground "DimGray" :weight bold :slant italic)
2375 (((class grayscale) (background dark))
2376 :foreground "LightGray" :weight bold :slant italic)
2377 (t :weight bold))
2378 "Face used for the comment tag on variables or faces."
2379 :group 'custom-faces)
2381 (define-widget 'custom-comment 'string
2382 "User comment."
2383 :tag "Comment"
2384 :help-echo "Edit a comment here."
2385 :sample-face 'custom-comment-tag
2386 :value-face 'custom-comment
2387 :shown nil
2388 :create 'custom-comment-create)
2390 (defun custom-comment-create (widget)
2391 (let* ((null-comment (equal "" (widget-value widget))))
2392 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2393 (not null-comment))
2394 (widget-default-create widget)
2395 ;; `widget-default-delete' expects markers in these slots --
2396 ;; maybe it shouldn't.
2397 (widget-put widget :from (point-marker))
2398 (widget-put widget :to (point-marker)))))
2400 (defun custom-comment-hide (widget)
2401 (widget-put (widget-get widget :parent) :comment-shown nil))
2403 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2404 ;; the global custom one
2405 (defun custom-comment-show (widget)
2406 (widget-put widget :comment-shown t)
2407 (custom-redraw widget)
2408 (widget-setup))
2410 (defun custom-comment-invisible-p (widget)
2411 (let ((val (widget-value (widget-get widget :comment-widget))))
2412 (and (equal "" val)
2413 (not (widget-get widget :comment-shown)))))
2415 ;;; The `custom-variable' Widget.
2417 (defface custom-variable-tag
2418 `((((class color) (background dark))
2419 :foreground "light blue" :weight bold)
2420 (((min-colors 88) (class color) (background light))
2421 :foreground "blue1" :weight bold)
2422 (((class color) (background light))
2423 :foreground "blue" :weight bold)
2424 (t :weight bold))
2425 "Face used for unpushable variable tags."
2426 :group 'custom-faces)
2428 (defface custom-variable-button '((t :underline t :weight bold))
2429 "Face used for pushable variable tags."
2430 :group 'custom-faces)
2432 (defcustom custom-variable-default-form 'edit
2433 "Default form of displaying variable values."
2434 :type '(choice (const edit)
2435 (const lisp))
2436 :group 'custom-buffer
2437 :version "20.3")
2439 (defun custom-variable-documentation (variable)
2440 "Return documentation of VARIABLE for use in Custom buffer.
2441 Normally just return the docstring. But if VARIABLE automatically
2442 becomes buffer local when set, append a message to that effect."
2443 (format "%s%s" (documentation-property variable 'variable-documentation)
2444 (if (and (local-variable-if-set-p variable)
2445 (or (not (local-variable-p variable))
2446 (with-temp-buffer
2447 (local-variable-if-set-p variable))))
2449 This variable automatically becomes buffer-local when set outside Custom.
2450 However, setting it through Custom sets the default value."
2451 "")))
2453 (define-widget 'custom-variable 'custom
2454 "A widget for displaying a Custom variable.
2455 The following properties have special meanings for this widget:
2457 :hidden-states should be a list of widget states for which the
2458 widget's initial contents are to be hidden.
2460 :custom-form should be a symbol describing how to display and
2461 edit the variable---either `edit' (using edit widgets),
2462 `lisp' (as a Lisp sexp), or `mismatch' (should not happen);
2463 if nil, use the return value of `custom-variable-default-form'.
2465 :shown-value, if non-nil, should be a list whose `car' is the
2466 variable value to display in place of the current value.
2468 :custom-style describes the widget interface style; nil is the
2469 default style, while `simple' means a simpler interface that
2470 inhibits the magic custom-state widget."
2471 :format "%v"
2472 :help-echo "Set or reset this variable."
2473 :documentation-property #'custom-variable-documentation
2474 :custom-category 'option
2475 :custom-state nil
2476 :custom-menu 'custom-variable-menu-create
2477 :custom-form nil
2478 :value-create 'custom-variable-value-create
2479 :action 'custom-variable-action
2480 :hidden-states '(standard)
2481 :custom-set 'custom-variable-set
2482 :custom-mark-to-save 'custom-variable-mark-to-save
2483 :custom-reset-current 'custom-redraw
2484 :custom-reset-saved 'custom-variable-reset-saved
2485 :custom-reset-standard 'custom-variable-reset-standard
2486 :custom-mark-to-reset-standard 'custom-variable-mark-to-reset-standard
2487 :custom-standard-value 'custom-variable-standard-value
2488 :custom-state-set-and-redraw 'custom-variable-state-set-and-redraw)
2490 (defun custom-variable-type (symbol)
2491 "Return a widget suitable for editing the value of SYMBOL.
2492 If SYMBOL has a `custom-type' property, use that.
2493 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2494 try matching its doc string against `custom-guess-doc-alist'."
2495 (let* ((type (or (get symbol 'custom-type)
2496 (and (not (get symbol 'standard-value))
2497 (custom-guess-type symbol))
2498 'sexp))
2499 (options (get symbol 'custom-options))
2500 (tmp (if (listp type)
2501 (copy-sequence type)
2502 (list type))))
2503 (when options
2504 (widget-put tmp :options options))
2505 tmp))
2507 (defun custom-variable-value-create (widget)
2508 "Here is where you edit the variable's value."
2509 (custom-load-widget widget)
2510 (unless (widget-get widget :custom-form)
2511 (widget-put widget :custom-form custom-variable-default-form))
2512 (let* ((buttons (widget-get widget :buttons))
2513 (children (widget-get widget :children))
2514 (form (widget-get widget :custom-form))
2515 (symbol (widget-get widget :value))
2516 (tag (widget-get widget :tag))
2517 (type (custom-variable-type symbol))
2518 (conv (widget-convert type))
2519 (get (or (get symbol 'custom-get) 'default-value))
2520 (prefix (widget-get widget :custom-prefix))
2521 (last (widget-get widget :custom-last))
2522 (style (widget-get widget :custom-style))
2523 (value (let ((shown-value (widget-get widget :shown-value)))
2524 (cond (shown-value
2525 (car shown-value))
2526 ((default-boundp symbol)
2527 (funcall get symbol))
2528 (t (widget-get conv :value)))))
2529 (state (or (widget-get widget :custom-state)
2530 (if (memq (custom-variable-state symbol value)
2531 (widget-get widget :hidden-states))
2532 'hidden))))
2534 ;; If we don't know the state, see if we need to edit it in lisp form.
2535 (unless state
2536 (setq state (if (custom-show type value) 'unknown 'hidden)))
2537 (when (eq state 'unknown)
2538 (unless (widget-apply conv :match value)
2539 (setq form 'mismatch)))
2540 ;; Now we can create the child widget.
2541 (cond ((eq custom-buffer-style 'tree)
2542 (insert prefix (if last " `--- " " |--- "))
2543 (push (widget-create-child-and-convert
2544 widget 'custom-browse-variable-tag)
2545 buttons)
2546 (insert " " tag "\n")
2547 (widget-put widget :buttons buttons))
2548 ((eq state 'hidden)
2549 ;; Indicate hidden value.
2550 (push (widget-create-child-and-convert
2551 widget 'custom-visibility
2552 :help-echo "Show the value of this option."
2553 :on-glyph "down"
2554 :on "Hide"
2555 :off-glyph "right"
2556 :off "Show Value"
2557 :action 'custom-toggle-hide-variable
2558 nil)
2559 buttons)
2560 (insert " ")
2561 (push (widget-create-child-and-convert
2562 widget 'item
2563 :format "%{%t%} "
2564 :sample-face 'custom-variable-tag
2565 :tag tag
2566 :parent widget)
2567 buttons))
2568 ((memq form '(lisp mismatch))
2569 (push (widget-create-child-and-convert
2570 widget 'custom-visibility
2571 :help-echo "Hide the value of this option."
2572 :on "Hide"
2573 :off "Show"
2574 :on-glyph "down"
2575 :off-glyph "right"
2576 :action 'custom-toggle-hide-variable
2578 buttons)
2579 (insert " ")
2580 ;; This used to try presenting the saved value or the
2581 ;; standard value, but it seems more intuitive to present
2582 ;; the current value (Bug#7600).
2583 (let* ((value (cond ((default-boundp symbol)
2584 (custom-quote (funcall get symbol)))
2586 (custom-quote (widget-get conv :value))))))
2587 (insert (symbol-name symbol) ": ")
2588 (push (widget-create-child-and-convert
2589 widget 'sexp
2590 :button-face 'custom-variable-button-face
2591 :format "%v"
2592 :tag (symbol-name symbol)
2593 :parent widget
2594 :value value)
2595 children)))
2597 ;; Edit mode.
2598 (push (widget-create-child-and-convert
2599 widget 'custom-visibility
2600 :help-echo "Hide or show this option."
2601 :on "Hide"
2602 :off "Show"
2603 :on-glyph "down"
2604 :off-glyph "right"
2605 :action 'custom-toggle-hide-variable
2607 buttons)
2608 (insert " ")
2609 (let* ((format (widget-get type :format))
2610 tag-format value-format)
2611 (unless (string-match ":" format)
2612 (error "Bad format"))
2613 (setq tag-format (substring format 0 (match-end 0)))
2614 (setq value-format (substring format (match-end 0)))
2615 (push (widget-create-child-and-convert
2616 widget 'item
2617 :format tag-format
2618 :action 'custom-tag-action
2619 :help-echo "Change value of this option."
2620 :mouse-down-action 'custom-tag-mouse-down-action
2621 :button-face 'custom-variable-button
2622 :sample-face 'custom-variable-tag
2623 tag)
2624 buttons)
2625 (push (widget-create-child-and-convert
2626 widget type
2627 :format value-format
2628 :value value)
2629 children))))
2630 (unless (eq custom-buffer-style 'tree)
2631 (unless (eq (preceding-char) ?\n)
2632 (widget-insert "\n"))
2633 ;; Create the magic button.
2634 (unless (eq style 'simple)
2635 (let ((magic (widget-create-child-and-convert
2636 widget 'custom-magic nil)))
2637 (widget-put widget :custom-magic magic)
2638 (push magic buttons)))
2639 (widget-put widget :buttons buttons)
2640 ;; Insert documentation.
2641 (widget-put widget :documentation-indent 3)
2642 (unless (and (eq style 'simple)
2643 (eq state 'hidden))
2644 (widget-add-documentation-string-button
2645 widget :visibility-widget 'custom-visibility))
2647 ;; The comment field
2648 (unless (eq state 'hidden)
2649 (let* ((comment (get symbol 'variable-comment))
2650 (comment-widget
2651 (widget-create-child-and-convert
2652 widget 'custom-comment
2653 :parent widget
2654 :value (or comment ""))))
2655 (widget-put widget :comment-widget comment-widget)
2656 ;; Don't push it !!! Custom assumes that the first child is the
2657 ;; value one.
2658 (setq children (append children (list comment-widget)))))
2659 ;; Update the rest of the properties.
2660 (widget-put widget :custom-form form)
2661 (widget-put widget :children children)
2662 ;; Now update the state.
2663 (if (eq state 'hidden)
2664 (widget-put widget :custom-state state)
2665 (custom-variable-state-set widget))
2666 ;; See also.
2667 (unless (eq state 'hidden)
2668 (when (eq (widget-get widget :custom-level) 1)
2669 (custom-add-parent-links widget))
2670 (custom-add-see-also widget)))))
2672 (defun custom-toggle-hide-variable (visibility-widget &rest _ignore)
2673 "Toggle the visibility of a `custom-variable' parent widget.
2674 By default, this signals an error if the parent has unsaved
2675 changes. If the parent has a `simple' :custom-style property,
2676 the present value is saved to its :shown-value property instead."
2677 (let ((widget (widget-get visibility-widget :parent)))
2678 (unless (eq (widget-type widget) 'custom-variable)
2679 (error "Invalid widget type"))
2680 (custom-load-widget widget)
2681 (let ((state (widget-get widget :custom-state)))
2682 (if (eq state 'hidden)
2683 (widget-put widget :custom-state 'unknown)
2684 ;; In normal interface, widget can't be hidden if modified.
2685 (when (memq state '(invalid modified set))
2686 (if (eq (widget-get widget :custom-style) 'simple)
2687 (widget-put widget :shown-value
2688 (list (widget-value
2689 (car-safe
2690 (widget-get widget :children)))))
2691 (error "There are unsaved changes")))
2692 (widget-put widget :documentation-shown nil)
2693 (widget-put widget :custom-state 'hidden))
2694 (custom-redraw widget)
2695 (widget-setup))))
2697 (defun custom-tag-action (widget &rest args)
2698 "Pass :action to first child of WIDGET's parent."
2699 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2700 :action args))
2702 (defun custom-tag-mouse-down-action (widget &rest args)
2703 "Pass :mouse-down-action to first child of WIDGET's parent."
2704 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2705 :mouse-down-action args))
2707 (defun custom-variable-state (symbol val)
2708 "Return the state of SYMBOL if its value is VAL.
2709 If SYMBOL has a non-nil `custom-get' property, it overrides VAL.
2710 Possible return values are `standard', `saved', `set', `themed',
2711 `changed', and `rogue'."
2712 (let* ((get (or (get symbol 'custom-get) 'default-value))
2713 (value (if (default-boundp symbol)
2714 (funcall get symbol)
2715 val))
2716 (comment (get symbol 'variable-comment))
2718 temp)
2719 (cond ((progn (setq tmp (get symbol 'customized-value))
2720 (setq temp
2721 (get symbol 'customized-variable-comment))
2722 (or tmp temp))
2723 (if (condition-case nil
2724 (and (equal value (eval (car tmp)))
2725 (equal comment temp))
2726 (error nil))
2727 'set
2728 'changed))
2729 ((progn (setq tmp (get symbol 'theme-value))
2730 (setq temp (get symbol 'saved-variable-comment))
2731 (or tmp temp))
2732 (if (condition-case nil
2733 (and (equal comment temp)
2734 (equal value
2735 (eval
2736 (car (custom-variable-theme-value
2737 symbol)))))
2738 (error nil))
2739 (cond
2740 ((eq (caar tmp) 'user) 'saved)
2741 ((eq (caar tmp) 'changed)
2742 (if (condition-case nil
2743 (and (null comment)
2744 (equal value
2745 (eval
2746 (car (get symbol 'standard-value)))))
2747 (error nil))
2748 ;; The value was originally set outside
2749 ;; custom, but it was set to the standard
2750 ;; value (probably an autoloaded defcustom).
2751 'standard
2752 'changed))
2753 (t 'themed))
2754 'changed))
2755 ((setq tmp (get symbol 'standard-value))
2756 (if (condition-case nil
2757 (and (equal value (eval (car tmp)))
2758 (equal comment nil))
2759 (error nil))
2760 'standard
2761 'changed))
2762 (t 'rogue))))
2764 (defun custom-variable-state-set (widget &optional state)
2765 "Set the state of WIDGET to STATE.
2766 If STATE is nil, the value is computed by `custom-variable-state'."
2767 (widget-put widget :custom-state
2768 (or state (custom-variable-state (widget-value widget)
2769 (widget-get widget :value)))))
2771 (defun custom-variable-standard-value (widget)
2772 (get (widget-value widget) 'standard-value))
2774 (defvar custom-variable-menu
2775 `(("Set for Current Session" custom-variable-set
2776 (lambda (widget)
2777 (eq (widget-get widget :custom-state) 'modified)))
2778 ;; Note that in all the backquoted code in this file, we test
2779 ;; init-file-user rather than user-init-file. This is in case
2780 ;; cus-edit is loaded by something in site-start.el, because
2781 ;; user-init-file is not set at that stage.
2782 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2783 ,@(when (or custom-file init-file-user)
2784 '(("Save for Future Sessions" custom-variable-save
2785 (lambda (widget)
2786 (memq (widget-get widget :custom-state)
2787 '(modified set changed rogue))))))
2788 ("Undo Edits" custom-redraw
2789 (lambda (widget)
2790 (and (default-boundp (widget-value widget))
2791 (memq (widget-get widget :custom-state) '(modified changed)))))
2792 ("Revert This Session's Customization" custom-variable-reset-saved
2793 (lambda (widget)
2794 (memq (widget-get widget :custom-state)
2795 '(modified set changed rogue))))
2796 ,@(when (or custom-file init-file-user)
2797 '(("Erase Customization" custom-variable-reset-standard
2798 (lambda (widget)
2799 (and (get (widget-value widget) 'standard-value)
2800 (memq (widget-get widget :custom-state)
2801 '(modified set changed saved rogue)))))))
2802 ("Set to Backup Value" custom-variable-reset-backup
2803 (lambda (widget)
2804 (get (widget-value widget) 'backup-value)))
2805 ("---" ignore ignore)
2806 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2807 ("---" ignore ignore)
2808 ("Show Current Value" custom-variable-edit
2809 (lambda (widget)
2810 (eq (widget-get widget :custom-form) 'lisp)))
2811 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2812 (lambda (widget)
2813 (eq (widget-get widget :custom-form) 'edit))))
2814 "Alist of actions for the `custom-variable' widget.
2815 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2816 the menu entry, ACTION is the function to call on the widget when the
2817 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2818 widget as an argument, and returns non-nil if ACTION is valid on that
2819 widget. If FILTER is nil, ACTION is always valid.")
2821 (defun custom-variable-action (widget &optional event)
2822 "Show the menu for `custom-variable' WIDGET.
2823 Optional EVENT is the location for the menu."
2824 (if (eq (widget-get widget :custom-state) 'hidden)
2825 (custom-toggle-hide widget)
2826 (unless (eq (widget-get widget :custom-state) 'modified)
2827 (custom-variable-state-set widget))
2828 (custom-redraw-magic widget)
2829 (let* ((completion-ignore-case t)
2830 (answer (widget-choose (concat "Operation on "
2831 (custom-unlispify-tag-name
2832 (widget-get widget :value)))
2833 (custom-menu-filter custom-variable-menu
2834 widget)
2835 event)))
2836 (if answer
2837 (funcall answer widget)))))
2839 (defun custom-variable-edit (widget)
2840 "Edit value of WIDGET."
2841 (widget-put widget :custom-state 'unknown)
2842 (widget-put widget :custom-form 'edit)
2843 (custom-redraw widget))
2845 (defun custom-variable-edit-lisp (widget)
2846 "Edit the Lisp representation of the value of WIDGET."
2847 (widget-put widget :custom-state 'unknown)
2848 (widget-put widget :custom-form 'lisp)
2849 (custom-redraw widget))
2851 (defun custom-variable-set (widget)
2852 "Set the current value for the variable being edited by WIDGET."
2853 (let* ((form (widget-get widget :custom-form))
2854 (state (widget-get widget :custom-state))
2855 (child (car (widget-get widget :children)))
2856 (symbol (widget-value widget))
2857 (set (or (get symbol 'custom-set) 'set-default))
2858 (comment-widget (widget-get widget :comment-widget))
2859 (comment (widget-value comment-widget))
2860 val)
2861 (cond ((eq state 'hidden)
2862 (user-error "Cannot set hidden variable"))
2863 ((setq val (widget-apply child :validate))
2864 (goto-char (widget-get val :from))
2865 (error "%s" (widget-get val :error)))
2866 ((memq form '(lisp mismatch))
2867 (when (equal comment "")
2868 (setq comment nil)
2869 ;; Make the comment invisible by hand if it's empty
2870 (custom-comment-hide comment-widget))
2871 (custom-variable-backup-value widget)
2872 (custom-push-theme 'theme-value symbol 'user
2873 'set (custom-quote (widget-value child)))
2874 (funcall set symbol (eval (setq val (widget-value child))))
2875 (put symbol 'customized-value (list val))
2876 (put symbol 'variable-comment comment)
2877 (put symbol 'customized-variable-comment comment))
2879 (when (equal comment "")
2880 (setq comment nil)
2881 ;; Make the comment invisible by hand if it's empty
2882 (custom-comment-hide comment-widget))
2883 (custom-variable-backup-value widget)
2884 (custom-push-theme 'theme-value symbol 'user
2885 'set (custom-quote (widget-value child)))
2886 (funcall set symbol (setq val (widget-value child)))
2887 (put symbol 'customized-value (list (custom-quote val)))
2888 (put symbol 'variable-comment comment)
2889 (put symbol 'customized-variable-comment comment)))
2890 (custom-variable-state-set widget)
2891 (custom-redraw-magic widget)))
2893 (defun custom-variable-mark-to-save (widget)
2894 "Set value and mark for saving the variable edited by WIDGET."
2895 (let* ((form (widget-get widget :custom-form))
2896 (state (widget-get widget :custom-state))
2897 (child (car (widget-get widget :children)))
2898 (symbol (widget-value widget))
2899 (set (or (get symbol 'custom-set) 'set-default))
2900 (comment-widget (widget-get widget :comment-widget))
2901 (comment (widget-value comment-widget))
2902 val)
2903 (cond ((eq state 'hidden)
2904 (user-error "Cannot set hidden variable"))
2905 ((setq val (widget-apply child :validate))
2906 (goto-char (widget-get val :from))
2907 (error "Saving %s: %s" symbol (widget-get val :error)))
2908 ((memq form '(lisp mismatch))
2909 (when (equal comment "")
2910 (setq comment nil)
2911 ;; Make the comment invisible by hand if it's empty
2912 (custom-comment-hide comment-widget))
2913 (put symbol 'saved-value (list (widget-value child)))
2914 (custom-push-theme 'theme-value symbol 'user
2915 'set (custom-quote (widget-value child)))
2916 (funcall set symbol (eval (widget-value child)))
2917 (put symbol 'variable-comment comment)
2918 (put symbol 'saved-variable-comment comment))
2920 (when (equal comment "")
2921 (setq comment nil)
2922 ;; Make the comment invisible by hand if it's empty
2923 (custom-comment-hide comment-widget))
2924 (put symbol 'saved-value
2925 (list (custom-quote (widget-value child))))
2926 (custom-push-theme 'theme-value symbol 'user
2927 'set (custom-quote (widget-value child)))
2928 (funcall set symbol (widget-value child))
2929 (put symbol 'variable-comment comment)
2930 (put symbol 'saved-variable-comment comment)))
2931 (put symbol 'customized-value nil)
2932 (put symbol 'customized-variable-comment nil)))
2934 (defsubst custom-variable-state-set-and-redraw (widget)
2935 "Set state of variable widget WIDGET and redraw with current settings."
2936 (custom-variable-state-set widget)
2937 (custom-redraw-magic widget))
2939 (defun custom-variable-save (widget)
2940 "Save value of variable edited by widget WIDGET."
2941 (custom-variable-mark-to-save widget)
2942 (custom-save-all)
2943 (custom-variable-state-set-and-redraw widget))
2945 (defun custom-variable-reset-saved (widget)
2946 "Restore the value of the variable being edited by WIDGET.
2947 If there is a saved value, restore it; otherwise reset to the
2948 uncustomized (themed or standard) value.
2950 Update the widget to show that value. The value that was current
2951 before this operation becomes the backup value."
2952 (let* ((symbol (widget-value widget))
2953 (saved-value (get symbol 'saved-value))
2954 (comment (get symbol 'saved-variable-comment)))
2955 (custom-variable-backup-value widget)
2956 (if (not (or saved-value comment))
2957 ;; If there is no saved value, remove the setting.
2958 (custom-push-theme 'theme-value symbol 'user 'reset)
2959 ;; Otherwise, apply the saved value.
2960 (put symbol 'variable-comment comment)
2961 (custom-push-theme 'theme-value symbol 'user 'set (car-safe saved-value))
2962 (ignore-errors
2963 (funcall (or (get symbol 'custom-set) 'set-default)
2964 symbol (eval (car saved-value)))))
2965 (put symbol 'customized-value nil)
2966 (put symbol 'customized-variable-comment nil)
2967 (widget-put widget :custom-state 'unknown)
2968 ;; This call will possibly make the comment invisible
2969 (custom-redraw widget)))
2971 (defun custom-variable-mark-to-reset-standard (widget)
2972 "Mark to restore standard setting for the variable edited by widget WIDGET.
2973 If `custom-reset-standard-variables-list' is nil, save, reset and
2974 redraw the widget immediately."
2975 (let* ((symbol (widget-value widget)))
2976 (if (get symbol 'standard-value)
2977 (custom-variable-backup-value widget)
2978 (user-error "No standard setting known for %S" symbol))
2979 (put symbol 'variable-comment nil)
2980 (put symbol 'customized-value nil)
2981 (put symbol 'customized-variable-comment nil)
2982 (custom-push-theme 'theme-value symbol 'user 'reset)
2983 (custom-theme-recalc-variable symbol)
2984 (if (and custom-reset-standard-variables-list
2985 (or (get symbol 'saved-value) (get symbol 'saved-variable-comment)))
2986 (progn
2987 (put symbol 'saved-value nil)
2988 (put symbol 'saved-variable-comment nil)
2989 ;; Append this to `custom-reset-standard-variables-list' to
2990 ;; have `custom-reset-standard-save-and-update' save setting
2991 ;; to the file, update the widget's state, and redraw it.
2992 (setq custom-reset-standard-variables-list
2993 (cons widget custom-reset-standard-variables-list)))
2994 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2995 (put symbol 'saved-value nil)
2996 (put symbol 'saved-variable-comment nil)
2997 (custom-save-all))
2998 (widget-put widget :custom-state 'unknown)
2999 ;; This call will possibly make the comment invisible
3000 (custom-redraw widget))))
3002 (defun custom-variable-reset-standard (widget)
3003 "Restore standard setting for the variable edited by WIDGET.
3004 This operation eliminates any saved setting for the variable,
3005 restoring it to the state of a variable that has never been customized.
3006 The value that was current before this operation
3007 becomes the backup value, so you can get it again."
3008 (let (custom-reset-standard-variables-list)
3009 (custom-variable-mark-to-reset-standard widget)))
3011 (defun custom-variable-backup-value (widget)
3012 "Back up the current value for WIDGET's variable.
3013 The backup value is kept in the car of the `backup-value' property."
3014 (let* ((symbol (widget-value widget))
3015 (get (or (get symbol 'custom-get) 'default-value))
3016 (type (custom-variable-type symbol))
3017 (conv (widget-convert type))
3018 (value (if (default-boundp symbol)
3019 (funcall get symbol)
3020 (widget-get conv :value))))
3021 (put symbol 'backup-value (list value))))
3023 (defun custom-variable-reset-backup (widget)
3024 "Restore the backup value for the variable being edited by WIDGET.
3025 The value that was current before this operation
3026 becomes the backup value, so you can use this operation repeatedly
3027 to switch between two values."
3028 (let* ((symbol (widget-value widget))
3029 (set (or (get symbol 'custom-set) 'set-default))
3030 (value (get symbol 'backup-value))
3031 (comment-widget (widget-get widget :comment-widget))
3032 (comment (widget-value comment-widget)))
3033 (if value
3034 (progn
3035 (custom-variable-backup-value widget)
3036 (custom-push-theme 'theme-value symbol 'user 'set value)
3037 (condition-case nil
3038 (funcall set symbol (car value))
3039 (error nil)))
3040 (user-error "No backup value for %s" symbol))
3041 (put symbol 'customized-value (list (custom-quote (car value))))
3042 (put symbol 'variable-comment comment)
3043 (put symbol 'customized-variable-comment comment)
3044 (custom-variable-state-set widget)
3045 ;; This call will possibly make the comment invisible
3046 (custom-redraw widget)))
3048 ;;; The `custom-visibility' Widget
3050 (define-widget 'custom-visibility 'visibility
3051 "Show or hide a documentation string."
3052 :button-face 'custom-visibility
3053 :pressed-face 'custom-visibility
3054 :mouse-face 'highlight
3055 :pressed-face 'highlight
3056 :on-glyph nil
3057 :off-glyph nil)
3059 (defface custom-visibility
3060 '((t :height 0.8 :inherit link))
3061 "Face for the `custom-visibility' widget."
3062 :version "23.1"
3063 :group 'custom-faces)
3065 ;;; The `custom-face-edit' Widget.
3067 (define-widget 'custom-face-edit 'checklist
3068 "Widget for editing face attributes.
3069 The following properties have special meanings for this widget:
3071 :value is a plist of face attributes.
3073 :default-face-attributes, if non-nil, is a plist of defaults for
3074 face attributes (as specified by a `default' defface entry)."
3075 :format "%v"
3076 :extra-offset 3
3077 :button-args '(:help-echo "Control whether this attribute has any effect.")
3078 :value-to-internal 'custom-face-edit-fix-value
3079 :match (lambda (widget value)
3080 (widget-checklist-match widget
3081 (custom-face-edit-fix-value widget value)))
3082 :value-create 'custom-face-edit-value-create
3083 :convert-widget 'custom-face-edit-convert-widget
3084 :args (mapcar (lambda (att)
3085 (list 'group :inline t
3086 :sibling-args (widget-get (nth 1 att) :sibling-args)
3087 (list 'const :format "" :value (nth 0 att))
3088 (nth 1 att)))
3089 custom-face-attributes))
3091 (defun custom-face-edit-value-create (widget)
3092 (let* ((alist (widget-checklist-match-find
3093 widget (widget-get widget :value)))
3094 (args (widget-get widget :args))
3095 (show-all (widget-get widget :show-all-attributes))
3096 (buttons (widget-get widget :buttons))
3097 (defaults (widget-checklist-match-find
3098 widget
3099 (widget-get widget :default-face-attributes)))
3100 entry)
3101 (unless (looking-back "^ *")
3102 (insert ?\n))
3103 (insert-char ?\s (widget-get widget :extra-offset))
3104 (if (or alist defaults show-all)
3105 (dolist (prop args)
3106 (setq entry (or (assq prop alist)
3107 (assq prop defaults)))
3108 (if (or entry show-all)
3109 (widget-checklist-add-item widget prop entry)))
3110 (insert (propertize "-- Empty face --" 'face 'shadow) ?\n))
3111 (let ((indent (widget-get widget :indent)))
3112 (if indent (insert-char ?\s (widget-get widget :indent))))
3113 (push (widget-create-child-and-convert
3114 widget 'visibility
3115 :help-echo "Show or hide all face attributes."
3116 :button-face 'custom-visibility
3117 :pressed-face 'custom-visibility
3118 :mouse-face 'highlight
3119 :on "Hide Unused Attributes" :off "Show All Attributes"
3120 :on-glyph nil :off-glyph nil
3121 :always-active t
3122 :action 'custom-face-edit-value-visibility-action
3123 show-all)
3124 buttons)
3125 (insert ?\n)
3126 (widget-put widget :buttons buttons)
3127 (widget-put widget :children (nreverse (widget-get widget :children)))))
3129 (defun custom-face-edit-value-visibility-action (widget &rest _ignore)
3130 ;; Toggle hiding of face attributes.
3131 (let ((parent (widget-get widget :parent)))
3132 (widget-put parent :show-all-attributes
3133 (not (widget-get parent :show-all-attributes)))
3134 (custom-redraw parent)))
3136 (defun custom-face-edit-fix-value (_widget value)
3137 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3138 Also change :reverse-video to :inverse-video."
3139 (custom-fix-face-spec value))
3141 (defun custom-face-edit-convert-widget (widget)
3142 "Convert :args as widget types in WIDGET."
3143 (widget-put
3144 widget
3145 :args (mapcar (lambda (arg)
3146 (widget-convert arg
3147 :deactivate 'custom-face-edit-deactivate
3148 :activate 'custom-face-edit-activate
3149 :delete 'custom-face-edit-delete))
3150 (widget-get widget :args)))
3151 widget)
3153 (defconst custom-face-edit (widget-convert 'custom-face-edit)
3154 "Converted version of the `custom-face-edit' widget.")
3156 (defun custom-face-edit-deactivate (widget)
3157 "Make face widget WIDGET inactive for user modifications."
3158 (unless (widget-get widget :inactive)
3159 (let ((tag (custom-face-edit-attribute-tag widget))
3160 (from (copy-marker (widget-get widget :from)))
3161 (value (widget-value widget))
3162 (inhibit-read-only t)
3163 (inhibit-modification-hooks t))
3164 (save-excursion
3165 (goto-char from)
3166 (widget-default-delete widget)
3167 (insert tag ": " (propertize "--" 'face 'shadow) "\n")
3168 (widget-put widget :inactive
3169 (cons value (cons from (- (point) from))))))))
3171 (defun custom-face-edit-activate (widget)
3172 "Make face widget WIDGET active for user modifications."
3173 (let ((inactive (widget-get widget :inactive))
3174 (inhibit-read-only t)
3175 (inhibit-modification-hooks t))
3176 (when (consp inactive)
3177 (save-excursion
3178 (goto-char (car (cdr inactive)))
3179 (delete-region (point) (+ (point) (cdr (cdr inactive))))
3180 (widget-put widget :inactive nil)
3181 (widget-apply widget :create)
3182 (widget-value-set widget (car inactive))
3183 (widget-setup)))))
3185 (defun custom-face-edit-delete (widget)
3186 "Remove WIDGET from the buffer."
3187 (let ((inactive (widget-get widget :inactive))
3188 (inhibit-read-only t)
3189 (inhibit-modification-hooks t))
3190 (if (not inactive)
3191 ;; Widget is alive, we don't have to do anything special
3192 (widget-default-delete widget)
3193 ;; WIDGET is already deleted because we did so to deactivate it;
3194 ;; now just get rid of the label we put in its place.
3195 (delete-region (car (cdr inactive))
3196 (+ (car (cdr inactive)) (cdr (cdr inactive))))
3197 (widget-put widget :inactive nil))))
3200 (defun custom-face-edit-attribute-tag (widget)
3201 "Return the first :tag property in WIDGET or one of its children."
3202 (let ((tag (widget-get widget :tag)))
3203 (or (and (not (equal tag "")) tag)
3204 (let ((children (widget-get widget :children)))
3205 (while (and (null tag) children)
3206 (setq tag (custom-face-edit-attribute-tag (pop children))))
3207 tag))))
3209 ;;; The `custom-display' Widget.
3211 (define-widget 'custom-display 'menu-choice
3212 "Select a display type."
3213 :tag "Display"
3214 :value t
3215 :help-echo "Specify frames where the face attributes should be used."
3216 :args '((const :tag "all" t)
3217 (const :tag "defaults" default)
3218 (checklist
3219 :tag "specific display"
3220 :offset 0
3221 :extra-offset 9
3222 :args ((group :sibling-args (:help-echo "\
3223 Only match the specified window systems.")
3224 (const :format "Type: "
3225 type)
3226 (checklist :inline t
3227 :offset 0
3228 (const :format "X "
3229 :sibling-args (:help-echo "\
3230 The X11 Window System.")
3232 (const :format "PM "
3233 :sibling-args (:help-echo "\
3234 OS/2 Presentation Manager.")
3236 (const :format "W32 "
3237 :sibling-args (:help-echo "\
3238 MS Windows.")
3239 w32)
3240 (const :format "NS "
3241 :sibling-args (:help-echo "\
3242 GNUstep or Macintosh OS Cocoa interface.")
3244 (const :format "DOS "
3245 :sibling-args (:help-echo "\
3246 Plain MS-DOS.")
3248 (const :format "TTY%n"
3249 :sibling-args (:help-echo "\
3250 Plain text terminals.")
3251 tty)))
3252 (group :sibling-args (:help-echo "\
3253 Only match the frames with the specified color support.")
3254 (const :format "Class: "
3255 class)
3256 (checklist :inline t
3257 :offset 0
3258 (const :format "Color "
3259 :sibling-args (:help-echo "\
3260 Match color frames.")
3261 color)
3262 (const :format "Grayscale "
3263 :sibling-args (:help-echo "\
3264 Match grayscale frames.")
3265 grayscale)
3266 (const :format "Monochrome%n"
3267 :sibling-args (:help-echo "\
3268 Match frames with no color support.")
3269 mono)))
3270 (group :sibling-args (:help-echo "\
3271 The minimum number of colors the frame should support.")
3272 (const :format "" min-colors)
3273 (integer :tag "Minimum number of colors" ))
3274 (group :sibling-args (:help-echo "\
3275 Only match frames with the specified intensity.")
3276 (const :format "\
3277 Background brightness: "
3278 background)
3279 (checklist :inline t
3280 :offset 0
3281 (const :format "Light "
3282 :sibling-args (:help-echo "\
3283 Match frames with light backgrounds.")
3284 light)
3285 (const :format "Dark\n"
3286 :sibling-args (:help-echo "\
3287 Match frames with dark backgrounds.")
3288 dark)))
3289 (group :sibling-args (:help-echo "\
3290 Only match frames that support the specified face attributes.")
3291 (const :format "Supports attributes:" supports)
3292 (custom-face-edit :inline t :format "%n%v"))))))
3294 ;;; The `custom-face' Widget.
3296 (defface custom-face-tag
3297 '((t :inherit custom-variable-tag))
3298 "Face used for face tags."
3299 :group 'custom-faces)
3301 (defcustom custom-face-default-form 'selected
3302 "Default form of displaying face definition."
3303 :type '(choice (const all)
3304 (const selected)
3305 (const lisp))
3306 :group 'custom-buffer
3307 :version "20.3")
3309 (define-widget 'custom-face 'custom
3310 "Widget for customizing a face.
3311 The following properties have special meanings for this widget:
3313 :value is the face name (a symbol).
3315 :custom-form should be a symbol describing how to display and
3316 edit the face attributes---either `selected' (attributes for
3317 selected display only), `all' (all attributes), `lisp' (as a
3318 Lisp sexp), or `mismatch' (should not happen); if nil, use
3319 the return value of `custom-face-default-form'.
3321 :custom-style describes the widget interface style; nil is the
3322 default style, while `simple' means a simpler interface that
3323 inhibits the magic custom-state widget.
3325 :sample-indent, if non-nil, is the number of columns to which to
3326 indent the face sample (an integer).
3328 :shown-value, if non-nil, is the face spec to display as the value
3329 of the widget, instead of the current face spec."
3330 :sample-face 'custom-face-tag
3331 :help-echo "Set or reset this face."
3332 :documentation-property #'face-doc-string
3333 :value-create 'custom-face-value-create
3334 :action 'custom-face-action
3335 :custom-category 'face
3336 :custom-form nil
3337 :custom-set 'custom-face-set
3338 :custom-mark-to-save 'custom-face-mark-to-save
3339 :custom-reset-current 'custom-redraw
3340 :custom-reset-saved 'custom-face-reset-saved
3341 :custom-reset-standard 'custom-face-reset-standard
3342 :custom-mark-to-reset-standard 'custom-face-mark-to-reset-standard
3343 :custom-standard-value 'custom-face-standard-value
3344 :custom-state-set-and-redraw 'custom-face-state-set-and-redraw
3345 :custom-menu 'custom-face-menu-create)
3347 (define-widget 'custom-face-all 'editable-list
3348 "An editable list of display specifications and attributes."
3349 :entry-format "%i %d %v"
3350 :insert-button-args '(:help-echo "Insert new display specification here.")
3351 :append-button-args '(:help-echo "Append new display specification here.")
3352 :delete-button-args '(:help-echo "Delete this display specification.")
3353 :args '((group :format "%v" custom-display custom-face-edit)))
3355 (defconst custom-face-all (widget-convert 'custom-face-all)
3356 "Converted version of the `custom-face-all' widget.")
3358 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
3359 "Return a canonicalized version of SPEC.
3360 FILTER-INDEX is the index in the entry for each attribute in
3361 `custom-face-attributes' at which the appropriate filter function can be
3362 found, and DEFAULT-FILTER is the filter to apply for attributes that
3363 don't specify one."
3364 (mapcar (lambda (entry)
3365 ;; Filter a single face-spec entry
3366 (let ((tests (car entry))
3367 (unfiltered-attrs
3368 ;; Handle both old- and new-style attribute syntax
3369 (if (listp (car (cdr entry)))
3370 (car (cdr entry))
3371 (cdr entry)))
3372 (filtered-attrs nil))
3373 ;; Filter each face attribute
3374 (while unfiltered-attrs
3375 (let* ((attr (pop unfiltered-attrs))
3376 (pre-filtered-value (pop unfiltered-attrs))
3377 (filter
3378 (or (nth filter-index (assq attr custom-face-attributes))
3379 default-filter))
3380 (filtered-value
3381 (if filter
3382 (funcall filter pre-filtered-value)
3383 pre-filtered-value)))
3384 (push filtered-value filtered-attrs)
3385 (push attr filtered-attrs)))
3387 (list tests filtered-attrs)))
3388 spec))
3390 (defun custom-pre-filter-face-spec (spec)
3391 "Return SPEC changed as necessary for editing by the face customization widget.
3392 SPEC must be a full face spec."
3393 (custom-filter-face-spec spec 2))
3395 (defun custom-post-filter-face-spec (spec)
3396 "Return the customized SPEC in a form suitable for setting the face."
3397 (custom-filter-face-spec spec 3))
3399 (defun custom-face-widget-to-spec (widget)
3400 "Return a face spec corresponding to WIDGET.
3401 WIDGET should be a `custom-face' widget."
3402 (unless (eq (widget-type widget) 'custom-face)
3403 (error "Invalid widget"))
3404 (let ((child (car (widget-get widget :children))))
3405 (custom-post-filter-face-spec
3406 (if (eq (widget-type child) 'custom-face-edit)
3407 `((t ,(widget-value child)))
3408 (widget-value child)))))
3410 (defun custom-face-get-current-spec (face)
3411 (let ((spec (or (get face 'customized-face)
3412 (get face 'saved-face)
3413 (get face 'face-defface-spec)
3414 ;; Attempt to construct it.
3415 `((t ,(custom-face-attributes-get
3416 face (selected-frame)))))))
3417 ;; If the user has changed this face in some other way,
3418 ;; edit it as the user has specified it.
3419 (if (not (face-spec-match-p face spec (selected-frame)))
3420 (setq spec `((t ,(face-attr-construct face (selected-frame))))))
3421 (custom-pre-filter-face-spec spec)))
3423 (defun custom-toggle-hide-face (visibility-widget &rest _ignore)
3424 "Toggle the visibility of a `custom-face' parent widget.
3425 By default, this signals an error if the parent has unsaved
3426 changes. If the parent has a `simple' :custom-style property,
3427 the present value is saved to its :shown-value property instead."
3428 (let ((widget (widget-get visibility-widget :parent)))
3429 (unless (eq (widget-type widget) 'custom-face)
3430 (error "Invalid widget type"))
3431 (custom-load-widget widget)
3432 (let ((state (widget-get widget :custom-state)))
3433 (if (eq state 'hidden)
3434 (widget-put widget :custom-state 'unknown)
3435 ;; In normal interface, widget can't be hidden if modified.
3436 (when (memq state '(invalid modified set))
3437 (if (eq (widget-get widget :custom-style) 'simple)
3438 (widget-put widget :shown-value
3439 (custom-face-widget-to-spec widget))
3440 (error "There are unsaved changes")))
3441 (widget-put widget :documentation-shown nil)
3442 (widget-put widget :custom-state 'hidden))
3443 (custom-redraw widget)
3444 (widget-setup))))
3446 (defun custom-face-value-create (widget)
3447 "Create a list of the display specifications for WIDGET."
3448 (let* ((buttons (widget-get widget :buttons))
3449 (symbol (widget-get widget :value))
3450 (tag (or (widget-get widget :tag)
3451 (prin1-to-string symbol)))
3452 (hiddenp (eq (widget-get widget :custom-state) 'hidden))
3453 (style (widget-get widget :custom-style))
3454 children)
3456 (if (eq custom-buffer-style 'tree)
3458 ;; Draw a tree-style `custom-face' widget
3459 (progn
3460 (insert (widget-get widget :custom-prefix)
3461 (if (widget-get widget :custom-last) " `--- " " |--- "))
3462 (push (widget-create-child-and-convert
3463 widget 'custom-browse-face-tag)
3464 buttons)
3465 (insert " " tag "\n")
3466 (widget-put widget :buttons buttons))
3468 ;; Draw an ordinary `custom-face' widget
3469 (let ((opoint (point)))
3470 ;; Visibility indicator.
3471 (push (widget-create-child-and-convert
3472 widget 'custom-visibility
3473 :help-echo "Hide or show this face."
3474 :on "Hide" :off "Show"
3475 :on-glyph "down" :off-glyph "right"
3476 :action 'custom-toggle-hide-face
3477 (not hiddenp))
3478 buttons)
3479 ;; Face name (tag).
3480 (insert " " tag)
3481 (widget-specify-sample widget opoint (point)))
3482 (insert
3483 (cond ((eq custom-buffer-style 'face) " ")
3484 ((string-match-p "face\\'" tag) ":")
3485 (t " face: ")))
3487 ;; Face sample.
3488 (let ((sample-indent (widget-get widget :sample-indent))
3489 (indent-tabs-mode nil))
3490 (and sample-indent
3491 (<= (current-column) sample-indent)
3492 (indent-to-column sample-indent)))
3493 (push (widget-create-child-and-convert
3494 widget 'item
3495 :format "[%{%t%}]"
3496 :sample-face (let ((spec (widget-get widget :shown-value)))
3497 (if spec (face-spec-choose spec) symbol))
3498 :tag "sample")
3499 buttons)
3500 (insert "\n")
3502 ;; Magic.
3503 (unless (eq (widget-get widget :custom-style) 'simple)
3504 (let ((magic (widget-create-child-and-convert
3505 widget 'custom-magic nil)))
3506 (widget-put widget :custom-magic magic)
3507 (push magic buttons)))
3509 ;; Update buttons.
3510 (widget-put widget :buttons buttons)
3512 ;; Insert documentation.
3513 (unless (and hiddenp (eq style 'simple))
3514 (widget-put widget :documentation-indent 3)
3515 (widget-add-documentation-string-button
3516 widget :visibility-widget 'custom-visibility)
3517 ;; The comment field
3518 (unless hiddenp
3519 (let* ((comment (get symbol 'face-comment))
3520 (comment-widget
3521 (widget-create-child-and-convert
3522 widget 'custom-comment
3523 :parent widget
3524 :value (or comment ""))))
3525 (widget-put widget :comment-widget comment-widget)
3526 (push comment-widget children))))
3528 ;; Editor.
3529 (unless (eq (preceding-char) ?\n)
3530 (insert "\n"))
3531 (unless hiddenp
3532 (custom-load-widget widget)
3533 (unless (widget-get widget :custom-form)
3534 (widget-put widget :custom-form custom-face-default-form))
3536 (let* ((spec (or (widget-get widget :shown-value)
3537 (custom-face-get-current-spec symbol)))
3538 (form (widget-get widget :custom-form))
3539 (indent (widget-get widget :indent))
3540 face-alist face-entry spec-default spec-match editor)
3542 ;; Find a display in SPEC matching the selected display.
3543 ;; This will use the usual face customization interface.
3544 (setq face-alist spec)
3545 (when (eq (car-safe (car-safe face-alist)) 'default)
3546 (setq spec-default (pop face-alist)))
3548 (while (and face-alist (listp face-alist) (null spec-match))
3549 (setq face-entry (car face-alist))
3550 (and (listp face-entry)
3551 (face-spec-set-match-display (car face-entry)
3552 (selected-frame))
3553 (widget-apply custom-face-edit :match (cadr face-entry))
3554 (setq spec-match face-entry))
3555 (setq face-alist (cdr face-alist)))
3557 ;; Insert the appropriate editing widget.
3558 (setq editor
3559 (cond
3560 ((and (eq form 'selected)
3561 (or spec-match spec-default))
3562 (when indent (insert-char ?\s indent))
3563 (widget-create-child-and-convert
3564 widget 'custom-face-edit
3565 :value (cadr spec-match)
3566 :default-face-attributes (cadr spec-default)))
3567 ((and (not (eq form 'lisp))
3568 (widget-apply custom-face-all :match spec))
3569 (widget-create-child-and-convert
3570 widget 'custom-face-all :value spec))
3572 (when indent
3573 (insert-char ?\s indent))
3574 (widget-create-child-and-convert
3575 widget 'sexp :value spec))))
3576 (custom-face-state-set widget)
3577 (push editor children)
3578 (widget-put widget :children children))))))
3580 (defvar custom-face-menu
3581 `(("Set for Current Session" custom-face-set)
3582 ,@(when (or custom-file init-file-user)
3583 '(("Save for Future Sessions" custom-face-save)))
3584 ("Undo Edits" custom-redraw
3585 (lambda (widget)
3586 (memq (widget-get widget :custom-state) '(modified changed))))
3587 ("Revert This Session's Customization" custom-face-reset-saved
3588 (lambda (widget)
3589 (memq (widget-get widget :custom-state) '(modified set changed))))
3590 ,@(when (or custom-file init-file-user)
3591 '(("Erase Customization" custom-face-reset-standard
3592 (lambda (widget)
3593 (get (widget-value widget) 'face-defface-spec)))))
3594 ("---" ignore ignore)
3595 ("Add Comment" custom-comment-show custom-comment-invisible-p)
3596 ("---" ignore ignore)
3597 ("For Current Display" custom-face-edit-selected
3598 (lambda (widget)
3599 (not (eq (widget-get widget :custom-form) 'selected))))
3600 ("For All Kinds of Displays" custom-face-edit-all
3601 (lambda (widget)
3602 (not (eq (widget-get widget :custom-form) 'all))))
3603 ("Show Lisp Expression" custom-face-edit-lisp
3604 (lambda (widget)
3605 (not (eq (widget-get widget :custom-form) 'lisp)))))
3606 "Alist of actions for the `custom-face' widget.
3607 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3608 the menu entry, ACTION is the function to call on the widget when the
3609 menu is selected, and FILTER is a predicate which takes a `custom-face'
3610 widget as an argument, and returns non-nil if ACTION is valid on that
3611 widget. If FILTER is nil, ACTION is always valid.")
3613 (defun custom-face-edit-selected (widget)
3614 "Edit selected attributes of the value of WIDGET."
3615 (widget-put widget :custom-state 'unknown)
3616 (widget-put widget :custom-form 'selected)
3617 (custom-redraw widget))
3619 (defun custom-face-edit-all (widget)
3620 "Edit all attributes of the value of WIDGET."
3621 (widget-put widget :custom-state 'unknown)
3622 (widget-put widget :custom-form 'all)
3623 (custom-redraw widget))
3625 (defun custom-face-edit-lisp (widget)
3626 "Edit the Lisp representation of the value of WIDGET."
3627 (widget-put widget :custom-state 'unknown)
3628 (widget-put widget :custom-form 'lisp)
3629 (custom-redraw widget))
3631 (defun custom-face-state (face)
3632 "Return the current state of the face FACE.
3633 This is one of `set', `saved', `changed', `themed', or `rogue'."
3634 (let* ((comment (get face 'face-comment))
3635 (state
3636 (cond
3637 ((or (get face 'customized-face)
3638 (get face 'customized-face-comment))
3639 (if (equal (get face 'customized-face-comment) comment)
3640 'set
3641 'changed))
3642 ((or (get face 'saved-face)
3643 (get face 'saved-face-comment))
3644 (cond ((not (equal (get face 'saved-face-comment) comment))
3645 'changed)
3646 ((eq 'user (caar (get face 'theme-face)))
3647 'saved)
3648 ((eq 'changed (caar (get face 'theme-face)))
3649 'changed)
3650 (t 'themed)))
3651 ((get face 'face-defface-spec)
3652 (cond (comment 'changed)
3653 ((get face 'theme-face) 'themed)
3654 (t 'standard)))
3655 (t 'rogue))))
3656 ;; If the user called set-face-attribute to change the default for
3657 ;; new frames, this face is "set outside of Customize".
3658 (if (and (not (eq state 'rogue))
3659 (get face 'face-modified))
3660 'changed
3661 state)))
3663 (defun custom-face-state-set (widget)
3664 "Set the state of WIDGET."
3665 (widget-put widget :custom-state
3666 (custom-face-state (widget-value widget))))
3668 (defun custom-face-action (widget &optional event)
3669 "Show the menu for `custom-face' WIDGET.
3670 Optional EVENT is the location for the menu."
3671 (if (eq (widget-get widget :custom-state) 'hidden)
3672 (custom-toggle-hide widget)
3673 (let* ((completion-ignore-case t)
3674 (symbol (widget-get widget :value))
3675 (answer (widget-choose (concat "Operation on "
3676 (custom-unlispify-tag-name symbol))
3677 (custom-menu-filter custom-face-menu
3678 widget)
3679 event)))
3680 (if answer
3681 (funcall answer widget)))))
3683 (defun custom-face-set (widget)
3684 "Make the face attributes in WIDGET take effect."
3685 (let* ((symbol (widget-value widget))
3686 (value (custom-face-widget-to-spec widget))
3687 (comment-widget (widget-get widget :comment-widget))
3688 (comment (widget-value comment-widget)))
3689 (when (equal comment "")
3690 (setq comment nil)
3691 ;; Make the comment invisible by hand if it's empty
3692 (custom-comment-hide comment-widget))
3693 (custom-push-theme 'theme-face symbol 'user 'set value)
3694 (face-spec-set symbol value 'customized-face)
3695 (put symbol 'face-comment comment)
3696 (put symbol 'customized-face-comment comment)
3697 (custom-face-state-set widget)
3698 (custom-redraw-magic widget)))
3700 (defun custom-face-mark-to-save (widget)
3701 "Mark for saving the face edited by WIDGET."
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 (standard (eq (widget-get widget :custom-state) 'standard)))
3707 (when (equal comment "")
3708 (setq comment nil)
3709 ;; Make the comment invisible by hand if it's empty
3710 (custom-comment-hide comment-widget))
3711 (custom-push-theme 'theme-face symbol 'user 'set value)
3712 (face-spec-set symbol value (if standard 'reset 'saved-face))
3713 (put symbol 'face-comment comment)
3714 (put symbol 'customized-face-comment nil)
3715 (put symbol 'saved-face-comment comment)))
3717 (defsubst custom-face-state-set-and-redraw (widget)
3718 "Set state of face widget WIDGET and redraw with current settings."
3719 (custom-face-state-set widget)
3720 (custom-redraw-magic widget))
3722 (defun custom-face-save (widget)
3723 "Save the face edited by WIDGET."
3724 (custom-face-mark-to-save widget)
3725 (custom-save-all)
3726 (custom-face-state-set-and-redraw widget))
3728 ;; For backward compatibility.
3729 (define-obsolete-function-alias 'custom-face-save-command 'custom-face-save
3730 "22.1")
3732 (defun custom-face-reset-saved (widget)
3733 "Restore WIDGET to the face's default attributes.
3734 If there is a saved face, restore it; otherwise reset to the
3735 uncustomized (themed or standard) face."
3736 (let* ((face (widget-value widget))
3737 (child (car (widget-get widget :children)))
3738 (saved-face (get face 'saved-face))
3739 (comment (get face 'saved-face-comment))
3740 (comment-widget (widget-get widget :comment-widget)))
3741 (custom-push-theme 'theme-face face 'user
3742 (if saved-face 'set 'reset)
3743 saved-face)
3744 (face-spec-set face saved-face 'saved-face)
3745 (put face 'face-comment comment)
3746 (put face 'customized-face-comment nil)
3747 (widget-value-set child saved-face)
3748 ;; This call manages the comment visibility
3749 (widget-value-set comment-widget (or comment ""))
3750 (custom-face-state-set widget)
3751 (custom-redraw widget)))
3753 (defun custom-face-standard-value (widget)
3754 (get (widget-value widget) 'face-defface-spec))
3756 (defun custom-face-mark-to-reset-standard (widget)
3757 "Restore widget WIDGET to the face's standard attribute values.
3758 If `custom-reset-standard-faces-list' is nil, save, reset and
3759 redraw the widget immediately."
3760 (let* ((symbol (widget-value widget))
3761 (child (car (widget-get widget :children)))
3762 (value (get symbol 'face-defface-spec))
3763 (comment-widget (widget-get widget :comment-widget)))
3764 (unless value
3765 (user-error "No standard setting for this face"))
3766 (custom-push-theme 'theme-face symbol 'user 'reset)
3767 (face-spec-set symbol value 'reset)
3768 (put symbol 'face-comment nil)
3769 (put symbol 'customized-face-comment nil)
3770 (if (and custom-reset-standard-faces-list
3771 (or (get symbol 'saved-face) (get symbol 'saved-face-comment)))
3772 ;; Do this later.
3773 (progn
3774 (put symbol 'saved-face nil)
3775 (put symbol 'saved-face-comment nil)
3776 ;; Append this to `custom-reset-standard-faces-list' and have
3777 ;; `custom-reset-standard-save-and-update' save setting to the
3778 ;; file, update the widget's state, and redraw it.
3779 (setq custom-reset-standard-faces-list
3780 (cons widget custom-reset-standard-faces-list)))
3781 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3782 (put symbol 'saved-face nil)
3783 (put symbol 'saved-face-comment nil)
3784 (custom-save-all))
3785 (widget-value-set child
3786 (custom-pre-filter-face-spec
3787 (list (list t (custom-face-attributes-get
3788 symbol nil)))))
3789 ;; This call manages the comment visibility
3790 (widget-value-set comment-widget "")
3791 (custom-face-state-set widget)
3792 (custom-redraw-magic widget))))
3794 (defun custom-face-reset-standard (widget)
3795 "Restore WIDGET to the face's standard attribute values.
3796 This operation eliminates any saved attributes for the face,
3797 restoring it to the state of a face that has never been customized."
3798 (let (custom-reset-standard-faces-list)
3799 (custom-face-mark-to-reset-standard widget)))
3801 ;;; The `face' Widget.
3803 (defvar widget-face-prompt-value-history nil
3804 "History of input to `widget-face-prompt-value'.")
3806 (define-widget 'face 'symbol
3807 "A Lisp face name (with sample)."
3808 :format "%{%t%}: (%{sample%}) %v"
3809 :tag "Face"
3810 :value 'default
3811 :sample-face-get 'widget-face-sample-face-get
3812 :notify 'widget-face-notify
3813 :match (lambda (_widget value) (facep value))
3814 :completions (apply-partially #'completion-table-with-predicate
3815 obarray #'facep 'strict)
3816 :prompt-match 'facep
3817 :prompt-history 'widget-face-prompt-value-history
3818 :validate (lambda (widget)
3819 (unless (facep (widget-value widget))
3820 (widget-put widget
3821 :error (format "Invalid face: %S"
3822 (widget-value widget)))
3823 widget)))
3825 (defun widget-face-sample-face-get (widget)
3826 (let ((value (widget-value widget)))
3827 (if (facep value)
3828 value
3829 'default)))
3831 (defun widget-face-notify (widget child &optional event)
3832 "Update the sample, and notify the parent."
3833 (overlay-put (widget-get widget :sample-overlay)
3834 'face (widget-apply widget :sample-face-get))
3835 (widget-default-notify widget child event))
3838 ;;; The `hook' Widget.
3840 (define-widget 'hook 'list
3841 "An Emacs Lisp hook."
3842 :value-to-internal (lambda (_widget value)
3843 (if (and value (symbolp value))
3844 (list value)
3845 value))
3846 :match (lambda (widget value)
3847 (or (symbolp value)
3848 (widget-group-match widget value)))
3849 ;; Avoid adding undefined functions to the hook, especially for
3850 ;; things like `find-file-hook' or even more basic ones, to avoid
3851 ;; chaos.
3852 :set (lambda (symbol value)
3853 (dolist (elt value)
3854 (if (fboundp elt)
3855 (add-hook symbol elt))))
3856 :convert-widget 'custom-hook-convert-widget
3857 :tag "Hook")
3859 (defun custom-hook-convert-widget (widget)
3860 ;; Handle `:options'.
3861 (let* ((options (widget-get widget :options))
3862 (other `(editable-list :inline t
3863 :entry-format "%i %d%v"
3864 (function :format " %v")))
3865 (args (if options
3866 (list `(checklist :inline t
3867 ,@(mapcar (lambda (entry)
3868 `(function-item ,entry))
3869 options))
3870 other)
3871 (list other))))
3872 (widget-put widget :args args)
3873 widget))
3875 ;;; The `custom-group-link' Widget.
3877 (define-widget 'custom-group-link 'link
3878 "Show parent in other window when activated."
3879 :button-face 'custom-link
3880 :mouse-face 'highlight
3881 :pressed-face 'highlight
3882 :help-echo "Create customization buffer for this group."
3883 :keymap custom-mode-link-map
3884 :follow-link 'mouse-face
3885 :action 'custom-group-link-action)
3887 (defun custom-group-link-action (widget &rest _ignore)
3888 (customize-group (widget-value widget)))
3890 ;;; The `custom-group' Widget.
3892 (defcustom custom-group-tag-faces nil
3893 "Face used for group tags.
3894 The first member is used for level 1 groups, the second for level 2,
3895 and so forth. The remaining group tags are shown with `custom-group-tag'."
3896 :type '(repeat face)
3897 :group 'custom-faces)
3899 (defface custom-group-tag-1
3900 '((default :weight bold :height 1.2 :inherit variable-pitch)
3901 (((class color) (background dark)) :foreground "pink")
3902 (((min-colors 88) (class color) (background light)) :foreground "red1")
3903 (((class color) (background light)) :foreground "red"))
3904 "Face for group tags."
3905 :group 'custom-faces)
3907 (defface custom-group-tag
3908 '((default :weight bold :height 1.2 :inherit variable-pitch)
3909 (((class color) (background dark)) :foreground "light blue")
3910 (((min-colors 88) (class color) (background light)) :foreground "blue1")
3911 (((class color) (background light)) :foreground "blue")
3912 (t :weight bold))
3913 "Face for low level group tags."
3914 :group 'custom-faces)
3916 (defface custom-group-subtitle
3917 '((t :weight bold))
3918 "Face for the \"Subgroups:\" subtitle in Custom buffers."
3919 :group 'custom-faces)
3921 (defvar custom-group-doc-align-col 20)
3923 (define-widget 'custom-group 'custom
3924 "Customize group."
3925 :format "%v"
3926 :sample-face-get 'custom-group-sample-face-get
3927 :documentation-property 'group-documentation
3928 :help-echo "Set or reset all members of this group."
3929 :value-create 'custom-group-value-create
3930 :action 'custom-group-action
3931 :custom-category 'group
3932 :custom-set 'custom-group-set
3933 :custom-mark-to-save 'custom-group-mark-to-save
3934 :custom-reset-current 'custom-group-reset-current
3935 :custom-reset-saved 'custom-group-reset-saved
3936 :custom-reset-standard 'custom-group-reset-standard
3937 :custom-mark-to-reset-standard 'custom-group-mark-to-reset-standard
3938 :custom-state-set-and-redraw 'custom-group-state-set-and-redraw
3939 :custom-menu 'custom-group-menu-create)
3941 (defun custom-group-sample-face-get (widget)
3942 ;; Use :sample-face.
3943 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3944 'custom-group-tag))
3946 (define-widget 'custom-group-visibility 'visibility
3947 "An indicator and manipulator for hidden group contents."
3948 :create 'custom-group-visibility-create)
3950 (defun custom-group-visibility-create (widget)
3951 (let ((visible (widget-value widget)))
3952 (if visible
3953 (insert "--------")))
3954 (widget-default-create widget))
3956 (defun custom-group-members (symbol groups-only)
3957 "Return SYMBOL's custom group members.
3958 If GROUPS-ONLY is non-nil, return only those members that are groups."
3959 (if (not groups-only)
3960 (get symbol 'custom-group)
3961 (let (members)
3962 (dolist (entry (get symbol 'custom-group))
3963 (when (eq (nth 1 entry) 'custom-group)
3964 (push entry members)))
3965 (nreverse members))))
3967 (defun custom-group-value-create (widget)
3968 "Insert a customize group for WIDGET in the current buffer."
3969 (unless (eq (widget-get widget :custom-state) 'hidden)
3970 (custom-load-widget widget))
3971 (let* ((state (widget-get widget :custom-state))
3972 (level (widget-get widget :custom-level))
3973 ;; (indent (widget-get widget :indent))
3974 (prefix (widget-get widget :custom-prefix))
3975 (buttons (widget-get widget :buttons))
3976 (tag (widget-get widget :tag))
3977 (symbol (widget-value widget))
3978 (members (custom-group-members symbol
3979 (and (eq custom-buffer-style 'tree)
3980 custom-browse-only-groups)))
3981 (doc (widget-docstring widget)))
3982 (cond ((and (eq custom-buffer-style 'tree)
3983 (eq state 'hidden)
3984 (or members (custom-unloaded-widget-p widget)))
3985 (custom-browse-insert-prefix prefix)
3986 (push (widget-create-child-and-convert
3987 widget 'custom-browse-visibility
3988 :tag "+")
3989 buttons)
3990 (insert "-- ")
3991 (push (widget-create-child-and-convert
3992 widget 'custom-browse-group-tag)
3993 buttons)
3994 (insert " " tag "\n")
3995 (widget-put widget :buttons buttons))
3996 ((and (eq custom-buffer-style 'tree)
3997 (zerop (length members)))
3998 (custom-browse-insert-prefix prefix)
3999 (insert "[ ]-- ")
4000 (push (widget-create-child-and-convert
4001 widget 'custom-browse-group-tag)
4002 buttons)
4003 (insert " " tag "\n")
4004 (widget-put widget :buttons buttons))
4005 ((eq custom-buffer-style 'tree)
4006 (custom-browse-insert-prefix prefix)
4007 (if (zerop (length members))
4008 (progn
4009 (custom-browse-insert-prefix prefix)
4010 (insert "[ ]-- ")
4011 ;; (widget-glyph-insert nil "[ ]" "empty")
4012 ;; (widget-glyph-insert nil "-- " "horizontal")
4013 (push (widget-create-child-and-convert
4014 widget 'custom-browse-group-tag)
4015 buttons)
4016 (insert " " tag "\n")
4017 (widget-put widget :buttons buttons))
4018 (push (widget-create-child-and-convert
4019 widget 'custom-browse-visibility
4020 ;; :tag-glyph "minus"
4021 :tag "-")
4022 buttons)
4023 (insert "-\\ ")
4024 ;; (widget-glyph-insert nil "-\\ " "top")
4025 (push (widget-create-child-and-convert
4026 widget 'custom-browse-group-tag)
4027 buttons)
4028 (insert " " tag "\n")
4029 (widget-put widget :buttons buttons)
4030 (message "Creating group...")
4031 (let* ((members (custom-sort-items
4032 members
4033 ;; Never sort the top-level custom group.
4034 (unless (eq symbol 'emacs)
4035 custom-browse-sort-alphabetically)
4036 custom-browse-order-groups))
4037 (prefixes (widget-get widget :custom-prefixes))
4038 (custom-prefix-list (custom-prefix-add symbol prefixes))
4039 (extra-prefix (if (widget-get widget :custom-last)
4041 " | "))
4042 (prefix (concat prefix extra-prefix))
4043 children entry)
4044 (while members
4045 (setq entry (car members)
4046 members (cdr members))
4047 (push (widget-create-child-and-convert
4048 widget (nth 1 entry)
4049 :group widget
4050 :tag (custom-unlispify-tag-name (nth 0 entry))
4051 :custom-prefixes custom-prefix-list
4052 :custom-level (1+ level)
4053 :custom-last (null members)
4054 :value (nth 0 entry)
4055 :custom-prefix prefix)
4056 children))
4057 (widget-put widget :children (reverse children)))
4058 (message "Creating group...done")))
4059 ;; Nested style.
4060 ((eq state 'hidden)
4061 ;; Create level indicator.
4062 ;; Create tag.
4063 (if (eq custom-buffer-style 'links)
4064 (push (widget-create-child-and-convert
4065 widget 'custom-group-link
4066 :tag tag
4067 symbol)
4068 buttons)
4069 (insert-char ?\s (* custom-buffer-indent (1- level)))
4070 (insert "-- ")
4071 (push (widget-create-child-and-convert
4072 widget 'custom-group-visibility
4073 :help-echo "Show members of this group."
4074 :action 'custom-toggle-parent
4075 (not (eq state 'hidden)))
4076 buttons))
4077 (if (>= (current-column) custom-group-doc-align-col)
4078 (insert " "))
4079 ;; Create magic button.
4080 (let ((magic (widget-create-child-and-convert
4081 widget 'custom-magic nil)))
4082 (widget-put widget :custom-magic magic)
4083 (push magic buttons))
4084 ;; Update buttons.
4085 (widget-put widget :buttons buttons)
4086 ;; Insert documentation.
4087 (if (and (eq custom-buffer-style 'links) (> level 1))
4088 (widget-put widget :documentation-indent
4089 custom-group-doc-align-col))
4090 (widget-add-documentation-string-button
4091 widget :visibility-widget 'custom-visibility))
4093 ;; Nested style.
4094 (t ;Visible.
4095 ;; Draw a horizontal line (this works for both graphical
4096 ;; and text displays):
4097 (let ((p (point)))
4098 (insert "\n")
4099 (put-text-property p (1+ p) 'face '(:underline t))
4100 (overlay-put (make-overlay p (1+ p))
4101 'before-string
4102 (propertize "\n" 'face '(:underline t)
4103 'display '(space :align-to 999))))
4105 ;; Add parent groups references above the group.
4106 (when (eq level 1)
4107 (if (custom-add-parent-links widget "Parent groups:")
4108 (insert "\n")))
4109 (insert-char ?\s (* custom-buffer-indent (1- level)))
4110 ;; Create tag.
4111 (let ((start (point)))
4112 (insert tag " group: ")
4113 (widget-specify-sample widget start (point)))
4114 (cond
4115 ((not doc)
4116 (insert " Group definition missing. "))
4117 ((< (length doc) 50)
4118 (insert doc)))
4119 ;; Create visibility indicator.
4120 (unless (eq custom-buffer-style 'links)
4121 (insert "--------")
4122 (push (widget-create-child-and-convert
4123 widget 'visibility
4124 :help-echo "Hide members of this group."
4125 :action 'custom-toggle-parent
4126 (not (eq state 'hidden)))
4127 buttons)
4128 (insert " "))
4129 (insert "\n")
4130 ;; Create magic button.
4131 (let ((magic (widget-create-child-and-convert
4132 widget 'custom-magic
4133 :indent 0
4134 nil)))
4135 (widget-put widget :custom-magic magic)
4136 (push magic buttons))
4137 ;; Update buttons.
4138 (widget-put widget :buttons buttons)
4139 ;; Insert documentation.
4140 (when (and doc (>= (length doc) 50))
4141 (widget-add-documentation-string-button
4142 widget :visibility-widget 'custom-visibility))
4144 ;; Parent groups.
4145 (if nil ;;; This should test that the buffer
4146 ;;; was not made to display a group.
4147 (when (eq level 1)
4148 (insert-char ?\s custom-buffer-indent)
4149 (custom-add-parent-links widget)))
4150 (custom-add-see-also widget
4151 (make-string (* custom-buffer-indent level)
4152 ?\s))
4153 ;; Members.
4154 (message "Creating group...")
4155 (let* ((members (custom-sort-items
4156 members
4157 ;; Never sort the top-level custom group.
4158 (unless (eq symbol 'emacs)
4159 custom-buffer-sort-alphabetically)
4160 custom-buffer-order-groups))
4161 (prefixes (widget-get widget :custom-prefixes))
4162 (custom-prefix-list (custom-prefix-add symbol prefixes))
4163 (len (length members))
4164 (count 0)
4165 (reporter (make-progress-reporter
4166 "Creating group entries..." 0 len))
4167 (have-subtitle (and (not (eq symbol 'emacs))
4168 (eq custom-buffer-order-groups 'last)))
4169 prev-type
4170 children)
4172 (dolist (entry members)
4173 (unless (eq prev-type 'custom-group)
4174 (widget-insert "\n"))
4175 (progress-reporter-update reporter (setq count (1+ count)))
4176 (let ((sym (nth 0 entry))
4177 (type (nth 1 entry)))
4178 (when (and have-subtitle (eq type 'custom-group))
4179 (setq have-subtitle nil)
4180 (widget-insert
4181 (propertize "Subgroups:\n" 'face 'custom-group-subtitle)))
4182 (setq prev-type type)
4183 (push (widget-create-child-and-convert
4184 widget type
4185 :group widget
4186 :tag (custom-unlispify-tag-name sym)
4187 :custom-prefixes custom-prefix-list
4188 :custom-level (1+ level)
4189 :value sym)
4190 children)
4191 (unless (eq (preceding-char) ?\n)
4192 (widget-insert "\n"))))
4194 (setq children (nreverse children))
4195 (mapc 'custom-magic-reset children)
4196 (widget-put widget :children children)
4197 (custom-group-state-update widget)
4198 (progress-reporter-done reporter))
4199 ;; End line
4200 (let ((p (1+ (point))))
4201 (insert "\n\n")
4202 (put-text-property p (1+ p) 'face '(:underline t))
4203 (overlay-put (make-overlay p (1+ p))
4204 'before-string
4205 (propertize "\n" 'face '(:underline t)
4206 'display '(space :align-to 999))))))))
4208 (defvar custom-group-menu
4209 `(("Set for Current Session" custom-group-set
4210 (lambda (widget)
4211 (eq (widget-get widget :custom-state) 'modified)))
4212 ,@(when (or custom-file init-file-user)
4213 '(("Save for Future Sessions" custom-group-save
4214 (lambda (widget)
4215 (memq (widget-get widget :custom-state) '(modified set))))))
4216 ("Undo Edits" custom-group-reset-current
4217 (lambda (widget)
4218 (memq (widget-get widget :custom-state) '(modified))))
4219 ("Revert This Session's Customizations" custom-group-reset-saved
4220 (lambda (widget)
4221 (memq (widget-get widget :custom-state) '(modified set))))
4222 ,@(when (or custom-file init-file-user)
4223 '(("Erase Customization" custom-group-reset-standard
4224 (lambda (widget)
4225 (memq (widget-get widget :custom-state) '(modified set saved)))))))
4226 "Alist of actions for the `custom-group' widget.
4227 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4228 the menu entry, ACTION is the function to call on the widget when the
4229 menu is selected, and FILTER is a predicate which takes a `custom-group'
4230 widget as an argument, and returns non-nil if ACTION is valid on that
4231 widget. If FILTER is nil, ACTION is always valid.")
4233 (defun custom-group-action (widget &optional event)
4234 "Show the menu for `custom-group' WIDGET.
4235 Optional EVENT is the location for the menu."
4236 (if (eq (widget-get widget :custom-state) 'hidden)
4237 (custom-toggle-hide widget)
4238 (let* ((completion-ignore-case t)
4239 (answer (widget-choose (concat "Operation on "
4240 (custom-unlispify-tag-name
4241 (widget-get widget :value)))
4242 (custom-menu-filter custom-group-menu
4243 widget)
4244 event)))
4245 (if answer
4246 (funcall answer widget)))))
4248 (defun custom-group-set (widget)
4249 "Set changes in all modified group members."
4250 (dolist (child (widget-get widget :children))
4251 (when (eq (widget-get child :custom-state) 'modified)
4252 (widget-apply child :custom-set))))
4254 (defun custom-group-mark-to-save (widget)
4255 "Mark all modified group members for saving."
4256 (dolist (child (widget-get widget :children))
4257 (when (memq (widget-get child :custom-state) '(modified set))
4258 (widget-apply child :custom-mark-to-save))))
4260 (defsubst custom-group-state-set-and-redraw (widget)
4261 "Set state of group widget WIDGET and redraw with current settings."
4262 (dolist (child (widget-get widget :children))
4263 (when (memq (widget-get child :custom-state) '(modified set))
4264 (widget-apply child :custom-state-set-and-redraw))))
4266 (defun custom-group-save (widget)
4267 "Save all modified group members."
4268 (custom-group-mark-to-save widget)
4269 (custom-save-all)
4270 (custom-group-state-set-and-redraw widget))
4272 (defun custom-group-reset-current (widget)
4273 "Reset all modified group members."
4274 (dolist (child (widget-get widget :children))
4275 (when (eq (widget-get child :custom-state) 'modified)
4276 (widget-apply child :custom-reset-current))))
4278 (defun custom-group-reset-saved (widget)
4279 "Reset all modified or set group members."
4280 (dolist (child (widget-get widget :children))
4281 (when (memq (widget-get child :custom-state) '(modified set))
4282 (widget-apply child :custom-reset-saved))))
4284 (defun custom-group-reset-standard (widget)
4285 "Reset all modified, set, or saved group members."
4286 (let ((custom-reset-standard-variables-list '(t))
4287 (custom-reset-standard-faces-list '(t)))
4288 (custom-group-mark-to-reset-standard widget)
4289 (custom-reset-standard-save-and-update)))
4291 (defun custom-group-mark-to-reset-standard (widget)
4292 "Mark to reset all modified, set, or saved group members."
4293 (dolist (child (widget-get widget :children))
4294 (when (memq (widget-get child :custom-state)
4295 '(modified set saved))
4296 (widget-apply child :custom-mark-to-reset-standard))))
4298 (defun custom-group-state-update (widget)
4299 "Update magic."
4300 (unless (eq (widget-get widget :custom-state) 'hidden)
4301 (let* ((children (widget-get widget :children))
4302 (states (mapcar (lambda (child)
4303 (widget-get child :custom-state))
4304 children))
4305 (magics custom-magic-alist)
4306 (found 'standard))
4307 (while magics
4308 (let ((magic (car (car magics))))
4309 (if (and (not (eq magic 'hidden))
4310 (memq magic states))
4311 (setq found magic
4312 magics nil)
4313 (setq magics (cdr magics)))))
4314 (widget-put widget :custom-state found)))
4315 (custom-magic-reset widget))
4317 ;;; Reading and writing the custom file.
4319 ;;;###autoload
4320 (defcustom custom-file nil
4321 "File used for storing customization information.
4322 The default is nil, which means to use your init file
4323 as specified by `user-init-file'. If the value is not nil,
4324 it should be an absolute file name.
4326 You can set this option through Custom, if you carefully read the
4327 last paragraph below. However, usually it is simpler to write
4328 something like the following in your init file:
4330 \(setq custom-file \"~/.emacs-custom.el\")
4331 \(load custom-file)
4333 Note that both lines are necessary: the first line tells Custom to
4334 save all customizations in this file, but does not load it.
4336 When you change this variable outside Custom, look in the
4337 previous custom file (usually your init file) for the
4338 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4339 and copy them (whichever ones you find) to the new custom file.
4340 This will preserve your existing customizations.
4342 If you save this option using Custom, Custom will write all
4343 currently saved customizations, including the new one for this
4344 option itself, into the file you specify, overwriting any
4345 `custom-set-variables' and `custom-set-faces' forms already
4346 present in that file. It will not delete any customizations from
4347 the old custom file. You should do that manually if that is what you
4348 want. You also have to put something like `(load \"CUSTOM-FILE\")
4349 in your init file, where CUSTOM-FILE is the actual name of the
4350 file. Otherwise, Emacs will not load the file when it starts up,
4351 and hence will not set `custom-file' to that file either."
4352 :type '(choice (const :tag "Your Emacs init file" nil)
4353 (file :format "%t:%v%d"
4354 :doc
4355 "Please read entire docstring below before setting \
4356 this through Custom.
4357 Click on \"More\" (or position point there and press RETURN)
4358 if only the first line of the docstring is shown."))
4359 :group 'customize)
4361 (defun custom-file (&optional no-error)
4362 "Return the file name for saving customizations."
4363 (if (null user-init-file)
4364 ;; Started with -q, i.e. the file containing Custom settings
4365 ;; hasn't been read. Saving settings there won't make much
4366 ;; sense.
4367 (if no-error
4369 (user-error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4370 (file-chase-links (or custom-file user-init-file))))
4372 ;; If recentf-mode is non-nil, this is defined.
4373 (declare-function recentf-expand-file-name "recentf" (name))
4375 ;;;###autoload
4376 (defun custom-save-all ()
4377 "Save all customizations in `custom-file'."
4378 (when (and (null custom-file) init-file-had-error)
4379 (error "Cannot save customizations; init file was not fully loaded"))
4380 (let* ((filename (custom-file))
4381 (recentf-exclude
4382 (if recentf-mode
4383 (cons (concat "\\`"
4384 (regexp-quote
4385 (recentf-expand-file-name (custom-file)))
4386 "\\'")
4387 recentf-exclude)))
4388 (old-buffer (find-buffer-visiting filename))
4389 old-buffer-name)
4391 (with-current-buffer (let ((find-file-visit-truename t))
4392 (or old-buffer (find-file-noselect filename)))
4393 ;; We'll save using file-precious-flag, so avoid destroying
4394 ;; symlinks. (If we're not already visiting the buffer, this is
4395 ;; handled by find-file-visit-truename, above.)
4396 (when old-buffer
4397 (setq old-buffer-name (buffer-file-name))
4398 (set-visited-file-name (file-chase-links filename)))
4400 (unless (eq major-mode 'emacs-lisp-mode)
4401 (emacs-lisp-mode))
4402 (let ((inhibit-read-only t)
4403 (print-length nil)
4404 (print-level nil))
4405 (custom-save-variables)
4406 (custom-save-faces))
4407 (let ((file-precious-flag t))
4408 (save-buffer))
4409 (if old-buffer
4410 (progn
4411 (set-visited-file-name old-buffer-name)
4412 (set-buffer-modified-p nil))
4413 (kill-buffer (current-buffer))))))
4415 ;;;###autoload
4416 (defun customize-save-customized ()
4417 "Save all user options which have been set in this session."
4418 (interactive)
4419 (mapatoms (lambda (symbol)
4420 (let ((face (get symbol 'customized-face))
4421 (value (get symbol 'customized-value))
4422 (face-comment (get symbol 'customized-face-comment))
4423 (variable-comment
4424 (get symbol 'customized-variable-comment)))
4425 (when face
4426 (put symbol 'saved-face face)
4427 (custom-push-theme 'theme-face symbol 'user 'set value)
4428 (put symbol 'customized-face nil))
4429 (when value
4430 (put symbol 'saved-value value)
4431 (custom-push-theme 'theme-value symbol 'user 'set value)
4432 (put symbol 'customized-value nil))
4433 (when variable-comment
4434 (put symbol 'saved-variable-comment variable-comment)
4435 (put symbol 'customized-variable-comment nil))
4436 (when face-comment
4437 (put symbol 'saved-face-comment face-comment)
4438 (put symbol 'customized-face-comment nil)))))
4439 ;; We really should update all custom buffers here.
4440 (custom-save-all))
4442 ;; Editing the custom file contents in a buffer.
4444 (defun custom-save-delete (symbol)
4445 "Delete all calls to SYMBOL from the contents of the current buffer.
4446 Leave point at the old location of the first such call,
4447 or (if there were none) at the end of the buffer.
4449 This function does not save the buffer."
4450 (goto-char (point-min))
4451 ;; Skip all whitespace and comments.
4452 (while (forward-comment 1))
4453 (or (eobp)
4454 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4455 (let (first)
4456 (catch 'found
4457 (while t ;; We exit this loop only via throw.
4458 ;; Skip all whitespace and comments.
4459 (while (forward-comment 1))
4460 (let ((start (point))
4461 (sexp (condition-case nil
4462 (read (current-buffer))
4463 (end-of-file (throw 'found nil)))))
4464 (when (and (listp sexp)
4465 (eq (car sexp) symbol))
4466 (delete-region start (point))
4467 (unless first
4468 (setq first (point)))))))
4469 (if first
4470 (goto-char first)
4471 ;; Move in front of local variables, otherwise long Custom
4472 ;; entries would make them ineffective.
4473 (let ((pos (point-max))
4474 (case-fold-search t))
4475 (save-excursion
4476 (goto-char (point-max))
4477 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4478 'move)
4479 (when (search-forward "Local Variables:" nil t)
4480 (setq pos (line-beginning-position))))
4481 (goto-char pos)))))
4483 (defvar sort-fold-case) ; defined in sort.el
4485 (defun custom-save-variables ()
4486 "Save all customized variables in `custom-file'."
4487 (save-excursion
4488 (custom-save-delete 'custom-set-variables)
4489 (let ((standard-output (current-buffer))
4490 (saved-list (make-list 1 0))
4491 sort-fold-case)
4492 ;; First create a sorted list of saved variables.
4493 (mapatoms
4494 (lambda (symbol)
4495 (if (and (get symbol 'saved-value)
4496 ;; ignore theme values
4497 (or (null (get symbol 'theme-value))
4498 (eq 'user (caar (get symbol 'theme-value)))))
4499 (nconc saved-list (list symbol)))))
4500 (setq saved-list (sort (cdr saved-list) 'string<))
4501 (unless (bolp)
4502 (princ "\n"))
4503 (princ "(custom-set-variables
4504 ;; custom-set-variables was added by Custom.
4505 ;; If you edit it by hand, you could mess it up, so be careful.
4506 ;; Your init file should contain only one such instance.
4507 ;; If there is more than one, they won't work right.\n")
4508 (dolist (symbol saved-list)
4509 (let ((spec (car-safe (get symbol 'theme-value)))
4510 (value (get symbol 'saved-value))
4511 (requests (get symbol 'custom-requests))
4512 (now (and (not (custom-variable-p symbol))
4513 (or (boundp symbol)
4514 (eq (get symbol 'force-value)
4515 'rogue))))
4516 (comment (get symbol 'saved-variable-comment)))
4517 ;; Check REQUESTS for validity.
4518 (dolist (request requests)
4519 (when (and (symbolp request) (not (featurep request)))
4520 (message "Unknown requested feature: %s" request)
4521 (setq requests (delq request requests))))
4522 ;; Is there anything customized about this variable?
4523 (when (or (and spec (eq (car spec) 'user))
4524 comment
4525 (and (null spec) (get symbol 'saved-value)))
4526 ;; Output an element for this variable.
4527 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4528 ;; SYMBOL is the variable name.
4529 ;; VALUE-FORM is an expression to return the customized value.
4530 ;; NOW if non-nil means always set the variable immediately
4531 ;; when the customizations are reloaded. This is used
4532 ;; for rogue variables
4533 ;; REQUESTS is a list of packages to load before setting the
4534 ;; variable. Each element of it will be passed to `require'.
4535 ;; COMMENT is whatever comment the user has specified
4536 ;; with the customize facility.
4537 (unless (bolp)
4538 (princ "\n"))
4539 (princ " '(")
4540 (prin1 symbol)
4541 (princ " ")
4542 (let ((val (prin1-to-string (car value))))
4543 (if (< (length val) 60)
4544 (insert val)
4545 (newline-and-indent)
4546 (let ((beginning-of-val (point)))
4547 (insert val)
4548 (save-excursion
4549 (goto-char beginning-of-val)
4550 (indent-pp-sexp 1)))))
4551 (when (or now requests comment)
4552 (princ " ")
4553 (prin1 now)
4554 (when (or requests comment)
4555 (princ " ")
4556 (prin1 requests)
4557 (when comment
4558 (princ " ")
4559 (prin1 comment))))
4560 (princ ")"))))
4561 (if (bolp)
4562 (princ " "))
4563 (princ ")")
4564 (unless (looking-at-p "\n")
4565 (princ "\n")))))
4567 (defun custom-save-faces ()
4568 "Save all customized faces in `custom-file'."
4569 (save-excursion
4570 (custom-save-delete 'custom-reset-faces)
4571 (custom-save-delete 'custom-set-faces)
4572 (let ((standard-output (current-buffer))
4573 (saved-list (make-list 1 0))
4574 sort-fold-case)
4575 ;; First create a sorted list of saved faces.
4576 (mapatoms
4577 (lambda (symbol)
4578 (if (and (get symbol 'saved-face)
4579 (eq 'user (car (car-safe (get symbol 'theme-face)))))
4580 (nconc saved-list (list symbol)))))
4581 (setq saved-list (sort (cdr saved-list) 'string<))
4582 ;; The default face must be first, since it affects the others.
4583 (if (memq 'default saved-list)
4584 (setq saved-list (cons 'default (delq 'default saved-list))))
4585 (unless (bolp)
4586 (princ "\n"))
4587 (princ "(custom-set-faces
4588 ;; custom-set-faces was added by Custom.
4589 ;; If you edit it by hand, you could mess it up, so be careful.
4590 ;; Your init file should contain only one such instance.
4591 ;; If there is more than one, they won't work right.\n")
4592 (dolist (symbol saved-list)
4593 (let ((spec (car-safe (get symbol 'theme-face)))
4594 (value (get symbol 'saved-face))
4595 (now (not (or (get symbol 'face-defface-spec)
4596 (and (not (custom-facep symbol))
4597 (not (get symbol 'force-face))))))
4598 (comment (get symbol 'saved-face-comment)))
4599 (when (or (and spec (eq (nth 0 spec) 'user))
4600 comment
4601 (and (null spec) (get symbol 'saved-face)))
4602 ;; Don't print default face here.
4603 (unless (bolp)
4604 (princ "\n"))
4605 (princ " '(")
4606 (prin1 symbol)
4607 (princ " ")
4608 (prin1 value)
4609 (when (or now comment)
4610 (princ " ")
4611 (prin1 now)
4612 (when comment
4613 (princ " ")
4614 (prin1 comment)))
4615 (princ ")"))))
4616 (if (bolp)
4617 (princ " "))
4618 (princ ")")
4619 (unless (looking-at-p "\n")
4620 (princ "\n")))))
4622 ;;; The Customize Menu.
4624 ;;; Menu support
4626 (defcustom custom-menu-nesting 2
4627 "Maximum nesting in custom menus."
4628 :type 'integer
4629 :group 'custom-menu)
4631 (defun custom-face-menu-create (_widget symbol)
4632 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4633 (vector (custom-unlispify-menu-entry symbol)
4634 `(customize-face ',symbol)
4637 (defun custom-variable-menu-create (_widget symbol)
4638 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4639 (let ((type (get symbol 'custom-type)))
4640 (unless (listp type)
4641 (setq type (list type)))
4642 (if (and type (widget-get type :custom-menu))
4643 (widget-apply type :custom-menu symbol)
4644 (vector (custom-unlispify-menu-entry symbol)
4645 `(customize-variable ',symbol)
4646 t))))
4648 ;; Add checkboxes to boolean variable entries.
4649 (widget-put (get 'boolean 'widget-type)
4650 :custom-menu (lambda (_widget symbol)
4651 (vector (custom-unlispify-menu-entry symbol)
4652 `(customize-variable ',symbol)
4653 ':style 'toggle
4654 ':selected symbol)))
4656 (defun custom-group-menu-create (_widget symbol)
4657 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4658 `( ,(custom-unlispify-menu-entry symbol t)
4659 :filter (lambda (&rest junk)
4660 (let* ((menu (custom-menu-create ',symbol)))
4661 (if (consp menu) (cdr menu) menu)))))
4663 ;;;###autoload
4664 (defun custom-menu-create (symbol)
4665 "Create menu for customization group SYMBOL.
4666 The menu is in a format applicable to `easy-menu-define'."
4667 (let* ((deactivate-mark nil)
4668 (item (vector (custom-unlispify-menu-entry symbol)
4669 `(customize-group ',symbol)
4670 t)))
4671 (if (and (or (not (boundp 'custom-menu-nesting))
4672 (>= custom-menu-nesting 0))
4673 (progn
4674 (custom-load-symbol symbol)
4675 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
4676 (let ((custom-prefix-list (custom-prefix-add symbol
4677 custom-prefix-list))
4678 (members (custom-sort-items (get symbol 'custom-group)
4679 custom-menu-sort-alphabetically
4680 custom-menu-order-groups)))
4681 `(,(custom-unlispify-menu-entry symbol t)
4682 ,item
4683 "--"
4684 ,@(mapcar (lambda (entry)
4685 (widget-apply (if (listp (nth 1 entry))
4686 (nth 1 entry)
4687 (list (nth 1 entry)))
4688 :custom-menu (nth 0 entry)))
4689 members)))
4690 item)))
4692 ;;;###autoload
4693 (defun customize-menu-create (symbol &optional name)
4694 "Return a customize menu for customization group SYMBOL.
4695 If optional NAME is given, use that as the name of the menu.
4696 Otherwise the menu will be named `Customize'.
4697 The format is suitable for use with `easy-menu-define'."
4698 (unless name
4699 (setq name "Customize"))
4700 `(,name
4701 :filter (lambda (&rest junk)
4702 (let ((menu (custom-menu-create ',symbol)))
4703 (if (consp menu) (cdr menu) menu)))))
4705 ;;; Toolbar and menubar support
4707 (easy-menu-define
4708 Custom-mode-menu (list custom-mode-map custom-field-keymap)
4709 "Menu used in customization buffers."
4710 (nconc (list "Custom"
4711 (customize-menu-create 'customize))
4712 (mapcar (lambda (arg)
4713 (let ((tag (nth 0 arg))
4714 (command (nth 1 arg))
4715 (active (nth 2 arg))
4716 (help (nth 3 arg)))
4717 (vector tag command :active (eval active) :help help)))
4718 custom-commands)))
4720 (defvar tool-bar-map)
4722 ;;; `custom-tool-bar-map' used to be set up here. This will fail to
4723 ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
4724 ;;; we set this up lazily in `Custom-mode'.
4725 (defvar custom-tool-bar-map nil
4726 "Keymap for toolbar in Custom mode.")
4728 ;;; The Custom Mode.
4730 (defun Custom-no-edit (_pos &optional _event)
4731 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4732 (interactive "@d")
4733 (error "You can't edit this part of the Custom buffer"))
4735 (defun Custom-newline (pos &optional event)
4736 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4737 (interactive "@d")
4738 (let ((button (get-char-property pos 'button)))
4739 ;; If there is no button at point, then use the one at the start
4740 ;; of the line, if it is a custom-group-link (bug#2298).
4741 (or button
4742 (if (setq button (get-char-property (line-beginning-position) 'button))
4743 (or (eq (widget-type button) 'custom-group-link)
4744 (setq button nil))))
4745 (if button
4746 (widget-apply-action button event)
4747 (error "You can't edit this part of the Custom buffer"))))
4749 (defun Custom-goto-parent ()
4750 "Go to the parent group listed at the top of this buffer.
4751 If several parents are listed, go to the first of them."
4752 (interactive)
4753 (save-excursion
4754 (goto-char (point-min))
4755 (if (search-forward "\nParent groups: " nil t)
4756 (let* ((button (get-char-property (point) 'button))
4757 (parent (downcase (widget-get button :tag))))
4758 (customize-group parent)))))
4760 (defcustom Custom-mode-hook nil
4761 "Hook called when entering Custom mode."
4762 :type 'hook
4763 :group 'custom-buffer)
4765 (defun custom-state-buffer-message (widget)
4766 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4767 (message "To install your edits, invoke [State] and choose the Set operation")))
4769 (defun custom--initialize-widget-variables ()
4770 (setq-local widget-documentation-face 'custom-documentation)
4771 (setq-local widget-button-face custom-button)
4772 (setq-local widget-button-pressed-face custom-button-pressed)
4773 (setq-local widget-mouse-face custom-button-mouse)
4774 ;; We need this because of the "More" button on docstrings.
4775 ;; Otherwise clicking on "More" can push point offscreen, which
4776 ;; causes the window to recenter on point, which pushes the
4777 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4778 (setq-local widget-button-click-moves-point t)
4779 ;; When possible, use relief for buttons, not bracketing. This test
4780 ;; may not be optimal.
4781 (when custom-raised-buttons
4782 (setq-local widget-push-button-prefix "")
4783 (setq-local widget-push-button-suffix "")
4784 (setq-local widget-link-prefix "")
4785 (setq-local widget-link-suffix ""))
4786 (setq show-trailing-whitespace nil))
4788 (define-obsolete-variable-alias 'custom-mode-hook 'Custom-mode-hook "23.1")
4789 (define-derived-mode Custom-mode nil "Custom"
4790 "Major mode for editing customization buffers.
4792 The following commands are available:
4794 \\<widget-keymap>\
4795 Move to next button, link or editable field. \\[widget-forward]
4796 Move to previous button, link or editable field. \\[widget-backward]
4797 \\<custom-field-keymap>\
4798 Complete content of editable text field. \\[widget-complete]
4799 \\<custom-mode-map>\
4800 Invoke button under the mouse pointer. \\[widget-button-click]
4801 Invoke button under point. \\[widget-button-press]
4802 Set all options from current text. \\[Custom-set]
4803 Make values in current text permanent. \\[Custom-save]
4804 Make text match actual option values. \\[Custom-reset-current]
4805 Reset options to permanent settings. \\[Custom-reset-saved]
4806 Erase customizations; set options
4807 and buffer text to the standard values. \\[Custom-reset-standard]
4809 Entry to this mode calls the value of `Custom-mode-hook'
4810 if that value is non-nil."
4811 (use-local-map custom-mode-map)
4812 (easy-menu-add Custom-mode-menu)
4813 (setq-local tool-bar-map
4814 (or custom-tool-bar-map
4815 ;; Set up `custom-tool-bar-map'.
4816 (let ((map (make-sparse-keymap)))
4817 (mapc
4818 (lambda (arg)
4819 (tool-bar-local-item-from-menu
4820 (nth 1 arg) (nth 4 arg) map custom-mode-map
4821 :label (nth 5 arg)))
4822 custom-commands)
4823 (setq custom-tool-bar-map map))))
4824 (make-local-variable 'custom-options)
4825 (make-local-variable 'custom-local-buffer)
4826 (custom--initialize-widget-variables)
4827 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t))
4829 (put 'Custom-mode 'mode-class 'special)
4831 (define-obsolete-function-alias 'custom-mode 'Custom-mode "23.1")
4833 (add-to-list 'debug-ignored-errors "^Invalid face:? ")
4835 ;;; The End.
4837 (provide 'cus-edit)
4839 ;;; cus-edit.el ends here