(Transient Mark): Fix xref.
[emacs.git] / lisp / cus-edit.el
blobd698aaeecc36878f877cf1b18b9adfbfdcfa5300
1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
2 ;;
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
5 ;;
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7 ;; Maintainer: FSF
8 ;; Keywords: help, faces
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
27 ;;; Commentary:
29 ;; This file implements the code to create and edit customize buffers.
31 ;; See `custom.el'.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
37 ;; The identity of a customize option is represented by a Lisp symbol.
38 ;; The following values are associated with an option.
40 ;; 0. The current value.
42 ;; This is the value of the option as seen by "the rest of Emacs".
44 ;; Usually extracted by 'default-value', but can be extracted with
45 ;; different means if the option symbol has the 'custom-get'
46 ;; property. Similarly, set-default (or the 'custom-set' property)
47 ;; can set it.
49 ;; 1. The widget value.
51 ;; This is the value shown in the widget in a customize buffer.
53 ;; 2. The customized value.
55 ;; This is the last value given to the option through customize.
57 ;; It is stored in the 'customized-value' property of the option, in a
58 ;; cons-cell whose car evaluates to the customized value.
60 ;; 3. The saved value.
62 ;; This is last value saved from customize.
64 ;; It is stored in the 'saved-value' property of the option, in a
65 ;; cons-cell whose car evaluates to the saved value.
67 ;; 4. The standard value.
69 ;; This is the value given in the 'defcustom' declaration.
71 ;; It is stored in the 'standard-value' property of the option, in a
72 ;; cons-cell whose car evaluates to the standard value.
74 ;; 5. The "think" value.
76 ;; This is what customize thinks the current value should be.
78 ;; This is the customized value, if any such value exists, otherwise
79 ;; the saved value, if that exists, and as a last resort the standard
80 ;; value.
82 ;; The reason for storing values unevaluated: This is so you can have
83 ;; values that depend on the environment. For example, you can have a
84 ;; variable that has one value when Emacs is running under a window
85 ;; system, and another value on a tty. Since the evaluation is only done
86 ;; when the variable is first initialized, this is only relevant for the
87 ;; saved (and standard) values, but affect others values for
88 ;; compatibility.
90 ;; You can see (and modify and save) this unevaluated value by selecting
91 ;; "Show Saved Lisp Expression" from the Lisp interface. This will
92 ;; give you the unevaluated saved value, if any, otherwise the
93 ;; unevaluated standard value.
95 ;; The possible states for a customize widget are:
97 ;; 0. unknown
99 ;; The state has not been determined yet.
101 ;; 1. modified
103 ;; The widget value is different from the current value.
105 ;; 2. changed
107 ;; The current value is different from the "think" value.
109 ;; 3. set
111 ;; The "think" value is the customized value.
113 ;; 4. saved
115 ;; The "think" value is the saved value.
117 ;; 5. standard
119 ;; The "think" value is the standard value.
121 ;; 6. rogue
123 ;; There is no standard value. This means that the variable was
124 ;; not defined with defcustom, nor handled in cus-start.el. Most
125 ;; standard interactive Custom commands do not let you create a
126 ;; Custom buffer containing such variables. However, such Custom
127 ;; buffers can be created, for instance, by calling
128 ;; `customize-apropos' with a prefix arg or by calling
129 ;; `customize-option' non-interactively.
131 ;; 7. hidden
133 ;; There is no widget value.
135 ;; 8. mismatch
137 ;; The widget value is not valid member of the :type specified for the
138 ;; option.
140 ;;; Code:
142 (require 'cus-face)
143 (require 'wid-edit)
144 (eval-when-compile
145 (defvar custom-versions-load-alist) ; from cus-load
146 (defvar recentf-exclude)) ; from recentf.el
148 (condition-case nil
149 (require 'cus-load)
150 (error nil))
152 (condition-case nil
153 (require 'cus-start)
154 (error nil))
156 (put 'custom-define-hook 'custom-type 'hook)
157 (put 'custom-define-hook 'standard-value '(nil))
158 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
160 ;;; Customization Groups.
162 (defgroup emacs nil
163 "Customization of the One True Editor."
164 :link '(custom-manual "(emacs)Top"))
166 ;; Most of these groups are stolen from `finder.el',
167 (defgroup editing nil
168 "Basic text editing facilities."
169 :group 'emacs)
171 (defgroup abbrev nil
172 "Abbreviation handling, typing shortcuts, macros."
173 :tag "Abbreviations"
174 :group 'editing)
176 (defgroup matching nil
177 "Various sorts of searching and matching."
178 :group 'editing)
180 (defgroup emulations nil
181 "Emulations of other editors."
182 :link '(custom-manual "(emacs)Emulation")
183 :group 'editing)
185 (defgroup mouse nil
186 "Mouse support."
187 :group 'editing)
189 (defgroup outlines nil
190 "Support for hierarchical outlining."
191 :group 'editing)
193 (defgroup external nil
194 "Interfacing to external utilities."
195 :group 'emacs)
197 (defgroup processes nil
198 "Process, subshell, compilation, and job control support."
199 :group 'external
200 :group 'development)
202 (defgroup convenience nil
203 "Convenience features for faster editing."
204 :group 'emacs)
206 (defgroup programming nil
207 "Support for programming in other languages."
208 :group 'emacs)
210 (defgroup languages nil
211 "Specialized modes for editing programming languages."
212 :group 'programming)
214 (defgroup lisp nil
215 "Lisp support, including Emacs Lisp."
216 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
217 :group 'languages
218 :group 'development)
220 (defgroup c nil
221 "Support for the C language and related languages."
222 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
223 :link '(custom-manual "(ccmode)")
224 :group 'languages)
226 (defgroup tools nil
227 "Programming tools."
228 :group 'programming)
230 (defgroup oop nil
231 "Support for object-oriented programming."
232 :group 'programming)
234 (defgroup applications nil
235 "Applications written in Emacs."
236 :group 'emacs)
238 (defgroup calendar nil
239 "Calendar and time management support."
240 :group 'applications)
242 (defgroup mail nil
243 "Modes for electronic-mail handling."
244 :group 'applications)
246 (defgroup news nil
247 "Support for netnews reading and posting."
248 :link '(custom-manual "(gnus)")
249 :group 'applications)
251 (defgroup games nil
252 "Games, jokes and amusements."
253 :group 'applications)
255 (defgroup development nil
256 "Support for further development of Emacs."
257 :group 'emacs)
259 (defgroup docs nil
260 "Support for Emacs documentation."
261 :group 'development)
263 (defgroup extensions nil
264 "Emacs Lisp language extensions."
265 :group 'development)
267 (defgroup internal nil
268 "Code for Emacs internals, build process, defaults."
269 :group 'development)
271 (defgroup maint nil
272 "Maintenance aids for the Emacs development group."
273 :tag "Maintenance"
274 :group 'development)
276 (defgroup environment nil
277 "Fitting Emacs with its environment."
278 :group 'emacs)
280 (defgroup comm nil
281 "Communications, networking, remote access to files."
282 :tag "Communication"
283 :group 'environment)
285 (defgroup hardware nil
286 "Support for interfacing with exotic hardware."
287 :group 'environment)
289 (defgroup terminals nil
290 "Support for terminal types."
291 :group 'environment)
293 (defgroup unix nil
294 "Front-ends/assistants for, or emulators of, UNIX features."
295 :group 'environment)
297 (defgroup vms nil
298 "Support code for vms."
299 :group 'environment)
301 (defgroup i18n nil
302 "Internationalization and alternate character-set support."
303 :link '(custom-manual "(emacs)International")
304 :group 'environment
305 :group 'editing)
307 (defgroup x nil
308 "The X Window system."
309 :group 'environment)
311 (defgroup frames nil
312 "Support for Emacs frames and window systems."
313 :group 'environment)
315 (defgroup data nil
316 "Support editing files of data."
317 :group 'emacs)
319 (defgroup files nil
320 "Support editing files."
321 :group 'emacs)
323 (defgroup wp nil
324 "Word processing."
325 :group 'emacs)
327 (defgroup tex nil
328 "Code related to the TeX formatter."
329 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
330 :group 'wp)
332 (defgroup faces nil
333 "Support for multiple fonts."
334 :group 'emacs)
336 (defgroup hypermedia nil
337 "Support for links between text or other media types."
338 :group 'emacs)
340 (defgroup help nil
341 "Support for on-line help systems."
342 :group 'emacs)
344 (defgroup multimedia nil
345 "Non-textual support, specifically images and sound."
346 :group 'emacs)
348 (defgroup local nil
349 "Code local to your site."
350 :group 'emacs)
352 (defgroup customize '((widgets custom-group))
353 "Customization of the Customization support."
354 :prefix "custom-"
355 :group 'help)
357 (defgroup custom-faces nil
358 "Faces used by customize."
359 :group 'customize
360 :group 'faces)
362 (defgroup custom-browse nil
363 "Control customize browser."
364 :prefix "custom-"
365 :group 'customize)
367 (defgroup custom-buffer nil
368 "Control customize buffers."
369 :prefix "custom-"
370 :group 'customize)
372 (defgroup custom-menu nil
373 "Control customize menus."
374 :prefix "custom-"
375 :group 'customize)
377 (defgroup abbrev-mode nil
378 "Word abbreviations mode."
379 :link '(custom-manual "(emacs)Abbrevs")
380 :group 'abbrev)
382 (defgroup alloc nil
383 "Storage allocation and gc for GNU Emacs Lisp interpreter."
384 :tag "Storage Allocation"
385 :group 'internal)
387 (defgroup undo nil
388 "Undoing changes in buffers."
389 :link '(custom-manual "(emacs)Undo")
390 :group 'editing)
392 (defgroup mode-line nil
393 "Content of the modeline."
394 :group 'environment)
396 (defgroup editing-basics nil
397 "Most basic editing facilities."
398 :group 'editing)
400 (defgroup display nil
401 "How characters are displayed in buffers."
402 :group 'environment)
404 (defgroup execute nil
405 "Executing external commands."
406 :group 'processes)
408 (defgroup installation nil
409 "The Emacs installation."
410 :group 'environment)
412 (defgroup dired nil
413 "Directory editing."
414 :group 'environment)
416 (defgroup limits nil
417 "Internal Emacs limits."
418 :group 'internal)
420 (defgroup debug nil
421 "Debugging Emacs itself."
422 :group 'development)
424 (defgroup minibuffer nil
425 "Controling the behavior of the minibuffer."
426 :link '(custom-manual "(emacs)Minibuffer")
427 :group 'environment)
429 (defgroup keyboard nil
430 "Input from the keyboard."
431 :group 'environment)
433 (defgroup mouse nil
434 "Input from the mouse."
435 :group 'environment)
437 (defgroup menu nil
438 "Input from the menus."
439 :group 'environment)
441 (defgroup dnd nil
442 "Handling data from drag and drop."
443 :group 'environment)
445 (defgroup auto-save nil
446 "Preventing accidential loss of data."
447 :group 'files)
449 (defgroup processes-basics nil
450 "Basic stuff dealing with processes."
451 :group 'processes)
453 (defgroup mule nil
454 "MULE Emacs internationalization."
455 :group 'i18n)
457 (defgroup windows nil
458 "Windows within a frame."
459 :link '(custom-manual "(emacs)Windows")
460 :group 'environment)
462 (defgroup mac nil
463 "Mac specific features."
464 :link '(custom-manual "(emacs)Mac OS")
465 :group 'environment
466 :version "22.1"
467 :prefix "mac-")
469 ;;; Custom mode keymaps
471 (defvar custom-mode-map
472 ;; This keymap should be dense, but a dense keymap would prevent inheriting
473 ;; "\r" bindings from the parent map.
474 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
475 (let ((map (make-keymap)))
476 (set-keymap-parent map widget-keymap)
477 (define-key map [remap self-insert-command] 'Custom-no-edit)
478 (define-key map "\^m" 'Custom-newline)
479 (define-key map " " 'scroll-up)
480 (define-key map "\177" 'scroll-down)
481 (define-key map "\C-c\C-c" 'Custom-set)
482 (define-key map "\C-x\C-s" 'Custom-save)
483 (define-key map "q" 'Custom-buffer-done)
484 (define-key map "u" 'Custom-goto-parent)
485 (define-key map "n" 'widget-forward)
486 (define-key map "p" 'widget-backward)
487 map)
488 "Keymap for `custom-mode'.")
490 (defvar custom-mode-link-map
491 (let ((map (make-keymap)))
492 (set-keymap-parent map custom-mode-map)
493 (define-key map [down-mouse-2] nil)
494 (define-key map [down-mouse-1] 'mouse-drag-region)
495 (define-key map [mouse-2] 'widget-move-and-invoke)
496 map)
497 "Local keymap for links in `custom-mode'.")
500 ;;; Utilities.
502 (defun custom-split-regexp-maybe (regexp)
503 "If REGEXP is a string, split it to a list at `\\|'.
504 You can get the original back with from the result with:
505 (mapconcat 'identity result \"\\|\")
507 IF REGEXP is not a string, return it unchanged."
508 (if (stringp regexp)
509 (let ((start 0)
510 all)
511 (while (string-match "\\\\|" regexp start)
512 (setq all (cons (substring regexp start (match-beginning 0)) all)
513 start (match-end 0)))
514 (nreverse (cons (substring regexp start) all)))
515 regexp))
517 (defun custom-variable-prompt ()
518 "Prompt for a custom variable, defaulting to the variable at point.
519 Return a list suitable for use in `interactive'."
520 (let* ((v (variable-at-point))
521 (default (and (symbolp v) (custom-variable-p v) (symbol-name v)))
522 (enable-recursive-minibuffers t)
523 val)
524 (setq val (completing-read
525 (if default (format "Customize variable (default %s): " default)
526 "Customize variable: ")
527 obarray 'custom-variable-p t nil nil default))
528 (list (if (equal val "")
529 (if (symbolp v) v nil)
530 (intern val)))))
532 (defun custom-menu-filter (menu widget)
533 "Convert MENU to the form used by `widget-choose'.
534 MENU should be in the same format as `custom-variable-menu'.
535 WIDGET is the widget to apply the filter entries of MENU on."
536 (let ((result nil)
537 current name action filter)
538 (while menu
539 (setq current (car menu)
540 name (nth 0 current)
541 action (nth 1 current)
542 filter (nth 2 current)
543 menu (cdr menu))
544 (if (or (null filter) (funcall filter widget))
545 (push (cons name action) result)
546 (push name result)))
547 (nreverse result)))
549 ;;; Unlispify.
551 (defvar custom-prefix-list nil
552 "List of prefixes that should be ignored by `custom-unlispify'.")
554 (defcustom custom-unlispify-menu-entries t
555 "Display menu entries as words instead of symbols if non-nil."
556 :group 'custom-menu
557 :type 'boolean)
559 (defcustom custom-unlispify-remove-prefixes nil
560 "Non-nil means remove group prefixes from option names in buffer."
561 :group 'custom-menu
562 :group 'custom-buffer
563 :type 'boolean)
565 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
566 "Convert SYMBOL into a menu entry."
567 (cond ((not custom-unlispify-menu-entries)
568 (symbol-name symbol))
569 ((get symbol 'custom-tag)
570 (if no-suffix
571 (get symbol 'custom-tag)
572 (concat (get symbol 'custom-tag) "...")))
574 (with-current-buffer (get-buffer-create " *Custom-Work*")
575 (erase-buffer)
576 (princ symbol (current-buffer))
577 (goto-char (point-min))
578 ;; FIXME: Boolean variables are not predicates, so they shouldn't
579 ;; end with `-p'. -stef
580 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
581 ;; (re-search-forward "-p\\'" nil t))
582 ;; (replace-match "" t t)
583 ;; (goto-char (point-min)))
584 (if custom-unlispify-remove-prefixes
585 (let ((prefixes custom-prefix-list)
586 prefix)
587 (while prefixes
588 (setq prefix (car prefixes))
589 (if (search-forward prefix (+ (point) (length prefix)) t)
590 (progn
591 (setq prefixes nil)
592 (delete-region (point-min) (point)))
593 (setq prefixes (cdr prefixes))))))
594 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
595 (capitalize-region (point-min) (point-max))
596 (unless no-suffix
597 (goto-char (point-max))
598 (insert "..."))
599 (buffer-string)))))
601 (defcustom custom-unlispify-tag-names t
602 "Display tag names as words instead of symbols if non-nil."
603 :group 'custom-buffer
604 :type 'boolean)
606 (defun custom-unlispify-tag-name (symbol)
607 "Convert SYMBOL into a menu entry."
608 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
609 (custom-unlispify-menu-entry symbol t)))
611 (defun custom-prefix-add (symbol prefixes)
612 "Add SYMBOL to list of ignored PREFIXES."
613 (cons (or (get symbol 'custom-prefix)
614 (concat (symbol-name symbol) "-"))
615 prefixes))
617 ;;; Guess.
619 (defcustom custom-guess-name-alist
620 '(("-p\\'" boolean)
621 ("-flag\\'" boolean)
622 ("-hook\\'" hook)
623 ("-face\\'" face)
624 ("-file\\'" file)
625 ("-function\\'" function)
626 ("-functions\\'" (repeat function))
627 ("-list\\'" (repeat sexp))
628 ("-alist\\'" (repeat (cons sexp sexp))))
629 "Alist of (MATCH TYPE).
631 MATCH should be a regexp matching the name of a symbol, and TYPE should
632 be a widget suitable for editing the value of that symbol. The TYPE
633 of the first entry where MATCH matches the name of the symbol will be
634 used.
636 This is used for guessing the type of variables not declared with
637 customize."
638 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
639 :group 'custom-buffer)
641 (defcustom custom-guess-doc-alist
642 '(("\\`\\*?Non-nil " boolean))
643 "Alist of (MATCH TYPE).
645 MATCH should be a regexp matching a documentation string, and TYPE
646 should be a widget suitable for editing the value of a variable with
647 that documentation string. The TYPE of the first entry where MATCH
648 matches the name of the symbol will be used.
650 This is used for guessing the type of variables not declared with
651 customize."
652 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
653 :group 'custom-buffer)
655 (defun custom-guess-type (symbol)
656 "Guess a widget suitable for editing the value of SYMBOL.
657 This is done by matching SYMBOL with `custom-guess-name-alist' and
658 if that fails, the doc string with `custom-guess-doc-alist'."
659 (let ((name (symbol-name symbol))
660 (names custom-guess-name-alist)
661 current found)
662 (while names
663 (setq current (car names)
664 names (cdr names))
665 (when (string-match (nth 0 current) name)
666 (setq found (nth 1 current)
667 names nil)))
668 (unless found
669 (let ((doc (documentation-property symbol 'variable-documentation))
670 (docs custom-guess-doc-alist))
671 (when doc
672 (while docs
673 (setq current (car docs)
674 docs (cdr docs))
675 (when (string-match (nth 0 current) doc)
676 (setq found (nth 1 current)
677 docs nil))))))
678 found))
680 ;;; Sorting.
682 (defcustom custom-browse-sort-alphabetically nil
683 "If non-nil, sort members of each customization group alphabetically."
684 :type 'boolean
685 :group 'custom-browse)
687 (defcustom custom-browse-order-groups nil
688 "If non-nil, order group members within each customization group.
689 If `first', order groups before non-groups.
690 If `last', order groups after non-groups."
691 :type '(choice (const first)
692 (const last)
693 (const :tag "none" nil))
694 :group 'custom-browse)
696 (defcustom custom-browse-only-groups nil
697 "If non-nil, show group members only within each customization group."
698 :type 'boolean
699 :group 'custom-browse)
701 (defcustom custom-buffer-sort-alphabetically nil
702 "If non-nil, sort members of each customization group alphabetically."
703 :type 'boolean
704 :group 'custom-buffer)
706 (defcustom custom-buffer-order-groups 'last
707 "If non-nil, order group members within each customization group.
708 If `first', order groups before non-groups.
709 If `last', order groups after non-groups."
710 :type '(choice (const first)
711 (const last)
712 (const :tag "none" nil))
713 :group 'custom-buffer)
715 (defcustom custom-menu-sort-alphabetically nil
716 "If non-nil, sort members of each customization group alphabetically."
717 :type 'boolean
718 :group 'custom-menu)
720 (defcustom custom-menu-order-groups 'first
721 "If non-nil, order group members within each customization group.
722 If `first', order groups before non-groups.
723 If `last', order groups after non-groups."
724 :type '(choice (const first)
725 (const last)
726 (const :tag "none" nil))
727 :group 'custom-menu)
729 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
731 (defun custom-sort-items (items sort-alphabetically order-groups)
732 "Return a sorted copy of ITEMS.
733 ITEMS should be a `custom-group' property.
734 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
735 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
736 groups after non-groups, if nil do not order groups at all."
737 (sort (copy-sequence items)
738 (lambda (a b)
739 (let ((typea (nth 1 a)) (typeb (nth 1 b))
740 (namea (nth 0 a)) (nameb (nth 0 b)))
741 (cond ((not order-groups)
742 ;; Since we don't care about A and B order, maybe sort.
743 (when sort-alphabetically
744 (string-lessp namea nameb)))
745 ((eq typea 'custom-group)
746 ;; If B is also a group, maybe sort. Otherwise, order A and B.
747 (if (eq typeb 'custom-group)
748 (when sort-alphabetically
749 (string-lessp namea nameb))
750 (eq order-groups 'first)))
751 ((eq typeb 'custom-group)
752 ;; Since A cannot be a group, order A and B.
753 (eq order-groups 'last))
754 (sort-alphabetically
755 ;; Since A and B cannot be groups, sort.
756 (string-lessp namea nameb)))))))
758 ;;; Custom Mode Commands.
760 (defvar custom-options nil
761 "Customization widgets in the current buffer.")
763 (defun Custom-set ()
764 "Set the current value of all edited settings in the buffer."
765 (interactive)
766 (let ((children custom-options))
767 (if (or (and (= 1 (length children))
768 (memq (widget-type (car children))
769 '(custom-variable custom-face)))
770 (y-or-n-p "Set all values according to this buffer? "))
771 (mapc (lambda (child)
772 (when (eq (widget-get child :custom-state) 'modified)
773 (widget-apply child :custom-set)))
774 children)
775 (message "Aborted"))))
777 (defun Custom-save ()
778 "Set all edited settings, then save all settings that have been set.
779 If a setting was edited and set before, this saves it.
780 If a setting was merely edited before, this sets it then saves it."
781 (interactive)
782 (let ((children custom-options))
783 (if (or (and (= 1 (length children))
784 (memq (widget-type (car children))
785 '(custom-variable custom-face)))
786 (yes-or-no-p "Save all settings in this buffer? "))
787 (progn
788 (mapc (lambda (child)
789 (when (memq (widget-get child :custom-state)
790 '(modified set changed rogue))
791 (widget-apply child :custom-save)))
792 children)
793 (custom-save-all))
794 (message "Aborted"))))
796 (defvar custom-reset-menu
797 '(("Undo Edits" . Custom-reset-current)
798 ("Reset to Saved" . Custom-reset-saved)
799 ("Erase Customization (use standard values)" . Custom-reset-standard))
800 "Alist of actions for the `Reset' button.
801 The key is a string containing the name of the action, the value is a
802 Lisp function taking the widget as an element which will be called
803 when the action is chosen.")
805 (defun custom-reset (event)
806 "Select item from reset menu."
807 (let* ((completion-ignore-case t)
808 (answer (widget-choose "Reset settings"
809 custom-reset-menu
810 event)))
811 (if answer
812 (funcall answer))))
814 (defun Custom-reset-current (&rest ignore)
815 "Reset all edited settings in the buffer to show their current values."
816 (interactive)
817 (let ((children custom-options))
818 (if (or (and (= 1 (length children))
819 (memq (widget-type (car children))
820 '(custom-variable custom-face)))
821 (y-or-n-p "Reset all settings' buffer text to show current values? "))
822 (mapc (lambda (widget)
823 (if (memq (widget-get widget :custom-state)
824 '(modified changed))
825 (widget-apply widget :custom-reset-current)))
826 children)
827 (message "Aborted"))))
829 (defun Custom-reset-saved (&rest ignore)
830 "Reset all edited or set settings in the buffer to their saved value.
831 This also shows the saved values in the buffer."
832 (interactive)
833 (let ((children custom-options))
834 (if (or (and (= 1 (length children))
835 (memq (widget-type (car children))
836 '(custom-variable custom-face)))
837 (y-or-n-p "Reset all settings (current values and buffer text) to saved values? "))
838 (mapc (lambda (widget)
839 (if (memq (widget-get widget :custom-state)
840 '(modified set changed rogue))
841 (widget-apply widget :custom-reset-saved)))
842 children)
843 (message "Aborted"))))
845 (defun Custom-reset-standard (&rest ignore)
846 "Erase all customization (either current or saved) for the group members.
847 The immediate result is to restore them to their standard values.
848 This operation eliminates any saved values for the group members,
849 making them as if they had never been customized at all."
850 (interactive)
851 (let ((children custom-options))
852 (if (or (and (= 1 (length children))
853 (memq (widget-type (car children))
854 '(custom-variable custom-face)))
855 (yes-or-no-p "Erase all customizations for settings in this buffer? "))
856 (mapc (lambda (widget)
857 (and (if (widget-get widget :custom-standard-value)
858 (widget-apply widget :custom-standard-value)
860 (memq (widget-get widget :custom-state)
861 '(modified set changed saved rogue))
862 (widget-apply widget :custom-reset-standard)))
863 children)
864 (message "Aborted"))))
866 ;;; The Customize Commands
868 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
869 "Prompt for a variable and a value and return them as a list.
870 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
871 prompt for the value. The %s escape in PROMPT-VAL is replaced with
872 the name of the variable.
874 If the variable has a `variable-interactive' property, that is used as if
875 it were the arg to `interactive' (which see) to interactively read the value.
877 If the variable has a `custom-type' property, it must be a widget and the
878 `:prompt-value' property of that widget will be used for reading the value.
880 If optional COMMENT argument is non-nil, also prompt for a comment and return
881 it as the third element in the list."
882 (let* ((var (read-variable prompt-var))
883 (minibuffer-help-form '(describe-variable var))
884 (val
885 (let ((prop (get var 'variable-interactive))
886 (type (get var 'custom-type))
887 (prompt (format prompt-val var)))
888 (unless (listp type)
889 (setq type (list type)))
890 (cond (prop
891 ;; Use VAR's `variable-interactive' property
892 ;; as an interactive spec for prompting.
893 (call-interactively (list 'lambda '(arg)
894 (list 'interactive prop)
895 'arg)))
896 (type
897 (widget-prompt-value type
898 prompt
899 (if (boundp var)
900 (symbol-value var))
901 (not (boundp var))))
903 (eval-minibuffer prompt))))))
904 (if comment
905 (list var val
906 (read-string "Comment: " (get var 'variable-comment)))
907 (list var val))))
909 ;;;###autoload
910 (defun customize-set-value (variable value &optional comment)
911 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
913 If VARIABLE has a `variable-interactive' property, that is used as if
914 it were the arg to `interactive' (which see) to interactively read the value.
916 If VARIABLE has a `custom-type' property, it must be a widget and the
917 `:prompt-value' property of that widget will be used for reading the value.
919 If given a prefix (or a COMMENT argument), also prompt for a comment."
920 (interactive (custom-prompt-variable "Set variable: "
921 "Set %s to value: "
922 current-prefix-arg))
924 (cond ((string= comment "")
925 (put variable 'variable-comment nil))
926 (comment
927 (put variable 'variable-comment comment)))
928 (set variable value))
930 ;;;###autoload
931 (defun customize-set-variable (variable value &optional comment)
932 "Set the default for VARIABLE to VALUE, and return VALUE.
933 VALUE is a Lisp object.
935 If VARIABLE has a `custom-set' property, that is used for setting
936 VARIABLE, otherwise `set-default' is used.
938 The `customized-value' property of the VARIABLE will be set to a list
939 with a quoted VALUE as its sole list member.
941 If VARIABLE has a `variable-interactive' property, that is used as if
942 it were the arg to `interactive' (which see) to interactively read the value.
944 If VARIABLE has a `custom-type' property, it must be a widget and the
945 `:prompt-value' property of that widget will be used for reading the value.
947 If given a prefix (or a COMMENT argument), also prompt for a comment."
948 (interactive (custom-prompt-variable "Set variable: "
949 "Set customized value for %s to: "
950 current-prefix-arg))
951 (custom-load-symbol variable)
952 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
953 (funcall (or (get variable 'custom-set) 'set-default) variable value)
954 (put variable 'customized-value (list (custom-quote value)))
955 (cond ((string= comment "")
956 (put variable 'variable-comment nil)
957 (put variable 'customized-variable-comment nil))
958 (comment
959 (put variable 'variable-comment comment)
960 (put variable 'customized-variable-comment comment)))
961 value)
963 ;;;###autoload
964 (defun customize-save-variable (variable value &optional comment)
965 "Set the default for VARIABLE to VALUE, and save it for future sessions.
966 Return VALUE.
968 If VARIABLE has a `custom-set' property, that is used for setting
969 VARIABLE, otherwise `set-default' is used.
971 The `customized-value' property of the VARIABLE will be set to a list
972 with a quoted VALUE as its sole list member.
974 If VARIABLE has a `variable-interactive' property, that is used as if
975 it were the arg to `interactive' (which see) to interactively read the value.
977 If VARIABLE has a `custom-type' property, it must be a widget and the
978 `:prompt-value' property of that widget will be used for reading the value.
980 If given a prefix (or a COMMENT argument), also prompt for a comment."
981 (interactive (custom-prompt-variable "Set and save variable: "
982 "Set and save value for %s as: "
983 current-prefix-arg))
984 (funcall (or (get variable 'custom-set) 'set-default) variable value)
985 (put variable 'saved-value (list (custom-quote value)))
986 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
987 (cond ((string= comment "")
988 (put variable 'variable-comment nil)
989 (put variable 'saved-variable-comment nil))
990 (comment
991 (put variable 'variable-comment comment)
992 (put variable 'saved-variable-comment comment)))
993 (custom-save-all)
994 value)
996 ;;;###autoload
997 (defun customize ()
998 "Select a customization buffer which you can use to set user options.
999 User options are structured into \"groups\".
1000 Initially the top-level group `Emacs' and its immediate subgroups
1001 are shown; the contents of those subgroups are initially hidden."
1002 (interactive)
1003 (customize-group 'emacs))
1005 ;;;###autoload
1006 (defun customize-mode (mode)
1007 "Customize options related to the current major mode.
1008 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1009 then prompt for the MODE to customize."
1010 (interactive
1011 (list
1012 (let ((completion-regexp-list '("-mode\\'"))
1013 (group (custom-group-of-mode major-mode)))
1014 (if (and group (not current-prefix-arg))
1015 major-mode
1016 (intern
1017 (completing-read (if group
1018 (format "Major mode (default %s): " major-mode)
1019 "Major mode: ")
1020 obarray
1021 'custom-group-of-mode
1022 t nil nil (if group (symbol-name major-mode))))))))
1023 (customize-group (custom-group-of-mode mode)))
1026 ;;;###autoload
1027 (defun customize-group (group)
1028 "Customize GROUP, which must be a customization group."
1029 (interactive
1030 (list (let ((completion-ignore-case t))
1031 (completing-read "Customize group (default emacs): "
1032 obarray
1033 (lambda (symbol)
1034 (or (and (get symbol 'custom-loads)
1035 (not (get symbol 'custom-autoload)))
1036 (get symbol 'custom-group)))
1037 t))))
1038 (when (stringp group)
1039 (if (string-equal "" group)
1040 (setq group 'emacs)
1041 (setq group (intern group))))
1042 (let ((name (format "*Customize Group: %s*"
1043 (custom-unlispify-tag-name group))))
1044 (if (get-buffer name)
1045 (pop-to-buffer name)
1046 (custom-buffer-create (list (list group 'custom-group))
1047 name
1048 (concat " for group "
1049 (custom-unlispify-tag-name group))))))
1051 ;;;###autoload
1052 (defun customize-group-other-window (group)
1053 "Customize GROUP, which must be a customization group."
1054 (interactive
1055 (list (let ((completion-ignore-case t))
1056 (completing-read "Customize group (default emacs): "
1057 obarray
1058 (lambda (symbol)
1059 (or (and (get symbol 'custom-loads)
1060 (not (get symbol 'custom-autoload)))
1061 (get symbol 'custom-group)))
1062 t))))
1063 (when (stringp group)
1064 (if (string-equal "" group)
1065 (setq group 'emacs)
1066 (setq group (intern group))))
1067 (let ((name (format "*Customize Group: %s*"
1068 (custom-unlispify-tag-name group))))
1069 (if (get-buffer name)
1070 (let (
1071 ;; Copied from `custom-buffer-create-other-window'.
1072 (pop-up-windows t)
1073 (same-window-buffer-names nil)
1074 (same-window-regexps nil))
1075 (pop-to-buffer name))
1076 (custom-buffer-create-other-window
1077 (list (list group 'custom-group))
1078 name
1079 (concat " for group "
1080 (custom-unlispify-tag-name group))))))
1082 ;;;###autoload
1083 (defalias 'customize-variable 'customize-option)
1085 ;;;###autoload
1086 (defun customize-option (symbol)
1087 "Customize SYMBOL, which must be a user option variable."
1088 (interactive (custom-variable-prompt))
1089 (unless symbol
1090 (error "No variable specified"))
1091 (let ((basevar (indirect-variable symbol)))
1092 (custom-buffer-create (list (list basevar 'custom-variable))
1093 (format "*Customize Option: %s*"
1094 (custom-unlispify-tag-name basevar)))
1095 (unless (eq symbol basevar)
1096 (message "`%s' is an alias for `%s'" symbol basevar))))
1098 ;;;###autoload
1099 (defalias 'customize-variable-other-window 'customize-option-other-window)
1101 ;;;###autoload
1102 (defun customize-option-other-window (symbol)
1103 "Customize SYMBOL, which must be a user option variable.
1104 Show the buffer in another window, but don't select it."
1105 (interactive (custom-variable-prompt))
1106 (unless symbol
1107 (error "No variable specified"))
1108 (let ((basevar (indirect-variable symbol)))
1109 (custom-buffer-create-other-window
1110 (list (list basevar 'custom-variable))
1111 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar)))
1112 (unless (eq symbol basevar)
1113 (message "`%s' is an alias for `%s'" symbol basevar))))
1115 (defvar customize-changed-options-previous-release "21.1"
1116 "Version for `customize-changed-options' to refer back to by default.")
1118 ;; Packages will update this variable, so make it available.
1119 ;;;###autoload
1120 (defvar customize-package-emacs-version-alist nil
1121 "Alist mapping versions of a package to Emacs versions.
1122 We use this for packages that have their own names, but are released
1123 as part of Emacs itself.
1125 Each elements looks like this:
1127 (PACKAGE (PVERSION . EVERSION)...)
1129 Here PACKAGE is the name of a package, as a symbol. After
1130 PACKAGE come one or more elements, each associating a
1131 package version PVERSION with the first Emacs version
1132 EVERSION in which it (or a subsequent version of PACKAGE)
1133 was first released. Both PVERSION and EVERSION are strings.
1134 PVERSION should be a string that this package used in
1135 the :package-version keyword for `defcustom', `defgroup',
1136 and `defface'.
1138 For example, the MH-E package updates this alist as follows:
1140 (add-to-list 'customize-package-emacs-version-alist
1141 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1142 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1143 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1144 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1146 The value of PACKAGE needs to be unique and it needs to match the
1147 PACKAGE value appearing in the :package-version keyword. Since
1148 the user might see the value in a error message, a good choice is
1149 the official name of the package, such as MH-E or Gnus.")
1151 ;;;###autoload
1152 (defalias 'customize-changed 'customize-changed-options)
1154 ;;;###autoload
1155 (defun customize-changed-options (since-version)
1156 "Customize all settings whose meanings have changed in Emacs itself.
1157 This includes new user option variables and faces, and new
1158 customization groups, as well as older options and faces whose meanings
1159 or default values have changed since the previous major Emacs release.
1161 With argument SINCE-VERSION (a string), customize all settings
1162 that were added or redefined since that version."
1164 (interactive
1165 (list
1166 (read-from-minibuffer
1167 (format "Customize options changed, since version (default %s): "
1168 customize-changed-options-previous-release))))
1169 (if (equal since-version "")
1170 (setq since-version nil)
1171 (unless (condition-case nil
1172 (numberp (read since-version))
1173 (error nil))
1174 (signal 'wrong-type-argument (list 'numberp since-version))))
1175 (unless since-version
1176 (setq since-version customize-changed-options-previous-release))
1178 ;; Load the information for versions since since-version. We use
1179 ;; custom-load-symbol for this.
1180 (put 'custom-versions-load-alist 'custom-loads nil)
1181 (dolist (elt custom-versions-load-alist)
1182 (if (customize-version-lessp since-version (car elt))
1183 (dolist (load (cdr elt))
1184 (custom-add-load 'custom-versions-load-alist load))))
1185 (custom-load-symbol 'custom-versions-load-alist)
1186 (put 'custom-versions-load-alist 'custom-loads nil)
1188 (let (found)
1189 (mapatoms
1190 (lambda (symbol)
1191 (let* ((package-version (get symbol 'custom-package-version))
1192 (version
1193 (or (and package-version
1194 (customize-package-emacs-version symbol
1195 package-version))
1196 (get symbol 'custom-version))))
1197 (if version
1198 (when (customize-version-lessp since-version version)
1199 (if (or (get symbol 'custom-group)
1200 (get symbol 'group-documentation))
1201 (push (list symbol 'custom-group) found))
1202 (if (custom-variable-p symbol)
1203 (push (list symbol 'custom-variable) found))
1204 (if (custom-facep symbol)
1205 (push (list symbol 'custom-face) found)))))))
1206 (if found
1207 (custom-buffer-create (custom-sort-items found t 'first)
1208 "*Customize Changed Options*")
1209 (error "No user option defaults have been changed since Emacs %s"
1210 since-version))))
1212 (defun customize-package-emacs-version (symbol package-version)
1213 "Return the Emacs version in which SYMBOL's meaning last changed.
1214 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1215 `customize-package-emacs-version-alist' to find the version of
1216 Emacs that is associated with version VERSION of PACKAGE."
1217 (let (package-versions emacs-version)
1218 ;; Use message instead of error since we want user to be able to
1219 ;; see the rest of the symbols even if a package author has
1220 ;; botched things up.
1221 (cond ((not (listp package-version))
1222 (message "Invalid package-version value for %s" symbol))
1223 ((setq package-versions (assq (car package-version)
1224 customize-package-emacs-version-alist))
1225 (setq emacs-version
1226 (cdr (assoc (cdr package-version) package-versions)))
1227 (unless emacs-version
1228 (message "%s version %s not found in %s" symbol
1229 (cdr package-version)
1230 "customize-package-emacs-version-alist")))
1232 (message "Package %s version %s lists no corresponding Emacs version"
1233 (car package-version)
1234 (cdr package-version))))
1235 emacs-version))
1237 (defun customize-version-lessp (version1 version2)
1238 ;; Why are the versions strings, and given that they are, why aren't
1239 ;; they converted to numbers and compared as such here? -- fx
1241 ;; In case someone made a mistake and left out the quotes
1242 ;; in the :version value.
1243 (if (numberp version2)
1244 (setq version2 (prin1-to-string version2)))
1245 (let (major1 major2 minor1 minor2)
1246 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1247 (setq major1 (read (or (match-string 1 version1)
1248 "0")))
1249 (setq minor1 (read (or (match-string 3 version1)
1250 "0")))
1251 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1252 (setq major2 (read (or (match-string 1 version2)
1253 "0")))
1254 (setq minor2 (read (or (match-string 3 version2)
1255 "0")))
1256 (or (< major1 major2)
1257 (and (= major1 major2)
1258 (< minor1 minor2)))))
1260 ;;;###autoload
1261 (defun customize-face (&optional face)
1262 "Customize FACE, which should be a face name or nil.
1263 If FACE is nil, customize all faces. If FACE is actually a
1264 face-alias, customize the face it is aliased to.
1266 Interactively, when point is on text which has a face specified,
1267 suggest to customize that face, if it's customizable."
1268 (interactive
1269 (list (read-face-name "Customize face" "all faces" t)))
1270 (if (member face '(nil ""))
1271 (setq face (face-list)))
1272 (if (and (listp face) (null (cdr face)))
1273 (setq face (car face)))
1274 (if (listp face)
1275 (custom-buffer-create (custom-sort-items
1276 (mapcar (lambda (s)
1277 (list s 'custom-face))
1278 face)
1279 t nil)
1280 "*Customize Faces*")
1281 ;; If FACE is actually an alias, customize the face it is aliased to.
1282 (if (get face 'face-alias)
1283 (setq face (get face 'face-alias)))
1284 (unless (facep face)
1285 (error "Invalid face %S" face))
1286 (custom-buffer-create (list (list face 'custom-face))
1287 (format "*Customize Face: %s*"
1288 (custom-unlispify-tag-name face)))))
1290 ;;;###autoload
1291 (defun customize-face-other-window (&optional face)
1292 "Show customization buffer for face FACE in other window.
1293 If FACE is actually a face-alias, customize the face it is aliased to.
1295 Interactively, when point is on text which has a face specified,
1296 suggest to customize that face, if it's customizable."
1297 (interactive
1298 (list (read-face-name "Customize face" "all faces" t)))
1299 (if (member face '(nil ""))
1300 (setq face (face-list)))
1301 (if (and (listp face) (null (cdr face)))
1302 (setq face (car face)))
1303 (if (listp face)
1304 (custom-buffer-create-other-window
1305 (custom-sort-items
1306 (mapcar (lambda (s)
1307 (list s 'custom-face))
1308 face)
1309 t nil)
1310 "*Customize Faces*")
1311 (if (get face 'face-alias)
1312 (setq face (get face 'face-alias)))
1313 (unless (facep face)
1314 (error "Invalid face %S" face))
1315 (custom-buffer-create-other-window
1316 (list (list face 'custom-face))
1317 (format "*Customize Face: %s*"
1318 (custom-unlispify-tag-name face)))))
1320 ;;;###autoload
1321 (defun customize-customized ()
1322 "Customize all user options set since the last save in this session."
1323 (interactive)
1324 (let ((found nil))
1325 (mapatoms (lambda (symbol)
1326 (and (or (get symbol 'customized-face)
1327 (get symbol 'customized-face-comment))
1328 (custom-facep symbol)
1329 (push (list symbol 'custom-face) found))
1330 (and (or (get symbol 'customized-value)
1331 (get symbol 'customized-variable-comment))
1332 (boundp symbol)
1333 (push (list symbol 'custom-variable) found))))
1334 (if (not found)
1335 (error "No customized user options")
1336 (custom-buffer-create (custom-sort-items found t nil)
1337 "*Customize Customized*"))))
1339 ;;;###autoload
1340 (defun customize-rogue ()
1341 "Customize all user variables modified outside customize."
1342 (interactive)
1343 (let ((found nil))
1344 (mapatoms (lambda (symbol)
1345 (let ((cval (or (get symbol 'customized-value)
1346 (get symbol 'saved-value)
1347 (get symbol 'standard-value))))
1348 (when (and cval ;Declared with defcustom.
1349 (default-boundp symbol) ;Has a value.
1350 (not (equal (eval (car cval))
1351 ;; Which does not match customize.
1352 (default-value symbol))))
1353 (push (list symbol 'custom-variable) found)))))
1354 (if (not found)
1355 (error "No rogue user options")
1356 (custom-buffer-create (custom-sort-items found t nil)
1357 "*Customize Rogue*"))))
1358 ;;;###autoload
1359 (defun customize-saved ()
1360 "Customize all already saved user options."
1361 (interactive)
1362 (let ((found nil))
1363 (mapatoms (lambda (symbol)
1364 (and (or (get symbol 'saved-face)
1365 (get symbol 'saved-face-comment))
1366 (custom-facep symbol)
1367 (push (list symbol 'custom-face) found))
1368 (and (or (get symbol 'saved-value)
1369 (get symbol 'saved-variable-comment))
1370 (boundp symbol)
1371 (push (list symbol 'custom-variable) found))))
1372 (if (not found )
1373 (error "No saved user options")
1374 (custom-buffer-create (custom-sort-items found t nil)
1375 "*Customize Saved*"))))
1377 ;;;###autoload
1378 (defun customize-apropos (regexp &optional all)
1379 "Customize all loaded options, faces and groups matching REGEXP.
1380 If ALL is `options', include only options.
1381 If ALL is `faces', include only faces.
1382 If ALL is `groups', include only groups.
1383 If ALL is t (interactively, with prefix arg), include variables
1384 that are not customizable options, as well as faces and groups
1385 \(but we recommend using `apropos-variable' instead)."
1386 (interactive "sCustomize regexp: \nP")
1387 (let ((found nil))
1388 (mapatoms (lambda (symbol)
1389 (when (string-match regexp (symbol-name symbol))
1390 (when (and (not (memq all '(faces options)))
1391 (get symbol 'custom-group))
1392 (push (list symbol 'custom-group) found))
1393 (when (and (not (memq all '(options groups)))
1394 (custom-facep symbol))
1395 (push (list symbol 'custom-face) found))
1396 (when (and (not (memq all '(groups faces)))
1397 (boundp symbol)
1398 (eq (indirect-variable symbol) symbol)
1399 (or (get symbol 'saved-value)
1400 (custom-variable-p symbol)
1401 (and (not (memq all '(nil options)))
1402 (get symbol 'variable-documentation))))
1403 (push (list symbol 'custom-variable) found)))))
1404 (if (not found)
1405 (error "No customizable items matching %s" regexp)
1406 (custom-buffer-create
1407 (custom-sort-items found t custom-buffer-order-groups)
1408 "*Customize Apropos*"))))
1410 ;;;###autoload
1411 (defun customize-apropos-options (regexp &optional arg)
1412 "Customize all loaded customizable options matching REGEXP.
1413 With prefix arg, include variables that are not customizable options
1414 \(but we recommend using `apropos-variable' instead)."
1415 (interactive "sCustomize regexp: \nP")
1416 (customize-apropos regexp (or arg 'options)))
1418 ;;;###autoload
1419 (defun customize-apropos-faces (regexp)
1420 "Customize all loaded faces matching REGEXP."
1421 (interactive "sCustomize regexp: \n")
1422 (customize-apropos regexp 'faces))
1424 ;;;###autoload
1425 (defun customize-apropos-groups (regexp)
1426 "Customize all loaded groups matching REGEXP."
1427 (interactive "sCustomize regexp: \n")
1428 (customize-apropos regexp 'groups))
1430 ;;; Buffer.
1432 (defcustom custom-buffer-style 'links
1433 "Control the presentation style for customization buffers.
1434 The value should be a symbol, one of:
1436 brackets: groups nest within each other with big horizontal brackets.
1437 links: groups have links to subgroups."
1438 :type '(radio (const brackets)
1439 (const links))
1440 :group 'custom-buffer)
1442 (defcustom custom-buffer-done-kill nil
1443 "*Non-nil means exiting a Custom buffer should kill it."
1444 :type 'boolean
1445 :version "22.1"
1446 :group 'custom-buffer)
1448 (defcustom custom-buffer-indent 3
1449 "Number of spaces to indent nested groups."
1450 :type 'integer
1451 :group 'custom-buffer)
1453 (defun custom-get-fresh-buffer (name)
1454 "Get a fresh new buffer with name NAME.
1455 If the buffer already exist, clean it up to be like new.
1456 Beware: it's not quite like new. Good enough for custom, but maybe
1457 not for everybody."
1458 ;; To be more complete, we should also kill all permanent-local variables,
1459 ;; but it's not needed for custom.
1460 (let ((buf (get-buffer name)))
1461 (when (and buf (buffer-local-value 'buffer-file-name buf))
1462 ;; This will check if the file is not saved.
1463 (kill-buffer buf)
1464 (setq buf nil))
1465 (if (null buf)
1466 (get-buffer-create name)
1467 (with-current-buffer buf
1468 (kill-all-local-variables)
1469 (run-hooks 'kill-buffer-hook)
1470 ;; Delete overlays before erasing the buffer so the overlay hooks
1471 ;; don't get run spuriously when we erase the buffer.
1472 (let ((ols (overlay-lists)))
1473 (dolist (ol (nconc (car ols) (cdr ols)))
1474 (delete-overlay ol)))
1475 (erase-buffer)
1476 buf))))
1478 ;;;###autoload
1479 (defun custom-buffer-create (options &optional name description)
1480 "Create a buffer containing OPTIONS.
1481 Optional NAME is the name of the buffer.
1482 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1483 SYMBOL is a customization option, and WIDGET is a widget for editing
1484 that option."
1485 (pop-to-buffer (custom-get-fresh-buffer (or name "*Customization*")))
1486 (custom-buffer-create-internal options description))
1488 ;;;###autoload
1489 (defun custom-buffer-create-other-window (options &optional name description)
1490 "Create a buffer containing OPTIONS, and display it in another window.
1491 The result includes selecting that window.
1492 Optional NAME is the name of the buffer.
1493 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1494 SYMBOL is a customization option, and WIDGET is a widget for editing
1495 that option."
1496 (unless name (setq name "*Customization*"))
1497 (let ((pop-up-windows t)
1498 (same-window-buffer-names nil)
1499 (same-window-regexps nil))
1500 (pop-to-buffer (custom-get-fresh-buffer name))
1501 (custom-buffer-create-internal options description)))
1503 (defcustom custom-reset-button-menu nil
1504 "If non-nil, only show a single reset button in customize buffers.
1505 This button will have a menu with all three reset operations."
1506 :type 'boolean
1507 :group 'custom-buffer)
1509 (defcustom custom-buffer-verbose-help t
1510 "If non-nil, include explanatory text in the customization buffer."
1511 :type 'boolean
1512 :group 'custom-buffer)
1514 (defun Custom-buffer-done (&rest ignore)
1515 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1516 (interactive)
1517 (quit-window custom-buffer-done-kill))
1519 (defvar custom-button nil
1520 "Face used for buttons in customization buffers.")
1522 (defvar custom-button-mouse nil
1523 "Mouse face used for buttons in customization buffers.")
1525 (defvar custom-button-pressed nil
1526 "Face used for pressed buttons in customization buffers.")
1528 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1529 '(("unspecified" . unspecified))))
1530 "If non-nil, indicate active buttons in a `raised-button' style.
1531 Otherwise use brackets."
1532 :type 'boolean
1533 :version "21.1"
1534 :group 'custom-buffer
1535 :set (lambda (variable value)
1536 (custom-set-default variable value)
1537 (setq custom-button
1538 (if value 'custom-button 'custom-button-unraised))
1539 (setq custom-button-mouse
1540 (if value 'custom-button-mouse 'highlight))
1541 (setq custom-button-pressed
1542 (if value
1543 'custom-button-pressed
1544 'custom-button-pressed-unraised))))
1546 (defun custom-buffer-create-internal (options &optional description)
1547 (custom-mode)
1548 (if custom-buffer-verbose-help
1549 (progn
1550 (widget-insert "This is a customization buffer")
1551 (if description
1552 (widget-insert description))
1553 (widget-insert (format ".
1554 %s buttons; type RET or click mouse-1 to actuate one.
1555 Editing a setting changes only the text in the buffer."
1556 (if custom-raised-buttons
1557 "`Raised' text indicates"
1558 "Square brackets indicate")))
1559 (if init-file-user
1560 (widget-insert "
1561 Use the setting's State button to set it or save changes in it.
1562 Saving a change normally works by editing your Emacs init file.")
1563 (widget-insert "
1564 \nSince you started Emacs with `-q', which inhibits use of the
1565 Emacs init file, you cannot save settings into the Emacs init file."))
1566 (widget-insert "\nSee ")
1567 (widget-create 'custom-manual
1568 :tag "Custom file"
1569 "(emacs)Saving Customizations")
1570 (widget-insert
1571 " for information on how to save in a different file.\n
1572 See ")
1573 (widget-create 'custom-manual
1574 :tag "Help"
1575 :help-echo "Read the online help."
1576 "(emacs)Easy Customization")
1577 (widget-insert " for more information.\n\n")
1578 (widget-insert "Operate on all settings in this buffer that \
1579 are not marked HIDDEN:\n "))
1580 (widget-insert " "))
1581 (widget-create 'push-button
1582 :tag "Set for Current Session"
1583 :help-echo "\
1584 Make your editing in this buffer take effect for this session."
1585 :action (lambda (widget &optional event)
1586 (Custom-set)))
1587 (if (not custom-buffer-verbose-help)
1588 (progn
1589 (widget-insert " ")
1590 (widget-create 'custom-manual
1591 :tag "Help"
1592 :help-echo "Read the online help."
1593 "(emacs)Easy Customization")))
1594 (when (or custom-file user-init-file)
1595 (widget-insert " ")
1596 (widget-create 'push-button
1597 :tag "Save for Future Sessions"
1598 :help-echo "\
1599 Make your editing in this buffer take effect for future Emacs sessions.
1600 This updates your Emacs initialization file or creates a new one."
1601 :action (lambda (widget &optional event)
1602 (Custom-save))))
1603 (if custom-reset-button-menu
1604 (progn
1605 (widget-insert " ")
1606 (widget-create 'push-button
1607 :tag "Reset buffer"
1608 :help-echo "Show a menu with reset operations."
1609 :mouse-down-action (lambda (&rest junk) t)
1610 :action (lambda (widget &optional event)
1611 (custom-reset event))))
1612 (widget-insert "\n ")
1613 (widget-create 'push-button
1614 :tag "Undo Edits"
1615 :help-echo "\
1616 Reset all edited text in this buffer to reflect current values."
1617 :action 'Custom-reset-current)
1618 (widget-insert " ")
1619 (widget-create 'push-button
1620 :tag "Reset to Saved"
1621 :help-echo "\
1622 Reset all settings in this buffer to their saved values."
1623 :action 'Custom-reset-saved)
1624 (widget-insert " ")
1625 (when (or custom-file user-init-file)
1626 (widget-create 'push-button
1627 :tag "Erase Customization"
1628 :help-echo "\
1629 Un-customize all settings in this buffer and save them with standard values."
1630 :action 'Custom-reset-standard)))
1631 (widget-insert " ")
1632 (widget-create 'push-button
1633 :tag "Finish"
1634 :help-echo
1635 (lambda (&rest ignore)
1636 (if custom-buffer-done-kill
1637 "Kill this buffer"
1638 "Bury this buffer"))
1639 :action #'Custom-buffer-done)
1640 (widget-insert "\n\n")
1641 (message "Creating customization items...")
1642 (buffer-disable-undo)
1643 (setq custom-options
1644 (if (= (length options) 1)
1645 (mapcar (lambda (entry)
1646 (widget-create (nth 1 entry)
1647 :documentation-shown t
1648 :custom-state 'unknown
1649 :tag (custom-unlispify-tag-name
1650 (nth 0 entry))
1651 :value (nth 0 entry)))
1652 options)
1653 (let ((count 0)
1654 (length (length options)))
1655 (mapcar (lambda (entry)
1656 (prog2
1657 (message "Creating customization items ...%2d%%"
1658 (/ (* 100.0 count) length))
1659 (widget-create (nth 1 entry)
1660 :tag (custom-unlispify-tag-name
1661 (nth 0 entry))
1662 :value (nth 0 entry))
1663 (setq count (1+ count))
1664 (unless (eq (preceding-char) ?\n)
1665 (widget-insert "\n"))
1666 (widget-insert "\n")))
1667 options))))
1668 (unless (eq (preceding-char) ?\n)
1669 (widget-insert "\n"))
1670 (message "Creating customization items ...done")
1671 (message "Resetting customization items...")
1672 (unless (eq custom-buffer-style 'tree)
1673 (mapc 'custom-magic-reset custom-options))
1674 (message "Resetting customization items...done")
1675 (message "Creating customization setup...")
1676 (widget-setup)
1677 (buffer-enable-undo)
1678 (goto-char (point-min))
1679 (message "Creating customization setup...done"))
1681 ;;; The Tree Browser.
1683 ;;;###autoload
1684 (defun customize-browse (&optional group)
1685 "Create a tree browser for the customize hierarchy."
1686 (interactive)
1687 (unless group
1688 (setq group 'emacs))
1689 (let ((name "*Customize Browser*"))
1690 (pop-to-buffer (custom-get-fresh-buffer name)))
1691 (custom-mode)
1692 (widget-insert (format "\
1693 %s buttons; type RET or click mouse-1
1694 on a button to invoke its action.
1695 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1696 (if custom-raised-buttons
1697 "`Raised' text indicates"
1698 "Square brackets indicate")))
1701 (if custom-browse-only-groups
1702 (widget-insert "\
1703 Invoke the [Group] button below to edit that item in another window.\n\n")
1704 (widget-insert "Invoke the ")
1705 (widget-create 'item
1706 :format "%t"
1707 :tag "[Group]"
1708 :tag-glyph "folder")
1709 (widget-insert ", ")
1710 (widget-create 'item
1711 :format "%t"
1712 :tag "[Face]"
1713 :tag-glyph "face")
1714 (widget-insert ", and ")
1715 (widget-create 'item
1716 :format "%t"
1717 :tag "[Option]"
1718 :tag-glyph "option")
1719 (widget-insert " buttons below to edit that
1720 item in another window.\n\n"))
1721 (let ((custom-buffer-style 'tree))
1722 (widget-create 'custom-group
1723 :custom-last t
1724 :custom-state 'unknown
1725 :tag (custom-unlispify-tag-name group)
1726 :value group))
1727 (widget-setup)
1728 (goto-char (point-min)))
1730 (define-widget 'custom-browse-visibility 'item
1731 "Control visibility of items in the customize tree browser."
1732 :format "%[[%t]%]"
1733 :action 'custom-browse-visibility-action)
1735 (defun custom-browse-visibility-action (widget &rest ignore)
1736 (let ((custom-buffer-style 'tree))
1737 (custom-toggle-parent widget)))
1739 (define-widget 'custom-browse-group-tag 'custom-group-link
1740 "Show parent in other window when activated."
1741 :tag "Group"
1742 :tag-glyph "folder"
1743 :action 'custom-browse-group-tag-action)
1745 (defun custom-browse-group-tag-action (widget &rest ignore)
1746 (let ((parent (widget-get widget :parent)))
1747 (customize-group-other-window (widget-value parent))))
1749 (define-widget 'custom-browse-variable-tag 'custom-group-link
1750 "Show parent in other window when activated."
1751 :tag "Option"
1752 :tag-glyph "option"
1753 :action 'custom-browse-variable-tag-action)
1755 (defun custom-browse-variable-tag-action (widget &rest ignore)
1756 (let ((parent (widget-get widget :parent)))
1757 (customize-variable-other-window (widget-value parent))))
1759 (define-widget 'custom-browse-face-tag 'custom-group-link
1760 "Show parent in other window when activated."
1761 :tag "Face"
1762 :tag-glyph "face"
1763 :action 'custom-browse-face-tag-action)
1765 (defun custom-browse-face-tag-action (widget &rest ignore)
1766 (let ((parent (widget-get widget :parent)))
1767 (customize-face-other-window (widget-value parent))))
1769 (defconst custom-browse-alist '((" " "space")
1770 (" | " "vertical")
1771 ("-\\ " "top")
1772 (" |-" "middle")
1773 (" `-" "bottom")))
1775 (defun custom-browse-insert-prefix (prefix)
1776 "Insert PREFIX. On XEmacs convert it to line graphics."
1777 ;; Fixme: do graphics.
1778 (if nil ; (string-match "XEmacs" emacs-version)
1779 (progn
1780 (insert "*")
1781 (while (not (string-equal prefix ""))
1782 (let ((entry (substring prefix 0 3)))
1783 (setq prefix (substring prefix 3))
1784 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1785 (name (nth 1 (assoc entry custom-browse-alist))))
1786 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1787 (overlay-put overlay 'start-open t)
1788 (overlay-put overlay 'end-open t)))))
1789 (insert prefix)))
1791 ;;; Modification of Basic Widgets.
1793 ;; We add extra properties to the basic widgets needed here. This is
1794 ;; fine, as long as we are careful to stay within out own namespace.
1796 ;; We want simple widgets to be displayed by default, but complex
1797 ;; widgets to be hidden.
1799 (widget-put (get 'item 'widget-type) :custom-show t)
1800 (widget-put (get 'editable-field 'widget-type)
1801 :custom-show (lambda (widget value)
1802 (let ((pp (pp-to-string value)))
1803 (cond ((string-match "\n" pp)
1804 nil)
1805 ((> (length pp) 40)
1806 nil)
1807 (t t)))))
1808 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1810 ;;; The `custom-manual' Widget.
1812 (define-widget 'custom-manual 'info-link
1813 "Link to the manual entry for this customization option."
1814 :help-echo "Read the manual entry for this option."
1815 :keymap custom-mode-link-map
1816 :follow-link 'mouse-face
1817 :button-face 'custom-link
1818 :mouse-face 'highlight
1819 :pressed-face 'highlight
1820 :tag "Manual")
1822 ;;; The `custom-magic' Widget.
1824 (defgroup custom-magic-faces nil
1825 "Faces used by the magic button."
1826 :group 'custom-faces
1827 :group 'custom-buffer)
1829 (defface custom-invalid '((((class color))
1830 (:foreground "yellow1" :background "red1"))
1832 (:weight bold :slant italic :underline t)))
1833 "Face used when the customize item is invalid."
1834 :group 'custom-magic-faces)
1835 ;; backward-compatibility alias
1836 (put 'custom-invalid-face 'face-alias 'custom-invalid)
1838 (defface custom-rogue '((((class color))
1839 (:foreground "pink" :background "black"))
1841 (:underline t)))
1842 "Face used when the customize item is not defined for customization."
1843 :group 'custom-magic-faces)
1844 ;; backward-compatibility alias
1845 (put 'custom-rogue-face 'face-alias 'custom-rogue)
1847 (defface custom-modified '((((min-colors 88) (class color))
1848 (:foreground "white" :background "blue1"))
1849 (((class color))
1850 (:foreground "white" :background "blue"))
1852 (:slant italic :bold)))
1853 "Face used when the customize item has been modified."
1854 :group 'custom-magic-faces)
1855 ;; backward-compatibility alias
1856 (put 'custom-modified-face 'face-alias 'custom-modified)
1858 (defface custom-set '((((min-colors 88) (class color))
1859 (:foreground "blue1" :background "white"))
1860 (((class color))
1861 (:foreground "blue" :background "white"))
1863 (:slant italic)))
1864 "Face used when the customize item has been set."
1865 :group 'custom-magic-faces)
1866 ;; backward-compatibility alias
1867 (put 'custom-set-face 'face-alias 'custom-set)
1869 (defface custom-changed '((((min-colors 88) (class color))
1870 (:foreground "white" :background "blue1"))
1871 (((class color))
1872 (:foreground "white" :background "blue"))
1874 (:slant italic)))
1875 "Face used when the customize item has been changed."
1876 :group 'custom-magic-faces)
1877 ;; backward-compatibility alias
1878 (put 'custom-changed-face 'face-alias 'custom-changed)
1880 (defface custom-themed '((((min-colors 88) (class color))
1881 (:foreground "white" :background "blue1"))
1882 (((class color))
1883 (:foreground "white" :background "blue"))
1885 (:slant italic)))
1886 "Face used when the customize item has been set by a theme."
1887 :group 'custom-magic-faces)
1889 (defface custom-saved '((t (:underline t)))
1890 "Face used when the customize item has been saved."
1891 :group 'custom-magic-faces)
1892 ;; backward-compatibility alias
1893 (put 'custom-saved-face 'face-alias 'custom-saved)
1895 (defconst custom-magic-alist
1896 '((nil "#" underline "\
1897 UNINITIALIZED, you should not see this.")
1898 (unknown "?" italic "\
1899 UNKNOWN, you should not see this.")
1900 (hidden "-" default "\
1901 HIDDEN, invoke \"Show\" in the previous line to show." "\
1902 group now hidden, invoke \"Show\", above, to show contents.")
1903 (invalid "x" custom-invalid "\
1904 INVALID, the displayed value cannot be set.")
1905 (modified "*" custom-modified "\
1906 EDITED, shown value does not take effect until you set or save it." "\
1907 something in this group has been edited but not set.")
1908 (set "+" custom-set "\
1909 SET for current session only." "\
1910 something in this group has been set but not saved.")
1911 (changed ":" custom-changed "\
1912 CHANGED outside Customize; operating on it here may be unreliable." "\
1913 something in this group has been changed outside customize.")
1914 (saved "!" custom-saved "\
1915 SAVED and set." "\
1916 something in this group has been set and saved.")
1917 (themed "o" custom-themed "\
1918 THEMED." "\
1919 visible group members are all at standard values.")
1920 (rogue "@" custom-rogue "\
1921 NO CUSTOMIZATION DATA; not intended to be customized." "\
1922 something in this group is not prepared for customization.")
1923 (standard " " nil "\
1924 STANDARD." "\
1925 visible group members are all at standard values."))
1926 "Alist of customize option states.
1927 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1929 STATE is one of the following symbols:
1931 `nil'
1932 For internal use, should never occur.
1933 `unknown'
1934 For internal use, should never occur.
1935 `hidden'
1936 This item is not being displayed.
1937 `invalid'
1938 This item is modified, but has an invalid form.
1939 `modified'
1940 This item is modified, and has a valid form.
1941 `set'
1942 This item has been set but not saved.
1943 `changed'
1944 The current value of this item has been changed outside Customize.
1945 `saved'
1946 This item is marked for saving.
1947 `rogue'
1948 This item has no customization information.
1949 `standard'
1950 This item is unchanged from the standard setting.
1952 MAGIC is a string used to present that state.
1954 FACE is a face used to present the state.
1956 ITEM-DESC is a string describing the state for options.
1958 GROUP-DESC is a string describing the state for groups. If this is
1959 left out, ITEM-DESC will be used.
1961 The string %c in either description will be replaced with the
1962 category of the item. These are `group'. `option', and `face'.
1964 The list should be sorted most significant first.")
1966 (defcustom custom-magic-show 'long
1967 "If non-nil, show textual description of the state.
1968 If `long', show a full-line description, not just one word."
1969 :type '(choice (const :tag "no" nil)
1970 (const long)
1971 (other :tag "short" short))
1972 :group 'custom-buffer)
1974 (defcustom custom-magic-show-hidden '(option face)
1975 "Control whether the State button is shown for hidden items.
1976 The value should be a list with the custom categories where the State
1977 button should be visible. Possible categories are `group', `option',
1978 and `face'."
1979 :type '(set (const group) (const option) (const face))
1980 :group 'custom-buffer)
1982 (defcustom custom-magic-show-button nil
1983 "Show a \"magic\" button indicating the state of each customization option."
1984 :type 'boolean
1985 :group 'custom-buffer)
1987 (define-widget 'custom-magic 'default
1988 "Show and manipulate state for a customization option."
1989 :format "%v"
1990 :action 'widget-parent-action
1991 :notify 'ignore
1992 :value-get 'ignore
1993 :value-create 'custom-magic-value-create
1994 :value-delete 'widget-children-value-delete)
1996 (defun widget-magic-mouse-down-action (widget &optional event)
1997 ;; Non-nil unless hidden.
1998 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1999 :custom-state)
2000 'hidden)))
2002 (defun custom-magic-value-create (widget)
2003 "Create compact status report for WIDGET."
2004 (let* ((parent (widget-get widget :parent))
2005 (state (widget-get parent :custom-state))
2006 (hidden (eq state 'hidden))
2007 (entry (assq state custom-magic-alist))
2008 (magic (nth 1 entry))
2009 (face (nth 2 entry))
2010 (category (widget-get parent :custom-category))
2011 (text (or (and (eq category 'group)
2012 (nth 4 entry))
2013 (nth 3 entry)))
2014 (form (widget-get parent :custom-form))
2015 children)
2016 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
2017 (setq text (concat (match-string 1 text)
2018 (symbol-name category)
2019 (match-string 2 text))))
2020 (when (and custom-magic-show
2021 (or (not hidden)
2022 (memq category custom-magic-show-hidden)))
2023 (insert " ")
2024 (when (and (eq category 'group)
2025 (not (and (eq custom-buffer-style 'links)
2026 (> (widget-get parent :custom-level) 1))))
2027 (insert-char ?\ (* custom-buffer-indent
2028 (widget-get parent :custom-level))))
2029 (push (widget-create-child-and-convert
2030 widget 'choice-item
2031 :help-echo "Change the state of this item."
2032 :format (if hidden "%t" "%[%t%]")
2033 :button-prefix 'widget-push-button-prefix
2034 :button-suffix 'widget-push-button-suffix
2035 :mouse-down-action 'widget-magic-mouse-down-action
2036 :tag "State")
2037 children)
2038 (insert ": ")
2039 (let ((start (point)))
2040 (if (eq custom-magic-show 'long)
2041 (insert text)
2042 (insert (symbol-name state)))
2043 (cond ((eq form 'lisp)
2044 (insert " (lisp)"))
2045 ((eq form 'mismatch)
2046 (insert " (mismatch)")))
2047 (put-text-property start (point) 'face 'custom-state))
2048 (insert "\n"))
2049 (when (and (eq category 'group)
2050 (not (and (eq custom-buffer-style 'links)
2051 (> (widget-get parent :custom-level) 1))))
2052 (insert-char ?\ (* custom-buffer-indent
2053 (widget-get parent :custom-level))))
2054 (when custom-magic-show-button
2055 (when custom-magic-show
2056 (let ((indent (widget-get parent :indent)))
2057 (when indent
2058 (insert-char ? indent))))
2059 (push (widget-create-child-and-convert
2060 widget 'choice-item
2061 :mouse-down-action 'widget-magic-mouse-down-action
2062 :button-face face
2063 :button-prefix ""
2064 :button-suffix ""
2065 :help-echo "Change the state."
2066 :format (if hidden "%t" "%[%t%]")
2067 :tag (if (memq form '(lisp mismatch))
2068 (concat "(" magic ")")
2069 (concat "[" magic "]")))
2070 children)
2071 (insert " "))
2072 (widget-put widget :children children)))
2074 (defun custom-magic-reset (widget)
2075 "Redraw the :custom-magic property of WIDGET."
2076 (let ((magic (widget-get widget :custom-magic)))
2077 (widget-value-set magic (widget-value magic))))
2079 ;;; The `custom' Widget.
2081 (defface custom-button
2082 '((((type x w32 mac) (class color)) ; Like default modeline
2083 (:box (:line-width 2 :style released-button)
2084 :background "lightgrey" :foreground "black"))
2086 nil))
2087 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2088 :version "21.1"
2089 :group 'custom-faces)
2090 ;; backward-compatibility alias
2091 (put 'custom-button-face 'face-alias 'custom-button)
2093 (defface custom-button-mouse
2094 '((((type x w32 mac) (class color))
2095 (:box (:line-width 2 :style released-button)
2096 :background "grey90" :foreground "black"))
2098 nil))
2099 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2100 :version "22.1"
2101 :group 'custom-faces)
2103 (defface custom-button-unraised
2104 '((t :inherit underline))
2105 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2106 :version "22.1"
2107 :group 'custom-faces)
2109 (setq custom-button
2110 (if custom-raised-buttons 'custom-button 'custom-button-unraised))
2112 (setq custom-button-mouse
2113 (if custom-raised-buttons 'custom-button-mouse 'highlight))
2115 (defface custom-button-pressed
2116 '((((type x w32 mac) (class color))
2117 (:box (:line-width 2 :style pressed-button)
2118 :background "lightgrey" :foreground "black"))
2120 (:inverse-video t)))
2121 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2122 :version "21.1"
2123 :group 'custom-faces)
2124 ;; backward-compatibility alias
2125 (put 'custom-button-pressed-face 'face-alias 'custom-button-pressed)
2127 (defface custom-button-pressed-unraised
2128 '((default :inherit custom-button-unraised)
2129 (((class color) (background light)) :foreground "magenta4")
2130 (((class color) (background dark)) :foreground "violet"))
2131 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2132 :version "22.1"
2133 :group 'custom-faces)
2135 (setq custom-button-pressed
2136 (if custom-raised-buttons
2137 'custom-button-pressed
2138 'custom-button-pressed-unraised))
2140 (defface custom-documentation '((t nil))
2141 "Face used for documentation strings in customization buffers."
2142 :group 'custom-faces)
2143 ;; backward-compatibility alias
2144 (put 'custom-documentation-face 'face-alias 'custom-documentation)
2146 (defface custom-state '((((class color)
2147 (background dark))
2148 (:foreground "lime green"))
2149 (((class color)
2150 (background light))
2151 (:foreground "dark green"))
2152 (t nil))
2153 "Face used for State descriptions in the customize buffer."
2154 :group 'custom-faces)
2155 ;; backward-compatibility alias
2156 (put 'custom-state-face 'face-alias 'custom-state)
2158 (defface custom-link
2159 '((t :inherit link))
2160 "Face for links in customization buffers."
2161 :version "22.1"
2162 :group 'custom-faces)
2164 (define-widget 'custom 'default
2165 "Customize a user option."
2166 :format "%v"
2167 :convert-widget 'custom-convert-widget
2168 :notify 'custom-notify
2169 :custom-prefix ""
2170 :custom-level 1
2171 :custom-state 'hidden
2172 :documentation-property 'widget-subclass-responsibility
2173 :value-create 'widget-subclass-responsibility
2174 :value-delete 'widget-children-value-delete
2175 :value-get 'widget-value-value-get
2176 :validate 'widget-children-validate
2177 :match (lambda (widget value) (symbolp value)))
2179 (defun custom-convert-widget (widget)
2180 "Initialize :value and :tag from :args in WIDGET."
2181 (let ((args (widget-get widget :args)))
2182 (when args
2183 (widget-put widget :value (widget-apply widget
2184 :value-to-internal (car args)))
2185 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
2186 (widget-put widget :args nil)))
2187 widget)
2189 (defun custom-notify (widget &rest args)
2190 "Keep track of changes."
2191 (let ((state (widget-get widget :custom-state)))
2192 (unless (eq state 'modified)
2193 (unless (memq state '(nil unknown hidden))
2194 (widget-put widget :custom-state 'modified))
2195 (custom-magic-reset widget)
2196 (apply 'widget-default-notify widget args))))
2198 (defun custom-redraw (widget)
2199 "Redraw WIDGET with current settings."
2200 (let ((line (count-lines (point-min) (point)))
2201 (column (current-column))
2202 (pos (point))
2203 (from (marker-position (widget-get widget :from)))
2204 (to (marker-position (widget-get widget :to))))
2205 (save-excursion
2206 (widget-value-set widget (widget-value widget))
2207 (custom-redraw-magic widget))
2208 (when (and (>= pos from) (<= pos to))
2209 (condition-case nil
2210 (progn
2211 (if (> column 0)
2212 (goto-line line)
2213 (goto-line (1+ line)))
2214 (move-to-column column))
2215 (error nil)))))
2217 (defun custom-redraw-magic (widget)
2218 "Redraw WIDGET state with current settings."
2219 (while widget
2220 (let ((magic (widget-get widget :custom-magic)))
2221 (cond (magic
2222 (widget-value-set magic (widget-value magic))
2223 (when (setq widget (widget-get widget :group))
2224 (custom-group-state-update widget)))
2226 (setq widget nil)))))
2227 (widget-setup))
2229 (defun custom-show (widget value)
2230 "Non-nil if WIDGET should be shown with VALUE by default."
2231 (let ((show (widget-get widget :custom-show)))
2232 (cond ((null show)
2233 nil)
2234 ((eq t show)
2237 (funcall show widget value)))))
2239 (defun custom-load-widget (widget)
2240 "Load all dependencies for WIDGET."
2241 (custom-load-symbol (widget-value widget)))
2243 (defun custom-unloaded-symbol-p (symbol)
2244 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2245 (let ((found nil)
2246 (loads (get symbol 'custom-loads))
2247 load)
2248 (while loads
2249 (setq load (car loads)
2250 loads (cdr loads))
2251 (cond ((symbolp load)
2252 (unless (featurep load)
2253 (setq found t)))
2254 ((assoc load load-history))
2255 ((assoc (locate-library load) load-history)
2256 (message nil))
2258 (setq found t))))
2259 found))
2261 (defun custom-unloaded-widget-p (widget)
2262 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2263 (custom-unloaded-symbol-p (widget-value widget)))
2265 (defun custom-toggle-hide (widget)
2266 "Toggle visibility of WIDGET."
2267 (custom-load-widget widget)
2268 (let ((state (widget-get widget :custom-state)))
2269 (cond ((memq state '(invalid modified))
2270 (error "There are unset changes"))
2271 ((eq state 'hidden)
2272 (widget-put widget :custom-state 'unknown))
2274 (widget-put widget :documentation-shown nil)
2275 (widget-put widget :custom-state 'hidden)))
2276 (custom-redraw widget)
2277 (widget-setup)))
2279 (defun custom-toggle-parent (widget &rest ignore)
2280 "Toggle visibility of parent of WIDGET."
2281 (custom-toggle-hide (widget-get widget :parent)))
2283 (defun custom-add-see-also (widget &optional prefix)
2284 "Add `See also ...' to WIDGET if there are any links.
2285 Insert PREFIX first if non-nil."
2286 (let* ((symbol (widget-get widget :value))
2287 (links (get symbol 'custom-links))
2288 (many (> (length links) 2))
2289 (buttons (widget-get widget :buttons))
2290 (indent (widget-get widget :indent)))
2291 (when links
2292 (when indent
2293 (insert-char ?\ indent))
2294 (when prefix
2295 (insert prefix))
2296 (insert "See also ")
2297 (while links
2298 (push (widget-create-child-and-convert
2299 widget (car links)
2300 :button-face 'custom-link
2301 :mouse-face 'highlight
2302 :pressed-face 'highlight)
2303 buttons)
2304 (setq links (cdr links))
2305 (cond ((null links)
2306 (insert ".\n"))
2307 ((null (cdr links))
2308 (if many
2309 (insert ", and ")
2310 (insert " and ")))
2312 (insert ", "))))
2313 (widget-put widget :buttons buttons))))
2315 (defun custom-add-parent-links (widget &optional initial-string)
2316 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2317 The value is non-nil if any parents were found.
2318 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2319 (let ((name (widget-value widget))
2320 (type (widget-type widget))
2321 (buttons (widget-get widget :buttons))
2322 (start (point))
2323 (parents nil))
2324 (insert (or initial-string "Parent groups:"))
2325 (mapatoms (lambda (symbol)
2326 (when (member (list name type) (get symbol 'custom-group))
2327 (insert " ")
2328 (push (widget-create-child-and-convert
2329 widget 'custom-group-link
2330 :tag (custom-unlispify-tag-name symbol)
2331 symbol)
2332 buttons)
2333 (setq parents (cons symbol parents)))))
2334 (and (null (get name 'custom-links)) ;No links of its own.
2335 (= (length parents) 1) ;A single parent.
2336 (let* ((links (delq nil (mapcar (lambda (w)
2337 (unless (eq (widget-type w)
2338 'custom-group-link)
2340 (get (car parents) 'custom-links))))
2341 (many (> (length links) 2)))
2342 (when links
2343 (insert "\nParent documentation: ")
2344 (while links
2345 (push (widget-create-child-and-convert
2346 widget (car links)
2347 :button-face 'custom-link
2348 :mouse-face 'highlight
2349 :pressed-face 'highlight)
2350 buttons)
2351 (setq links (cdr links))
2352 (cond ((null links)
2353 (insert ".\n"))
2354 ((null (cdr links))
2355 (if many
2356 (insert ", and ")
2357 (insert " and ")))
2359 (insert ", ")))))))
2360 (if parents
2361 (insert "\n")
2362 (delete-region start (point)))
2363 (widget-put widget :buttons buttons)
2364 parents))
2366 ;;; The `custom-comment' Widget.
2368 ;; like the editable field
2369 (defface custom-comment '((((type tty))
2370 :background "yellow3"
2371 :foreground "black")
2372 (((class grayscale color)
2373 (background light))
2374 :background "gray85")
2375 (((class grayscale color)
2376 (background dark))
2377 :background "dim gray")
2379 :slant italic))
2380 "Face used for comments on variables or faces"
2381 :version "21.1"
2382 :group 'custom-faces)
2383 ;; backward-compatibility alias
2384 (put 'custom-comment-face 'face-alias 'custom-comment)
2386 ;; like font-lock-comment-face
2387 (defface custom-comment-tag
2388 '((((class color) (background dark)) (:foreground "gray80"))
2389 (((class color) (background light)) (:foreground "blue4"))
2390 (((class grayscale) (background light))
2391 (:foreground "DimGray" :weight bold :slant italic))
2392 (((class grayscale) (background dark))
2393 (:foreground "LightGray" :weight bold :slant italic))
2394 (t (:weight bold)))
2395 "Face used for variables or faces comment tags"
2396 :group 'custom-faces)
2397 ;; backward-compatibility alias
2398 (put 'custom-comment-tag-face 'face-alias 'custom-comment-tag)
2400 (define-widget 'custom-comment 'string
2401 "User comment."
2402 :tag "Comment"
2403 :help-echo "Edit a comment here."
2404 :sample-face 'custom-comment-tag-face
2405 :value-face 'custom-comment-face
2406 :shown nil
2407 :create 'custom-comment-create)
2409 (defun custom-comment-create (widget)
2410 (let* ((null-comment (equal "" (widget-value widget))))
2411 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2412 (not null-comment))
2413 (widget-default-create widget)
2414 ;; `widget-default-delete' expects markers in these slots --
2415 ;; maybe it shouldn't.
2416 (widget-put widget :from (point-marker))
2417 (widget-put widget :to (point-marker)))))
2419 (defun custom-comment-hide (widget)
2420 (widget-put (widget-get widget :parent) :comment-shown nil))
2422 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2423 ;; the global custom one
2424 (defun custom-comment-show (widget)
2425 (widget-put widget :comment-shown t)
2426 (custom-redraw widget)
2427 (widget-setup))
2429 (defun custom-comment-invisible-p (widget)
2430 (let ((val (widget-value (widget-get widget :comment-widget))))
2431 (and (equal "" val)
2432 (not (widget-get widget :comment-shown)))))
2434 ;;; The `custom-variable' Widget.
2436 ;; When this was underlined blue, users confused it with a
2437 ;; Mosaic-style hyperlink...
2438 (defface custom-variable-tag
2439 `((((class color)
2440 (background dark))
2441 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
2442 (((min-colors 88) (class color)
2443 (background light))
2444 (:foreground "blue1" :weight bold :height 1.2 :inherit variable-pitch))
2445 (((class color)
2446 (background light))
2447 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
2448 (t (:weight bold)))
2449 "Face used for unpushable variable tags."
2450 :group 'custom-faces)
2451 ;; backward-compatibility alias
2452 (put 'custom-variable-tag-face 'face-alias 'custom-variable-tag)
2454 (defface custom-variable-button '((t (:underline t :weight bold)))
2455 "Face used for pushable variable tags."
2456 :group 'custom-faces)
2457 ;; backward-compatibility alias
2458 (put 'custom-variable-button-face 'face-alias 'custom-variable-button)
2460 (defcustom custom-variable-default-form 'edit
2461 "Default form of displaying variable values."
2462 :type '(choice (const edit)
2463 (const lisp))
2464 :group 'custom-buffer
2465 :version "20.3")
2467 (defun custom-variable-documentation (variable)
2468 "Return documentation of VARIABLE for use in Custom buffer.
2469 Normally just return the docstring. But if VARIABLE automatically
2470 becomes buffer local when set, append a message to that effect."
2471 (if (and (local-variable-if-set-p variable)
2472 (or (not (local-variable-p variable))
2473 (with-temp-buffer
2474 (local-variable-if-set-p variable))))
2475 (concat (documentation-property variable 'variable-documentation)
2477 This variable automatically becomes buffer-local when set outside Custom.
2478 However, setting it through Custom sets the default value.")
2479 (documentation-property variable 'variable-documentation)))
2481 (define-widget 'custom-variable 'custom
2482 "Customize variable."
2483 :format "%v"
2484 :help-echo "Set or reset this variable."
2485 :documentation-property #'custom-variable-documentation
2486 :custom-category 'option
2487 :custom-state nil
2488 :custom-menu 'custom-variable-menu-create
2489 :custom-form nil ; defaults to value of `custom-variable-default-form'
2490 :value-create 'custom-variable-value-create
2491 :action 'custom-variable-action
2492 :custom-set 'custom-variable-set
2493 :custom-save 'custom-variable-save
2494 :custom-reset-current 'custom-redraw
2495 :custom-reset-saved 'custom-variable-reset-saved
2496 :custom-reset-standard 'custom-variable-reset-standard
2497 :custom-standard-value 'custom-variable-standard-value)
2499 (defun custom-variable-type (symbol)
2500 "Return a widget suitable for editing the value of SYMBOL.
2501 If SYMBOL has a `custom-type' property, use that.
2502 Otherwise, look up symbol in `custom-guess-type-alist'."
2503 (let* ((type (or (get symbol 'custom-type)
2504 (and (not (get symbol 'standard-value))
2505 (custom-guess-type symbol))
2506 'sexp))
2507 (options (get symbol 'custom-options))
2508 (tmp (if (listp type)
2509 (copy-sequence type)
2510 (list type))))
2511 (when options
2512 (widget-put tmp :options options))
2513 tmp))
2515 (defun custom-variable-value-create (widget)
2516 "Here is where you edit the variable's value."
2517 (custom-load-widget widget)
2518 (unless (widget-get widget :custom-form)
2519 (widget-put widget :custom-form custom-variable-default-form))
2520 (let* ((buttons (widget-get widget :buttons))
2521 (children (widget-get widget :children))
2522 (form (widget-get widget :custom-form))
2523 (state (widget-get widget :custom-state))
2524 (symbol (widget-get widget :value))
2525 (tag (widget-get widget :tag))
2526 (type (custom-variable-type symbol))
2527 (conv (widget-convert type))
2528 (get (or (get symbol 'custom-get) 'default-value))
2529 (prefix (widget-get widget :custom-prefix))
2530 (last (widget-get widget :custom-last))
2531 (value (if (default-boundp symbol)
2532 (funcall get symbol)
2533 (widget-get conv :value))))
2534 ;; If the widget is new, the child determines whether it is hidden.
2535 (cond (state)
2536 ((custom-show type value)
2537 (setq state 'unknown))
2539 (setq state 'hidden)))
2540 ;; If we don't know the state, see if we need to edit it in lisp form.
2541 (when (eq state 'unknown)
2542 (unless (widget-apply conv :match value)
2543 ;; (widget-apply (widget-convert type) :match value)
2544 (setq form 'mismatch)))
2545 ;; Now we can create the child widget.
2546 (cond ((eq custom-buffer-style 'tree)
2547 (insert prefix (if last " `--- " " |--- "))
2548 (push (widget-create-child-and-convert
2549 widget 'custom-browse-variable-tag)
2550 buttons)
2551 (insert " " tag "\n")
2552 (widget-put widget :buttons buttons))
2553 ((eq state 'hidden)
2554 ;; Indicate hidden value.
2555 (push (widget-create-child-and-convert
2556 widget 'item
2557 :format "%{%t%}: "
2558 :sample-face 'custom-variable-tag-face
2559 :tag tag
2560 :parent widget)
2561 buttons)
2562 (push (widget-create-child-and-convert
2563 widget 'visibility
2564 :help-echo "Show the value of this option."
2565 :off "Show Value"
2566 :action 'custom-toggle-parent
2567 nil)
2568 buttons))
2569 ((memq form '(lisp mismatch))
2570 ;; In lisp mode edit the saved value when possible.
2571 (let* ((value (cond ((get symbol 'saved-value)
2572 (car (get symbol 'saved-value)))
2573 ((get symbol 'standard-value)
2574 (car (get symbol 'standard-value)))
2575 ((default-boundp symbol)
2576 (custom-quote (funcall get symbol)))
2578 (custom-quote (widget-get conv :value))))))
2579 (insert (symbol-name symbol) ": ")
2580 (push (widget-create-child-and-convert
2581 widget 'visibility
2582 :help-echo "Hide the value of this option."
2583 :on "Hide Value"
2584 :off "Show Value"
2585 :action 'custom-toggle-parent
2587 buttons)
2588 (insert " ")
2589 (push (widget-create-child-and-convert
2590 widget 'sexp
2591 :button-face 'custom-variable-button-face
2592 :format "%v"
2593 :tag (symbol-name symbol)
2594 :parent widget
2595 :value value)
2596 children)))
2598 ;; Edit mode.
2599 (let* ((format (widget-get type :format))
2600 tag-format value-format)
2601 (unless (string-match ":" format)
2602 (error "Bad format"))
2603 (setq tag-format (substring format 0 (match-end 0)))
2604 (setq value-format (substring format (match-end 0)))
2605 (push (widget-create-child-and-convert
2606 widget 'item
2607 :format tag-format
2608 :action 'custom-tag-action
2609 :help-echo "Change value of this option."
2610 :mouse-down-action 'custom-tag-mouse-down-action
2611 :button-face 'custom-variable-button-face
2612 :sample-face 'custom-variable-tag-face
2613 tag)
2614 buttons)
2615 (insert " ")
2616 (push (widget-create-child-and-convert
2617 widget 'visibility
2618 :help-echo "Hide the value of this option."
2619 :on "Hide Value"
2620 :off "Show Value"
2621 :action 'custom-toggle-parent
2623 buttons)
2624 (push (widget-create-child-and-convert
2625 widget type
2626 :format value-format
2627 :value value)
2628 children))))
2629 (unless (eq custom-buffer-style 'tree)
2630 (unless (eq (preceding-char) ?\n)
2631 (widget-insert "\n"))
2632 ;; Create the magic button.
2633 (let ((magic (widget-create-child-and-convert
2634 widget 'custom-magic nil)))
2635 (widget-put widget :custom-magic magic)
2636 (push magic buttons))
2637 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2638 ;; before the call to `widget-default-format-handler'. Otherwise, I
2639 ;; loose my current `buttons'. This function shouldn't be called like
2640 ;; this anyway. The doc string widget should be added like the others.
2641 ;; --dv
2642 (widget-put widget :buttons buttons)
2643 (insert "\n")
2644 ;; Insert documentation.
2645 (widget-default-format-handler widget ?h)
2647 ;; The comment field
2648 (unless (eq state 'hidden)
2649 (let* ((comment (get symbol 'variable-comment))
2650 (comment-widget
2651 (widget-create-child-and-convert
2652 widget 'custom-comment
2653 :parent widget
2654 :value (or comment ""))))
2655 (widget-put widget :comment-widget comment-widget)
2656 ;; Don't push it !!! Custom assumes that the first child is the
2657 ;; value one.
2658 (setq children (append children (list comment-widget)))))
2659 ;; Update the rest of the properties properties.
2660 (widget-put widget :custom-form form)
2661 (widget-put widget :children children)
2662 ;; Now update the state.
2663 (if (eq state 'hidden)
2664 (widget-put widget :custom-state state)
2665 (custom-variable-state-set widget))
2666 ;; See also.
2667 (unless (eq state 'hidden)
2668 (when (eq (widget-get widget :custom-level) 1)
2669 (custom-add-parent-links widget))
2670 (custom-add-see-also widget)))))
2672 (defun custom-tag-action (widget &rest args)
2673 "Pass :action to first child of WIDGET's parent."
2674 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2675 :action args))
2677 (defun custom-tag-mouse-down-action (widget &rest args)
2678 "Pass :mouse-down-action to first child of WIDGET's parent."
2679 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2680 :mouse-down-action args))
2682 (defun custom-variable-state-set (widget)
2683 "Set the state of WIDGET."
2684 (let* ((symbol (widget-value widget))
2685 (get (or (get symbol 'custom-get) 'default-value))
2686 (value (if (default-boundp symbol)
2687 (funcall get symbol)
2688 (widget-get widget :value)))
2689 (comment (get symbol 'variable-comment))
2691 temp
2692 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2693 (setq temp
2694 (get symbol 'customized-variable-comment))
2695 (or tmp temp))
2696 (if (condition-case nil
2697 (and (equal value (eval (car tmp)))
2698 (equal comment temp))
2699 (error nil))
2700 'set
2701 'changed))
2702 ((progn (setq tmp (get symbol 'theme-value))
2703 (setq temp (get symbol 'saved-variable-comment))
2704 (or tmp temp))
2705 (if (condition-case nil
2706 (and (equal comment temp)
2707 (equal value
2708 (eval
2709 (car (custom-variable-theme-value
2710 symbol)))))
2711 (error nil))
2712 (cond
2713 ((eq (caar tmp) 'user) 'saved)
2714 ((eq (caar tmp) 'changed)
2715 (if (condition-case nil
2716 (and (null comment)
2717 (equal value
2718 (eval
2719 (car (get symbol 'standard-value)))))
2720 (error nil))
2721 ;; The value was originally set outside
2722 ;; custom, but it was set to the standard
2723 ;; value (probably an autoloaded defcustom).
2724 'standard
2725 'changed))
2726 (t 'themed))
2727 'changed))
2728 ((setq tmp (get symbol 'standard-value))
2729 (if (condition-case nil
2730 (and (equal value (eval (car tmp)))
2731 (equal comment nil))
2732 (error nil))
2733 'standard
2734 'changed))
2735 (t 'rogue))))
2736 (widget-put widget :custom-state state)))
2738 (defun custom-variable-standard-value (widget)
2739 (get (widget-value widget) 'standard-value))
2741 (defvar custom-variable-menu
2742 `(("Set for Current Session" custom-variable-set
2743 (lambda (widget)
2744 (eq (widget-get widget :custom-state) 'modified)))
2745 ,@(when (or custom-file user-init-file)
2746 '(("Save for Future Sessions" custom-variable-save
2747 (lambda (widget)
2748 (memq (widget-get widget :custom-state)
2749 '(modified set changed rogue))))))
2750 ("Undo Edits" custom-redraw
2751 (lambda (widget)
2752 (and (default-boundp (widget-value widget))
2753 (memq (widget-get widget :custom-state) '(modified changed)))))
2754 ("Reset to Saved" custom-variable-reset-saved
2755 (lambda (widget)
2756 (and (or (get (widget-value widget) 'saved-value)
2757 (get (widget-value widget) 'saved-variable-comment))
2758 (memq (widget-get widget :custom-state)
2759 '(modified set changed rogue)))))
2760 ,@(when (or custom-file user-init-file)
2761 '(("Erase Customization" custom-variable-reset-standard
2762 (lambda (widget)
2763 (and (get (widget-value widget) 'standard-value)
2764 (memq (widget-get widget :custom-state)
2765 '(modified set changed saved rogue)))))))
2766 ("Set to Backup Value" custom-variable-reset-backup
2767 (lambda (widget)
2768 (get (widget-value widget) 'backup-value)))
2769 ("---" ignore ignore)
2770 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2771 ("---" ignore ignore)
2772 ("Show Current Value" custom-variable-edit
2773 (lambda (widget)
2774 (eq (widget-get widget :custom-form) 'lisp)))
2775 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2776 (lambda (widget)
2777 (eq (widget-get widget :custom-form) 'edit))))
2778 "Alist of actions for the `custom-variable' widget.
2779 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2780 the menu entry, ACTION is the function to call on the widget when the
2781 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2782 widget as an argument, and returns non-nil if ACTION is valid on that
2783 widget. If FILTER is nil, ACTION is always valid.")
2785 (defun custom-variable-action (widget &optional event)
2786 "Show the menu for `custom-variable' WIDGET.
2787 Optional EVENT is the location for the menu."
2788 (if (eq (widget-get widget :custom-state) 'hidden)
2789 (custom-toggle-hide widget)
2790 (unless (eq (widget-get widget :custom-state) 'modified)
2791 (custom-variable-state-set widget))
2792 (custom-redraw-magic widget)
2793 (let* ((completion-ignore-case t)
2794 (answer (widget-choose (concat "Operation on "
2795 (custom-unlispify-tag-name
2796 (widget-get widget :value)))
2797 (custom-menu-filter custom-variable-menu
2798 widget)
2799 event)))
2800 (if answer
2801 (funcall answer widget)))))
2803 (defun custom-variable-edit (widget)
2804 "Edit value of WIDGET."
2805 (widget-put widget :custom-state 'unknown)
2806 (widget-put widget :custom-form 'edit)
2807 (custom-redraw widget))
2809 (defun custom-variable-edit-lisp (widget)
2810 "Edit the Lisp representation of the value of WIDGET."
2811 (widget-put widget :custom-state 'unknown)
2812 (widget-put widget :custom-form 'lisp)
2813 (custom-redraw widget))
2815 (defun custom-variable-set (widget)
2816 "Set the current value for the variable being edited by WIDGET."
2817 (let* ((form (widget-get widget :custom-form))
2818 (state (widget-get widget :custom-state))
2819 (child (car (widget-get widget :children)))
2820 (symbol (widget-value widget))
2821 (set (or (get symbol 'custom-set) 'set-default))
2822 (comment-widget (widget-get widget :comment-widget))
2823 (comment (widget-value comment-widget))
2824 val)
2825 (cond ((eq state 'hidden)
2826 (error "Cannot set hidden variable"))
2827 ((setq val (widget-apply child :validate))
2828 (goto-char (widget-get val :from))
2829 (error "%s" (widget-get val :error)))
2830 ((memq form '(lisp mismatch))
2831 (when (equal comment "")
2832 (setq comment nil)
2833 ;; Make the comment invisible by hand if it's empty
2834 (custom-comment-hide comment-widget))
2835 (custom-variable-backup-value widget)
2836 (custom-push-theme 'theme-value symbol 'user
2837 'set (custom-quote (widget-value child)))
2838 (funcall set symbol (eval (setq val (widget-value child))))
2839 (put symbol 'customized-value (list val))
2840 (put symbol 'variable-comment comment)
2841 (put symbol 'customized-variable-comment comment))
2843 (when (equal comment "")
2844 (setq comment nil)
2845 ;; Make the comment invisible by hand if it's empty
2846 (custom-comment-hide comment-widget))
2847 (custom-variable-backup-value widget)
2848 (custom-push-theme 'theme-value symbol 'user
2849 'set (custom-quote (widget-value child)))
2850 (funcall set symbol (setq val (widget-value child)))
2851 (put symbol 'customized-value (list (custom-quote val)))
2852 (put symbol 'variable-comment comment)
2853 (put symbol 'customized-variable-comment comment)))
2854 (custom-variable-state-set widget)
2855 (custom-redraw-magic widget)))
2857 (defun custom-variable-save (widget)
2858 "Set and save the value for the variable being edited by WIDGET."
2859 (let* ((form (widget-get widget :custom-form))
2860 (state (widget-get widget :custom-state))
2861 (child (car (widget-get widget :children)))
2862 (symbol (widget-value widget))
2863 (set (or (get symbol 'custom-set) 'set-default))
2864 (comment-widget (widget-get widget :comment-widget))
2865 (comment (widget-value comment-widget))
2866 val)
2867 (cond ((eq state 'hidden)
2868 (error "Cannot set hidden variable"))
2869 ((setq val (widget-apply child :validate))
2870 (goto-char (widget-get val :from))
2871 (error "Saving %s: %s" symbol (widget-get val :error)))
2872 ((memq form '(lisp mismatch))
2873 (when (equal comment "")
2874 (setq comment nil)
2875 ;; Make the comment invisible by hand if it's empty
2876 (custom-comment-hide comment-widget))
2877 (put symbol 'saved-value (list (widget-value child)))
2878 (custom-push-theme 'theme-value symbol 'user
2879 'set (custom-quote (widget-value child)))
2880 (funcall set symbol (eval (widget-value child)))
2881 (put symbol 'variable-comment comment)
2882 (put symbol 'saved-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 (put symbol 'saved-value
2889 (list (custom-quote (widget-value child))))
2890 (custom-push-theme 'theme-value symbol 'user
2891 'set (custom-quote (widget-value child)))
2892 (funcall set symbol (widget-value child))
2893 (put symbol 'variable-comment comment)
2894 (put symbol 'saved-variable-comment comment)))
2895 (put symbol 'customized-value nil)
2896 (put symbol 'customized-variable-comment nil)
2897 (custom-save-all)
2898 (custom-variable-state-set widget)
2899 (custom-redraw-magic widget)))
2901 (defun custom-variable-reset-saved (widget)
2902 "Restore the saved value for the variable being edited by WIDGET.
2903 This also updates the buffer to show that value.
2904 The value that was current before this operation
2905 becomes the backup value, so you can get it again."
2906 (let* ((symbol (widget-value widget))
2907 (set (or (get symbol 'custom-set) 'set-default))
2908 (value (get symbol 'saved-value))
2909 (comment (get symbol 'saved-variable-comment)))
2910 (cond ((or value comment)
2911 (put symbol 'variable-comment comment)
2912 (custom-variable-backup-value widget)
2913 (custom-push-theme 'theme-value symbol 'user 'set (car-safe value))
2914 (condition-case nil
2915 (funcall set symbol (eval (car value)))
2916 (error nil)))
2918 (error "No saved value for %s" symbol)))
2919 (put symbol 'customized-value nil)
2920 (put symbol 'customized-variable-comment nil)
2921 (widget-put widget :custom-state 'unknown)
2922 ;; This call will possibly make the comment invisible
2923 (custom-redraw widget)))
2925 (defun custom-variable-reset-standard (widget)
2926 "Restore the standard setting for the variable being edited by WIDGET.
2927 This operation eliminates any saved setting for the variable,
2928 restoring it to the state of a variable that has never been customized.
2929 The value that was current before this operation
2930 becomes the backup value, so you can get it again."
2931 (let* ((symbol (widget-value widget)))
2932 (if (get symbol 'standard-value)
2933 (custom-variable-backup-value widget)
2934 (error "No standard setting known for %S" symbol))
2935 (put symbol 'variable-comment nil)
2936 (put symbol 'customized-value nil)
2937 (put symbol 'customized-variable-comment nil)
2938 (custom-push-theme 'theme-value symbol 'user 'reset)
2939 (custom-theme-recalc-variable symbol)
2940 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2941 (put symbol 'saved-value nil)
2942 (put symbol 'saved-variable-comment nil)
2943 (custom-save-all))
2944 (widget-put widget :custom-state 'unknown)
2945 ;; This call will possibly make the comment invisible
2946 (custom-redraw widget)))
2948 (defun custom-variable-backup-value (widget)
2949 "Back up the current value for WIDGET's variable.
2950 The backup value is kept in the car of the `backup-value' property."
2951 (let* ((symbol (widget-value widget))
2952 (get (or (get symbol 'custom-get) 'default-value))
2953 (type (custom-variable-type symbol))
2954 (conv (widget-convert type))
2955 (value (if (default-boundp symbol)
2956 (funcall get symbol)
2957 (widget-get conv :value))))
2958 (put symbol 'backup-value (list value))))
2960 (defun custom-variable-reset-backup (widget)
2961 "Restore the backup value for the variable being edited by WIDGET.
2962 The value that was current before this operation
2963 becomes the backup value, so you can use this operation repeatedly
2964 to switch between two values."
2965 (let* ((symbol (widget-value widget))
2966 (set (or (get symbol 'custom-set) 'set-default))
2967 (value (get symbol 'backup-value))
2968 (comment-widget (widget-get widget :comment-widget))
2969 (comment (widget-value comment-widget)))
2970 (if value
2971 (progn
2972 (custom-variable-backup-value widget)
2973 (custom-push-theme 'theme-value symbol 'user 'set value)
2974 (condition-case nil
2975 (funcall set symbol (car value))
2976 (error nil)))
2977 (error "No backup value for %s" symbol))
2978 (put symbol 'customized-value (list (car value)))
2979 (put symbol 'variable-comment comment)
2980 (put symbol 'customized-variable-comment comment)
2981 (custom-variable-state-set widget)
2982 ;; This call will possibly make the comment invisible
2983 (custom-redraw widget)))
2985 ;;; The `custom-face-edit' Widget.
2987 (define-widget 'custom-face-edit 'checklist
2988 "Edit face attributes."
2989 :format "%t: %v"
2990 :tag "Attributes"
2991 :extra-offset 13
2992 :button-args '(:help-echo "Control whether this attribute has any effect.")
2993 :value-to-internal 'custom-face-edit-fix-value
2994 :match (lambda (widget value)
2995 (widget-checklist-match widget
2996 (custom-face-edit-fix-value widget value)))
2997 :convert-widget 'custom-face-edit-convert-widget
2998 :args (mapcar (lambda (att)
2999 (list 'group
3000 :inline t
3001 :sibling-args (widget-get (nth 1 att) :sibling-args)
3002 (list 'const :format "" :value (nth 0 att))
3003 (nth 1 att)))
3004 custom-face-attributes))
3006 (defun custom-face-edit-fix-value (widget value)
3007 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3008 Also change :reverse-video to :inverse-video."
3009 (if (listp value)
3010 (let (result)
3011 (while value
3012 (let ((key (car value))
3013 (val (car (cdr value))))
3014 (cond ((eq key :italic)
3015 (push :slant result)
3016 (push (if val 'italic 'normal) result))
3017 ((eq key :bold)
3018 (push :weight result)
3019 (push (if val 'bold 'normal) result))
3020 ((eq key :reverse-video)
3021 (push :inverse-video result)
3022 (push val result))
3024 (push key result)
3025 (push val result))))
3026 (setq value (cdr (cdr value))))
3027 (setq result (nreverse result))
3028 result)
3029 value))
3031 (defun custom-face-edit-convert-widget (widget)
3032 "Convert :args as widget types in WIDGET."
3033 (widget-put
3034 widget
3035 :args (mapcar (lambda (arg)
3036 (widget-convert arg
3037 :deactivate 'custom-face-edit-deactivate
3038 :activate 'custom-face-edit-activate
3039 :delete 'custom-face-edit-delete))
3040 (widget-get widget :args)))
3041 widget)
3043 (defun custom-face-edit-deactivate (widget)
3044 "Make face widget WIDGET inactive for user modifications."
3045 (unless (widget-get widget :inactive)
3046 (let ((tag (custom-face-edit-attribute-tag widget))
3047 (from (copy-marker (widget-get widget :from)))
3048 (value (widget-value widget))
3049 (inhibit-read-only t)
3050 (inhibit-modification-hooks t))
3051 (save-excursion
3052 (goto-char from)
3053 (widget-default-delete widget)
3054 (insert tag ": *\n")
3055 (widget-put widget :inactive
3056 (cons value (cons from (- (point) from))))))))
3058 (defun custom-face-edit-activate (widget)
3059 "Make face widget WIDGET inactive for user modifications."
3060 (let ((inactive (widget-get widget :inactive))
3061 (inhibit-read-only t)
3062 (inhibit-modification-hooks t))
3063 (when (consp inactive)
3064 (save-excursion
3065 (goto-char (car (cdr inactive)))
3066 (delete-region (point) (+ (point) (cdr (cdr inactive))))
3067 (widget-put widget :inactive nil)
3068 (widget-apply widget :create)
3069 (widget-value-set widget (car inactive))
3070 (widget-setup)))))
3072 (defun custom-face-edit-delete (widget)
3073 "Remove WIDGET from the buffer."
3074 (let ((inactive (widget-get widget :inactive))
3075 (inhibit-read-only t)
3076 (inhibit-modification-hooks t))
3077 (if (not inactive)
3078 ;; Widget is alive, we don't have to do anything special
3079 (widget-default-delete widget)
3080 ;; WIDGET is already deleted because we did so to inactivate it;
3081 ;; now just get rid of the label we put in its place.
3082 (delete-region (car (cdr inactive))
3083 (+ (car (cdr inactive)) (cdr (cdr inactive))))
3084 (widget-put widget :inactive nil))))
3087 (defun custom-face-edit-attribute-tag (widget)
3088 "Returns the first :tag property in WIDGET or one of its children."
3089 (let ((tag (widget-get widget :tag)))
3090 (or (and (not (equal tag "")) tag)
3091 (let ((children (widget-get widget :children)))
3092 (while (and (null tag) children)
3093 (setq tag (custom-face-edit-attribute-tag (pop children))))
3094 tag))))
3096 ;;; The `custom-display' Widget.
3098 (define-widget 'custom-display 'menu-choice
3099 "Select a display type."
3100 :tag "Display"
3101 :value t
3102 :help-echo "Specify frames where the face attributes should be used."
3103 :args '((const :tag "all" t)
3104 (const :tag "defaults" default)
3105 (checklist
3106 :offset 0
3107 :extra-offset 9
3108 :args ((group :sibling-args (:help-echo "\
3109 Only match the specified window systems.")
3110 (const :format "Type: "
3111 type)
3112 (checklist :inline t
3113 :offset 0
3114 (const :format "X "
3115 :sibling-args (:help-echo "\
3116 The X11 Window System.")
3118 (const :format "PM "
3119 :sibling-args (:help-echo "\
3120 OS/2 Presentation Manager.")
3122 (const :format "W32 "
3123 :sibling-args (:help-echo "\
3124 Windows NT/9X.")
3125 w32)
3126 (const :format "MAC "
3127 :sibling-args (:help-echo "\
3128 Macintosh OS.")
3129 mac)
3130 (const :format "DOS "
3131 :sibling-args (:help-echo "\
3132 Plain MS-DOS.")
3134 (const :format "TTY%n"
3135 :sibling-args (:help-echo "\
3136 Plain text terminals.")
3137 tty)))
3138 (group :sibling-args (:help-echo "\
3139 Only match the frames with the specified color support.")
3140 (const :format "Class: "
3141 class)
3142 (checklist :inline t
3143 :offset 0
3144 (const :format "Color "
3145 :sibling-args (:help-echo "\
3146 Match color frames.")
3147 color)
3148 (const :format "Grayscale "
3149 :sibling-args (:help-echo "\
3150 Match grayscale frames.")
3151 grayscale)
3152 (const :format "Monochrome%n"
3153 :sibling-args (:help-echo "\
3154 Match frames with no color support.")
3155 mono)))
3156 (group :sibling-args (:help-echo "\
3157 The minimum number of colors the frame should support.")
3158 (const :format "" min-colors)
3159 (integer :tag "Minimum number of colors" ))
3160 (group :sibling-args (:help-echo "\
3161 Only match frames with the specified intensity.")
3162 (const :format "\
3163 Background brightness: "
3164 background)
3165 (checklist :inline t
3166 :offset 0
3167 (const :format "Light "
3168 :sibling-args (:help-echo "\
3169 Match frames with light backgrounds.")
3170 light)
3171 (const :format "Dark\n"
3172 :sibling-args (:help-echo "\
3173 Match frames with dark backgrounds.")
3174 dark)))
3175 (group :sibling-args (:help-echo "\
3176 Only match frames that support the specified face attributes.")
3177 (const :format "Supports attributes:" supports)
3178 (custom-face-edit :inline t :format "%n%v"))))))
3180 ;;; The `custom-face' Widget.
3182 (defface custom-face-tag
3183 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
3184 "Face used for face tags."
3185 :group 'custom-faces)
3186 ;; backward-compatibility alias
3187 (put 'custom-face-tag-face 'face-alias 'custom-face-tag)
3189 (defcustom custom-face-default-form 'selected
3190 "Default form of displaying face definition."
3191 :type '(choice (const all)
3192 (const selected)
3193 (const lisp))
3194 :group 'custom-buffer
3195 :version "20.3")
3197 (define-widget 'custom-face 'custom
3198 "Customize face."
3199 :sample-face 'custom-face-tag-face
3200 :help-echo "Set or reset this face."
3201 :documentation-property #'face-doc-string
3202 :value-create 'custom-face-value-create
3203 :action 'custom-face-action
3204 :custom-category 'face
3205 :custom-form nil ; defaults to value of `custom-face-default-form'
3206 :custom-set 'custom-face-set
3207 :custom-save 'custom-face-save
3208 :custom-reset-current 'custom-redraw
3209 :custom-reset-saved 'custom-face-reset-saved
3210 :custom-reset-standard 'custom-face-reset-standard
3211 :custom-standard-value 'custom-face-standard-value
3212 :custom-menu 'custom-face-menu-create)
3214 (define-widget 'custom-face-all 'editable-list
3215 "An editable list of display specifications and attributes."
3216 :entry-format "%i %d %v"
3217 :insert-button-args '(:help-echo "Insert new display specification here.")
3218 :append-button-args '(:help-echo "Append new display specification here.")
3219 :delete-button-args '(:help-echo "Delete this display specification.")
3220 :args '((group :format "%v" custom-display custom-face-edit)))
3222 (defconst custom-face-all (widget-convert 'custom-face-all)
3223 "Converted version of the `custom-face-all' widget.")
3225 (define-widget 'custom-display-unselected 'item
3226 "A display specification that doesn't match the selected display."
3227 :match 'custom-display-unselected-match)
3229 (defun custom-display-unselected-match (widget value)
3230 "Non-nil if VALUE is an unselected display specification."
3231 (not (face-spec-set-match-display value (selected-frame))))
3233 (define-widget 'custom-face-selected 'group
3234 "Edit the attributes of the selected display in a face specification."
3235 :args '((choice :inline t
3236 (group :tag "With Defaults" :inline t
3237 (group (const :tag "" default)
3238 (custom-face-edit :tag " Default\n Attributes"))
3239 (repeat :format ""
3240 :inline t
3241 (group custom-display-unselected sexp))
3242 (group (sexp :format "")
3243 (custom-face-edit :tag " Overriding\n Attributes"))
3244 (repeat :format ""
3245 :inline t
3246 sexp))
3247 (group :tag "No Defaults" :inline t
3248 (repeat :format ""
3249 :inline t
3250 (group custom-display-unselected sexp))
3251 (group (sexp :format "")
3252 (custom-face-edit :tag "\n Attributes"))
3253 (repeat :format ""
3254 :inline t
3255 sexp)))))
3259 (defconst custom-face-selected (widget-convert 'custom-face-selected)
3260 "Converted version of the `custom-face-selected' widget.")
3262 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
3263 "Return a canonicalized version of SPEC using.
3264 FILTER-INDEX is the index in the entry for each attribute in
3265 `custom-face-attributes' at which the appropriate filter function can be
3266 found, and DEFAULT-FILTER is the filter to apply for attributes that
3267 don't specify one."
3268 (mapcar (lambda (entry)
3269 ;; Filter a single face-spec entry
3270 (let ((tests (car entry))
3271 (unfiltered-attrs
3272 ;; Handle both old- and new-style attribute syntax
3273 (if (listp (car (cdr entry)))
3274 (car (cdr entry))
3275 (cdr entry)))
3276 (filtered-attrs nil))
3277 ;; Filter each face attribute
3278 (while unfiltered-attrs
3279 (let* ((attr (pop unfiltered-attrs))
3280 (pre-filtered-value (pop unfiltered-attrs))
3281 (filter
3282 (or (nth filter-index (assq attr custom-face-attributes))
3283 default-filter))
3284 (filtered-value
3285 (if filter
3286 (funcall filter pre-filtered-value)
3287 pre-filtered-value)))
3288 (push filtered-value filtered-attrs)
3289 (push attr filtered-attrs)))
3291 (list tests filtered-attrs)))
3292 spec))
3294 (defun custom-pre-filter-face-spec (spec)
3295 "Return SPEC changed as necessary for editing by the face customization widget.
3296 SPEC must be a full face spec."
3297 (custom-filter-face-spec spec 2))
3299 (defun custom-post-filter-face-spec (spec)
3300 "Return the customized SPEC in a form suitable for setting the face."
3301 (custom-filter-face-spec spec 3))
3303 (defun custom-face-value-create (widget)
3304 "Create a list of the display specifications for WIDGET."
3305 (let ((buttons (widget-get widget :buttons))
3306 children
3307 (symbol (widget-get widget :value))
3308 (tag (widget-get widget :tag))
3309 (state (widget-get widget :custom-state))
3310 (begin (point))
3311 (is-last (widget-get widget :custom-last))
3312 (prefix (widget-get widget :custom-prefix)))
3313 (unless tag
3314 (setq tag (prin1-to-string symbol)))
3315 (cond ((eq custom-buffer-style 'tree)
3316 (insert prefix (if is-last " `--- " " |--- "))
3317 (push (widget-create-child-and-convert
3318 widget 'custom-browse-face-tag)
3319 buttons)
3320 (insert " " tag "\n")
3321 (widget-put widget :buttons buttons))
3323 ;; Create tag.
3324 (insert tag)
3325 (widget-specify-sample widget begin (point))
3326 (if (eq custom-buffer-style 'face)
3327 (insert " ")
3328 (if (string-match "face\\'" tag)
3329 (insert ":")
3330 (insert " face: ")))
3331 ;; Sample.
3332 (push (widget-create-child-and-convert widget 'item
3333 :format "(%{%t%})"
3334 :sample-face symbol
3335 :tag "sample")
3336 buttons)
3337 ;; Visibility.
3338 (insert " ")
3339 (push (widget-create-child-and-convert
3340 widget 'visibility
3341 :help-echo "Hide or show this face."
3342 :on "Hide Face"
3343 :off "Show Face"
3344 :action 'custom-toggle-parent
3345 (not (eq state 'hidden)))
3346 buttons)
3347 ;; Magic.
3348 (insert "\n")
3349 (let ((magic (widget-create-child-and-convert
3350 widget 'custom-magic nil)))
3351 (widget-put widget :custom-magic magic)
3352 (push magic buttons))
3353 ;; Update buttons.
3354 (widget-put widget :buttons buttons)
3355 ;; Insert documentation.
3356 (widget-default-format-handler widget ?h)
3357 ;; The comment field
3358 (unless (eq state 'hidden)
3359 (let* ((comment (get symbol 'face-comment))
3360 (comment-widget
3361 (widget-create-child-and-convert
3362 widget 'custom-comment
3363 :parent widget
3364 :value (or comment ""))))
3365 (widget-put widget :comment-widget comment-widget)
3366 (push comment-widget children)))
3367 ;; See also.
3368 (unless (eq state 'hidden)
3369 (when (eq (widget-get widget :custom-level) 1)
3370 (custom-add-parent-links widget))
3371 (custom-add-see-also widget))
3372 ;; Editor.
3373 (unless (eq (preceding-char) ?\n)
3374 (insert "\n"))
3375 (unless (eq state 'hidden)
3376 (message "Creating face editor...")
3377 (custom-load-widget widget)
3378 (unless (widget-get widget :custom-form)
3379 (widget-put widget :custom-form custom-face-default-form))
3380 (let* ((symbol (widget-value widget))
3381 (spec (or (get symbol 'customized-face)
3382 (get symbol 'saved-face)
3383 (get symbol 'face-defface-spec)
3384 ;; Attempt to construct it.
3385 (list (list t (custom-face-attributes-get
3386 symbol (selected-frame))))))
3387 (form (widget-get widget :custom-form))
3388 (indent (widget-get widget :indent))
3389 edit)
3390 ;; If the user has changed this face in some other way,
3391 ;; edit it as the user has specified it.
3392 (if (not (face-spec-match-p symbol spec (selected-frame)))
3393 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
3394 (setq spec (custom-pre-filter-face-spec spec))
3395 (setq edit (widget-create-child-and-convert
3396 widget
3397 (cond ((and (eq form 'selected)
3398 (widget-apply custom-face-selected
3399 :match spec))
3400 (when indent (insert-char ?\ indent))
3401 'custom-face-selected)
3402 ((and (not (eq form 'lisp))
3403 (widget-apply custom-face-all
3404 :match spec))
3405 'custom-face-all)
3407 (when indent (insert-char ?\ indent))
3408 'sexp))
3409 :value spec))
3410 (custom-face-state-set widget)
3411 (push edit children)
3412 (widget-put widget :children children))
3413 (message "Creating face editor...done"))))))
3415 (defvar custom-face-menu
3416 `(("Set for Current Session" custom-face-set)
3417 ,@(when (or custom-file user-init-file)
3418 '(("Save for Future Sessions" custom-face-save)))
3419 ("Undo Edits" custom-redraw
3420 (lambda (widget)
3421 (memq (widget-get widget :custom-state) '(modified changed))))
3422 ("Reset to Saved" custom-face-reset-saved
3423 (lambda (widget)
3424 (or (get (widget-value widget) 'saved-face)
3425 (get (widget-value widget) 'saved-face-comment))))
3426 ,@(when (or custom-file user-init-file)
3427 '(("Erase Customization" custom-face-reset-standard
3428 (lambda (widget)
3429 (get (widget-value widget) 'face-defface-spec)))))
3430 ("---" ignore ignore)
3431 ("Add Comment" custom-comment-show custom-comment-invisible-p)
3432 ("---" ignore ignore)
3433 ("For Current Display" custom-face-edit-selected
3434 (lambda (widget)
3435 (not (eq (widget-get widget :custom-form) 'selected))))
3436 ("For All Kinds of Displays" custom-face-edit-all
3437 (lambda (widget)
3438 (not (eq (widget-get widget :custom-form) 'all))))
3439 ("Show Lisp Expression" custom-face-edit-lisp
3440 (lambda (widget)
3441 (not (eq (widget-get widget :custom-form) 'lisp)))))
3442 "Alist of actions for the `custom-face' widget.
3443 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3444 the menu entry, ACTION is the function to call on the widget when the
3445 menu is selected, and FILTER is a predicate which takes a `custom-face'
3446 widget as an argument, and returns non-nil if ACTION is valid on that
3447 widget. If FILTER is nil, ACTION is always valid.")
3449 (defun custom-face-edit-selected (widget)
3450 "Edit selected attributes of the value of WIDGET."
3451 (widget-put widget :custom-state 'unknown)
3452 (widget-put widget :custom-form 'selected)
3453 (custom-redraw widget))
3455 (defun custom-face-edit-all (widget)
3456 "Edit all attributes of the value of WIDGET."
3457 (widget-put widget :custom-state 'unknown)
3458 (widget-put widget :custom-form 'all)
3459 (custom-redraw widget))
3461 (defun custom-face-edit-lisp (widget)
3462 "Edit the Lisp representation of the value of WIDGET."
3463 (widget-put widget :custom-state 'unknown)
3464 (widget-put widget :custom-form 'lisp)
3465 (custom-redraw widget))
3467 (defun custom-face-state-set (widget)
3468 "Set the state of WIDGET."
3469 (let* ((symbol (widget-value widget))
3470 (comment (get symbol 'face-comment))
3471 tmp temp
3472 (state
3473 (cond ((progn
3474 (setq tmp (get symbol 'customized-face))
3475 (setq temp (get symbol 'customized-face-comment))
3476 (or tmp temp))
3477 (if (equal temp comment)
3478 'set
3479 'changed))
3480 ((progn
3481 (setq tmp (get symbol 'saved-face))
3482 (setq temp (get symbol 'saved-face-comment))
3483 (or tmp temp))
3484 (if (equal temp comment)
3485 (cond
3486 ((eq 'user (caar (get symbol 'theme-face)))
3487 'saved)
3488 ((eq 'changed (caar (get symbol 'theme-face)))
3489 'changed)
3490 (t 'themed))
3491 'changed))
3492 ((get symbol 'face-defface-spec)
3493 (if (equal comment nil)
3494 'standard
3495 'changed))
3497 'rogue))))
3498 ;; If the user called set-face-attribute to change the default
3499 ;; for new frames, this face is "set outside of Customize".
3500 (if (and (not (eq state 'rogue))
3501 (get symbol 'face-modified))
3502 (setq state 'changed))
3503 (widget-put widget :custom-state state)))
3505 (defun custom-face-action (widget &optional event)
3506 "Show the menu for `custom-face' WIDGET.
3507 Optional EVENT is the location for the menu."
3508 (if (eq (widget-get widget :custom-state) 'hidden)
3509 (custom-toggle-hide widget)
3510 (let* ((completion-ignore-case t)
3511 (symbol (widget-get widget :value))
3512 (answer (widget-choose (concat "Operation on "
3513 (custom-unlispify-tag-name symbol))
3514 (custom-menu-filter custom-face-menu
3515 widget)
3516 event)))
3517 (if answer
3518 (funcall answer widget)))))
3520 (defun custom-face-set (widget)
3521 "Make the face attributes in WIDGET take effect."
3522 (let* ((symbol (widget-value widget))
3523 (child (car (widget-get widget :children)))
3524 (value (custom-post-filter-face-spec (widget-value child)))
3525 (comment-widget (widget-get widget :comment-widget))
3526 (comment (widget-value comment-widget)))
3527 (when (equal comment "")
3528 (setq comment nil)
3529 ;; Make the comment invisible by hand if it's empty
3530 (custom-comment-hide comment-widget))
3531 (put symbol 'customized-face value)
3532 (custom-push-theme 'theme-face symbol 'user 'set value)
3533 (if (face-spec-choose value)
3534 (face-spec-set symbol value)
3535 ;; face-set-spec ignores empty attribute lists, so just give it
3536 ;; something harmless instead.
3537 (face-spec-set symbol '((t :foreground unspecified))))
3538 (put symbol 'customized-face-comment comment)
3539 (put symbol 'face-comment comment)
3540 (custom-face-state-set widget)
3541 (custom-redraw-magic widget)))
3543 (defun custom-face-save (widget)
3544 "Save in `.emacs' the face attributes in WIDGET."
3545 (let* ((symbol (widget-value widget))
3546 (child (car (widget-get widget :children)))
3547 (value (custom-post-filter-face-spec (widget-value child)))
3548 (comment-widget (widget-get widget :comment-widget))
3549 (comment (widget-value comment-widget)))
3550 (when (equal comment "")
3551 (setq comment nil)
3552 ;; Make the comment invisible by hand if it's empty
3553 (custom-comment-hide comment-widget))
3554 (custom-push-theme 'theme-face symbol 'user 'set value)
3555 (if (face-spec-choose value)
3556 (face-spec-set symbol value)
3557 ;; face-set-spec ignores empty attribute lists, so just give it
3558 ;; something harmless instead.
3559 (face-spec-set symbol '((t :foreground unspecified))))
3560 (unless (eq (widget-get widget :custom-state) 'standard)
3561 (put symbol 'saved-face value))
3562 (put symbol 'customized-face nil)
3563 (put symbol 'face-comment comment)
3564 (put symbol 'customized-face-comment nil)
3565 (put symbol 'saved-face-comment comment)
3566 (custom-save-all)
3567 (custom-face-state-set widget)
3568 (custom-redraw-magic widget)))
3570 ;; For backward compatibility.
3571 (define-obsolete-function-alias 'custom-face-save-command 'custom-face-save
3572 "22.1")
3574 (defun custom-face-reset-saved (widget)
3575 "Restore WIDGET to the face's default attributes."
3576 (let* ((symbol (widget-value widget))
3577 (child (car (widget-get widget :children)))
3578 (value (get symbol 'saved-face))
3579 (comment (get symbol 'saved-face-comment))
3580 (comment-widget (widget-get widget :comment-widget)))
3581 (unless (or value comment)
3582 (error "No saved value for this face"))
3583 (put symbol 'customized-face nil)
3584 (put symbol 'customized-face-comment nil)
3585 (custom-push-theme 'theme-face symbol 'user 'set value)
3586 (face-spec-set symbol value)
3587 (put symbol 'face-comment comment)
3588 (widget-value-set child value)
3589 ;; This call manages the comment visibility
3590 (widget-value-set comment-widget (or comment ""))
3591 (custom-face-state-set widget)
3592 (custom-redraw-magic widget)))
3594 (defun custom-face-standard-value (widget)
3595 (get (widget-value widget) 'face-defface-spec))
3597 (defun custom-face-reset-standard (widget)
3598 "Restore WIDGET to the face's standard attribute values.
3599 This operation eliminates any saved attributes for the face,
3600 restoring it to the state of a face that has never been customized."
3601 (let* ((symbol (widget-value widget))
3602 (child (car (widget-get widget :children)))
3603 (value (get symbol 'face-defface-spec))
3604 (comment-widget (widget-get widget :comment-widget)))
3605 (unless value
3606 (error "No standard setting for this face"))
3607 (put symbol 'customized-face nil)
3608 (put symbol 'customized-face-comment nil)
3609 (custom-push-theme 'theme-face symbol 'user 'reset)
3610 (face-spec-set symbol value)
3611 (custom-theme-recalc-face symbol)
3612 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3613 (put symbol 'saved-face nil)
3614 (put symbol 'saved-face-comment nil)
3615 (custom-save-all))
3616 (put symbol 'face-comment nil)
3617 (widget-value-set child
3618 (custom-pre-filter-face-spec
3619 (list (list t (custom-face-attributes-get
3620 symbol nil)))))
3621 ;; This call manages the comment visibility
3622 (widget-value-set comment-widget "")
3623 (custom-face-state-set widget)
3624 (custom-redraw-magic widget)))
3626 ;;; The `face' Widget.
3628 (defvar widget-face-prompt-value-history nil
3629 "History of input to `widget-face-prompt-value'.")
3631 (define-widget 'face 'symbol
3632 "A Lisp face name (with sample)."
3633 :format "%{%t%}: (%{sample%}) %v"
3634 :tag "Face"
3635 :value 'default
3636 :sample-face-get 'widget-face-sample-face-get
3637 :notify 'widget-face-notify
3638 :match (lambda (widget value) (facep value))
3639 :complete-function (lambda ()
3640 (interactive)
3641 (lisp-complete-symbol 'facep))
3642 :prompt-match 'facep
3643 :prompt-history 'widget-face-prompt-value-history
3644 :validate (lambda (widget)
3645 (unless (facep (widget-value widget))
3646 (widget-put widget
3647 :error (format "Invalid face: %S"
3648 (widget-value widget)))
3649 widget)))
3651 (defun widget-face-sample-face-get (widget)
3652 (let ((value (widget-value widget)))
3653 (if (facep value)
3654 value
3655 'default)))
3657 (defun widget-face-notify (widget child &optional event)
3658 "Update the sample, and notify the parent."
3659 (overlay-put (widget-get widget :sample-overlay)
3660 'face (widget-apply widget :sample-face-get))
3661 (widget-default-notify widget child event))
3664 ;;; The `hook' Widget.
3666 (define-widget 'hook 'list
3667 "An Emacs Lisp hook."
3668 :value-to-internal (lambda (widget value)
3669 (if (and value (symbolp value))
3670 (list value)
3671 value))
3672 :match (lambda (widget value)
3673 (or (symbolp value)
3674 (widget-group-match widget value)))
3675 ;; Avoid adding undefined functions to the hook, especially for
3676 ;; things like `find-file-hook' or even more basic ones, to avoid
3677 ;; chaos.
3678 :set (lambda (symbol value)
3679 (dolist (elt value)
3680 (if (fboundp elt)
3681 (add-hook symbol elt))))
3682 :convert-widget 'custom-hook-convert-widget
3683 :tag "Hook")
3685 (defun custom-hook-convert-widget (widget)
3686 ;; Handle `:options'.
3687 (let* ((options (widget-get widget :options))
3688 (other `(editable-list :inline t
3689 :entry-format "%i %d%v"
3690 (function :format " %v")))
3691 (args (if options
3692 (list `(checklist :inline t
3693 ,@(mapcar (lambda (entry)
3694 `(function-item ,entry))
3695 options))
3696 other)
3697 (list other))))
3698 (widget-put widget :args args)
3699 widget))
3701 ;;; The `custom-group-link' Widget.
3703 (define-widget 'custom-group-link 'link
3704 "Show parent in other window when activated."
3705 :button-face 'custom-link
3706 :mouse-face 'highlight
3707 :pressed-face 'highlight
3708 :help-echo "Create customization buffer for this group."
3709 :keymap custom-mode-link-map
3710 :follow-link 'mouse-face
3711 :action 'custom-group-link-action)
3713 (defun custom-group-link-action (widget &rest ignore)
3714 (customize-group (widget-value widget)))
3716 ;;; The `custom-group' Widget.
3718 (defcustom custom-group-tag-faces nil
3719 ;; In XEmacs, this ought to play games with font size.
3720 ;; Fixme: make it do so in Emacs.
3721 "Face used for group tags.
3722 The first member is used for level 1 groups, the second for level 2,
3723 and so forth. The remaining group tags are shown with `custom-group-tag'."
3724 :type '(repeat face)
3725 :group 'custom-faces)
3727 (defface custom-group-tag-1
3728 `((((class color)
3729 (background dark))
3730 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3731 (((min-colors 88) (class color)
3732 (background light))
3733 (:foreground "red1" :weight bold :height 1.2 :inherit variable-pitch))
3734 (((class color)
3735 (background light))
3736 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3737 (t (:weight bold)))
3738 "Face used for group tags."
3739 :group 'custom-faces)
3740 ;; backward-compatibility alias
3741 (put 'custom-group-tag-face-1 'face-alias 'custom-group-tag-1)
3743 (defface custom-group-tag
3744 `((((class color)
3745 (background dark))
3746 (:foreground "light blue" :weight bold :height 1.2))
3747 (((min-colors 88) (class color)
3748 (background light))
3749 (:foreground "blue1" :weight bold :height 1.2))
3750 (((class color)
3751 (background light))
3752 (:foreground "blue" :weight bold :height 1.2))
3753 (t (:weight bold)))
3754 "Face used for low level group tags."
3755 :group 'custom-faces)
3756 ;; backward-compatibility alias
3757 (put 'custom-group-tag-face 'face-alias 'custom-group-tag)
3759 (define-widget 'custom-group 'custom
3760 "Customize group."
3761 :format "%v"
3762 :sample-face-get 'custom-group-sample-face-get
3763 :documentation-property 'group-documentation
3764 :help-echo "Set or reset all members of this group."
3765 :value-create 'custom-group-value-create
3766 :action 'custom-group-action
3767 :custom-category 'group
3768 :custom-set 'custom-group-set
3769 :custom-save 'custom-group-save
3770 :custom-reset-current 'custom-group-reset-current
3771 :custom-reset-saved 'custom-group-reset-saved
3772 :custom-reset-standard 'custom-group-reset-standard
3773 :custom-menu 'custom-group-menu-create)
3775 (defun custom-group-sample-face-get (widget)
3776 ;; Use :sample-face.
3777 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3778 'custom-group-tag))
3780 (define-widget 'custom-group-visibility 'visibility
3781 "An indicator and manipulator for hidden group contents."
3782 :create 'custom-group-visibility-create)
3784 (defun custom-group-visibility-create (widget)
3785 (let ((visible (widget-value widget)))
3786 (if visible
3787 (insert "--------")))
3788 (widget-default-create widget))
3790 (defun custom-group-members (symbol groups-only)
3791 "Return SYMBOL's custom group members.
3792 If GROUPS-ONLY non-nil, return only those members that are groups."
3793 (if (not groups-only)
3794 (get symbol 'custom-group)
3795 (let (members)
3796 (dolist (entry (get symbol 'custom-group))
3797 (when (eq (nth 1 entry) 'custom-group)
3798 (push entry members)))
3799 (nreverse members))))
3801 (defun custom-group-value-create (widget)
3802 "Insert a customize group for WIDGET in the current buffer."
3803 (unless (eq (widget-get widget :custom-state) 'hidden)
3804 (custom-load-widget widget))
3805 (let* ((state (widget-get widget :custom-state))
3806 (level (widget-get widget :custom-level))
3807 ;; (indent (widget-get widget :indent))
3808 (prefix (widget-get widget :custom-prefix))
3809 (buttons (widget-get widget :buttons))
3810 (tag (widget-get widget :tag))
3811 (symbol (widget-value widget))
3812 (members (custom-group-members symbol
3813 (and (eq custom-buffer-style 'tree)
3814 custom-browse-only-groups))))
3815 (cond ((and (eq custom-buffer-style 'tree)
3816 (eq state 'hidden)
3817 (or members (custom-unloaded-widget-p widget)))
3818 (custom-browse-insert-prefix prefix)
3819 (push (widget-create-child-and-convert
3820 widget 'custom-browse-visibility
3821 ;; :tag-glyph "plus"
3822 :tag "+")
3823 buttons)
3824 (insert "-- ")
3825 ;; (widget-glyph-insert nil "-- " "horizontal")
3826 (push (widget-create-child-and-convert
3827 widget 'custom-browse-group-tag)
3828 buttons)
3829 (insert " " tag "\n")
3830 (widget-put widget :buttons buttons))
3831 ((and (eq custom-buffer-style 'tree)
3832 (zerop (length members)))
3833 (custom-browse-insert-prefix prefix)
3834 (insert "[ ]-- ")
3835 ;; (widget-glyph-insert nil "[ ]" "empty")
3836 ;; (widget-glyph-insert nil "-- " "horizontal")
3837 (push (widget-create-child-and-convert
3838 widget 'custom-browse-group-tag)
3839 buttons)
3840 (insert " " tag "\n")
3841 (widget-put widget :buttons buttons))
3842 ((eq custom-buffer-style 'tree)
3843 (custom-browse-insert-prefix prefix)
3844 (if (zerop (length members))
3845 (progn
3846 (custom-browse-insert-prefix prefix)
3847 (insert "[ ]-- ")
3848 ;; (widget-glyph-insert nil "[ ]" "empty")
3849 ;; (widget-glyph-insert nil "-- " "horizontal")
3850 (push (widget-create-child-and-convert
3851 widget 'custom-browse-group-tag)
3852 buttons)
3853 (insert " " tag "\n")
3854 (widget-put widget :buttons buttons))
3855 (push (widget-create-child-and-convert
3856 widget 'custom-browse-visibility
3857 ;; :tag-glyph "minus"
3858 :tag "-")
3859 buttons)
3860 (insert "-\\ ")
3861 ;; (widget-glyph-insert nil "-\\ " "top")
3862 (push (widget-create-child-and-convert
3863 widget 'custom-browse-group-tag)
3864 buttons)
3865 (insert " " tag "\n")
3866 (widget-put widget :buttons buttons)
3867 (message "Creating group...")
3868 (let* ((members (custom-sort-items members
3869 custom-browse-sort-alphabetically
3870 custom-browse-order-groups))
3871 (prefixes (widget-get widget :custom-prefixes))
3872 (custom-prefix-list (custom-prefix-add symbol prefixes))
3873 (extra-prefix (if (widget-get widget :custom-last)
3875 " | "))
3876 (prefix (concat prefix extra-prefix))
3877 children entry)
3878 (while members
3879 (setq entry (car members)
3880 members (cdr members))
3881 (push (widget-create-child-and-convert
3882 widget (nth 1 entry)
3883 :group widget
3884 :tag (custom-unlispify-tag-name (nth 0 entry))
3885 :custom-prefixes custom-prefix-list
3886 :custom-level (1+ level)
3887 :custom-last (null members)
3888 :value (nth 0 entry)
3889 :custom-prefix prefix)
3890 children))
3891 (widget-put widget :children (reverse children)))
3892 (message "Creating group...done")))
3893 ;; Nested style.
3894 ((eq state 'hidden)
3895 ;; Create level indicator.
3896 (unless (eq custom-buffer-style 'links)
3897 (insert-char ?\ (* custom-buffer-indent (1- level)))
3898 (insert "-- "))
3899 ;; Create tag.
3900 (let ((begin (point)))
3901 (insert tag)
3902 (widget-specify-sample widget begin (point)))
3903 (insert " group: ")
3904 ;; Create link/visibility indicator.
3905 (if (eq custom-buffer-style 'links)
3906 (push (widget-create-child-and-convert
3907 widget 'custom-group-link
3908 :tag "Go to Group"
3909 symbol)
3910 buttons)
3911 (push (widget-create-child-and-convert
3912 widget 'custom-group-visibility
3913 :help-echo "Show members of this group."
3914 :action 'custom-toggle-parent
3915 (not (eq state 'hidden)))
3916 buttons))
3917 (insert " \n")
3918 ;; Create magic button.
3919 (let ((magic (widget-create-child-and-convert
3920 widget 'custom-magic nil)))
3921 (widget-put widget :custom-magic magic)
3922 (push magic buttons))
3923 ;; Update buttons.
3924 (widget-put widget :buttons buttons)
3925 ;; Insert documentation.
3926 (if (and (eq custom-buffer-style 'links) (> level 1))
3927 (widget-put widget :documentation-indent 0))
3928 (widget-default-format-handler widget ?h))
3929 ;; Nested style.
3930 (t ;Visible.
3931 ;; Add parent groups references above the group.
3932 (if t ;;; This should test that the buffer
3933 ;;; was made to display a group.
3934 (when (eq level 1)
3935 (if (custom-add-parent-links widget
3936 "Go to parent group:")
3937 (insert "\n"))))
3938 ;; Create level indicator.
3939 (insert-char ?\ (* custom-buffer-indent (1- level)))
3940 (insert "/- ")
3941 ;; Create tag.
3942 (let ((start (point)))
3943 (insert tag)
3944 (widget-specify-sample widget start (point)))
3945 (insert " group: ")
3946 ;; Create visibility indicator.
3947 (unless (eq custom-buffer-style 'links)
3948 (insert "--------")
3949 (push (widget-create-child-and-convert
3950 widget 'visibility
3951 :help-echo "Hide members of this group."
3952 :action 'custom-toggle-parent
3953 (not (eq state 'hidden)))
3954 buttons)
3955 (insert " "))
3956 ;; Create more dashes.
3957 ;; Use 76 instead of 75 to compensate for the temporary "<"
3958 ;; added by `widget-insert'.
3959 (insert-char ?- (- 76 (current-column)
3960 (* custom-buffer-indent level)))
3961 (insert "\\\n")
3962 ;; Create magic button.
3963 (let ((magic (widget-create-child-and-convert
3964 widget 'custom-magic
3965 :indent 0
3966 nil)))
3967 (widget-put widget :custom-magic magic)
3968 (push magic buttons))
3969 ;; Update buttons.
3970 (widget-put widget :buttons buttons)
3971 ;; Insert documentation.
3972 (widget-default-format-handler widget ?h)
3973 ;; Parent groups.
3974 (if nil ;;; This should test that the buffer
3975 ;;; was not made to display a group.
3976 (when (eq level 1)
3977 (insert-char ?\ custom-buffer-indent)
3978 (custom-add-parent-links widget)))
3979 (custom-add-see-also widget
3980 (make-string (* custom-buffer-indent level)
3981 ?\ ))
3982 ;; Members.
3983 (message "Creating group...")
3984 (let* ((members (custom-sort-items members
3985 custom-buffer-sort-alphabetically
3986 custom-buffer-order-groups))
3987 (prefixes (widget-get widget :custom-prefixes))
3988 (custom-prefix-list (custom-prefix-add symbol prefixes))
3989 (length (length members))
3990 (count 0)
3991 (children (mapcar (lambda (entry)
3992 (widget-insert "\n")
3993 (message "\
3994 Creating group members... %2d%%"
3995 (/ (* 100.0 count) length))
3996 (setq count (1+ count))
3997 (prog1
3998 (widget-create-child-and-convert
3999 widget (nth 1 entry)
4000 :group widget
4001 :tag (custom-unlispify-tag-name
4002 (nth 0 entry))
4003 :custom-prefixes custom-prefix-list
4004 :custom-level (1+ level)
4005 :value (nth 0 entry))
4006 (unless (eq (preceding-char) ?\n)
4007 (widget-insert "\n"))))
4008 members)))
4009 (message "Creating group magic...")
4010 (mapc 'custom-magic-reset children)
4011 (message "Creating group state...")
4012 (widget-put widget :children children)
4013 (custom-group-state-update widget)
4014 (message "Creating group... done"))
4015 ;; End line
4016 (insert "\n")
4017 (insert-char ?\ (* custom-buffer-indent (1- level)))
4018 (insert "\\- " (widget-get widget :tag) " group end ")
4019 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
4020 (insert "/\n")))))
4022 (defvar custom-group-menu
4023 `(("Set for Current Session" custom-group-set
4024 (lambda (widget)
4025 (eq (widget-get widget :custom-state) 'modified)))
4026 ,@(when (or custom-file user-init-file)
4027 '(("Save for Future Sessions" custom-group-save
4028 (lambda (widget)
4029 (memq (widget-get widget :custom-state) '(modified set))))))
4030 ("Undo Edits" custom-group-reset-current
4031 (lambda (widget)
4032 (memq (widget-get widget :custom-state) '(modified))))
4033 ("Reset to Saved" custom-group-reset-saved
4034 (lambda (widget)
4035 (memq (widget-get widget :custom-state) '(modified set))))
4036 ,@(when (or custom-file user-init-file)
4037 '(("Erase Customization" custom-group-reset-standard
4038 (lambda (widget)
4039 (memq (widget-get widget :custom-state) '(modified set saved)))))))
4040 "Alist of actions for the `custom-group' widget.
4041 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4042 the menu entry, ACTION is the function to call on the widget when the
4043 menu is selected, and FILTER is a predicate which takes a `custom-group'
4044 widget as an argument, and returns non-nil if ACTION is valid on that
4045 widget. If FILTER is nil, ACTION is always valid.")
4047 (defun custom-group-action (widget &optional event)
4048 "Show the menu for `custom-group' WIDGET.
4049 Optional EVENT is the location for the menu."
4050 (if (eq (widget-get widget :custom-state) 'hidden)
4051 (custom-toggle-hide widget)
4052 (let* ((completion-ignore-case t)
4053 (answer (widget-choose (concat "Operation on "
4054 (custom-unlispify-tag-name
4055 (widget-get widget :value)))
4056 (custom-menu-filter custom-group-menu
4057 widget)
4058 event)))
4059 (if answer
4060 (funcall answer widget)))))
4062 (defun custom-group-set (widget)
4063 "Set changes in all modified group members."
4064 (let ((children (widget-get widget :children)))
4065 (mapc (lambda (child)
4066 (when (eq (widget-get child :custom-state) 'modified)
4067 (widget-apply child :custom-set)))
4068 children )))
4070 (defun custom-group-save (widget)
4071 "Save all modified group members."
4072 (let ((children (widget-get widget :children)))
4073 (mapc (lambda (child)
4074 (when (memq (widget-get child :custom-state) '(modified set))
4075 (widget-apply child :custom-save)))
4076 children )))
4078 (defun custom-group-reset-current (widget)
4079 "Reset all modified group members."
4080 (let ((children (widget-get widget :children)))
4081 (mapc (lambda (child)
4082 (when (eq (widget-get child :custom-state) 'modified)
4083 (widget-apply child :custom-reset-current)))
4084 children )))
4086 (defun custom-group-reset-saved (widget)
4087 "Reset all modified or set group members."
4088 (let ((children (widget-get widget :children)))
4089 (mapc (lambda (child)
4090 (when (memq (widget-get child :custom-state) '(modified set))
4091 (widget-apply child :custom-reset-saved)))
4092 children )))
4094 (defun custom-group-reset-standard (widget)
4095 "Reset all modified, set, or saved group members."
4096 (let ((children (widget-get widget :children)))
4097 (mapc (lambda (child)
4098 (when (memq (widget-get child :custom-state)
4099 '(modified set saved))
4100 (widget-apply child :custom-reset-standard)))
4101 children )))
4103 (defun custom-group-state-update (widget)
4104 "Update magic."
4105 (unless (eq (widget-get widget :custom-state) 'hidden)
4106 (let* ((children (widget-get widget :children))
4107 (states (mapcar (lambda (child)
4108 (widget-get child :custom-state))
4109 children))
4110 (magics custom-magic-alist)
4111 (found 'standard))
4112 (while magics
4113 (let ((magic (car (car magics))))
4114 (if (and (not (eq magic 'hidden))
4115 (memq magic states))
4116 (setq found magic
4117 magics nil)
4118 (setq magics (cdr magics)))))
4119 (widget-put widget :custom-state found)))
4120 (custom-magic-reset widget))
4122 ;;; Reading and writing the custom file.
4124 ;;;###autoload
4125 (defcustom custom-file nil
4126 "File used for storing customization information.
4127 The default is nil, which means to use your init file
4128 as specified by `user-init-file'. If the value is not nil,
4129 it should be an absolute file name.
4131 You can set this option through Custom, if you carefully read the
4132 last paragraph below. However, usually it is simpler to write
4133 something like the following in your init file:
4135 \(setq custom-file \"~/.emacs-custom.el\")
4136 \(load custom-file)
4138 Note that both lines are necessary: the first line tells Custom to
4139 save all customizations in this file, but does not load it.
4141 When you change this variable outside Custom, look in the
4142 previous custom file \(usually your init file) for the
4143 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4144 and copy them (whichever ones you find) to the new custom file.
4145 This will preserve your existing customizations.
4147 If you save this option using Custom, Custom will write all
4148 currently saved customizations, including the new one for this
4149 option itself, into the file you specify, overwriting any
4150 `custom-set-variables' and `custom-set-faces' forms already
4151 present in that file. It will not delete any customizations from
4152 the old custom file. You should do that manually if that is what you
4153 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4154 in your init file, where CUSTOM-FILE is the actual name of the
4155 file. Otherwise, Emacs will not load the file when it starts up,
4156 and hence will not set `custom-file' to that file either."
4157 :type '(choice (const :tag "Your Emacs init file" nil)
4158 (file :format "%t:%v%d"
4159 :doc
4160 "Please read entire docstring below before setting \
4161 this through Custom.
4162 Click om \"More\" \(or position point there and press RETURN)
4163 if only the first line of the docstring is shown."))
4164 :group 'customize)
4166 (defun custom-file ()
4167 "Return the file name for saving customizations."
4168 (file-chase-links
4169 (or custom-file
4170 (let ((user-init-file user-init-file)
4171 (default-init-file
4172 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
4173 (when (null user-init-file)
4174 (if (or (file-exists-p default-init-file)
4175 (and (eq system-type 'windows-nt)
4176 (file-exists-p "~/_emacs")))
4177 ;; Started with -q, i.e. the file containing
4178 ;; Custom settings hasn't been read. Saving
4179 ;; settings there would overwrite other settings.
4180 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4181 (setq user-init-file default-init-file))
4182 user-init-file))))
4184 ;;;###autoload
4185 (defun custom-save-all ()
4186 "Save all customizations in `custom-file'."
4187 (when (and (null custom-file) init-file-had-error)
4188 (error "Cannot save customizations; init file was not fully loaded"))
4189 (let* ((filename (custom-file))
4190 (recentf-exclude (if recentf-mode
4191 (cons (concat "\\`"
4192 (regexp-quote (custom-file))
4193 "\\'")
4194 recentf-exclude)))
4195 (old-buffer (find-buffer-visiting filename)))
4196 (with-current-buffer (let ((find-file-visit-truename t))
4197 (or old-buffer (find-file-noselect filename)))
4198 (unless (eq major-mode 'emacs-lisp-mode)
4199 (emacs-lisp-mode))
4200 (let ((inhibit-read-only t))
4201 (custom-save-variables)
4202 (custom-save-faces))
4203 (let ((file-precious-flag t))
4204 (save-buffer))
4205 (unless old-buffer
4206 (kill-buffer (current-buffer))))))
4208 ;;;###autoload
4209 (defun customize-save-customized ()
4210 "Save all user options which have been set in this session."
4211 (interactive)
4212 (mapatoms (lambda (symbol)
4213 (let ((face (get symbol 'customized-face))
4214 (value (get symbol 'customized-value))
4215 (face-comment (get symbol 'customized-face-comment))
4216 (variable-comment
4217 (get symbol 'customized-variable-comment)))
4218 (when face
4219 (put symbol 'saved-face face)
4220 (custom-push-theme 'theme-face symbol 'user 'set value)
4221 (put symbol 'customized-face nil))
4222 (when value
4223 (put symbol 'saved-value value)
4224 (custom-push-theme 'theme-value symbol 'user 'set value)
4225 (put symbol 'customized-value nil))
4226 (when variable-comment
4227 (put symbol 'saved-variable-comment variable-comment)
4228 (put symbol 'customized-variable-comment nil))
4229 (when face-comment
4230 (put symbol 'saved-face-comment face-comment)
4231 (put symbol 'customized-face-comment nil)))))
4232 ;; We really should update all custom buffers here.
4233 (custom-save-all))
4235 ;; Editing the custom file contents in a buffer.
4237 (defun custom-save-delete (symbol)
4238 "Delete all calls to SYMBOL from the contents of the current buffer.
4239 Leave point at the old location of the first such call,
4240 or (if there were none) at the end of the buffer.
4242 This function does not save the buffer."
4243 (goto-char (point-min))
4244 ;; Skip all whitespace and comments.
4245 (while (forward-comment 1))
4246 (or (eobp)
4247 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4248 (let (first)
4249 (catch 'found
4250 (while t ;; We exit this loop only via throw.
4251 ;; Skip all whitespace and comments.
4252 (while (forward-comment 1))
4253 (let ((start (point))
4254 (sexp (condition-case nil
4255 (read (current-buffer))
4256 (end-of-file (throw 'found nil)))))
4257 (when (and (listp sexp)
4258 (eq (car sexp) symbol))
4259 (delete-region start (point))
4260 (unless first
4261 (setq first (point)))))))
4262 (if first
4263 (goto-char first)
4264 ;; Move in front of local variables, otherwise long Custom
4265 ;; entries would make them ineffective.
4266 (let ((pos (point-max))
4267 (case-fold-search t))
4268 (save-excursion
4269 (goto-char (point-max))
4270 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4271 'move)
4272 (when (search-forward "Local Variables:" nil t)
4273 (setq pos (line-beginning-position))))
4274 (goto-char pos)))))
4276 (defun custom-save-variables ()
4277 "Save all customized variables in `custom-file'."
4278 (save-excursion
4279 (custom-save-delete 'custom-set-variables)
4280 (let ((standard-output (current-buffer))
4281 (saved-list (make-list 1 0))
4282 sort-fold-case)
4283 ;; First create a sorted list of saved variables.
4284 (mapatoms
4285 (lambda (symbol)
4286 (if (and (get symbol 'saved-value)
4287 ;; ignore theme values
4288 (or (null (get symbol 'theme-value))
4289 (eq 'user (caar (get symbol 'theme-value)))))
4290 (nconc saved-list (list symbol)))))
4291 (setq saved-list (sort (cdr saved-list) 'string<))
4292 (unless (bolp)
4293 (princ "\n"))
4294 (princ "(custom-set-variables
4295 ;; custom-set-variables was added by Custom.
4296 ;; If you edit it by hand, you could mess it up, so be careful.
4297 ;; Your init file should contain only one such instance.
4298 ;; If there is more than one, they won't work right.\n")
4299 (dolist (symbol saved-list)
4300 (let ((spec (car-safe (get symbol 'theme-value)))
4301 (value (get symbol 'saved-value))
4302 (requests (get symbol 'custom-requests))
4303 (now (and (not (custom-variable-p symbol))
4304 (or (boundp symbol)
4305 (eq (get symbol 'force-value)
4306 'rogue))))
4307 (comment (get symbol 'saved-variable-comment)))
4308 ;; Check REQUESTS for validity.
4309 (dolist (request requests)
4310 (when (and (symbolp request) (not (featurep request)))
4311 (message "Unknown requested feature: %s" request)
4312 (setq requests (delq request requests))))
4313 ;; Is there anything customized about this variable?
4314 (when (or (and spec (eq (car spec) 'user))
4315 comment
4316 (and (null spec) (get symbol 'saved-value)))
4317 ;; Output an element for this variable.
4318 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4319 ;; SYMBOL is the variable name.
4320 ;; VALUE-FORM is an expression to return the customized value.
4321 ;; NOW if non-nil means always set the variable immediately
4322 ;; when the customizations are reloaded. This is used
4323 ;; for rogue variables
4324 ;; REQUESTS is a list of packages to load before setting the
4325 ;; variable. Each element of it will be passed to `require'.
4326 ;; COMMENT is whatever comment the user has specified
4327 ;; with the customize facility.
4328 (unless (bolp)
4329 (princ "\n"))
4330 (princ " '(")
4331 (prin1 symbol)
4332 (princ " ")
4333 (prin1 (car value))
4334 (when (or now requests comment)
4335 (princ " ")
4336 (prin1 now)
4337 (when (or requests comment)
4338 (princ " ")
4339 (prin1 requests)
4340 (when comment
4341 (princ " ")
4342 (prin1 comment))))
4343 (princ ")"))))
4344 (if (bolp)
4345 (princ " "))
4346 (princ ")")
4347 (unless (looking-at "\n")
4348 (princ "\n")))))
4350 (defun custom-save-faces ()
4351 "Save all customized faces in `custom-file'."
4352 (save-excursion
4353 (custom-save-delete 'custom-reset-faces)
4354 (custom-save-delete 'custom-set-faces)
4355 (let ((standard-output (current-buffer))
4356 (saved-list (make-list 1 0))
4357 sort-fold-case)
4358 ;; First create a sorted list of saved faces.
4359 (mapatoms
4360 (lambda (symbol)
4361 (if (and (get symbol 'saved-face)
4362 (eq 'user (car (car-safe (get symbol 'theme-face)))))
4363 (nconc saved-list (list symbol)))))
4364 (setq saved-list (sort (cdr saved-list) 'string<))
4365 ;; The default face must be first, since it affects the others.
4366 (if (memq 'default saved-list)
4367 (setq saved-list (cons 'default (delq 'default saved-list))))
4368 (unless (bolp)
4369 (princ "\n"))
4370 (princ "(custom-set-faces
4371 ;; custom-set-faces was added by Custom.
4372 ;; If you edit it by hand, you could mess it up, so be careful.
4373 ;; Your init file should contain only one such instance.
4374 ;; If there is more than one, they won't work right.\n")
4375 (dolist (symbol saved-list)
4376 (let ((spec (car-safe (get symbol 'theme-face)))
4377 (value (get symbol 'saved-face))
4378 (now (not (or (get symbol 'face-defface-spec)
4379 (and (not (custom-facep symbol))
4380 (not (get symbol 'force-face))))))
4381 (comment (get symbol 'saved-face-comment)))
4382 (when (or (and spec (eq (nth 0 spec) 'user))
4383 comment
4384 (and (null spec) (get symbol 'saved-face)))
4385 ;; Don't print default face here.
4386 (unless (bolp)
4387 (princ "\n"))
4388 (princ " '(")
4389 (prin1 symbol)
4390 (princ " ")
4391 (prin1 value)
4392 (when (or now comment)
4393 (princ " ")
4394 (prin1 now)
4395 (when comment
4396 (princ " ")
4397 (prin1 comment)))
4398 (princ ")"))))
4399 (if (bolp)
4400 (princ " "))
4401 (princ ")")
4402 (unless (looking-at "\n")
4403 (princ "\n")))))
4405 ;;; The Customize Menu.
4407 ;;; Menu support
4409 (defcustom custom-menu-nesting 2
4410 "Maximum nesting in custom menus."
4411 :type 'integer
4412 :group 'custom-menu)
4414 (defun custom-face-menu-create (widget symbol)
4415 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4416 (vector (custom-unlispify-menu-entry symbol)
4417 `(customize-face ',symbol)
4420 (defun custom-variable-menu-create (widget symbol)
4421 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4422 (let ((type (get symbol 'custom-type)))
4423 (unless (listp type)
4424 (setq type (list type)))
4425 (if (and type (widget-get type :custom-menu))
4426 (widget-apply type :custom-menu symbol)
4427 (vector (custom-unlispify-menu-entry symbol)
4428 `(customize-variable ',symbol)
4429 t))))
4431 ;; Add checkboxes to boolean variable entries.
4432 (widget-put (get 'boolean 'widget-type)
4433 :custom-menu (lambda (widget symbol)
4434 (vector (custom-unlispify-menu-entry symbol)
4435 `(customize-variable ',symbol)
4436 ':style 'toggle
4437 ':selected symbol)))
4439 (defun custom-group-menu-create (widget symbol)
4440 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4441 `( ,(custom-unlispify-menu-entry symbol t)
4442 :filter (lambda (&rest junk)
4443 (let* ((menu (custom-menu-create ',symbol)))
4444 (if (consp menu) (cdr menu) menu)))))
4446 ;;;###autoload
4447 (defun custom-menu-create (symbol)
4448 "Create menu for customization group SYMBOL.
4449 The menu is in a format applicable to `easy-menu-define'."
4450 (let* ((deactivate-mark nil)
4451 (item (vector (custom-unlispify-menu-entry symbol)
4452 `(customize-group ',symbol)
4453 t)))
4454 (if (and (or (not (boundp 'custom-menu-nesting))
4455 (>= custom-menu-nesting 0))
4456 (progn
4457 (custom-load-symbol symbol)
4458 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
4459 (let ((custom-prefix-list (custom-prefix-add symbol
4460 custom-prefix-list))
4461 (members (custom-sort-items (get symbol 'custom-group)
4462 custom-menu-sort-alphabetically
4463 custom-menu-order-groups)))
4464 `(,(custom-unlispify-menu-entry symbol t)
4465 ,item
4466 "--"
4467 ,@(mapcar (lambda (entry)
4468 (widget-apply (if (listp (nth 1 entry))
4469 (nth 1 entry)
4470 (list (nth 1 entry)))
4471 :custom-menu (nth 0 entry)))
4472 members)))
4473 item)))
4475 ;;;###autoload
4476 (defun customize-menu-create (symbol &optional name)
4477 "Return a customize menu for customization group SYMBOL.
4478 If optional NAME is given, use that as the name of the menu.
4479 Otherwise the menu will be named `Customize'.
4480 The format is suitable for use with `easy-menu-define'."
4481 (unless name
4482 (setq name "Customize"))
4483 `(,name
4484 :filter (lambda (&rest junk)
4485 (let ((menu (custom-menu-create ',symbol)))
4486 (if (consp menu) (cdr menu) menu)))))
4488 ;;; The Custom Mode.
4490 (defun Custom-no-edit (pos &optional event)
4491 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4492 (interactive "@d")
4493 (error "You can't edit this part of the Custom buffer"))
4495 (defun Custom-newline (pos &optional event)
4496 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4497 (interactive "@d")
4498 (let ((button (get-char-property pos 'button)))
4499 (if button
4500 (widget-apply-action button event)
4501 (error "You can't edit this part of the Custom buffer"))))
4503 (easy-menu-define Custom-mode-menu
4504 custom-mode-map
4505 "Menu used in customization buffers."
4506 `("Custom"
4507 ,(customize-menu-create 'customize)
4508 ["Set" Custom-set t]
4509 ["Save" Custom-save t]
4510 ["Undo Edits" Custom-reset-current t]
4511 ["Reset to Saved" Custom-reset-saved t]
4512 ["Erase Customization" Custom-reset-standard t]
4513 ["Info" (info "(emacs)Easy Customization") t]))
4515 (defvar custom-field-keymap
4516 (let ((map (copy-keymap widget-field-keymap)))
4517 (define-key map "\C-c\C-c" 'Custom-set)
4518 (define-key map "\C-x\C-s" 'Custom-save)
4519 map)
4520 "Keymap used inside editable fields in customization buffers.")
4522 (widget-put (get 'editable-field 'widget-type) :keymap custom-field-keymap)
4524 (defun Custom-goto-parent ()
4525 "Go to the parent group listed at the top of this buffer.
4526 If several parents are listed, go to the first of them."
4527 (interactive)
4528 (save-excursion
4529 (goto-char (point-min))
4530 (if (search-forward "\nGo to parent group: " nil t)
4531 (let* ((button (get-char-property (point) 'button))
4532 (parent (downcase (widget-get button :tag))))
4533 (customize-group parent)))))
4535 (defcustom custom-mode-hook nil
4536 "Hook called when entering Custom mode."
4537 :type 'hook
4538 :group 'custom-buffer )
4540 (defun custom-state-buffer-message (widget)
4541 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4542 (message "To install your edits, invoke [State] and choose the Set operation")))
4544 (defun custom-mode ()
4545 "Major mode for editing customization buffers.
4547 The following commands are available:
4549 \\<widget-keymap>\
4550 Move to next button, link or editable field. \\[widget-forward]
4551 Move to previous button, link or editable field. \\[advertised-widget-backward]
4552 \\<custom-field-keymap>\
4553 Complete content of editable text field. \\[widget-complete]
4554 \\<custom-mode-map>\
4555 Invoke button under the mouse pointer. \\[widget-button-click]
4556 Invoke button under point. \\[widget-button-press]
4557 Set all options from current text. \\[Custom-set]
4558 Make values in current text permanent. \\[Custom-save]
4559 Make text match actual option values. \\[Custom-reset-current]
4560 Reset options to permanent settings. \\[Custom-reset-saved]
4561 Erase customizations; set options
4562 and buffer text to the standard values. \\[Custom-reset-standard]
4564 Entry to this mode calls the value of `custom-mode-hook'
4565 if that value is non-nil."
4566 (kill-all-local-variables)
4567 (setq major-mode 'custom-mode
4568 mode-name "Custom")
4569 (use-local-map custom-mode-map)
4570 (easy-menu-add Custom-mode-menu)
4571 (make-local-variable 'custom-options)
4572 (make-local-variable 'custom-local-buffer)
4573 (make-local-variable 'widget-documentation-face)
4574 (setq widget-documentation-face 'custom-documentation)
4575 (make-local-variable 'widget-button-face)
4576 (setq widget-button-face custom-button)
4578 ;; We need this because of the "More" button on docstrings.
4579 ;; Otherwise clicking on "More" can push point offscreen, which
4580 ;; causes the window to recenter on point, which pushes the
4581 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4582 (set (make-local-variable 'widget-button-click-moves-point) t)
4584 (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed)
4585 (set (make-local-variable 'widget-mouse-face) custom-button-mouse)
4587 ;; When possible, use relief for buttons, not bracketing. This test
4588 ;; may not be optimal.
4589 (when custom-raised-buttons
4590 (set (make-local-variable 'widget-push-button-prefix) "")
4591 (set (make-local-variable 'widget-push-button-suffix) "")
4592 (set (make-local-variable 'widget-link-prefix) "")
4593 (set (make-local-variable 'widget-link-suffix) ""))
4594 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
4595 (run-mode-hooks 'custom-mode-hook))
4597 (put 'custom-mode 'mode-class 'special)
4599 (dolist (regexp
4600 '("^No user option defaults have been changed since Emacs "
4601 "^Invalid face:? "
4602 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4603 "^No customizable items matching "
4604 "^There are unset changes"
4605 "^Cannot set hidden variable"
4606 "^No \\(?:saved\\|backup\\) value for "
4607 "^No standard setting known for "
4608 "^No standard setting for this face"
4609 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4610 (add-to-list 'debug-ignored-errors regexp))
4612 ;;; The End.
4614 (provide 'cus-edit)
4616 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4617 ;;; cus-edit.el ends here