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