(font-lock-default-fontify-buffer): Try and set-defaults even if font-lock-mode
[emacs.git] / lisp / cus-edit.el
blob43c38e172b5bce1f005441c987ff844a6196f854
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 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 initial 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 modeline 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 ;;; Utilities.
471 (defun custom-quote (sexp)
472 "Quote SEXP iff it is not self quoting."
473 (if (or (memq sexp '(t nil))
474 (keywordp sexp)
475 (and (listp sexp)
476 (memq (car sexp) '(lambda)))
477 (stringp sexp)
478 (numberp sexp)
479 (vectorp sexp)
480 ;;; (and (fboundp 'characterp)
481 ;;; (characterp sexp))
483 sexp
484 (list 'quote sexp)))
486 (defun custom-split-regexp-maybe (regexp)
487 "If REGEXP is a string, split it to a list at `\\|'.
488 You can get the original back with from the result with:
489 (mapconcat 'identity result \"\\|\")
491 IF REGEXP is not a string, return it unchanged."
492 (if (stringp regexp)
493 (let ((start 0)
494 all)
495 (while (string-match "\\\\|" regexp start)
496 (setq all (cons (substring regexp start (match-beginning 0)) all)
497 start (match-end 0)))
498 (nreverse (cons (substring regexp start) all)))
499 regexp))
501 (defun custom-variable-prompt ()
502 "Prompt for a custom variable, defaulting to the variable at point.
503 Return a list suitable for use in `interactive'."
504 (let* ((v (variable-at-point))
505 (default (and (symbolp v) (custom-variable-p v) (symbol-name v)))
506 (enable-recursive-minibuffers t)
507 val)
508 (setq val (completing-read
509 (if default (format "Customize option (default %s): " default)
510 "Customize option: ")
511 obarray 'custom-variable-p t nil nil default))
512 (list (if (equal val "")
513 (if (symbolp v) v nil)
514 (intern val)))))
516 (defun custom-menu-filter (menu widget)
517 "Convert MENU to the form used by `widget-choose'.
518 MENU should be in the same format as `custom-variable-menu'.
519 WIDGET is the widget to apply the filter entries of MENU on."
520 (let ((result nil)
521 current name action filter)
522 (while menu
523 (setq current (car menu)
524 name (nth 0 current)
525 action (nth 1 current)
526 filter (nth 2 current)
527 menu (cdr menu))
528 (if (or (null filter) (funcall filter widget))
529 (push (cons name action) result)
530 (push name result)))
531 (nreverse result)))
533 ;;; Unlispify.
535 (defvar custom-prefix-list nil
536 "List of prefixes that should be ignored by `custom-unlispify'.")
538 (defcustom custom-unlispify-menu-entries t
539 "Display menu entries as words instead of symbols if non nil."
540 :group 'custom-menu
541 :type 'boolean)
543 (defcustom custom-unlispify-remove-prefixes nil
544 "Non-nil means remove group prefixes from option names in buffer."
545 :group 'custom-menu
546 :group 'custom-buffer
547 :type 'boolean)
549 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
550 "Convert SYMBOL into a menu entry."
551 (cond ((not custom-unlispify-menu-entries)
552 (symbol-name symbol))
553 ((get symbol 'custom-tag)
554 (if no-suffix
555 (get symbol 'custom-tag)
556 (concat (get symbol 'custom-tag) "...")))
558 (with-current-buffer (get-buffer-create " *Custom-Work*")
559 (erase-buffer)
560 (princ symbol (current-buffer))
561 (goto-char (point-min))
562 ;; FIXME: Boolean variables are not predicates, so they shouldn't
563 ;; end with `-p'. -stef
564 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
565 ;; (re-search-forward "-p\\'" nil t))
566 ;; (replace-match "" t t)
567 ;; (goto-char (point-min)))
568 (if custom-unlispify-remove-prefixes
569 (let ((prefixes custom-prefix-list)
570 prefix)
571 (while prefixes
572 (setq prefix (car prefixes))
573 (if (search-forward prefix (+ (point) (length prefix)) t)
574 (progn
575 (setq prefixes nil)
576 (delete-region (point-min) (point)))
577 (setq prefixes (cdr prefixes))))))
578 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
579 (capitalize-region (point-min) (point-max))
580 (unless no-suffix
581 (goto-char (point-max))
582 (insert "..."))
583 (buffer-string)))))
585 (defcustom custom-unlispify-tag-names t
586 "Display tag names as words instead of symbols if non nil."
587 :group 'custom-buffer
588 :type 'boolean)
590 (defun custom-unlispify-tag-name (symbol)
591 "Convert SYMBOL into a menu entry."
592 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
593 (custom-unlispify-menu-entry symbol t)))
595 (defun custom-prefix-add (symbol prefixes)
596 "Add SYMBOL to list of ignored PREFIXES."
597 (cons (or (get symbol 'custom-prefix)
598 (concat (symbol-name symbol) "-"))
599 prefixes))
601 ;;; Guess.
603 (defcustom custom-guess-name-alist
604 '(("-p\\'" boolean)
605 ("-hook\\'" hook)
606 ("-face\\'" face)
607 ("-file\\'" file)
608 ("-function\\'" function)
609 ("-functions\\'" (repeat function))
610 ("-list\\'" (repeat sexp))
611 ("-alist\\'" (repeat (cons sexp sexp))))
612 "Alist of (MATCH TYPE).
614 MATCH should be a regexp matching the name of a symbol, and TYPE should
615 be a widget suitable for editing the value of that symbol. The TYPE
616 of the first entry where MATCH matches the name of the symbol will be
617 used.
619 This is used for guessing the type of variables not declared with
620 customize."
621 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
622 :group 'customize)
624 (defcustom custom-guess-doc-alist
625 '(("\\`\\*?Non-nil " boolean))
626 "Alist of (MATCH TYPE).
628 MATCH should be a regexp matching a documentation string, and TYPE
629 should be a widget suitable for editing the value of a variable with
630 that documentation string. The TYPE of the first entry where MATCH
631 matches the name of the symbol will be used.
633 This is used for guessing the type of variables not declared with
634 customize."
635 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
636 :group 'customize)
638 (defun custom-guess-type (symbol)
639 "Guess a widget suitable for editing the value of SYMBOL.
640 This is done by matching SYMBOL with `custom-guess-name-alist' and
641 if that fails, the doc string with `custom-guess-doc-alist'."
642 (let ((name (symbol-name symbol))
643 (names custom-guess-name-alist)
644 current found)
645 (while names
646 (setq current (car names)
647 names (cdr names))
648 (when (string-match (nth 0 current) name)
649 (setq found (nth 1 current)
650 names nil)))
651 (unless found
652 (let ((doc (documentation-property symbol 'variable-documentation))
653 (docs custom-guess-doc-alist))
654 (when doc
655 (while docs
656 (setq current (car docs)
657 docs (cdr docs))
658 (when (string-match (nth 0 current) doc)
659 (setq found (nth 1 current)
660 docs nil))))))
661 found))
663 ;;; Sorting.
665 (defcustom custom-browse-sort-alphabetically nil
666 "If non-nil, sort members of each customization group alphabetically."
667 :type 'boolean
668 :group 'custom-browse)
670 (defcustom custom-browse-order-groups nil
671 "If non-nil, order group members within each customization group.
672 If `first', order groups before non-groups.
673 If `last', order groups after non-groups."
674 :type '(choice (const first)
675 (const last)
676 (const :tag "none" nil))
677 :group 'custom-browse)
679 (defcustom custom-browse-only-groups nil
680 "If non-nil, show group members only within each customization group."
681 :type 'boolean
682 :group 'custom-browse)
684 (defcustom custom-buffer-sort-alphabetically nil
685 "If non-nil, sort members of each customization group alphabetically."
686 :type 'boolean
687 :group 'custom-buffer)
689 (defcustom custom-buffer-order-groups 'last
690 "If non-nil, order group members within each customization group.
691 If `first', order groups before non-groups.
692 If `last', order groups after non-groups."
693 :type '(choice (const first)
694 (const last)
695 (const :tag "none" nil))
696 :group 'custom-buffer)
698 (defcustom custom-menu-sort-alphabetically nil
699 "If non-nil, sort members of each customization group alphabetically."
700 :type 'boolean
701 :group 'custom-menu)
703 (defcustom custom-menu-order-groups 'first
704 "If non-nil, order group members within each customization group.
705 If `first', order groups before non-groups.
706 If `last', order groups after non-groups."
707 :type '(choice (const first)
708 (const last)
709 (const :tag "none" nil))
710 :group 'custom-menu)
712 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
714 (defun custom-sort-items (items sort-alphabetically order-groups)
715 "Return a sorted copy of ITEMS.
716 ITEMS should be a `custom-group' property.
717 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
718 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
719 groups after non-groups, if nil do not order groups at all."
720 (sort (copy-sequence items)
721 (lambda (a b)
722 (let ((typea (nth 1 a)) (typeb (nth 1 b))
723 (namea (nth 0 a)) (nameb (nth 0 b)))
724 (cond ((not order-groups)
725 ;; Since we don't care about A and B order, maybe sort.
726 (when sort-alphabetically
727 (string-lessp namea nameb)))
728 ((eq typea 'custom-group)
729 ;; If B is also a group, maybe sort. Otherwise, order A and B.
730 (if (eq typeb 'custom-group)
731 (when sort-alphabetically
732 (string-lessp namea nameb))
733 (eq order-groups 'first)))
734 ((eq typeb 'custom-group)
735 ;; Since A cannot be a group, order A and B.
736 (eq order-groups 'last))
737 (sort-alphabetically
738 ;; Since A and B cannot be groups, sort.
739 (string-lessp namea nameb)))))))
741 ;;; Custom Mode Commands.
743 (defvar custom-options nil
744 "Customization widgets in the current buffer.")
746 (defun Custom-set ()
747 "Set changes in all modified options."
748 (interactive)
749 (let ((children custom-options))
750 (mapc (lambda (child)
751 (when (eq (widget-get child :custom-state) 'modified)
752 (widget-apply child :custom-set)))
753 children)))
755 (defun Custom-save ()
756 "Set all modified group members and save them."
757 (interactive)
758 (let ((children custom-options))
759 (mapc (lambda (child)
760 (when (memq (widget-get child :custom-state)
761 '(modified set changed rogue))
762 (widget-apply child :custom-save)))
763 children))
764 (custom-save-all))
766 (defvar custom-reset-menu
767 '(("Current" . Custom-reset-current)
768 ("Saved" . Custom-reset-saved)
769 ("Erase Customization (use standard settings)" . Custom-reset-standard))
770 "Alist of actions for the `Reset' button.
771 The key is a string containing the name of the action, the value is a
772 Lisp function taking the widget as an element which will be called
773 when the action is chosen.")
775 (defun custom-reset (event)
776 "Select item from reset menu."
777 (let* ((completion-ignore-case t)
778 (answer (widget-choose "Reset to"
779 custom-reset-menu
780 event)))
781 (if answer
782 (funcall answer))))
784 (defun Custom-reset-current (&rest ignore)
785 "Reset all modified group members to their current value."
786 (interactive)
787 (let ((children custom-options))
788 (mapc (lambda (widget)
789 (if (memq (widget-get widget :custom-state)
790 '(modified changed))
791 (widget-apply widget :custom-reset-current)))
792 children)))
794 (defun Custom-reset-saved (&rest ignore)
795 "Reset all modified or set group members to their saved value."
796 (interactive)
797 (let ((children custom-options))
798 (mapc (lambda (widget)
799 (if (memq (widget-get widget :custom-state)
800 '(modified set changed rogue))
801 (widget-apply widget :custom-reset-saved)))
802 children)))
804 (defun Custom-reset-standard (&rest ignore)
805 "Erase all customization (either current or saved) for the group members.
806 The immediate result is to restore them to their standard settings.
807 This operation eliminates any saved settings for the group members,
808 making them as if they had never been customized at all."
809 (interactive)
810 (let ((children custom-options))
811 (when (or (and (= 1 (length children))
812 (memq (widget-type (car children))
813 '(custom-variable custom-face)))
814 (yes-or-no-p "Really erase all customizations in this buffer? "))
815 (mapc (lambda (widget)
816 (and (if (widget-get widget :custom-standard-value)
817 (widget-apply widget :custom-standard-value)
819 (memq (widget-get widget :custom-state)
820 '(modified set changed saved rogue))
821 (widget-apply widget :custom-reset-standard)))
822 children))))
824 ;;; The Customize Commands
826 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
827 "Prompt for a variable and a value and return them as a list.
828 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
829 prompt for the value. The %s escape in PROMPT-VAL is replaced with
830 the name of the variable.
832 If the variable has a `variable-interactive' property, that is used as if
833 it were the arg to `interactive' (which see) to interactively read the value.
835 If the variable has a `custom-type' property, it must be a widget and the
836 `:prompt-value' property of that widget will be used for reading the value.
838 If optional COMMENT argument is non nil, also prompt for a comment and return
839 it as the third element in the list."
840 (let* ((var (read-variable prompt-var))
841 (minibuffer-help-form '(describe-variable var))
842 (val
843 (let ((prop (get var 'variable-interactive))
844 (type (get var 'custom-type))
845 (prompt (format prompt-val var)))
846 (unless (listp type)
847 (setq type (list type)))
848 (cond (prop
849 ;; Use VAR's `variable-interactive' property
850 ;; as an interactive spec for prompting.
851 (call-interactively (list 'lambda '(arg)
852 (list 'interactive prop)
853 'arg)))
854 (type
855 (widget-prompt-value type
856 prompt
857 (if (boundp var)
858 (symbol-value var))
859 (not (boundp var))))
861 (eval-minibuffer prompt))))))
862 (if comment
863 (list var val
864 (read-string "Comment: " (get var 'variable-comment)))
865 (list var val))))
867 ;;;###autoload
868 (defun customize-set-value (variable value &optional comment)
869 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
871 If VARIABLE has a `variable-interactive' property, that is used as if
872 it were the arg to `interactive' (which see) to interactively read the value.
874 If VARIABLE has a `custom-type' property, it must be a widget and the
875 `:prompt-value' property of that widget will be used for reading the value.
877 If given a prefix (or a COMMENT argument), also prompt for a comment."
878 (interactive (custom-prompt-variable "Set variable: "
879 "Set %s to value: "
880 current-prefix-arg))
882 (cond ((string= comment "")
883 (put variable 'variable-comment nil))
884 (comment
885 (put variable 'variable-comment comment)))
886 (set variable value))
888 ;;;###autoload
889 (defun customize-set-variable (variable value &optional comment)
890 "Set the default for VARIABLE to VALUE, and return VALUE.
891 VALUE is a Lisp object.
893 If VARIABLE has a `custom-set' property, that is used for setting
894 VARIABLE, otherwise `set-default' is used.
896 The `customized-value' property of the VARIABLE will be set to a list
897 with a quoted VALUE as its sole list member.
899 If VARIABLE has a `variable-interactive' property, that is used as if
900 it were the arg to `interactive' (which see) to interactively read the value.
902 If VARIABLE has a `custom-type' property, it must be a widget and the
903 `:prompt-value' property of that widget will be used for reading the value.
905 If given a prefix (or a COMMENT argument), also prompt for a comment."
906 (interactive (custom-prompt-variable "Set variable: "
907 "Set customized value for %s to: "
908 current-prefix-arg))
909 (custom-load-symbol variable)
910 (funcall (or (get variable 'custom-set) 'set-default) variable value)
911 (put variable 'customized-value (list (custom-quote value)))
912 (cond ((string= comment "")
913 (put variable 'variable-comment nil)
914 (put variable 'customized-variable-comment nil))
915 (comment
916 (put variable 'variable-comment comment)
917 (put variable 'customized-variable-comment comment)))
918 value)
920 ;;;###autoload
921 (defun customize-save-variable (variable value &optional comment)
922 "Set the default for VARIABLE to VALUE, and save it for future sessions.
923 Return VALUE.
925 If VARIABLE has a `custom-set' property, that is used for setting
926 VARIABLE, otherwise `set-default' is used.
928 The `customized-value' property of the VARIABLE will be set to a list
929 with a quoted VALUE as its sole list member.
931 If VARIABLE has a `variable-interactive' property, that is used as if
932 it were the arg to `interactive' (which see) to interactively read the value.
934 If VARIABLE has a `custom-type' property, it must be a widget and the
935 `:prompt-value' property of that widget will be used for reading the value.
937 If given a prefix (or a COMMENT argument), also prompt for a comment."
938 (interactive (custom-prompt-variable "Set and save variable: "
939 "Set and save value for %s as: "
940 current-prefix-arg))
941 (funcall (or (get variable 'custom-set) 'set-default) variable value)
942 (put variable 'saved-value (list (custom-quote value)))
943 (custom-push-theme 'theme-value variable 'user 'set (list (custom-quote value)))
944 (cond ((string= comment "")
945 (put variable 'variable-comment nil)
946 (put variable 'saved-variable-comment nil))
947 (comment
948 (put variable 'variable-comment comment)
949 (put variable 'saved-variable-comment comment)))
950 (custom-save-all)
951 value)
953 ;;;###autoload
954 (defun customize ()
955 "Select a customization buffer which you can use to set user options.
956 User options are structured into \"groups\".
957 Initially the top-level group `Emacs' and its immediate subgroups
958 are shown; the contents of those subgroups are initially hidden."
959 (interactive)
960 (customize-group 'emacs))
962 ;;;###autoload
963 (defun customize-mode (mode)
964 "Customize options related to the current major mode.
965 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
966 then prompt for the MODE to customize."
967 (interactive
968 (list
969 (let ((completion-regexp-list '("-mode\\'"))
970 (group (custom-group-of-mode major-mode)))
971 (if (and group (not current-prefix-arg))
972 major-mode
973 (intern
974 (completing-read (if group
975 (format "Major mode (default %s): " major-mode)
976 "Major mode: ")
977 obarray
978 'custom-group-of-mode
979 t nil nil (if group (symbol-name major-mode))))))))
980 (customize-group (custom-group-of-mode mode)))
983 ;;;###autoload
984 (defun customize-group (group)
985 "Customize GROUP, which must be a customization group."
986 (interactive
987 (list (let ((completion-ignore-case t))
988 (completing-read "Customize group (default emacs): "
989 obarray
990 (lambda (symbol)
991 (or (and (get symbol 'custom-loads)
992 (not (get symbol 'custom-autoload)))
993 (get symbol 'custom-group)))
994 t))))
995 (when (stringp group)
996 (if (string-equal "" group)
997 (setq group 'emacs)
998 (setq group (intern group))))
999 (let ((name (format "*Customize Group: %s*"
1000 (custom-unlispify-tag-name group))))
1001 (if (get-buffer name)
1002 (pop-to-buffer name)
1003 (custom-buffer-create (list (list group 'custom-group))
1004 name
1005 (concat " for group "
1006 (custom-unlispify-tag-name group))))))
1008 ;;;###autoload
1009 (defun customize-group-other-window (group)
1010 "Customize GROUP, which must be a customization group."
1011 (interactive
1012 (list (let ((completion-ignore-case t))
1013 (completing-read "Customize group (default emacs): "
1014 obarray
1015 (lambda (symbol)
1016 (or (and (get symbol 'custom-loads)
1017 (not (get symbol 'custom-autoload)))
1018 (get symbol 'custom-group)))
1019 t))))
1020 (when (stringp group)
1021 (if (string-equal "" group)
1022 (setq group 'emacs)
1023 (setq group (intern group))))
1024 (let ((name (format "*Customize Group: %s*"
1025 (custom-unlispify-tag-name group))))
1026 (if (get-buffer name)
1027 (let (
1028 ;; Copied from `custom-buffer-create-other-window'.
1029 (pop-up-windows t)
1030 (same-window-buffer-names nil)
1031 (same-window-regexps nil))
1032 (pop-to-buffer name))
1033 (custom-buffer-create-other-window
1034 (list (list group 'custom-group))
1035 name
1036 (concat " for group "
1037 (custom-unlispify-tag-name group))))))
1039 ;;;###autoload
1040 (defalias 'customize-variable 'customize-option)
1042 ;;;###autoload
1043 (defun customize-option (symbol)
1044 "Customize SYMBOL, which must be a user option variable."
1045 (interactive (custom-variable-prompt))
1046 (let ((basevar (indirect-variable symbol)))
1047 (custom-buffer-create (list (list basevar 'custom-variable))
1048 (format "*Customize Option: %s*"
1049 (custom-unlispify-tag-name basevar)))
1050 (unless (eq symbol basevar)
1051 (message "`%s' is an alias for `%s'" symbol basevar))))
1053 ;;;###autoload
1054 (defalias 'customize-variable-other-window 'customize-option-other-window)
1056 ;;;###autoload
1057 (defun customize-option-other-window (symbol)
1058 "Customize SYMBOL, which must be a user option variable.
1059 Show the buffer in another window, but don't select it."
1060 (interactive (custom-variable-prompt))
1061 (let ((basevar (indirect-variable symbol)))
1062 (custom-buffer-create-other-window
1063 (list (list basevar 'custom-variable))
1064 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar)))
1065 (unless (eq symbol basevar)
1066 (message "`%s' is an alias for `%s'" symbol basevar))))
1068 (defvar customize-changed-options-previous-release "20.2"
1069 "Version for `customize-changed-options' to refer back to by default.")
1071 ;;;###autoload
1072 (defun customize-changed-options (since-version)
1073 "Customize all user option variables changed in Emacs itself.
1074 This includes new user option variables and faces, and new
1075 customization groups, as well as older options and faces whose default
1076 values have changed since the previous major Emacs release.
1078 With argument SINCE-VERSION (a string), customize all user option
1079 variables that were added (or their meanings were changed) since that
1080 version."
1082 (interactive "sCustomize options changed, since version (default all versions): ")
1083 (if (equal since-version "")
1084 (setq since-version nil)
1085 (unless (condition-case nil
1086 (numberp (read since-version))
1087 (error nil))
1088 (signal 'wrong-type-argument (list 'numberp since-version))))
1089 (unless since-version
1090 (setq since-version customize-changed-options-previous-release))
1092 ;; Load the information for versions since since-version. We use
1093 ;; custom-load-symbol for this.
1094 (put 'custom-versions-load-alist 'custom-loads nil)
1095 (dolist (elt custom-versions-load-alist)
1096 (if (customize-version-lessp since-version (car elt))
1097 (dolist (load (cdr elt))
1098 (custom-add-load 'custom-versions-load-alist load))))
1099 (custom-load-symbol 'custom-versions-load-alist)
1100 (put 'custom-versions-load-alist 'custom-loads nil)
1102 (let (found)
1103 (mapatoms
1104 (lambda (symbol)
1105 (let ((version (get symbol 'custom-version)))
1106 (if version
1107 (when (customize-version-lessp since-version version)
1108 (if (or (get symbol 'custom-group)
1109 (get symbol 'group-documentation))
1110 (push (list symbol 'custom-group) found))
1111 (if (custom-variable-p symbol)
1112 (push (list symbol 'custom-variable) found))
1113 (if (custom-facep symbol)
1114 (push (list symbol 'custom-face) found)))))))
1115 (if found
1116 (custom-buffer-create (custom-sort-items found t 'first)
1117 "*Customize Changed Options*")
1118 (error "No user option defaults have been changed since Emacs %s"
1119 since-version))))
1121 (defun customize-version-lessp (version1 version2)
1122 ;; Why are the versions strings, and given that they are, why aren't
1123 ;; they converted to numbers and compared as such here? -- fx
1125 ;; In case someone made a mistake and left out the quotes
1126 ;; in the :version value.
1127 (if (numberp version2)
1128 (setq version2 (prin1-to-string version2)))
1129 (let (major1 major2 minor1 minor2)
1130 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1131 (setq major1 (read (or (match-string 1 version1)
1132 "0")))
1133 (setq minor1 (read (or (match-string 3 version1)
1134 "0")))
1135 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1136 (setq major2 (read (or (match-string 1 version2)
1137 "0")))
1138 (setq minor2 (read (or (match-string 3 version2)
1139 "0")))
1140 (or (< major1 major2)
1141 (and (= major1 major2)
1142 (< minor1 minor2)))))
1144 ;;;###autoload
1145 (defun customize-face (&optional face)
1146 "Customize FACE, which should be a face name or nil.
1147 If FACE is nil, customize all faces. If FACE is actually a
1148 face-alias, customize the face it is aliased to.
1150 Interactively, when point is on text which has a face specified,
1151 suggest to customize that face, if it's customizable."
1152 (interactive
1153 (list (read-face-name "Customize face" "all faces" t)))
1154 (if (member face '(nil ""))
1155 (setq face (face-list)))
1156 (if (and (listp face) (null (cdr face)))
1157 (setq face (car face)))
1158 (if (listp face)
1159 (custom-buffer-create (custom-sort-items
1160 (mapcar (lambda (s)
1161 (list s 'custom-face))
1162 face)
1163 t nil)
1164 "*Customize Faces*")
1165 ;; If FACE is actually an alias, customize the face it is aliased to.
1166 (if (get face 'face-alias)
1167 (setq face (get face 'face-alias)))
1168 (unless (facep face)
1169 (error "Invalid face %S" face))
1170 (custom-buffer-create (list (list face 'custom-face))
1171 (format "*Customize Face: %s*"
1172 (custom-unlispify-tag-name face)))))
1174 ;;;###autoload
1175 (defun customize-face-other-window (&optional face)
1176 "Show customization buffer for face FACE in other window.
1177 If FACE is actually a face-alias, customize the face it is aliased to.
1179 Interactively, when point is on text which has a face specified,
1180 suggest to customize that face, if it's customizable."
1181 (interactive
1182 (list (read-face-name "Customize face" "all faces" t)))
1183 (if (member face '(nil ""))
1184 (setq face (face-list)))
1185 (if (and (listp face) (null (cdr face)))
1186 (setq face (car face)))
1187 (if (listp face)
1188 (custom-buffer-create-other-window
1189 (custom-sort-items
1190 (mapcar (lambda (s)
1191 (list s 'custom-face))
1192 face)
1193 t nil)
1194 "*Customize Faces*")
1195 (if (get face 'face-alias)
1196 (setq face (get face 'face-alias)))
1197 (unless (facep face)
1198 (error "Invalid face %S" face))
1199 (custom-buffer-create-other-window
1200 (list (list face 'custom-face))
1201 (format "*Customize Face: %s*"
1202 (custom-unlispify-tag-name face)))))
1204 ;;;###autoload
1205 (defun customize-customized ()
1206 "Customize all user options set since the last save in this session."
1207 (interactive)
1208 (let ((found nil))
1209 (mapatoms (lambda (symbol)
1210 (and (or (get symbol 'customized-face)
1211 (get symbol 'customized-face-comment))
1212 (custom-facep symbol)
1213 (push (list symbol 'custom-face) found))
1214 (and (or (get symbol 'customized-value)
1215 (get symbol 'customized-variable-comment))
1216 (boundp symbol)
1217 (push (list symbol 'custom-variable) found))))
1218 (if (not found)
1219 (error "No customized user options")
1220 (custom-buffer-create (custom-sort-items found t nil)
1221 "*Customize Customized*"))))
1223 ;;;###autoload
1224 (defun customize-rogue ()
1225 "Customize all user variable modified outside customize."
1226 (interactive)
1227 (let ((found nil))
1228 (mapatoms (lambda (symbol)
1229 (let ((cval (or (get symbol 'customized-value)
1230 (get symbol 'saved-value)
1231 (get symbol 'standard-value))))
1232 (when (and cval ;Declared with defcustom.
1233 (default-boundp symbol) ;Has a value.
1234 (not (equal (eval (car cval))
1235 ;; Which does not match customize.
1236 (default-value symbol))))
1237 (push (list symbol 'custom-variable) found)))))
1238 (if (not found)
1239 (error "No rogue user options")
1240 (custom-buffer-create (custom-sort-items found t nil)
1241 "*Customize Rogue*"))))
1242 ;;;###autoload
1243 (defun customize-saved ()
1244 "Customize all already saved user options."
1245 (interactive)
1246 (let ((found nil))
1247 (mapatoms (lambda (symbol)
1248 (and (or (get symbol 'saved-face)
1249 (get symbol 'saved-face-comment))
1250 (custom-facep symbol)
1251 (push (list symbol 'custom-face) found))
1252 (and (or (get symbol 'saved-value)
1253 (get symbol 'saved-variable-comment))
1254 (boundp symbol)
1255 (push (list symbol 'custom-variable) found))))
1256 (if (not found )
1257 (error "No saved user options")
1258 (custom-buffer-create (custom-sort-items found t nil)
1259 "*Customize Saved*"))))
1261 ;;;###autoload
1262 (defun customize-apropos (regexp &optional all)
1263 "Customize all loaded options, faces and groups matching REGEXP.
1264 If ALL is `options', include only options.
1265 If ALL is `faces', include only faces.
1266 If ALL is `groups', include only groups.
1267 If ALL is t (interactively, with prefix arg), include variables
1268 that are not customizable options, as well as faces and groups
1269 \(but we recommend using `apropos-variable' instead)."
1270 (interactive "sCustomize regexp: \nP")
1271 (let ((found nil))
1272 (mapatoms (lambda (symbol)
1273 (when (string-match regexp (symbol-name symbol))
1274 (when (and (not (memq all '(faces options)))
1275 (get symbol 'custom-group))
1276 (push (list symbol 'custom-group) found))
1277 (when (and (not (memq all '(options groups)))
1278 (custom-facep symbol))
1279 (push (list symbol 'custom-face) found))
1280 (when (and (not (memq all '(groups faces)))
1281 (boundp symbol)
1282 (eq (indirect-variable symbol) symbol)
1283 (or (get symbol 'saved-value)
1284 (custom-variable-p symbol)
1285 (and (not (memq all '(nil options)))
1286 (get symbol 'variable-documentation))))
1287 (push (list symbol 'custom-variable) found)))))
1288 (if (not found)
1289 (error "No matches")
1290 (custom-buffer-create (custom-sort-items found t
1291 custom-buffer-order-groups)
1292 "*Customize Apropos*"))))
1294 ;;;###autoload
1295 (defun customize-apropos-options (regexp &optional arg)
1296 "Customize all loaded customizable options matching REGEXP.
1297 With prefix arg, include variables that are not customizable options
1298 \(but we recommend using `apropos-variable' instead)."
1299 (interactive "sCustomize regexp: \nP")
1300 (customize-apropos regexp (or arg 'options)))
1302 ;;;###autoload
1303 (defun customize-apropos-faces (regexp)
1304 "Customize all loaded faces matching REGEXP."
1305 (interactive "sCustomize regexp: \n")
1306 (customize-apropos regexp 'faces))
1308 ;;;###autoload
1309 (defun customize-apropos-groups (regexp)
1310 "Customize all loaded groups matching REGEXP."
1311 (interactive "sCustomize regexp: \n")
1312 (customize-apropos regexp 'groups))
1314 ;;; Buffer.
1316 (defcustom custom-buffer-style 'links
1317 "Control the presentation style for customization buffers.
1318 The value should be a symbol, one of:
1320 brackets: groups nest within each other with big horizontal brackets.
1321 links: groups have links to subgroups."
1322 :type '(radio (const brackets)
1323 (const links))
1324 :group 'custom-buffer)
1326 (defcustom custom-buffer-done-kill nil
1327 "*Non-nil means exiting a Custom buffer should kill it."
1328 :type 'boolean
1329 :version "22.1"
1330 :group 'custom-buffer)
1332 (defcustom custom-buffer-indent 3
1333 "Number of spaces to indent nested groups."
1334 :type 'integer
1335 :group 'custom-buffer)
1337 (defun custom-get-fresh-buffer (name)
1338 "Get a fresh new buffer with name NAME.
1339 If the buffer already exist, clean it up to be like new.
1340 Beware: it's not quite like new. Good enough for custom, but maybe
1341 not for everybody."
1342 ;; To be more complete, we should also kill all permanent-local variables,
1343 ;; but it's not needed for custom.
1344 (let ((buf (get-buffer name)))
1345 (when (and buf (buffer-local-value 'buffer-file-name buf))
1346 ;; This will check if the file is not saved.
1347 (kill-buffer buf)
1348 (setq buf nil))
1349 (if (null buf)
1350 (get-buffer-create name)
1351 (with-current-buffer buf
1352 (kill-all-local-variables)
1353 (run-hooks 'kill-buffer-hook)
1354 ;; Delete overlays before erasing the buffer so the overlay hooks
1355 ;; don't get run spuriously when we erase the buffer.
1356 (let ((ols (overlay-lists)))
1357 (dolist (ol (nconc (car ols) (cdr ols)))
1358 (delete-overlay ol)))
1359 (erase-buffer)
1360 buf))))
1362 ;;;###autoload
1363 (defun custom-buffer-create (options &optional name description)
1364 "Create a buffer containing OPTIONS.
1365 Optional NAME is the name of the buffer.
1366 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1367 SYMBOL is a customization option, and WIDGET is a widget for editing
1368 that option."
1369 (pop-to-buffer (custom-get-fresh-buffer (or name "*Customization*")))
1370 (custom-buffer-create-internal options description))
1372 ;;;###autoload
1373 (defun custom-buffer-create-other-window (options &optional name description)
1374 "Create a buffer containing OPTIONS, and display it in another window.
1375 The result includes selecting that window.
1376 Optional NAME is the name of the buffer.
1377 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1378 SYMBOL is a customization option, and WIDGET is a widget for editing
1379 that option."
1380 (unless name (setq name "*Customization*"))
1381 (let ((pop-up-windows t)
1382 (same-window-buffer-names nil)
1383 (same-window-regexps nil))
1384 (pop-to-buffer (custom-get-fresh-buffer name))
1385 (custom-buffer-create-internal options description)))
1387 (defcustom custom-reset-button-menu nil
1388 "If non-nil, only show a single reset button in customize buffers.
1389 This button will have a menu with all three reset operations."
1390 :type 'boolean
1391 :group 'custom-buffer)
1393 (defcustom custom-buffer-verbose-help t
1394 "If non-nil, include explanatory text in the customization buffer."
1395 :type 'boolean
1396 :group 'custom-buffer)
1398 (defun Custom-buffer-done (&rest ignore)
1399 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1400 (interactive)
1401 (quit-window custom-buffer-done-kill))
1403 (defvar custom-button nil
1404 "Face used for buttons in customization buffers.")
1406 (defvar custom-button-pressed nil
1407 "Face used for pressed buttons in customization buffers.")
1409 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1410 '(("unspecified" . unspecified))))
1411 "If non-nil, indicate active buttons in a `raised-button' style.
1412 Otherwise use brackets."
1413 :type 'boolean
1414 :version "21.1"
1415 :group 'custom-buffer
1416 :set (lambda (variable value)
1417 (custom-set-default variable value)
1418 (setq custom-button
1419 (if value 'custom-button 'custom-button-unraised))
1420 (setq custom-button-pressed
1421 (if value
1422 'custom-button-pressed
1423 'custom-button-pressed-unraised))))
1425 (defun custom-buffer-create-internal (options &optional description)
1426 (custom-mode)
1427 (if custom-buffer-verbose-help
1428 (progn
1429 (widget-insert "This is a customization buffer")
1430 (if description
1431 (widget-insert description))
1432 (widget-insert (format ".
1433 %s show active fields; type RET or click mouse-1
1434 on an active field to invoke its action. Editing an option value
1435 changes only the text in the buffer. Invoke the State button to set or
1436 save the option value. Saving an option normally edits your init file.
1437 Invoke "
1438 (if custom-raised-buttons
1439 "`Raised' buttons"
1440 "Square brackets")))
1441 (widget-create 'info-link
1442 :tag "Custom file"
1443 "(emacs)Saving Customizations")
1444 (widget-insert
1445 " for information on how to save in a different file.
1446 Invoke ")
1447 (widget-create 'info-link
1448 :tag "Help"
1449 :help-echo "Read the online help."
1450 "(emacs)Easy Customization")
1451 (widget-insert " for general information.\n\n")
1452 (widget-insert "Operate on everything in this buffer:\n "))
1453 (widget-insert " "))
1454 (widget-create 'push-button
1455 :tag "Set for Current Session"
1456 :help-echo "\
1457 Make your editing in this buffer take effect for this session."
1458 :action (lambda (widget &optional event)
1459 (Custom-set)))
1460 (widget-insert " ")
1461 (widget-create 'push-button
1462 :tag "Save for Future Sessions"
1463 :help-echo "\
1464 Make your editing in this buffer take effect for future Emacs sessions.
1465 This updates your Emacs initialization file or creates a new one."
1466 :action (lambda (widget &optional event)
1467 (Custom-save)))
1468 (if custom-reset-button-menu
1469 (progn
1470 (widget-insert " ")
1471 (widget-create 'push-button
1472 :tag "Reset"
1473 :help-echo "Show a menu with reset operations."
1474 :mouse-down-action (lambda (&rest junk) t)
1475 :action (lambda (widget &optional event)
1476 (custom-reset event))))
1477 (widget-insert "\n ")
1478 (widget-create 'push-button
1479 :tag "Reset to Current"
1480 :help-echo "\
1481 Reset all edited text in this buffer to reflect current values."
1482 :action 'Custom-reset-current)
1483 (widget-insert " ")
1484 (widget-create 'push-button
1485 :tag "Reset to Saved"
1486 :help-echo "\
1487 Reset all values in this buffer to their saved settings."
1488 :action 'Custom-reset-saved)
1489 (widget-insert " ")
1490 (widget-create 'push-button
1491 :tag "Erase Customization"
1492 :help-echo "\
1493 Un-customize all values in this buffer. They get their standard settings."
1494 :action 'Custom-reset-standard))
1495 (if (not custom-buffer-verbose-help)
1496 (progn
1497 (widget-insert " ")
1498 (widget-create 'info-link
1499 :tag "Help"
1500 :help-echo "Read the online help."
1501 "(emacs)Easy Customization")))
1502 (widget-insert " ")
1503 (widget-create 'push-button
1504 :tag "Finish"
1505 :help-echo
1506 (lambda (&rest ignore)
1507 (if custom-buffer-done-kill
1508 "Kill this buffer"
1509 "Bury this buffer"))
1510 :action #'Custom-buffer-done)
1511 (widget-insert "\n\n")
1512 (message "Creating customization items...")
1513 (buffer-disable-undo)
1514 (setq custom-options
1515 (if (= (length options) 1)
1516 (mapcar (lambda (entry)
1517 (widget-create (nth 1 entry)
1518 :documentation-shown t
1519 :custom-state 'unknown
1520 :tag (custom-unlispify-tag-name
1521 (nth 0 entry))
1522 :value (nth 0 entry)))
1523 options)
1524 (let ((count 0)
1525 (length (length options)))
1526 (mapcar (lambda (entry)
1527 (prog2
1528 (message "Creating customization items ...%2d%%"
1529 (/ (* 100.0 count) length))
1530 (widget-create (nth 1 entry)
1531 :tag (custom-unlispify-tag-name
1532 (nth 0 entry))
1533 :value (nth 0 entry))
1534 (setq count (1+ count))
1535 (unless (eq (preceding-char) ?\n)
1536 (widget-insert "\n"))
1537 (widget-insert "\n")))
1538 options))))
1539 (unless (eq (preceding-char) ?\n)
1540 (widget-insert "\n"))
1541 (message "Creating customization items ...done")
1542 (message "Resetting customization items...")
1543 (unless (eq custom-buffer-style 'tree)
1544 (mapc 'custom-magic-reset custom-options))
1545 (message "Resetting customization items...done")
1546 (message "Creating customization setup...")
1547 (widget-setup)
1548 (buffer-enable-undo)
1549 (goto-char (point-min))
1550 (message "Creating customization setup...done"))
1552 ;;; The Tree Browser.
1554 ;;;###autoload
1555 (defun customize-browse (&optional group)
1556 "Create a tree browser for the customize hierarchy."
1557 (interactive)
1558 (unless group
1559 (setq group 'emacs))
1560 (let ((name "*Customize Browser*"))
1561 (pop-to-buffer (custom-get-fresh-buffer name)))
1562 (custom-mode)
1563 (widget-insert "\
1564 Square brackets show active fields; type RET or click mouse-1
1565 on an active field to invoke its action.
1566 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1567 (if custom-browse-only-groups
1568 (widget-insert "\
1569 Invoke the [Group] button below to edit that item in another window.\n\n")
1570 (widget-insert "Invoke the ")
1571 (widget-create 'item
1572 :format "%t"
1573 :tag "[Group]"
1574 :tag-glyph "folder")
1575 (widget-insert ", ")
1576 (widget-create 'item
1577 :format "%t"
1578 :tag "[Face]"
1579 :tag-glyph "face")
1580 (widget-insert ", and ")
1581 (widget-create 'item
1582 :format "%t"
1583 :tag "[Option]"
1584 :tag-glyph "option")
1585 (widget-insert " buttons below to edit that
1586 item in another window.\n\n"))
1587 (let ((custom-buffer-style 'tree))
1588 (widget-create 'custom-group
1589 :custom-last t
1590 :custom-state 'unknown
1591 :tag (custom-unlispify-tag-name group)
1592 :value group))
1593 (widget-setup)
1594 (goto-char (point-min)))
1596 (define-widget 'custom-browse-visibility 'item
1597 "Control visibility of items in the customize tree browser."
1598 :format "%[[%t]%]"
1599 :action 'custom-browse-visibility-action)
1601 (defun custom-browse-visibility-action (widget &rest ignore)
1602 (let ((custom-buffer-style 'tree))
1603 (custom-toggle-parent widget)))
1605 (define-widget 'custom-browse-group-tag 'push-button
1606 "Show parent in other window when activated."
1607 :tag "Group"
1608 :tag-glyph "folder"
1609 :action 'custom-browse-group-tag-action)
1611 (defun custom-browse-group-tag-action (widget &rest ignore)
1612 (let ((parent (widget-get widget :parent)))
1613 (customize-group-other-window (widget-value parent))))
1615 (define-widget 'custom-browse-variable-tag 'push-button
1616 "Show parent in other window when activated."
1617 :tag "Option"
1618 :tag-glyph "option"
1619 :action 'custom-browse-variable-tag-action)
1621 (defun custom-browse-variable-tag-action (widget &rest ignore)
1622 (let ((parent (widget-get widget :parent)))
1623 (customize-variable-other-window (widget-value parent))))
1625 (define-widget 'custom-browse-face-tag 'push-button
1626 "Show parent in other window when activated."
1627 :tag "Face"
1628 :tag-glyph "face"
1629 :action 'custom-browse-face-tag-action)
1631 (defun custom-browse-face-tag-action (widget &rest ignore)
1632 (let ((parent (widget-get widget :parent)))
1633 (customize-face-other-window (widget-value parent))))
1635 (defconst custom-browse-alist '((" " "space")
1636 (" | " "vertical")
1637 ("-\\ " "top")
1638 (" |-" "middle")
1639 (" `-" "bottom")))
1641 (defun custom-browse-insert-prefix (prefix)
1642 "Insert PREFIX. On XEmacs convert it to line graphics."
1643 ;; Fixme: do graphics.
1644 (if nil ; (string-match "XEmacs" emacs-version)
1645 (progn
1646 (insert "*")
1647 (while (not (string-equal prefix ""))
1648 (let ((entry (substring prefix 0 3)))
1649 (setq prefix (substring prefix 3))
1650 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1651 (name (nth 1 (assoc entry custom-browse-alist))))
1652 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1653 (overlay-put overlay 'start-open t)
1654 (overlay-put overlay 'end-open t)))))
1655 (insert prefix)))
1657 ;;; Modification of Basic Widgets.
1659 ;; We add extra properties to the basic widgets needed here. This is
1660 ;; fine, as long as we are careful to stay within out own namespace.
1662 ;; We want simple widgets to be displayed by default, but complex
1663 ;; widgets to be hidden.
1665 (widget-put (get 'item 'widget-type) :custom-show t)
1666 (widget-put (get 'editable-field 'widget-type)
1667 :custom-show (lambda (widget value)
1668 (let ((pp (pp-to-string value)))
1669 (cond ((string-match "\n" pp)
1670 nil)
1671 ((> (length pp) 40)
1672 nil)
1673 (t t)))))
1674 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1676 ;;; The `custom-manual' Widget.
1678 (define-widget 'custom-manual 'info-link
1679 "Link to the manual entry for this customization option."
1680 :help-echo "Read the manual entry for this option."
1681 :tag "Manual")
1683 ;;; The `custom-magic' Widget.
1685 (defgroup custom-magic-faces nil
1686 "Faces used by the magic button."
1687 :group 'custom-faces
1688 :group 'custom-buffer)
1690 (defface custom-invalid '((((class color))
1691 (:foreground "yellow1" :background "red1"))
1693 (:weight bold :slant italic :underline t)))
1694 "Face used when the customize item is invalid."
1695 :group 'custom-magic-faces)
1696 ;; backward-compatibility alias
1697 (put 'custom-invalid-face 'face-alias 'custom-invalid)
1699 (defface custom-rogue '((((class color))
1700 (:foreground "pink" :background "black"))
1702 (:underline t)))
1703 "Face used when the customize item is not defined for customization."
1704 :group 'custom-magic-faces)
1705 ;; backward-compatibility alias
1706 (put 'custom-rogue-face 'face-alias 'custom-rogue)
1708 (defface custom-modified '((((min-colors 88) (class color))
1709 (:foreground "white" :background "blue1"))
1710 (((class color))
1711 (:foreground "white" :background "blue"))
1713 (:slant italic :bold)))
1714 "Face used when the customize item has been modified."
1715 :group 'custom-magic-faces)
1716 ;; backward-compatibility alias
1717 (put 'custom-modified-face 'face-alias 'custom-modified)
1719 (defface custom-set '((((min-colors 88) (class color))
1720 (:foreground "blue1" :background "white"))
1721 (((class color))
1722 (:foreground "blue" :background "white"))
1724 (:slant italic)))
1725 "Face used when the customize item has been set."
1726 :group 'custom-magic-faces)
1727 ;; backward-compatibility alias
1728 (put 'custom-set-face 'face-alias 'custom-set)
1730 (defface custom-changed '((((min-colors 88) (class color))
1731 (:foreground "white" :background "blue1"))
1732 (((class color))
1733 (:foreground "white" :background "blue"))
1735 (:slant italic)))
1736 "Face used when the customize item has been changed."
1737 :group 'custom-magic-faces)
1738 ;; backward-compatibility alias
1739 (put 'custom-changed-face 'face-alias 'custom-changed)
1741 (defface custom-saved '((t (:underline t)))
1742 "Face used when the customize item has been saved."
1743 :group 'custom-magic-faces)
1744 ;; backward-compatibility alias
1745 (put 'custom-saved-face 'face-alias 'custom-saved)
1747 (defconst custom-magic-alist
1748 '((nil "#" underline "\
1749 UNINITIALIZED, you should not see this.")
1750 (unknown "?" italic "\
1751 UNKNOWN, you should not see this.")
1752 (hidden "-" default "\
1753 HIDDEN, invoke \"Show\" in the previous line to show." "\
1754 group now hidden, invoke \"Show\", above, to show contents.")
1755 (invalid "x" custom-invalid "\
1756 INVALID, the displayed value cannot be set.")
1757 (modified "*" custom-modified "\
1758 EDITED, shown value does not take effect until you set or save it." "\
1759 something in this group has been edited but not set.")
1760 (set "+" custom-set "\
1761 SET for current session only." "\
1762 something in this group has been set but not saved.")
1763 (changed ":" custom-changed "\
1764 CHANGED outside Customize; operating on it here may be unreliable." "\
1765 something in this group has been changed outside customize.")
1766 (saved "!" custom-saved "\
1767 SAVED and set." "\
1768 something in this group has been set and saved.")
1769 (rogue "@" custom-rogue "\
1770 NO CUSTOMIZATION DATA; not intended to be customized." "\
1771 something in this group is not prepared for customization.")
1772 (standard " " nil "\
1773 STANDARD." "\
1774 visible group members are all at standard settings."))
1775 "Alist of customize option states.
1776 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1778 STATE is one of the following symbols:
1780 `nil'
1781 For internal use, should never occur.
1782 `unknown'
1783 For internal use, should never occur.
1784 `hidden'
1785 This item is not being displayed.
1786 `invalid'
1787 This item is modified, but has an invalid form.
1788 `modified'
1789 This item is modified, and has a valid form.
1790 `set'
1791 This item has been set but not saved.
1792 `changed'
1793 The current value of this item has been changed outside Customize.
1794 `saved'
1795 This item is marked for saving.
1796 `rogue'
1797 This item has no customization information.
1798 `standard'
1799 This item is unchanged from the standard setting.
1801 MAGIC is a string used to present that state.
1803 FACE is a face used to present the state.
1805 ITEM-DESC is a string describing the state for options.
1807 GROUP-DESC is a string describing the state for groups. If this is
1808 left out, ITEM-DESC will be used.
1810 The string %c in either description will be replaced with the
1811 category of the item. These are `group'. `option', and `face'.
1813 The list should be sorted most significant first.")
1815 (defcustom custom-magic-show 'long
1816 "If non-nil, show textual description of the state.
1817 If `long', show a full-line description, not just one word."
1818 :type '(choice (const :tag "no" nil)
1819 (const long)
1820 (other :tag "short" short))
1821 :group 'custom-buffer)
1823 (defcustom custom-magic-show-hidden '(option face)
1824 "Control whether the State button is shown for hidden items.
1825 The value should be a list with the custom categories where the State
1826 button should be visible. Possible categories are `group', `option',
1827 and `face'."
1828 :type '(set (const group) (const option) (const face))
1829 :group 'custom-buffer)
1831 (defcustom custom-magic-show-button nil
1832 "Show a \"magic\" button indicating the state of each customization option."
1833 :type 'boolean
1834 :group 'custom-buffer)
1836 (define-widget 'custom-magic 'default
1837 "Show and manipulate state for a customization option."
1838 :format "%v"
1839 :action 'widget-parent-action
1840 :notify 'ignore
1841 :value-get 'ignore
1842 :value-create 'custom-magic-value-create
1843 :value-delete 'widget-children-value-delete)
1845 (defun widget-magic-mouse-down-action (widget &optional event)
1846 ;; Non-nil unless hidden.
1847 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1848 :custom-state)
1849 'hidden)))
1851 (defun custom-magic-value-create (widget)
1852 "Create compact status report for WIDGET."
1853 (let* ((parent (widget-get widget :parent))
1854 (state (widget-get parent :custom-state))
1855 (hidden (eq state 'hidden))
1856 (entry (assq state custom-magic-alist))
1857 (magic (nth 1 entry))
1858 (face (nth 2 entry))
1859 (category (widget-get parent :custom-category))
1860 (text (or (and (eq category 'group)
1861 (nth 4 entry))
1862 (nth 3 entry)))
1863 (form (widget-get parent :custom-form))
1864 children)
1865 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1866 (setq text (concat (match-string 1 text)
1867 (symbol-name category)
1868 (match-string 2 text))))
1869 (when (and custom-magic-show
1870 (or (not hidden)
1871 (memq category custom-magic-show-hidden)))
1872 (insert " ")
1873 (when (and (eq category 'group)
1874 (not (and (eq custom-buffer-style 'links)
1875 (> (widget-get parent :custom-level) 1))))
1876 (insert-char ?\ (* custom-buffer-indent
1877 (widget-get parent :custom-level))))
1878 (push (widget-create-child-and-convert
1879 widget 'choice-item
1880 :help-echo "Change the state of this item."
1881 :format (if hidden "%t" "%[%t%]")
1882 :button-prefix 'widget-push-button-prefix
1883 :button-suffix 'widget-push-button-suffix
1884 :mouse-down-action 'widget-magic-mouse-down-action
1885 :tag "State")
1886 children)
1887 (insert ": ")
1888 (let ((start (point)))
1889 (if (eq custom-magic-show 'long)
1890 (insert text)
1891 (insert (symbol-name state)))
1892 (cond ((eq form 'lisp)
1893 (insert " (lisp)"))
1894 ((eq form 'mismatch)
1895 (insert " (mismatch)")))
1896 (put-text-property start (point) 'face 'custom-state))
1897 (insert "\n"))
1898 (when (and (eq category 'group)
1899 (not (and (eq custom-buffer-style 'links)
1900 (> (widget-get parent :custom-level) 1))))
1901 (insert-char ?\ (* custom-buffer-indent
1902 (widget-get parent :custom-level))))
1903 (when custom-magic-show-button
1904 (when custom-magic-show
1905 (let ((indent (widget-get parent :indent)))
1906 (when indent
1907 (insert-char ? indent))))
1908 (push (widget-create-child-and-convert
1909 widget 'choice-item
1910 :mouse-down-action 'widget-magic-mouse-down-action
1911 :button-face face
1912 :button-prefix ""
1913 :button-suffix ""
1914 :help-echo "Change the state."
1915 :format (if hidden "%t" "%[%t%]")
1916 :tag (if (memq form '(lisp mismatch))
1917 (concat "(" magic ")")
1918 (concat "[" magic "]")))
1919 children)
1920 (insert " "))
1921 (widget-put widget :children children)))
1923 (defun custom-magic-reset (widget)
1924 "Redraw the :custom-magic property of WIDGET."
1925 (let ((magic (widget-get widget :custom-magic)))
1926 (widget-value-set magic (widget-value magic))))
1928 ;;; The `custom' Widget.
1930 (defface custom-button
1931 '((((type x w32 mac) (class color)) ; Like default modeline
1932 (:box (:line-width 2 :style released-button)
1933 :background "lightgrey" :foreground "black"))
1935 nil))
1936 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
1937 :version "21.1"
1938 :group 'custom-faces)
1939 ;; backward-compatibility alias
1940 (put 'custom-button-face 'face-alias 'custom-button)
1942 (defface custom-button-unraised
1943 '((((min-colors 88)
1944 (class color) (background light)) :foreground "blue1" :underline t)
1945 (((class color) (background light)) :foreground "blue" :underline t)
1946 (((min-colors 88)
1947 (class color) (background dark)) :foreground "cyan1" :underline t)
1948 (((class color) (background dark)) :foreground "cyan" :underline t)
1949 (t :underline t))
1950 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
1951 :version "22.1"
1952 :group 'custom-faces)
1954 (setq custom-button
1955 (if custom-raised-buttons 'custom-button 'custom-button-unraised))
1957 (defface custom-button-pressed
1958 '((((type x w32 mac) (class color))
1959 (:box (:line-width 2 :style pressed-button)
1960 :background "lightgrey" :foreground "black"))
1962 (:inverse-video t)))
1963 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
1964 :version "21.1"
1965 :group 'custom-faces)
1966 ;; backward-compatibility alias
1967 (put 'custom-button-pressed-face 'face-alias 'custom-button-pressed)
1969 (defface custom-button-pressed-unraised
1970 '((default :inherit custom-button-unraised)
1971 (((class color) (background light)) :foreground "magenta4")
1972 (((class color) (background dark)) :foreground "violet"))
1973 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
1974 :version "22.1"
1975 :group 'custom-faces)
1977 (setq custom-button-pressed
1978 (if custom-raised-buttons
1979 'custom-button-pressed
1980 'custom-button-pressed-unraised))
1982 (defface custom-documentation nil
1983 "Face used for documentation strings in customization buffers."
1984 :group 'custom-faces)
1985 ;; backward-compatibility alias
1986 (put 'custom-documentation-face 'face-alias 'custom-documentation)
1988 (defface custom-state '((((class color)
1989 (background dark))
1990 (:foreground "lime green"))
1991 (((class color)
1992 (background light))
1993 (:foreground "dark green"))
1994 (t nil))
1995 "Face used for State descriptions in the customize buffer."
1996 :group 'custom-faces)
1997 ;; backward-compatibility alias
1998 (put 'custom-state-face 'face-alias 'custom-state)
2000 (define-widget 'custom 'default
2001 "Customize a user option."
2002 :format "%v"
2003 :convert-widget 'custom-convert-widget
2004 :notify 'custom-notify
2005 :custom-prefix ""
2006 :custom-level 1
2007 :custom-state 'hidden
2008 :documentation-property 'widget-subclass-responsibility
2009 :value-create 'widget-subclass-responsibility
2010 :value-delete 'widget-children-value-delete
2011 :value-get 'widget-value-value-get
2012 :validate 'widget-children-validate
2013 :match (lambda (widget value) (symbolp value)))
2015 (defun custom-convert-widget (widget)
2016 "Initialize :value and :tag from :args in WIDGET."
2017 (let ((args (widget-get widget :args)))
2018 (when args
2019 (widget-put widget :value (widget-apply widget
2020 :value-to-internal (car args)))
2021 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
2022 (widget-put widget :args nil)))
2023 widget)
2025 (defun custom-notify (widget &rest args)
2026 "Keep track of changes."
2027 (let ((state (widget-get widget :custom-state)))
2028 (unless (eq state 'modified)
2029 (unless (memq state '(nil unknown hidden))
2030 (widget-put widget :custom-state 'modified))
2031 (custom-magic-reset widget)
2032 (apply 'widget-default-notify widget args))))
2034 (defun custom-redraw (widget)
2035 "Redraw WIDGET with current settings."
2036 (let ((line (count-lines (point-min) (point)))
2037 (column (current-column))
2038 (pos (point))
2039 (from (marker-position (widget-get widget :from)))
2040 (to (marker-position (widget-get widget :to))))
2041 (save-excursion
2042 (widget-value-set widget (widget-value widget))
2043 (custom-redraw-magic widget))
2044 (when (and (>= pos from) (<= pos to))
2045 (condition-case nil
2046 (progn
2047 (if (> column 0)
2048 (goto-line line)
2049 (goto-line (1+ line)))
2050 (move-to-column column))
2051 (error nil)))))
2053 (defun custom-redraw-magic (widget)
2054 "Redraw WIDGET state with current settings."
2055 (while widget
2056 (let ((magic (widget-get widget :custom-magic)))
2057 (cond (magic
2058 (widget-value-set magic (widget-value magic))
2059 (when (setq widget (widget-get widget :group))
2060 (custom-group-state-update widget)))
2062 (setq widget nil)))))
2063 (widget-setup))
2065 (defun custom-show (widget value)
2066 "Non-nil if WIDGET should be shown with VALUE by default."
2067 (let ((show (widget-get widget :custom-show)))
2068 (cond ((null show)
2069 nil)
2070 ((eq t show)
2073 (funcall show widget value)))))
2075 (defun custom-load-widget (widget)
2076 "Load all dependencies for WIDGET."
2077 (custom-load-symbol (widget-value widget)))
2079 (defun custom-unloaded-symbol-p (symbol)
2080 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2081 (let ((found nil)
2082 (loads (get symbol 'custom-loads))
2083 load)
2084 (while loads
2085 (setq load (car loads)
2086 loads (cdr loads))
2087 (cond ((symbolp load)
2088 (unless (featurep load)
2089 (setq found t)))
2090 ((assoc load load-history))
2091 ((assoc (locate-library load) load-history)
2092 (message nil))
2094 (setq found t))))
2095 found))
2097 (defun custom-unloaded-widget-p (widget)
2098 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2099 (custom-unloaded-symbol-p (widget-value widget)))
2101 (defun custom-toggle-hide (widget)
2102 "Toggle visibility of WIDGET."
2103 (custom-load-widget widget)
2104 (let ((state (widget-get widget :custom-state)))
2105 (cond ((memq state '(invalid modified))
2106 (error "There are unset changes"))
2107 ((eq state 'hidden)
2108 (widget-put widget :custom-state 'unknown))
2110 (widget-put widget :documentation-shown nil)
2111 (widget-put widget :custom-state 'hidden)))
2112 (custom-redraw widget)
2113 (widget-setup)))
2115 (defun custom-toggle-parent (widget &rest ignore)
2116 "Toggle visibility of parent of WIDGET."
2117 (custom-toggle-hide (widget-get widget :parent)))
2119 (defun custom-add-see-also (widget &optional prefix)
2120 "Add `See also ...' to WIDGET if there are any links.
2121 Insert PREFIX first if non-nil."
2122 (let* ((symbol (widget-get widget :value))
2123 (links (get symbol 'custom-links))
2124 (many (> (length links) 2))
2125 (buttons (widget-get widget :buttons))
2126 (indent (widget-get widget :indent)))
2127 (when links
2128 (when indent
2129 (insert-char ?\ indent))
2130 (when prefix
2131 (insert prefix))
2132 (insert "See also ")
2133 (while links
2134 (push (widget-create-child-and-convert widget (car links))
2135 buttons)
2136 (setq links (cdr links))
2137 (cond ((null links)
2138 (insert ".\n"))
2139 ((null (cdr links))
2140 (if many
2141 (insert ", and ")
2142 (insert " and ")))
2144 (insert ", "))))
2145 (widget-put widget :buttons buttons))))
2147 (defun custom-add-parent-links (widget &optional initial-string)
2148 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2149 The value is non-nil if any parents were found.
2150 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2151 (let ((name (widget-value widget))
2152 (type (widget-type widget))
2153 (buttons (widget-get widget :buttons))
2154 (start (point))
2155 (parents nil))
2156 (insert (or initial-string "Parent groups:"))
2157 (mapatoms (lambda (symbol)
2158 (when (member (list name type) (get symbol 'custom-group))
2159 (insert " ")
2160 (push (widget-create-child-and-convert
2161 widget 'custom-group-link
2162 :tag (custom-unlispify-tag-name symbol)
2163 symbol)
2164 buttons)
2165 (setq parents (cons symbol parents)))))
2166 (and (null (get name 'custom-links)) ;No links of its own.
2167 (= (length parents) 1) ;A single parent.
2168 (let* ((links (delq nil (mapcar (lambda (w)
2169 (unless (eq (widget-type w)
2170 'custom-group-link)
2172 (get (car parents) 'custom-links))))
2173 (many (> (length links) 2)))
2174 (when links
2175 (insert "\nParent documentation: ")
2176 (while links
2177 (push (widget-create-child-and-convert widget (car links))
2178 buttons)
2179 (setq links (cdr links))
2180 (cond ((null links)
2181 (insert ".\n"))
2182 ((null (cdr links))
2183 (if many
2184 (insert ", and ")
2185 (insert " and ")))
2187 (insert ", ")))))))
2188 (if parents
2189 (insert "\n")
2190 (delete-region start (point)))
2191 (widget-put widget :buttons buttons)
2192 parents))
2194 ;;; The `custom-comment' Widget.
2196 ;; like the editable field
2197 (defface custom-comment '((((class grayscale color)
2198 (background light))
2199 (:background "gray85"))
2200 (((class grayscale color)
2201 (background dark))
2202 (:background "dim gray"))
2204 (:slant italic)))
2205 "Face used for comments on variables or faces"
2206 :version "21.1"
2207 :group 'custom-faces)
2208 ;; backward-compatibility alias
2209 (put 'custom-comment-face 'face-alias 'custom-comment)
2211 ;; like font-lock-comment-face
2212 (defface custom-comment-tag
2213 '((((class color) (background dark)) (:foreground "gray80"))
2214 (((class color) (background light)) (:foreground "blue4"))
2215 (((class grayscale) (background light))
2216 (:foreground "DimGray" :weight bold :slant italic))
2217 (((class grayscale) (background dark))
2218 (:foreground "LightGray" :weight bold :slant italic))
2219 (t (:weight bold)))
2220 "Face used for variables or faces comment tags"
2221 :group 'custom-faces)
2222 ;; backward-compatibility alias
2223 (put 'custom-comment-tag-face 'face-alias 'custom-comment-tag)
2225 (define-widget 'custom-comment 'string
2226 "User comment."
2227 :tag "Comment"
2228 :help-echo "Edit a comment here."
2229 :sample-face 'custom-comment-tag-face
2230 :value-face 'custom-comment-face
2231 :shown nil
2232 :create 'custom-comment-create)
2234 (defun custom-comment-create (widget)
2235 (let* ((null-comment (equal "" (widget-value widget))))
2236 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2237 (not null-comment))
2238 (widget-default-create widget)
2239 ;; `widget-default-delete' expects markers in these slots --
2240 ;; maybe it shouldn't.
2241 (widget-put widget :from (point-marker))
2242 (widget-put widget :to (point-marker)))))
2244 (defun custom-comment-hide (widget)
2245 (widget-put (widget-get widget :parent) :comment-shown nil))
2247 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2248 ;; the global custom one
2249 (defun custom-comment-show (widget)
2250 (widget-put widget :comment-shown t)
2251 (custom-redraw widget)
2252 (widget-setup))
2254 (defun custom-comment-invisible-p (widget)
2255 (let ((val (widget-value (widget-get widget :comment-widget))))
2256 (and (equal "" val)
2257 (not (widget-get widget :comment-shown)))))
2259 ;;; The `custom-variable' Widget.
2261 ;; When this was underlined blue, users confused it with a
2262 ;; Mosaic-style hyperlink...
2263 (defface custom-variable-tag
2264 `((((class color)
2265 (background dark))
2266 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
2267 (((min-colors 88) (class color)
2268 (background light))
2269 (:foreground "blue1" :weight bold :height 1.2 :inherit variable-pitch))
2270 (((class color)
2271 (background light))
2272 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
2273 (t (:weight bold)))
2274 "Face used for unpushable variable tags."
2275 :group 'custom-faces)
2276 ;; backward-compatibility alias
2277 (put 'custom-variable-tag-face 'face-alias 'custom-variable-tag)
2279 (defface custom-variable-button '((t (:underline t :weight bold)))
2280 "Face used for pushable variable tags."
2281 :group 'custom-faces)
2282 ;; backward-compatibility alias
2283 (put 'custom-variable-button-face 'face-alias 'custom-variable-button)
2285 (defcustom custom-variable-default-form 'edit
2286 "Default form of displaying variable values."
2287 :type '(choice (const edit)
2288 (const lisp))
2289 :group 'custom-buffer
2290 :version "20.3")
2292 (defun custom-variable-documentation (variable)
2293 "Return documentation of VARIABLE for use in Custom buffer.
2294 Normally just return the docstring. But if VARIABLE automatically
2295 becomes buffer local when set, append a message to that effect."
2296 (if (and (local-variable-if-set-p variable)
2297 (or (not (local-variable-p variable))
2298 (with-temp-buffer
2299 (local-variable-if-set-p variable))))
2300 (concat (documentation-property variable 'variable-documentation)
2302 This variable automatically becomes buffer-local when set outside Custom.
2303 However, setting it through Custom sets the default value.")
2304 (documentation-property variable 'variable-documentation)))
2306 (define-widget 'custom-variable 'custom
2307 "Customize variable."
2308 :format "%v"
2309 :help-echo "Set or reset this variable."
2310 :documentation-property #'custom-variable-documentation
2311 :custom-category 'option
2312 :custom-state nil
2313 :custom-menu 'custom-variable-menu-create
2314 :custom-form nil ; defaults to value of `custom-variable-default-form'
2315 :value-create 'custom-variable-value-create
2316 :action 'custom-variable-action
2317 :custom-set 'custom-variable-set
2318 :custom-save 'custom-variable-save
2319 :custom-reset-current 'custom-redraw
2320 :custom-reset-saved 'custom-variable-reset-saved
2321 :custom-reset-standard 'custom-variable-reset-standard
2322 :custom-standard-value 'custom-variable-standard-value)
2324 (defun custom-variable-type (symbol)
2325 "Return a widget suitable for editing the value of SYMBOL.
2326 If SYMBOL has a `custom-type' property, use that.
2327 Otherwise, look up symbol in `custom-guess-type-alist'."
2328 (let* ((type (or (get symbol 'custom-type)
2329 (and (not (get symbol 'standard-value))
2330 (custom-guess-type symbol))
2331 'sexp))
2332 (options (get symbol 'custom-options))
2333 (tmp (if (listp type)
2334 (copy-sequence type)
2335 (list type))))
2336 (when options
2337 (widget-put tmp :options options))
2338 tmp))
2340 (defun custom-variable-value-create (widget)
2341 "Here is where you edit the variable's value."
2342 (custom-load-widget widget)
2343 (unless (widget-get widget :custom-form)
2344 (widget-put widget :custom-form custom-variable-default-form))
2345 (let* ((buttons (widget-get widget :buttons))
2346 (children (widget-get widget :children))
2347 (form (widget-get widget :custom-form))
2348 (state (widget-get widget :custom-state))
2349 (symbol (widget-get widget :value))
2350 (tag (widget-get widget :tag))
2351 (type (custom-variable-type symbol))
2352 (conv (widget-convert type))
2353 (get (or (get symbol 'custom-get) 'default-value))
2354 (prefix (widget-get widget :custom-prefix))
2355 (last (widget-get widget :custom-last))
2356 (value (if (default-boundp symbol)
2357 (funcall get symbol)
2358 (widget-get conv :value))))
2359 ;; If the widget is new, the child determines whether it is hidden.
2360 (cond (state)
2361 ((custom-show type value)
2362 (setq state 'unknown))
2364 (setq state 'hidden)))
2365 ;; If we don't know the state, see if we need to edit it in lisp form.
2366 (when (eq state 'unknown)
2367 (unless (widget-apply conv :match value)
2368 ;; (widget-apply (widget-convert type) :match value)
2369 (setq form 'mismatch)))
2370 ;; Now we can create the child widget.
2371 (cond ((eq custom-buffer-style 'tree)
2372 (insert prefix (if last " `--- " " |--- "))
2373 (push (widget-create-child-and-convert
2374 widget 'custom-browse-variable-tag)
2375 buttons)
2376 (insert " " tag "\n")
2377 (widget-put widget :buttons buttons))
2378 ((eq state 'hidden)
2379 ;; Indicate hidden value.
2380 (push (widget-create-child-and-convert
2381 widget 'item
2382 :format "%{%t%}: "
2383 :sample-face 'custom-variable-tag-face
2384 :tag tag
2385 :parent widget)
2386 buttons)
2387 (push (widget-create-child-and-convert
2388 widget 'visibility
2389 :help-echo "Show the value of this option."
2390 :off "Show Value"
2391 :action 'custom-toggle-parent
2392 nil)
2393 buttons))
2394 ((memq form '(lisp mismatch))
2395 ;; In lisp mode edit the saved value when possible.
2396 (let* ((value (cond ((get symbol 'saved-value)
2397 (car (get symbol 'saved-value)))
2398 ((get symbol 'standard-value)
2399 (car (get symbol 'standard-value)))
2400 ((default-boundp symbol)
2401 (custom-quote (funcall get symbol)))
2403 (custom-quote (widget-get conv :value))))))
2404 (insert (symbol-name symbol) ": ")
2405 (push (widget-create-child-and-convert
2406 widget 'visibility
2407 :help-echo "Hide the value of this option."
2408 :on "Hide Value"
2409 :off "Show Value"
2410 :action 'custom-toggle-parent
2412 buttons)
2413 (insert " ")
2414 (push (widget-create-child-and-convert
2415 widget 'sexp
2416 :button-face 'custom-variable-button-face
2417 :format "%v"
2418 :tag (symbol-name symbol)
2419 :parent widget
2420 :value value)
2421 children)))
2423 ;; Edit mode.
2424 (let* ((format (widget-get type :format))
2425 tag-format value-format)
2426 (unless (string-match ":" format)
2427 (error "Bad format"))
2428 (setq tag-format (substring format 0 (match-end 0)))
2429 (setq value-format (substring format (match-end 0)))
2430 (push (widget-create-child-and-convert
2431 widget 'item
2432 :format tag-format
2433 :action 'custom-tag-action
2434 :help-echo "Change value of this option."
2435 :mouse-down-action 'custom-tag-mouse-down-action
2436 :button-face 'custom-variable-button-face
2437 :sample-face 'custom-variable-tag-face
2438 tag)
2439 buttons)
2440 (insert " ")
2441 (push (widget-create-child-and-convert
2442 widget 'visibility
2443 :help-echo "Hide the value of this option."
2444 :on "Hide Value"
2445 :off "Show Value"
2446 :action 'custom-toggle-parent
2448 buttons)
2449 (push (widget-create-child-and-convert
2450 widget type
2451 :format value-format
2452 :value value)
2453 children))))
2454 (unless (eq custom-buffer-style 'tree)
2455 (unless (eq (preceding-char) ?\n)
2456 (widget-insert "\n"))
2457 ;; Create the magic button.
2458 (let ((magic (widget-create-child-and-convert
2459 widget 'custom-magic nil)))
2460 (widget-put widget :custom-magic magic)
2461 (push magic buttons))
2462 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2463 ;; before the call to `widget-default-format-handler'. Otherwise, I
2464 ;; loose my current `buttons'. This function shouldn't be called like
2465 ;; this anyway. The doc string widget should be added like the others.
2466 ;; --dv
2467 (widget-put widget :buttons buttons)
2468 (insert "\n")
2469 ;; Insert documentation.
2470 (widget-default-format-handler widget ?h)
2472 ;; The comment field
2473 (unless (eq state 'hidden)
2474 (let* ((comment (get symbol 'variable-comment))
2475 (comment-widget
2476 (widget-create-child-and-convert
2477 widget 'custom-comment
2478 :parent widget
2479 :value (or comment ""))))
2480 (widget-put widget :comment-widget comment-widget)
2481 ;; Don't push it !!! Custom assumes that the first child is the
2482 ;; value one.
2483 (setq children (append children (list comment-widget)))))
2484 ;; Update the rest of the properties properties.
2485 (widget-put widget :custom-form form)
2486 (widget-put widget :children children)
2487 ;; Now update the state.
2488 (if (eq state 'hidden)
2489 (widget-put widget :custom-state state)
2490 (custom-variable-state-set widget))
2491 ;; See also.
2492 (unless (eq state 'hidden)
2493 (when (eq (widget-get widget :custom-level) 1)
2494 (custom-add-parent-links widget))
2495 (custom-add-see-also widget)))))
2497 (defun custom-tag-action (widget &rest args)
2498 "Pass :action to first child of WIDGET's parent."
2499 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2500 :action args))
2502 (defun custom-tag-mouse-down-action (widget &rest args)
2503 "Pass :mouse-down-action to first child of WIDGET's parent."
2504 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2505 :mouse-down-action args))
2507 (defun custom-variable-state-set (widget)
2508 "Set the state of WIDGET."
2509 (let* ((symbol (widget-value widget))
2510 (get (or (get symbol 'custom-get) 'default-value))
2511 (value (if (default-boundp symbol)
2512 (funcall get symbol)
2513 (widget-get widget :value)))
2514 (comment (get symbol 'variable-comment))
2516 temp
2517 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2518 (setq temp
2519 (get symbol 'customized-variable-comment))
2520 (or tmp temp))
2521 (if (condition-case nil
2522 (and (equal value (eval (car tmp)))
2523 (equal comment temp))
2524 (error nil))
2525 'set
2526 'changed))
2527 ((progn (setq tmp (get symbol 'saved-value))
2528 (setq temp (get symbol 'saved-variable-comment))
2529 (or tmp temp))
2530 (if (condition-case nil
2531 (and (equal value (eval (car tmp)))
2532 (equal comment temp))
2533 (error nil))
2534 'saved
2535 'changed))
2536 ((setq tmp (get symbol 'standard-value))
2537 (if (condition-case nil
2538 (and (equal value (eval (car tmp)))
2539 (equal comment nil))
2540 (error nil))
2541 'standard
2542 'changed))
2543 (t 'rogue))))
2544 (widget-put widget :custom-state state)))
2546 (defun custom-variable-standard-value (widget)
2547 (get (widget-value widget) 'standard-value))
2549 (defvar custom-variable-menu
2550 '(("Set for Current Session" custom-variable-set
2551 (lambda (widget)
2552 (eq (widget-get widget :custom-state) 'modified)))
2553 ("Save for Future Sessions" custom-variable-save
2554 (lambda (widget)
2555 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2556 ("Reset to Current" custom-redraw
2557 (lambda (widget)
2558 (and (default-boundp (widget-value widget))
2559 (memq (widget-get widget :custom-state) '(modified changed)))))
2560 ("Reset to Saved" custom-variable-reset-saved
2561 (lambda (widget)
2562 (and (or (get (widget-value widget) 'saved-value)
2563 (get (widget-value widget) 'saved-variable-comment))
2564 (memq (widget-get widget :custom-state)
2565 '(modified set changed rogue)))))
2566 ("Erase Customization" custom-variable-reset-standard
2567 (lambda (widget)
2568 (and (get (widget-value widget) 'standard-value)
2569 (memq (widget-get widget :custom-state)
2570 '(modified set changed saved rogue)))))
2571 ("Use Backup Value" custom-variable-reset-backup
2572 (lambda (widget)
2573 (get (widget-value widget) 'backup-value)))
2574 ("---" ignore ignore)
2575 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2576 ("---" ignore ignore)
2577 ("Don't show as Lisp expression" custom-variable-edit
2578 (lambda (widget)
2579 (eq (widget-get widget :custom-form) 'lisp)))
2580 ("Show initial Lisp expression" custom-variable-edit-lisp
2581 (lambda (widget)
2582 (eq (widget-get widget :custom-form) 'edit))))
2583 "Alist of actions for the `custom-variable' widget.
2584 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2585 the menu entry, ACTION is the function to call on the widget when the
2586 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2587 widget as an argument, and returns non-nil if ACTION is valid on that
2588 widget. If FILTER is nil, ACTION is always valid.")
2590 (defun custom-variable-action (widget &optional event)
2591 "Show the menu for `custom-variable' WIDGET.
2592 Optional EVENT is the location for the menu."
2593 (if (eq (widget-get widget :custom-state) 'hidden)
2594 (custom-toggle-hide widget)
2595 (unless (eq (widget-get widget :custom-state) 'modified)
2596 (custom-variable-state-set widget))
2597 (custom-redraw-magic widget)
2598 (let* ((completion-ignore-case t)
2599 (answer (widget-choose (concat "Operation on "
2600 (custom-unlispify-tag-name
2601 (widget-get widget :value)))
2602 (custom-menu-filter custom-variable-menu
2603 widget)
2604 event)))
2605 (if answer
2606 (funcall answer widget)))))
2608 (defun custom-variable-edit (widget)
2609 "Edit value of WIDGET."
2610 (widget-put widget :custom-state 'unknown)
2611 (widget-put widget :custom-form 'edit)
2612 (custom-redraw widget))
2614 (defun custom-variable-edit-lisp (widget)
2615 "Edit the Lisp representation of the value of WIDGET."
2616 (widget-put widget :custom-state 'unknown)
2617 (widget-put widget :custom-form 'lisp)
2618 (custom-redraw widget))
2620 (defun custom-variable-set (widget)
2621 "Set the current value for the variable being edited by WIDGET."
2622 (let* ((form (widget-get widget :custom-form))
2623 (state (widget-get widget :custom-state))
2624 (child (car (widget-get widget :children)))
2625 (symbol (widget-value widget))
2626 (set (or (get symbol 'custom-set) 'set-default))
2627 (comment-widget (widget-get widget :comment-widget))
2628 (comment (widget-value comment-widget))
2629 val)
2630 (cond ((eq state 'hidden)
2631 (error "Cannot set hidden variable"))
2632 ((setq val (widget-apply child :validate))
2633 (goto-char (widget-get val :from))
2634 (error "%s" (widget-get val :error)))
2635 ((memq form '(lisp mismatch))
2636 (when (equal comment "")
2637 (setq comment nil)
2638 ;; Make the comment invisible by hand if it's empty
2639 (custom-comment-hide comment-widget))
2640 (custom-variable-backup-value widget)
2641 (funcall set symbol (eval (setq val (widget-value child))))
2642 (put symbol 'customized-value (list val))
2643 (put symbol 'variable-comment comment)
2644 (put symbol 'customized-variable-comment comment))
2646 (when (equal comment "")
2647 (setq comment nil)
2648 ;; Make the comment invisible by hand if it's empty
2649 (custom-comment-hide comment-widget))
2650 (custom-variable-backup-value widget)
2651 (funcall set symbol (setq val (widget-value child)))
2652 (put symbol 'customized-value (list (custom-quote val)))
2653 (put symbol 'variable-comment comment)
2654 (put symbol 'customized-variable-comment comment)))
2655 (custom-variable-state-set widget)
2656 (custom-redraw-magic widget)))
2658 (defun custom-variable-save (widget)
2659 "Set and save the value for the variable being edited by WIDGET."
2660 (let* ((form (widget-get widget :custom-form))
2661 (state (widget-get widget :custom-state))
2662 (child (car (widget-get widget :children)))
2663 (symbol (widget-value widget))
2664 (set (or (get symbol 'custom-set) 'set-default))
2665 (comment-widget (widget-get widget :comment-widget))
2666 (comment (widget-value comment-widget))
2667 val)
2668 (cond ((eq state 'hidden)
2669 (error "Cannot set hidden variable"))
2670 ((setq val (widget-apply child :validate))
2671 (goto-char (widget-get val :from))
2672 (error "Saving %s: %s" symbol (widget-get val :error)))
2673 ((memq form '(lisp mismatch))
2674 (when (equal comment "")
2675 (setq comment nil)
2676 ;; Make the comment invisible by hand if it's empty
2677 (custom-comment-hide comment-widget))
2678 (put symbol 'saved-value (list (widget-value child)))
2679 (custom-push-theme 'theme-value symbol 'user
2680 'set (list (widget-value child)))
2681 (funcall set symbol (eval (widget-value child)))
2682 (put symbol 'variable-comment comment)
2683 (put symbol 'saved-variable-comment comment))
2685 (when (equal comment "")
2686 (setq comment nil)
2687 ;; Make the comment invisible by hand if it's empty
2688 (custom-comment-hide comment-widget))
2689 (put symbol 'saved-value
2690 (list (custom-quote (widget-value child))))
2691 (custom-push-theme 'theme-value symbol 'user
2692 'set (list (custom-quote (widget-value
2693 child))))
2694 (funcall set symbol (widget-value child))
2695 (put symbol 'variable-comment comment)
2696 (put symbol 'saved-variable-comment comment)))
2697 (put symbol 'customized-value nil)
2698 (put symbol 'customized-variable-comment nil)
2699 (custom-save-all)
2700 (custom-variable-state-set widget)
2701 (custom-redraw-magic widget)))
2703 (defun custom-variable-reset-saved (widget)
2704 "Restore the saved value for the variable being edited by WIDGET.
2705 The value that was current before this operation
2706 becomes the backup value, so you can get it again."
2707 (let* ((symbol (widget-value widget))
2708 (set (or (get symbol 'custom-set) 'set-default))
2709 (value (get symbol 'saved-value))
2710 (comment (get symbol 'saved-variable-comment)))
2711 (cond ((or value comment)
2712 (put symbol 'variable-comment comment)
2713 (custom-variable-backup-value widget)
2714 (condition-case nil
2715 (funcall set symbol (eval (car value)))
2716 (error nil)))
2718 (error "No saved value for %s" symbol)))
2719 (put symbol 'customized-value nil)
2720 (put symbol 'customized-variable-comment nil)
2721 (widget-put widget :custom-state 'unknown)
2722 ;; This call will possibly make the comment invisible
2723 (custom-redraw widget)))
2725 (defun custom-variable-reset-standard (widget)
2726 "Restore the standard setting for the variable being edited by WIDGET.
2727 This operation eliminates any saved setting for the variable,
2728 restoring it to the state of a variable that has never been customized.
2729 The value that was current before this operation
2730 becomes the backup value, so you can get it again."
2731 (let* ((symbol (widget-value widget))
2732 (set (or (get symbol 'custom-set) 'set-default)))
2733 (if (get symbol 'standard-value)
2734 (progn
2735 (custom-variable-backup-value widget)
2736 (funcall set symbol (eval (car (get symbol 'standard-value)))))
2737 (error "No standard setting known for %S" symbol))
2738 (put symbol 'variable-comment nil)
2739 (put symbol 'customized-value nil)
2740 (put symbol 'customized-variable-comment nil)
2741 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2742 (put symbol 'saved-value nil)
2743 (custom-push-theme 'theme-value symbol 'user 'reset 'standard)
2744 ;; As a special optimizations we do not (explictly)
2745 ;; save resets to standard when no theme set the value.
2746 (if (null (cdr (get symbol 'theme-value)))
2747 (put symbol 'theme-value nil))
2748 (put symbol 'saved-variable-comment nil)
2749 (custom-save-all))
2750 (widget-put widget :custom-state 'unknown)
2751 ;; This call will possibly make the comment invisible
2752 (custom-redraw widget)))
2754 (defun custom-variable-backup-value (widget)
2755 "Back up the current value for WIDGET's variable.
2756 The backup value is kept in the car of the `backup-value' property."
2757 (let* ((symbol (widget-value widget))
2758 (get (or (get symbol 'custom-get) 'default-value))
2759 (type (custom-variable-type symbol))
2760 (conv (widget-convert type))
2761 (value (if (default-boundp symbol)
2762 (funcall get symbol)
2763 (widget-get conv :value))))
2764 (put symbol 'backup-value (list value))))
2766 (defun custom-variable-reset-backup (widget)
2767 "Restore the backup value for the variable being edited by WIDGET.
2768 The value that was current before this operation
2769 becomes the backup value, so you can use this operation repeatedly
2770 to switch between two values."
2771 (let* ((symbol (widget-value widget))
2772 (set (or (get symbol 'custom-set) 'set-default))
2773 (value (get symbol 'backup-value))
2774 (comment-widget (widget-get widget :comment-widget))
2775 (comment (widget-value comment-widget)))
2776 (if value
2777 (progn
2778 (custom-variable-backup-value widget)
2779 (condition-case nil
2780 (funcall set symbol (car value))
2781 (error nil)))
2782 (error "No backup value for %s" symbol))
2783 (put symbol 'customized-value (list (car value)))
2784 (put symbol 'variable-comment comment)
2785 (put symbol 'customized-variable-comment comment)
2786 (custom-variable-state-set widget)
2787 ;; This call will possibly make the comment invisible
2788 (custom-redraw widget)))
2790 ;;; The `custom-face-edit' Widget.
2792 (define-widget 'custom-face-edit 'checklist
2793 "Edit face attributes."
2794 :format "%t: %v"
2795 :tag "Attributes"
2796 :extra-offset 13
2797 :button-args '(:help-echo "Control whether this attribute has any effect.")
2798 :value-to-internal 'custom-face-edit-fix-value
2799 :match (lambda (widget value)
2800 (widget-checklist-match widget
2801 (custom-face-edit-fix-value widget value)))
2802 :convert-widget 'custom-face-edit-convert-widget
2803 :args (mapcar (lambda (att)
2804 (list 'group
2805 :inline t
2806 :sibling-args (widget-get (nth 1 att) :sibling-args)
2807 (list 'const :format "" :value (nth 0 att))
2808 (nth 1 att)))
2809 custom-face-attributes))
2811 (defun custom-face-edit-fix-value (widget value)
2812 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2813 Also change :reverse-video to :inverse-video."
2814 (if (listp value)
2815 (let (result)
2816 (while value
2817 (let ((key (car value))
2818 (val (car (cdr value))))
2819 (cond ((eq key :italic)
2820 (push :slant result)
2821 (push (if val 'italic 'normal) result))
2822 ((eq key :bold)
2823 (push :weight result)
2824 (push (if val 'bold 'normal) result))
2825 ((eq key :reverse-video)
2826 (push :inverse-video result)
2827 (push val result))
2829 (push key result)
2830 (push val result))))
2831 (setq value (cdr (cdr value))))
2832 (setq result (nreverse result))
2833 result)
2834 value))
2836 (defun custom-face-edit-convert-widget (widget)
2837 "Convert :args as widget types in WIDGET."
2838 (widget-put
2839 widget
2840 :args (mapcar (lambda (arg)
2841 (widget-convert arg
2842 :deactivate 'custom-face-edit-deactivate
2843 :activate 'custom-face-edit-activate
2844 :delete 'custom-face-edit-delete))
2845 (widget-get widget :args)))
2846 widget)
2848 (defun custom-face-edit-deactivate (widget)
2849 "Make face widget WIDGET inactive for user modifications."
2850 (unless (widget-get widget :inactive)
2851 (let ((tag (custom-face-edit-attribute-tag widget))
2852 (from (copy-marker (widget-get widget :from)))
2853 (value (widget-value widget))
2854 (inhibit-read-only t)
2855 (inhibit-modification-hooks t))
2856 (save-excursion
2857 (goto-char from)
2858 (widget-default-delete widget)
2859 (insert tag ": *\n")
2860 (widget-put widget :inactive
2861 (cons value (cons from (- (point) from))))))))
2863 (defun custom-face-edit-activate (widget)
2864 "Make face widget WIDGET inactive for user modifications."
2865 (let ((inactive (widget-get widget :inactive))
2866 (inhibit-read-only t)
2867 (inhibit-modification-hooks t))
2868 (when (consp inactive)
2869 (save-excursion
2870 (goto-char (car (cdr inactive)))
2871 (delete-region (point) (+ (point) (cdr (cdr inactive))))
2872 (widget-put widget :inactive nil)
2873 (widget-apply widget :create)
2874 (widget-value-set widget (car inactive))
2875 (widget-setup)))))
2877 (defun custom-face-edit-delete (widget)
2878 "Remove WIDGET from the buffer."
2879 (let ((inactive (widget-get widget :inactive))
2880 (inhibit-read-only t)
2881 (inhibit-modification-hooks t))
2882 (if (not inactive)
2883 ;; Widget is alive, we don't have to do anything special
2884 (widget-default-delete widget)
2885 ;; WIDGET is already deleted because we did so to inactivate it;
2886 ;; now just get rid of the label we put in its place.
2887 (delete-region (car (cdr inactive))
2888 (+ (car (cdr inactive)) (cdr (cdr inactive))))
2889 (widget-put widget :inactive nil))))
2892 (defun custom-face-edit-attribute-tag (widget)
2893 "Returns the first :tag property in WIDGET or one of its children."
2894 (let ((tag (widget-get widget :tag)))
2895 (or (and (not (equal tag "")) tag)
2896 (let ((children (widget-get widget :children)))
2897 (while (and (null tag) children)
2898 (setq tag (custom-face-edit-attribute-tag (pop children))))
2899 tag))))
2901 ;;; The `custom-display' Widget.
2903 (define-widget 'custom-display 'menu-choice
2904 "Select a display type."
2905 :tag "Display"
2906 :value t
2907 :help-echo "Specify frames where the face attributes should be used."
2908 :args '((const :tag "all" t)
2909 (const :tag "defaults" default)
2910 (checklist
2911 :offset 0
2912 :extra-offset 9
2913 :args ((group :sibling-args (:help-echo "\
2914 Only match the specified window systems.")
2915 (const :format "Type: "
2916 type)
2917 (checklist :inline t
2918 :offset 0
2919 (const :format "X "
2920 :sibling-args (:help-echo "\
2921 The X11 Window System.")
2923 (const :format "PM "
2924 :sibling-args (:help-echo "\
2925 OS/2 Presentation Manager.")
2927 (const :format "W32 "
2928 :sibling-args (:help-echo "\
2929 Windows NT/9X.")
2930 w32)
2931 (const :format "MAC "
2932 :sibling-args (:help-echo "\
2933 Macintosh OS.")
2934 mac)
2935 (const :format "DOS "
2936 :sibling-args (:help-echo "\
2937 Plain MS-DOS.")
2939 (const :format "TTY%n"
2940 :sibling-args (:help-echo "\
2941 Plain text terminals.")
2942 tty)))
2943 (group :sibling-args (:help-echo "\
2944 Only match the frames with the specified color support.")
2945 (const :format "Class: "
2946 class)
2947 (checklist :inline t
2948 :offset 0
2949 (const :format "Color "
2950 :sibling-args (:help-echo "\
2951 Match color frames.")
2952 color)
2953 (const :format "Grayscale "
2954 :sibling-args (:help-echo "\
2955 Match grayscale frames.")
2956 grayscale)
2957 (const :format "Monochrome%n"
2958 :sibling-args (:help-echo "\
2959 Match frames with no color support.")
2960 mono)))
2961 (group :sibling-args (:help-echo "\
2962 The minimum number of colors the frame should support.")
2963 (const :format "" min-colors)
2964 (integer :tag "Minimum number of colors" ))
2965 (group :sibling-args (:help-echo "\
2966 Only match frames with the specified intensity.")
2967 (const :format "\
2968 Background brightness: "
2969 background)
2970 (checklist :inline t
2971 :offset 0
2972 (const :format "Light "
2973 :sibling-args (:help-echo "\
2974 Match frames with light backgrounds.")
2975 light)
2976 (const :format "Dark\n"
2977 :sibling-args (:help-echo "\
2978 Match frames with dark backgrounds.")
2979 dark)))
2980 (group :sibling-args (:help-echo "\
2981 Only match frames that support the specified face attributes.")
2982 (const :format "Supports attributes:" supports)
2983 (custom-face-edit :inline t :format "%n%v"))))))
2985 ;;; The `custom-face' Widget.
2987 (defface custom-face-tag
2988 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
2989 "Face used for face tags."
2990 :group 'custom-faces)
2991 ;; backward-compatibility alias
2992 (put 'custom-face-tag-face 'face-alias 'custom-face-tag)
2994 (defcustom custom-face-default-form 'selected
2995 "Default form of displaying face definition."
2996 :type '(choice (const all)
2997 (const selected)
2998 (const lisp))
2999 :group 'custom-buffer
3000 :version "20.3")
3002 (define-widget 'custom-face 'custom
3003 "Customize face."
3004 :sample-face 'custom-face-tag-face
3005 :help-echo "Set or reset this face."
3006 :documentation-property #'face-doc-string
3007 :value-create 'custom-face-value-create
3008 :action 'custom-face-action
3009 :custom-category 'face
3010 :custom-form nil ; defaults to value of `custom-face-default-form'
3011 :custom-set 'custom-face-set
3012 :custom-save 'custom-face-save
3013 :custom-reset-current 'custom-redraw
3014 :custom-reset-saved 'custom-face-reset-saved
3015 :custom-reset-standard 'custom-face-reset-standard
3016 :custom-standard-value 'custom-face-standard-value
3017 :custom-menu 'custom-face-menu-create)
3019 (define-widget 'custom-face-all 'editable-list
3020 "An editable list of display specifications and attributes."
3021 :entry-format "%i %d %v"
3022 :insert-button-args '(:help-echo "Insert new display specification here.")
3023 :append-button-args '(:help-echo "Append new display specification here.")
3024 :delete-button-args '(:help-echo "Delete this display specification.")
3025 :args '((group :format "%v" custom-display custom-face-edit)))
3027 (defconst custom-face-all (widget-convert 'custom-face-all)
3028 "Converted version of the `custom-face-all' widget.")
3030 (define-widget 'custom-display-unselected 'item
3031 "A display specification that doesn't match the selected display."
3032 :match 'custom-display-unselected-match)
3034 (defun custom-display-unselected-match (widget value)
3035 "Non-nil if VALUE is an unselected display specification."
3036 (not (face-spec-set-match-display value (selected-frame))))
3038 (define-widget 'custom-face-selected 'group
3039 "Edit the attributes of the selected display in a face specification."
3040 :args '((choice :inline t
3041 (group :tag "With Defaults" :inline t
3042 (group (const :tag "" default)
3043 (custom-face-edit :tag " Default\n Attributes"))
3044 (repeat :format ""
3045 :inline t
3046 (group custom-display-unselected sexp))
3047 (group (sexp :format "")
3048 (custom-face-edit :tag " Overriding\n Attributes"))
3049 (repeat :format ""
3050 :inline t
3051 sexp))
3052 (group :tag "No Defaults" :inline t
3053 (repeat :format ""
3054 :inline t
3055 (group custom-display-unselected sexp))
3056 (group (sexp :format "")
3057 (custom-face-edit :tag "\n Attributes"))
3058 (repeat :format ""
3059 :inline t
3060 sexp)))))
3064 (defconst custom-face-selected (widget-convert 'custom-face-selected)
3065 "Converted version of the `custom-face-selected' widget.")
3067 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
3068 "Return a canonicalized version of SPEC using.
3069 FILTER-INDEX is the index in the entry for each attribute in
3070 `custom-face-attributes' at which the appropriate filter function can be
3071 found, and DEFAULT-FILTER is the filter to apply for attributes that
3072 don't specify one."
3073 (mapcar (lambda (entry)
3074 ;; Filter a single face-spec entry
3075 (let ((tests (car entry))
3076 (unfiltered-attrs
3077 ;; Handle both old- and new-style attribute syntax
3078 (if (listp (car (cdr entry)))
3079 (car (cdr entry))
3080 (cdr entry)))
3081 (filtered-attrs nil))
3082 ;; Filter each face attribute
3083 (while unfiltered-attrs
3084 (let* ((attr (pop unfiltered-attrs))
3085 (pre-filtered-value (pop unfiltered-attrs))
3086 (filter
3087 (or (nth filter-index (assq attr custom-face-attributes))
3088 default-filter))
3089 (filtered-value
3090 (if filter
3091 (funcall filter pre-filtered-value)
3092 pre-filtered-value)))
3093 (push filtered-value filtered-attrs)
3094 (push attr filtered-attrs)))
3096 (list tests filtered-attrs)))
3097 spec))
3099 (defun custom-pre-filter-face-spec (spec)
3100 "Return SPEC changed as necessary for editing by the face customization widget.
3101 SPEC must be a full face spec."
3102 (custom-filter-face-spec spec 2))
3104 (defun custom-post-filter-face-spec (spec)
3105 "Return the customized SPEC in a form suitable for setting the face."
3106 (custom-filter-face-spec spec 3))
3108 (defun custom-face-value-create (widget)
3109 "Create a list of the display specifications for WIDGET."
3110 (let ((buttons (widget-get widget :buttons))
3111 children
3112 (symbol (widget-get widget :value))
3113 (tag (widget-get widget :tag))
3114 (state (widget-get widget :custom-state))
3115 (begin (point))
3116 (is-last (widget-get widget :custom-last))
3117 (prefix (widget-get widget :custom-prefix)))
3118 (unless tag
3119 (setq tag (prin1-to-string symbol)))
3120 (cond ((eq custom-buffer-style 'tree)
3121 (insert prefix (if is-last " `--- " " |--- "))
3122 (push (widget-create-child-and-convert
3123 widget 'custom-browse-face-tag)
3124 buttons)
3125 (insert " " tag "\n")
3126 (widget-put widget :buttons buttons))
3128 ;; Create tag.
3129 (insert tag)
3130 (widget-specify-sample widget begin (point))
3131 (if (eq custom-buffer-style 'face)
3132 (insert " ")
3133 (if (string-match "face\\'" tag)
3134 (insert ":")
3135 (insert " face: ")))
3136 ;; Sample.
3137 (push (widget-create-child-and-convert widget 'item
3138 :format "(%{%t%})"
3139 :sample-face symbol
3140 :tag "sample")
3141 buttons)
3142 ;; Visibility.
3143 (insert " ")
3144 (push (widget-create-child-and-convert
3145 widget 'visibility
3146 :help-echo "Hide or show this face."
3147 :on "Hide Face"
3148 :off "Show Face"
3149 :action 'custom-toggle-parent
3150 (not (eq state 'hidden)))
3151 buttons)
3152 ;; Magic.
3153 (insert "\n")
3154 (let ((magic (widget-create-child-and-convert
3155 widget 'custom-magic nil)))
3156 (widget-put widget :custom-magic magic)
3157 (push magic buttons))
3158 ;; Update buttons.
3159 (widget-put widget :buttons buttons)
3160 ;; Insert documentation.
3161 (widget-default-format-handler widget ?h)
3162 ;; The comment field
3163 (unless (eq state 'hidden)
3164 (let* ((comment (get symbol 'face-comment))
3165 (comment-widget
3166 (widget-create-child-and-convert
3167 widget 'custom-comment
3168 :parent widget
3169 :value (or comment ""))))
3170 (widget-put widget :comment-widget comment-widget)
3171 (push comment-widget children)))
3172 ;; See also.
3173 (unless (eq state 'hidden)
3174 (when (eq (widget-get widget :custom-level) 1)
3175 (custom-add-parent-links widget))
3176 (custom-add-see-also widget))
3177 ;; Editor.
3178 (unless (eq (preceding-char) ?\n)
3179 (insert "\n"))
3180 (unless (eq state 'hidden)
3181 (message "Creating face editor...")
3182 (custom-load-widget widget)
3183 (unless (widget-get widget :custom-form)
3184 (widget-put widget :custom-form custom-face-default-form))
3185 (let* ((symbol (widget-value widget))
3186 (spec (or (get symbol 'customized-face)
3187 (get symbol 'saved-face)
3188 (get symbol 'face-defface-spec)
3189 ;; Attempt to construct it.
3190 (list (list t (custom-face-attributes-get
3191 symbol (selected-frame))))))
3192 (form (widget-get widget :custom-form))
3193 (indent (widget-get widget :indent))
3194 edit)
3195 ;; If the user has changed this face in some other way,
3196 ;; edit it as the user has specified it.
3197 (if (not (face-spec-match-p symbol spec (selected-frame)))
3198 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
3199 (setq spec (custom-pre-filter-face-spec spec))
3200 (setq edit (widget-create-child-and-convert
3201 widget
3202 (cond ((and (eq form 'selected)
3203 (widget-apply custom-face-selected
3204 :match spec))
3205 (when indent (insert-char ?\ indent))
3206 'custom-face-selected)
3207 ((and (not (eq form 'lisp))
3208 (widget-apply custom-face-all
3209 :match spec))
3210 'custom-face-all)
3212 (when indent (insert-char ?\ indent))
3213 'sexp))
3214 :value spec))
3215 (custom-face-state-set widget)
3216 (push edit children)
3217 (widget-put widget :children children))
3218 (message "Creating face editor...done"))))))
3220 (defvar custom-face-menu
3221 '(("Set for Current Session" custom-face-set)
3222 ("Save for Future Sessions" custom-face-save-command)
3223 ("Reset to Saved" custom-face-reset-saved
3224 (lambda (widget)
3225 (or (get (widget-value widget) 'saved-face)
3226 (get (widget-value widget) 'saved-face-comment))))
3227 ("Erase Customization" custom-face-reset-standard
3228 (lambda (widget)
3229 (get (widget-value widget) 'face-defface-spec)))
3230 ("---" ignore ignore)
3231 ("Add Comment" custom-comment-show custom-comment-invisible-p)
3232 ("---" ignore ignore)
3233 ("Show all display specs" custom-face-edit-all
3234 (lambda (widget)
3235 (not (eq (widget-get widget :custom-form) 'all))))
3236 ("Just current attributes" custom-face-edit-selected
3237 (lambda (widget)
3238 (not (eq (widget-get widget :custom-form) 'selected))))
3239 ("Show as Lisp expression" custom-face-edit-lisp
3240 (lambda (widget)
3241 (not (eq (widget-get widget :custom-form) 'lisp)))))
3242 "Alist of actions for the `custom-face' widget.
3243 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3244 the menu entry, ACTION is the function to call on the widget when the
3245 menu is selected, and FILTER is a predicate which takes a `custom-face'
3246 widget as an argument, and returns non-nil if ACTION is valid on that
3247 widget. If FILTER is nil, ACTION is always valid.")
3249 (defun custom-face-edit-selected (widget)
3250 "Edit selected attributes of the value of WIDGET."
3251 (widget-put widget :custom-state 'unknown)
3252 (widget-put widget :custom-form 'selected)
3253 (custom-redraw widget))
3255 (defun custom-face-edit-all (widget)
3256 "Edit all attributes of the value of WIDGET."
3257 (widget-put widget :custom-state 'unknown)
3258 (widget-put widget :custom-form 'all)
3259 (custom-redraw widget))
3261 (defun custom-face-edit-lisp (widget)
3262 "Edit the Lisp representation of the value of WIDGET."
3263 (widget-put widget :custom-state 'unknown)
3264 (widget-put widget :custom-form 'lisp)
3265 (custom-redraw widget))
3267 (defun custom-face-state-set (widget)
3268 "Set the state of WIDGET."
3269 (let* ((symbol (widget-value widget))
3270 (comment (get symbol 'face-comment))
3271 tmp temp
3272 (state
3273 (cond ((progn
3274 (setq tmp (get symbol 'customized-face))
3275 (setq temp (get symbol 'customized-face-comment))
3276 (or tmp temp))
3277 (if (equal temp comment)
3278 'set
3279 'changed))
3280 ((progn
3281 (setq tmp (get symbol 'saved-face))
3282 (setq temp (get symbol 'saved-face-comment))
3283 (or tmp temp))
3284 (if (equal temp comment)
3285 'saved
3286 'changed))
3287 ((get symbol 'face-defface-spec)
3288 (if (equal comment nil)
3289 'standard
3290 'changed))
3292 'rogue))))
3293 ;; If the user called set-face-attribute to change the default
3294 ;; for new frames, this face is "set outside of Customize".
3295 (if (and (not (eq state 'rogue))
3296 (get symbol 'face-modified))
3297 (setq state 'changed))
3298 (widget-put widget :custom-state state)))
3300 (defun custom-face-action (widget &optional event)
3301 "Show the menu for `custom-face' WIDGET.
3302 Optional EVENT is the location for the menu."
3303 (if (eq (widget-get widget :custom-state) 'hidden)
3304 (custom-toggle-hide widget)
3305 (let* ((completion-ignore-case t)
3306 (symbol (widget-get widget :value))
3307 (answer (widget-choose (concat "Operation on "
3308 (custom-unlispify-tag-name symbol))
3309 (custom-menu-filter custom-face-menu
3310 widget)
3311 event)))
3312 (if answer
3313 (funcall answer widget)))))
3315 (defun custom-face-set (widget)
3316 "Make the face attributes in WIDGET take effect."
3317 (let* ((symbol (widget-value widget))
3318 (child (car (widget-get widget :children)))
3319 (value (custom-post-filter-face-spec (widget-value child)))
3320 (comment-widget (widget-get widget :comment-widget))
3321 (comment (widget-value comment-widget)))
3322 (when (equal comment "")
3323 (setq comment nil)
3324 ;; Make the comment invisible by hand if it's empty
3325 (custom-comment-hide comment-widget))
3326 (put symbol 'customized-face value)
3327 (if (face-spec-choose value)
3328 (face-spec-set symbol value)
3329 ;; face-set-spec ignores empty attribute lists, so just give it
3330 ;; something harmless instead.
3331 (face-spec-set symbol '((t :foreground unspecified))))
3332 (put symbol 'customized-face-comment comment)
3333 (put symbol 'face-comment comment)
3334 (custom-face-state-set widget)
3335 (custom-redraw-magic widget)))
3337 (defun custom-face-save-command (widget)
3338 "Save in `.emacs' the face attributes in WIDGET."
3339 (custom-face-save widget)
3340 (custom-save-all))
3342 (defun custom-face-save (widget)
3343 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3344 (let* ((symbol (widget-value widget))
3345 (child (car (widget-get widget :children)))
3346 (value (custom-post-filter-face-spec (widget-value child)))
3347 (comment-widget (widget-get widget :comment-widget))
3348 (comment (widget-value comment-widget)))
3349 (when (equal comment "")
3350 (setq comment nil)
3351 ;; Make the comment invisible by hand if it's empty
3352 (custom-comment-hide comment-widget))
3353 (if (face-spec-choose value)
3354 (face-spec-set symbol value)
3355 ;; face-set-spec ignores empty attribute lists, so just give it
3356 ;; something harmless instead.
3357 (face-spec-set symbol '((t :foreground unspecified))))
3358 (unless (eq (widget-get widget :custom-state) 'standard)
3359 (put symbol 'saved-face value))
3360 (custom-push-theme 'theme-face symbol 'user 'set value)
3361 (put symbol 'customized-face nil)
3362 (put symbol 'face-comment comment)
3363 (put symbol 'customized-face-comment nil)
3364 (put symbol 'saved-face-comment comment)
3365 (custom-save-all)
3366 (custom-face-state-set widget)
3367 (custom-redraw-magic widget)))
3369 (defun custom-face-reset-saved (widget)
3370 "Restore WIDGET to the face's default attributes."
3371 (let* ((symbol (widget-value widget))
3372 (child (car (widget-get widget :children)))
3373 (value (get symbol 'saved-face))
3374 (comment (get symbol 'saved-face-comment))
3375 (comment-widget (widget-get widget :comment-widget)))
3376 (unless (or value comment)
3377 (error "No saved value for this face"))
3378 (put symbol 'customized-face nil)
3379 (put symbol 'customized-face-comment nil)
3380 (face-spec-set symbol value)
3381 (put symbol 'face-comment comment)
3382 (widget-value-set child value)
3383 ;; This call manages the comment visibility
3384 (widget-value-set comment-widget (or comment ""))
3385 (custom-face-state-set widget)
3386 (custom-redraw-magic widget)))
3388 (defun custom-face-standard-value (widget)
3389 (get (widget-value widget) 'face-defface-spec))
3391 (defun custom-face-reset-standard (widget)
3392 "Restore WIDGET to the face's standard settings.
3393 This operation eliminates any saved setting for the face,
3394 restoring it to the state of a face that has never been customized."
3395 (let* ((symbol (widget-value widget))
3396 (child (car (widget-get widget :children)))
3397 (value (get symbol 'face-defface-spec))
3398 (comment-widget (widget-get widget :comment-widget)))
3399 (unless value
3400 (error "No standard setting for this face"))
3401 (put symbol 'customized-face nil)
3402 (put symbol 'customized-face-comment nil)
3403 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3404 (put symbol 'saved-face nil)
3405 (custom-push-theme 'theme-face symbol 'user 'reset 'standard)
3406 ;; Do not explictly save resets to standards without themes.
3407 (if (null (cdr (get symbol 'theme-face)))
3408 (put symbol 'theme-face nil))
3409 (put symbol 'saved-face-comment nil)
3410 (custom-save-all))
3411 (face-spec-set symbol value)
3412 (put symbol 'face-comment nil)
3413 (widget-value-set child value)
3414 ;; This call manages the comment visibility
3415 (widget-value-set comment-widget "")
3416 (custom-face-state-set widget)
3417 (custom-redraw-magic widget)))
3419 ;;; The `face' Widget.
3421 (defvar widget-face-prompt-value-history nil
3422 "History of input to `widget-face-prompt-value'.")
3424 (define-widget 'face 'symbol
3425 "A Lisp face name (with sample)."
3426 :format "%{%t%}: (%{sample%}) %v"
3427 :tag "Face"
3428 :value 'default
3429 :sample-face-get 'widget-face-sample-face-get
3430 :notify 'widget-face-notify
3431 :match (lambda (widget value) (facep value))
3432 :complete-function (lambda ()
3433 (interactive)
3434 (lisp-complete-symbol 'facep))
3435 :prompt-match 'facep
3436 :prompt-history 'widget-face-prompt-value-history
3437 :validate (lambda (widget)
3438 (unless (facep (widget-value widget))
3439 (widget-put widget
3440 :error (format "Invalid face: %S"
3441 (widget-value widget)))
3442 widget)))
3444 (defun widget-face-sample-face-get (widget)
3445 (let ((value (widget-value widget)))
3446 (if (facep value)
3447 value
3448 'default)))
3450 (defun widget-face-notify (widget child &optional event)
3451 "Update the sample, and notify the parent."
3452 (overlay-put (widget-get widget :sample-overlay)
3453 'face (widget-apply widget :sample-face-get))
3454 (widget-default-notify widget child event))
3457 ;;; The `hook' Widget.
3459 (define-widget 'hook 'list
3460 "A emacs lisp hook"
3461 :value-to-internal (lambda (widget value)
3462 (if (and value (symbolp value))
3463 (list value)
3464 value))
3465 :match (lambda (widget value)
3466 (or (symbolp value)
3467 (widget-group-match widget value)))
3468 ;; Avoid adding undefined functions to the hook, especially for
3469 ;; things like `find-file-hook' or even more basic ones, to avoid
3470 ;; chaos.
3471 :set (lambda (symbol value)
3472 (dolist (elt value)
3473 (if (fboundp elt)
3474 (add-hook symbol elt))))
3475 :convert-widget 'custom-hook-convert-widget
3476 :tag "Hook")
3478 (defun custom-hook-convert-widget (widget)
3479 ;; Handle `:options'.
3480 (let* ((options (widget-get widget :options))
3481 (other `(editable-list :inline t
3482 :entry-format "%i %d%v"
3483 (function :format " %v")))
3484 (args (if options
3485 (list `(checklist :inline t
3486 ,@(mapcar (lambda (entry)
3487 `(function-item ,entry))
3488 options))
3489 other)
3490 (list other))))
3491 (widget-put widget :args args)
3492 widget))
3494 ;;; The `custom-group-link' Widget.
3496 (define-widget 'custom-group-link 'link
3497 "Show parent in other window when activated."
3498 :help-echo "Create customization buffer for this group."
3499 :action 'custom-group-link-action)
3501 (defun custom-group-link-action (widget &rest ignore)
3502 (customize-group (widget-value widget)))
3504 ;;; The `custom-group' Widget.
3506 (defcustom custom-group-tag-faces nil
3507 ;; In XEmacs, this ought to play games with font size.
3508 ;; Fixme: make it do so in Emacs.
3509 "Face used for group tags.
3510 The first member is used for level 1 groups, the second for level 2,
3511 and so forth. The remaining group tags are shown with `custom-group-tag'."
3512 :type '(repeat face)
3513 :group 'custom-faces)
3515 (defface custom-group-tag-1
3516 `((((class color)
3517 (background dark))
3518 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3519 (((min-colors 88) (class color)
3520 (background light))
3521 (:foreground "red1" :weight bold :height 1.2 :inherit variable-pitch))
3522 (((class color)
3523 (background light))
3524 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3525 (t (:weight bold)))
3526 "Face used for group tags."
3527 :group 'custom-faces)
3528 ;; backward-compatibility alias
3529 (put 'custom-group-tag-face-1 'face-alias 'custom-group-tag-1)
3531 (defface custom-group-tag
3532 `((((class color)
3533 (background dark))
3534 (:foreground "light blue" :weight bold :height 1.2))
3535 (((min-colors 88) (class color)
3536 (background light))
3537 (:foreground "blue1" :weight bold :height 1.2))
3538 (((class color)
3539 (background light))
3540 (:foreground "blue" :weight bold :height 1.2))
3541 (t (:weight bold)))
3542 "Face used for low level group tags."
3543 :group 'custom-faces)
3544 ;; backward-compatibility alias
3545 (put 'custom-group-tag-face 'face-alias 'custom-group-tag)
3547 (define-widget 'custom-group 'custom
3548 "Customize group."
3549 :format "%v"
3550 :sample-face-get 'custom-group-sample-face-get
3551 :documentation-property 'group-documentation
3552 :help-echo "Set or reset all members of this group."
3553 :value-create 'custom-group-value-create
3554 :action 'custom-group-action
3555 :custom-category 'group
3556 :custom-set 'custom-group-set
3557 :custom-save 'custom-group-save
3558 :custom-reset-current 'custom-group-reset-current
3559 :custom-reset-saved 'custom-group-reset-saved
3560 :custom-reset-standard 'custom-group-reset-standard
3561 :custom-menu 'custom-group-menu-create)
3563 (defun custom-group-sample-face-get (widget)
3564 ;; Use :sample-face.
3565 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3566 'custom-group-tag))
3568 (define-widget 'custom-group-visibility 'visibility
3569 "An indicator and manipulator for hidden group contents."
3570 :create 'custom-group-visibility-create)
3572 (defun custom-group-visibility-create (widget)
3573 (let ((visible (widget-value widget)))
3574 (if visible
3575 (insert "--------")))
3576 (widget-default-create widget))
3578 (defun custom-group-members (symbol groups-only)
3579 "Return SYMBOL's custom group members.
3580 If GROUPS-ONLY non-nil, return only those members that are groups."
3581 (if (not groups-only)
3582 (get symbol 'custom-group)
3583 (let (members)
3584 (dolist (entry (get symbol 'custom-group))
3585 (when (eq (nth 1 entry) 'custom-group)
3586 (push entry members)))
3587 (nreverse members))))
3589 (defun custom-group-value-create (widget)
3590 "Insert a customize group for WIDGET in the current buffer."
3591 (unless (eq (widget-get widget :custom-state) 'hidden)
3592 (custom-load-widget widget))
3593 (let* ((state (widget-get widget :custom-state))
3594 (level (widget-get widget :custom-level))
3595 ;; (indent (widget-get widget :indent))
3596 (prefix (widget-get widget :custom-prefix))
3597 (buttons (widget-get widget :buttons))
3598 (tag (widget-get widget :tag))
3599 (symbol (widget-value widget))
3600 (members (custom-group-members symbol
3601 (and (eq custom-buffer-style 'tree)
3602 custom-browse-only-groups))))
3603 (cond ((and (eq custom-buffer-style 'tree)
3604 (eq state 'hidden)
3605 (or members (custom-unloaded-widget-p widget)))
3606 (custom-browse-insert-prefix prefix)
3607 (push (widget-create-child-and-convert
3608 widget 'custom-browse-visibility
3609 ;; :tag-glyph "plus"
3610 :tag "+")
3611 buttons)
3612 (insert "-- ")
3613 ;; (widget-glyph-insert nil "-- " "horizontal")
3614 (push (widget-create-child-and-convert
3615 widget 'custom-browse-group-tag)
3616 buttons)
3617 (insert " " tag "\n")
3618 (widget-put widget :buttons buttons))
3619 ((and (eq custom-buffer-style 'tree)
3620 (zerop (length members)))
3621 (custom-browse-insert-prefix prefix)
3622 (insert "[ ]-- ")
3623 ;; (widget-glyph-insert nil "[ ]" "empty")
3624 ;; (widget-glyph-insert nil "-- " "horizontal")
3625 (push (widget-create-child-and-convert
3626 widget 'custom-browse-group-tag)
3627 buttons)
3628 (insert " " tag "\n")
3629 (widget-put widget :buttons buttons))
3630 ((eq custom-buffer-style 'tree)
3631 (custom-browse-insert-prefix prefix)
3632 (if (zerop (length members))
3633 (progn
3634 (custom-browse-insert-prefix prefix)
3635 (insert "[ ]-- ")
3636 ;; (widget-glyph-insert nil "[ ]" "empty")
3637 ;; (widget-glyph-insert nil "-- " "horizontal")
3638 (push (widget-create-child-and-convert
3639 widget 'custom-browse-group-tag)
3640 buttons)
3641 (insert " " tag "\n")
3642 (widget-put widget :buttons buttons))
3643 (push (widget-create-child-and-convert
3644 widget 'custom-browse-visibility
3645 ;; :tag-glyph "minus"
3646 :tag "-")
3647 buttons)
3648 (insert "-\\ ")
3649 ;; (widget-glyph-insert nil "-\\ " "top")
3650 (push (widget-create-child-and-convert
3651 widget 'custom-browse-group-tag)
3652 buttons)
3653 (insert " " tag "\n")
3654 (widget-put widget :buttons buttons)
3655 (message "Creating group...")
3656 (let* ((members (custom-sort-items members
3657 custom-browse-sort-alphabetically
3658 custom-browse-order-groups))
3659 (prefixes (widget-get widget :custom-prefixes))
3660 (custom-prefix-list (custom-prefix-add symbol prefixes))
3661 (extra-prefix (if (widget-get widget :custom-last)
3663 " | "))
3664 (prefix (concat prefix extra-prefix))
3665 children entry)
3666 (while members
3667 (setq entry (car members)
3668 members (cdr members))
3669 (push (widget-create-child-and-convert
3670 widget (nth 1 entry)
3671 :group widget
3672 :tag (custom-unlispify-tag-name (nth 0 entry))
3673 :custom-prefixes custom-prefix-list
3674 :custom-level (1+ level)
3675 :custom-last (null members)
3676 :value (nth 0 entry)
3677 :custom-prefix prefix)
3678 children))
3679 (widget-put widget :children (reverse children)))
3680 (message "Creating group...done")))
3681 ;; Nested style.
3682 ((eq state 'hidden)
3683 ;; Create level indicator.
3684 (unless (eq custom-buffer-style 'links)
3685 (insert-char ?\ (* custom-buffer-indent (1- level)))
3686 (insert "-- "))
3687 ;; Create tag.
3688 (let ((begin (point)))
3689 (insert tag)
3690 (widget-specify-sample widget begin (point)))
3691 (insert " group: ")
3692 ;; Create link/visibility indicator.
3693 (if (eq custom-buffer-style 'links)
3694 (push (widget-create-child-and-convert
3695 widget 'custom-group-link
3696 :tag "Go to Group"
3697 symbol)
3698 buttons)
3699 (push (widget-create-child-and-convert
3700 widget 'custom-group-visibility
3701 :help-echo "Show members of this group."
3702 :action 'custom-toggle-parent
3703 (not (eq state 'hidden)))
3704 buttons))
3705 (insert " \n")
3706 ;; Create magic button.
3707 (let ((magic (widget-create-child-and-convert
3708 widget 'custom-magic nil)))
3709 (widget-put widget :custom-magic magic)
3710 (push magic buttons))
3711 ;; Update buttons.
3712 (widget-put widget :buttons buttons)
3713 ;; Insert documentation.
3714 (if (and (eq custom-buffer-style 'links) (> level 1))
3715 (widget-put widget :documentation-indent 0))
3716 (widget-default-format-handler widget ?h))
3717 ;; Nested style.
3718 (t ;Visible.
3719 ;; Add parent groups references above the group.
3720 (if t ;;; This should test that the buffer
3721 ;;; was made to display a group.
3722 (when (eq level 1)
3723 (if (custom-add-parent-links widget
3724 "Go to parent group:")
3725 (insert "\n"))))
3726 ;; Create level indicator.
3727 (insert-char ?\ (* custom-buffer-indent (1- level)))
3728 (insert "/- ")
3729 ;; Create tag.
3730 (let ((start (point)))
3731 (insert tag)
3732 (widget-specify-sample widget start (point)))
3733 (insert " group: ")
3734 ;; Create visibility indicator.
3735 (unless (eq custom-buffer-style 'links)
3736 (insert "--------")
3737 (push (widget-create-child-and-convert
3738 widget 'visibility
3739 :help-echo "Hide members of this group."
3740 :action 'custom-toggle-parent
3741 (not (eq state 'hidden)))
3742 buttons)
3743 (insert " "))
3744 ;; Create more dashes.
3745 ;; Use 76 instead of 75 to compensate for the temporary "<"
3746 ;; added by `widget-insert'.
3747 (insert-char ?- (- 76 (current-column)
3748 (* custom-buffer-indent level)))
3749 (insert "\\\n")
3750 ;; Create magic button.
3751 (let ((magic (widget-create-child-and-convert
3752 widget 'custom-magic
3753 :indent 0
3754 nil)))
3755 (widget-put widget :custom-magic magic)
3756 (push magic buttons))
3757 ;; Update buttons.
3758 (widget-put widget :buttons buttons)
3759 ;; Insert documentation.
3760 (widget-default-format-handler widget ?h)
3761 ;; Parent groups.
3762 (if nil ;;; This should test that the buffer
3763 ;;; was not made to display a group.
3764 (when (eq level 1)
3765 (insert-char ?\ custom-buffer-indent)
3766 (custom-add-parent-links widget)))
3767 (custom-add-see-also widget
3768 (make-string (* custom-buffer-indent level)
3769 ?\ ))
3770 ;; Members.
3771 (message "Creating group...")
3772 (let* ((members (custom-sort-items members
3773 custom-buffer-sort-alphabetically
3774 custom-buffer-order-groups))
3775 (prefixes (widget-get widget :custom-prefixes))
3776 (custom-prefix-list (custom-prefix-add symbol prefixes))
3777 (length (length members))
3778 (count 0)
3779 (children (mapcar (lambda (entry)
3780 (widget-insert "\n")
3781 (message "\
3782 Creating group members... %2d%%"
3783 (/ (* 100.0 count) length))
3784 (setq count (1+ count))
3785 (prog1
3786 (widget-create-child-and-convert
3787 widget (nth 1 entry)
3788 :group widget
3789 :tag (custom-unlispify-tag-name
3790 (nth 0 entry))
3791 :custom-prefixes custom-prefix-list
3792 :custom-level (1+ level)
3793 :value (nth 0 entry))
3794 (unless (eq (preceding-char) ?\n)
3795 (widget-insert "\n"))))
3796 members)))
3797 (message "Creating group magic...")
3798 (mapc 'custom-magic-reset children)
3799 (message "Creating group state...")
3800 (widget-put widget :children children)
3801 (custom-group-state-update widget)
3802 (message "Creating group... done"))
3803 ;; End line
3804 (insert "\n")
3805 (insert-char ?\ (* custom-buffer-indent (1- level)))
3806 (insert "\\- " (widget-get widget :tag) " group end ")
3807 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3808 (insert "/\n")))))
3810 (defvar custom-group-menu
3811 '(("Set for Current Session" custom-group-set
3812 (lambda (widget)
3813 (eq (widget-get widget :custom-state) 'modified)))
3814 ("Save for Future Sessions" custom-group-save
3815 (lambda (widget)
3816 (memq (widget-get widget :custom-state) '(modified set))))
3817 ("Reset to Current" custom-group-reset-current
3818 (lambda (widget)
3819 (memq (widget-get widget :custom-state) '(modified))))
3820 ("Reset to Saved" custom-group-reset-saved
3821 (lambda (widget)
3822 (memq (widget-get widget :custom-state) '(modified set))))
3823 ("Reset to standard setting" custom-group-reset-standard
3824 (lambda (widget)
3825 (memq (widget-get widget :custom-state) '(modified set saved)))))
3826 "Alist of actions for the `custom-group' widget.
3827 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3828 the menu entry, ACTION is the function to call on the widget when the
3829 menu is selected, and FILTER is a predicate which takes a `custom-group'
3830 widget as an argument, and returns non-nil if ACTION is valid on that
3831 widget. If FILTER is nil, ACTION is always valid.")
3833 (defun custom-group-action (widget &optional event)
3834 "Show the menu for `custom-group' WIDGET.
3835 Optional EVENT is the location for the menu."
3836 (if (eq (widget-get widget :custom-state) 'hidden)
3837 (custom-toggle-hide widget)
3838 (let* ((completion-ignore-case t)
3839 (answer (widget-choose (concat "Operation on "
3840 (custom-unlispify-tag-name
3841 (widget-get widget :value)))
3842 (custom-menu-filter custom-group-menu
3843 widget)
3844 event)))
3845 (if answer
3846 (funcall answer widget)))))
3848 (defun custom-group-set (widget)
3849 "Set changes in all modified group members."
3850 (let ((children (widget-get widget :children)))
3851 (mapc (lambda (child)
3852 (when (eq (widget-get child :custom-state) 'modified)
3853 (widget-apply child :custom-set)))
3854 children )))
3856 (defun custom-group-save (widget)
3857 "Save all modified group members."
3858 (let ((children (widget-get widget :children)))
3859 (mapc (lambda (child)
3860 (when (memq (widget-get child :custom-state) '(modified set))
3861 (widget-apply child :custom-save)))
3862 children )))
3864 (defun custom-group-reset-current (widget)
3865 "Reset all modified group members."
3866 (let ((children (widget-get widget :children)))
3867 (mapc (lambda (child)
3868 (when (eq (widget-get child :custom-state) 'modified)
3869 (widget-apply child :custom-reset-current)))
3870 children )))
3872 (defun custom-group-reset-saved (widget)
3873 "Reset all modified or set group members."
3874 (let ((children (widget-get widget :children)))
3875 (mapc (lambda (child)
3876 (when (memq (widget-get child :custom-state) '(modified set))
3877 (widget-apply child :custom-reset-saved)))
3878 children )))
3880 (defun custom-group-reset-standard (widget)
3881 "Reset all modified, set, or saved group members."
3882 (let ((children (widget-get widget :children)))
3883 (mapc (lambda (child)
3884 (when (memq (widget-get child :custom-state)
3885 '(modified set saved))
3886 (widget-apply child :custom-reset-standard)))
3887 children )))
3889 (defun custom-group-state-update (widget)
3890 "Update magic."
3891 (unless (eq (widget-get widget :custom-state) 'hidden)
3892 (let* ((children (widget-get widget :children))
3893 (states (mapcar (lambda (child)
3894 (widget-get child :custom-state))
3895 children))
3896 (magics custom-magic-alist)
3897 (found 'standard))
3898 (while magics
3899 (let ((magic (car (car magics))))
3900 (if (and (not (eq magic 'hidden))
3901 (memq magic states))
3902 (setq found magic
3903 magics nil)
3904 (setq magics (cdr magics)))))
3905 (widget-put widget :custom-state found)))
3906 (custom-magic-reset widget))
3908 ;;; Reading and writing the custom file.
3910 ;;;###autoload
3911 (defcustom custom-file nil
3912 "File used for storing customization information.
3913 The default is nil, which means to use your init file
3914 as specified by `user-init-file'. If the value is not nil,
3915 it should be an absolute file name.
3917 You can set this option through Custom, if you carefully read the
3918 last paragraph below. However, usually it is simpler to write
3919 something like the following in your init file:
3921 \(setq custom-file \"~/.emacs-custom.el\")
3922 \(load custom-file)
3924 Note that both lines are necessary: the first line tells Custom to
3925 save all customizations in this file, but does not load it.
3927 When you change this variable outside Custom, look in the
3928 previous custom file \(usually your init file) for the
3929 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
3930 and copy them (whichever ones you find) to the new custom file.
3931 This will preserve your existing customizations.
3933 If you save this option using Custom, Custom will write all
3934 currently saved customizations, including the new one for this
3935 option itself, into the file you specify, overwriting any
3936 `custom-set-variables' and `custom-set-faces' forms already
3937 present in that file. It will not delete any customizations from
3938 the old custom file. You should do that manually if that is what you
3939 want. You also have to put something like `\(load \"CUSTOM-FILE\")
3940 in your init file, where CUSTOM-FILE is the actual name of the
3941 file. Otherwise, Emacs will not load the file when it starts up,
3942 and hence will not set `custom-file' to that file either."
3943 :type '(choice (const :tag "Your Emacs init file" nil)
3944 (file :format "%t:%v%d"
3945 :doc
3946 "Please read entire docstring below before setting \
3947 this through Custom.
3948 Click om \"More\" \(or position point there and press RETURN)
3949 if only the first line of the docstring is shown."))
3950 :group 'customize)
3952 (defun custom-file ()
3953 "Return the file name for saving customizations."
3954 (file-chase-links
3955 (or custom-file
3956 (let ((user-init-file user-init-file)
3957 (default-init-file
3958 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
3959 (when (null user-init-file)
3960 (if (or (file-exists-p default-init-file)
3961 (and (eq system-type 'windows-nt)
3962 (file-exists-p "~/_emacs")))
3963 ;; Started with -q, i.e. the file containing
3964 ;; Custom settings hasn't been read. Saving
3965 ;; settings there would overwrite other settings.
3966 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3967 (setq user-init-file default-init-file))
3968 user-init-file))))
3970 ;;;###autoload
3971 (defun custom-save-all ()
3972 "Save all customizations in `custom-file'."
3973 (let* ((filename (custom-file))
3974 (recentf-exclude (if recentf-mode
3975 (cons (concat "\\`"
3976 (regexp-quote (custom-file))
3977 "\\'")
3978 recentf-exclude)))
3979 (old-buffer (find-buffer-visiting filename)))
3980 (with-current-buffer (or old-buffer (find-file-noselect filename))
3981 (let ((inhibit-read-only t))
3982 (custom-save-variables)
3983 (custom-save-faces))
3984 (let ((file-precious-flag t))
3985 (save-buffer))
3986 (unless old-buffer
3987 (kill-buffer (current-buffer))))))
3989 ;; Editing the custom file contents in a buffer.
3991 (defun custom-save-delete (symbol)
3992 "Delete all calls to SYMBOL from the contents of the current buffer.
3993 Leave point at the old location of the first such call,
3994 or (if there were none) at the end of the buffer.
3996 This function does not save the buffer."
3997 (goto-char (point-min))
3998 ;; Skip all whitespace and comments.
3999 (while (forward-comment 1))
4000 (or (eobp)
4001 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4002 (let (first)
4003 (catch 'found
4004 (while t ;; We exit this loop only via throw.
4005 ;; Skip all whitespace and comments.
4006 (while (forward-comment 1))
4007 (let ((start (point))
4008 (sexp (condition-case nil
4009 (read (current-buffer))
4010 (end-of-file (throw 'found nil)))))
4011 (when (and (listp sexp)
4012 (eq (car sexp) symbol))
4013 (delete-region start (point))
4014 (unless first
4015 (setq first (point)))))))
4016 (if first
4017 (goto-char first)
4018 ;; Move in front of local variables, otherwise long Custom
4019 ;; entries would make them ineffective.
4020 (let ((pos (point-max))
4021 (case-fold-search t))
4022 (save-excursion
4023 (goto-char (point-max))
4024 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4025 'move)
4026 (when (search-forward "Local Variables:" nil t)
4027 (setq pos (line-beginning-position))))
4028 (goto-char pos)))))
4030 (defun custom-save-variables ()
4031 "Save all customized variables in `custom-file'."
4032 (save-excursion
4033 (custom-save-delete 'custom-load-themes)
4034 (custom-save-delete 'custom-reset-variables)
4035 (custom-save-delete 'custom-set-variables)
4036 (custom-save-loaded-themes)
4037 (custom-save-resets 'theme-value 'custom-reset-variables nil)
4038 (let ((standard-output (current-buffer))
4039 (saved-list (make-list 1 0))
4040 sort-fold-case)
4041 ;; First create a sorted list of saved variables.
4042 (mapatoms
4043 (lambda (symbol)
4044 (if (get symbol 'saved-value)
4045 (nconc saved-list (list symbol)))))
4046 (setq saved-list (sort (cdr saved-list) 'string<))
4047 (unless (bolp)
4048 (princ "\n"))
4049 (princ "(custom-set-variables
4050 ;; custom-set-variables was added by Custom.
4051 ;; If you edit it by hand, you could mess it up, so be careful.
4052 ;; Your init file should contain only one such instance.
4053 ;; If there is more than one, they won't work right.\n")
4054 (dolist (symbol saved-list)
4055 (let ((spec (car-safe (get symbol 'theme-value)))
4056 (value (get symbol 'saved-value))
4057 (requests (get symbol 'custom-requests))
4058 (now (not (or (custom-variable-p symbol)
4059 (and (not (boundp symbol))
4060 (not (eq (get symbol 'force-value)
4061 'rogue))))))
4062 (comment (get symbol 'saved-variable-comment)))
4063 ;; Check `requests'.
4064 (dolist (request requests)
4065 (when (and (symbolp request) (not (featurep request)))
4066 (message "Unknown requested feature: %s" request)
4067 (setq requests (delq request requests))))
4068 (when (or (and spec
4069 (eq (nth 0 spec) 'user)
4070 (eq (nth 1 spec) 'set))
4071 comment
4072 (and (null spec) (get symbol 'saved-value)))
4073 (unless (bolp)
4074 (princ "\n"))
4075 (princ " '(")
4076 (prin1 symbol)
4077 (princ " ")
4078 (prin1 (car value))
4079 (when (or now requests comment)
4080 (princ " ")
4081 (prin1 now)
4082 (when (or requests comment)
4083 (princ " ")
4084 (prin1 requests)
4085 (when comment
4086 (princ " ")
4087 (prin1 comment))))
4088 (princ ")"))))
4089 (if (bolp)
4090 (princ " "))
4091 (princ ")")
4092 (unless (looking-at "\n")
4093 (princ "\n")))))
4095 (defun custom-save-faces ()
4096 "Save all customized faces in `custom-file'."
4097 (save-excursion
4098 (custom-save-delete 'custom-reset-faces)
4099 (custom-save-delete 'custom-set-faces)
4100 (custom-save-resets 'theme-face 'custom-reset-faces '(default))
4101 (let ((standard-output (current-buffer))
4102 (saved-list (make-list 1 0))
4103 sort-fold-case)
4104 ;; First create a sorted list of saved faces.
4105 (mapatoms
4106 (lambda (symbol)
4107 (if (get symbol 'saved-face)
4108 (nconc saved-list (list symbol)))))
4109 (setq saved-list (sort (cdr saved-list) 'string<))
4110 ;; The default face must be first, since it affects the others.
4111 (if (memq 'default saved-list)
4112 (setq saved-list (cons 'default (delq 'default saved-list))))
4113 (unless (bolp)
4114 (princ "\n"))
4115 (princ "(custom-set-faces
4116 ;; custom-set-faces was added by Custom.
4117 ;; If you edit it by hand, you could mess it up, so be careful.
4118 ;; Your init file should contain only one such instance.
4119 ;; If there is more than one, they won't work right.\n")
4120 (dolist (symbol saved-list)
4121 (let ((spec (car-safe (get symbol 'theme-face)))
4122 (value (get symbol 'saved-face))
4123 (now (not (or (get symbol 'face-defface-spec)
4124 (and (not (custom-facep symbol))
4125 (not (get symbol 'force-face))))))
4126 (comment (get symbol 'saved-face-comment)))
4127 (when (or (and spec
4128 (eq (nth 0 spec) 'user)
4129 (eq (nth 1 spec) 'set))
4130 comment
4131 (and (null spec) (get symbol 'saved-face)))
4132 ;; Don't print default face here.
4133 (unless (bolp)
4134 (princ "\n"))
4135 (princ " '(")
4136 (prin1 symbol)
4137 (princ " ")
4138 (prin1 value)
4139 (when (or now comment)
4140 (princ " ")
4141 (prin1 now)
4142 (when comment
4143 (princ " ")
4144 (prin1 comment)))
4145 (princ ")"))))
4146 (if (bolp)
4147 (princ " "))
4148 (princ ")")
4149 (unless (looking-at "\n")
4150 (princ "\n")))))
4152 (defun custom-save-resets (property setter special)
4153 (let (started-writing ignored-special)
4154 ;; (custom-save-delete setter) Done by caller
4155 (let ((standard-output (current-buffer))
4156 (mapper `(lambda (object)
4157 (let ((spec (car-safe (get object (quote ,property)))))
4158 (when (and (not (memq object ignored-special))
4159 (eq (nth 0 spec) 'user)
4160 (eq (nth 1 spec) 'reset))
4161 ;; Do not write reset statements unless necessary.
4162 (unless started-writing
4163 (setq started-writing t)
4164 (unless (bolp)
4165 (princ "\n"))
4166 (princ "(")
4167 (princ (quote ,setter))
4168 (princ "\n '(")
4169 (prin1 object)
4170 (princ " ")
4171 (prin1 (nth 3 spec))
4172 (princ ")")))))))
4173 (mapc mapper special)
4174 (setq ignored-special special)
4175 (mapatoms mapper)
4176 (when started-writing
4177 (princ ")\n")))))
4179 (defun custom-save-loaded-themes ()
4180 (let ((themes (reverse (get 'user 'theme-loads-themes)))
4181 (standard-output (current-buffer)))
4182 (when themes
4183 (unless (bolp) (princ "\n"))
4184 (princ "(custom-load-themes")
4185 (mapc (lambda (theme)
4186 (princ "\n '")
4187 (prin1 theme)) themes)
4188 (princ " )\n"))))
4190 ;;;###autoload
4191 (defun customize-save-customized ()
4192 "Save all user options which have been set in this session."
4193 (interactive)
4194 (mapatoms (lambda (symbol)
4195 (let ((face (get symbol 'customized-face))
4196 (value (get symbol 'customized-value))
4197 (face-comment (get symbol 'customized-face-comment))
4198 (variable-comment
4199 (get symbol 'customized-variable-comment)))
4200 (when face
4201 (put symbol 'saved-face face)
4202 (custom-push-theme 'theme-face symbol 'user 'set value)
4203 (put symbol 'customized-face nil))
4204 (when value
4205 (put symbol 'saved-value value)
4206 (custom-push-theme 'theme-value symbol 'user 'set value)
4207 (put symbol 'customized-value nil))
4208 (when variable-comment
4209 (put symbol 'saved-variable-comment variable-comment)
4210 (put symbol 'customized-variable-comment nil))
4211 (when face-comment
4212 (put symbol 'saved-face-comment face-comment)
4213 (put symbol 'customized-face-comment nil)))))
4214 ;; We really should update all custom buffers here.
4215 (custom-save-all))
4217 ;;; The Customize Menu.
4219 ;;; Menu support
4221 (defcustom custom-menu-nesting 2
4222 "Maximum nesting in custom menus."
4223 :type 'integer
4224 :group 'custom-menu)
4226 (defun custom-face-menu-create (widget symbol)
4227 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4228 (vector (custom-unlispify-menu-entry symbol)
4229 `(customize-face ',symbol)
4232 (defun custom-variable-menu-create (widget symbol)
4233 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4234 (let ((type (get symbol 'custom-type)))
4235 (unless (listp type)
4236 (setq type (list type)))
4237 (if (and type (widget-get type :custom-menu))
4238 (widget-apply type :custom-menu symbol)
4239 (vector (custom-unlispify-menu-entry symbol)
4240 `(customize-variable ',symbol)
4241 t))))
4243 ;; Add checkboxes to boolean variable entries.
4244 (widget-put (get 'boolean 'widget-type)
4245 :custom-menu (lambda (widget symbol)
4246 (vector (custom-unlispify-menu-entry symbol)
4247 `(customize-variable ',symbol)
4248 ':style 'toggle
4249 ':selected symbol)))
4251 (defun custom-group-menu-create (widget symbol)
4252 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4253 `( ,(custom-unlispify-menu-entry symbol t)
4254 :filter (lambda (&rest junk)
4255 (let ((menu (custom-menu-create ',symbol)))
4256 (if (consp menu) (cdr menu) menu)))))
4258 ;;;###autoload
4259 (defun custom-menu-create (symbol)
4260 "Create menu for customization group SYMBOL.
4261 The menu is in a format applicable to `easy-menu-define'."
4262 (let* ((item (vector (custom-unlispify-menu-entry symbol)
4263 `(customize-group ',symbol)
4264 t)))
4265 (if (and (or (not (boundp 'custom-menu-nesting))
4266 (>= custom-menu-nesting 0))
4267 (progn
4268 (custom-load-symbol symbol)
4269 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
4270 (let ((custom-prefix-list (custom-prefix-add symbol
4271 custom-prefix-list))
4272 (members (custom-sort-items (get symbol 'custom-group)
4273 custom-menu-sort-alphabetically
4274 custom-menu-order-groups)))
4275 `(,(custom-unlispify-menu-entry symbol t)
4276 ,item
4277 "--"
4278 ,@(mapcar (lambda (entry)
4279 (widget-apply (if (listp (nth 1 entry))
4280 (nth 1 entry)
4281 (list (nth 1 entry)))
4282 :custom-menu (nth 0 entry)))
4283 members)))
4284 item)))
4286 ;;;###autoload
4287 (defun customize-menu-create (symbol &optional name)
4288 "Return a customize menu for customization group SYMBOL.
4289 If optional NAME is given, use that as the name of the menu.
4290 Otherwise the menu will be named `Customize'.
4291 The format is suitable for use with `easy-menu-define'."
4292 (unless name
4293 (setq name "Customize"))
4294 `(,name
4295 :filter (lambda (&rest junk)
4296 (let ((menu (custom-menu-create ',symbol)))
4297 (if (consp menu) (cdr menu) menu)))))
4299 ;;; The Custom Mode.
4301 (defvar custom-mode-map
4302 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4303 ;; "\r" bindings from the parent map.
4304 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4305 (let ((map (make-keymap)))
4306 (set-keymap-parent map widget-keymap)
4307 (suppress-keymap map)
4308 (define-key map " " 'scroll-up)
4309 (define-key map "\177" 'scroll-down)
4310 (define-key map "\C-c\C-c" 'Custom-set)
4311 (define-key map "\C-x\C-s" 'Custom-save)
4312 (define-key map "q" 'Custom-buffer-done)
4313 (define-key map "u" 'Custom-goto-parent)
4314 (define-key map "n" 'widget-forward)
4315 (define-key map "p" 'widget-backward)
4316 (define-key map [mouse-1] 'widget-move-and-invoke)
4317 map)
4318 "Keymap for `custom-mode'.")
4320 (easy-menu-define Custom-mode-menu
4321 custom-mode-map
4322 "Menu used in customization buffers."
4323 `("Custom"
4324 ,(customize-menu-create 'customize)
4325 ["Set" Custom-set t]
4326 ["Save" Custom-save t]
4327 ["Reset to Current" Custom-reset-current t]
4328 ["Reset to Saved" Custom-reset-saved t]
4329 ["Reset to Standard Settings" Custom-reset-standard t]
4330 ["Info" (info "(emacs)Easy Customization") t]))
4332 (defun Custom-goto-parent ()
4333 "Go to the parent group listed at the top of this buffer.
4334 If several parents are listed, go to the first of them."
4335 (interactive)
4336 (save-excursion
4337 (goto-char (point-min))
4338 (if (search-forward "\nGo to parent group: " nil t)
4339 (let* ((button (get-char-property (point) 'button))
4340 (parent (downcase (widget-get button :tag))))
4341 (customize-group parent)))))
4343 (defcustom custom-mode-hook nil
4344 "Hook called when entering Custom mode."
4345 :type 'hook
4346 :group 'custom-buffer )
4348 (defun custom-state-buffer-message (widget)
4349 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4350 (message "To install your edits, invoke [State] and choose the Set operation")))
4352 (defun custom-mode ()
4353 "Major mode for editing customization buffers.
4355 The following commands are available:
4357 Move to next button or editable field. \\[widget-forward]
4358 Move to previous button or editable field. \\[widget-backward]
4359 \\<widget-field-keymap>\
4360 Complete content of editable text field. \\[widget-complete]
4361 \\<custom-mode-map>\
4362 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4363 Invoke button under point. \\[widget-button-press]
4364 Set all modifications. \\[Custom-set]
4365 Make all modifications default. \\[Custom-save]
4366 Reset all modified options. \\[Custom-reset-current]
4367 Reset all modified or set options. \\[Custom-reset-saved]
4368 Reset all options. \\[Custom-reset-standard]
4370 Entry to this mode calls the value of `custom-mode-hook'
4371 if that value is non-nil."
4372 (kill-all-local-variables)
4373 (setq major-mode 'custom-mode
4374 mode-name "Custom")
4375 (use-local-map custom-mode-map)
4376 (easy-menu-add Custom-mode-menu)
4377 (make-local-variable 'custom-options)
4378 (make-local-variable 'custom-local-buffer)
4379 (make-local-variable 'widget-documentation-face)
4380 (setq widget-documentation-face 'custom-documentation)
4381 (make-local-variable 'widget-button-face)
4382 (setq widget-button-face custom-button)
4383 (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed)
4384 (if custom-raised-buttons
4385 (set (make-local-variable 'widget-mouse-face) custom-button))
4387 ;; When possible, use relief for buttons, not bracketing. This test
4388 ;; may not be optimal.
4389 (when custom-raised-buttons
4390 (set (make-local-variable 'widget-push-button-prefix) "")
4391 (set (make-local-variable 'widget-push-button-suffix) "")
4392 (set (make-local-variable 'widget-link-prefix) "")
4393 (set (make-local-variable 'widget-link-suffix) ""))
4394 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
4395 (run-mode-hooks 'custom-mode-hook))
4397 (put 'custom-mode 'mode-class 'special)
4399 (add-to-list
4400 'debug-ignored-errors
4401 "^No user options have changed defaults in recent Emacs versions$")
4403 ;;; The End.
4405 (provide 'cus-edit)
4407 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4408 ;;; cus-edit.el ends here