(set_case_table): If standard is nonzero, setup
[emacs.git] / lisp / cus-edit.el
blobfb76aa6c3d899bd104ea2da2e6234536e5d2cdff
1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
2 ;;
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 ;; 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., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
27 ;;; Commentary:
29 ;; This file implements the code to create and edit customize buffers.
31 ;; See `custom.el'.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
37 ;; The identity of a customize option is represented by a Lisp symbol.
38 ;; The following values are associated with an option.
40 ;; 0. The current value.
42 ;; This is the value of the option as seen by "the rest of Emacs".
44 ;; Usually extracted by 'default-value', but can be extracted with
45 ;; different means if the option symbol has the 'custom-get'
46 ;; property. Similarly, set-default (or the 'custom-set' property)
47 ;; can set it.
49 ;; 1. The widget value.
51 ;; This is the value shown in the widget in a customize buffer.
53 ;; 2. The customized value.
55 ;; This is the last value given to the option through customize.
57 ;; It is stored in the 'customized-value' property of the option, in a
58 ;; cons-cell whose car evaluates to the customized value.
60 ;; 3. The saved value.
62 ;; This is last value saved from customize.
64 ;; It is stored in the 'saved-value' property of the option, in a
65 ;; cons-cell whose car evaluates to the saved value.
67 ;; 4. The standard value.
69 ;; This is the value given in the 'defcustom' declaration.
71 ;; It is stored in the 'standard-value' property of the option, in a
72 ;; cons-cell whose car evaluates to the standard value.
74 ;; 5. The "think" value.
76 ;; This is what customize thinks the current value should be.
78 ;; This is the customized value, if any such value exists, otherwise
79 ;; the saved value, if that exists, and as a last resort the standard
80 ;; value.
82 ;; The reason for storing values unevaluated: This is so you can have
83 ;; values that depend on the environment. For example, you can have a
84 ;; variable that has one value when Emacs is running under a window
85 ;; system, and another value on a tty. Since the evaluation is only done
86 ;; when the variable is first initialized, this is only relevant for the
87 ;; saved (and standard) values, but affect others values for
88 ;; compatibility.
90 ;; You can see (and modify and save) this unevaluated value by selecting
91 ;; "Show initial Lisp expression" from the Lisp interface. This will
92 ;; give you the unevaluated saved value, if any, otherwise the
93 ;; unevaluated standard value.
95 ;; The possible states for a customize widget are:
97 ;; 0. unknown
99 ;; The state has not been determined yet.
101 ;; 1. modified
103 ;; The widget value is different from the current value.
105 ;; 2. changed
107 ;; The current value is different from the "think" value.
109 ;; 3. set
111 ;; The "think" value is the customized value.
113 ;; 4. saved
115 ;; The "think" value is the saved value.
117 ;; 5. standard
119 ;; The "think" value is the standard value.
121 ;; 6. rogue
123 ;; There is no standard value. This means that the variable was
124 ;; not defined with defcustom, nor handled in cus-start.el. You
125 ;; can not create a Custom buffer for such variables using the
126 ;; normal interactive Custom commands. However, such Custom
127 ;; buffers can be created in other ways, for instance, by calling
128 ;; `customize-option' non-interactively.
130 ;; 7. hidden
132 ;; There is no widget value.
134 ;; 8. mismatch
136 ;; The widget value is not valid member of the :type specified for the
137 ;; option.
139 ;;; Code:
141 (require 'cus-face)
142 (require 'wid-edit)
143 (eval-when-compile
144 (defvar custom-versions-load-alist)) ; from cus-load
146 (condition-case nil
147 (require 'cus-load)
148 (error nil))
150 (condition-case nil
151 (require 'cus-start)
152 (error nil))
154 (put 'custom-define-hook 'custom-type 'hook)
155 (put 'custom-define-hook 'standard-value '(nil))
156 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
158 ;;; Customization Groups.
160 (defgroup emacs nil
161 "Customization of the One True Editor."
162 :link '(custom-manual "(emacs)Top"))
164 ;; Most of these groups are stolen from `finder.el',
165 (defgroup editing nil
166 "Basic text editing facilities."
167 :group 'emacs)
169 (defgroup abbrev nil
170 "Abbreviation handling, typing shortcuts, macros."
171 :tag "Abbreviations"
172 :group 'editing)
174 (defgroup matching nil
175 "Various sorts of searching and matching."
176 :group 'editing)
178 (defgroup emulations nil
179 "Emulations of other editors."
180 :link '(custom-manual "(emacs)Emulation")
181 :group 'editing)
183 (defgroup mouse nil
184 "Mouse support."
185 :group 'editing)
187 (defgroup outlines nil
188 "Support for hierarchical outlining."
189 :group 'editing)
191 (defgroup external nil
192 "Interfacing to external utilities."
193 :group 'emacs)
195 (defgroup processes nil
196 "Process, subshell, compilation, and job control support."
197 :group 'external
198 :group 'development)
200 (defgroup convenience nil
201 "Convenience features for faster editing."
202 :group 'emacs)
204 (defgroup programming nil
205 "Support for programming in other languages."
206 :group 'emacs)
208 (defgroup languages nil
209 "Specialized modes for editing programming languages."
210 :group 'programming)
212 (defgroup lisp nil
213 "Lisp support, including Emacs Lisp."
214 :group 'languages
215 :group 'development)
217 (defgroup c nil
218 "Support for the C language and related languages."
219 :link '(custom-manual "(ccmode)")
220 :group 'languages)
222 (defgroup tools nil
223 "Programming tools."
224 :group 'programming)
226 (defgroup oop nil
227 "Support for object-oriented programming."
228 :group 'programming)
230 (defgroup applications nil
231 "Applications written in Emacs."
232 :group 'emacs)
234 (defgroup calendar nil
235 "Calendar and time management support."
236 :group 'applications)
238 (defgroup mail nil
239 "Modes for electronic-mail handling."
240 :group 'applications)
242 (defgroup news nil
243 "Support for netnews reading and posting."
244 :link '(custom-manual "(gnus)")
245 :group 'applications)
247 (defgroup games nil
248 "Games, jokes and amusements."
249 :group 'applications)
251 (defgroup development nil
252 "Support for further development of Emacs."
253 :group 'emacs)
255 (defgroup docs nil
256 "Support for Emacs documentation."
257 :group 'development)
259 (defgroup extensions nil
260 "Emacs Lisp language extensions."
261 :group 'development)
263 (defgroup internal nil
264 "Code for Emacs internals, build process, defaults."
265 :group 'development)
267 (defgroup maint nil
268 "Maintenance aids for the Emacs development group."
269 :tag "Maintenance"
270 :group 'development)
272 (defgroup environment nil
273 "Fitting Emacs with its environment."
274 :group 'emacs)
276 (defgroup comm nil
277 "Communications, networking, remote access to files."
278 :tag "Communication"
279 :group 'environment)
281 (defgroup hardware nil
282 "Support for interfacing with exotic hardware."
283 :group 'environment)
285 (defgroup terminals nil
286 "Support for terminal types."
287 :group 'environment)
289 (defgroup unix nil
290 "Front-ends/assistants for, or emulators of, UNIX features."
291 :group 'environment)
293 (defgroup vms nil
294 "Support code for vms."
295 :group 'environment)
297 (defgroup i18n nil
298 "Internationalization and alternate character-set support."
299 :link '(custom-manual "(emacs)International")
300 :group 'environment
301 :group 'editing)
303 (defgroup x nil
304 "The X Window system."
305 :group 'environment)
307 (defgroup frames nil
308 "Support for Emacs frames and window systems."
309 :group 'environment)
311 (defgroup data nil
312 "Support editing files of data."
313 :group 'emacs)
315 (defgroup files nil
316 "Support editing files."
317 :group 'emacs)
319 (defgroup wp nil
320 "Word processing."
321 :group 'emacs)
323 (defgroup tex nil
324 "Code related to the TeX formatter."
325 :group 'wp)
327 (defgroup faces nil
328 "Support for multiple fonts."
329 :group 'emacs)
331 (defgroup hypermedia nil
332 "Support for links between text or other media types."
333 :group 'emacs)
335 (defgroup help nil
336 "Support for on-line help systems."
337 :group 'emacs)
339 (defgroup multimedia nil
340 "Non-textual support, specifically images and sound."
341 :group 'emacs)
343 (defgroup local nil
344 "Code local to your site."
345 :group 'emacs)
347 (defgroup customize '((widgets custom-group))
348 "Customization of the Customization support."
349 :prefix "custom-"
350 :group 'help)
352 (defgroup custom-faces nil
353 "Faces used by customize."
354 :group 'customize
355 :group 'faces)
357 (defgroup custom-browse nil
358 "Control customize browser."
359 :prefix "custom-"
360 :group 'customize)
362 (defgroup custom-buffer nil
363 "Control customize buffers."
364 :prefix "custom-"
365 :group 'customize)
367 (defgroup custom-menu nil
368 "Control customize menus."
369 :prefix "custom-"
370 :group 'customize)
372 (defgroup abbrev-mode nil
373 "Word abbreviations mode."
374 :link '(custom-manual "(emacs)Abbrevs")
375 :group 'abbrev)
377 (defgroup alloc nil
378 "Storage allocation and gc for GNU Emacs Lisp interpreter."
379 :tag "Storage Allocation"
380 :group 'internal)
382 (defgroup undo nil
383 "Undoing changes in buffers."
384 :link '(custom-manual "(emacs)Undo")
385 :group 'editing)
387 (defgroup modeline nil
388 "Content of the modeline."
389 :group 'environment)
391 (defgroup editing-basics nil
392 "Most basic editing facilities."
393 :group 'editing)
395 (defgroup display nil
396 "How characters are displayed in buffers."
397 :group 'environment)
399 (defgroup execute nil
400 "Executing external commands."
401 :group 'processes)
403 (defgroup installation nil
404 "The Emacs installation."
405 :group 'environment)
407 (defgroup dired nil
408 "Directory editing."
409 :group 'environment)
411 (defgroup limits nil
412 "Internal Emacs limits."
413 :group 'internal)
415 (defgroup debug nil
416 "Debugging Emacs itself."
417 :group 'development)
419 (defgroup minibuffer nil
420 "Controling the behaviour of the minibuffer."
421 :link '(custom-manual "(emacs)Minibuffer")
422 :group 'environment)
424 (defgroup keyboard nil
425 "Input from the keyboard."
426 :group 'environment)
428 (defgroup mouse nil
429 "Input from the mouse."
430 :group 'environment)
432 (defgroup menu nil
433 "Input from the menus."
434 :group 'environment)
436 (defgroup auto-save nil
437 "Preventing accidential loss of data."
438 :group 'files)
440 (defgroup processes-basics nil
441 "Basic stuff dealing with processes."
442 :group 'processes)
444 (defgroup mule nil
445 "MULE Emacs internationalization."
446 :group 'i18n)
448 (defgroup windows nil
449 "Windows within a frame."
450 :link '(custom-manual "(emacs)Windows")
451 :group 'environment)
453 ;;; Utilities.
455 (defun custom-quote (sexp)
456 "Quote SEXP iff it is not self quoting."
457 (if (or (memq sexp '(t nil))
458 (keywordp sexp)
459 (and (listp sexp)
460 (memq (car sexp) '(lambda)))
461 (stringp sexp)
462 (numberp sexp)
463 (vectorp sexp)
464 ;;; (and (fboundp 'characterp)
465 ;;; (characterp sexp))
467 sexp
468 (list 'quote sexp)))
470 (defun custom-split-regexp-maybe (regexp)
471 "If REGEXP is a string, split it to a list at `\\|'.
472 You can get the original back with from the result with:
473 (mapconcat 'identity result \"\\|\")
475 IF REGEXP is not a string, return it unchanged."
476 (if (stringp regexp)
477 (let ((start 0)
478 all)
479 (while (string-match "\\\\|" regexp start)
480 (setq all (cons (substring regexp start (match-beginning 0)) all)
481 start (match-end 0)))
482 (nreverse (cons (substring regexp start) all)))
483 regexp))
485 (defun custom-variable-prompt ()
486 "Prompt for a custom variable, defaulting to the variable at point.
487 Return a list suitable for use in `interactive'."
488 (let ((v (variable-at-point))
489 (enable-recursive-minibuffers t)
490 val)
491 (setq val (completing-read
492 (if (and (symbolp v) (custom-variable-p v))
493 (format "Customize option: (default %s) " v)
494 "Customize option: ")
495 obarray 'custom-variable-p t))
496 (list (if (equal val "")
497 (if (symbolp v) v nil)
498 (intern val)))))
500 (defun custom-menu-filter (menu widget)
501 "Convert MENU to the form used by `widget-choose'.
502 MENU should be in the same format as `custom-variable-menu'.
503 WIDGET is the widget to apply the filter entries of MENU on."
504 (let ((result nil)
505 current name action filter)
506 (while menu
507 (setq current (car menu)
508 name (nth 0 current)
509 action (nth 1 current)
510 filter (nth 2 current)
511 menu (cdr menu))
512 (if (or (null filter) (funcall filter widget))
513 (push (cons name action) result)
514 (push name result)))
515 (nreverse result)))
517 ;;; Unlispify.
519 (defvar custom-prefix-list nil
520 "List of prefixes that should be ignored by `custom-unlispify'.")
522 (defcustom custom-unlispify-menu-entries t
523 "Display menu entries as words instead of symbols if non nil."
524 :group 'custom-menu
525 :type 'boolean)
527 (defcustom custom-unlispify-remove-prefixes nil
528 "Non-nil means remove group prefixes from option names in buffer."
529 :group 'custom-menu
530 :group 'custom-buffer
531 :type 'boolean)
533 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
534 "Convert SYMBOL into a menu entry."
535 (cond ((not custom-unlispify-menu-entries)
536 (symbol-name symbol))
537 ((get symbol 'custom-tag)
538 (if no-suffix
539 (get symbol 'custom-tag)
540 (concat (get symbol 'custom-tag) "...")))
542 (with-current-buffer (get-buffer-create " *Custom-Work*")
543 (erase-buffer)
544 (princ symbol (current-buffer))
545 (goto-char (point-min))
546 ;; FIXME: Boolean variables are not predicates, so they shouldn't
547 ;; end with `-p'. -stef
548 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
549 ;; (re-search-forward "-p\\'" nil t))
550 ;; (replace-match "" t t)
551 ;; (goto-char (point-min)))
552 (if custom-unlispify-remove-prefixes
553 (let ((prefixes custom-prefix-list)
554 prefix)
555 (while prefixes
556 (setq prefix (car prefixes))
557 (if (search-forward prefix (+ (point) (length prefix)) t)
558 (progn
559 (setq prefixes nil)
560 (delete-region (point-min) (point)))
561 (setq prefixes (cdr prefixes))))))
562 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
563 (capitalize-region (point-min) (point-max))
564 (unless no-suffix
565 (goto-char (point-max))
566 (insert "..."))
567 (buffer-string)))))
569 (defcustom custom-unlispify-tag-names t
570 "Display tag names as words instead of symbols if non nil."
571 :group 'custom-buffer
572 :type 'boolean)
574 (defun custom-unlispify-tag-name (symbol)
575 "Convert SYMBOL into a menu entry."
576 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
577 (custom-unlispify-menu-entry symbol t)))
579 (defun custom-prefix-add (symbol prefixes)
580 "Add SYMBOL to list of ignored PREFIXES."
581 (cons (or (get symbol 'custom-prefix)
582 (concat (symbol-name symbol) "-"))
583 prefixes))
585 ;;; Guess.
587 (defcustom custom-guess-name-alist
588 '(("-p\\'" boolean)
589 ("-hook\\'" hook)
590 ("-face\\'" face)
591 ("-file\\'" file)
592 ("-function\\'" function)
593 ("-functions\\'" (repeat function))
594 ("-list\\'" (repeat sexp))
595 ("-alist\\'" (repeat (cons sexp sexp))))
596 "Alist of (MATCH TYPE).
598 MATCH should be a regexp matching the name of a symbol, and TYPE should
599 be a widget suitable for editing the value of that symbol. The TYPE
600 of the first entry where MATCH matches the name of the symbol will be
601 used.
603 This is used for guessing the type of variables not declared with
604 customize."
605 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
606 :group 'customize)
608 (defcustom custom-guess-doc-alist
609 '(("\\`\\*?Non-nil " boolean))
610 "Alist of (MATCH TYPE).
612 MATCH should be a regexp matching a documentation string, and TYPE
613 should be a widget suitable for editing the value of a variable with
614 that documentation string. The TYPE of the first entry where MATCH
615 matches the name of the symbol will be used.
617 This is used for guessing the type of variables not declared with
618 customize."
619 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
620 :group 'customize)
622 (defun custom-guess-type (symbol)
623 "Guess a widget suitable for editing the value of SYMBOL.
624 This is done by matching SYMBOL with `custom-guess-name-alist' and
625 if that fails, the doc string with `custom-guess-doc-alist'."
626 (let ((name (symbol-name symbol))
627 (names custom-guess-name-alist)
628 current found)
629 (while names
630 (setq current (car names)
631 names (cdr names))
632 (when (string-match (nth 0 current) name)
633 (setq found (nth 1 current)
634 names nil)))
635 (unless found
636 (let ((doc (documentation-property symbol 'variable-documentation))
637 (docs custom-guess-doc-alist))
638 (when doc
639 (while docs
640 (setq current (car docs)
641 docs (cdr docs))
642 (when (string-match (nth 0 current) doc)
643 (setq found (nth 1 current)
644 docs nil))))))
645 found))
647 ;;; Sorting.
649 (defcustom custom-browse-sort-alphabetically nil
650 "If non-nil, sort members of each customization group alphabetically."
651 :type 'boolean
652 :group 'custom-browse)
654 (defcustom custom-browse-order-groups nil
655 "If non-nil, order group members within each customization group.
656 If `first', order groups before non-groups.
657 If `last', order groups after non-groups."
658 :type '(choice (const first)
659 (const last)
660 (const :tag "none" nil))
661 :group 'custom-browse)
663 (defcustom custom-browse-only-groups nil
664 "If non-nil, show group members only within each customization group."
665 :type 'boolean
666 :group 'custom-browse)
668 (defcustom custom-buffer-sort-alphabetically nil
669 "If non-nil, sort members of each customization group alphabetically."
670 :type 'boolean
671 :group 'custom-buffer)
673 (defcustom custom-buffer-order-groups 'last
674 "If non-nil, order group members within each customization group.
675 If `first', order groups before non-groups.
676 If `last', order groups after non-groups."
677 :type '(choice (const first)
678 (const last)
679 (const :tag "none" nil))
680 :group 'custom-buffer)
682 (defcustom custom-menu-sort-alphabetically nil
683 "If non-nil, sort members of each customization group alphabetically."
684 :type 'boolean
685 :group 'custom-menu)
687 (defcustom custom-menu-order-groups 'first
688 "If non-nil, order group members within each customization group.
689 If `first', order groups before non-groups.
690 If `last', order groups after non-groups."
691 :type '(choice (const first)
692 (const last)
693 (const :tag "none" nil))
694 :group 'custom-menu)
696 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
698 (defun custom-sort-items (items sort-alphabetically order-groups)
699 "Return a sorted copy of ITEMS.
700 ITEMS should be a `custom-group' property.
701 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
702 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
703 groups after non-groups, if nil do not order groups at all."
704 (sort (copy-sequence items)
705 (lambda (a b)
706 (let ((typea (nth 1 a)) (typeb (nth 1 b))
707 (namea (nth 0 a)) (nameb (nth 0 b)))
708 (cond ((not order-groups)
709 ;; Since we don't care about A and B order, maybe sort.
710 (when sort-alphabetically
711 (string-lessp namea nameb)))
712 ((eq typea 'custom-group)
713 ;; If B is also a group, maybe sort. Otherwise, order A and B.
714 (if (eq typeb 'custom-group)
715 (when sort-alphabetically
716 (string-lessp namea nameb))
717 (eq order-groups 'first)))
718 ((eq typeb 'custom-group)
719 ;; Since A cannot be a group, order A and B.
720 (eq order-groups 'last))
721 (sort-alphabetically
722 ;; Since A and B cannot be groups, sort.
723 (string-lessp namea nameb)))))))
725 ;;; Custom Mode Commands.
727 (defvar custom-options nil
728 "Customization widgets in the current buffer.")
730 (defun Custom-set ()
731 "Set changes in all modified options."
732 (interactive)
733 (let ((children custom-options))
734 (mapc (lambda (child)
735 (when (eq (widget-get child :custom-state) 'modified)
736 (widget-apply child :custom-set)))
737 children)))
739 (defun Custom-save ()
740 "Set all modified group members and save them."
741 (interactive)
742 (let ((children custom-options))
743 (mapc (lambda (child)
744 (when (memq (widget-get child :custom-state)
745 '(modified set changed rogue))
746 (widget-apply child :custom-save)))
747 children))
748 (custom-save-all))
750 (defvar custom-reset-menu
751 '(("Current" . Custom-reset-current)
752 ("Saved" . Custom-reset-saved)
753 ("Erase Customization (use standard settings)" . Custom-reset-standard))
754 "Alist of actions for the `Reset' button.
755 The key is a string containing the name of the action, the value is a
756 Lisp function taking the widget as an element which will be called
757 when the action is chosen.")
759 (defun custom-reset (event)
760 "Select item from reset menu."
761 (let* ((completion-ignore-case t)
762 (answer (widget-choose "Reset to"
763 custom-reset-menu
764 event)))
765 (if answer
766 (funcall answer))))
768 (defun Custom-reset-current (&rest ignore)
769 "Reset all modified group members to their current value."
770 (interactive)
771 (let ((children custom-options))
772 (mapc (lambda (widget)
773 (if (memq (widget-get widget :custom-state)
774 '(modified changed))
775 (widget-apply widget :custom-reset-current)))
776 children)))
778 (defun Custom-reset-saved (&rest ignore)
779 "Reset all modified or set group members to their saved value."
780 (interactive)
781 (let ((children custom-options))
782 (mapc (lambda (widget)
783 (if (memq (widget-get widget :custom-state)
784 '(modified set changed rogue))
785 (widget-apply widget :custom-reset-saved)))
786 children)))
788 (defun Custom-reset-standard (&rest ignore)
789 "Erase all customization (either current or saved) for the group members.
790 The immediate result is to restore them to their standard settings.
791 This operation eliminates any saved settings for the group members,
792 making them as if they had never been customized at all."
793 (interactive)
794 (let ((children custom-options))
795 (mapc (lambda (widget)
796 (and (widget-apply widget :custom-standard-value)
797 (if (memq (widget-get widget :custom-state)
798 '(modified set changed saved rogue))
799 (widget-apply widget :custom-reset-standard))))
800 children)))
802 ;;; The Customize Commands
804 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
805 "Prompt for a variable and a value and return them as a list.
806 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
807 prompt for the value. The %s escape in PROMPT-VAL is replaced with
808 the name of the variable.
810 If the variable has a `variable-interactive' property, that is used as if
811 it were the arg to `interactive' (which see) to interactively read the value.
813 If the variable has a `custom-type' property, it must be a widget and the
814 `:prompt-value' property of that widget will be used for reading the value.
816 If optional COMMENT argument is non nil, also prompt for a comment and return
817 it as the third element in the list."
818 (let* ((var (read-variable prompt-var))
819 (minibuffer-help-form '(describe-variable var))
820 (val
821 (let ((prop (get var 'variable-interactive))
822 (type (get var 'custom-type))
823 (prompt (format prompt-val var)))
824 (unless (listp type)
825 (setq type (list type)))
826 (cond (prop
827 ;; Use VAR's `variable-interactive' property
828 ;; as an interactive spec for prompting.
829 (call-interactively (list 'lambda '(arg)
830 (list 'interactive prop)
831 'arg)))
832 (type
833 (widget-prompt-value type
834 prompt
835 (if (boundp var)
836 (symbol-value var))
837 (not (boundp var))))
839 (eval-minibuffer prompt))))))
840 (if comment
841 (list var val
842 (read-string "Comment: " (get var 'variable-comment)))
843 (list var val))))
845 ;;;###autoload
846 (defun customize-set-value (variable value &optional comment)
847 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
849 If VARIABLE has a `variable-interactive' property, that is used as if
850 it were the arg to `interactive' (which see) to interactively read the value.
852 If VARIABLE has a `custom-type' property, it must be a widget and the
853 `:prompt-value' property of that widget will be used for reading the value.
855 If given a prefix (or a COMMENT argument), also prompt for a comment."
856 (interactive (custom-prompt-variable "Set variable: "
857 "Set %s to value: "
858 current-prefix-arg))
860 (cond ((string= comment "")
861 (put variable 'variable-comment nil))
862 (comment
863 (put variable 'variable-comment comment)))
864 (set variable value))
866 ;;;###autoload
867 (defun customize-set-variable (variable value &optional comment)
868 "Set the default for VARIABLE to VALUE, and return VALUE.
869 VALUE is a Lisp object.
871 If VARIABLE has a `custom-set' property, that is used for setting
872 VARIABLE, otherwise `set-default' is used.
874 The `customized-value' property of the VARIABLE will be set to a list
875 with a quoted VALUE as its sole list member.
877 If VARIABLE has a `variable-interactive' property, that is used as if
878 it were the arg to `interactive' (which see) to interactively read the value.
880 If VARIABLE has a `custom-type' property, it must be a widget and the
881 `:prompt-value' property of that widget will be used for reading the value.
883 If given a prefix (or a COMMENT argument), also prompt for a comment."
884 (interactive (custom-prompt-variable "Set variable: "
885 "Set customized value for %s to: "
886 current-prefix-arg))
887 (custom-load-symbol variable)
888 (funcall (or (get variable 'custom-set) 'set-default) variable value)
889 (put variable 'customized-value (list (custom-quote value)))
890 (cond ((string= comment "")
891 (put variable 'variable-comment nil)
892 (put variable 'customized-variable-comment nil))
893 (comment
894 (put variable 'variable-comment comment)
895 (put variable 'customized-variable-comment comment)))
896 value)
898 ;;;###autoload
899 (defun customize-save-variable (variable value &optional comment)
900 "Set the default for VARIABLE to VALUE, and save it for future sessions.
901 Return VALUE.
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 and save variable: "
917 "Set and save value for %s as: "
918 current-prefix-arg))
919 (funcall (or (get variable 'custom-set) 'set-default) variable value)
920 (put variable 'saved-value (list (custom-quote value)))
921 (custom-push-theme 'theme-value variable 'user 'set (list (custom-quote value)))
922 (cond ((string= comment "")
923 (put variable 'variable-comment nil)
924 (put variable 'saved-variable-comment nil))
925 (comment
926 (put variable 'variable-comment comment)
927 (put variable 'saved-variable-comment comment)))
928 (custom-save-all)
929 value)
931 ;;;###autoload
932 (defun customize ()
933 "Select a customization buffer which you can use to set user options.
934 User options are structured into \"groups\".
935 Initially the top-level group `Emacs' and its immediate subgroups
936 are shown; the contents of those subgroups are initially hidden."
937 (interactive)
938 (customize-group 'emacs))
940 ;;;###autoload
941 (defun customize-mode (mode)
942 "Customize options related to the current major mode.
943 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
944 then prompt for the MODE to customize."
945 (interactive
946 (list
947 (let ((completion-regexp-list '("-mode\\'"))
948 (group (custom-group-of-mode major-mode)))
949 (if (and group (not current-prefix-arg))
950 major-mode
951 (intern
952 (completing-read (if group
953 (format "Major mode (default %s): " major-mode)
954 "Major mode: ")
955 obarray
956 'custom-group-of-mode
957 t nil nil (if group (symbol-name major-mode))))))))
958 (customize-group (custom-group-of-mode mode)))
961 ;;;###autoload
962 (defun customize-group (group)
963 "Customize GROUP, which must be a customization group."
964 (interactive (list (let ((completion-ignore-case t))
965 (completing-read "Customize group: (default emacs) "
966 obarray
967 (lambda (symbol)
968 (or (get symbol 'custom-loads)
969 (get symbol 'custom-group)))
970 t))))
971 (when (stringp group)
972 (if (string-equal "" group)
973 (setq group 'emacs)
974 (setq group (intern group))))
975 (let ((name (format "*Customize Group: %s*"
976 (custom-unlispify-tag-name group))))
977 (if (get-buffer name)
978 (pop-to-buffer name)
979 (custom-buffer-create (list (list group 'custom-group))
980 name
981 (concat " for group "
982 (custom-unlispify-tag-name group))))))
984 ;;;###autoload
985 (defun customize-group-other-window (group)
986 "Customize GROUP, which must be a customization group."
987 (interactive (list (let ((completion-ignore-case t))
988 (completing-read "Customize group: (default emacs) "
989 obarray
990 (lambda (symbol)
991 (or (get symbol 'custom-loads)
992 (get symbol 'custom-group)))
993 t))))
994 (when (stringp group)
995 (if (string-equal "" group)
996 (setq group 'emacs)
997 (setq group (intern group))))
998 (let ((name (format "*Customize Group: %s*"
999 (custom-unlispify-tag-name group))))
1000 (if (get-buffer name)
1001 (let (
1002 ;; Copied from `custom-buffer-create-other-window'.
1003 (pop-up-windows t)
1004 (same-window-buffer-names nil)
1005 (same-window-regexps nil))
1006 (pop-to-buffer name))
1007 (custom-buffer-create-other-window
1008 (list (list group 'custom-group))
1009 name
1010 (concat " for group "
1011 (custom-unlispify-tag-name group))))))
1013 ;;;###autoload
1014 (defalias 'customize-variable 'customize-option)
1016 ;;;###autoload
1017 (defun customize-option (symbol)
1018 "Customize SYMBOL, which must be a user option variable."
1019 (interactive (custom-variable-prompt))
1020 (custom-buffer-create (list (list symbol 'custom-variable))
1021 (format "*Customize Option: %s*"
1022 (custom-unlispify-tag-name symbol))))
1024 ;;;###autoload
1025 (defalias 'customize-variable-other-window 'customize-option-other-window)
1027 ;;;###autoload
1028 (defun customize-option-other-window (symbol)
1029 "Customize SYMBOL, which must be a user option variable.
1030 Show the buffer in another window, but don't select it."
1031 (interactive (custom-variable-prompt))
1032 (custom-buffer-create-other-window
1033 (list (list symbol 'custom-variable))
1034 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
1036 (defvar customize-changed-options-previous-release "20.2"
1037 "Version for `customize-changed-options' to refer back to by default.")
1039 ;;;###autoload
1040 (defun customize-changed-options (since-version)
1041 "Customize all user option variables changed in Emacs itself.
1042 This includes new user option variables and faces, and new
1043 customization groups, as well as older options and faces whose default
1044 values have changed since the previous major Emacs release.
1046 With argument SINCE-VERSION (a string), customize all user option
1047 variables that were added (or their meanings were changed) since that
1048 version."
1050 (interactive "sCustomize options changed, since version (default all versions): ")
1051 (if (equal since-version "")
1052 (setq since-version nil)
1053 (unless (condition-case nil
1054 (numberp (read since-version))
1055 (error nil))
1056 (signal 'wrong-type-argument (list 'numberp since-version))))
1057 (unless since-version
1058 (setq since-version customize-changed-options-previous-release))
1060 ;; Load the information for versions since since-version. We use
1061 ;; custom-load-symbol for this.
1062 (put 'custom-versions-load-alist 'custom-loads nil)
1063 (dolist (elt custom-versions-load-alist)
1064 (if (customize-version-lessp since-version (car elt))
1065 (dolist (load (cdr elt))
1066 (custom-add-load 'custom-versions-load-alist load))))
1067 (custom-load-symbol 'custom-versions-load-alist)
1068 (put 'custom-versions-load-alist 'custom-loads nil)
1070 (let (found)
1071 (mapatoms
1072 (lambda (symbol)
1073 (let ((version (get symbol 'custom-version)))
1074 (if version
1075 (when (customize-version-lessp since-version version)
1076 (if (or (get symbol 'custom-group)
1077 (get symbol 'group-documentation))
1078 (push (list symbol 'custom-group) found))
1079 (if (custom-variable-p symbol)
1080 (push (list symbol 'custom-variable) found))
1081 (if (custom-facep symbol)
1082 (push (list symbol 'custom-face) found)))))))
1083 (if found
1084 (custom-buffer-create (custom-sort-items found t 'first)
1085 "*Customize Changed Options*")
1086 (error "No user option defaults have been changed since Emacs %s"
1087 since-version))))
1089 (defun customize-version-lessp (version1 version2)
1090 ;; Why are the versions strings, and given that they are, why aren't
1091 ;; they converted to numbers and compared as such here? -- fx
1093 ;; In case someone made a mistake and left out the quotes
1094 ;; in the :version value.
1095 (if (numberp version2)
1096 (setq version2 (prin1-to-string version2)))
1097 (let (major1 major2 minor1 minor2)
1098 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1099 (setq major1 (read (or (match-string 1 version1)
1100 "0")))
1101 (setq minor1 (read (or (match-string 3 version1)
1102 "0")))
1103 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1104 (setq major2 (read (or (match-string 1 version2)
1105 "0")))
1106 (setq minor2 (read (or (match-string 3 version2)
1107 "0")))
1108 (or (< major1 major2)
1109 (and (= major1 major2)
1110 (< minor1 minor2)))))
1112 ;;;###autoload
1113 (defun customize-face (&optional face)
1114 "Customize FACE, which should be a face name or nil.
1115 If FACE is nil, customize all faces.
1117 Interactively, when point is on text which has a face specified,
1118 suggest to customize that face, if it's customizable."
1119 (interactive
1120 (list (read-face-name "Customize face" "all faces" t)))
1121 (if (member face '(nil ""))
1122 (setq face (face-list)))
1123 (if (and (listp face) (null (cdr face)))
1124 (setq face (car face)))
1125 (if (listp face)
1126 (custom-buffer-create (custom-sort-items
1127 (mapcar (lambda (s)
1128 (list s 'custom-face))
1129 face)
1130 t nil)
1131 "*Customize Faces*")
1132 (unless (facep face)
1133 (error "Invalid face %S" face))
1134 (custom-buffer-create (list (list face 'custom-face))
1135 (format "*Customize Face: %s*"
1136 (custom-unlispify-tag-name face)))))
1138 ;;;###autoload
1139 (defun customize-face-other-window (&optional face)
1140 "Show customization buffer for face FACE in other window.
1142 Interactively, when point is on text which has a face specified,
1143 suggest to customize that face, if it's customizable."
1144 (interactive
1145 (list (read-face-name "Customize face" "all faces" t)))
1146 (if (member face '(nil ""))
1147 (setq face (face-list)))
1148 (if (and (listp face) (null (cdr face)))
1149 (setq face (car face)))
1150 (if (listp face)
1151 (custom-buffer-create-other-window
1152 (custom-sort-items
1153 (mapcar (lambda (s)
1154 (list s 'custom-face))
1155 face)
1156 t nil)
1157 "*Customize Faces*")
1158 (unless (facep face)
1159 (error "Invalid face %S" face))
1160 (custom-buffer-create-other-window
1161 (list (list face 'custom-face))
1162 (format "*Customize Face: %s*"
1163 (custom-unlispify-tag-name face)))))
1165 ;;;###autoload
1166 (defun customize-customized ()
1167 "Customize all user options set since the last save in this session."
1168 (interactive)
1169 (let ((found nil))
1170 (mapatoms (lambda (symbol)
1171 (and (or (get symbol 'customized-face)
1172 (get symbol 'customized-face-comment))
1173 (custom-facep symbol)
1174 (push (list symbol 'custom-face) found))
1175 (and (or (get symbol 'customized-value)
1176 (get symbol 'customized-variable-comment))
1177 (boundp symbol)
1178 (push (list symbol 'custom-variable) found))))
1179 (if (not found)
1180 (error "No customized user options")
1181 (custom-buffer-create (custom-sort-items found t nil)
1182 "*Customize Customized*"))))
1184 ;;;###autoload
1185 (defun customize-rogue ()
1186 "Customize all user variable modified outside customize."
1187 (interactive)
1188 (let ((found nil))
1189 (mapatoms (lambda (symbol)
1190 (let ((cval (or (get symbol 'customized-value)
1191 (get symbol 'saved-value)
1192 (get symbol 'standard-value))))
1193 (when (and cval ;Declared with defcustom.
1194 (default-boundp symbol) ;Has a value.
1195 (not (equal (eval (car cval))
1196 ;; Which does not match customize.
1197 (default-value symbol))))
1198 (push (list symbol 'custom-variable) found)))))
1199 (if (not found)
1200 (error "No rogue user options")
1201 (custom-buffer-create (custom-sort-items found t nil)
1202 "*Customize Rogue*"))))
1203 ;;;###autoload
1204 (defun customize-saved ()
1205 "Customize all already saved user options."
1206 (interactive)
1207 (let ((found nil))
1208 (mapatoms (lambda (symbol)
1209 (and (or (get symbol 'saved-face)
1210 (get symbol 'saved-face-comment))
1211 (custom-facep symbol)
1212 (push (list symbol 'custom-face) found))
1213 (and (or (get symbol 'saved-value)
1214 (get symbol 'saved-variable-comment))
1215 (boundp symbol)
1216 (push (list symbol 'custom-variable) found))))
1217 (if (not found )
1218 (error "No saved user options")
1219 (custom-buffer-create (custom-sort-items found t nil)
1220 "*Customize Saved*"))))
1222 ;;;###autoload
1223 (defun customize-apropos (regexp &optional all)
1224 "Customize all user options matching REGEXP.
1225 If ALL is `options', include only options.
1226 If ALL is `faces', include only faces.
1227 If ALL is `groups', include only groups.
1228 If ALL is t (interactively, with prefix arg), include options which are not
1229 user-settable, as well as faces and groups."
1230 (interactive "sCustomize regexp: \nP")
1231 (let ((found nil))
1232 (mapatoms (lambda (symbol)
1233 (when (string-match regexp (symbol-name symbol))
1234 (when (and (not (memq all '(faces options)))
1235 (get symbol 'custom-group))
1236 (push (list symbol 'custom-group) found))
1237 (when (and (not (memq all '(options groups)))
1238 (custom-facep symbol))
1239 (push (list symbol 'custom-face) found))
1240 (when (and (not (memq all '(groups faces)))
1241 (boundp symbol)
1242 (or (get symbol 'saved-value)
1243 (custom-variable-p symbol)
1244 (if (memq all '(nil options))
1245 (user-variable-p symbol)
1246 (get symbol 'variable-documentation))))
1247 (push (list symbol 'custom-variable) found)))))
1248 (if (not found)
1249 (error "No matches")
1250 (custom-buffer-create (custom-sort-items found t
1251 custom-buffer-order-groups)
1252 "*Customize Apropos*"))))
1254 ;;;###autoload
1255 (defun customize-apropos-options (regexp &optional arg)
1256 "Customize all user options matching REGEXP.
1257 With prefix arg, include options which are not user-settable."
1258 (interactive "sCustomize regexp: \nP")
1259 (customize-apropos regexp (or arg 'options)))
1261 ;;;###autoload
1262 (defun customize-apropos-faces (regexp)
1263 "Customize all user faces matching REGEXP."
1264 (interactive "sCustomize regexp: \n")
1265 (customize-apropos regexp 'faces))
1267 ;;;###autoload
1268 (defun customize-apropos-groups (regexp)
1269 "Customize all user groups matching REGEXP."
1270 (interactive "sCustomize regexp: \n")
1271 (customize-apropos regexp 'groups))
1273 ;;; Buffer.
1275 (defcustom custom-buffer-style 'links
1276 "Control the presentation style for customization buffers.
1277 The value should be a symbol, one of:
1279 brackets: groups nest within each other with big horizontal brackets.
1280 links: groups have links to subgroups."
1281 :type '(radio (const brackets)
1282 (const links))
1283 :group 'custom-buffer)
1285 (defcustom custom-buffer-done-kill nil
1286 "*Non-nil means exiting a Custom buffer should kill it."
1287 :type 'boolean
1288 :version "22.1"
1289 :group 'custom-buffer)
1291 (defcustom custom-buffer-indent 3
1292 "Number of spaces to indent nested groups."
1293 :type 'integer
1294 :group 'custom-buffer)
1296 (defun custom-get-fresh-buffer (name)
1297 "Get a fresh new buffer with name NAME.
1298 If the buffer already exist, clean it up to be like new.
1299 Beware: it's not quite like new. Good enough for custom, but maybe
1300 not for everybody."
1301 ;; To be more complete, we should also kill all permanent-local variables,
1302 ;; but it's not needed for custom.
1303 (let ((buf (get-buffer name)))
1304 (when (and buf (buffer-local-value 'buffer-file-name buf))
1305 ;; This will check if the file is not saved.
1306 (kill-buffer buf)
1307 (setq buf nil))
1308 (if (null buf)
1309 (get-buffer-create name)
1310 (with-current-buffer buf
1311 (kill-all-local-variables)
1312 (run-hooks 'kill-buffer-hook)
1313 ;; Delete overlays before erasing the buffer so the overlay hooks
1314 ;; don't get run spuriously when we erase the buffer.
1315 (let ((ols (overlay-lists)))
1316 (dolist (ol (nconc (car ols) (cdr ols)))
1317 (delete-overlay ol)))
1318 (erase-buffer)
1319 buf))))
1321 ;;;###autoload
1322 (defun custom-buffer-create (options &optional name description)
1323 "Create a buffer containing OPTIONS.
1324 Optional NAME is the name of the buffer.
1325 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1326 SYMBOL is a customization option, and WIDGET is a widget for editing
1327 that option."
1328 (pop-to-buffer (custom-get-fresh-buffer (or name "*Customization*")))
1329 (custom-buffer-create-internal options description))
1331 ;;;###autoload
1332 (defun custom-buffer-create-other-window (options &optional name description)
1333 "Create a buffer containing OPTIONS, and display it in another window.
1334 The result includes selecting that window.
1335 Optional NAME is the name of the buffer.
1336 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1337 SYMBOL is a customization option, and WIDGET is a widget for editing
1338 that option."
1339 (unless name (setq name "*Customization*"))
1340 (let ((pop-up-windows t)
1341 (same-window-buffer-names nil)
1342 (same-window-regexps nil))
1343 (pop-to-buffer (custom-get-fresh-buffer name))
1344 (custom-buffer-create-internal options description)))
1346 (defcustom custom-reset-button-menu nil
1347 "If non-nil, only show a single reset button in customize buffers.
1348 This button will have a menu with all three reset operations."
1349 :type 'boolean
1350 :group 'custom-buffer)
1352 (defcustom custom-buffer-verbose-help t
1353 "If non-nil, include explanatory text in the customization buffer."
1354 :type 'boolean
1355 :group 'custom-buffer)
1357 (defun Custom-buffer-done (&rest ignore)
1358 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1359 (interactive)
1360 (quit-window custom-buffer-done-kill))
1362 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1363 '(("unspecified" . unspecified))))
1364 "If non-nil, indicate active buttons in a `raised-button' style.
1365 Otherwise use brackets."
1366 :type 'boolean
1367 :version "21.1"
1368 :group 'custom-buffer)
1370 (defun custom-buffer-create-internal (options &optional description)
1371 (custom-mode)
1372 (if custom-buffer-verbose-help
1373 (progn
1374 (widget-insert "This is a customization buffer")
1375 (if description
1376 (widget-insert description))
1377 (widget-insert (format ".
1378 %s show active fields; type RET or click mouse-1
1379 on an active field to invoke its action. Editing an option value
1380 changes only the text in the buffer. Invoke the State button to set or
1381 save the option value. Saving an option normally edits your init file.
1382 Invoke "
1383 (if custom-raised-buttons
1384 "`Raised' buttons"
1385 "Square brackets")))
1386 (widget-create 'info-link
1387 :tag "Custom file"
1388 "(emacs)Saving Customizations")
1389 (widget-insert
1390 " for information on how to save in a different file.
1391 Invoke ")
1392 (widget-create 'info-link
1393 :tag "Help"
1394 :help-echo "Read the online help."
1395 "(emacs)Easy Customization")
1396 (widget-insert " for general information.\n\n")
1397 (widget-insert "Operate on everything in this buffer:\n "))
1398 (widget-insert " "))
1399 (widget-create 'push-button
1400 :tag "Set for Current Session"
1401 :help-echo "\
1402 Make your editing in this buffer take effect for this session."
1403 :action (lambda (widget &optional event)
1404 (Custom-set)))
1405 (widget-insert " ")
1406 (widget-create 'push-button
1407 :tag "Save for Future Sessions"
1408 :help-echo "\
1409 Make your editing in this buffer take effect for future Emacs sessions.
1410 This updates your Emacs initialization file or creates a new one."
1411 :action (lambda (widget &optional event)
1412 (Custom-save)))
1413 (if custom-reset-button-menu
1414 (progn
1415 (widget-insert " ")
1416 (widget-create 'push-button
1417 :tag "Reset"
1418 :help-echo "Show a menu with reset operations."
1419 :mouse-down-action (lambda (&rest junk) t)
1420 :action (lambda (widget &optional event)
1421 (custom-reset event))))
1422 (widget-insert "\n ")
1423 (widget-create 'push-button
1424 :tag "Reset"
1425 :help-echo "\
1426 Reset all edited text in this buffer to reflect current values."
1427 :action 'Custom-reset-current)
1428 (widget-insert " ")
1429 (widget-create 'push-button
1430 :tag "Reset to Saved"
1431 :help-echo "\
1432 Reset all values in this buffer to their saved settings."
1433 :action 'Custom-reset-saved)
1434 (widget-insert " ")
1435 (widget-create 'push-button
1436 :tag "Erase Customization"
1437 :help-echo "\
1438 Un-customize all values in this buffer. They get their standard settings."
1439 :action 'Custom-reset-standard))
1440 (if (not custom-buffer-verbose-help)
1441 (progn
1442 (widget-insert " ")
1443 (widget-create 'info-link
1444 :tag "Help"
1445 :help-echo "Read the online help."
1446 "(emacs)Easy Customization")))
1447 (widget-insert " ")
1448 (widget-create 'push-button
1449 :tag "Finish"
1450 :help-echo
1451 (lambda (&rest ignore)
1452 (if custom-buffer-done-kill
1453 "Kill this buffer"
1454 "Bury this buffer"))
1455 :action #'Custom-buffer-done)
1456 (widget-insert "\n\n")
1457 (message "Creating customization items...")
1458 (buffer-disable-undo)
1459 (setq custom-options
1460 (if (= (length options) 1)
1461 (mapcar (lambda (entry)
1462 (widget-create (nth 1 entry)
1463 :documentation-shown t
1464 :custom-state 'unknown
1465 :tag (custom-unlispify-tag-name
1466 (nth 0 entry))
1467 :value (nth 0 entry)))
1468 options)
1469 (let ((count 0)
1470 (length (length options)))
1471 (mapcar (lambda (entry)
1472 (prog2
1473 (message "Creating customization items ...%2d%%"
1474 (/ (* 100.0 count) length))
1475 (widget-create (nth 1 entry)
1476 :tag (custom-unlispify-tag-name
1477 (nth 0 entry))
1478 :value (nth 0 entry))
1479 (setq count (1+ count))
1480 (unless (eq (preceding-char) ?\n)
1481 (widget-insert "\n"))
1482 (widget-insert "\n")))
1483 options))))
1484 (unless (eq (preceding-char) ?\n)
1485 (widget-insert "\n"))
1486 (message "Creating customization items ...done")
1487 (message "Resetting customization items...")
1488 (unless (eq custom-buffer-style 'tree)
1489 (mapc 'custom-magic-reset custom-options))
1490 (message "Resetting customization items...done")
1491 (message "Creating customization setup...")
1492 (widget-setup)
1493 (buffer-enable-undo)
1494 (goto-char (point-min))
1495 (message "Creating customization setup...done"))
1497 ;;; The Tree Browser.
1499 ;;;###autoload
1500 (defun customize-browse (&optional group)
1501 "Create a tree browser for the customize hierarchy."
1502 (interactive)
1503 (unless group
1504 (setq group 'emacs))
1505 (let ((name "*Customize Browser*"))
1506 (pop-to-buffer (custom-get-fresh-buffer name)))
1507 (custom-mode)
1508 (widget-insert "\
1509 Square brackets show active fields; type RET or click mouse-1
1510 on an active field to invoke its action.
1511 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1512 (if custom-browse-only-groups
1513 (widget-insert "\
1514 Invoke the [Group] button below to edit that item in another window.\n\n")
1515 (widget-insert "Invoke the ")
1516 (widget-create 'item
1517 :format "%t"
1518 :tag "[Group]"
1519 :tag-glyph "folder")
1520 (widget-insert ", ")
1521 (widget-create 'item
1522 :format "%t"
1523 :tag "[Face]"
1524 :tag-glyph "face")
1525 (widget-insert ", and ")
1526 (widget-create 'item
1527 :format "%t"
1528 :tag "[Option]"
1529 :tag-glyph "option")
1530 (widget-insert " buttons below to edit that
1531 item in another window.\n\n"))
1532 (let ((custom-buffer-style 'tree))
1533 (widget-create 'custom-group
1534 :custom-last t
1535 :custom-state 'unknown
1536 :tag (custom-unlispify-tag-name group)
1537 :value group))
1538 (widget-setup)
1539 (goto-char (point-min)))
1541 (define-widget 'custom-browse-visibility 'item
1542 "Control visibility of items in the customize tree browser."
1543 :format "%[[%t]%]"
1544 :action 'custom-browse-visibility-action)
1546 (defun custom-browse-visibility-action (widget &rest ignore)
1547 (let ((custom-buffer-style 'tree))
1548 (custom-toggle-parent widget)))
1550 (define-widget 'custom-browse-group-tag 'push-button
1551 "Show parent in other window when activated."
1552 :tag "Group"
1553 :tag-glyph "folder"
1554 :action 'custom-browse-group-tag-action)
1556 (defun custom-browse-group-tag-action (widget &rest ignore)
1557 (let ((parent (widget-get widget :parent)))
1558 (customize-group-other-window (widget-value parent))))
1560 (define-widget 'custom-browse-variable-tag 'push-button
1561 "Show parent in other window when activated."
1562 :tag "Option"
1563 :tag-glyph "option"
1564 :action 'custom-browse-variable-tag-action)
1566 (defun custom-browse-variable-tag-action (widget &rest ignore)
1567 (let ((parent (widget-get widget :parent)))
1568 (customize-variable-other-window (widget-value parent))))
1570 (define-widget 'custom-browse-face-tag 'push-button
1571 "Show parent in other window when activated."
1572 :tag "Face"
1573 :tag-glyph "face"
1574 :action 'custom-browse-face-tag-action)
1576 (defun custom-browse-face-tag-action (widget &rest ignore)
1577 (let ((parent (widget-get widget :parent)))
1578 (customize-face-other-window (widget-value parent))))
1580 (defconst custom-browse-alist '((" " "space")
1581 (" | " "vertical")
1582 ("-\\ " "top")
1583 (" |-" "middle")
1584 (" `-" "bottom")))
1586 (defun custom-browse-insert-prefix (prefix)
1587 "Insert PREFIX. On XEmacs convert it to line graphics."
1588 ;; Fixme: do graphics.
1589 (if nil ; (string-match "XEmacs" emacs-version)
1590 (progn
1591 (insert "*")
1592 (while (not (string-equal prefix ""))
1593 (let ((entry (substring prefix 0 3)))
1594 (setq prefix (substring prefix 3))
1595 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1596 (name (nth 1 (assoc entry custom-browse-alist))))
1597 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1598 (overlay-put overlay 'start-open t)
1599 (overlay-put overlay 'end-open t)))))
1600 (insert prefix)))
1602 ;;; Modification of Basic Widgets.
1604 ;; We add extra properties to the basic widgets needed here. This is
1605 ;; fine, as long as we are careful to stay within out own namespace.
1607 ;; We want simple widgets to be displayed by default, but complex
1608 ;; widgets to be hidden.
1610 (widget-put (get 'item 'widget-type) :custom-show t)
1611 (widget-put (get 'editable-field 'widget-type)
1612 :custom-show (lambda (widget value)
1613 (let ((pp (pp-to-string value)))
1614 (cond ((string-match "\n" pp)
1615 nil)
1616 ((> (length pp) 40)
1617 nil)
1618 (t t)))))
1619 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1621 ;;; The `custom-manual' Widget.
1623 (define-widget 'custom-manual 'info-link
1624 "Link to the manual entry for this customization option."
1625 :help-echo "Read the manual entry for this option."
1626 :tag "Manual")
1628 ;;; The `custom-magic' Widget.
1630 (defgroup custom-magic-faces nil
1631 "Faces used by the magic button."
1632 :group 'custom-faces
1633 :group 'custom-buffer)
1635 (defface custom-invalid-face '((((class color))
1636 (:foreground "yellow" :background "red"))
1638 (:weight bold :slant italic :underline t)))
1639 "Face used when the customize item is invalid."
1640 :group 'custom-magic-faces)
1642 (defface custom-rogue-face '((((class color))
1643 (:foreground "pink" :background "black"))
1645 (:underline t)))
1646 "Face used when the customize item is not defined for customization."
1647 :group 'custom-magic-faces)
1649 (defface custom-modified-face '((((class color))
1650 (:foreground "white" :background "blue"))
1652 (:slant italic :bold)))
1653 "Face used when the customize item has been modified."
1654 :group 'custom-magic-faces)
1656 (defface custom-set-face '((((class color))
1657 (:foreground "blue" :background "white"))
1659 (:slant italic)))
1660 "Face used when the customize item has been set."
1661 :group 'custom-magic-faces)
1663 (defface custom-changed-face '((((class color))
1664 (:foreground "white" :background "blue"))
1666 (:slant italic)))
1667 "Face used when the customize item has been changed."
1668 :group 'custom-magic-faces)
1670 (defface custom-saved-face '((t (:underline t)))
1671 "Face used when the customize item has been saved."
1672 :group 'custom-magic-faces)
1674 (defconst custom-magic-alist
1675 '((nil "#" underline "\
1676 UNINITIALIZED, you should not see this.")
1677 (unknown "?" italic "\
1678 UNKNOWN, you should not see this.")
1679 (hidden "-" default "\
1680 HIDDEN, invoke \"Show\" in the previous line to show." "\
1681 group now hidden, invoke \"Show\", above, to show contents.")
1682 (invalid "x" custom-invalid-face "\
1683 INVALID, the displayed value cannot be set.")
1684 (modified "*" custom-modified-face "\
1685 EDITED, shown value does not take effect until you set or save it." "\
1686 something in this group has been edited but not set.")
1687 (set "+" custom-set-face "\
1688 SET for current session only." "\
1689 something in this group has been set but not saved.")
1690 (changed ":" custom-changed-face "\
1691 CHANGED outside Customize; operating on it here may be unreliable." "\
1692 something in this group has been changed outside customize.")
1693 (saved "!" custom-saved-face "\
1694 SAVED and set." "\
1695 something in this group has been set and saved.")
1696 (rogue "@" custom-rogue-face "\
1697 NO CUSTOMIZATION DATA; you should not see this." "\
1698 something in this group is not prepared for customization.")
1699 (standard " " nil "\
1700 STANDARD." "\
1701 visible group members are all at standard settings."))
1702 "Alist of customize option states.
1703 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1705 STATE is one of the following symbols:
1707 `nil'
1708 For internal use, should never occur.
1709 `unknown'
1710 For internal use, should never occur.
1711 `hidden'
1712 This item is not being displayed.
1713 `invalid'
1714 This item is modified, but has an invalid form.
1715 `modified'
1716 This item is modified, and has a valid form.
1717 `set'
1718 This item has been set but not saved.
1719 `changed'
1720 The current value of this item has been changed outside Customize.
1721 `saved'
1722 This item is marked for saving.
1723 `rogue'
1724 This item has no customization information.
1725 `standard'
1726 This item is unchanged from the standard setting.
1728 MAGIC is a string used to present that state.
1730 FACE is a face used to present the state.
1732 ITEM-DESC is a string describing the state for options.
1734 GROUP-DESC is a string describing the state for groups. If this is
1735 left out, ITEM-DESC will be used.
1737 The string %c in either description will be replaced with the
1738 category of the item. These are `group'. `option', and `face'.
1740 The list should be sorted most significant first.")
1742 (defcustom custom-magic-show 'long
1743 "If non-nil, show textual description of the state.
1744 If `long', show a full-line description, not just one word."
1745 :type '(choice (const :tag "no" nil)
1746 (const long)
1747 (other :tag "short" short))
1748 :group 'custom-buffer)
1750 (defcustom custom-magic-show-hidden '(option face)
1751 "Control whether the State button is shown for hidden items.
1752 The value should be a list with the custom categories where the State
1753 button should be visible. Possible categories are `group', `option',
1754 and `face'."
1755 :type '(set (const group) (const option) (const face))
1756 :group 'custom-buffer)
1758 (defcustom custom-magic-show-button nil
1759 "Show a \"magic\" button indicating the state of each customization option."
1760 :type 'boolean
1761 :group 'custom-buffer)
1763 (define-widget 'custom-magic 'default
1764 "Show and manipulate state for a customization option."
1765 :format "%v"
1766 :action 'widget-parent-action
1767 :notify 'ignore
1768 :value-get 'ignore
1769 :value-create 'custom-magic-value-create
1770 :value-delete 'widget-children-value-delete)
1772 (defun widget-magic-mouse-down-action (widget &optional event)
1773 ;; Non-nil unless hidden.
1774 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1775 :custom-state)
1776 'hidden)))
1778 (defun custom-magic-value-create (widget)
1779 "Create compact status report for WIDGET."
1780 (let* ((parent (widget-get widget :parent))
1781 (state (widget-get parent :custom-state))
1782 (hidden (eq state 'hidden))
1783 (entry (assq state custom-magic-alist))
1784 (magic (nth 1 entry))
1785 (face (nth 2 entry))
1786 (category (widget-get parent :custom-category))
1787 (text (or (and (eq category 'group)
1788 (nth 4 entry))
1789 (nth 3 entry)))
1790 (form (widget-get parent :custom-form))
1791 children)
1792 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1793 (setq text (concat (match-string 1 text)
1794 (symbol-name category)
1795 (match-string 2 text))))
1796 (when (and custom-magic-show
1797 (or (not hidden)
1798 (memq category custom-magic-show-hidden)))
1799 (insert " ")
1800 (when (and (eq category 'group)
1801 (not (and (eq custom-buffer-style 'links)
1802 (> (widget-get parent :custom-level) 1))))
1803 (insert-char ?\ (* custom-buffer-indent
1804 (widget-get parent :custom-level))))
1805 (push (widget-create-child-and-convert
1806 widget 'choice-item
1807 :help-echo "Change the state of this item."
1808 :format (if hidden "%t" "%[%t%]")
1809 :button-prefix 'widget-push-button-prefix
1810 :button-suffix 'widget-push-button-suffix
1811 :mouse-down-action 'widget-magic-mouse-down-action
1812 :tag "State")
1813 children)
1814 (insert ": ")
1815 (let ((start (point)))
1816 (if (eq custom-magic-show 'long)
1817 (insert text)
1818 (insert (symbol-name state)))
1819 (cond ((eq form 'lisp)
1820 (insert " (lisp)"))
1821 ((eq form 'mismatch)
1822 (insert " (mismatch)")))
1823 (put-text-property start (point) 'face 'custom-state-face))
1824 (insert "\n"))
1825 (when (and (eq category 'group)
1826 (not (and (eq custom-buffer-style 'links)
1827 (> (widget-get parent :custom-level) 1))))
1828 (insert-char ?\ (* custom-buffer-indent
1829 (widget-get parent :custom-level))))
1830 (when custom-magic-show-button
1831 (when custom-magic-show
1832 (let ((indent (widget-get parent :indent)))
1833 (when indent
1834 (insert-char ? indent))))
1835 (push (widget-create-child-and-convert
1836 widget 'choice-item
1837 :mouse-down-action 'widget-magic-mouse-down-action
1838 :button-face face
1839 :button-prefix ""
1840 :button-suffix ""
1841 :help-echo "Change the state."
1842 :format (if hidden "%t" "%[%t%]")
1843 :tag (if (memq form '(lisp mismatch))
1844 (concat "(" magic ")")
1845 (concat "[" magic "]")))
1846 children)
1847 (insert " "))
1848 (widget-put widget :children children)))
1850 (defun custom-magic-reset (widget)
1851 "Redraw the :custom-magic property of WIDGET."
1852 (let ((magic (widget-get widget :custom-magic)))
1853 (widget-value-set magic (widget-value magic))))
1855 ;;; The `custom' Widget.
1857 (defface custom-button-face
1858 '((((type x w32 mac) (class color)) ; Like default modeline
1859 (:box (:line-width 2 :style released-button)
1860 :background "lightgrey" :foreground "black"))
1862 nil))
1863 "Face used for buttons in customization buffers."
1864 :version "21.1"
1865 :group 'custom-faces)
1867 (defface custom-button-pressed-face
1868 '((((type x w32 mac) (class color))
1869 (:box (:line-width 2 :style pressed-button)
1870 :background "lightgrey" :foreground "black"))
1872 (:inverse-video t)))
1873 "Face used for buttons in customization buffers."
1874 :version "21.1"
1875 :group 'custom-faces)
1877 (defface custom-documentation-face nil
1878 "Face used for documentation strings in customization buffers."
1879 :group 'custom-faces)
1881 (defface custom-state-face '((((class color)
1882 (background dark))
1883 (:foreground "lime green"))
1884 (((class color)
1885 (background light))
1886 (:foreground "dark green"))
1887 (t nil))
1888 "Face used for State descriptions in the customize buffer."
1889 :group 'custom-faces)
1891 (define-widget 'custom 'default
1892 "Customize a user option."
1893 :format "%v"
1894 :convert-widget 'custom-convert-widget
1895 :notify 'custom-notify
1896 :custom-prefix ""
1897 :custom-level 1
1898 :custom-state 'hidden
1899 :documentation-property 'widget-subclass-responsibility
1900 :value-create 'widget-subclass-responsibility
1901 :value-delete 'widget-children-value-delete
1902 :value-get 'widget-value-value-get
1903 :validate 'widget-children-validate
1904 :match (lambda (widget value) (symbolp value)))
1906 (defun custom-convert-widget (widget)
1907 "Initialize :value and :tag from :args in WIDGET."
1908 (let ((args (widget-get widget :args)))
1909 (when args
1910 (widget-put widget :value (widget-apply widget
1911 :value-to-internal (car args)))
1912 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1913 (widget-put widget :args nil)))
1914 widget)
1916 (defun custom-notify (widget &rest args)
1917 "Keep track of changes."
1918 (let ((state (widget-get widget :custom-state)))
1919 (unless (eq state 'modified)
1920 (unless (memq state '(nil unknown hidden))
1921 (widget-put widget :custom-state 'modified))
1922 (custom-magic-reset widget)
1923 (apply 'widget-default-notify widget args))))
1925 (defun custom-redraw (widget)
1926 "Redraw WIDGET with current settings."
1927 (let ((line (count-lines (point-min) (point)))
1928 (column (current-column))
1929 (pos (point))
1930 (from (marker-position (widget-get widget :from)))
1931 (to (marker-position (widget-get widget :to))))
1932 (save-excursion
1933 (widget-value-set widget (widget-value widget))
1934 (custom-redraw-magic widget))
1935 (when (and (>= pos from) (<= pos to))
1936 (condition-case nil
1937 (progn
1938 (if (> column 0)
1939 (goto-line line)
1940 (goto-line (1+ line)))
1941 (move-to-column column))
1942 (error nil)))))
1944 (defun custom-redraw-magic (widget)
1945 "Redraw WIDGET state with current settings."
1946 (while widget
1947 (let ((magic (widget-get widget :custom-magic)))
1948 (cond (magic
1949 (widget-value-set magic (widget-value magic))
1950 (when (setq widget (widget-get widget :group))
1951 (custom-group-state-update widget)))
1953 (setq widget nil)))))
1954 (widget-setup))
1956 (defun custom-show (widget value)
1957 "Non-nil if WIDGET should be shown with VALUE by default."
1958 (let ((show (widget-get widget :custom-show)))
1959 (cond ((null show)
1960 nil)
1961 ((eq t show)
1964 (funcall show widget value)))))
1966 (defun custom-load-widget (widget)
1967 "Load all dependencies for WIDGET."
1968 (custom-load-symbol (widget-value widget)))
1970 (defun custom-unloaded-symbol-p (symbol)
1971 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
1972 (let ((found nil)
1973 (loads (get symbol 'custom-loads))
1974 load)
1975 (while loads
1976 (setq load (car loads)
1977 loads (cdr loads))
1978 (cond ((symbolp load)
1979 (unless (featurep load)
1980 (setq found t)))
1981 ((assoc load load-history))
1982 ((assoc (locate-library load) load-history)
1983 (message nil))
1985 (setq found t))))
1986 found))
1988 (defun custom-unloaded-widget-p (widget)
1989 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
1990 (custom-unloaded-symbol-p (widget-value widget)))
1992 (defun custom-toggle-hide (widget)
1993 "Toggle visibility of WIDGET."
1994 (custom-load-widget widget)
1995 (let ((state (widget-get widget :custom-state)))
1996 (cond ((memq state '(invalid modified))
1997 (error "There are unset changes"))
1998 ((eq state 'hidden)
1999 (widget-put widget :custom-state 'unknown))
2001 (widget-put widget :documentation-shown nil)
2002 (widget-put widget :custom-state 'hidden)))
2003 (custom-redraw widget)
2004 (widget-setup)))
2006 (defun custom-toggle-parent (widget &rest ignore)
2007 "Toggle visibility of parent of WIDGET."
2008 (custom-toggle-hide (widget-get widget :parent)))
2010 (defun custom-add-see-also (widget &optional prefix)
2011 "Add `See also ...' to WIDGET if there are any links.
2012 Insert PREFIX first if non-nil."
2013 (let* ((symbol (widget-get widget :value))
2014 (links (get symbol 'custom-links))
2015 (many (> (length links) 2))
2016 (buttons (widget-get widget :buttons))
2017 (indent (widget-get widget :indent)))
2018 (when links
2019 (when indent
2020 (insert-char ?\ indent))
2021 (when prefix
2022 (insert prefix))
2023 (insert "See also ")
2024 (while links
2025 (push (widget-create-child-and-convert widget (car links))
2026 buttons)
2027 (setq links (cdr links))
2028 (cond ((null links)
2029 (insert ".\n"))
2030 ((null (cdr links))
2031 (if many
2032 (insert ", and ")
2033 (insert " and ")))
2035 (insert ", "))))
2036 (widget-put widget :buttons buttons))))
2038 (defun custom-add-parent-links (widget &optional initial-string)
2039 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2040 The value if non-nil if any parents were found.
2041 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2042 (let ((name (widget-value widget))
2043 (type (widget-type widget))
2044 (buttons (widget-get widget :buttons))
2045 (start (point))
2046 (parents nil))
2047 (insert (or initial-string "Parent groups:"))
2048 (mapatoms (lambda (symbol)
2049 (let ((entry (assq name (get symbol 'custom-group))))
2050 (when (eq (nth 1 entry) type)
2051 (insert " ")
2052 (push (widget-create-child-and-convert
2053 widget 'custom-group-link
2054 :tag (custom-unlispify-tag-name symbol)
2055 symbol)
2056 buttons)
2057 (setq parents (cons symbol parents))))))
2058 (and (null (get name 'custom-links)) ;No links of its own.
2059 (= (length parents) 1) ;A single parent.
2060 (let* ((links (get (car parents) 'custom-links))
2061 (many (> (length links) 2)))
2062 (when links
2063 (insert "\nParent documentation: ")
2064 (while links
2065 (push (widget-create-child-and-convert widget (car links))
2066 buttons)
2067 (setq links (cdr links))
2068 (cond ((null links)
2069 (insert ".\n"))
2070 ((null (cdr links))
2071 (if many
2072 (insert ", and ")
2073 (insert " and ")))
2075 (insert ", ")))))))
2076 (if parents
2077 (insert "\n")
2078 (delete-region start (point)))
2079 (widget-put widget :buttons buttons)
2080 parents))
2082 ;;; The `custom-comment' Widget.
2084 ;; like the editable field
2085 (defface custom-comment-face '((((class grayscale color)
2086 (background light))
2087 (:background "gray85"))
2088 (((class grayscale color)
2089 (background dark))
2090 (:background "dim gray"))
2092 (:slant italic)))
2093 "Face used for comments on variables or faces"
2094 :version "21.1"
2095 :group 'custom-faces)
2097 ;; like font-lock-comment-face
2098 (defface custom-comment-tag-face
2099 '((((class color) (background dark)) (:foreground "gray80"))
2100 (((class color) (background light)) (:foreground "blue4"))
2101 (((class grayscale) (background light))
2102 (:foreground "DimGray" :weight bold :slant italic))
2103 (((class grayscale) (background dark))
2104 (:foreground "LightGray" :weight bold :slant italic))
2105 (t (:weight bold)))
2106 "Face used for variables or faces comment tags"
2107 :group 'custom-faces)
2109 (define-widget 'custom-comment 'string
2110 "User comment."
2111 :tag "Comment"
2112 :help-echo "Edit a comment here."
2113 :sample-face 'custom-comment-tag-face
2114 :value-face 'custom-comment-face
2115 :shown nil
2116 :create 'custom-comment-create)
2118 (defun custom-comment-create (widget)
2119 (let* ((null-comment (equal "" (widget-value widget))))
2120 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2121 (not null-comment))
2122 (widget-default-create widget)
2123 ;; `widget-default-delete' expects markers in these slots --
2124 ;; maybe it shouldn't.
2125 (widget-put widget :from (point-marker))
2126 (widget-put widget :to (point-marker)))))
2128 (defun custom-comment-hide (widget)
2129 (widget-put (widget-get widget :parent) :comment-shown nil))
2131 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2132 ;; the global custom one
2133 (defun custom-comment-show (widget)
2134 (widget-put widget :comment-shown t)
2135 (custom-redraw widget)
2136 (widget-setup))
2138 (defun custom-comment-invisible-p (widget)
2139 (let ((val (widget-value (widget-get widget :comment-widget))))
2140 (and (equal "" val)
2141 (not (widget-get widget :comment-shown)))))
2143 ;;; The `custom-variable' Widget.
2145 ;; When this was underlined blue, users confused it with a
2146 ;; Mosaic-style hyperlink...
2147 (defface custom-variable-tag-face
2148 `((((class color)
2149 (background dark))
2150 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
2151 (((class color)
2152 (background light))
2153 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
2154 (t (:weight bold)))
2155 "Face used for unpushable variable tags."
2156 :group 'custom-faces)
2158 (defface custom-variable-button-face '((t (:underline t :weight bold)))
2159 "Face used for pushable variable tags."
2160 :group 'custom-faces)
2162 (defcustom custom-variable-default-form 'edit
2163 "Default form of displaying variable values."
2164 :type '(choice (const edit)
2165 (const lisp))
2166 :group 'custom-buffer
2167 :version "20.3")
2169 (defun custom-variable-documentation (variable)
2170 "Return documentation of VARIABLE for use in Custom buffer.
2171 Normally just return the docstring. But if VARIABLE automatically
2172 becomes buffer local when set, append a message to that effect."
2173 (if (and (local-variable-if-set-p variable)
2174 (or (not (local-variable-p variable))
2175 (with-temp-buffer
2176 (local-variable-if-set-p variable))))
2177 (concat (documentation-property variable 'variable-documentation)
2179 This variable automatically becomes buffer-local when set outside Custom.
2180 However, setting it through Custom sets the default value.")
2181 (documentation-property variable 'variable-documentation)))
2183 (define-widget 'custom-variable 'custom
2184 "Customize variable."
2185 :format "%v"
2186 :help-echo "Set or reset this variable."
2187 :documentation-property #'custom-variable-documentation
2188 :custom-category 'option
2189 :custom-state nil
2190 :custom-menu 'custom-variable-menu-create
2191 :custom-form nil ; defaults to value of `custom-variable-default-form'
2192 :value-create 'custom-variable-value-create
2193 :action 'custom-variable-action
2194 :custom-set 'custom-variable-set
2195 :custom-save 'custom-variable-save
2196 :custom-reset-current 'custom-redraw
2197 :custom-reset-saved 'custom-variable-reset-saved
2198 :custom-reset-standard 'custom-variable-reset-standard
2199 :custom-standard-value 'custom-variable-standard-value)
2201 (defun custom-variable-type (symbol)
2202 "Return a widget suitable for editing the value of SYMBOL.
2203 If SYMBOL has a `custom-type' property, use that.
2204 Otherwise, look up symbol in `custom-guess-type-alist'."
2205 (let* ((type (or (get symbol 'custom-type)
2206 (and (not (get symbol 'standard-value))
2207 (custom-guess-type symbol))
2208 'sexp))
2209 (options (get symbol 'custom-options))
2210 (tmp (if (listp type)
2211 (copy-sequence type)
2212 (list type))))
2213 (when options
2214 (widget-put tmp :options options))
2215 tmp))
2217 (defun custom-variable-value-create (widget)
2218 "Here is where you edit the variable's value."
2219 (custom-load-widget widget)
2220 (unless (widget-get widget :custom-form)
2221 (widget-put widget :custom-form custom-variable-default-form))
2222 (let* ((buttons (widget-get widget :buttons))
2223 (children (widget-get widget :children))
2224 (form (widget-get widget :custom-form))
2225 (state (widget-get widget :custom-state))
2226 (symbol (widget-get widget :value))
2227 (tag (widget-get widget :tag))
2228 (type (custom-variable-type symbol))
2229 (conv (widget-convert type))
2230 (get (or (get symbol 'custom-get) 'default-value))
2231 (prefix (widget-get widget :custom-prefix))
2232 (last (widget-get widget :custom-last))
2233 (value (if (default-boundp symbol)
2234 (funcall get symbol)
2235 (widget-get conv :value))))
2236 ;; If the widget is new, the child determines whether it is hidden.
2237 (cond (state)
2238 ((custom-show type value)
2239 (setq state 'unknown))
2241 (setq state 'hidden)))
2242 ;; If we don't know the state, see if we need to edit it in lisp form.
2243 (when (eq state 'unknown)
2244 (unless (widget-apply conv :match value)
2245 ;; (widget-apply (widget-convert type) :match value)
2246 (setq form 'mismatch)))
2247 ;; Now we can create the child widget.
2248 (cond ((eq custom-buffer-style 'tree)
2249 (insert prefix (if last " `--- " " |--- "))
2250 (push (widget-create-child-and-convert
2251 widget 'custom-browse-variable-tag)
2252 buttons)
2253 (insert " " tag "\n")
2254 (widget-put widget :buttons buttons))
2255 ((eq state 'hidden)
2256 ;; Indicate hidden value.
2257 (push (widget-create-child-and-convert
2258 widget 'item
2259 :format "%{%t%}: "
2260 :sample-face 'custom-variable-tag-face
2261 :tag tag
2262 :parent widget)
2263 buttons)
2264 (push (widget-create-child-and-convert
2265 widget 'visibility
2266 :help-echo "Show the value of this option."
2267 :off "Show Value"
2268 :action 'custom-toggle-parent
2269 nil)
2270 buttons))
2271 ((memq form '(lisp mismatch))
2272 ;; In lisp mode edit the saved value when possible.
2273 (let* ((value (cond ((get symbol 'saved-value)
2274 (car (get symbol 'saved-value)))
2275 ((get symbol 'standard-value)
2276 (car (get symbol 'standard-value)))
2277 ((default-boundp symbol)
2278 (custom-quote (funcall get symbol)))
2280 (custom-quote (widget-get conv :value))))))
2281 (insert (symbol-name symbol) ": ")
2282 (push (widget-create-child-and-convert
2283 widget 'visibility
2284 :help-echo "Hide the value of this option."
2285 :on "Hide Value"
2286 :off "Show Value"
2287 :action 'custom-toggle-parent
2289 buttons)
2290 (insert " ")
2291 (push (widget-create-child-and-convert
2292 widget 'sexp
2293 :button-face 'custom-variable-button-face
2294 :format "%v"
2295 :tag (symbol-name symbol)
2296 :parent widget
2297 :value value)
2298 children)))
2300 ;; Edit mode.
2301 (let* ((format (widget-get type :format))
2302 tag-format value-format)
2303 (unless (string-match ":" format)
2304 (error "Bad format"))
2305 (setq tag-format (substring format 0 (match-end 0)))
2306 (setq value-format (substring format (match-end 0)))
2307 (push (widget-create-child-and-convert
2308 widget 'item
2309 :format tag-format
2310 :action 'custom-tag-action
2311 :help-echo "Change value of this option."
2312 :mouse-down-action 'custom-tag-mouse-down-action
2313 :button-face 'custom-variable-button-face
2314 :sample-face 'custom-variable-tag-face
2315 tag)
2316 buttons)
2317 (insert " ")
2318 (push (widget-create-child-and-convert
2319 widget 'visibility
2320 :help-echo "Hide the value of this option."
2321 :on "Hide Value"
2322 :off "Show Value"
2323 :action 'custom-toggle-parent
2325 buttons)
2326 (push (widget-create-child-and-convert
2327 widget type
2328 :format value-format
2329 :value value)
2330 children))))
2331 (unless (eq custom-buffer-style 'tree)
2332 (unless (eq (preceding-char) ?\n)
2333 (widget-insert "\n"))
2334 ;; Create the magic button.
2335 (let ((magic (widget-create-child-and-convert
2336 widget 'custom-magic nil)))
2337 (widget-put widget :custom-magic magic)
2338 (push magic buttons))
2339 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2340 ;; before the call to `widget-default-format-handler'. Otherwise, I
2341 ;; loose my current `buttons'. This function shouldn't be called like
2342 ;; this anyway. The doc string widget should be added like the others.
2343 ;; --dv
2344 (widget-put widget :buttons buttons)
2345 (insert "\n")
2346 ;; Insert documentation.
2347 (widget-default-format-handler widget ?h)
2349 ;; The comment field
2350 (unless (eq state 'hidden)
2351 (let* ((comment (get symbol 'variable-comment))
2352 (comment-widget
2353 (widget-create-child-and-convert
2354 widget 'custom-comment
2355 :parent widget
2356 :value (or comment ""))))
2357 (widget-put widget :comment-widget comment-widget)
2358 ;; Don't push it !!! Custom assumes that the first child is the
2359 ;; value one.
2360 (setq children (append children (list comment-widget)))))
2361 ;; Update the rest of the properties properties.
2362 (widget-put widget :custom-form form)
2363 (widget-put widget :children children)
2364 ;; Now update the state.
2365 (if (eq state 'hidden)
2366 (widget-put widget :custom-state state)
2367 (custom-variable-state-set widget))
2368 ;; See also.
2369 (unless (eq state 'hidden)
2370 (when (eq (widget-get widget :custom-level) 1)
2371 (custom-add-parent-links widget))
2372 (custom-add-see-also widget)))))
2374 (defun custom-tag-action (widget &rest args)
2375 "Pass :action to first child of WIDGET's parent."
2376 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2377 :action args))
2379 (defun custom-tag-mouse-down-action (widget &rest args)
2380 "Pass :mouse-down-action to first child of WIDGET's parent."
2381 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2382 :mouse-down-action args))
2384 (defun custom-variable-state-set (widget)
2385 "Set the state of WIDGET."
2386 (let* ((symbol (widget-value widget))
2387 (get (or (get symbol 'custom-get) 'default-value))
2388 (value (if (default-boundp symbol)
2389 (funcall get symbol)
2390 (widget-get widget :value)))
2391 (comment (get symbol 'variable-comment))
2393 temp
2394 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2395 (setq temp
2396 (get symbol 'customized-variable-comment))
2397 (or tmp temp))
2398 (if (condition-case nil
2399 (and (equal value (eval (car tmp)))
2400 (equal comment temp))
2401 (error nil))
2402 'set
2403 'changed))
2404 ((progn (setq tmp (get symbol 'saved-value))
2405 (setq temp (get symbol 'saved-variable-comment))
2406 (or tmp temp))
2407 (if (condition-case nil
2408 (and (equal value (eval (car tmp)))
2409 (equal comment temp))
2410 (error nil))
2411 'saved
2412 'changed))
2413 ((setq tmp (get symbol 'standard-value))
2414 (if (condition-case nil
2415 (and (equal value (eval (car tmp)))
2416 (equal comment nil))
2417 (error nil))
2418 'standard
2419 'changed))
2420 (t 'rogue))))
2421 (widget-put widget :custom-state state)))
2423 (defun custom-variable-standard-value (widget)
2424 (get (widget-value widget) 'standard-value))
2426 (defvar custom-variable-menu
2427 '(("Set for Current Session" custom-variable-set
2428 (lambda (widget)
2429 (eq (widget-get widget :custom-state) 'modified)))
2430 ("Save for Future Sessions" custom-variable-save
2431 (lambda (widget)
2432 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2433 ("Reset to Current" custom-redraw
2434 (lambda (widget)
2435 (and (default-boundp (widget-value widget))
2436 (memq (widget-get widget :custom-state) '(modified changed)))))
2437 ("Reset to Saved" custom-variable-reset-saved
2438 (lambda (widget)
2439 (and (or (get (widget-value widget) 'saved-value)
2440 (get (widget-value widget) 'saved-variable-comment))
2441 (memq (widget-get widget :custom-state)
2442 '(modified set changed rogue)))))
2443 ("Erase Customization" custom-variable-reset-standard
2444 (lambda (widget)
2445 (and (get (widget-value widget) 'standard-value)
2446 (memq (widget-get widget :custom-state)
2447 '(modified set changed saved rogue)))))
2448 ("Use Backup Value" custom-variable-reset-backup
2449 (lambda (widget)
2450 (get (widget-value widget) 'backup-value)))
2451 ("---" ignore ignore)
2452 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2453 ("---" ignore ignore)
2454 ("Don't show as Lisp expression" custom-variable-edit
2455 (lambda (widget)
2456 (eq (widget-get widget :custom-form) 'lisp)))
2457 ("Show initial Lisp expression" custom-variable-edit-lisp
2458 (lambda (widget)
2459 (eq (widget-get widget :custom-form) 'edit))))
2460 "Alist of actions for the `custom-variable' widget.
2461 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2462 the menu entry, ACTION is the function to call on the widget when the
2463 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2464 widget as an argument, and returns non-nil if ACTION is valid on that
2465 widget. If FILTER is nil, ACTION is always valid.")
2467 (defun custom-variable-action (widget &optional event)
2468 "Show the menu for `custom-variable' WIDGET.
2469 Optional EVENT is the location for the menu."
2470 (if (eq (widget-get widget :custom-state) 'hidden)
2471 (custom-toggle-hide widget)
2472 (unless (eq (widget-get widget :custom-state) 'modified)
2473 (custom-variable-state-set widget))
2474 (custom-redraw-magic widget)
2475 (let* ((completion-ignore-case t)
2476 (answer (widget-choose (concat "Operation on "
2477 (custom-unlispify-tag-name
2478 (widget-get widget :value)))
2479 (custom-menu-filter custom-variable-menu
2480 widget)
2481 event)))
2482 (if answer
2483 (funcall answer widget)))))
2485 (defun custom-variable-edit (widget)
2486 "Edit value of WIDGET."
2487 (widget-put widget :custom-state 'unknown)
2488 (widget-put widget :custom-form 'edit)
2489 (custom-redraw widget))
2491 (defun custom-variable-edit-lisp (widget)
2492 "Edit the Lisp representation of the value of WIDGET."
2493 (widget-put widget :custom-state 'unknown)
2494 (widget-put widget :custom-form 'lisp)
2495 (custom-redraw widget))
2497 (defun custom-variable-set (widget)
2498 "Set the current value for the variable being edited by WIDGET."
2499 (let* ((form (widget-get widget :custom-form))
2500 (state (widget-get widget :custom-state))
2501 (child (car (widget-get widget :children)))
2502 (symbol (widget-value widget))
2503 (set (or (get symbol 'custom-set) 'set-default))
2504 (comment-widget (widget-get widget :comment-widget))
2505 (comment (widget-value comment-widget))
2506 val)
2507 (cond ((eq state 'hidden)
2508 (error "Cannot set hidden variable"))
2509 ((setq val (widget-apply child :validate))
2510 (goto-char (widget-get val :from))
2511 (error "%s" (widget-get val :error)))
2512 ((memq form '(lisp mismatch))
2513 (when (equal comment "")
2514 (setq comment nil)
2515 ;; Make the comment invisible by hand if it's empty
2516 (custom-comment-hide comment-widget))
2517 (custom-variable-backup-value widget)
2518 (funcall set symbol (eval (setq val (widget-value child))))
2519 (put symbol 'customized-value (list val))
2520 (put symbol 'variable-comment comment)
2521 (put symbol 'customized-variable-comment comment))
2523 (when (equal comment "")
2524 (setq comment nil)
2525 ;; Make the comment invisible by hand if it's empty
2526 (custom-comment-hide comment-widget))
2527 (custom-variable-backup-value widget)
2528 (funcall set symbol (setq val (widget-value child)))
2529 (put symbol 'customized-value (list (custom-quote val)))
2530 (put symbol 'variable-comment comment)
2531 (put symbol 'customized-variable-comment comment)))
2532 (custom-variable-state-set widget)
2533 (custom-redraw-magic widget)))
2535 (defun custom-variable-save (widget)
2536 "Set and save the value for the variable being edited by WIDGET."
2537 (let* ((form (widget-get widget :custom-form))
2538 (state (widget-get widget :custom-state))
2539 (child (car (widget-get widget :children)))
2540 (symbol (widget-value widget))
2541 (set (or (get symbol 'custom-set) 'set-default))
2542 (comment-widget (widget-get widget :comment-widget))
2543 (comment (widget-value comment-widget))
2544 val)
2545 (cond ((eq state 'hidden)
2546 (error "Cannot set hidden variable"))
2547 ((setq val (widget-apply child :validate))
2548 (goto-char (widget-get val :from))
2549 (error "Saving %s: %s" symbol (widget-get val :error)))
2550 ((memq form '(lisp mismatch))
2551 (when (equal comment "")
2552 (setq comment nil)
2553 ;; Make the comment invisible by hand if it's empty
2554 (custom-comment-hide comment-widget))
2555 (put symbol 'saved-value (list (widget-value child)))
2556 (custom-push-theme 'theme-value symbol 'user
2557 'set (list (widget-value child)))
2558 (funcall set symbol (eval (widget-value child)))
2559 (put symbol 'variable-comment comment)
2560 (put symbol 'saved-variable-comment comment))
2562 (when (equal comment "")
2563 (setq comment nil)
2564 ;; Make the comment invisible by hand if it's empty
2565 (custom-comment-hide comment-widget))
2566 (put symbol 'saved-value
2567 (list (custom-quote (widget-value child))))
2568 (custom-push-theme 'theme-value symbol 'user
2569 'set (list (custom-quote (widget-value
2570 child))))
2571 (funcall set symbol (widget-value child))
2572 (put symbol 'variable-comment comment)
2573 (put symbol 'saved-variable-comment comment)))
2574 (put symbol 'customized-value nil)
2575 (put symbol 'customized-variable-comment nil)
2576 (custom-save-all)
2577 (custom-variable-state-set widget)
2578 (custom-redraw-magic widget)))
2580 (defun custom-variable-reset-saved (widget)
2581 "Restore the saved value for the variable being edited by WIDGET.
2582 The value that was current before this operation
2583 becomes the backup value, so you can get it again."
2584 (let* ((symbol (widget-value widget))
2585 (set (or (get symbol 'custom-set) 'set-default))
2586 (value (get symbol 'saved-value))
2587 (comment (get symbol 'saved-variable-comment)))
2588 (cond ((or value comment)
2589 (put symbol 'variable-comment comment)
2590 (custom-variable-backup-value widget)
2591 (condition-case nil
2592 (funcall set symbol (eval (car value)))
2593 (error nil)))
2595 (error "No saved value for %s" symbol)))
2596 (put symbol 'customized-value nil)
2597 (put symbol 'customized-variable-comment nil)
2598 (widget-put widget :custom-state 'unknown)
2599 ;; This call will possibly make the comment invisible
2600 (custom-redraw widget)))
2602 (defun custom-variable-reset-standard (widget)
2603 "Restore the standard setting for the variable being edited by WIDGET.
2604 This operation eliminates any saved setting for the variable,
2605 restoring it to the state of a variable that has never been customized.
2606 The value that was current before this operation
2607 becomes the backup value, so you can get it again."
2608 (let* ((symbol (widget-value widget))
2609 (set (or (get symbol 'custom-set) 'set-default)))
2610 (if (get symbol 'standard-value)
2611 (progn
2612 (custom-variable-backup-value widget)
2613 (funcall set symbol (eval (car (get symbol 'standard-value)))))
2614 (error "No standard setting known for %S" symbol))
2615 (put symbol 'variable-comment nil)
2616 (put symbol 'customized-value nil)
2617 (put symbol 'customized-variable-comment nil)
2618 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2619 (put symbol 'saved-value nil)
2620 (custom-push-theme 'theme-value symbol 'user 'reset 'standard)
2621 ;; As a special optimizations we do not (explictly)
2622 ;; save resets to standard when no theme set the value.
2623 (if (null (cdr (get symbol 'theme-value)))
2624 (put symbol 'theme-value nil))
2625 (put symbol 'saved-variable-comment nil)
2626 (custom-save-all))
2627 (widget-put widget :custom-state 'unknown)
2628 ;; This call will possibly make the comment invisible
2629 (custom-redraw widget)))
2631 (defun custom-variable-backup-value (widget)
2632 "Back up the current value for WIDGET's variable.
2633 The backup value is kept in the car of the `backup-value' property."
2634 (let* ((symbol (widget-value widget))
2635 (get (or (get symbol 'custom-get) 'default-value))
2636 (type (custom-variable-type symbol))
2637 (conv (widget-convert type))
2638 (value (if (default-boundp symbol)
2639 (funcall get symbol)
2640 (widget-get conv :value))))
2641 (put symbol 'backup-value (list value))))
2643 (defun custom-variable-reset-backup (widget)
2644 "Restore the backup value for the variable being edited by WIDGET.
2645 The value that was current before this operation
2646 becomes the backup value, so you can use this operation repeatedly
2647 to switch between two values."
2648 (let* ((symbol (widget-value widget))
2649 (set (or (get symbol 'custom-set) 'set-default))
2650 (value (get symbol 'backup-value))
2651 (comment-widget (widget-get widget :comment-widget))
2652 (comment (widget-value comment-widget)))
2653 (if value
2654 (progn
2655 (custom-variable-backup-value widget)
2656 (condition-case nil
2657 (funcall set symbol (car value))
2658 (error nil)))
2659 (error "No backup value for %s" symbol))
2660 (put symbol 'customized-value (list (car value)))
2661 (put symbol 'variable-comment comment)
2662 (put symbol 'customized-variable-comment comment)
2663 (custom-variable-state-set widget)
2664 ;; This call will possibly make the comment invisible
2665 (custom-redraw widget)))
2667 ;;; The `custom-face-edit' Widget.
2669 (define-widget 'custom-face-edit 'checklist
2670 "Edit face attributes."
2671 :format "%t: %v"
2672 :tag "Attributes"
2673 :extra-offset 13
2674 :button-args '(:help-echo "Control whether this attribute has any effect.")
2675 :value-to-internal 'custom-face-edit-fix-value
2676 :match (lambda (widget value)
2677 (widget-checklist-match widget
2678 (custom-face-edit-fix-value widget value)))
2679 :convert-widget 'custom-face-edit-convert-widget
2680 :args (mapcar (lambda (att)
2681 (list 'group
2682 :inline t
2683 :sibling-args (widget-get (nth 1 att) :sibling-args)
2684 (list 'const :format "" :value (nth 0 att))
2685 (nth 1 att)))
2686 custom-face-attributes))
2688 (defun custom-face-edit-fix-value (widget value)
2689 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2690 Also change :reverse-video to :inverse-video."
2691 (if (listp value)
2692 (let (result)
2693 (while value
2694 (let ((key (car value))
2695 (val (car (cdr value))))
2696 (cond ((eq key :italic)
2697 (push :slant result)
2698 (push (if val 'italic 'normal) result))
2699 ((eq key :bold)
2700 (push :weight result)
2701 (push (if val 'bold 'normal) result))
2702 ((eq key :reverse-video)
2703 (push :inverse-video result)
2704 (push val result))
2706 (push key result)
2707 (push val result))))
2708 (setq value (cdr (cdr value))))
2709 (setq result (nreverse result))
2710 result)
2711 value))
2713 (defun custom-face-edit-convert-widget (widget)
2714 "Convert :args as widget types in WIDGET."
2715 (widget-put
2716 widget
2717 :args (mapcar (lambda (arg)
2718 (widget-convert arg
2719 :deactivate 'custom-face-edit-deactivate
2720 :activate 'custom-face-edit-activate
2721 :delete 'custom-face-edit-delete))
2722 (widget-get widget :args)))
2723 widget)
2725 (defun custom-face-edit-deactivate (widget)
2726 "Make face widget WIDGET inactive for user modifications."
2727 (unless (widget-get widget :inactive)
2728 (let ((tag (custom-face-edit-attribute-tag widget))
2729 (from (copy-marker (widget-get widget :from)))
2730 (value (widget-value widget))
2731 (inhibit-read-only t)
2732 (inhibit-modification-hooks t))
2733 (save-excursion
2734 (goto-char from)
2735 (widget-default-delete widget)
2736 (insert tag ": *\n")
2737 (widget-put widget :inactive
2738 (cons value (cons from (- (point) from))))))))
2740 (defun custom-face-edit-activate (widget)
2741 "Make face widget WIDGET inactive for user modifications."
2742 (let ((inactive (widget-get widget :inactive))
2743 (inhibit-read-only t)
2744 (inhibit-modification-hooks t))
2745 (when (consp inactive)
2746 (save-excursion
2747 (goto-char (car (cdr inactive)))
2748 (delete-region (point) (+ (point) (cdr (cdr inactive))))
2749 (widget-put widget :inactive nil)
2750 (widget-apply widget :create)
2751 (widget-value-set widget (car inactive))
2752 (widget-setup)))))
2754 (defun custom-face-edit-delete (widget)
2755 "Remove WIDGET from the buffer."
2756 (let ((inactive (widget-get widget :inactive))
2757 (inhibit-read-only t)
2758 (inhibit-modification-hooks t))
2759 (if (not inactive)
2760 ;; Widget is alive, we don't have to do anything special
2761 (widget-default-delete widget)
2762 ;; WIDGET is already deleted because we did so to inactivate it;
2763 ;; now just get rid of the label we put in its place.
2764 (delete-region (car (cdr inactive))
2765 (+ (car (cdr inactive)) (cdr (cdr inactive))))
2766 (widget-put widget :inactive nil))))
2769 (defun custom-face-edit-attribute-tag (widget)
2770 "Returns the first :tag property in WIDGET or one of its children."
2771 (let ((tag (widget-get widget :tag)))
2772 (or (and (not (equal tag "")) tag)
2773 (let ((children (widget-get widget :children)))
2774 (while (and (null tag) children)
2775 (setq tag (custom-face-edit-attribute-tag (pop children))))
2776 tag))))
2778 ;;; The `custom-display' Widget.
2780 (define-widget 'custom-display 'menu-choice
2781 "Select a display type."
2782 :tag "Display"
2783 :value t
2784 :help-echo "Specify frames where the face attributes should be used."
2785 :args '((const :tag "all" t)
2786 (const :tag "defaults" default)
2787 (checklist
2788 :offset 0
2789 :extra-offset 9
2790 :args ((group :sibling-args (:help-echo "\
2791 Only match the specified window systems.")
2792 (const :format "Type: "
2793 type)
2794 (checklist :inline t
2795 :offset 0
2796 (const :format "X "
2797 :sibling-args (:help-echo "\
2798 The X11 Window System.")
2800 (const :format "PM "
2801 :sibling-args (:help-echo "\
2802 OS/2 Presentation Manager.")
2804 (const :format "W32 "
2805 :sibling-args (:help-echo "\
2806 Windows NT/9X.")
2807 w32)
2808 (const :format "MAC "
2809 :sibling-args (:help-echo "\
2810 Macintosh OS.")
2811 mac)
2812 (const :format "DOS "
2813 :sibling-args (:help-echo "\
2814 Plain MS-DOS.")
2816 (const :format "TTY%n"
2817 :sibling-args (:help-echo "\
2818 Plain text terminals.")
2819 tty)))
2820 (group :sibling-args (:help-echo "\
2821 Only match the frames with the specified color support.")
2822 (const :format "Class: "
2823 class)
2824 (checklist :inline t
2825 :offset 0
2826 (const :format "Color "
2827 :sibling-args (:help-echo "\
2828 Match color frames.")
2829 color)
2830 (const :format "Grayscale "
2831 :sibling-args (:help-echo "\
2832 Match grayscale frames.")
2833 grayscale)
2834 (const :format "Monochrome%n"
2835 :sibling-args (:help-echo "\
2836 Match frames with no color support.")
2837 mono)))
2838 (group :sibling-args (:help-echo "\
2839 The minimum number of colors the frame should support.")
2840 (const :format "" min-colors)
2841 (integer :tag "Minimum number of colors" ))
2842 (group :sibling-args (:help-echo "\
2843 Only match frames with the specified intensity.")
2844 (const :format "\
2845 Background brightness: "
2846 background)
2847 (checklist :inline t
2848 :offset 0
2849 (const :format "Light "
2850 :sibling-args (:help-echo "\
2851 Match frames with light backgrounds.")
2852 light)
2853 (const :format "Dark\n"
2854 :sibling-args (:help-echo "\
2855 Match frames with dark backgrounds.")
2856 dark)))
2857 (group :sibling-args (:help-echo "\
2858 Only match frames that support the specified face attributes.")
2859 (const :format "Supports attributes:" supports)
2860 (custom-face-edit :inline t :format "%n%v"))))))
2862 ;;; The `custom-face' Widget.
2864 (defface custom-face-tag-face
2865 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
2866 "Face used for face tags."
2867 :group 'custom-faces)
2869 (defcustom custom-face-default-form 'selected
2870 "Default form of displaying face definition."
2871 :type '(choice (const all)
2872 (const selected)
2873 (const lisp))
2874 :group 'custom-buffer
2875 :version "20.3")
2877 (define-widget 'custom-face 'custom
2878 "Customize face."
2879 :sample-face 'custom-face-tag-face
2880 :help-echo "Set or reset this face."
2881 :documentation-property #'face-doc-string
2882 :value-create 'custom-face-value-create
2883 :action 'custom-face-action
2884 :custom-category 'face
2885 :custom-form nil ; defaults to value of `custom-face-default-form'
2886 :custom-set 'custom-face-set
2887 :custom-save 'custom-face-save
2888 :custom-reset-current 'custom-redraw
2889 :custom-reset-saved 'custom-face-reset-saved
2890 :custom-reset-standard 'custom-face-reset-standard
2891 :custom-standard-value 'custom-face-standard-value
2892 :custom-menu 'custom-face-menu-create)
2894 (define-widget 'custom-face-all 'editable-list
2895 "An editable list of display specifications and attributes."
2896 :entry-format "%i %d %v"
2897 :insert-button-args '(:help-echo "Insert new display specification here.")
2898 :append-button-args '(:help-echo "Append new display specification here.")
2899 :delete-button-args '(:help-echo "Delete this display specification.")
2900 :args '((group :format "%v" custom-display custom-face-edit)))
2902 (defconst custom-face-all (widget-convert 'custom-face-all)
2903 "Converted version of the `custom-face-all' widget.")
2905 (define-widget 'custom-display-unselected 'item
2906 "A display specification that doesn't match the selected display."
2907 :match 'custom-display-unselected-match)
2909 (defun custom-display-unselected-match (widget value)
2910 "Non-nil if VALUE is an unselected display specification."
2911 (not (face-spec-set-match-display value (selected-frame))))
2913 (define-widget 'custom-face-selected 'group
2914 "Edit the attributes of the selected display in a face specification."
2915 :args '((choice :inline t
2916 (group :tag "With Defaults" :inline t
2917 (group (const :tag "" default)
2918 (custom-face-edit :tag " Default\n Attributes"))
2919 (repeat :format ""
2920 :inline t
2921 (group custom-display-unselected sexp))
2922 (group (sexp :format "")
2923 (custom-face-edit :tag " Overriding\n Attributes"))
2924 (repeat :format ""
2925 :inline t
2926 sexp))
2927 (group :tag "No Defaults" :inline t
2928 (repeat :format ""
2929 :inline t
2930 (group custom-display-unselected sexp))
2931 (group (sexp :format "")
2932 (custom-face-edit :tag "\n Attributes"))
2933 (repeat :format ""
2934 :inline t
2935 sexp)))))
2939 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2940 "Converted version of the `custom-face-selected' widget.")
2942 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
2943 "Return a canonicalized version of SPEC using.
2944 FILTER-INDEX is the index in the entry for each attribute in
2945 `custom-face-attributes' at which the appropriate filter function can be
2946 found, and DEFAULT-FILTER is the filter to apply for attributes that
2947 don't specify one."
2948 (mapcar (lambda (entry)
2949 ;; Filter a single face-spec entry
2950 (let ((tests (car entry))
2951 (unfiltered-attrs
2952 ;; Handle both old- and new-style attribute syntax
2953 (if (listp (car (cdr entry)))
2954 (car (cdr entry))
2955 (cdr entry)))
2956 (filtered-attrs nil))
2957 ;; Filter each face attribute
2958 (while unfiltered-attrs
2959 (let* ((attr (pop unfiltered-attrs))
2960 (pre-filtered-value (pop unfiltered-attrs))
2961 (filter
2962 (or (nth filter-index (assq attr custom-face-attributes))
2963 default-filter))
2964 (filtered-value
2965 (if filter
2966 (funcall filter pre-filtered-value)
2967 pre-filtered-value)))
2968 (push filtered-value filtered-attrs)
2969 (push attr filtered-attrs)))
2971 (list tests filtered-attrs)))
2972 spec))
2974 (defun custom-pre-filter-face-spec (spec)
2975 "Return SPEC changed as necessary for editing by the face customization widget.
2976 SPEC must be a full face spec."
2977 (custom-filter-face-spec spec 2))
2979 (defun custom-post-filter-face-spec (spec)
2980 "Return the customized SPEC in a form suitable for setting the face."
2981 (custom-filter-face-spec spec 3))
2983 (defun custom-face-value-create (widget)
2984 "Create a list of the display specifications for WIDGET."
2985 (let ((buttons (widget-get widget :buttons))
2986 children
2987 (symbol (widget-get widget :value))
2988 (tag (widget-get widget :tag))
2989 (state (widget-get widget :custom-state))
2990 (begin (point))
2991 (is-last (widget-get widget :custom-last))
2992 (prefix (widget-get widget :custom-prefix)))
2993 (unless tag
2994 (setq tag (prin1-to-string symbol)))
2995 (cond ((eq custom-buffer-style 'tree)
2996 (insert prefix (if is-last " `--- " " |--- "))
2997 (push (widget-create-child-and-convert
2998 widget 'custom-browse-face-tag)
2999 buttons)
3000 (insert " " tag "\n")
3001 (widget-put widget :buttons buttons))
3003 ;; Create tag.
3004 (insert tag)
3005 (widget-specify-sample widget begin (point))
3006 (if (eq custom-buffer-style 'face)
3007 (insert " ")
3008 (if (string-match "face\\'" tag)
3009 (insert ":")
3010 (insert " face: ")))
3011 ;; Sample.
3012 (push (widget-create-child-and-convert widget 'item
3013 :format "(%{%t%})"
3014 :sample-face symbol
3015 :tag "sample")
3016 buttons)
3017 ;; Visibility.
3018 (insert " ")
3019 (push (widget-create-child-and-convert
3020 widget 'visibility
3021 :help-echo "Hide or show this face."
3022 :on "Hide Face"
3023 :off "Show Face"
3024 :action 'custom-toggle-parent
3025 (not (eq state 'hidden)))
3026 buttons)
3027 ;; Magic.
3028 (insert "\n")
3029 (let ((magic (widget-create-child-and-convert
3030 widget 'custom-magic nil)))
3031 (widget-put widget :custom-magic magic)
3032 (push magic buttons))
3033 ;; Update buttons.
3034 (widget-put widget :buttons buttons)
3035 ;; Insert documentation.
3036 (widget-default-format-handler widget ?h)
3037 ;; The comment field
3038 (unless (eq state 'hidden)
3039 (let* ((comment (get symbol 'face-comment))
3040 (comment-widget
3041 (widget-create-child-and-convert
3042 widget 'custom-comment
3043 :parent widget
3044 :value (or comment ""))))
3045 (widget-put widget :comment-widget comment-widget)
3046 (push comment-widget children)))
3047 ;; See also.
3048 (unless (eq state 'hidden)
3049 (when (eq (widget-get widget :custom-level) 1)
3050 (custom-add-parent-links widget))
3051 (custom-add-see-also widget))
3052 ;; Editor.
3053 (unless (eq (preceding-char) ?\n)
3054 (insert "\n"))
3055 (unless (eq state 'hidden)
3056 (message "Creating face editor...")
3057 (custom-load-widget widget)
3058 (unless (widget-get widget :custom-form)
3059 (widget-put widget :custom-form custom-face-default-form))
3060 (let* ((symbol (widget-value widget))
3061 (spec (or (get symbol 'customized-face)
3062 (get symbol 'saved-face)
3063 (get symbol 'face-defface-spec)
3064 ;; Attempt to construct it.
3065 (list (list t (custom-face-attributes-get
3066 symbol (selected-frame))))))
3067 (form (widget-get widget :custom-form))
3068 (indent (widget-get widget :indent))
3069 edit)
3070 ;; If the user has changed this face in some other way,
3071 ;; edit it as the user has specified it.
3072 (if (not (face-spec-match-p symbol spec (selected-frame)))
3073 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
3074 (setq spec (custom-pre-filter-face-spec spec))
3075 (setq edit (widget-create-child-and-convert
3076 widget
3077 (cond ((and (eq form 'selected)
3078 (widget-apply custom-face-selected
3079 :match spec))
3080 (when indent (insert-char ?\ indent))
3081 'custom-face-selected)
3082 ((and (not (eq form 'lisp))
3083 (widget-apply custom-face-all
3084 :match spec))
3085 'custom-face-all)
3087 (when indent (insert-char ?\ indent))
3088 'sexp))
3089 :value spec))
3090 (custom-face-state-set widget)
3091 (push edit children)
3092 (widget-put widget :children children))
3093 (message "Creating face editor...done"))))))
3095 (defvar custom-face-menu
3096 '(("Set for Current Session" custom-face-set)
3097 ("Save for Future Sessions" custom-face-save-command)
3098 ("Reset to Saved" custom-face-reset-saved
3099 (lambda (widget)
3100 (or (get (widget-value widget) 'saved-face)
3101 (get (widget-value widget) 'saved-face-comment))))
3102 ("Erase Customization" custom-face-reset-standard
3103 (lambda (widget)
3104 (get (widget-value widget) 'face-defface-spec)))
3105 ("---" ignore ignore)
3106 ("Add Comment" custom-comment-show custom-comment-invisible-p)
3107 ("---" ignore ignore)
3108 ("Show all display specs" custom-face-edit-all
3109 (lambda (widget)
3110 (not (eq (widget-get widget :custom-form) 'all))))
3111 ("Just current attributes" custom-face-edit-selected
3112 (lambda (widget)
3113 (not (eq (widget-get widget :custom-form) 'selected))))
3114 ("Show as Lisp expression" custom-face-edit-lisp
3115 (lambda (widget)
3116 (not (eq (widget-get widget :custom-form) 'lisp)))))
3117 "Alist of actions for the `custom-face' widget.
3118 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3119 the menu entry, ACTION is the function to call on the widget when the
3120 menu is selected, and FILTER is a predicate which takes a `custom-face'
3121 widget as an argument, and returns non-nil if ACTION is valid on that
3122 widget. If FILTER is nil, ACTION is always valid.")
3124 (defun custom-face-edit-selected (widget)
3125 "Edit selected attributes of the value of WIDGET."
3126 (widget-put widget :custom-state 'unknown)
3127 (widget-put widget :custom-form 'selected)
3128 (custom-redraw widget))
3130 (defun custom-face-edit-all (widget)
3131 "Edit all attributes of the value of WIDGET."
3132 (widget-put widget :custom-state 'unknown)
3133 (widget-put widget :custom-form 'all)
3134 (custom-redraw widget))
3136 (defun custom-face-edit-lisp (widget)
3137 "Edit the Lisp representation of the value of WIDGET."
3138 (widget-put widget :custom-state 'unknown)
3139 (widget-put widget :custom-form 'lisp)
3140 (custom-redraw widget))
3142 (defun custom-face-state-set (widget)
3143 "Set the state of WIDGET."
3144 (let* ((symbol (widget-value widget))
3145 (comment (get symbol 'face-comment))
3146 tmp temp
3147 (state
3148 (cond ((progn
3149 (setq tmp (get symbol 'customized-face))
3150 (setq temp (get symbol 'customized-face-comment))
3151 (or tmp temp))
3152 (if (equal temp comment)
3153 'set
3154 'changed))
3155 ((progn
3156 (setq tmp (get symbol 'saved-face))
3157 (setq temp (get symbol 'saved-face-comment))
3158 (or tmp temp))
3159 (if (equal temp comment)
3160 'saved
3161 'changed))
3162 ((get symbol 'face-defface-spec)
3163 (if (equal comment nil)
3164 'standard
3165 'changed))
3167 'rogue))))
3168 ;; If the user called set-face-attribute to change the default
3169 ;; for new frames, this face is "set outside of Customize".
3170 (if (and (not (eq state 'rogue))
3171 (get symbol 'face-modified))
3172 (setq state 'changed))
3173 (widget-put widget :custom-state state)))
3175 (defun custom-face-action (widget &optional event)
3176 "Show the menu for `custom-face' WIDGET.
3177 Optional EVENT is the location for the menu."
3178 (if (eq (widget-get widget :custom-state) 'hidden)
3179 (custom-toggle-hide widget)
3180 (let* ((completion-ignore-case t)
3181 (symbol (widget-get widget :value))
3182 (answer (widget-choose (concat "Operation on "
3183 (custom-unlispify-tag-name symbol))
3184 (custom-menu-filter custom-face-menu
3185 widget)
3186 event)))
3187 (if answer
3188 (funcall answer widget)))))
3190 (defun custom-face-set (widget)
3191 "Make the face attributes in WIDGET take effect."
3192 (let* ((symbol (widget-value widget))
3193 (child (car (widget-get widget :children)))
3194 (value (custom-post-filter-face-spec (widget-value child)))
3195 (comment-widget (widget-get widget :comment-widget))
3196 (comment (widget-value comment-widget)))
3197 (when (equal comment "")
3198 (setq comment nil)
3199 ;; Make the comment invisible by hand if it's empty
3200 (custom-comment-hide comment-widget))
3201 (put symbol 'customized-face value)
3202 (if (face-spec-choose value)
3203 (face-spec-set symbol value)
3204 ;; face-set-spec ignores empty attribute lists, so just give it
3205 ;; something harmless instead.
3206 (face-spec-set symbol '((t :foreground unspecified))))
3207 (put symbol 'customized-face-comment comment)
3208 (put symbol 'face-comment comment)
3209 (custom-face-state-set widget)
3210 (custom-redraw-magic widget)))
3212 (defun custom-face-save-command (widget)
3213 "Save in `.emacs' the face attributes in WIDGET."
3214 (custom-face-save widget)
3215 (custom-save-all))
3217 (defun custom-face-save (widget)
3218 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3219 (let* ((symbol (widget-value widget))
3220 (child (car (widget-get widget :children)))
3221 (value (custom-post-filter-face-spec (widget-value child)))
3222 (comment-widget (widget-get widget :comment-widget))
3223 (comment (widget-value comment-widget)))
3224 (when (equal comment "")
3225 (setq comment nil)
3226 ;; Make the comment invisible by hand if it's empty
3227 (custom-comment-hide comment-widget))
3228 (if (face-spec-choose value)
3229 (face-spec-set symbol value)
3230 ;; face-set-spec ignores empty attribute lists, so just give it
3231 ;; something harmless instead.
3232 (face-spec-set symbol '((t :foreground unspecified))))
3233 (unless (eq (widget-get widget :custom-state) 'standard)
3234 (put symbol 'saved-face value))
3235 (custom-push-theme 'theme-face symbol 'user 'set value)
3236 (put symbol 'customized-face nil)
3237 (put symbol 'face-comment comment)
3238 (put symbol 'customized-face-comment nil)
3239 (put symbol 'saved-face-comment comment)
3240 (custom-save-all)
3241 (custom-face-state-set widget)
3242 (custom-redraw-magic widget)))
3244 (defun custom-face-reset-saved (widget)
3245 "Restore WIDGET to the face's default attributes."
3246 (let* ((symbol (widget-value widget))
3247 (child (car (widget-get widget :children)))
3248 (value (get symbol 'saved-face))
3249 (comment (get symbol 'saved-face-comment))
3250 (comment-widget (widget-get widget :comment-widget)))
3251 (unless (or value comment)
3252 (error "No saved value for this face"))
3253 (put symbol 'customized-face nil)
3254 (put symbol 'customized-face-comment nil)
3255 (face-spec-set symbol value)
3256 (put symbol 'face-comment comment)
3257 (widget-value-set child value)
3258 ;; This call manages the comment visibility
3259 (widget-value-set comment-widget (or comment ""))
3260 (custom-face-state-set widget)
3261 (custom-redraw-magic widget)))
3263 (defun custom-face-standard-value (widget)
3264 (get (widget-value widget) 'face-defface-spec))
3266 (defun custom-face-reset-standard (widget)
3267 "Restore WIDGET to the face's standard settings.
3268 This operation eliminates any saved setting for the face,
3269 restoring it to the state of a face that has never been customized."
3270 (let* ((symbol (widget-value widget))
3271 (child (car (widget-get widget :children)))
3272 (value (get symbol 'face-defface-spec))
3273 (comment-widget (widget-get widget :comment-widget)))
3274 (unless value
3275 (error "No standard setting for this face"))
3276 (put symbol 'customized-face nil)
3277 (put symbol 'customized-face-comment nil)
3278 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3279 (put symbol 'saved-face nil)
3280 (custom-push-theme 'theme-face symbol 'user 'reset 'standard)
3281 ;; Do not explictly save resets to standards without themes.
3282 (if (null (cdr (get symbol 'theme-face)))
3283 (put symbol 'theme-face nil))
3284 (put symbol 'saved-face-comment nil)
3285 (custom-save-all))
3286 (face-spec-set symbol value)
3287 (put symbol 'face-comment nil)
3288 (widget-value-set child value)
3289 ;; This call manages the comment visibility
3290 (widget-value-set comment-widget "")
3291 (custom-face-state-set widget)
3292 (custom-redraw-magic widget)))
3294 ;;; The `face' Widget.
3296 (defvar widget-face-prompt-value-history nil
3297 "History of input to `widget-face-prompt-value'.")
3299 (define-widget 'face 'restricted-sexp
3300 "A Lisp face name."
3301 :complete-function (lambda ()
3302 (interactive)
3303 (lisp-complete-symbol 'facep))
3304 :prompt-value 'widget-field-prompt-value
3305 :prompt-internal 'widget-symbol-prompt-internal
3306 :prompt-match 'facep
3307 :prompt-history 'widget-face-prompt-value-history
3308 :value-create 'widget-face-value-create
3309 :action 'widget-field-action
3310 :match-alternatives '(facep)
3311 :validate (lambda (widget)
3312 (unless (facep (widget-value widget))
3313 (widget-put widget :error (format "Invalid face: %S"
3314 (widget-value widget)))
3315 widget))
3316 :value 'ignore
3317 :tag "Function")
3320 ;;; There is a bug here: the sample doesn't get redisplayed
3321 ;;; in the new font when you specify one. Does anyone know how to
3322 ;;; make that work? -- rms.
3324 (defun widget-face-value-create (widget)
3325 "Create an editable face name field."
3326 (let ((buttons (widget-get widget :buttons))
3327 (symbol (widget-get widget :value)))
3328 ;; Sample.
3329 (push (widget-create-child-and-convert widget 'item
3330 :format "(%{%t%})"
3331 :sample-face symbol
3332 :tag "sample")
3333 buttons)
3334 (insert " ")
3335 ;; Update buttons.
3336 (widget-put widget :buttons buttons))
3338 (let ((size (widget-get widget :size))
3339 (value (widget-get widget :value))
3340 (from (point))
3341 ;; This is changed to a real overlay in `widget-setup'. We
3342 ;; need the end points to behave differently until
3343 ;; `widget-setup' is called.
3344 (overlay (cons (make-marker) (make-marker))))
3345 (widget-put widget :field-overlay overlay)
3346 (insert value)
3347 (and size
3348 (< (length value) size)
3349 (insert-char ?\ (- size (length value))))
3350 (unless (memq widget widget-field-list)
3351 (setq widget-field-new (cons widget widget-field-new)))
3352 (move-marker (cdr overlay) (point))
3353 (set-marker-insertion-type (cdr overlay) nil)
3354 (when (null size)
3355 (insert ?\n))
3356 (move-marker (car overlay) from)
3357 (set-marker-insertion-type (car overlay) t)))
3360 ;;; The `hook' Widget.
3362 (define-widget 'hook 'list
3363 "A emacs lisp hook"
3364 :value-to-internal (lambda (widget value)
3365 (if (and value (symbolp value))
3366 (list value)
3367 value))
3368 :match (lambda (widget value)
3369 (or (symbolp value)
3370 (widget-group-match widget value)))
3371 ;; Avoid adding undefined functions to the hook, especially for
3372 ;; things like `find-file-hook' or even more basic ones, to avoid
3373 ;; chaos.
3374 :set (lambda (symbol value)
3375 (dolist (elt value)
3376 (if (fboundp elt)
3377 (add-hook symbol elt))))
3378 :convert-widget 'custom-hook-convert-widget
3379 :tag "Hook")
3381 (defun custom-hook-convert-widget (widget)
3382 ;; Handle `:options'.
3383 (let* ((options (widget-get widget :options))
3384 (other `(editable-list :inline t
3385 :entry-format "%i %d%v"
3386 (function :format " %v")))
3387 (args (if options
3388 (list `(checklist :inline t
3389 ,@(mapcar (lambda (entry)
3390 `(function-item ,entry))
3391 options))
3392 other)
3393 (list other))))
3394 (widget-put widget :args args)
3395 widget))
3397 ;;; The `custom-group-link' Widget.
3399 (define-widget 'custom-group-link 'link
3400 "Show parent in other window when activated."
3401 :help-echo "Create customization buffer for this group."
3402 :action 'custom-group-link-action)
3404 (defun custom-group-link-action (widget &rest ignore)
3405 (customize-group (widget-value widget)))
3407 ;;; The `custom-group' Widget.
3409 (defcustom custom-group-tag-faces nil
3410 ;; In XEmacs, this ought to play games with font size.
3411 ;; Fixme: make it do so in Emacs.
3412 "Face used for group tags.
3413 The first member is used for level 1 groups, the second for level 2,
3414 and so forth. The remaining group tags are shown with
3415 `custom-group-tag-face'."
3416 :type '(repeat face)
3417 :group 'custom-faces)
3419 (defface custom-group-tag-face-1
3420 `((((class color)
3421 (background dark))
3422 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3423 (((class color)
3424 (background light))
3425 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3426 (t (:weight bold)))
3427 "Face used for group tags."
3428 :group 'custom-faces)
3430 (defface custom-group-tag-face
3431 `((((class color)
3432 (background dark))
3433 (:foreground "light blue" :weight bold :height 1.2))
3434 (((class color)
3435 (background light))
3436 (:foreground "blue" :weight bold :height 1.2))
3437 (t (:weight bold)))
3438 "Face used for low level group tags."
3439 :group 'custom-faces)
3441 (define-widget 'custom-group 'custom
3442 "Customize group."
3443 :format "%v"
3444 :sample-face-get 'custom-group-sample-face-get
3445 :documentation-property 'group-documentation
3446 :help-echo "Set or reset all members of this group."
3447 :value-create 'custom-group-value-create
3448 :action 'custom-group-action
3449 :custom-category 'group
3450 :custom-set 'custom-group-set
3451 :custom-save 'custom-group-save
3452 :custom-reset-current 'custom-group-reset-current
3453 :custom-reset-saved 'custom-group-reset-saved
3454 :custom-reset-standard 'custom-group-reset-standard
3455 :custom-menu 'custom-group-menu-create)
3457 (defun custom-group-sample-face-get (widget)
3458 ;; Use :sample-face.
3459 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3460 'custom-group-tag-face))
3462 (define-widget 'custom-group-visibility 'visibility
3463 "An indicator and manipulator for hidden group contents."
3464 :create 'custom-group-visibility-create)
3466 (defun custom-group-visibility-create (widget)
3467 (let ((visible (widget-value widget)))
3468 (if visible
3469 (insert "--------")))
3470 (widget-default-create widget))
3472 (defun custom-group-members (symbol groups-only)
3473 "Return SYMBOL's custom group members.
3474 If GROUPS-ONLY non-nil, return only those members that are groups."
3475 (if (not groups-only)
3476 (get symbol 'custom-group)
3477 (let (members)
3478 (dolist (entry (get symbol 'custom-group))
3479 (when (eq (nth 1 entry) 'custom-group)
3480 (push entry members)))
3481 (nreverse members))))
3483 (defun custom-group-value-create (widget)
3484 "Insert a customize group for WIDGET in the current buffer."
3485 (unless (eq (widget-get widget :custom-state) 'hidden)
3486 (custom-load-widget widget))
3487 (let* ((state (widget-get widget :custom-state))
3488 (level (widget-get widget :custom-level))
3489 ;; (indent (widget-get widget :indent))
3490 (prefix (widget-get widget :custom-prefix))
3491 (buttons (widget-get widget :buttons))
3492 (tag (widget-get widget :tag))
3493 (symbol (widget-value widget))
3494 (members (custom-group-members symbol
3495 (and (eq custom-buffer-style 'tree)
3496 custom-browse-only-groups))))
3497 (cond ((and (eq custom-buffer-style 'tree)
3498 (eq state 'hidden)
3499 (or members (custom-unloaded-widget-p widget)))
3500 (custom-browse-insert-prefix prefix)
3501 (push (widget-create-child-and-convert
3502 widget 'custom-browse-visibility
3503 ;; :tag-glyph "plus"
3504 :tag "+")
3505 buttons)
3506 (insert "-- ")
3507 ;; (widget-glyph-insert nil "-- " "horizontal")
3508 (push (widget-create-child-and-convert
3509 widget 'custom-browse-group-tag)
3510 buttons)
3511 (insert " " tag "\n")
3512 (widget-put widget :buttons buttons))
3513 ((and (eq custom-buffer-style 'tree)
3514 (zerop (length members)))
3515 (custom-browse-insert-prefix prefix)
3516 (insert "[ ]-- ")
3517 ;; (widget-glyph-insert nil "[ ]" "empty")
3518 ;; (widget-glyph-insert nil "-- " "horizontal")
3519 (push (widget-create-child-and-convert
3520 widget 'custom-browse-group-tag)
3521 buttons)
3522 (insert " " tag "\n")
3523 (widget-put widget :buttons buttons))
3524 ((eq custom-buffer-style 'tree)
3525 (custom-browse-insert-prefix prefix)
3526 (if (zerop (length members))
3527 (progn
3528 (custom-browse-insert-prefix prefix)
3529 (insert "[ ]-- ")
3530 ;; (widget-glyph-insert nil "[ ]" "empty")
3531 ;; (widget-glyph-insert nil "-- " "horizontal")
3532 (push (widget-create-child-and-convert
3533 widget 'custom-browse-group-tag)
3534 buttons)
3535 (insert " " tag "\n")
3536 (widget-put widget :buttons buttons))
3537 (push (widget-create-child-and-convert
3538 widget 'custom-browse-visibility
3539 ;; :tag-glyph "minus"
3540 :tag "-")
3541 buttons)
3542 (insert "-\\ ")
3543 ;; (widget-glyph-insert nil "-\\ " "top")
3544 (push (widget-create-child-and-convert
3545 widget 'custom-browse-group-tag)
3546 buttons)
3547 (insert " " tag "\n")
3548 (widget-put widget :buttons buttons)
3549 (message "Creating group...")
3550 (let* ((members (custom-sort-items members
3551 custom-browse-sort-alphabetically
3552 custom-browse-order-groups))
3553 (prefixes (widget-get widget :custom-prefixes))
3554 (custom-prefix-list (custom-prefix-add symbol prefixes))
3555 (extra-prefix (if (widget-get widget :custom-last)
3557 " | "))
3558 (prefix (concat prefix extra-prefix))
3559 children entry)
3560 (while members
3561 (setq entry (car members)
3562 members (cdr members))
3563 (push (widget-create-child-and-convert
3564 widget (nth 1 entry)
3565 :group widget
3566 :tag (custom-unlispify-tag-name (nth 0 entry))
3567 :custom-prefixes custom-prefix-list
3568 :custom-level (1+ level)
3569 :custom-last (null members)
3570 :value (nth 0 entry)
3571 :custom-prefix prefix)
3572 children))
3573 (widget-put widget :children (reverse children)))
3574 (message "Creating group...done")))
3575 ;; Nested style.
3576 ((eq state 'hidden)
3577 ;; Create level indicator.
3578 (unless (eq custom-buffer-style 'links)
3579 (insert-char ?\ (* custom-buffer-indent (1- level)))
3580 (insert "-- "))
3581 ;; Create tag.
3582 (let ((begin (point)))
3583 (insert tag)
3584 (widget-specify-sample widget begin (point)))
3585 (insert " group: ")
3586 ;; Create link/visibility indicator.
3587 (if (eq custom-buffer-style 'links)
3588 (push (widget-create-child-and-convert
3589 widget 'custom-group-link
3590 :tag "Go to Group"
3591 symbol)
3592 buttons)
3593 (push (widget-create-child-and-convert
3594 widget 'custom-group-visibility
3595 :help-echo "Show members of this group."
3596 :action 'custom-toggle-parent
3597 (not (eq state 'hidden)))
3598 buttons))
3599 (insert " \n")
3600 ;; Create magic button.
3601 (let ((magic (widget-create-child-and-convert
3602 widget 'custom-magic nil)))
3603 (widget-put widget :custom-magic magic)
3604 (push magic buttons))
3605 ;; Update buttons.
3606 (widget-put widget :buttons buttons)
3607 ;; Insert documentation.
3608 (if (and (eq custom-buffer-style 'links) (> level 1))
3609 (widget-put widget :documentation-indent 0))
3610 (widget-default-format-handler widget ?h))
3611 ;; Nested style.
3612 (t ;Visible.
3613 ;; Add parent groups references above the group.
3614 (if t ;;; This should test that the buffer
3615 ;;; was made to display a group.
3616 (when (eq level 1)
3617 (if (custom-add-parent-links widget
3618 "Go to parent group:")
3619 (insert "\n"))))
3620 ;; Create level indicator.
3621 (insert-char ?\ (* custom-buffer-indent (1- level)))
3622 (insert "/- ")
3623 ;; Create tag.
3624 (let ((start (point)))
3625 (insert tag)
3626 (widget-specify-sample widget start (point)))
3627 (insert " group: ")
3628 ;; Create visibility indicator.
3629 (unless (eq custom-buffer-style 'links)
3630 (insert "--------")
3631 (push (widget-create-child-and-convert
3632 widget 'visibility
3633 :help-echo "Hide members of this group."
3634 :action 'custom-toggle-parent
3635 (not (eq state 'hidden)))
3636 buttons)
3637 (insert " "))
3638 ;; Create more dashes.
3639 ;; Use 76 instead of 75 to compensate for the temporary "<"
3640 ;; added by `widget-insert'.
3641 (insert-char ?- (- 76 (current-column)
3642 (* custom-buffer-indent level)))
3643 (insert "\\\n")
3644 ;; Create magic button.
3645 (let ((magic (widget-create-child-and-convert
3646 widget 'custom-magic
3647 :indent 0
3648 nil)))
3649 (widget-put widget :custom-magic magic)
3650 (push magic buttons))
3651 ;; Update buttons.
3652 (widget-put widget :buttons buttons)
3653 ;; Insert documentation.
3654 (widget-default-format-handler widget ?h)
3655 ;; Parent groups.
3656 (if nil ;;; This should test that the buffer
3657 ;;; was not made to display a group.
3658 (when (eq level 1)
3659 (insert-char ?\ custom-buffer-indent)
3660 (custom-add-parent-links widget)))
3661 (custom-add-see-also widget
3662 (make-string (* custom-buffer-indent level)
3663 ?\ ))
3664 ;; Members.
3665 (message "Creating group...")
3666 (let* ((members (custom-sort-items members
3667 custom-buffer-sort-alphabetically
3668 custom-buffer-order-groups))
3669 (prefixes (widget-get widget :custom-prefixes))
3670 (custom-prefix-list (custom-prefix-add symbol prefixes))
3671 (length (length members))
3672 (count 0)
3673 (children (mapcar (lambda (entry)
3674 (widget-insert "\n")
3675 (message "\
3676 Creating group members... %2d%%"
3677 (/ (* 100.0 count) length))
3678 (setq count (1+ count))
3679 (prog1
3680 (widget-create-child-and-convert
3681 widget (nth 1 entry)
3682 :group widget
3683 :tag (custom-unlispify-tag-name
3684 (nth 0 entry))
3685 :custom-prefixes custom-prefix-list
3686 :custom-level (1+ level)
3687 :value (nth 0 entry))
3688 (unless (eq (preceding-char) ?\n)
3689 (widget-insert "\n"))))
3690 members)))
3691 (message "Creating group magic...")
3692 (mapc 'custom-magic-reset children)
3693 (message "Creating group state...")
3694 (widget-put widget :children children)
3695 (custom-group-state-update widget)
3696 (message "Creating group... done"))
3697 ;; End line
3698 (insert "\n")
3699 (insert-char ?\ (* custom-buffer-indent (1- level)))
3700 (insert "\\- " (widget-get widget :tag) " group end ")
3701 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3702 (insert "/\n")))))
3704 (defvar custom-group-menu
3705 '(("Set for Current Session" custom-group-set
3706 (lambda (widget)
3707 (eq (widget-get widget :custom-state) 'modified)))
3708 ("Save for Future Sessions" custom-group-save
3709 (lambda (widget)
3710 (memq (widget-get widget :custom-state) '(modified set))))
3711 ("Reset to Current" custom-group-reset-current
3712 (lambda (widget)
3713 (memq (widget-get widget :custom-state) '(modified))))
3714 ("Reset to Saved" custom-group-reset-saved
3715 (lambda (widget)
3716 (memq (widget-get widget :custom-state) '(modified set))))
3717 ("Reset to standard setting" custom-group-reset-standard
3718 (lambda (widget)
3719 (memq (widget-get widget :custom-state) '(modified set saved)))))
3720 "Alist of actions for the `custom-group' widget.
3721 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3722 the menu entry, ACTION is the function to call on the widget when the
3723 menu is selected, and FILTER is a predicate which takes a `custom-group'
3724 widget as an argument, and returns non-nil if ACTION is valid on that
3725 widget. If FILTER is nil, ACTION is always valid.")
3727 (defun custom-group-action (widget &optional event)
3728 "Show the menu for `custom-group' WIDGET.
3729 Optional EVENT is the location for the menu."
3730 (if (eq (widget-get widget :custom-state) 'hidden)
3731 (custom-toggle-hide widget)
3732 (let* ((completion-ignore-case t)
3733 (answer (widget-choose (concat "Operation on "
3734 (custom-unlispify-tag-name
3735 (widget-get widget :value)))
3736 (custom-menu-filter custom-group-menu
3737 widget)
3738 event)))
3739 (if answer
3740 (funcall answer widget)))))
3742 (defun custom-group-set (widget)
3743 "Set changes in all modified group members."
3744 (let ((children (widget-get widget :children)))
3745 (mapc (lambda (child)
3746 (when (eq (widget-get child :custom-state) 'modified)
3747 (widget-apply child :custom-set)))
3748 children )))
3750 (defun custom-group-save (widget)
3751 "Save all modified group members."
3752 (let ((children (widget-get widget :children)))
3753 (mapc (lambda (child)
3754 (when (memq (widget-get child :custom-state) '(modified set))
3755 (widget-apply child :custom-save)))
3756 children )))
3758 (defun custom-group-reset-current (widget)
3759 "Reset all modified group members."
3760 (let ((children (widget-get widget :children)))
3761 (mapc (lambda (child)
3762 (when (eq (widget-get child :custom-state) 'modified)
3763 (widget-apply child :custom-reset-current)))
3764 children )))
3766 (defun custom-group-reset-saved (widget)
3767 "Reset all modified or set group members."
3768 (let ((children (widget-get widget :children)))
3769 (mapc (lambda (child)
3770 (when (memq (widget-get child :custom-state) '(modified set))
3771 (widget-apply child :custom-reset-saved)))
3772 children )))
3774 (defun custom-group-reset-standard (widget)
3775 "Reset all modified, set, or saved group members."
3776 (let ((children (widget-get widget :children)))
3777 (mapc (lambda (child)
3778 (when (memq (widget-get child :custom-state)
3779 '(modified set saved))
3780 (widget-apply child :custom-reset-standard)))
3781 children )))
3783 (defun custom-group-state-update (widget)
3784 "Update magic."
3785 (unless (eq (widget-get widget :custom-state) 'hidden)
3786 (let* ((children (widget-get widget :children))
3787 (states (mapcar (lambda (child)
3788 (widget-get child :custom-state))
3789 children))
3790 (magics custom-magic-alist)
3791 (found 'standard))
3792 (while magics
3793 (let ((magic (car (car magics))))
3794 (if (and (not (eq magic 'hidden))
3795 (memq magic states))
3796 (setq found magic
3797 magics nil)
3798 (setq magics (cdr magics)))))
3799 (widget-put widget :custom-state found)))
3800 (custom-magic-reset widget))
3802 ;;; The `custom-save-all' Function.
3803 ;;;###autoload
3804 (defcustom custom-file nil
3805 "File used for storing customization information.
3806 The default is nil, which means to use your init file
3807 as specified by `user-init-file'. If the value is not nil,
3808 it should be an absolute file name.
3810 You can set this option through Custom, if you carefully read the
3811 last paragraph below. However, usually it is simpler to write
3812 something like the following in your init file:
3814 \(setq custom-file \"~/.emacs-custom.el\")
3815 \(load custom-file)
3817 Note that both lines are necessary: the first line tells Custom to
3818 save all customizations in this file, but does not load it.
3820 When you change this variable outside Custom, look in the
3821 previous custom file \(usually your init file) for the
3822 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
3823 and copy them (whichever ones you find) to the new custom file.
3824 This will preserve your existing customizations.
3826 If you save this option using Custom, Custom will write all
3827 currently saved customizations, including the new one for this
3828 option itself, into the file you specify, overwriting any
3829 `custom-set-variables' and `custom-set-faces' forms already
3830 present in that file. It will not delete any customizations from
3831 the old custom file. You should do that manually if that is what you
3832 want. You also have to put something like `\(load \"CUSTOM-FILE\")
3833 in your init file, where CUSTOM-FILE is the actual name of the
3834 file. Otherwise, Emacs will not load the file when it starts up,
3835 and hence will not set `custom-file' to that file either."
3836 :type '(choice (const :tag "Your Emacs init file" nil)
3837 (file :format "%t:%v%d"
3838 :doc
3839 "Please read entire docstring below before setting \
3840 this through Custom.
3841 Click om \"More\" \(or position point there and press RETURN)
3842 if only the first line of the docstring is shown."))
3843 :group 'customize)
3845 (defun custom-file ()
3846 "Return the file name for saving customizations."
3847 (or custom-file
3848 (let ((user-init-file user-init-file)
3849 (default-init-file
3850 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
3851 (when (null user-init-file)
3852 (if (or (file-exists-p default-init-file)
3853 (and (eq system-type 'windows-nt)
3854 (file-exists-p "~/_emacs")))
3855 ;; Started with -q, i.e. the file containing
3856 ;; Custom settings hasn't been read. Saving
3857 ;; settings there would overwrite other settings.
3858 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3859 (setq user-init-file default-init-file))
3860 user-init-file)))
3862 (defun custom-save-delete (symbol)
3863 "Visit `custom-file' and delete all calls to SYMBOL from it.
3864 Leave point at the old location of the first such call,
3865 or (if there were none) at the end of the buffer."
3866 (let ((default-major-mode 'emacs-lisp-mode))
3867 (set-buffer (find-file-noselect (custom-file))))
3868 (goto-char (point-min))
3869 ;; Skip all whitespace and comments.
3870 (while (forward-comment 1))
3871 (or (eobp)
3872 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3873 (let (first)
3874 (catch 'found
3875 (while t ;; We exit this loop only via throw.
3876 ;; Skip all whitespace and comments.
3877 (while (forward-comment 1))
3878 (let ((start (point))
3879 (sexp (condition-case nil
3880 (read (current-buffer))
3881 (end-of-file (throw 'found nil)))))
3882 (when (and (listp sexp)
3883 (eq (car sexp) symbol))
3884 (delete-region start (point))
3885 (unless first
3886 (setq first (point)))))))
3887 (if first
3888 (goto-char first)
3889 ;; Move in front of local variables, otherwise long Custom
3890 ;; entries would make them ineffective.
3891 (let ((pos (point-max))
3892 (case-fold-search t))
3893 (save-excursion
3894 (goto-char (point-max))
3895 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3896 'move)
3897 (when (search-forward "Local Variables:" nil t)
3898 (setq pos (line-beginning-position))))
3899 (goto-char pos)))))
3901 (defun custom-save-variables ()
3902 "Save all customized variables in `custom-file'."
3903 (save-excursion
3904 (custom-save-delete 'custom-load-themes)
3905 (custom-save-delete 'custom-reset-variables)
3906 (custom-save-delete 'custom-set-variables)
3907 (custom-save-loaded-themes)
3908 (custom-save-resets 'theme-value 'custom-reset-variables nil)
3909 (let ((standard-output (current-buffer))
3910 (saved-list (make-list 1 0))
3911 sort-fold-case)
3912 ;; First create a sorted list of saved variables.
3913 (mapatoms
3914 (lambda (symbol)
3915 (if (get symbol 'saved-value)
3916 (nconc saved-list (list symbol)))))
3917 (setq saved-list (sort (cdr saved-list) 'string<))
3918 (unless (bolp)
3919 (princ "\n"))
3920 (princ "(custom-set-variables
3921 ;; custom-set-variables was added by Custom.
3922 ;; If you edit it by hand, you could mess it up, so be careful.
3923 ;; Your init file should contain only one such instance.
3924 ;; If there is more than one, they won't work right.\n")
3925 (dolist (symbol saved-list)
3926 (let ((spec (car-safe (get symbol 'theme-value)))
3927 (value (get symbol 'saved-value))
3928 (requests (get symbol 'custom-requests))
3929 (now (not (or (custom-variable-p symbol)
3930 (and (not (boundp symbol))
3931 (not (eq (get symbol 'force-value)
3932 'rogue))))))
3933 (comment (get symbol 'saved-variable-comment)))
3934 ;; Check `requests'.
3935 (dolist (request requests)
3936 (when (and (symbolp request) (not (featurep request)))
3937 (message "Unknown requested feature: %s" request)
3938 (setq requests (delq request requests))))
3939 (when (or (and spec
3940 (eq (nth 0 spec) 'user)
3941 (eq (nth 1 spec) 'set))
3942 comment
3943 (and (null spec) (get symbol 'saved-value)))
3944 (unless (bolp)
3945 (princ "\n"))
3946 (princ " '(")
3947 (prin1 symbol)
3948 (princ " ")
3949 (prin1 (car value))
3950 (when (or now requests comment)
3951 (princ " ")
3952 (prin1 now)
3953 (when (or requests comment)
3954 (princ " ")
3955 (prin1 requests)
3956 (when comment
3957 (princ " ")
3958 (prin1 comment))))
3959 (princ ")"))))
3960 (if (bolp)
3961 (princ " "))
3962 (princ ")")
3963 (unless (looking-at "\n")
3964 (princ "\n")))))
3966 (defun custom-save-faces ()
3967 "Save all customized faces in `custom-file'."
3968 (save-excursion
3969 (custom-save-delete 'custom-reset-faces)
3970 (custom-save-delete 'custom-set-faces)
3971 (custom-save-resets 'theme-face 'custom-reset-faces '(default))
3972 (let ((standard-output (current-buffer))
3973 (saved-list (make-list 1 0))
3974 sort-fold-case)
3975 ;; First create a sorted list of saved faces.
3976 (mapatoms
3977 (lambda (symbol)
3978 (if (get symbol 'saved-face)
3979 (nconc saved-list (list symbol)))))
3980 (setq saved-list (sort (cdr saved-list) 'string<))
3981 ;; The default face must be first, since it affects the others.
3982 (if (memq 'default saved-list)
3983 (setq saved-list (cons 'default (delq 'default saved-list))))
3984 (unless (bolp)
3985 (princ "\n"))
3986 (princ "(custom-set-faces
3987 ;; custom-set-faces was added by Custom.
3988 ;; If you edit it by hand, you could mess it up, so be careful.
3989 ;; Your init file should contain only one such instance.
3990 ;; If there is more than one, they won't work right.\n")
3991 (dolist (symbol saved-list)
3992 (let ((spec (car-safe (get symbol 'theme-face)))
3993 (value (get symbol 'saved-face))
3994 (now (not (or (get symbol 'face-defface-spec)
3995 (and (not (custom-facep symbol))
3996 (not (get symbol 'force-face))))))
3997 (comment (get symbol 'saved-face-comment)))
3998 (when (or (and spec
3999 (eq (nth 0 spec) 'user)
4000 (eq (nth 1 spec) 'set))
4001 comment
4002 (and (null spec) (get symbol 'saved-face)))
4003 ;; Don't print default face here.
4004 (unless (bolp)
4005 (princ "\n"))
4006 (princ " '(")
4007 (prin1 symbol)
4008 (princ " ")
4009 (prin1 value)
4010 (when (or now comment)
4011 (princ " ")
4012 (prin1 now)
4013 (when comment
4014 (princ " ")
4015 (prin1 comment)))
4016 (princ ")"))))
4017 (if (bolp)
4018 (princ " "))
4019 (princ ")")
4020 (unless (looking-at "\n")
4021 (princ "\n")))))
4023 (defun custom-save-resets (property setter special)
4024 (let (started-writing ignored-special)
4025 ;; (custom-save-delete setter) Done by caller
4026 (let ((standard-output (current-buffer))
4027 (mapper `(lambda (object)
4028 (let ((spec (car-safe (get object (quote ,property)))))
4029 (when (and (not (memq object ignored-special))
4030 (eq (nth 0 spec) 'user)
4031 (eq (nth 1 spec) 'reset))
4032 ;; Do not write reset statements unless necessary.
4033 (unless started-writing
4034 (setq started-writing t)
4035 (unless (bolp)
4036 (princ "\n"))
4037 (princ "(")
4038 (princ (quote ,setter))
4039 (princ "\n '(")
4040 (prin1 object)
4041 (princ " ")
4042 (prin1 (nth 3 spec))
4043 (princ ")")))))))
4044 (mapc mapper special)
4045 (setq ignored-special special)
4046 (mapatoms mapper)
4047 (when started-writing
4048 (princ ")\n")))))
4050 (defun custom-save-loaded-themes ()
4051 (let ((themes (reverse (get 'user 'theme-loads-themes)))
4052 (standard-output (current-buffer)))
4053 (when themes
4054 (unless (bolp) (princ "\n"))
4055 (princ "(custom-load-themes")
4056 (mapc (lambda (theme)
4057 (princ "\n '")
4058 (prin1 theme)) themes)
4059 (princ " )\n"))))
4061 ;;;###autoload
4062 (defun customize-save-customized ()
4063 "Save all user options which have been set in this session."
4064 (interactive)
4065 (mapatoms (lambda (symbol)
4066 (let ((face (get symbol 'customized-face))
4067 (value (get symbol 'customized-value))
4068 (face-comment (get symbol 'customized-face-comment))
4069 (variable-comment
4070 (get symbol 'customized-variable-comment)))
4071 (when face
4072 (put symbol 'saved-face face)
4073 (custom-push-theme 'theme-face symbol 'user 'set value)
4074 (put symbol 'customized-face nil))
4075 (when value
4076 (put symbol 'saved-value value)
4077 (custom-push-theme 'theme-value symbol 'user 'set value)
4078 (put symbol 'customized-value nil))
4079 (when variable-comment
4080 (put symbol 'saved-variable-comment variable-comment)
4081 (put symbol 'customized-variable-comment nil))
4082 (when face-comment
4083 (put symbol 'saved-face-comment face-comment)
4084 (put symbol 'customized-face-comment nil)))))
4085 ;; We really should update all custom buffers here.
4086 (custom-save-all))
4088 ;;;###autoload
4089 (defun custom-save-all ()
4090 "Save all customizations in `custom-file'."
4091 (let ((inhibit-read-only t))
4092 (custom-save-variables)
4093 (custom-save-faces)
4094 (save-excursion
4095 (let ((default-major-mode nil))
4096 (set-buffer (find-file-noselect (custom-file))))
4097 (let ((file-precious-flag t))
4098 (save-buffer)))))
4100 ;;; The Customize Menu.
4102 ;;; Menu support
4104 (defcustom custom-menu-nesting 2
4105 "Maximum nesting in custom menus."
4106 :type 'integer
4107 :group 'custom-menu)
4109 (defun custom-face-menu-create (widget symbol)
4110 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4111 (vector (custom-unlispify-menu-entry symbol)
4112 `(customize-face ',symbol)
4115 (defun custom-variable-menu-create (widget symbol)
4116 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4117 (let ((type (get symbol 'custom-type)))
4118 (unless (listp type)
4119 (setq type (list type)))
4120 (if (and type (widget-get type :custom-menu))
4121 (widget-apply type :custom-menu symbol)
4122 (vector (custom-unlispify-menu-entry symbol)
4123 `(customize-variable ',symbol)
4124 t))))
4126 ;; Add checkboxes to boolean variable entries.
4127 (widget-put (get 'boolean 'widget-type)
4128 :custom-menu (lambda (widget symbol)
4129 (vector (custom-unlispify-menu-entry symbol)
4130 `(customize-variable ',symbol)
4131 ':style 'toggle
4132 ':selected symbol)))
4134 (defun custom-group-menu-create (widget symbol)
4135 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4136 `( ,(custom-unlispify-menu-entry symbol t)
4137 :filter (lambda (&rest junk)
4138 (let ((menu (custom-menu-create ',symbol)))
4139 (if (consp menu) (cdr menu) menu)))))
4141 ;;;###autoload
4142 (defun custom-menu-create (symbol)
4143 "Create menu for customization group SYMBOL.
4144 The menu is in a format applicable to `easy-menu-define'."
4145 (let* ((item (vector (custom-unlispify-menu-entry symbol)
4146 `(customize-group ',symbol)
4147 t)))
4148 (if (and (or (not (boundp 'custom-menu-nesting))
4149 (>= custom-menu-nesting 0))
4150 (progn
4151 (custom-load-symbol symbol)
4152 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
4153 (let ((custom-prefix-list (custom-prefix-add symbol
4154 custom-prefix-list))
4155 (members (custom-sort-items (get symbol 'custom-group)
4156 custom-menu-sort-alphabetically
4157 custom-menu-order-groups)))
4158 `(,(custom-unlispify-menu-entry symbol t)
4159 ,item
4160 "--"
4161 ,@(mapcar (lambda (entry)
4162 (widget-apply (if (listp (nth 1 entry))
4163 (nth 1 entry)
4164 (list (nth 1 entry)))
4165 :custom-menu (nth 0 entry)))
4166 members)))
4167 item)))
4169 ;;;###autoload
4170 (defun customize-menu-create (symbol &optional name)
4171 "Return a customize menu for customization group SYMBOL.
4172 If optional NAME is given, use that as the name of the menu.
4173 Otherwise the menu will be named `Customize'.
4174 The format is suitable for use with `easy-menu-define'."
4175 (unless name
4176 (setq name "Customize"))
4177 `(,name
4178 :filter (lambda (&rest junk)
4179 (let ((menu (custom-menu-create ',symbol)))
4180 (if (consp menu) (cdr menu) menu)))))
4182 ;;; The Custom Mode.
4184 (defvar custom-mode-map
4185 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4186 ;; "\r" bindings from the parent map.
4187 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4188 (let ((map (make-keymap)))
4189 (set-keymap-parent map widget-keymap)
4190 (suppress-keymap map)
4191 (define-key map " " 'scroll-up)
4192 (define-key map "\177" 'scroll-down)
4193 (define-key map "\C-x\C-s" 'Custom-save)
4194 (define-key map "q" 'Custom-buffer-done)
4195 (define-key map "u" 'Custom-goto-parent)
4196 (define-key map "n" 'widget-forward)
4197 (define-key map "p" 'widget-backward)
4198 (define-key map [mouse-1] 'Custom-move-and-invoke)
4199 map)
4200 "Keymap for `custom-mode'.")
4202 (defun Custom-move-and-invoke (event)
4203 "Move to where you click, and if it is an active field, invoke it."
4204 (interactive "e")
4205 (mouse-set-point event)
4206 (if (widget-event-point event)
4207 (let* ((pos (widget-event-point event))
4208 (button (get-char-property pos 'button)))
4209 (if button
4210 (widget-button-click event)))))
4212 (easy-menu-define Custom-mode-menu
4213 custom-mode-map
4214 "Menu used in customization buffers."
4215 `("Custom"
4216 ,(customize-menu-create 'customize)
4217 ["Set" Custom-set t]
4218 ["Save" Custom-save t]
4219 ["Reset to Current" Custom-reset-current t]
4220 ["Reset to Saved" Custom-reset-saved t]
4221 ["Reset to Standard Settings" Custom-reset-standard t]
4222 ["Info" (Info-goto-node "(emacs)Easy Customization") t]))
4224 (defun Custom-goto-parent ()
4225 "Go to the parent group listed at the top of this buffer.
4226 If several parents are listed, go to the first of them."
4227 (interactive)
4228 (save-excursion
4229 (goto-char (point-min))
4230 (if (search-forward "\nGo to parent group: " nil t)
4231 (let* ((button (get-char-property (point) 'button))
4232 (parent (downcase (widget-get button :tag))))
4233 (customize-group parent)))))
4235 (defcustom custom-mode-hook nil
4236 "Hook called when entering Custom mode."
4237 :type 'hook
4238 :group 'custom-buffer )
4240 (defun custom-state-buffer-message (widget)
4241 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4242 (message "To install your edits, invoke [State] and choose the Set operation")))
4244 (defun custom-mode ()
4245 "Major mode for editing customization buffers.
4247 The following commands are available:
4249 Move to next button or editable field. \\[widget-forward]
4250 Move to previous button or editable field. \\[widget-backward]
4251 \\<widget-field-keymap>\
4252 Complete content of editable text field. \\[widget-complete]
4253 \\<custom-mode-map>\
4254 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4255 Invoke button under point. \\[widget-button-press]
4256 Set all modifications. \\[Custom-set]
4257 Make all modifications default. \\[Custom-save]
4258 Reset all modified options. \\[Custom-reset-current]
4259 Reset all modified or set options. \\[Custom-reset-saved]
4260 Reset all options. \\[Custom-reset-standard]
4262 Entry to this mode calls the value of `custom-mode-hook'
4263 if that value is non-nil."
4264 (kill-all-local-variables)
4265 (setq major-mode 'custom-mode
4266 mode-name "Custom")
4267 (use-local-map custom-mode-map)
4268 (easy-menu-add Custom-mode-menu)
4269 (make-local-variable 'custom-options)
4270 (make-local-variable 'custom-local-buffer)
4271 (make-local-variable 'widget-documentation-face)
4272 (setq widget-documentation-face 'custom-documentation-face)
4273 (make-local-variable 'widget-button-face)
4274 (setq widget-button-face 'custom-button-face)
4275 (set (make-local-variable 'widget-button-pressed-face)
4276 'custom-button-pressed-face)
4277 (set (make-local-variable 'widget-mouse-face)
4278 'custom-button-pressed-face) ; buttons `depress' when moused
4279 ;; When possible, use relief for buttons, not bracketing. This test
4280 ;; may not be optimal.
4281 (when custom-raised-buttons
4282 (set (make-local-variable 'widget-push-button-prefix) "")
4283 (set (make-local-variable 'widget-push-button-suffix) "")
4284 (set (make-local-variable 'widget-link-prefix) "")
4285 (set (make-local-variable 'widget-link-suffix) ""))
4286 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
4287 (run-hooks 'custom-mode-hook))
4289 (put 'custom-mode 'mode-class 'special)
4291 (add-to-list
4292 'debug-ignored-errors
4293 "^No user options have changed defaults in recent Emacs versions$")
4295 ;;; The End.
4297 (provide 'cus-edit)
4299 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4300 ;;; cus-edit.el ends here