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