(url-retrieve-internal): Don't use `url-proxy-object'.
[emacs.git] / lisp / cus-edit.el
blob27ce163157bc349ba98057a22a7035d421071849
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 ;;;###autoload
683 (defcustom custom-browse-sort-alphabetically nil
684 "If non-nil, sort customization group alphabetically in `custom-browse'."
685 :type 'boolean
686 :group 'custom-browse)
688 (defcustom custom-browse-order-groups nil
689 "If non-nil, order group members within each customization group.
690 If `first', order groups before non-groups.
691 If `last', order groups after non-groups."
692 :type '(choice (const first)
693 (const last)
694 (const :tag "none" nil))
695 :group 'custom-browse)
697 (defcustom custom-browse-only-groups nil
698 "If non-nil, show group members only within each customization group."
699 :type 'boolean
700 :group 'custom-browse)
702 ;;;###autoload
703 (defcustom custom-buffer-sort-alphabetically nil
704 "If non-nil, sort each customization group alphabetically in Custom buffer."
705 :type 'boolean
706 :group 'custom-buffer)
708 (defcustom custom-buffer-order-groups 'last
709 "If non-nil, order group members within each customization group.
710 If `first', order groups before non-groups.
711 If `last', order groups after non-groups."
712 :type '(choice (const first)
713 (const last)
714 (const :tag "none" nil))
715 :group 'custom-buffer)
717 ;;;###autoload
718 (defcustom custom-menu-sort-alphabetically nil
719 "If non-nil, sort each customization group alphabetically in menus."
720 :type 'boolean
721 :group 'custom-menu)
723 (defcustom custom-menu-order-groups 'first
724 "If non-nil, order group members within each customization group.
725 If `first', order groups before non-groups.
726 If `last', order groups after non-groups."
727 :type '(choice (const first)
728 (const last)
729 (const :tag "none" nil))
730 :group 'custom-menu)
732 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
734 (defun custom-sort-items (items sort-alphabetically order-groups)
735 "Return a sorted copy of ITEMS.
736 ITEMS should be a `custom-group' property.
737 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
738 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
739 groups after non-groups, if nil do not order groups at all."
740 (sort (copy-sequence items)
741 (lambda (a b)
742 (let ((typea (nth 1 a)) (typeb (nth 1 b))
743 (namea (nth 0 a)) (nameb (nth 0 b)))
744 (cond ((not order-groups)
745 ;; Since we don't care about A and B order, maybe sort.
746 (when sort-alphabetically
747 (string-lessp namea nameb)))
748 ((eq typea 'custom-group)
749 ;; If B is also a group, maybe sort. Otherwise, order A and B.
750 (if (eq typeb 'custom-group)
751 (when sort-alphabetically
752 (string-lessp namea nameb))
753 (eq order-groups 'first)))
754 ((eq typeb 'custom-group)
755 ;; Since A cannot be a group, order A and B.
756 (eq order-groups 'last))
757 (sort-alphabetically
758 ;; Since A and B cannot be groups, sort.
759 (string-lessp namea nameb)))))))
761 ;;; Custom Mode Commands.
763 (defvar custom-options nil
764 "Customization widgets in the current buffer.")
766 (defun Custom-set ()
767 "Set the current value of all edited settings in the buffer."
768 (interactive)
769 (let ((children custom-options))
770 (if (or (and (= 1 (length children))
771 (memq (widget-type (car children))
772 '(custom-variable custom-face)))
773 (y-or-n-p "Set all values according to this buffer? "))
774 (mapc (lambda (child)
775 (when (eq (widget-get child :custom-state) 'modified)
776 (widget-apply child :custom-set)))
777 children)
778 (message "Aborted"))))
780 (defun Custom-save ()
781 "Set all edited settings, then save all settings that have been set.
782 If a setting was edited and set before, this saves it.
783 If a setting was merely edited before, this sets it then saves it."
784 (interactive)
785 (let ((children custom-options))
786 (if (or (and (= 1 (length children))
787 (memq (widget-type (car children))
788 '(custom-variable custom-face)))
789 (yes-or-no-p "Save all settings in this buffer? "))
790 (progn
791 (mapc (lambda (child)
792 (when (memq (widget-get child :custom-state)
793 '(modified set changed rogue))
794 (widget-apply child :custom-save)))
795 children)
796 (custom-save-all))
797 (message "Aborted"))))
799 (defvar custom-reset-menu
800 '(("Undo Edits" . Custom-reset-current)
801 ("Reset to Saved" . Custom-reset-saved)
802 ("Erase Customization (use standard values)" . Custom-reset-standard))
803 "Alist of actions for the `Reset' button.
804 The key is a string containing the name of the action, the value is a
805 Lisp function taking the widget as an element which will be called
806 when the action is chosen.")
808 (defun custom-reset (event)
809 "Select item from reset menu."
810 (let* ((completion-ignore-case t)
811 (answer (widget-choose "Reset settings"
812 custom-reset-menu
813 event)))
814 (if answer
815 (funcall answer))))
817 (defun Custom-reset-current (&rest ignore)
818 "Reset all edited settings in the buffer to show their current values."
819 (interactive)
820 (let ((children custom-options))
821 (if (or (and (= 1 (length children))
822 (memq (widget-type (car children))
823 '(custom-variable custom-face)))
824 (y-or-n-p "Reset all settings' buffer text to show current values? "))
825 (mapc (lambda (widget)
826 (if (memq (widget-get widget :custom-state)
827 '(modified changed))
828 (widget-apply widget :custom-reset-current)))
829 children)
830 (message "Aborted"))))
832 (defun Custom-reset-saved (&rest ignore)
833 "Reset all edited or set settings in the buffer to their saved value.
834 This also shows the saved values in the buffer."
835 (interactive)
836 (let ((children custom-options))
837 (if (or (and (= 1 (length children))
838 (memq (widget-type (car children))
839 '(custom-variable custom-face)))
840 (y-or-n-p "Reset all settings (current values and buffer text) to saved values? "))
841 (mapc (lambda (widget)
842 (if (memq (widget-get widget :custom-state)
843 '(modified set changed rogue))
844 (widget-apply widget :custom-reset-saved)))
845 children)
846 (message "Aborted"))))
848 (defun Custom-reset-standard (&rest ignore)
849 "Erase all customization (either current or saved) for the group members.
850 The immediate result is to restore them to their standard values.
851 This operation eliminates any saved values for the group members,
852 making them as if they had never been customized at all."
853 (interactive)
854 (let ((children custom-options))
855 (if (or (and (= 1 (length children))
856 (memq (widget-type (car children))
857 '(custom-variable custom-face)))
858 (yes-or-no-p "Erase all customizations for settings in this buffer? "))
859 (mapc (lambda (widget)
860 (and (if (widget-get widget :custom-standard-value)
861 (widget-apply widget :custom-standard-value)
863 (memq (widget-get widget :custom-state)
864 '(modified set changed saved rogue))
865 (widget-apply widget :custom-reset-standard)))
866 children)
867 (message "Aborted"))))
869 ;;; The Customize Commands
871 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
872 "Prompt for a variable and a value and return them as a list.
873 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
874 prompt for the value. The %s escape in PROMPT-VAL is replaced with
875 the name of the variable.
877 If the variable has a `variable-interactive' property, that is used as if
878 it were the arg to `interactive' (which see) to interactively read the value.
880 If the variable has a `custom-type' property, it must be a widget and the
881 `:prompt-value' property of that widget will be used for reading the value.
883 If optional COMMENT argument is non-nil, also prompt for a comment and return
884 it as the third element in the list."
885 (let* ((var (read-variable prompt-var))
886 (minibuffer-help-form '(describe-variable var))
887 (val
888 (let ((prop (get var 'variable-interactive))
889 (type (get var 'custom-type))
890 (prompt (format prompt-val var)))
891 (unless (listp type)
892 (setq type (list type)))
893 (cond (prop
894 ;; Use VAR's `variable-interactive' property
895 ;; as an interactive spec for prompting.
896 (call-interactively (list 'lambda '(arg)
897 (list 'interactive prop)
898 'arg)))
899 (type
900 (widget-prompt-value type
901 prompt
902 (if (boundp var)
903 (symbol-value var))
904 (not (boundp var))))
906 (eval-minibuffer prompt))))))
907 (if comment
908 (list var val
909 (read-string "Comment: " (get var 'variable-comment)))
910 (list var val))))
912 ;;;###autoload
913 (defun customize-set-value (variable value &optional comment)
914 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
916 If VARIABLE has a `variable-interactive' property, that is used as if
917 it were the arg to `interactive' (which see) to interactively read the value.
919 If VARIABLE has a `custom-type' property, it must be a widget and the
920 `:prompt-value' property of that widget will be used for reading the value.
922 If given a prefix (or a COMMENT argument), also prompt for a comment."
923 (interactive (custom-prompt-variable "Set variable: "
924 "Set %s to value: "
925 current-prefix-arg))
927 (cond ((string= comment "")
928 (put variable 'variable-comment nil))
929 (comment
930 (put variable 'variable-comment comment)))
931 (set variable value))
933 ;;;###autoload
934 (defun customize-set-variable (variable value &optional comment)
935 "Set the default for VARIABLE to VALUE, and return VALUE.
936 VALUE is a Lisp object.
938 If VARIABLE has a `custom-set' property, that is used for setting
939 VARIABLE, otherwise `set-default' is used.
941 The `customized-value' property of the VARIABLE will be set to a list
942 with a quoted VALUE as its sole list member.
944 If VARIABLE has a `variable-interactive' property, that is used as if
945 it were the arg to `interactive' (which see) to interactively read the value.
947 If VARIABLE has a `custom-type' property, it must be a widget and the
948 `:prompt-value' property of that widget will be used for reading the value.
950 If given a prefix (or a COMMENT argument), also prompt for a comment."
951 (interactive (custom-prompt-variable "Set variable: "
952 "Set customized value for %s to: "
953 current-prefix-arg))
954 (custom-load-symbol variable)
955 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
956 (funcall (or (get variable 'custom-set) 'set-default) variable value)
957 (put variable 'customized-value (list (custom-quote value)))
958 (cond ((string= comment "")
959 (put variable 'variable-comment nil)
960 (put variable 'customized-variable-comment nil))
961 (comment
962 (put variable 'variable-comment comment)
963 (put variable 'customized-variable-comment comment)))
964 value)
966 ;;;###autoload
967 (defun customize-save-variable (variable value &optional comment)
968 "Set the default for VARIABLE to VALUE, and save it for future sessions.
969 Return VALUE.
971 If VARIABLE has a `custom-set' property, that is used for setting
972 VARIABLE, otherwise `set-default' is used.
974 The `customized-value' property of the VARIABLE will be set to a list
975 with a quoted VALUE as its sole list member.
977 If VARIABLE has a `variable-interactive' property, that is used as if
978 it were the arg to `interactive' (which see) to interactively read the value.
980 If VARIABLE has a `custom-type' property, it must be a widget and the
981 `:prompt-value' property of that widget will be used for reading the value.
983 If given a prefix (or a COMMENT argument), also prompt for a comment."
984 (interactive (custom-prompt-variable "Set and save variable: "
985 "Set and save value for %s as: "
986 current-prefix-arg))
987 (funcall (or (get variable 'custom-set) 'set-default) variable value)
988 (put variable 'saved-value (list (custom-quote value)))
989 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
990 (cond ((string= comment "")
991 (put variable 'variable-comment nil)
992 (put variable 'saved-variable-comment nil))
993 (comment
994 (put variable 'variable-comment comment)
995 (put variable 'saved-variable-comment comment)))
996 (custom-save-all)
997 value)
999 ;;;###autoload
1000 (defun customize ()
1001 "Select a customization buffer which you can use to set user options.
1002 User options are structured into \"groups\".
1003 Initially the top-level group `Emacs' and its immediate subgroups
1004 are shown; the contents of those subgroups are initially hidden."
1005 (interactive)
1006 (customize-group 'emacs))
1008 ;;;###autoload
1009 (defun customize-mode (mode)
1010 "Customize options related to the current major mode.
1011 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1012 then prompt for the MODE to customize."
1013 (interactive
1014 (list
1015 (let ((completion-regexp-list '("-mode\\'"))
1016 (group (custom-group-of-mode major-mode)))
1017 (if (and group (not current-prefix-arg))
1018 major-mode
1019 (intern
1020 (completing-read (if group
1021 (format "Major mode (default %s): " major-mode)
1022 "Major mode: ")
1023 obarray
1024 'custom-group-of-mode
1025 t nil nil (if group (symbol-name major-mode))))))))
1026 (customize-group (custom-group-of-mode mode)))
1029 ;;;###autoload
1030 (defun customize-group (group)
1031 "Customize GROUP, which must be a customization group."
1032 (interactive
1033 (list (let ((completion-ignore-case t))
1034 (completing-read "Customize group (default emacs): "
1035 obarray
1036 (lambda (symbol)
1037 (or (and (get symbol 'custom-loads)
1038 (not (get symbol 'custom-autoload)))
1039 (get symbol 'custom-group)))
1040 t))))
1041 (when (stringp group)
1042 (if (string-equal "" group)
1043 (setq group 'emacs)
1044 (setq group (intern group))))
1045 (let ((name (format "*Customize Group: %s*"
1046 (custom-unlispify-tag-name group))))
1047 (if (get-buffer name)
1048 (pop-to-buffer name)
1049 (custom-buffer-create (list (list group 'custom-group))
1050 name
1051 (concat " for group "
1052 (custom-unlispify-tag-name group))))))
1054 ;;;###autoload
1055 (defun customize-group-other-window (group)
1056 "Customize GROUP, which must be a customization group."
1057 (interactive
1058 (list (let ((completion-ignore-case t))
1059 (completing-read "Customize group (default emacs): "
1060 obarray
1061 (lambda (symbol)
1062 (or (and (get symbol 'custom-loads)
1063 (not (get symbol 'custom-autoload)))
1064 (get symbol 'custom-group)))
1065 t))))
1066 (when (stringp group)
1067 (if (string-equal "" group)
1068 (setq group 'emacs)
1069 (setq group (intern group))))
1070 (let ((name (format "*Customize Group: %s*"
1071 (custom-unlispify-tag-name group))))
1072 (if (get-buffer name)
1073 (let (
1074 ;; Copied from `custom-buffer-create-other-window'.
1075 (pop-up-windows t)
1076 (same-window-buffer-names nil)
1077 (same-window-regexps nil))
1078 (pop-to-buffer name))
1079 (custom-buffer-create-other-window
1080 (list (list group 'custom-group))
1081 name
1082 (concat " for group "
1083 (custom-unlispify-tag-name group))))))
1085 ;;;###autoload
1086 (defalias 'customize-variable 'customize-option)
1088 ;;;###autoload
1089 (defun customize-option (symbol)
1090 "Customize SYMBOL, which must be a user option variable."
1091 (interactive (custom-variable-prompt))
1092 (unless symbol
1093 (error "No variable specified"))
1094 (let ((basevar (indirect-variable symbol)))
1095 (custom-buffer-create (list (list basevar 'custom-variable))
1096 (format "*Customize Option: %s*"
1097 (custom-unlispify-tag-name basevar)))
1098 (unless (eq symbol basevar)
1099 (message "`%s' is an alias for `%s'" symbol basevar))))
1101 ;;;###autoload
1102 (defalias 'customize-variable-other-window 'customize-option-other-window)
1104 ;;;###autoload
1105 (defun customize-option-other-window (symbol)
1106 "Customize SYMBOL, which must be a user option variable.
1107 Show the buffer in another window, but don't select it."
1108 (interactive (custom-variable-prompt))
1109 (unless symbol
1110 (error "No variable specified"))
1111 (let ((basevar (indirect-variable symbol)))
1112 (custom-buffer-create-other-window
1113 (list (list basevar 'custom-variable))
1114 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar)))
1115 (unless (eq symbol basevar)
1116 (message "`%s' is an alias for `%s'" symbol basevar))))
1118 (defvar customize-changed-options-previous-release "21.1"
1119 "Version for `customize-changed-options' to refer back to by default.")
1121 ;; Packages will update this variable, so make it available.
1122 ;;;###autoload
1123 (defvar customize-package-emacs-version-alist nil
1124 "Alist mapping versions of a package to Emacs versions.
1125 We use this for packages that have their own names, but are released
1126 as part of Emacs itself.
1128 Each elements looks like this:
1130 (PACKAGE (PVERSION . EVERSION)...)
1132 Here PACKAGE is the name of a package, as a symbol. After
1133 PACKAGE come one or more elements, each associating a
1134 package version PVERSION with the first Emacs version
1135 EVERSION in which it (or a subsequent version of PACKAGE)
1136 was first released. Both PVERSION and EVERSION are strings.
1137 PVERSION should be a string that this package used in
1138 the :package-version keyword for `defcustom', `defgroup',
1139 and `defface'.
1141 For example, the MH-E package updates this alist as follows:
1143 (add-to-list 'customize-package-emacs-version-alist
1144 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1145 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1146 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1147 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1149 The value of PACKAGE needs to be unique and it needs to match the
1150 PACKAGE value appearing in the :package-version keyword. Since
1151 the user might see the value in a error message, a good choice is
1152 the official name of the package, such as MH-E or Gnus.")
1154 ;;;###autoload
1155 (defalias 'customize-changed 'customize-changed-options)
1157 ;;;###autoload
1158 (defun customize-changed-options (since-version)
1159 "Customize all settings whose meanings have changed in Emacs itself.
1160 This includes new user option variables and faces, and new
1161 customization groups, as well as older options and faces whose meanings
1162 or default values have changed since the previous major Emacs release.
1164 With argument SINCE-VERSION (a string), customize all settings
1165 that were added or redefined since that version."
1167 (interactive
1168 (list
1169 (read-from-minibuffer
1170 (format "Customize options changed, since version (default %s): "
1171 customize-changed-options-previous-release))))
1172 (if (equal since-version "")
1173 (setq since-version nil)
1174 (unless (condition-case nil
1175 (numberp (read since-version))
1176 (error nil))
1177 (signal 'wrong-type-argument (list 'numberp since-version))))
1178 (unless since-version
1179 (setq since-version customize-changed-options-previous-release))
1181 ;; Load the information for versions since since-version. We use
1182 ;; custom-load-symbol for this.
1183 (put 'custom-versions-load-alist 'custom-loads nil)
1184 (dolist (elt custom-versions-load-alist)
1185 (if (customize-version-lessp since-version (car elt))
1186 (dolist (load (cdr elt))
1187 (custom-add-load 'custom-versions-load-alist load))))
1188 (custom-load-symbol 'custom-versions-load-alist)
1189 (put 'custom-versions-load-alist 'custom-loads nil)
1191 (let (found)
1192 (mapatoms
1193 (lambda (symbol)
1194 (let* ((package-version (get symbol 'custom-package-version))
1195 (version
1196 (or (and package-version
1197 (customize-package-emacs-version symbol
1198 package-version))
1199 (get symbol 'custom-version))))
1200 (if version
1201 (when (customize-version-lessp since-version version)
1202 (if (or (get symbol 'custom-group)
1203 (get symbol 'group-documentation))
1204 (push (list symbol 'custom-group) found))
1205 (if (custom-variable-p symbol)
1206 (push (list symbol 'custom-variable) found))
1207 (if (custom-facep symbol)
1208 (push (list symbol 'custom-face) found)))))))
1209 (if found
1210 (custom-buffer-create (custom-sort-items found t 'first)
1211 "*Customize Changed Options*")
1212 (error "No user option defaults have been changed since Emacs %s"
1213 since-version))))
1215 (defun customize-package-emacs-version (symbol package-version)
1216 "Return the Emacs version in which SYMBOL's meaning last changed.
1217 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1218 `customize-package-emacs-version-alist' to find the version of
1219 Emacs that is associated with version VERSION of PACKAGE."
1220 (let (package-versions emacs-version)
1221 ;; Use message instead of error since we want user to be able to
1222 ;; see the rest of the symbols even if a package author has
1223 ;; botched things up.
1224 (cond ((not (listp package-version))
1225 (message "Invalid package-version value for %s" symbol))
1226 ((setq package-versions (assq (car package-version)
1227 customize-package-emacs-version-alist))
1228 (setq emacs-version
1229 (cdr (assoc (cdr package-version) package-versions)))
1230 (unless emacs-version
1231 (message "%s version %s not found in %s" symbol
1232 (cdr package-version)
1233 "customize-package-emacs-version-alist")))
1235 (message "Package %s version %s lists no corresponding Emacs version"
1236 (car package-version)
1237 (cdr package-version))))
1238 emacs-version))
1240 (defun customize-version-lessp (version1 version2)
1241 ;; Why are the versions strings, and given that they are, why aren't
1242 ;; they converted to numbers and compared as such here? -- fx
1244 ;; In case someone made a mistake and left out the quotes
1245 ;; in the :version value.
1246 (if (numberp version2)
1247 (setq version2 (prin1-to-string version2)))
1248 (let (major1 major2 minor1 minor2)
1249 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1250 (setq major1 (read (or (match-string 1 version1)
1251 "0")))
1252 (setq minor1 (read (or (match-string 3 version1)
1253 "0")))
1254 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1255 (setq major2 (read (or (match-string 1 version2)
1256 "0")))
1257 (setq minor2 (read (or (match-string 3 version2)
1258 "0")))
1259 (or (< major1 major2)
1260 (and (= major1 major2)
1261 (< minor1 minor2)))))
1263 ;;;###autoload
1264 (defun customize-face (&optional face)
1265 "Customize FACE, which should be a face name or nil.
1266 If FACE is nil, customize all faces. If FACE is actually a
1267 face-alias, customize the face it is aliased to.
1269 Interactively, when point is on text which has a face specified,
1270 suggest to customize that face, if it's customizable."
1271 (interactive
1272 (list (read-face-name "Customize face" "all faces" t)))
1273 (if (member face '(nil ""))
1274 (setq face (face-list)))
1275 (if (and (listp face) (null (cdr face)))
1276 (setq face (car face)))
1277 (if (listp face)
1278 (custom-buffer-create (custom-sort-items
1279 (mapcar (lambda (s)
1280 (list s 'custom-face))
1281 face)
1282 t nil)
1283 "*Customize Faces*")
1284 ;; If FACE is actually an alias, customize the face it is aliased to.
1285 (if (get face 'face-alias)
1286 (setq face (get face 'face-alias)))
1287 (unless (facep face)
1288 (error "Invalid face %S" face))
1289 (custom-buffer-create (list (list face 'custom-face))
1290 (format "*Customize Face: %s*"
1291 (custom-unlispify-tag-name face)))))
1293 ;;;###autoload
1294 (defun customize-face-other-window (&optional face)
1295 "Show customization buffer for face FACE in other window.
1296 If FACE is actually a face-alias, customize the face it is aliased to.
1298 Interactively, when point is on text which has a face specified,
1299 suggest to customize that face, if it's customizable."
1300 (interactive
1301 (list (read-face-name "Customize face" "all faces" t)))
1302 (if (member face '(nil ""))
1303 (setq face (face-list)))
1304 (if (and (listp face) (null (cdr face)))
1305 (setq face (car face)))
1306 (if (listp face)
1307 (custom-buffer-create-other-window
1308 (custom-sort-items
1309 (mapcar (lambda (s)
1310 (list s 'custom-face))
1311 face)
1312 t nil)
1313 "*Customize Faces*")
1314 (if (get face 'face-alias)
1315 (setq face (get face 'face-alias)))
1316 (unless (facep face)
1317 (error "Invalid face %S" face))
1318 (custom-buffer-create-other-window
1319 (list (list face 'custom-face))
1320 (format "*Customize Face: %s*"
1321 (custom-unlispify-tag-name face)))))
1323 (defalias 'customize-customized 'customize-unsaved)
1325 ;;;###autoload
1326 (defun customize-unsaved ()
1327 "Customize all user options set in this session but not saved."
1328 (interactive)
1329 (let ((found nil))
1330 (mapatoms (lambda (symbol)
1331 (and (or (get symbol 'customized-face)
1332 (get symbol 'customized-face-comment))
1333 (custom-facep symbol)
1334 (push (list symbol 'custom-face) found))
1335 (and (or (get symbol 'customized-value)
1336 (get symbol 'customized-variable-comment))
1337 (boundp symbol)
1338 (push (list symbol 'custom-variable) found))))
1339 (if (not found)
1340 (error "No user options are set but unsaved")
1341 (custom-buffer-create (custom-sort-items found t nil)
1342 "*Customize Unsaved*"))))
1344 ;;;###autoload
1345 (defun customize-rogue ()
1346 "Customize all user variables modified outside customize."
1347 (interactive)
1348 (let ((found nil))
1349 (mapatoms (lambda (symbol)
1350 (let ((cval (or (get symbol 'customized-value)
1351 (get symbol 'saved-value)
1352 (get symbol 'standard-value))))
1353 (when (and cval ;Declared with defcustom.
1354 (default-boundp symbol) ;Has a value.
1355 (not (equal (eval (car cval))
1356 ;; Which does not match customize.
1357 (default-value symbol))))
1358 (push (list symbol 'custom-variable) found)))))
1359 (if (not found)
1360 (error "No rogue user options")
1361 (custom-buffer-create (custom-sort-items found t nil)
1362 "*Customize Rogue*"))))
1363 ;;;###autoload
1364 (defun customize-saved ()
1365 "Customize all already saved user options."
1366 (interactive)
1367 (let ((found nil))
1368 (mapatoms (lambda (symbol)
1369 (and (or (get symbol 'saved-face)
1370 (get symbol 'saved-face-comment))
1371 (custom-facep symbol)
1372 (push (list symbol 'custom-face) found))
1373 (and (or (get symbol 'saved-value)
1374 (get symbol 'saved-variable-comment))
1375 (boundp symbol)
1376 (push (list symbol 'custom-variable) found))))
1377 (if (not found )
1378 (error "No saved user options")
1379 (custom-buffer-create (custom-sort-items found t nil)
1380 "*Customize Saved*"))))
1382 ;;;###autoload
1383 (defun customize-apropos (regexp &optional all)
1384 "Customize all loaded options, faces and groups matching REGEXP.
1385 If ALL is `options', include only options.
1386 If ALL is `faces', include only faces.
1387 If ALL is `groups', include only groups.
1388 If ALL is t (interactively, with prefix arg), include variables
1389 that are not customizable options, as well as faces and groups
1390 \(but we recommend using `apropos-variable' instead)."
1391 (interactive "sCustomize regexp: \nP")
1392 (let ((found nil))
1393 (mapatoms (lambda (symbol)
1394 (when (string-match regexp (symbol-name symbol))
1395 (when (and (not (memq all '(faces options)))
1396 (get symbol 'custom-group))
1397 (push (list symbol 'custom-group) found))
1398 (when (and (not (memq all '(options groups)))
1399 (custom-facep symbol))
1400 (push (list symbol 'custom-face) found))
1401 (when (and (not (memq all '(groups faces)))
1402 (boundp symbol)
1403 (eq (indirect-variable symbol) symbol)
1404 (or (get symbol 'saved-value)
1405 (custom-variable-p symbol)
1406 (and (not (memq all '(nil options)))
1407 (get symbol 'variable-documentation))))
1408 (push (list symbol 'custom-variable) found)))))
1409 (if (not found)
1410 (error "No customizable items matching %s" regexp)
1411 (custom-buffer-create
1412 (custom-sort-items found t custom-buffer-order-groups)
1413 "*Customize Apropos*"))))
1415 ;;;###autoload
1416 (defun customize-apropos-options (regexp &optional arg)
1417 "Customize all loaded customizable options matching REGEXP.
1418 With prefix arg, include variables that are not customizable options
1419 \(but we recommend using `apropos-variable' instead)."
1420 (interactive "sCustomize regexp: \nP")
1421 (customize-apropos regexp (or arg 'options)))
1423 ;;;###autoload
1424 (defun customize-apropos-faces (regexp)
1425 "Customize all loaded faces matching REGEXP."
1426 (interactive "sCustomize regexp: \n")
1427 (customize-apropos regexp 'faces))
1429 ;;;###autoload
1430 (defun customize-apropos-groups (regexp)
1431 "Customize all loaded groups matching REGEXP."
1432 (interactive "sCustomize regexp: \n")
1433 (customize-apropos regexp 'groups))
1435 ;;; Buffer.
1437 (defcustom custom-buffer-style 'links
1438 "Control the presentation style for customization buffers.
1439 The value should be a symbol, one of:
1441 brackets: groups nest within each other with big horizontal brackets.
1442 links: groups have links to subgroups."
1443 :type '(radio (const brackets)
1444 (const links))
1445 :group 'custom-buffer)
1447 (defcustom custom-buffer-done-kill nil
1448 "*Non-nil means exiting a Custom buffer should kill it."
1449 :type 'boolean
1450 :version "22.1"
1451 :group 'custom-buffer)
1453 (defcustom custom-buffer-indent 3
1454 "Number of spaces to indent nested groups."
1455 :type 'integer
1456 :group 'custom-buffer)
1458 (defun custom-get-fresh-buffer (name)
1459 "Get a fresh new buffer with name NAME.
1460 If the buffer already exist, clean it up to be like new.
1461 Beware: it's not quite like new. Good enough for custom, but maybe
1462 not for everybody."
1463 ;; To be more complete, we should also kill all permanent-local variables,
1464 ;; but it's not needed for custom.
1465 (let ((buf (get-buffer name)))
1466 (when (and buf (buffer-local-value 'buffer-file-name buf))
1467 ;; This will check if the file is not saved.
1468 (kill-buffer buf)
1469 (setq buf nil))
1470 (if (null buf)
1471 (get-buffer-create name)
1472 (with-current-buffer buf
1473 (kill-all-local-variables)
1474 (run-hooks 'kill-buffer-hook)
1475 ;; Delete overlays before erasing the buffer so the overlay hooks
1476 ;; don't get run spuriously when we erase the buffer.
1477 (let ((ols (overlay-lists)))
1478 (dolist (ol (nconc (car ols) (cdr ols)))
1479 (delete-overlay ol)))
1480 (erase-buffer)
1481 buf))))
1483 ;;;###autoload
1484 (defun custom-buffer-create (options &optional name description)
1485 "Create a buffer containing OPTIONS.
1486 Optional NAME is the name of the buffer.
1487 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1488 SYMBOL is a customization option, and WIDGET is a widget for editing
1489 that option."
1490 (pop-to-buffer (custom-get-fresh-buffer (or name "*Customization*")))
1491 (custom-buffer-create-internal options description))
1493 ;;;###autoload
1494 (defun custom-buffer-create-other-window (options &optional name description)
1495 "Create a buffer containing OPTIONS, and display it in another window.
1496 The result includes selecting that window.
1497 Optional NAME is the name of the buffer.
1498 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1499 SYMBOL is a customization option, and WIDGET is a widget for editing
1500 that option."
1501 (unless name (setq name "*Customization*"))
1502 (let ((pop-up-windows t)
1503 (same-window-buffer-names nil)
1504 (same-window-regexps nil))
1505 (pop-to-buffer (custom-get-fresh-buffer name))
1506 (custom-buffer-create-internal options description)))
1508 (defcustom custom-reset-button-menu nil
1509 "If non-nil, only show a single reset button in customize buffers.
1510 This button will have a menu with all three reset operations."
1511 :type 'boolean
1512 :group 'custom-buffer)
1514 (defcustom custom-buffer-verbose-help t
1515 "If non-nil, include explanatory text in the customization buffer."
1516 :type 'boolean
1517 :group 'custom-buffer)
1519 (defun Custom-buffer-done (&rest ignore)
1520 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1521 (interactive)
1522 (quit-window custom-buffer-done-kill))
1524 (defvar custom-button nil
1525 "Face used for buttons in customization buffers.")
1527 (defvar custom-button-mouse nil
1528 "Mouse face used for buttons in customization buffers.")
1530 (defvar custom-button-pressed nil
1531 "Face used for pressed buttons in customization buffers.")
1533 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1534 '(("unspecified" . unspecified))))
1535 "If non-nil, indicate active buttons in a `raised-button' style.
1536 Otherwise use brackets."
1537 :type 'boolean
1538 :version "21.1"
1539 :group 'custom-buffer
1540 :set (lambda (variable value)
1541 (custom-set-default variable value)
1542 (setq custom-button
1543 (if value 'custom-button 'custom-button-unraised))
1544 (setq custom-button-mouse
1545 (if value 'custom-button-mouse 'highlight))
1546 (setq custom-button-pressed
1547 (if value
1548 'custom-button-pressed
1549 'custom-button-pressed-unraised))))
1551 (defun custom-buffer-create-internal (options &optional description)
1552 (custom-mode)
1553 (if custom-buffer-verbose-help
1554 (progn
1555 (widget-insert "This is a customization buffer")
1556 (if description
1557 (widget-insert description))
1558 (widget-insert (format ".
1559 %s buttons; type RET or click mouse-1 to actuate one.
1560 Editing a setting changes only the text in the buffer."
1561 (if custom-raised-buttons
1562 "`Raised' text indicates"
1563 "Square brackets indicate")))
1564 (if init-file-user
1565 (widget-insert "
1566 Use the setting's State button to set it or save changes in it.
1567 Saving a change normally works by editing your Emacs init file.")
1568 (widget-insert "
1569 \nSince you started Emacs with `-q', which inhibits use of the
1570 Emacs init file, you cannot save settings into the Emacs init file."))
1571 (widget-insert "\nSee ")
1572 (widget-create 'custom-manual
1573 :tag "Custom file"
1574 "(emacs)Saving Customizations")
1575 (widget-insert
1576 " for information on how to save in a different file.\n
1577 See ")
1578 (widget-create 'custom-manual
1579 :tag "Help"
1580 :help-echo "Read the online help."
1581 "(emacs)Easy Customization")
1582 (widget-insert " for more information.\n\n")
1583 (widget-insert "Operate on all settings in this buffer that \
1584 are not marked HIDDEN:\n "))
1585 (widget-insert " "))
1586 (widget-create 'push-button
1587 :tag "Set for Current Session"
1588 :help-echo "\
1589 Make your editing in this buffer take effect for this session."
1590 :action (lambda (widget &optional event)
1591 (Custom-set)))
1592 (if (not custom-buffer-verbose-help)
1593 (progn
1594 (widget-insert " ")
1595 (widget-create 'custom-manual
1596 :tag "Help"
1597 :help-echo "Read the online help."
1598 "(emacs)Easy Customization")))
1599 (when (or custom-file user-init-file)
1600 (widget-insert " ")
1601 (widget-create 'push-button
1602 :tag "Save for Future Sessions"
1603 :help-echo "\
1604 Make your editing in this buffer take effect for future Emacs sessions.
1605 This updates your Emacs initialization file or creates a new one."
1606 :action (lambda (widget &optional event)
1607 (Custom-save))))
1608 (if custom-reset-button-menu
1609 (progn
1610 (widget-insert " ")
1611 (widget-create 'push-button
1612 :tag "Reset buffer"
1613 :help-echo "Show a menu with reset operations."
1614 :mouse-down-action (lambda (&rest junk) t)
1615 :action (lambda (widget &optional event)
1616 (custom-reset event))))
1617 (widget-insert "\n ")
1618 (widget-create 'push-button
1619 :tag "Undo Edits"
1620 :help-echo "\
1621 Reset all edited text in this buffer to reflect current values."
1622 :action 'Custom-reset-current)
1623 (widget-insert " ")
1624 (widget-create 'push-button
1625 :tag "Reset to Saved"
1626 :help-echo "\
1627 Reset all settings in this buffer to their saved values."
1628 :action 'Custom-reset-saved)
1629 (widget-insert " ")
1630 (when (or custom-file user-init-file)
1631 (widget-create 'push-button
1632 :tag "Erase Customization"
1633 :help-echo "\
1634 Un-customize all settings in this buffer and save them with standard values."
1635 :action 'Custom-reset-standard)))
1636 (widget-insert " ")
1637 (widget-create 'push-button
1638 :tag "Finish"
1639 :help-echo
1640 (lambda (&rest ignore)
1641 (if custom-buffer-done-kill
1642 "Kill this buffer"
1643 "Bury this buffer"))
1644 :action #'Custom-buffer-done)
1645 (widget-insert "\n\n")
1646 (message "Creating customization items...")
1647 (buffer-disable-undo)
1648 (setq custom-options
1649 (if (= (length options) 1)
1650 (mapcar (lambda (entry)
1651 (widget-create (nth 1 entry)
1652 :documentation-shown t
1653 :custom-state 'unknown
1654 :tag (custom-unlispify-tag-name
1655 (nth 0 entry))
1656 :value (nth 0 entry)))
1657 options)
1658 (let ((count 0)
1659 (length (length options)))
1660 (mapcar (lambda (entry)
1661 (prog2
1662 (message "Creating customization items ...%2d%%"
1663 (/ (* 100.0 count) length))
1664 (widget-create (nth 1 entry)
1665 :tag (custom-unlispify-tag-name
1666 (nth 0 entry))
1667 :value (nth 0 entry))
1668 (setq count (1+ count))
1669 (unless (eq (preceding-char) ?\n)
1670 (widget-insert "\n"))
1671 (widget-insert "\n")))
1672 options))))
1673 (unless (eq (preceding-char) ?\n)
1674 (widget-insert "\n"))
1675 (message "Creating customization items ...done")
1676 (message "Resetting customization items...")
1677 (unless (eq custom-buffer-style 'tree)
1678 (mapc 'custom-magic-reset custom-options))
1679 (message "Resetting customization items...done")
1680 (message "Creating customization setup...")
1681 (widget-setup)
1682 (buffer-enable-undo)
1683 (goto-char (point-min))
1684 (message "Creating customization setup...done"))
1686 ;;; The Tree Browser.
1688 ;;;###autoload
1689 (defun customize-browse (&optional group)
1690 "Create a tree browser for the customize hierarchy."
1691 (interactive)
1692 (unless group
1693 (setq group 'emacs))
1694 (let ((name "*Customize Browser*"))
1695 (pop-to-buffer (custom-get-fresh-buffer name)))
1696 (custom-mode)
1697 (widget-insert (format "\
1698 %s buttons; type RET or click mouse-1
1699 on a button to invoke its action.
1700 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1701 (if custom-raised-buttons
1702 "`Raised' text indicates"
1703 "Square brackets indicate")))
1706 (if custom-browse-only-groups
1707 (widget-insert "\
1708 Invoke the [Group] button below to edit that item in another window.\n\n")
1709 (widget-insert "Invoke the ")
1710 (widget-create 'item
1711 :format "%t"
1712 :tag "[Group]"
1713 :tag-glyph "folder")
1714 (widget-insert ", ")
1715 (widget-create 'item
1716 :format "%t"
1717 :tag "[Face]"
1718 :tag-glyph "face")
1719 (widget-insert ", and ")
1720 (widget-create 'item
1721 :format "%t"
1722 :tag "[Option]"
1723 :tag-glyph "option")
1724 (widget-insert " buttons below to edit that
1725 item in another window.\n\n"))
1726 (let ((custom-buffer-style 'tree))
1727 (widget-create 'custom-group
1728 :custom-last t
1729 :custom-state 'unknown
1730 :tag (custom-unlispify-tag-name group)
1731 :value group))
1732 (widget-setup)
1733 (goto-char (point-min)))
1735 (define-widget 'custom-browse-visibility 'item
1736 "Control visibility of items in the customize tree browser."
1737 :format "%[[%t]%]"
1738 :action 'custom-browse-visibility-action)
1740 (defun custom-browse-visibility-action (widget &rest ignore)
1741 (let ((custom-buffer-style 'tree))
1742 (custom-toggle-parent widget)))
1744 (define-widget 'custom-browse-group-tag 'custom-group-link
1745 "Show parent in other window when activated."
1746 :tag "Group"
1747 :tag-glyph "folder"
1748 :action 'custom-browse-group-tag-action)
1750 (defun custom-browse-group-tag-action (widget &rest ignore)
1751 (let ((parent (widget-get widget :parent)))
1752 (customize-group-other-window (widget-value parent))))
1754 (define-widget 'custom-browse-variable-tag 'custom-group-link
1755 "Show parent in other window when activated."
1756 :tag "Option"
1757 :tag-glyph "option"
1758 :action 'custom-browse-variable-tag-action)
1760 (defun custom-browse-variable-tag-action (widget &rest ignore)
1761 (let ((parent (widget-get widget :parent)))
1762 (customize-variable-other-window (widget-value parent))))
1764 (define-widget 'custom-browse-face-tag 'custom-group-link
1765 "Show parent in other window when activated."
1766 :tag "Face"
1767 :tag-glyph "face"
1768 :action 'custom-browse-face-tag-action)
1770 (defun custom-browse-face-tag-action (widget &rest ignore)
1771 (let ((parent (widget-get widget :parent)))
1772 (customize-face-other-window (widget-value parent))))
1774 (defconst custom-browse-alist '((" " "space")
1775 (" | " "vertical")
1776 ("-\\ " "top")
1777 (" |-" "middle")
1778 (" `-" "bottom")))
1780 (defun custom-browse-insert-prefix (prefix)
1781 "Insert PREFIX. On XEmacs convert it to line graphics."
1782 ;; Fixme: do graphics.
1783 (if nil ; (string-match "XEmacs" emacs-version)
1784 (progn
1785 (insert "*")
1786 (while (not (string-equal prefix ""))
1787 (let ((entry (substring prefix 0 3)))
1788 (setq prefix (substring prefix 3))
1789 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1790 (name (nth 1 (assoc entry custom-browse-alist))))
1791 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1792 (overlay-put overlay 'start-open t)
1793 (overlay-put overlay 'end-open t)))))
1794 (insert prefix)))
1796 ;;; Modification of Basic Widgets.
1798 ;; We add extra properties to the basic widgets needed here. This is
1799 ;; fine, as long as we are careful to stay within out own namespace.
1801 ;; We want simple widgets to be displayed by default, but complex
1802 ;; widgets to be hidden.
1804 (widget-put (get 'item 'widget-type) :custom-show t)
1805 (widget-put (get 'editable-field 'widget-type)
1806 :custom-show (lambda (widget value)
1807 (let ((pp (pp-to-string value)))
1808 (cond ((string-match "\n" pp)
1809 nil)
1810 ((> (length pp) 40)
1811 nil)
1812 (t t)))))
1813 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1815 ;;; The `custom-manual' Widget.
1817 (define-widget 'custom-manual 'info-link
1818 "Link to the manual entry for this customization option."
1819 :help-echo "Read the manual entry for this option."
1820 :keymap custom-mode-link-map
1821 :follow-link 'mouse-face
1822 :button-face 'custom-link
1823 :mouse-face 'highlight
1824 :pressed-face 'highlight
1825 :tag "Manual")
1827 ;;; The `custom-magic' Widget.
1829 (defgroup custom-magic-faces nil
1830 "Faces used by the magic button."
1831 :group 'custom-faces
1832 :group 'custom-buffer)
1834 (defface custom-invalid '((((class color))
1835 (:foreground "yellow1" :background "red1"))
1837 (:weight bold :slant italic :underline t)))
1838 "Face used when the customize item is invalid."
1839 :group 'custom-magic-faces)
1840 ;; backward-compatibility alias
1841 (put 'custom-invalid-face 'face-alias 'custom-invalid)
1843 (defface custom-rogue '((((class color))
1844 (:foreground "pink" :background "black"))
1846 (:underline t)))
1847 "Face used when the customize item is not defined for customization."
1848 :group 'custom-magic-faces)
1849 ;; backward-compatibility alias
1850 (put 'custom-rogue-face 'face-alias 'custom-rogue)
1852 (defface custom-modified '((((min-colors 88) (class color))
1853 (:foreground "white" :background "blue1"))
1854 (((class color))
1855 (:foreground "white" :background "blue"))
1857 (:slant italic :bold)))
1858 "Face used when the customize item has been modified."
1859 :group 'custom-magic-faces)
1860 ;; backward-compatibility alias
1861 (put 'custom-modified-face 'face-alias 'custom-modified)
1863 (defface custom-set '((((min-colors 88) (class color))
1864 (:foreground "blue1" :background "white"))
1865 (((class color))
1866 (:foreground "blue" :background "white"))
1868 (:slant italic)))
1869 "Face used when the customize item has been set."
1870 :group 'custom-magic-faces)
1871 ;; backward-compatibility alias
1872 (put 'custom-set-face 'face-alias 'custom-set)
1874 (defface custom-changed '((((min-colors 88) (class color))
1875 (:foreground "white" :background "blue1"))
1876 (((class color))
1877 (:foreground "white" :background "blue"))
1879 (:slant italic)))
1880 "Face used when the customize item has been changed."
1881 :group 'custom-magic-faces)
1882 ;; backward-compatibility alias
1883 (put 'custom-changed-face 'face-alias 'custom-changed)
1885 (defface custom-themed '((((min-colors 88) (class color))
1886 (:foreground "white" :background "blue1"))
1887 (((class color))
1888 (:foreground "white" :background "blue"))
1890 (:slant italic)))
1891 "Face used when the customize item has been set by a theme."
1892 :group 'custom-magic-faces)
1894 (defface custom-saved '((t (:underline t)))
1895 "Face used when the customize item has been saved."
1896 :group 'custom-magic-faces)
1897 ;; backward-compatibility alias
1898 (put 'custom-saved-face 'face-alias 'custom-saved)
1900 (defconst custom-magic-alist
1901 '((nil "#" underline "\
1902 UNINITIALIZED, you should not see this.")
1903 (unknown "?" italic "\
1904 UNKNOWN, you should not see this.")
1905 (hidden "-" default "\
1906 HIDDEN, invoke \"Show\" in the previous line to show." "\
1907 group now hidden, invoke \"Show\", above, to show contents.")
1908 (invalid "x" custom-invalid "\
1909 INVALID, the displayed value cannot be set.")
1910 (modified "*" custom-modified "\
1911 EDITED, shown value does not take effect until you set or save it." "\
1912 something in this group has been edited but not set.")
1913 (set "+" custom-set "\
1914 SET for current session only." "\
1915 something in this group has been set but not saved.")
1916 (changed ":" custom-changed "\
1917 CHANGED outside Customize; operating on it here may be unreliable." "\
1918 something in this group has been changed outside customize.")
1919 (saved "!" custom-saved "\
1920 SAVED and set." "\
1921 something in this group has been set and saved.")
1922 (themed "o" custom-themed "\
1923 THEMED." "\
1924 visible group members are all at standard values.")
1925 (rogue "@" custom-rogue "\
1926 NO CUSTOMIZATION DATA; not intended to be customized." "\
1927 something in this group is not prepared for customization.")
1928 (standard " " nil "\
1929 STANDARD." "\
1930 visible group members are all at standard values."))
1931 "Alist of customize option states.
1932 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1934 STATE is one of the following symbols:
1936 `nil'
1937 For internal use, should never occur.
1938 `unknown'
1939 For internal use, should never occur.
1940 `hidden'
1941 This item is not being displayed.
1942 `invalid'
1943 This item is modified, but has an invalid form.
1944 `modified'
1945 This item is modified, and has a valid form.
1946 `set'
1947 This item has been set but not saved.
1948 `changed'
1949 The current value of this item has been changed outside Customize.
1950 `saved'
1951 This item is marked for saving.
1952 `rogue'
1953 This item has no customization information.
1954 `standard'
1955 This item is unchanged from the standard setting.
1957 MAGIC is a string used to present that state.
1959 FACE is a face used to present the state.
1961 ITEM-DESC is a string describing the state for options.
1963 GROUP-DESC is a string describing the state for groups. If this is
1964 left out, ITEM-DESC will be used.
1966 The string %c in either description will be replaced with the
1967 category of the item. These are `group'. `option', and `face'.
1969 The list should be sorted most significant first.")
1971 (defcustom custom-magic-show 'long
1972 "If non-nil, show textual description of the state.
1973 If `long', show a full-line description, not just one word."
1974 :type '(choice (const :tag "no" nil)
1975 (const long)
1976 (other :tag "short" short))
1977 :group 'custom-buffer)
1979 (defcustom custom-magic-show-hidden '(option face)
1980 "Control whether the State button is shown for hidden items.
1981 The value should be a list with the custom categories where the State
1982 button should be visible. Possible categories are `group', `option',
1983 and `face'."
1984 :type '(set (const group) (const option) (const face))
1985 :group 'custom-buffer)
1987 (defcustom custom-magic-show-button nil
1988 "Show a \"magic\" button indicating the state of each customization option."
1989 :type 'boolean
1990 :group 'custom-buffer)
1992 (define-widget 'custom-magic 'default
1993 "Show and manipulate state for a customization option."
1994 :format "%v"
1995 :action 'widget-parent-action
1996 :notify 'ignore
1997 :value-get 'ignore
1998 :value-create 'custom-magic-value-create
1999 :value-delete 'widget-children-value-delete)
2001 (defun widget-magic-mouse-down-action (widget &optional event)
2002 ;; Non-nil unless hidden.
2003 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
2004 :custom-state)
2005 'hidden)))
2007 (defun custom-magic-value-create (widget)
2008 "Create compact status report for WIDGET."
2009 (let* ((parent (widget-get widget :parent))
2010 (state (widget-get parent :custom-state))
2011 (hidden (eq state 'hidden))
2012 (entry (assq state custom-magic-alist))
2013 (magic (nth 1 entry))
2014 (face (nth 2 entry))
2015 (category (widget-get parent :custom-category))
2016 (text (or (and (eq category 'group)
2017 (nth 4 entry))
2018 (nth 3 entry)))
2019 (form (widget-get parent :custom-form))
2020 children)
2021 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
2022 (setq text (concat (match-string 1 text)
2023 (symbol-name category)
2024 (match-string 2 text))))
2025 (when (and custom-magic-show
2026 (or (not hidden)
2027 (memq category custom-magic-show-hidden)))
2028 (insert " ")
2029 (when (and (eq category 'group)
2030 (not (and (eq custom-buffer-style 'links)
2031 (> (widget-get parent :custom-level) 1))))
2032 (insert-char ?\ (* custom-buffer-indent
2033 (widget-get parent :custom-level))))
2034 (push (widget-create-child-and-convert
2035 widget 'choice-item
2036 :help-echo "Change the state of this item."
2037 :format (if hidden "%t" "%[%t%]")
2038 :button-prefix 'widget-push-button-prefix
2039 :button-suffix 'widget-push-button-suffix
2040 :mouse-down-action 'widget-magic-mouse-down-action
2041 :tag "State")
2042 children)
2043 (insert ": ")
2044 (let ((start (point)))
2045 (if (eq custom-magic-show 'long)
2046 (insert text)
2047 (insert (symbol-name state)))
2048 (cond ((eq form 'lisp)
2049 (insert " (lisp)"))
2050 ((eq form 'mismatch)
2051 (insert " (mismatch)")))
2052 (put-text-property start (point) 'face 'custom-state))
2053 (insert "\n"))
2054 (when (and (eq category 'group)
2055 (not (and (eq custom-buffer-style 'links)
2056 (> (widget-get parent :custom-level) 1))))
2057 (insert-char ?\ (* custom-buffer-indent
2058 (widget-get parent :custom-level))))
2059 (when custom-magic-show-button
2060 (when custom-magic-show
2061 (let ((indent (widget-get parent :indent)))
2062 (when indent
2063 (insert-char ? indent))))
2064 (push (widget-create-child-and-convert
2065 widget 'choice-item
2066 :mouse-down-action 'widget-magic-mouse-down-action
2067 :button-face face
2068 :button-prefix ""
2069 :button-suffix ""
2070 :help-echo "Change the state."
2071 :format (if hidden "%t" "%[%t%]")
2072 :tag (if (memq form '(lisp mismatch))
2073 (concat "(" magic ")")
2074 (concat "[" magic "]")))
2075 children)
2076 (insert " "))
2077 (widget-put widget :children children)))
2079 (defun custom-magic-reset (widget)
2080 "Redraw the :custom-magic property of WIDGET."
2081 (let ((magic (widget-get widget :custom-magic)))
2082 (widget-value-set magic (widget-value magic))))
2084 ;;; The `custom' Widget.
2086 (defface custom-button
2087 '((((type x w32 mac) (class color)) ; Like default modeline
2088 (:box (:line-width 2 :style released-button)
2089 :background "lightgrey" :foreground "black"))
2091 nil))
2092 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2093 :version "21.1"
2094 :group 'custom-faces)
2095 ;; backward-compatibility alias
2096 (put 'custom-button-face 'face-alias 'custom-button)
2098 (defface custom-button-mouse
2099 '((((type x w32 mac) (class color))
2100 (:box (:line-width 2 :style released-button)
2101 :background "grey90" :foreground "black"))
2103 nil))
2104 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2105 :version "22.1"
2106 :group 'custom-faces)
2108 (defface custom-button-unraised
2109 '((t :inherit underline))
2110 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2111 :version "22.1"
2112 :group 'custom-faces)
2114 (setq custom-button
2115 (if custom-raised-buttons 'custom-button 'custom-button-unraised))
2117 (setq custom-button-mouse
2118 (if custom-raised-buttons 'custom-button-mouse 'highlight))
2120 (defface custom-button-pressed
2121 '((((type x w32 mac) (class color))
2122 (:box (:line-width 2 :style pressed-button)
2123 :background "lightgrey" :foreground "black"))
2125 (:inverse-video t)))
2126 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2127 :version "21.1"
2128 :group 'custom-faces)
2129 ;; backward-compatibility alias
2130 (put 'custom-button-pressed-face 'face-alias 'custom-button-pressed)
2132 (defface custom-button-pressed-unraised
2133 '((default :inherit custom-button-unraised)
2134 (((class color) (background light)) :foreground "magenta4")
2135 (((class color) (background dark)) :foreground "violet"))
2136 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2137 :version "22.1"
2138 :group 'custom-faces)
2140 (setq custom-button-pressed
2141 (if custom-raised-buttons
2142 'custom-button-pressed
2143 'custom-button-pressed-unraised))
2145 (defface custom-documentation '((t nil))
2146 "Face used for documentation strings in customization buffers."
2147 :group 'custom-faces)
2148 ;; backward-compatibility alias
2149 (put 'custom-documentation-face 'face-alias 'custom-documentation)
2151 (defface custom-state '((((class color)
2152 (background dark))
2153 (:foreground "lime green"))
2154 (((class color)
2155 (background light))
2156 (:foreground "dark green"))
2157 (t nil))
2158 "Face used for State descriptions in the customize buffer."
2159 :group 'custom-faces)
2160 ;; backward-compatibility alias
2161 (put 'custom-state-face 'face-alias 'custom-state)
2163 (defface custom-link
2164 '((t :inherit link))
2165 "Face for links in customization buffers."
2166 :version "22.1"
2167 :group 'custom-faces)
2169 (define-widget 'custom 'default
2170 "Customize a user option."
2171 :format "%v"
2172 :convert-widget 'custom-convert-widget
2173 :notify 'custom-notify
2174 :custom-prefix ""
2175 :custom-level 1
2176 :custom-state 'hidden
2177 :documentation-property 'widget-subclass-responsibility
2178 :value-create 'widget-subclass-responsibility
2179 :value-delete 'widget-children-value-delete
2180 :value-get 'widget-value-value-get
2181 :validate 'widget-children-validate
2182 :match (lambda (widget value) (symbolp value)))
2184 (defun custom-convert-widget (widget)
2185 "Initialize :value and :tag from :args in WIDGET."
2186 (let ((args (widget-get widget :args)))
2187 (when args
2188 (widget-put widget :value (widget-apply widget
2189 :value-to-internal (car args)))
2190 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
2191 (widget-put widget :args nil)))
2192 widget)
2194 (defun custom-notify (widget &rest args)
2195 "Keep track of changes."
2196 (let ((state (widget-get widget :custom-state)))
2197 (unless (eq state 'modified)
2198 (unless (memq state '(nil unknown hidden))
2199 (widget-put widget :custom-state 'modified))
2200 (custom-magic-reset widget)
2201 (apply 'widget-default-notify widget args))))
2203 (defun custom-redraw (widget)
2204 "Redraw WIDGET with current settings."
2205 (let ((line (count-lines (point-min) (point)))
2206 (column (current-column))
2207 (pos (point))
2208 (from (marker-position (widget-get widget :from)))
2209 (to (marker-position (widget-get widget :to))))
2210 (save-excursion
2211 (widget-value-set widget (widget-value widget))
2212 (custom-redraw-magic widget))
2213 (when (and (>= pos from) (<= pos to))
2214 (condition-case nil
2215 (progn
2216 (if (> column 0)
2217 (goto-line line)
2218 (goto-line (1+ line)))
2219 (move-to-column column))
2220 (error nil)))))
2222 (defun custom-redraw-magic (widget)
2223 "Redraw WIDGET state with current settings."
2224 (while widget
2225 (let ((magic (widget-get widget :custom-magic)))
2226 (cond (magic
2227 (widget-value-set magic (widget-value magic))
2228 (when (setq widget (widget-get widget :group))
2229 (custom-group-state-update widget)))
2231 (setq widget nil)))))
2232 (widget-setup))
2234 (defun custom-show (widget value)
2235 "Non-nil if WIDGET should be shown with VALUE by default."
2236 (let ((show (widget-get widget :custom-show)))
2237 (cond ((null show)
2238 nil)
2239 ((eq t show)
2242 (funcall show widget value)))))
2244 (defun custom-load-widget (widget)
2245 "Load all dependencies for WIDGET."
2246 (custom-load-symbol (widget-value widget)))
2248 (defun custom-unloaded-symbol-p (symbol)
2249 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2250 (let ((found nil)
2251 (loads (get symbol 'custom-loads))
2252 load)
2253 (while loads
2254 (setq load (car loads)
2255 loads (cdr loads))
2256 (cond ((symbolp load)
2257 (unless (featurep load)
2258 (setq found t)))
2259 ((assoc load load-history))
2260 ((assoc (locate-library load) load-history)
2261 (message nil))
2263 (setq found t))))
2264 found))
2266 (defun custom-unloaded-widget-p (widget)
2267 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2268 (custom-unloaded-symbol-p (widget-value widget)))
2270 (defun custom-toggle-hide (widget)
2271 "Toggle visibility of WIDGET."
2272 (custom-load-widget widget)
2273 (let ((state (widget-get widget :custom-state)))
2274 (cond ((memq state '(invalid modified))
2275 (error "There are unset changes"))
2276 ((eq state 'hidden)
2277 (widget-put widget :custom-state 'unknown))
2279 (widget-put widget :documentation-shown nil)
2280 (widget-put widget :custom-state 'hidden)))
2281 (custom-redraw widget)
2282 (widget-setup)))
2284 (defun custom-toggle-parent (widget &rest ignore)
2285 "Toggle visibility of parent of WIDGET."
2286 (custom-toggle-hide (widget-get widget :parent)))
2288 (defun custom-add-see-also (widget &optional prefix)
2289 "Add `See also ...' to WIDGET if there are any links.
2290 Insert PREFIX first if non-nil."
2291 (let* ((symbol (widget-get widget :value))
2292 (links (get symbol 'custom-links))
2293 (many (> (length links) 2))
2294 (buttons (widget-get widget :buttons))
2295 (indent (widget-get widget :indent)))
2296 (when links
2297 (when indent
2298 (insert-char ?\ indent))
2299 (when prefix
2300 (insert prefix))
2301 (insert "See also ")
2302 (while links
2303 (push (widget-create-child-and-convert
2304 widget (car links)
2305 :button-face 'custom-link
2306 :mouse-face 'highlight
2307 :pressed-face 'highlight)
2308 buttons)
2309 (setq links (cdr links))
2310 (cond ((null links)
2311 (insert ".\n"))
2312 ((null (cdr links))
2313 (if many
2314 (insert ", and ")
2315 (insert " and ")))
2317 (insert ", "))))
2318 (widget-put widget :buttons buttons))))
2320 (defun custom-add-parent-links (widget &optional initial-string)
2321 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2322 The value is non-nil if any parents were found.
2323 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2324 (let ((name (widget-value widget))
2325 (type (widget-type widget))
2326 (buttons (widget-get widget :buttons))
2327 (start (point))
2328 (parents nil))
2329 (insert (or initial-string "Parent groups:"))
2330 (mapatoms (lambda (symbol)
2331 (when (member (list name type) (get symbol 'custom-group))
2332 (insert " ")
2333 (push (widget-create-child-and-convert
2334 widget 'custom-group-link
2335 :tag (custom-unlispify-tag-name symbol)
2336 symbol)
2337 buttons)
2338 (setq parents (cons symbol parents)))))
2339 (and (null (get name 'custom-links)) ;No links of its own.
2340 (= (length parents) 1) ;A single parent.
2341 (let* ((links (delq nil (mapcar (lambda (w)
2342 (unless (eq (widget-type w)
2343 'custom-group-link)
2345 (get (car parents) 'custom-links))))
2346 (many (> (length links) 2)))
2347 (when links
2348 (insert "\nParent documentation: ")
2349 (while links
2350 (push (widget-create-child-and-convert
2351 widget (car links)
2352 :button-face 'custom-link
2353 :mouse-face 'highlight
2354 :pressed-face 'highlight)
2355 buttons)
2356 (setq links (cdr links))
2357 (cond ((null links)
2358 (insert ".\n"))
2359 ((null (cdr links))
2360 (if many
2361 (insert ", and ")
2362 (insert " and ")))
2364 (insert ", ")))))))
2365 (if parents
2366 (insert "\n")
2367 (delete-region start (point)))
2368 (widget-put widget :buttons buttons)
2369 parents))
2371 ;;; The `custom-comment' Widget.
2373 ;; like the editable field
2374 (defface custom-comment '((((type tty))
2375 :background "yellow3"
2376 :foreground "black")
2377 (((class grayscale color)
2378 (background light))
2379 :background "gray85")
2380 (((class grayscale color)
2381 (background dark))
2382 :background "dim gray")
2384 :slant italic))
2385 "Face used for comments on variables or faces"
2386 :version "21.1"
2387 :group 'custom-faces)
2388 ;; backward-compatibility alias
2389 (put 'custom-comment-face 'face-alias 'custom-comment)
2391 ;; like font-lock-comment-face
2392 (defface custom-comment-tag
2393 '((((class color) (background dark)) (:foreground "gray80"))
2394 (((class color) (background light)) (:foreground "blue4"))
2395 (((class grayscale) (background light))
2396 (:foreground "DimGray" :weight bold :slant italic))
2397 (((class grayscale) (background dark))
2398 (:foreground "LightGray" :weight bold :slant italic))
2399 (t (:weight bold)))
2400 "Face used for variables or faces comment tags"
2401 :group 'custom-faces)
2402 ;; backward-compatibility alias
2403 (put 'custom-comment-tag-face 'face-alias 'custom-comment-tag)
2405 (define-widget 'custom-comment 'string
2406 "User comment."
2407 :tag "Comment"
2408 :help-echo "Edit a comment here."
2409 :sample-face 'custom-comment-tag-face
2410 :value-face 'custom-comment-face
2411 :shown nil
2412 :create 'custom-comment-create)
2414 (defun custom-comment-create (widget)
2415 (let* ((null-comment (equal "" (widget-value widget))))
2416 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2417 (not null-comment))
2418 (widget-default-create widget)
2419 ;; `widget-default-delete' expects markers in these slots --
2420 ;; maybe it shouldn't.
2421 (widget-put widget :from (point-marker))
2422 (widget-put widget :to (point-marker)))))
2424 (defun custom-comment-hide (widget)
2425 (widget-put (widget-get widget :parent) :comment-shown nil))
2427 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2428 ;; the global custom one
2429 (defun custom-comment-show (widget)
2430 (widget-put widget :comment-shown t)
2431 (custom-redraw widget)
2432 (widget-setup))
2434 (defun custom-comment-invisible-p (widget)
2435 (let ((val (widget-value (widget-get widget :comment-widget))))
2436 (and (equal "" val)
2437 (not (widget-get widget :comment-shown)))))
2439 ;;; The `custom-variable' Widget.
2441 ;; When this was underlined blue, users confused it with a
2442 ;; Mosaic-style hyperlink...
2443 (defface custom-variable-tag
2444 `((((class color)
2445 (background dark))
2446 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
2447 (((min-colors 88) (class color)
2448 (background light))
2449 (:foreground "blue1" :weight bold :height 1.2 :inherit variable-pitch))
2450 (((class color)
2451 (background light))
2452 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
2453 (t (:weight bold)))
2454 "Face used for unpushable variable tags."
2455 :group 'custom-faces)
2456 ;; backward-compatibility alias
2457 (put 'custom-variable-tag-face 'face-alias 'custom-variable-tag)
2459 (defface custom-variable-button '((t (:underline t :weight bold)))
2460 "Face used for pushable variable tags."
2461 :group 'custom-faces)
2462 ;; backward-compatibility alias
2463 (put 'custom-variable-button-face 'face-alias 'custom-variable-button)
2465 (defcustom custom-variable-default-form 'edit
2466 "Default form of displaying variable values."
2467 :type '(choice (const edit)
2468 (const lisp))
2469 :group 'custom-buffer
2470 :version "20.3")
2472 (defun custom-variable-documentation (variable)
2473 "Return documentation of VARIABLE for use in Custom buffer.
2474 Normally just return the docstring. But if VARIABLE automatically
2475 becomes buffer local when set, append a message to that effect."
2476 (if (and (local-variable-if-set-p variable)
2477 (or (not (local-variable-p variable))
2478 (with-temp-buffer
2479 (local-variable-if-set-p variable))))
2480 (concat (documentation-property variable 'variable-documentation)
2482 This variable automatically becomes buffer-local when set outside Custom.
2483 However, setting it through Custom sets the default value.")
2484 (documentation-property variable 'variable-documentation)))
2486 (define-widget 'custom-variable 'custom
2487 "Customize variable."
2488 :format "%v"
2489 :help-echo "Set or reset this variable."
2490 :documentation-property #'custom-variable-documentation
2491 :custom-category 'option
2492 :custom-state nil
2493 :custom-menu 'custom-variable-menu-create
2494 :custom-form nil ; defaults to value of `custom-variable-default-form'
2495 :value-create 'custom-variable-value-create
2496 :action 'custom-variable-action
2497 :custom-set 'custom-variable-set
2498 :custom-save 'custom-variable-save
2499 :custom-reset-current 'custom-redraw
2500 :custom-reset-saved 'custom-variable-reset-saved
2501 :custom-reset-standard 'custom-variable-reset-standard
2502 :custom-standard-value 'custom-variable-standard-value)
2504 (defun custom-variable-type (symbol)
2505 "Return a widget suitable for editing the value of SYMBOL.
2506 If SYMBOL has a `custom-type' property, use that.
2507 Otherwise, look up symbol in `custom-guess-type-alist'."
2508 (let* ((type (or (get symbol 'custom-type)
2509 (and (not (get symbol 'standard-value))
2510 (custom-guess-type symbol))
2511 'sexp))
2512 (options (get symbol 'custom-options))
2513 (tmp (if (listp type)
2514 (copy-sequence type)
2515 (list type))))
2516 (when options
2517 (widget-put tmp :options options))
2518 tmp))
2520 (defun custom-variable-value-create (widget)
2521 "Here is where you edit the variable's value."
2522 (custom-load-widget widget)
2523 (unless (widget-get widget :custom-form)
2524 (widget-put widget :custom-form custom-variable-default-form))
2525 (let* ((buttons (widget-get widget :buttons))
2526 (children (widget-get widget :children))
2527 (form (widget-get widget :custom-form))
2528 (state (widget-get widget :custom-state))
2529 (symbol (widget-get widget :value))
2530 (tag (widget-get widget :tag))
2531 (type (custom-variable-type symbol))
2532 (conv (widget-convert type))
2533 (get (or (get symbol 'custom-get) 'default-value))
2534 (prefix (widget-get widget :custom-prefix))
2535 (last (widget-get widget :custom-last))
2536 (value (if (default-boundp symbol)
2537 (funcall get symbol)
2538 (widget-get conv :value))))
2539 ;; If the widget is new, the child determines whether it is hidden.
2540 (cond (state)
2541 ((custom-show type value)
2542 (setq state 'unknown))
2544 (setq state 'hidden)))
2545 ;; If we don't know the state, see if we need to edit it in lisp form.
2546 (when (eq state 'unknown)
2547 (unless (widget-apply conv :match value)
2548 ;; (widget-apply (widget-convert type) :match value)
2549 (setq form 'mismatch)))
2550 ;; Now we can create the child widget.
2551 (cond ((eq custom-buffer-style 'tree)
2552 (insert prefix (if last " `--- " " |--- "))
2553 (push (widget-create-child-and-convert
2554 widget 'custom-browse-variable-tag)
2555 buttons)
2556 (insert " " tag "\n")
2557 (widget-put widget :buttons buttons))
2558 ((eq state 'hidden)
2559 ;; Indicate hidden value.
2560 (push (widget-create-child-and-convert
2561 widget 'item
2562 :format "%{%t%}: "
2563 :sample-face 'custom-variable-tag-face
2564 :tag tag
2565 :parent widget)
2566 buttons)
2567 (push (widget-create-child-and-convert
2568 widget 'visibility
2569 :help-echo "Show the value of this option."
2570 :off "Show Value"
2571 :action 'custom-toggle-parent
2572 nil)
2573 buttons))
2574 ((memq form '(lisp mismatch))
2575 ;; In lisp mode edit the saved value when possible.
2576 (let* ((value (cond ((get symbol 'saved-value)
2577 (car (get symbol 'saved-value)))
2578 ((get symbol 'standard-value)
2579 (car (get symbol 'standard-value)))
2580 ((default-boundp symbol)
2581 (custom-quote (funcall get symbol)))
2583 (custom-quote (widget-get conv :value))))))
2584 (insert (symbol-name symbol) ": ")
2585 (push (widget-create-child-and-convert
2586 widget 'visibility
2587 :help-echo "Hide the value of this option."
2588 :on "Hide Value"
2589 :off "Show Value"
2590 :action 'custom-toggle-parent
2592 buttons)
2593 (insert " ")
2594 (push (widget-create-child-and-convert
2595 widget 'sexp
2596 :button-face 'custom-variable-button-face
2597 :format "%v"
2598 :tag (symbol-name symbol)
2599 :parent widget
2600 :value value)
2601 children)))
2603 ;; Edit mode.
2604 (let* ((format (widget-get type :format))
2605 tag-format value-format)
2606 (unless (string-match ":" format)
2607 (error "Bad format"))
2608 (setq tag-format (substring format 0 (match-end 0)))
2609 (setq value-format (substring format (match-end 0)))
2610 (push (widget-create-child-and-convert
2611 widget 'item
2612 :format tag-format
2613 :action 'custom-tag-action
2614 :help-echo "Change value of this option."
2615 :mouse-down-action 'custom-tag-mouse-down-action
2616 :button-face 'custom-variable-button-face
2617 :sample-face 'custom-variable-tag-face
2618 tag)
2619 buttons)
2620 (insert " ")
2621 (push (widget-create-child-and-convert
2622 widget 'visibility
2623 :help-echo "Hide the value of this option."
2624 :on "Hide Value"
2625 :off "Show Value"
2626 :action 'custom-toggle-parent
2628 buttons)
2629 (push (widget-create-child-and-convert
2630 widget type
2631 :format value-format
2632 :value value)
2633 children))))
2634 (unless (eq custom-buffer-style 'tree)
2635 (unless (eq (preceding-char) ?\n)
2636 (widget-insert "\n"))
2637 ;; Create the magic button.
2638 (let ((magic (widget-create-child-and-convert
2639 widget 'custom-magic nil)))
2640 (widget-put widget :custom-magic magic)
2641 (push magic buttons))
2642 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2643 ;; before the call to `widget-default-format-handler'. Otherwise, I
2644 ;; loose my current `buttons'. This function shouldn't be called like
2645 ;; this anyway. The doc string widget should be added like the others.
2646 ;; --dv
2647 (widget-put widget :buttons buttons)
2648 (insert "\n")
2649 ;; Insert documentation.
2650 (widget-default-format-handler widget ?h)
2652 ;; The comment field
2653 (unless (eq state 'hidden)
2654 (let* ((comment (get symbol 'variable-comment))
2655 (comment-widget
2656 (widget-create-child-and-convert
2657 widget 'custom-comment
2658 :parent widget
2659 :value (or comment ""))))
2660 (widget-put widget :comment-widget comment-widget)
2661 ;; Don't push it !!! Custom assumes that the first child is the
2662 ;; value one.
2663 (setq children (append children (list comment-widget)))))
2664 ;; Update the rest of the properties properties.
2665 (widget-put widget :custom-form form)
2666 (widget-put widget :children children)
2667 ;; Now update the state.
2668 (if (eq state 'hidden)
2669 (widget-put widget :custom-state state)
2670 (custom-variable-state-set widget))
2671 ;; See also.
2672 (unless (eq state 'hidden)
2673 (when (eq (widget-get widget :custom-level) 1)
2674 (custom-add-parent-links widget))
2675 (custom-add-see-also widget)))))
2677 (defun custom-tag-action (widget &rest args)
2678 "Pass :action to first child of WIDGET's parent."
2679 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2680 :action args))
2682 (defun custom-tag-mouse-down-action (widget &rest args)
2683 "Pass :mouse-down-action to first child of WIDGET's parent."
2684 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2685 :mouse-down-action args))
2687 (defun custom-variable-state-set (widget)
2688 "Set the state of WIDGET."
2689 (let* ((symbol (widget-value widget))
2690 (get (or (get symbol 'custom-get) 'default-value))
2691 (value (if (default-boundp symbol)
2692 (funcall get symbol)
2693 (widget-get widget :value)))
2694 (comment (get symbol 'variable-comment))
2696 temp
2697 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2698 (setq temp
2699 (get symbol 'customized-variable-comment))
2700 (or tmp temp))
2701 (if (condition-case nil
2702 (and (equal value (eval (car tmp)))
2703 (equal comment temp))
2704 (error nil))
2705 'set
2706 'changed))
2707 ((progn (setq tmp (get symbol 'theme-value))
2708 (setq temp (get symbol 'saved-variable-comment))
2709 (or tmp temp))
2710 (if (condition-case nil
2711 (and (equal comment temp)
2712 (equal value
2713 (eval
2714 (car (custom-variable-theme-value
2715 symbol)))))
2716 (error nil))
2717 (cond
2718 ((eq (caar tmp) 'user) 'saved)
2719 ((eq (caar tmp) 'changed)
2720 (if (condition-case nil
2721 (and (null comment)
2722 (equal value
2723 (eval
2724 (car (get symbol 'standard-value)))))
2725 (error nil))
2726 ;; The value was originally set outside
2727 ;; custom, but it was set to the standard
2728 ;; value (probably an autoloaded defcustom).
2729 'standard
2730 'changed))
2731 (t 'themed))
2732 'changed))
2733 ((setq tmp (get symbol 'standard-value))
2734 (if (condition-case nil
2735 (and (equal value (eval (car tmp)))
2736 (equal comment nil))
2737 (error nil))
2738 'standard
2739 'changed))
2740 (t 'rogue))))
2741 (widget-put widget :custom-state state)))
2743 (defun custom-variable-standard-value (widget)
2744 (get (widget-value widget) 'standard-value))
2746 (defvar custom-variable-menu
2747 `(("Set for Current Session" custom-variable-set
2748 (lambda (widget)
2749 (eq (widget-get widget :custom-state) 'modified)))
2750 ,@(when (or custom-file user-init-file)
2751 '(("Save for Future Sessions" custom-variable-save
2752 (lambda (widget)
2753 (memq (widget-get widget :custom-state)
2754 '(modified set changed rogue))))))
2755 ("Undo Edits" custom-redraw
2756 (lambda (widget)
2757 (and (default-boundp (widget-value widget))
2758 (memq (widget-get widget :custom-state) '(modified changed)))))
2759 ("Reset to Saved" custom-variable-reset-saved
2760 (lambda (widget)
2761 (and (or (get (widget-value widget) 'saved-value)
2762 (get (widget-value widget) 'saved-variable-comment))
2763 (memq (widget-get widget :custom-state)
2764 '(modified set changed rogue)))))
2765 ,@(when (or custom-file user-init-file)
2766 '(("Erase Customization" custom-variable-reset-standard
2767 (lambda (widget)
2768 (and (get (widget-value widget) 'standard-value)
2769 (memq (widget-get widget :custom-state)
2770 '(modified set changed saved rogue)))))))
2771 ("Set to Backup Value" custom-variable-reset-backup
2772 (lambda (widget)
2773 (get (widget-value widget) 'backup-value)))
2774 ("---" ignore ignore)
2775 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2776 ("---" ignore ignore)
2777 ("Show Current Value" custom-variable-edit
2778 (lambda (widget)
2779 (eq (widget-get widget :custom-form) 'lisp)))
2780 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2781 (lambda (widget)
2782 (eq (widget-get widget :custom-form) 'edit))))
2783 "Alist of actions for the `custom-variable' widget.
2784 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2785 the menu entry, ACTION is the function to call on the widget when the
2786 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2787 widget as an argument, and returns non-nil if ACTION is valid on that
2788 widget. If FILTER is nil, ACTION is always valid.")
2790 (defun custom-variable-action (widget &optional event)
2791 "Show the menu for `custom-variable' WIDGET.
2792 Optional EVENT is the location for the menu."
2793 (if (eq (widget-get widget :custom-state) 'hidden)
2794 (custom-toggle-hide widget)
2795 (unless (eq (widget-get widget :custom-state) 'modified)
2796 (custom-variable-state-set widget))
2797 (custom-redraw-magic widget)
2798 (let* ((completion-ignore-case t)
2799 (answer (widget-choose (concat "Operation on "
2800 (custom-unlispify-tag-name
2801 (widget-get widget :value)))
2802 (custom-menu-filter custom-variable-menu
2803 widget)
2804 event)))
2805 (if answer
2806 (funcall answer widget)))))
2808 (defun custom-variable-edit (widget)
2809 "Edit value of WIDGET."
2810 (widget-put widget :custom-state 'unknown)
2811 (widget-put widget :custom-form 'edit)
2812 (custom-redraw widget))
2814 (defun custom-variable-edit-lisp (widget)
2815 "Edit the Lisp representation of the value of WIDGET."
2816 (widget-put widget :custom-state 'unknown)
2817 (widget-put widget :custom-form 'lisp)
2818 (custom-redraw widget))
2820 (defun custom-variable-set (widget)
2821 "Set the current value for the variable being edited by WIDGET."
2822 (let* ((form (widget-get widget :custom-form))
2823 (state (widget-get widget :custom-state))
2824 (child (car (widget-get widget :children)))
2825 (symbol (widget-value widget))
2826 (set (or (get symbol 'custom-set) 'set-default))
2827 (comment-widget (widget-get widget :comment-widget))
2828 (comment (widget-value comment-widget))
2829 val)
2830 (cond ((eq state 'hidden)
2831 (error "Cannot set hidden variable"))
2832 ((setq val (widget-apply child :validate))
2833 (goto-char (widget-get val :from))
2834 (error "%s" (widget-get val :error)))
2835 ((memq form '(lisp mismatch))
2836 (when (equal comment "")
2837 (setq comment nil)
2838 ;; Make the comment invisible by hand if it's empty
2839 (custom-comment-hide comment-widget))
2840 (custom-variable-backup-value widget)
2841 (custom-push-theme 'theme-value symbol 'user
2842 'set (custom-quote (widget-value child)))
2843 (funcall set symbol (eval (setq val (widget-value child))))
2844 (put symbol 'customized-value (list val))
2845 (put symbol 'variable-comment comment)
2846 (put symbol 'customized-variable-comment comment))
2848 (when (equal comment "")
2849 (setq comment nil)
2850 ;; Make the comment invisible by hand if it's empty
2851 (custom-comment-hide comment-widget))
2852 (custom-variable-backup-value widget)
2853 (custom-push-theme 'theme-value symbol 'user
2854 'set (custom-quote (widget-value child)))
2855 (funcall set symbol (setq val (widget-value child)))
2856 (put symbol 'customized-value (list (custom-quote val)))
2857 (put symbol 'variable-comment comment)
2858 (put symbol 'customized-variable-comment comment)))
2859 (custom-variable-state-set widget)
2860 (custom-redraw-magic widget)))
2862 (defun custom-variable-save (widget)
2863 "Set and save the value for the variable being edited by WIDGET."
2864 (let* ((form (widget-get widget :custom-form))
2865 (state (widget-get widget :custom-state))
2866 (child (car (widget-get widget :children)))
2867 (symbol (widget-value widget))
2868 (set (or (get symbol 'custom-set) 'set-default))
2869 (comment-widget (widget-get widget :comment-widget))
2870 (comment (widget-value comment-widget))
2871 val)
2872 (cond ((eq state 'hidden)
2873 (error "Cannot set hidden variable"))
2874 ((setq val (widget-apply child :validate))
2875 (goto-char (widget-get val :from))
2876 (error "Saving %s: %s" symbol (widget-get val :error)))
2877 ((memq form '(lisp mismatch))
2878 (when (equal comment "")
2879 (setq comment nil)
2880 ;; Make the comment invisible by hand if it's empty
2881 (custom-comment-hide comment-widget))
2882 (put symbol 'saved-value (list (widget-value child)))
2883 (custom-push-theme 'theme-value symbol 'user
2884 'set (custom-quote (widget-value child)))
2885 (funcall set symbol (eval (widget-value child)))
2886 (put symbol 'variable-comment comment)
2887 (put symbol 'saved-variable-comment comment))
2889 (when (equal comment "")
2890 (setq comment nil)
2891 ;; Make the comment invisible by hand if it's empty
2892 (custom-comment-hide comment-widget))
2893 (put symbol 'saved-value
2894 (list (custom-quote (widget-value child))))
2895 (custom-push-theme 'theme-value symbol 'user
2896 'set (custom-quote (widget-value child)))
2897 (funcall set symbol (widget-value child))
2898 (put symbol 'variable-comment comment)
2899 (put symbol 'saved-variable-comment comment)))
2900 (put symbol 'customized-value nil)
2901 (put symbol 'customized-variable-comment nil)
2902 (custom-save-all)
2903 (custom-variable-state-set widget)
2904 (custom-redraw-magic widget)))
2906 (defun custom-variable-reset-saved (widget)
2907 "Restore the saved value for the variable being edited by WIDGET.
2908 This also updates the buffer to show that value.
2909 The value that was current before this operation
2910 becomes the backup value, so you can get it again."
2911 (let* ((symbol (widget-value widget))
2912 (set (or (get symbol 'custom-set) 'set-default))
2913 (value (get symbol 'saved-value))
2914 (comment (get symbol 'saved-variable-comment)))
2915 (cond ((or value comment)
2916 (put symbol 'variable-comment comment)
2917 (custom-variable-backup-value widget)
2918 (custom-push-theme 'theme-value symbol 'user 'set (car-safe value))
2919 (condition-case nil
2920 (funcall set symbol (eval (car value)))
2921 (error nil)))
2923 (error "No saved value for %s" symbol)))
2924 (put symbol 'customized-value nil)
2925 (put symbol 'customized-variable-comment nil)
2926 (widget-put widget :custom-state 'unknown)
2927 ;; This call will possibly make the comment invisible
2928 (custom-redraw widget)))
2930 (defun custom-variable-reset-standard (widget)
2931 "Restore the standard setting for the variable being edited by WIDGET.
2932 This operation eliminates any saved setting for the variable,
2933 restoring it to the state of a variable that has never been customized.
2934 The value that was current before this operation
2935 becomes the backup value, so you can get it again."
2936 (let* ((symbol (widget-value widget)))
2937 (if (get symbol 'standard-value)
2938 (custom-variable-backup-value widget)
2939 (error "No standard setting known for %S" symbol))
2940 (put symbol 'variable-comment nil)
2941 (put symbol 'customized-value nil)
2942 (put symbol 'customized-variable-comment nil)
2943 (custom-push-theme 'theme-value symbol 'user 'reset)
2944 (custom-theme-recalc-variable symbol)
2945 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2946 (put symbol 'saved-value nil)
2947 (put symbol 'saved-variable-comment nil)
2948 (custom-save-all))
2949 (widget-put widget :custom-state 'unknown)
2950 ;; This call will possibly make the comment invisible
2951 (custom-redraw widget)))
2953 (defun custom-variable-backup-value (widget)
2954 "Back up the current value for WIDGET's variable.
2955 The backup value is kept in the car of the `backup-value' property."
2956 (let* ((symbol (widget-value widget))
2957 (get (or (get symbol 'custom-get) 'default-value))
2958 (type (custom-variable-type symbol))
2959 (conv (widget-convert type))
2960 (value (if (default-boundp symbol)
2961 (funcall get symbol)
2962 (widget-get conv :value))))
2963 (put symbol 'backup-value (list value))))
2965 (defun custom-variable-reset-backup (widget)
2966 "Restore the backup value for the variable being edited by WIDGET.
2967 The value that was current before this operation
2968 becomes the backup value, so you can use this operation repeatedly
2969 to switch between two values."
2970 (let* ((symbol (widget-value widget))
2971 (set (or (get symbol 'custom-set) 'set-default))
2972 (value (get symbol 'backup-value))
2973 (comment-widget (widget-get widget :comment-widget))
2974 (comment (widget-value comment-widget)))
2975 (if value
2976 (progn
2977 (custom-variable-backup-value widget)
2978 (custom-push-theme 'theme-value symbol 'user 'set value)
2979 (condition-case nil
2980 (funcall set symbol (car value))
2981 (error nil)))
2982 (error "No backup value for %s" symbol))
2983 (put symbol 'customized-value (list (car value)))
2984 (put symbol 'variable-comment comment)
2985 (put symbol 'customized-variable-comment comment)
2986 (custom-variable-state-set widget)
2987 ;; This call will possibly make the comment invisible
2988 (custom-redraw widget)))
2990 ;;; The `custom-face-edit' Widget.
2992 (define-widget 'custom-face-edit 'checklist
2993 "Edit face attributes."
2994 :format "%t: %v"
2995 :tag "Attributes"
2996 :extra-offset 13
2997 :button-args '(:help-echo "Control whether this attribute has any effect.")
2998 :value-to-internal 'custom-face-edit-fix-value
2999 :match (lambda (widget value)
3000 (widget-checklist-match widget
3001 (custom-face-edit-fix-value widget value)))
3002 :convert-widget 'custom-face-edit-convert-widget
3003 :args (mapcar (lambda (att)
3004 (list 'group
3005 :inline t
3006 :sibling-args (widget-get (nth 1 att) :sibling-args)
3007 (list 'const :format "" :value (nth 0 att))
3008 (nth 1 att)))
3009 custom-face-attributes))
3011 (defun custom-face-edit-fix-value (widget value)
3012 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3013 Also change :reverse-video to :inverse-video."
3014 (if (listp value)
3015 (let (result)
3016 (while value
3017 (let ((key (car value))
3018 (val (car (cdr value))))
3019 (cond ((eq key :italic)
3020 (push :slant result)
3021 (push (if val 'italic 'normal) result))
3022 ((eq key :bold)
3023 (push :weight result)
3024 (push (if val 'bold 'normal) result))
3025 ((eq key :reverse-video)
3026 (push :inverse-video result)
3027 (push val result))
3029 (push key result)
3030 (push val result))))
3031 (setq value (cdr (cdr value))))
3032 (setq result (nreverse result))
3033 result)
3034 value))
3036 (defun custom-face-edit-convert-widget (widget)
3037 "Convert :args as widget types in WIDGET."
3038 (widget-put
3039 widget
3040 :args (mapcar (lambda (arg)
3041 (widget-convert arg
3042 :deactivate 'custom-face-edit-deactivate
3043 :activate 'custom-face-edit-activate
3044 :delete 'custom-face-edit-delete))
3045 (widget-get widget :args)))
3046 widget)
3048 (defun custom-face-edit-deactivate (widget)
3049 "Make face widget WIDGET inactive for user modifications."
3050 (unless (widget-get widget :inactive)
3051 (let ((tag (custom-face-edit-attribute-tag widget))
3052 (from (copy-marker (widget-get widget :from)))
3053 (value (widget-value widget))
3054 (inhibit-read-only t)
3055 (inhibit-modification-hooks t))
3056 (save-excursion
3057 (goto-char from)
3058 (widget-default-delete widget)
3059 (insert tag ": *\n")
3060 (widget-put widget :inactive
3061 (cons value (cons from (- (point) from))))))))
3063 (defun custom-face-edit-activate (widget)
3064 "Make face widget WIDGET inactive for user modifications."
3065 (let ((inactive (widget-get widget :inactive))
3066 (inhibit-read-only t)
3067 (inhibit-modification-hooks t))
3068 (when (consp inactive)
3069 (save-excursion
3070 (goto-char (car (cdr inactive)))
3071 (delete-region (point) (+ (point) (cdr (cdr inactive))))
3072 (widget-put widget :inactive nil)
3073 (widget-apply widget :create)
3074 (widget-value-set widget (car inactive))
3075 (widget-setup)))))
3077 (defun custom-face-edit-delete (widget)
3078 "Remove WIDGET from the buffer."
3079 (let ((inactive (widget-get widget :inactive))
3080 (inhibit-read-only t)
3081 (inhibit-modification-hooks t))
3082 (if (not inactive)
3083 ;; Widget is alive, we don't have to do anything special
3084 (widget-default-delete widget)
3085 ;; WIDGET is already deleted because we did so to inactivate it;
3086 ;; now just get rid of the label we put in its place.
3087 (delete-region (car (cdr inactive))
3088 (+ (car (cdr inactive)) (cdr (cdr inactive))))
3089 (widget-put widget :inactive nil))))
3092 (defun custom-face-edit-attribute-tag (widget)
3093 "Returns the first :tag property in WIDGET or one of its children."
3094 (let ((tag (widget-get widget :tag)))
3095 (or (and (not (equal tag "")) tag)
3096 (let ((children (widget-get widget :children)))
3097 (while (and (null tag) children)
3098 (setq tag (custom-face-edit-attribute-tag (pop children))))
3099 tag))))
3101 ;;; The `custom-display' Widget.
3103 (define-widget 'custom-display 'menu-choice
3104 "Select a display type."
3105 :tag "Display"
3106 :value t
3107 :help-echo "Specify frames where the face attributes should be used."
3108 :args '((const :tag "all" t)
3109 (const :tag "defaults" default)
3110 (checklist
3111 :offset 0
3112 :extra-offset 9
3113 :args ((group :sibling-args (:help-echo "\
3114 Only match the specified window systems.")
3115 (const :format "Type: "
3116 type)
3117 (checklist :inline t
3118 :offset 0
3119 (const :format "X "
3120 :sibling-args (:help-echo "\
3121 The X11 Window System.")
3123 (const :format "PM "
3124 :sibling-args (:help-echo "\
3125 OS/2 Presentation Manager.")
3127 (const :format "W32 "
3128 :sibling-args (:help-echo "\
3129 Windows NT/9X.")
3130 w32)
3131 (const :format "MAC "
3132 :sibling-args (:help-echo "\
3133 Macintosh OS.")
3134 mac)
3135 (const :format "DOS "
3136 :sibling-args (:help-echo "\
3137 Plain MS-DOS.")
3139 (const :format "TTY%n"
3140 :sibling-args (:help-echo "\
3141 Plain text terminals.")
3142 tty)))
3143 (group :sibling-args (:help-echo "\
3144 Only match the frames with the specified color support.")
3145 (const :format "Class: "
3146 class)
3147 (checklist :inline t
3148 :offset 0
3149 (const :format "Color "
3150 :sibling-args (:help-echo "\
3151 Match color frames.")
3152 color)
3153 (const :format "Grayscale "
3154 :sibling-args (:help-echo "\
3155 Match grayscale frames.")
3156 grayscale)
3157 (const :format "Monochrome%n"
3158 :sibling-args (:help-echo "\
3159 Match frames with no color support.")
3160 mono)))
3161 (group :sibling-args (:help-echo "\
3162 The minimum number of colors the frame should support.")
3163 (const :format "" min-colors)
3164 (integer :tag "Minimum number of colors" ))
3165 (group :sibling-args (:help-echo "\
3166 Only match frames with the specified intensity.")
3167 (const :format "\
3168 Background brightness: "
3169 background)
3170 (checklist :inline t
3171 :offset 0
3172 (const :format "Light "
3173 :sibling-args (:help-echo "\
3174 Match frames with light backgrounds.")
3175 light)
3176 (const :format "Dark\n"
3177 :sibling-args (:help-echo "\
3178 Match frames with dark backgrounds.")
3179 dark)))
3180 (group :sibling-args (:help-echo "\
3181 Only match frames that support the specified face attributes.")
3182 (const :format "Supports attributes:" supports)
3183 (custom-face-edit :inline t :format "%n%v"))))))
3185 ;;; The `custom-face' Widget.
3187 (defface custom-face-tag
3188 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
3189 "Face used for face tags."
3190 :group 'custom-faces)
3191 ;; backward-compatibility alias
3192 (put 'custom-face-tag-face 'face-alias 'custom-face-tag)
3194 (defcustom custom-face-default-form 'selected
3195 "Default form of displaying face definition."
3196 :type '(choice (const all)
3197 (const selected)
3198 (const lisp))
3199 :group 'custom-buffer
3200 :version "20.3")
3202 (define-widget 'custom-face 'custom
3203 "Customize face."
3204 :sample-face 'custom-face-tag-face
3205 :help-echo "Set or reset this face."
3206 :documentation-property #'face-doc-string
3207 :value-create 'custom-face-value-create
3208 :action 'custom-face-action
3209 :custom-category 'face
3210 :custom-form nil ; defaults to value of `custom-face-default-form'
3211 :custom-set 'custom-face-set
3212 :custom-save 'custom-face-save
3213 :custom-reset-current 'custom-redraw
3214 :custom-reset-saved 'custom-face-reset-saved
3215 :custom-reset-standard 'custom-face-reset-standard
3216 :custom-standard-value 'custom-face-standard-value
3217 :custom-menu 'custom-face-menu-create)
3219 (define-widget 'custom-face-all 'editable-list
3220 "An editable list of display specifications and attributes."
3221 :entry-format "%i %d %v"
3222 :insert-button-args '(:help-echo "Insert new display specification here.")
3223 :append-button-args '(:help-echo "Append new display specification here.")
3224 :delete-button-args '(:help-echo "Delete this display specification.")
3225 :args '((group :format "%v" custom-display custom-face-edit)))
3227 (defconst custom-face-all (widget-convert 'custom-face-all)
3228 "Converted version of the `custom-face-all' widget.")
3230 (define-widget 'custom-display-unselected 'item
3231 "A display specification that doesn't match the selected display."
3232 :match 'custom-display-unselected-match)
3234 (defun custom-display-unselected-match (widget value)
3235 "Non-nil if VALUE is an unselected display specification."
3236 (not (face-spec-set-match-display value (selected-frame))))
3238 (define-widget 'custom-face-selected 'group
3239 "Edit the attributes of the selected display in a face specification."
3240 :args '((choice :inline t
3241 (group :tag "With Defaults" :inline t
3242 (group (const :tag "" default)
3243 (custom-face-edit :tag " Default\n Attributes"))
3244 (repeat :format ""
3245 :inline t
3246 (group custom-display-unselected sexp))
3247 (group (sexp :format "")
3248 (custom-face-edit :tag " Overriding\n Attributes"))
3249 (repeat :format ""
3250 :inline t
3251 sexp))
3252 (group :tag "No Defaults" :inline t
3253 (repeat :format ""
3254 :inline t
3255 (group custom-display-unselected sexp))
3256 (group (sexp :format "")
3257 (custom-face-edit :tag "\n Attributes"))
3258 (repeat :format ""
3259 :inline t
3260 sexp)))))
3264 (defconst custom-face-selected (widget-convert 'custom-face-selected)
3265 "Converted version of the `custom-face-selected' widget.")
3267 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
3268 "Return a canonicalized version of SPEC using.
3269 FILTER-INDEX is the index in the entry for each attribute in
3270 `custom-face-attributes' at which the appropriate filter function can be
3271 found, and DEFAULT-FILTER is the filter to apply for attributes that
3272 don't specify one."
3273 (mapcar (lambda (entry)
3274 ;; Filter a single face-spec entry
3275 (let ((tests (car entry))
3276 (unfiltered-attrs
3277 ;; Handle both old- and new-style attribute syntax
3278 (if (listp (car (cdr entry)))
3279 (car (cdr entry))
3280 (cdr entry)))
3281 (filtered-attrs nil))
3282 ;; Filter each face attribute
3283 (while unfiltered-attrs
3284 (let* ((attr (pop unfiltered-attrs))
3285 (pre-filtered-value (pop unfiltered-attrs))
3286 (filter
3287 (or (nth filter-index (assq attr custom-face-attributes))
3288 default-filter))
3289 (filtered-value
3290 (if filter
3291 (funcall filter pre-filtered-value)
3292 pre-filtered-value)))
3293 (push filtered-value filtered-attrs)
3294 (push attr filtered-attrs)))
3296 (list tests filtered-attrs)))
3297 spec))
3299 (defun custom-pre-filter-face-spec (spec)
3300 "Return SPEC changed as necessary for editing by the face customization widget.
3301 SPEC must be a full face spec."
3302 (custom-filter-face-spec spec 2))
3304 (defun custom-post-filter-face-spec (spec)
3305 "Return the customized SPEC in a form suitable for setting the face."
3306 (custom-filter-face-spec spec 3))
3308 (defun custom-face-value-create (widget)
3309 "Create a list of the display specifications for WIDGET."
3310 (let ((buttons (widget-get widget :buttons))
3311 children
3312 (symbol (widget-get widget :value))
3313 (tag (widget-get widget :tag))
3314 (state (widget-get widget :custom-state))
3315 (begin (point))
3316 (is-last (widget-get widget :custom-last))
3317 (prefix (widget-get widget :custom-prefix)))
3318 (unless tag
3319 (setq tag (prin1-to-string symbol)))
3320 (cond ((eq custom-buffer-style 'tree)
3321 (insert prefix (if is-last " `--- " " |--- "))
3322 (push (widget-create-child-and-convert
3323 widget 'custom-browse-face-tag)
3324 buttons)
3325 (insert " " tag "\n")
3326 (widget-put widget :buttons buttons))
3328 ;; Create tag.
3329 (insert tag)
3330 (widget-specify-sample widget begin (point))
3331 (if (eq custom-buffer-style 'face)
3332 (insert " ")
3333 (if (string-match "face\\'" tag)
3334 (insert ":")
3335 (insert " face: ")))
3336 ;; Sample.
3337 (push (widget-create-child-and-convert widget 'item
3338 :format "(%{%t%})"
3339 :sample-face symbol
3340 :tag "sample")
3341 buttons)
3342 ;; Visibility.
3343 (insert " ")
3344 (push (widget-create-child-and-convert
3345 widget 'visibility
3346 :help-echo "Hide or show this face."
3347 :on "Hide Face"
3348 :off "Show Face"
3349 :action 'custom-toggle-parent
3350 (not (eq state 'hidden)))
3351 buttons)
3352 ;; Magic.
3353 (insert "\n")
3354 (let ((magic (widget-create-child-and-convert
3355 widget 'custom-magic nil)))
3356 (widget-put widget :custom-magic magic)
3357 (push magic buttons))
3358 ;; Update buttons.
3359 (widget-put widget :buttons buttons)
3360 ;; Insert documentation.
3361 (widget-default-format-handler widget ?h)
3362 ;; The comment field
3363 (unless (eq state 'hidden)
3364 (let* ((comment (get symbol 'face-comment))
3365 (comment-widget
3366 (widget-create-child-and-convert
3367 widget 'custom-comment
3368 :parent widget
3369 :value (or comment ""))))
3370 (widget-put widget :comment-widget comment-widget)
3371 (push comment-widget children)))
3372 ;; See also.
3373 (unless (eq state 'hidden)
3374 (when (eq (widget-get widget :custom-level) 1)
3375 (custom-add-parent-links widget))
3376 (custom-add-see-also widget))
3377 ;; Editor.
3378 (unless (eq (preceding-char) ?\n)
3379 (insert "\n"))
3380 (unless (eq state 'hidden)
3381 (message "Creating face editor...")
3382 (custom-load-widget widget)
3383 (unless (widget-get widget :custom-form)
3384 (widget-put widget :custom-form custom-face-default-form))
3385 (let* ((symbol (widget-value widget))
3386 (spec (or (get symbol 'customized-face)
3387 (get symbol 'saved-face)
3388 (get symbol 'face-defface-spec)
3389 ;; Attempt to construct it.
3390 (list (list t (custom-face-attributes-get
3391 symbol (selected-frame))))))
3392 (form (widget-get widget :custom-form))
3393 (indent (widget-get widget :indent))
3394 edit)
3395 ;; If the user has changed this face in some other way,
3396 ;; edit it as the user has specified it.
3397 (if (not (face-spec-match-p symbol spec (selected-frame)))
3398 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
3399 (setq spec (custom-pre-filter-face-spec spec))
3400 (setq edit (widget-create-child-and-convert
3401 widget
3402 (cond ((and (eq form 'selected)
3403 (widget-apply custom-face-selected
3404 :match spec))
3405 (when indent (insert-char ?\ indent))
3406 'custom-face-selected)
3407 ((and (not (eq form 'lisp))
3408 (widget-apply custom-face-all
3409 :match spec))
3410 'custom-face-all)
3412 (when indent (insert-char ?\ indent))
3413 'sexp))
3414 :value spec))
3415 (custom-face-state-set widget)
3416 (push edit children)
3417 (widget-put widget :children children))
3418 (message "Creating face editor...done"))))))
3420 (defvar custom-face-menu
3421 `(("Set for Current Session" custom-face-set)
3422 ,@(when (or custom-file user-init-file)
3423 '(("Save for Future Sessions" custom-face-save)))
3424 ("Undo Edits" custom-redraw
3425 (lambda (widget)
3426 (memq (widget-get widget :custom-state) '(modified changed))))
3427 ("Reset to Saved" custom-face-reset-saved
3428 (lambda (widget)
3429 (or (get (widget-value widget) 'saved-face)
3430 (get (widget-value widget) 'saved-face-comment))))
3431 ,@(when (or custom-file user-init-file)
3432 '(("Erase Customization" custom-face-reset-standard
3433 (lambda (widget)
3434 (get (widget-value widget) 'face-defface-spec)))))
3435 ("---" ignore ignore)
3436 ("Add Comment" custom-comment-show custom-comment-invisible-p)
3437 ("---" ignore ignore)
3438 ("For Current Display" custom-face-edit-selected
3439 (lambda (widget)
3440 (not (eq (widget-get widget :custom-form) 'selected))))
3441 ("For All Kinds of Displays" custom-face-edit-all
3442 (lambda (widget)
3443 (not (eq (widget-get widget :custom-form) 'all))))
3444 ("Show Lisp Expression" custom-face-edit-lisp
3445 (lambda (widget)
3446 (not (eq (widget-get widget :custom-form) 'lisp)))))
3447 "Alist of actions for the `custom-face' widget.
3448 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3449 the menu entry, ACTION is the function to call on the widget when the
3450 menu is selected, and FILTER is a predicate which takes a `custom-face'
3451 widget as an argument, and returns non-nil if ACTION is valid on that
3452 widget. If FILTER is nil, ACTION is always valid.")
3454 (defun custom-face-edit-selected (widget)
3455 "Edit selected attributes of the value of WIDGET."
3456 (widget-put widget :custom-state 'unknown)
3457 (widget-put widget :custom-form 'selected)
3458 (custom-redraw widget))
3460 (defun custom-face-edit-all (widget)
3461 "Edit all attributes of the value of WIDGET."
3462 (widget-put widget :custom-state 'unknown)
3463 (widget-put widget :custom-form 'all)
3464 (custom-redraw widget))
3466 (defun custom-face-edit-lisp (widget)
3467 "Edit the Lisp representation of the value of WIDGET."
3468 (widget-put widget :custom-state 'unknown)
3469 (widget-put widget :custom-form 'lisp)
3470 (custom-redraw widget))
3472 (defun custom-face-state-set (widget)
3473 "Set the state of WIDGET."
3474 (let* ((symbol (widget-value widget))
3475 (comment (get symbol 'face-comment))
3476 tmp temp
3477 (state
3478 (cond ((progn
3479 (setq tmp (get symbol 'customized-face))
3480 (setq temp (get symbol 'customized-face-comment))
3481 (or tmp temp))
3482 (if (equal temp comment)
3483 'set
3484 'changed))
3485 ((progn
3486 (setq tmp (get symbol 'saved-face))
3487 (setq temp (get symbol 'saved-face-comment))
3488 (or tmp temp))
3489 (if (equal temp comment)
3490 (cond
3491 ((eq 'user (caar (get symbol 'theme-face)))
3492 'saved)
3493 ((eq 'changed (caar (get symbol 'theme-face)))
3494 'changed)
3495 (t 'themed))
3496 'changed))
3497 ((get symbol 'face-defface-spec)
3498 (if (equal comment nil)
3499 'standard
3500 'changed))
3502 'rogue))))
3503 ;; If the user called set-face-attribute to change the default
3504 ;; for new frames, this face is "set outside of Customize".
3505 (if (and (not (eq state 'rogue))
3506 (get symbol 'face-modified))
3507 (setq state 'changed))
3508 (widget-put widget :custom-state state)))
3510 (defun custom-face-action (widget &optional event)
3511 "Show the menu for `custom-face' WIDGET.
3512 Optional EVENT is the location for the menu."
3513 (if (eq (widget-get widget :custom-state) 'hidden)
3514 (custom-toggle-hide widget)
3515 (let* ((completion-ignore-case t)
3516 (symbol (widget-get widget :value))
3517 (answer (widget-choose (concat "Operation on "
3518 (custom-unlispify-tag-name symbol))
3519 (custom-menu-filter custom-face-menu
3520 widget)
3521 event)))
3522 (if answer
3523 (funcall answer widget)))))
3525 (defun custom-face-set (widget)
3526 "Make the face attributes in WIDGET take effect."
3527 (let* ((symbol (widget-value widget))
3528 (child (car (widget-get widget :children)))
3529 (value (custom-post-filter-face-spec (widget-value child)))
3530 (comment-widget (widget-get widget :comment-widget))
3531 (comment (widget-value comment-widget)))
3532 (when (equal comment "")
3533 (setq comment nil)
3534 ;; Make the comment invisible by hand if it's empty
3535 (custom-comment-hide comment-widget))
3536 (put symbol 'customized-face value)
3537 (custom-push-theme 'theme-face symbol 'user 'set value)
3538 (if (face-spec-choose value)
3539 (face-spec-set symbol value)
3540 ;; face-set-spec ignores empty attribute lists, so just give it
3541 ;; something harmless instead.
3542 (face-spec-set symbol '((t :foreground unspecified))))
3543 (put symbol 'customized-face-comment comment)
3544 (put symbol 'face-comment comment)
3545 (custom-face-state-set widget)
3546 (custom-redraw-magic widget)))
3548 (defun custom-face-save (widget)
3549 "Save in `.emacs' the face attributes in WIDGET."
3550 (let* ((symbol (widget-value widget))
3551 (child (car (widget-get widget :children)))
3552 (value (custom-post-filter-face-spec (widget-value child)))
3553 (comment-widget (widget-get widget :comment-widget))
3554 (comment (widget-value comment-widget)))
3555 (when (equal comment "")
3556 (setq comment nil)
3557 ;; Make the comment invisible by hand if it's empty
3558 (custom-comment-hide comment-widget))
3559 (custom-push-theme 'theme-face symbol 'user 'set value)
3560 (if (face-spec-choose value)
3561 (face-spec-set symbol value)
3562 ;; face-set-spec ignores empty attribute lists, so just give it
3563 ;; something harmless instead.
3564 (face-spec-set symbol '((t :foreground unspecified))))
3565 (unless (eq (widget-get widget :custom-state) 'standard)
3566 (put symbol 'saved-face value))
3567 (put symbol 'customized-face nil)
3568 (put symbol 'face-comment comment)
3569 (put symbol 'customized-face-comment nil)
3570 (put symbol 'saved-face-comment comment)
3571 (custom-save-all)
3572 (custom-face-state-set widget)
3573 (custom-redraw-magic widget)))
3575 ;; For backward compatibility.
3576 (define-obsolete-function-alias 'custom-face-save-command 'custom-face-save
3577 "22.1")
3579 (defun custom-face-reset-saved (widget)
3580 "Restore WIDGET to the face's default attributes."
3581 (let* ((symbol (widget-value widget))
3582 (child (car (widget-get widget :children)))
3583 (value (get symbol 'saved-face))
3584 (comment (get symbol 'saved-face-comment))
3585 (comment-widget (widget-get widget :comment-widget)))
3586 (unless (or value comment)
3587 (error "No saved value for this face"))
3588 (put symbol 'customized-face nil)
3589 (put symbol 'customized-face-comment nil)
3590 (custom-push-theme 'theme-face symbol 'user 'set value)
3591 (face-spec-set symbol value)
3592 (put symbol 'face-comment comment)
3593 (widget-value-set child value)
3594 ;; This call manages the comment visibility
3595 (widget-value-set comment-widget (or comment ""))
3596 (custom-face-state-set widget)
3597 (custom-redraw-magic widget)))
3599 (defun custom-face-standard-value (widget)
3600 (get (widget-value widget) 'face-defface-spec))
3602 (defun custom-face-reset-standard (widget)
3603 "Restore WIDGET to the face's standard attribute values.
3604 This operation eliminates any saved attributes for the face,
3605 restoring it to the state of a face that has never been customized."
3606 (let* ((symbol (widget-value widget))
3607 (child (car (widget-get widget :children)))
3608 (value (get symbol 'face-defface-spec))
3609 (comment-widget (widget-get widget :comment-widget)))
3610 (unless value
3611 (error "No standard setting for this face"))
3612 (put symbol 'customized-face nil)
3613 (put symbol 'customized-face-comment nil)
3614 (custom-push-theme 'theme-face symbol 'user 'reset)
3615 (face-spec-set symbol value)
3616 (custom-theme-recalc-face symbol)
3617 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3618 (put symbol 'saved-face nil)
3619 (put symbol 'saved-face-comment nil)
3620 (custom-save-all))
3621 (put symbol 'face-comment nil)
3622 (widget-value-set child
3623 (custom-pre-filter-face-spec
3624 (list (list t (custom-face-attributes-get
3625 symbol nil)))))
3626 ;; This call manages the comment visibility
3627 (widget-value-set comment-widget "")
3628 (custom-face-state-set widget)
3629 (custom-redraw-magic widget)))
3631 ;;; The `face' Widget.
3633 (defvar widget-face-prompt-value-history nil
3634 "History of input to `widget-face-prompt-value'.")
3636 (define-widget 'face 'symbol
3637 "A Lisp face name (with sample)."
3638 :format "%{%t%}: (%{sample%}) %v"
3639 :tag "Face"
3640 :value 'default
3641 :sample-face-get 'widget-face-sample-face-get
3642 :notify 'widget-face-notify
3643 :match (lambda (widget value) (facep value))
3644 :complete-function (lambda ()
3645 (interactive)
3646 (lisp-complete-symbol 'facep))
3647 :prompt-match 'facep
3648 :prompt-history 'widget-face-prompt-value-history
3649 :validate (lambda (widget)
3650 (unless (facep (widget-value widget))
3651 (widget-put widget
3652 :error (format "Invalid face: %S"
3653 (widget-value widget)))
3654 widget)))
3656 (defun widget-face-sample-face-get (widget)
3657 (let ((value (widget-value widget)))
3658 (if (facep value)
3659 value
3660 'default)))
3662 (defun widget-face-notify (widget child &optional event)
3663 "Update the sample, and notify the parent."
3664 (overlay-put (widget-get widget :sample-overlay)
3665 'face (widget-apply widget :sample-face-get))
3666 (widget-default-notify widget child event))
3669 ;;; The `hook' Widget.
3671 (define-widget 'hook 'list
3672 "An Emacs Lisp hook."
3673 :value-to-internal (lambda (widget value)
3674 (if (and value (symbolp value))
3675 (list value)
3676 value))
3677 :match (lambda (widget value)
3678 (or (symbolp value)
3679 (widget-group-match widget value)))
3680 ;; Avoid adding undefined functions to the hook, especially for
3681 ;; things like `find-file-hook' or even more basic ones, to avoid
3682 ;; chaos.
3683 :set (lambda (symbol value)
3684 (dolist (elt value)
3685 (if (fboundp elt)
3686 (add-hook symbol elt))))
3687 :convert-widget 'custom-hook-convert-widget
3688 :tag "Hook")
3690 (defun custom-hook-convert-widget (widget)
3691 ;; Handle `:options'.
3692 (let* ((options (widget-get widget :options))
3693 (other `(editable-list :inline t
3694 :entry-format "%i %d%v"
3695 (function :format " %v")))
3696 (args (if options
3697 (list `(checklist :inline t
3698 ,@(mapcar (lambda (entry)
3699 `(function-item ,entry))
3700 options))
3701 other)
3702 (list other))))
3703 (widget-put widget :args args)
3704 widget))
3706 ;;; The `custom-group-link' Widget.
3708 (define-widget 'custom-group-link 'link
3709 "Show parent in other window when activated."
3710 :button-face 'custom-link
3711 :mouse-face 'highlight
3712 :pressed-face 'highlight
3713 :help-echo "Create customization buffer for this group."
3714 :keymap custom-mode-link-map
3715 :follow-link 'mouse-face
3716 :action 'custom-group-link-action)
3718 (defun custom-group-link-action (widget &rest ignore)
3719 (customize-group (widget-value widget)))
3721 ;;; The `custom-group' Widget.
3723 (defcustom custom-group-tag-faces nil
3724 ;; In XEmacs, this ought to play games with font size.
3725 ;; Fixme: make it do so in Emacs.
3726 "Face used for group tags.
3727 The first member is used for level 1 groups, the second for level 2,
3728 and so forth. The remaining group tags are shown with `custom-group-tag'."
3729 :type '(repeat face)
3730 :group 'custom-faces)
3732 (defface custom-group-tag-1
3733 `((((class color)
3734 (background dark))
3735 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3736 (((min-colors 88) (class color)
3737 (background light))
3738 (:foreground "red1" :weight bold :height 1.2 :inherit variable-pitch))
3739 (((class color)
3740 (background light))
3741 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3742 (t (:weight bold)))
3743 "Face used for group tags."
3744 :group 'custom-faces)
3745 ;; backward-compatibility alias
3746 (put 'custom-group-tag-face-1 'face-alias 'custom-group-tag-1)
3748 (defface custom-group-tag
3749 `((((class color)
3750 (background dark))
3751 (:foreground "light blue" :weight bold :height 1.2))
3752 (((min-colors 88) (class color)
3753 (background light))
3754 (:foreground "blue1" :weight bold :height 1.2))
3755 (((class color)
3756 (background light))
3757 (:foreground "blue" :weight bold :height 1.2))
3758 (t (:weight bold)))
3759 "Face used for low level group tags."
3760 :group 'custom-faces)
3761 ;; backward-compatibility alias
3762 (put 'custom-group-tag-face 'face-alias 'custom-group-tag)
3764 (define-widget 'custom-group 'custom
3765 "Customize group."
3766 :format "%v"
3767 :sample-face-get 'custom-group-sample-face-get
3768 :documentation-property 'group-documentation
3769 :help-echo "Set or reset all members of this group."
3770 :value-create 'custom-group-value-create
3771 :action 'custom-group-action
3772 :custom-category 'group
3773 :custom-set 'custom-group-set
3774 :custom-save 'custom-group-save
3775 :custom-reset-current 'custom-group-reset-current
3776 :custom-reset-saved 'custom-group-reset-saved
3777 :custom-reset-standard 'custom-group-reset-standard
3778 :custom-menu 'custom-group-menu-create)
3780 (defun custom-group-sample-face-get (widget)
3781 ;; Use :sample-face.
3782 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3783 'custom-group-tag))
3785 (define-widget 'custom-group-visibility 'visibility
3786 "An indicator and manipulator for hidden group contents."
3787 :create 'custom-group-visibility-create)
3789 (defun custom-group-visibility-create (widget)
3790 (let ((visible (widget-value widget)))
3791 (if visible
3792 (insert "--------")))
3793 (widget-default-create widget))
3795 (defun custom-group-members (symbol groups-only)
3796 "Return SYMBOL's custom group members.
3797 If GROUPS-ONLY non-nil, return only those members that are groups."
3798 (if (not groups-only)
3799 (get symbol 'custom-group)
3800 (let (members)
3801 (dolist (entry (get symbol 'custom-group))
3802 (when (eq (nth 1 entry) 'custom-group)
3803 (push entry members)))
3804 (nreverse members))))
3806 (defun custom-group-value-create (widget)
3807 "Insert a customize group for WIDGET in the current buffer."
3808 (unless (eq (widget-get widget :custom-state) 'hidden)
3809 (custom-load-widget widget))
3810 (let* ((state (widget-get widget :custom-state))
3811 (level (widget-get widget :custom-level))
3812 ;; (indent (widget-get widget :indent))
3813 (prefix (widget-get widget :custom-prefix))
3814 (buttons (widget-get widget :buttons))
3815 (tag (widget-get widget :tag))
3816 (symbol (widget-value widget))
3817 (members (custom-group-members symbol
3818 (and (eq custom-buffer-style 'tree)
3819 custom-browse-only-groups))))
3820 (cond ((and (eq custom-buffer-style 'tree)
3821 (eq state 'hidden)
3822 (or members (custom-unloaded-widget-p widget)))
3823 (custom-browse-insert-prefix prefix)
3824 (push (widget-create-child-and-convert
3825 widget 'custom-browse-visibility
3826 ;; :tag-glyph "plus"
3827 :tag "+")
3828 buttons)
3829 (insert "-- ")
3830 ;; (widget-glyph-insert nil "-- " "horizontal")
3831 (push (widget-create-child-and-convert
3832 widget 'custom-browse-group-tag)
3833 buttons)
3834 (insert " " tag "\n")
3835 (widget-put widget :buttons buttons))
3836 ((and (eq custom-buffer-style 'tree)
3837 (zerop (length members)))
3838 (custom-browse-insert-prefix prefix)
3839 (insert "[ ]-- ")
3840 ;; (widget-glyph-insert nil "[ ]" "empty")
3841 ;; (widget-glyph-insert nil "-- " "horizontal")
3842 (push (widget-create-child-and-convert
3843 widget 'custom-browse-group-tag)
3844 buttons)
3845 (insert " " tag "\n")
3846 (widget-put widget :buttons buttons))
3847 ((eq custom-buffer-style 'tree)
3848 (custom-browse-insert-prefix prefix)
3849 (if (zerop (length members))
3850 (progn
3851 (custom-browse-insert-prefix prefix)
3852 (insert "[ ]-- ")
3853 ;; (widget-glyph-insert nil "[ ]" "empty")
3854 ;; (widget-glyph-insert nil "-- " "horizontal")
3855 (push (widget-create-child-and-convert
3856 widget 'custom-browse-group-tag)
3857 buttons)
3858 (insert " " tag "\n")
3859 (widget-put widget :buttons buttons))
3860 (push (widget-create-child-and-convert
3861 widget 'custom-browse-visibility
3862 ;; :tag-glyph "minus"
3863 :tag "-")
3864 buttons)
3865 (insert "-\\ ")
3866 ;; (widget-glyph-insert nil "-\\ " "top")
3867 (push (widget-create-child-and-convert
3868 widget 'custom-browse-group-tag)
3869 buttons)
3870 (insert " " tag "\n")
3871 (widget-put widget :buttons buttons)
3872 (message "Creating group...")
3873 (let* ((members (custom-sort-items members
3874 custom-browse-sort-alphabetically
3875 custom-browse-order-groups))
3876 (prefixes (widget-get widget :custom-prefixes))
3877 (custom-prefix-list (custom-prefix-add symbol prefixes))
3878 (extra-prefix (if (widget-get widget :custom-last)
3880 " | "))
3881 (prefix (concat prefix extra-prefix))
3882 children entry)
3883 (while members
3884 (setq entry (car members)
3885 members (cdr members))
3886 (push (widget-create-child-and-convert
3887 widget (nth 1 entry)
3888 :group widget
3889 :tag (custom-unlispify-tag-name (nth 0 entry))
3890 :custom-prefixes custom-prefix-list
3891 :custom-level (1+ level)
3892 :custom-last (null members)
3893 :value (nth 0 entry)
3894 :custom-prefix prefix)
3895 children))
3896 (widget-put widget :children (reverse children)))
3897 (message "Creating group...done")))
3898 ;; Nested style.
3899 ((eq state 'hidden)
3900 ;; Create level indicator.
3901 (unless (eq custom-buffer-style 'links)
3902 (insert-char ?\ (* custom-buffer-indent (1- level)))
3903 (insert "-- "))
3904 ;; Create tag.
3905 (let ((begin (point)))
3906 (insert tag)
3907 (widget-specify-sample widget begin (point)))
3908 (insert " group: ")
3909 ;; Create link/visibility indicator.
3910 (if (eq custom-buffer-style 'links)
3911 (push (widget-create-child-and-convert
3912 widget 'custom-group-link
3913 :tag "Go to Group"
3914 symbol)
3915 buttons)
3916 (push (widget-create-child-and-convert
3917 widget 'custom-group-visibility
3918 :help-echo "Show members of this group."
3919 :action 'custom-toggle-parent
3920 (not (eq state 'hidden)))
3921 buttons))
3922 (insert " \n")
3923 ;; Create magic button.
3924 (let ((magic (widget-create-child-and-convert
3925 widget 'custom-magic nil)))
3926 (widget-put widget :custom-magic magic)
3927 (push magic buttons))
3928 ;; Update buttons.
3929 (widget-put widget :buttons buttons)
3930 ;; Insert documentation.
3931 (if (and (eq custom-buffer-style 'links) (> level 1))
3932 (widget-put widget :documentation-indent 0))
3933 (widget-default-format-handler widget ?h))
3934 ;; Nested style.
3935 (t ;Visible.
3936 ;; Add parent groups references above the group.
3937 (if t ;;; This should test that the buffer
3938 ;;; was made to display a group.
3939 (when (eq level 1)
3940 (if (custom-add-parent-links widget
3941 "Go to parent group:")
3942 (insert "\n"))))
3943 ;; Create level indicator.
3944 (insert-char ?\ (* custom-buffer-indent (1- level)))
3945 (insert "/- ")
3946 ;; Create tag.
3947 (let ((start (point)))
3948 (insert tag)
3949 (widget-specify-sample widget start (point)))
3950 (insert " group: ")
3951 ;; Create visibility indicator.
3952 (unless (eq custom-buffer-style 'links)
3953 (insert "--------")
3954 (push (widget-create-child-and-convert
3955 widget 'visibility
3956 :help-echo "Hide members of this group."
3957 :action 'custom-toggle-parent
3958 (not (eq state 'hidden)))
3959 buttons)
3960 (insert " "))
3961 ;; Create more dashes.
3962 ;; Use 76 instead of 75 to compensate for the temporary "<"
3963 ;; added by `widget-insert'.
3964 (insert-char ?- (- 76 (current-column)
3965 (* custom-buffer-indent level)))
3966 (insert "\\\n")
3967 ;; Create magic button.
3968 (let ((magic (widget-create-child-and-convert
3969 widget 'custom-magic
3970 :indent 0
3971 nil)))
3972 (widget-put widget :custom-magic magic)
3973 (push magic buttons))
3974 ;; Update buttons.
3975 (widget-put widget :buttons buttons)
3976 ;; Insert documentation.
3977 (widget-default-format-handler widget ?h)
3978 ;; Parent groups.
3979 (if nil ;;; This should test that the buffer
3980 ;;; was not made to display a group.
3981 (when (eq level 1)
3982 (insert-char ?\ custom-buffer-indent)
3983 (custom-add-parent-links widget)))
3984 (custom-add-see-also widget
3985 (make-string (* custom-buffer-indent level)
3986 ?\ ))
3987 ;; Members.
3988 (message "Creating group...")
3989 (let* ((members (custom-sort-items members
3990 custom-buffer-sort-alphabetically
3991 custom-buffer-order-groups))
3992 (prefixes (widget-get widget :custom-prefixes))
3993 (custom-prefix-list (custom-prefix-add symbol prefixes))
3994 (length (length members))
3995 (count 0)
3996 (children (mapcar (lambda (entry)
3997 (widget-insert "\n")
3998 (message "\
3999 Creating group members... %2d%%"
4000 (/ (* 100.0 count) length))
4001 (setq count (1+ count))
4002 (prog1
4003 (widget-create-child-and-convert
4004 widget (nth 1 entry)
4005 :group widget
4006 :tag (custom-unlispify-tag-name
4007 (nth 0 entry))
4008 :custom-prefixes custom-prefix-list
4009 :custom-level (1+ level)
4010 :value (nth 0 entry))
4011 (unless (eq (preceding-char) ?\n)
4012 (widget-insert "\n"))))
4013 members)))
4014 (message "Creating group magic...")
4015 (mapc 'custom-magic-reset children)
4016 (message "Creating group state...")
4017 (widget-put widget :children children)
4018 (custom-group-state-update widget)
4019 (message "Creating group... done"))
4020 ;; End line
4021 (insert "\n")
4022 (insert-char ?\ (* custom-buffer-indent (1- level)))
4023 (insert "\\- " (widget-get widget :tag) " group end ")
4024 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
4025 (insert "/\n")))))
4027 (defvar custom-group-menu
4028 `(("Set for Current Session" custom-group-set
4029 (lambda (widget)
4030 (eq (widget-get widget :custom-state) 'modified)))
4031 ,@(when (or custom-file user-init-file)
4032 '(("Save for Future Sessions" custom-group-save
4033 (lambda (widget)
4034 (memq (widget-get widget :custom-state) '(modified set))))))
4035 ("Undo Edits" custom-group-reset-current
4036 (lambda (widget)
4037 (memq (widget-get widget :custom-state) '(modified))))
4038 ("Reset to Saved" custom-group-reset-saved
4039 (lambda (widget)
4040 (memq (widget-get widget :custom-state) '(modified set))))
4041 ,@(when (or custom-file user-init-file)
4042 '(("Erase Customization" custom-group-reset-standard
4043 (lambda (widget)
4044 (memq (widget-get widget :custom-state) '(modified set saved)))))))
4045 "Alist of actions for the `custom-group' widget.
4046 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4047 the menu entry, ACTION is the function to call on the widget when the
4048 menu is selected, and FILTER is a predicate which takes a `custom-group'
4049 widget as an argument, and returns non-nil if ACTION is valid on that
4050 widget. If FILTER is nil, ACTION is always valid.")
4052 (defun custom-group-action (widget &optional event)
4053 "Show the menu for `custom-group' WIDGET.
4054 Optional EVENT is the location for the menu."
4055 (if (eq (widget-get widget :custom-state) 'hidden)
4056 (custom-toggle-hide widget)
4057 (let* ((completion-ignore-case t)
4058 (answer (widget-choose (concat "Operation on "
4059 (custom-unlispify-tag-name
4060 (widget-get widget :value)))
4061 (custom-menu-filter custom-group-menu
4062 widget)
4063 event)))
4064 (if answer
4065 (funcall answer widget)))))
4067 (defun custom-group-set (widget)
4068 "Set changes in all modified group members."
4069 (let ((children (widget-get widget :children)))
4070 (mapc (lambda (child)
4071 (when (eq (widget-get child :custom-state) 'modified)
4072 (widget-apply child :custom-set)))
4073 children )))
4075 (defun custom-group-save (widget)
4076 "Save all modified group members."
4077 (let ((children (widget-get widget :children)))
4078 (mapc (lambda (child)
4079 (when (memq (widget-get child :custom-state) '(modified set))
4080 (widget-apply child :custom-save)))
4081 children )))
4083 (defun custom-group-reset-current (widget)
4084 "Reset all modified group members."
4085 (let ((children (widget-get widget :children)))
4086 (mapc (lambda (child)
4087 (when (eq (widget-get child :custom-state) 'modified)
4088 (widget-apply child :custom-reset-current)))
4089 children )))
4091 (defun custom-group-reset-saved (widget)
4092 "Reset all modified or set group members."
4093 (let ((children (widget-get widget :children)))
4094 (mapc (lambda (child)
4095 (when (memq (widget-get child :custom-state) '(modified set))
4096 (widget-apply child :custom-reset-saved)))
4097 children )))
4099 (defun custom-group-reset-standard (widget)
4100 "Reset all modified, set, or saved group members."
4101 (let ((children (widget-get widget :children)))
4102 (mapc (lambda (child)
4103 (when (memq (widget-get child :custom-state)
4104 '(modified set saved))
4105 (widget-apply child :custom-reset-standard)))
4106 children )))
4108 (defun custom-group-state-update (widget)
4109 "Update magic."
4110 (unless (eq (widget-get widget :custom-state) 'hidden)
4111 (let* ((children (widget-get widget :children))
4112 (states (mapcar (lambda (child)
4113 (widget-get child :custom-state))
4114 children))
4115 (magics custom-magic-alist)
4116 (found 'standard))
4117 (while magics
4118 (let ((magic (car (car magics))))
4119 (if (and (not (eq magic 'hidden))
4120 (memq magic states))
4121 (setq found magic
4122 magics nil)
4123 (setq magics (cdr magics)))))
4124 (widget-put widget :custom-state found)))
4125 (custom-magic-reset widget))
4127 ;;; Reading and writing the custom file.
4129 ;;;###autoload
4130 (defcustom custom-file nil
4131 "File used for storing customization information.
4132 The default is nil, which means to use your init file
4133 as specified by `user-init-file'. If the value is not nil,
4134 it should be an absolute file name.
4136 You can set this option through Custom, if you carefully read the
4137 last paragraph below. However, usually it is simpler to write
4138 something like the following in your init file:
4140 \(setq custom-file \"~/.emacs-custom.el\")
4141 \(load custom-file)
4143 Note that both lines are necessary: the first line tells Custom to
4144 save all customizations in this file, but does not load it.
4146 When you change this variable outside Custom, look in the
4147 previous custom file \(usually your init file) for the
4148 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4149 and copy them (whichever ones you find) to the new custom file.
4150 This will preserve your existing customizations.
4152 If you save this option using Custom, Custom will write all
4153 currently saved customizations, including the new one for this
4154 option itself, into the file you specify, overwriting any
4155 `custom-set-variables' and `custom-set-faces' forms already
4156 present in that file. It will not delete any customizations from
4157 the old custom file. You should do that manually if that is what you
4158 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4159 in your init file, where CUSTOM-FILE is the actual name of the
4160 file. Otherwise, Emacs will not load the file when it starts up,
4161 and hence will not set `custom-file' to that file either."
4162 :type '(choice (const :tag "Your Emacs init file" nil)
4163 (file :format "%t:%v%d"
4164 :doc
4165 "Please read entire docstring below before setting \
4166 this through Custom.
4167 Click om \"More\" \(or position point there and press RETURN)
4168 if only the first line of the docstring is shown."))
4169 :group 'customize)
4171 (defun custom-file ()
4172 "Return the file name for saving customizations."
4173 (file-chase-links
4174 (or custom-file
4175 (let ((user-init-file user-init-file)
4176 (default-init-file
4177 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
4178 (when (null user-init-file)
4179 (if (or (file-exists-p default-init-file)
4180 (and (eq system-type 'windows-nt)
4181 (file-exists-p "~/_emacs")))
4182 ;; Started with -q, i.e. the file containing
4183 ;; Custom settings hasn't been read. Saving
4184 ;; settings there would overwrite other settings.
4185 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4186 (setq user-init-file default-init-file))
4187 user-init-file))))
4189 ;;;###autoload
4190 (defun custom-save-all ()
4191 "Save all customizations in `custom-file'."
4192 (when (and (null custom-file) init-file-had-error)
4193 (error "Cannot save customizations; init file was not fully loaded"))
4194 (let* ((filename (custom-file))
4195 (recentf-exclude (if recentf-mode
4196 (cons (concat "\\`"
4197 (regexp-quote (custom-file))
4198 "\\'")
4199 recentf-exclude)))
4200 (old-buffer (find-buffer-visiting filename)))
4201 (with-current-buffer (let ((find-file-visit-truename t))
4202 (or old-buffer (find-file-noselect filename)))
4203 (unless (eq major-mode 'emacs-lisp-mode)
4204 (emacs-lisp-mode))
4205 (let ((inhibit-read-only t))
4206 (custom-save-variables)
4207 (custom-save-faces))
4208 (let ((file-precious-flag t))
4209 (save-buffer))
4210 (unless old-buffer
4211 (kill-buffer (current-buffer))))))
4213 ;;;###autoload
4214 (defun customize-save-customized ()
4215 "Save all user options which have been set in this session."
4216 (interactive)
4217 (mapatoms (lambda (symbol)
4218 (let ((face (get symbol 'customized-face))
4219 (value (get symbol 'customized-value))
4220 (face-comment (get symbol 'customized-face-comment))
4221 (variable-comment
4222 (get symbol 'customized-variable-comment)))
4223 (when face
4224 (put symbol 'saved-face face)
4225 (custom-push-theme 'theme-face symbol 'user 'set value)
4226 (put symbol 'customized-face nil))
4227 (when value
4228 (put symbol 'saved-value value)
4229 (custom-push-theme 'theme-value symbol 'user 'set value)
4230 (put symbol 'customized-value nil))
4231 (when variable-comment
4232 (put symbol 'saved-variable-comment variable-comment)
4233 (put symbol 'customized-variable-comment nil))
4234 (when face-comment
4235 (put symbol 'saved-face-comment face-comment)
4236 (put symbol 'customized-face-comment nil)))))
4237 ;; We really should update all custom buffers here.
4238 (custom-save-all))
4240 ;; Editing the custom file contents in a buffer.
4242 (defun custom-save-delete (symbol)
4243 "Delete all calls to SYMBOL from the contents of the current buffer.
4244 Leave point at the old location of the first such call,
4245 or (if there were none) at the end of the buffer.
4247 This function does not save the buffer."
4248 (goto-char (point-min))
4249 ;; Skip all whitespace and comments.
4250 (while (forward-comment 1))
4251 (or (eobp)
4252 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4253 (let (first)
4254 (catch 'found
4255 (while t ;; We exit this loop only via throw.
4256 ;; Skip all whitespace and comments.
4257 (while (forward-comment 1))
4258 (let ((start (point))
4259 (sexp (condition-case nil
4260 (read (current-buffer))
4261 (end-of-file (throw 'found nil)))))
4262 (when (and (listp sexp)
4263 (eq (car sexp) symbol))
4264 (delete-region start (point))
4265 (unless first
4266 (setq first (point)))))))
4267 (if first
4268 (goto-char first)
4269 ;; Move in front of local variables, otherwise long Custom
4270 ;; entries would make them ineffective.
4271 (let ((pos (point-max))
4272 (case-fold-search t))
4273 (save-excursion
4274 (goto-char (point-max))
4275 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4276 'move)
4277 (when (search-forward "Local Variables:" nil t)
4278 (setq pos (line-beginning-position))))
4279 (goto-char pos)))))
4281 (defun custom-save-variables ()
4282 "Save all customized variables in `custom-file'."
4283 (save-excursion
4284 (custom-save-delete 'custom-set-variables)
4285 (let ((standard-output (current-buffer))
4286 (saved-list (make-list 1 0))
4287 sort-fold-case)
4288 ;; First create a sorted list of saved variables.
4289 (mapatoms
4290 (lambda (symbol)
4291 (if (and (get symbol 'saved-value)
4292 ;; ignore theme values
4293 (or (null (get symbol 'theme-value))
4294 (eq 'user (caar (get symbol 'theme-value)))))
4295 (nconc saved-list (list symbol)))))
4296 (setq saved-list (sort (cdr saved-list) 'string<))
4297 (unless (bolp)
4298 (princ "\n"))
4299 (princ "(custom-set-variables
4300 ;; custom-set-variables was added by Custom.
4301 ;; If you edit it by hand, you could mess it up, so be careful.
4302 ;; Your init file should contain only one such instance.
4303 ;; If there is more than one, they won't work right.\n")
4304 (dolist (symbol saved-list)
4305 (let ((spec (car-safe (get symbol 'theme-value)))
4306 (value (get symbol 'saved-value))
4307 (requests (get symbol 'custom-requests))
4308 (now (and (not (custom-variable-p symbol))
4309 (or (boundp symbol)
4310 (eq (get symbol 'force-value)
4311 'rogue))))
4312 (comment (get symbol 'saved-variable-comment)))
4313 ;; Check REQUESTS for validity.
4314 (dolist (request requests)
4315 (when (and (symbolp request) (not (featurep request)))
4316 (message "Unknown requested feature: %s" request)
4317 (setq requests (delq request requests))))
4318 ;; Is there anything customized about this variable?
4319 (when (or (and spec (eq (car spec) 'user))
4320 comment
4321 (and (null spec) (get symbol 'saved-value)))
4322 ;; Output an element for this variable.
4323 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4324 ;; SYMBOL is the variable name.
4325 ;; VALUE-FORM is an expression to return the customized value.
4326 ;; NOW if non-nil means always set the variable immediately
4327 ;; when the customizations are reloaded. This is used
4328 ;; for rogue variables
4329 ;; REQUESTS is a list of packages to load before setting the
4330 ;; variable. Each element of it will be passed to `require'.
4331 ;; COMMENT is whatever comment the user has specified
4332 ;; with the customize facility.
4333 (unless (bolp)
4334 (princ "\n"))
4335 (princ " '(")
4336 (prin1 symbol)
4337 (princ " ")
4338 (prin1 (car value))
4339 (when (or now requests comment)
4340 (princ " ")
4341 (prin1 now)
4342 (when (or requests comment)
4343 (princ " ")
4344 (prin1 requests)
4345 (when comment
4346 (princ " ")
4347 (prin1 comment))))
4348 (princ ")"))))
4349 (if (bolp)
4350 (princ " "))
4351 (princ ")")
4352 (unless (looking-at "\n")
4353 (princ "\n")))))
4355 (defun custom-save-faces ()
4356 "Save all customized faces in `custom-file'."
4357 (save-excursion
4358 (custom-save-delete 'custom-reset-faces)
4359 (custom-save-delete 'custom-set-faces)
4360 (let ((standard-output (current-buffer))
4361 (saved-list (make-list 1 0))
4362 sort-fold-case)
4363 ;; First create a sorted list of saved faces.
4364 (mapatoms
4365 (lambda (symbol)
4366 (if (and (get symbol 'saved-face)
4367 (eq 'user (car (car-safe (get symbol 'theme-face)))))
4368 (nconc saved-list (list symbol)))))
4369 (setq saved-list (sort (cdr saved-list) 'string<))
4370 ;; The default face must be first, since it affects the others.
4371 (if (memq 'default saved-list)
4372 (setq saved-list (cons 'default (delq 'default saved-list))))
4373 (unless (bolp)
4374 (princ "\n"))
4375 (princ "(custom-set-faces
4376 ;; custom-set-faces was added by Custom.
4377 ;; If you edit it by hand, you could mess it up, so be careful.
4378 ;; Your init file should contain only one such instance.
4379 ;; If there is more than one, they won't work right.\n")
4380 (dolist (symbol saved-list)
4381 (let ((spec (car-safe (get symbol 'theme-face)))
4382 (value (get symbol 'saved-face))
4383 (now (not (or (get symbol 'face-defface-spec)
4384 (and (not (custom-facep symbol))
4385 (not (get symbol 'force-face))))))
4386 (comment (get symbol 'saved-face-comment)))
4387 (when (or (and spec (eq (nth 0 spec) 'user))
4388 comment
4389 (and (null spec) (get symbol 'saved-face)))
4390 ;; Don't print default face here.
4391 (unless (bolp)
4392 (princ "\n"))
4393 (princ " '(")
4394 (prin1 symbol)
4395 (princ " ")
4396 (prin1 value)
4397 (when (or now comment)
4398 (princ " ")
4399 (prin1 now)
4400 (when comment
4401 (princ " ")
4402 (prin1 comment)))
4403 (princ ")"))))
4404 (if (bolp)
4405 (princ " "))
4406 (princ ")")
4407 (unless (looking-at "\n")
4408 (princ "\n")))))
4410 ;;; The Customize Menu.
4412 ;;; Menu support
4414 (defcustom custom-menu-nesting 2
4415 "Maximum nesting in custom menus."
4416 :type 'integer
4417 :group 'custom-menu)
4419 (defun custom-face-menu-create (widget symbol)
4420 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4421 (vector (custom-unlispify-menu-entry symbol)
4422 `(customize-face ',symbol)
4425 (defun custom-variable-menu-create (widget symbol)
4426 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4427 (let ((type (get symbol 'custom-type)))
4428 (unless (listp type)
4429 (setq type (list type)))
4430 (if (and type (widget-get type :custom-menu))
4431 (widget-apply type :custom-menu symbol)
4432 (vector (custom-unlispify-menu-entry symbol)
4433 `(customize-variable ',symbol)
4434 t))))
4436 ;; Add checkboxes to boolean variable entries.
4437 (widget-put (get 'boolean 'widget-type)
4438 :custom-menu (lambda (widget symbol)
4439 (vector (custom-unlispify-menu-entry symbol)
4440 `(customize-variable ',symbol)
4441 ':style 'toggle
4442 ':selected symbol)))
4444 (defun custom-group-menu-create (widget symbol)
4445 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4446 `( ,(custom-unlispify-menu-entry symbol t)
4447 :filter (lambda (&rest junk)
4448 (let* ((menu (custom-menu-create ',symbol)))
4449 (if (consp menu) (cdr menu) menu)))))
4451 ;;;###autoload
4452 (defun custom-menu-create (symbol)
4453 "Create menu for customization group SYMBOL.
4454 The menu is in a format applicable to `easy-menu-define'."
4455 (let* ((deactivate-mark nil)
4456 (item (vector (custom-unlispify-menu-entry symbol)
4457 `(customize-group ',symbol)
4458 t)))
4459 (if (and (or (not (boundp 'custom-menu-nesting))
4460 (>= custom-menu-nesting 0))
4461 (progn
4462 (custom-load-symbol symbol)
4463 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
4464 (let ((custom-prefix-list (custom-prefix-add symbol
4465 custom-prefix-list))
4466 (members (custom-sort-items (get symbol 'custom-group)
4467 custom-menu-sort-alphabetically
4468 custom-menu-order-groups)))
4469 `(,(custom-unlispify-menu-entry symbol t)
4470 ,item
4471 "--"
4472 ,@(mapcar (lambda (entry)
4473 (widget-apply (if (listp (nth 1 entry))
4474 (nth 1 entry)
4475 (list (nth 1 entry)))
4476 :custom-menu (nth 0 entry)))
4477 members)))
4478 item)))
4480 ;;;###autoload
4481 (defun customize-menu-create (symbol &optional name)
4482 "Return a customize menu for customization group SYMBOL.
4483 If optional NAME is given, use that as the name of the menu.
4484 Otherwise the menu will be named `Customize'.
4485 The format is suitable for use with `easy-menu-define'."
4486 (unless name
4487 (setq name "Customize"))
4488 `(,name
4489 :filter (lambda (&rest junk)
4490 (let ((menu (custom-menu-create ',symbol)))
4491 (if (consp menu) (cdr menu) menu)))))
4493 ;;; The Custom Mode.
4495 (defun Custom-no-edit (pos &optional event)
4496 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4497 (interactive "@d")
4498 (error "You can't edit this part of the Custom buffer"))
4500 (defun Custom-newline (pos &optional event)
4501 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4502 (interactive "@d")
4503 (let ((button (get-char-property pos 'button)))
4504 (if button
4505 (widget-apply-action button event)
4506 (error "You can't edit this part of the Custom buffer"))))
4508 (easy-menu-define Custom-mode-menu
4509 custom-mode-map
4510 "Menu used in customization buffers."
4511 `("Custom"
4512 ,(customize-menu-create 'customize)
4513 ["Set" Custom-set t]
4514 ["Save" Custom-save t]
4515 ["Undo Edits" Custom-reset-current t]
4516 ["Reset to Saved" Custom-reset-saved t]
4517 ["Erase Customization" Custom-reset-standard t]
4518 ["Info" (info "(emacs)Easy Customization") t]))
4520 (defvar custom-field-keymap
4521 (let ((map (copy-keymap widget-field-keymap)))
4522 (define-key map "\C-c\C-c" 'Custom-set)
4523 (define-key map "\C-x\C-s" 'Custom-save)
4524 map)
4525 "Keymap used inside editable fields in customization buffers.")
4527 (widget-put (get 'editable-field 'widget-type) :keymap custom-field-keymap)
4529 (defun Custom-goto-parent ()
4530 "Go to the parent group listed at the top of this buffer.
4531 If several parents are listed, go to the first of them."
4532 (interactive)
4533 (save-excursion
4534 (goto-char (point-min))
4535 (if (search-forward "\nGo to parent group: " nil t)
4536 (let* ((button (get-char-property (point) 'button))
4537 (parent (downcase (widget-get button :tag))))
4538 (customize-group parent)))))
4540 (defcustom custom-mode-hook nil
4541 "Hook called when entering Custom mode."
4542 :type 'hook
4543 :group 'custom-buffer )
4545 (defun custom-state-buffer-message (widget)
4546 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4547 (message "To install your edits, invoke [State] and choose the Set operation")))
4549 (defun custom-mode ()
4550 "Major mode for editing customization buffers.
4552 The following commands are available:
4554 \\<widget-keymap>\
4555 Move to next button, link or editable field. \\[widget-forward]
4556 Move to previous button, link or editable field. \\[advertised-widget-backward]
4557 \\<custom-field-keymap>\
4558 Complete content of editable text field. \\[widget-complete]
4559 \\<custom-mode-map>\
4560 Invoke button under the mouse pointer. \\[widget-button-click]
4561 Invoke button under point. \\[widget-button-press]
4562 Set all options from current text. \\[Custom-set]
4563 Make values in current text permanent. \\[Custom-save]
4564 Make text match actual option values. \\[Custom-reset-current]
4565 Reset options to permanent settings. \\[Custom-reset-saved]
4566 Erase customizations; set options
4567 and buffer text to the standard values. \\[Custom-reset-standard]
4569 Entry to this mode calls the value of `custom-mode-hook'
4570 if that value is non-nil."
4571 (kill-all-local-variables)
4572 (setq major-mode 'custom-mode
4573 mode-name "Custom")
4574 (use-local-map custom-mode-map)
4575 (easy-menu-add Custom-mode-menu)
4576 (make-local-variable 'custom-options)
4577 (make-local-variable 'custom-local-buffer)
4578 (make-local-variable 'widget-documentation-face)
4579 (setq widget-documentation-face 'custom-documentation)
4580 (make-local-variable 'widget-button-face)
4581 (setq widget-button-face custom-button)
4583 ;; We need this because of the "More" button on docstrings.
4584 ;; Otherwise clicking on "More" can push point offscreen, which
4585 ;; causes the window to recenter on point, which pushes the
4586 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4587 (set (make-local-variable 'widget-button-click-moves-point) t)
4589 (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed)
4590 (set (make-local-variable 'widget-mouse-face) custom-button-mouse)
4592 ;; When possible, use relief for buttons, not bracketing. This test
4593 ;; may not be optimal.
4594 (when custom-raised-buttons
4595 (set (make-local-variable 'widget-push-button-prefix) "")
4596 (set (make-local-variable 'widget-push-button-suffix) "")
4597 (set (make-local-variable 'widget-link-prefix) "")
4598 (set (make-local-variable 'widget-link-suffix) ""))
4599 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
4600 (run-mode-hooks 'custom-mode-hook))
4602 (put 'custom-mode 'mode-class 'special)
4604 (dolist (regexp
4605 '("^No user option defaults have been changed since Emacs "
4606 "^Invalid face:? "
4607 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4608 "^No customizable items matching "
4609 "^There are unset changes"
4610 "^Cannot set hidden variable"
4611 "^No \\(?:saved\\|backup\\) value for "
4612 "^No standard setting known for "
4613 "^No standard setting for this face"
4614 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4615 (add-to-list 'debug-ignored-errors regexp))
4617 ;;; The End.
4619 (provide 'cus-edit)
4621 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4622 ;;; cus-edit.el ends here