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