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