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