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