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