(python-open-block-statement-p): Fix
[emacs.git] / lisp / cus-edit.el
blob5caeb78265e826fb0c341bb7556b04810e5d8dd5
1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
2 ;;
3 ;; Copyright (C) 1996,97,1999,2000,01,02,03,2004 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 editing-basics nil
290 "Most basic editing facilities."
291 :group 'editing)
293 (defgroup display nil
294 "How characters are displayed in buffers."
295 :group 'environment)
297 (defgroup execute nil
298 "Executing external commands."
299 :group 'processes)
301 (defgroup installation nil
302 "The Emacs installation."
303 :group 'environment)
305 (defgroup dired nil
306 "Directory editing."
307 :group 'environment)
309 (defgroup limits nil
310 "Internal Emacs limits."
311 :group 'internal)
313 (defgroup debug nil
314 "Debugging Emacs itself."
315 :group 'development)
317 (defgroup minibuffer nil
318 "Controling the behaviour of the minibuffer."
319 :link '(custom-manual "(emacs)Minibuffer")
320 :group 'environment)
322 (defgroup keyboard nil
323 "Input from the keyboard."
324 :group 'environment)
326 (defgroup mouse nil
327 "Input from the mouse."
328 :group 'environment)
330 (defgroup menu nil
331 "Input from the menus."
332 :group 'environment)
334 (defgroup auto-save nil
335 "Preventing accidential loss of data."
336 :group 'files)
338 (defgroup processes-basics nil
339 "Basic stuff dealing with processes."
340 :group 'processes)
342 (defgroup mule nil
343 "MULE Emacs internationalization."
344 :group 'i18n)
346 (defgroup windows nil
347 "Windows within a frame."
348 :link '(custom-manual "(emacs)Windows")
349 :group 'environment)
351 ;;; Utilities.
353 (defun custom-quote (sexp)
354 "Quote SEXP iff it is not self quoting."
355 (if (or (memq sexp '(t nil))
356 (keywordp sexp)
357 (and (listp sexp)
358 (memq (car sexp) '(lambda)))
359 (stringp sexp)
360 (numberp sexp)
361 (vectorp sexp)
362 ;;; (and (fboundp 'characterp)
363 ;;; (characterp sexp))
365 sexp
366 (list 'quote sexp)))
368 (defun custom-split-regexp-maybe (regexp)
369 "If REGEXP is a string, split it to a list at `\\|'.
370 You can get the original back with from the result with:
371 (mapconcat 'identity result \"\\|\")
373 IF REGEXP is not a string, return it unchanged."
374 (if (stringp regexp)
375 (let ((start 0)
376 all)
377 (while (string-match "\\\\|" regexp start)
378 (setq all (cons (substring regexp start (match-beginning 0)) all)
379 start (match-end 0)))
380 (nreverse (cons (substring regexp start) all)))
381 regexp))
383 (defun custom-variable-prompt ()
384 "Prompt for a custom variable, defaulting to the variable at point.
385 Return a list suitable for use in `interactive'."
386 (let ((v (variable-at-point))
387 (enable-recursive-minibuffers t)
388 val)
389 (setq val (completing-read
390 (if (and (symbolp v) (custom-variable-p v))
391 (format "Customize option: (default %s) " v)
392 "Customize option: ")
393 obarray 'custom-variable-p t))
394 (list (if (equal val "")
395 (if (symbolp v) v nil)
396 (intern val)))))
398 (defun custom-menu-filter (menu widget)
399 "Convert MENU to the form used by `widget-choose'.
400 MENU should be in the same format as `custom-variable-menu'.
401 WIDGET is the widget to apply the filter entries of MENU on."
402 (let ((result nil)
403 current name action filter)
404 (while menu
405 (setq current (car menu)
406 name (nth 0 current)
407 action (nth 1 current)
408 filter (nth 2 current)
409 menu (cdr menu))
410 (if (or (null filter) (funcall filter widget))
411 (push (cons name action) result)
412 (push name result)))
413 (nreverse result)))
415 ;;; Unlispify.
417 (defvar custom-prefix-list nil
418 "List of prefixes that should be ignored by `custom-unlispify'.")
420 (defcustom custom-unlispify-menu-entries t
421 "Display menu entries as words instead of symbols if non nil."
422 :group 'custom-menu
423 :type 'boolean)
425 (defcustom custom-unlispify-remove-prefixes nil
426 "Non-nil means remove group prefixes from option names in buffer."
427 :group 'custom-menu
428 :group 'custom-buffer
429 :type 'boolean)
431 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
432 "Convert SYMBOL into a menu entry."
433 (cond ((not custom-unlispify-menu-entries)
434 (symbol-name symbol))
435 ((get symbol 'custom-tag)
436 (if no-suffix
437 (get symbol 'custom-tag)
438 (concat (get symbol 'custom-tag) "...")))
440 (with-current-buffer (get-buffer-create " *Custom-Work*")
441 (erase-buffer)
442 (princ symbol (current-buffer))
443 (goto-char (point-min))
444 ;; FIXME: Boolean variables are not predicates, so they shouldn't
445 ;; end with `-p'. -stef
446 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
447 ;; (re-search-forward "-p\\'" nil t))
448 ;; (replace-match "" t t)
449 ;; (goto-char (point-min)))
450 (if custom-unlispify-remove-prefixes
451 (let ((prefixes custom-prefix-list)
452 prefix)
453 (while prefixes
454 (setq prefix (car prefixes))
455 (if (search-forward prefix (+ (point) (length prefix)) t)
456 (progn
457 (setq prefixes nil)
458 (delete-region (point-min) (point)))
459 (setq prefixes (cdr prefixes))))))
460 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
461 (capitalize-region (point-min) (point-max))
462 (unless no-suffix
463 (goto-char (point-max))
464 (insert "..."))
465 (buffer-string)))))
467 (defcustom custom-unlispify-tag-names t
468 "Display tag names as words instead of symbols if non nil."
469 :group 'custom-buffer
470 :type 'boolean)
472 (defun custom-unlispify-tag-name (symbol)
473 "Convert SYMBOL into a menu entry."
474 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
475 (custom-unlispify-menu-entry symbol t)))
477 (defun custom-prefix-add (symbol prefixes)
478 "Add SYMBOL to list of ignored PREFIXES."
479 (cons (or (get symbol 'custom-prefix)
480 (concat (symbol-name symbol) "-"))
481 prefixes))
483 ;;; Guess.
485 (defcustom custom-guess-name-alist
486 '(("-p\\'" boolean)
487 ("-hook\\'" hook)
488 ("-face\\'" face)
489 ("-file\\'" file)
490 ("-function\\'" function)
491 ("-functions\\'" (repeat function))
492 ("-list\\'" (repeat sexp))
493 ("-alist\\'" (repeat (cons sexp sexp))))
494 "Alist of (MATCH TYPE).
496 MATCH should be a regexp matching the name of a symbol, and TYPE should
497 be a widget suitable for editing the value of that symbol. The TYPE
498 of the first entry where MATCH matches the name of the symbol will be
499 used.
501 This is used for guessing the type of variables not declared with
502 customize."
503 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
504 :group 'customize)
506 (defcustom custom-guess-doc-alist
507 '(("\\`\\*?Non-nil " boolean))
508 "Alist of (MATCH TYPE).
510 MATCH should be a regexp matching a documentation string, and TYPE
511 should be a widget suitable for editing the value of a variable with
512 that documentation string. The TYPE of the first entry where MATCH
513 matches the name of the symbol will be used.
515 This is used for guessing the type of variables not declared with
516 customize."
517 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
518 :group 'customize)
520 (defun custom-guess-type (symbol)
521 "Guess a widget suitable for editing the value of SYMBOL.
522 This is done by matching SYMBOL with `custom-guess-name-alist' and
523 if that fails, the doc string with `custom-guess-doc-alist'."
524 (let ((name (symbol-name symbol))
525 (names custom-guess-name-alist)
526 current found)
527 (while names
528 (setq current (car names)
529 names (cdr names))
530 (when (string-match (nth 0 current) name)
531 (setq found (nth 1 current)
532 names nil)))
533 (unless found
534 (let ((doc (documentation-property symbol 'variable-documentation))
535 (docs custom-guess-doc-alist))
536 (when doc
537 (while docs
538 (setq current (car docs)
539 docs (cdr docs))
540 (when (string-match (nth 0 current) doc)
541 (setq found (nth 1 current)
542 docs nil))))))
543 found))
545 ;;; Sorting.
547 (defcustom custom-browse-sort-alphabetically nil
548 "If non-nil, sort members of each customization group alphabetically."
549 :type 'boolean
550 :group 'custom-browse)
552 (defcustom custom-browse-order-groups nil
553 "If non-nil, order group members within each customization group.
554 If `first', order groups before non-groups.
555 If `last', order groups after non-groups."
556 :type '(choice (const first)
557 (const last)
558 (const :tag "none" nil))
559 :group 'custom-browse)
561 (defcustom custom-browse-only-groups nil
562 "If non-nil, show group members only within each customization group."
563 :type 'boolean
564 :group 'custom-browse)
566 (defcustom custom-buffer-sort-alphabetically nil
567 "If non-nil, sort members of each customization group alphabetically."
568 :type 'boolean
569 :group 'custom-buffer)
571 (defcustom custom-buffer-order-groups 'last
572 "If non-nil, order group members within each customization group.
573 If `first', order groups before non-groups.
574 If `last', order groups after non-groups."
575 :type '(choice (const first)
576 (const last)
577 (const :tag "none" nil))
578 :group 'custom-buffer)
580 (defcustom custom-menu-sort-alphabetically nil
581 "If non-nil, sort members of each customization group alphabetically."
582 :type 'boolean
583 :group 'custom-menu)
585 (defcustom custom-menu-order-groups 'first
586 "If non-nil, order group members within each customization group.
587 If `first', order groups before non-groups.
588 If `last', order groups after non-groups."
589 :type '(choice (const first)
590 (const last)
591 (const :tag "none" nil))
592 :group 'custom-menu)
594 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
596 (defun custom-sort-items (items sort-alphabetically order-groups)
597 "Return a sorted copy of ITEMS.
598 ITEMS should be a `custom-group' property.
599 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
600 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
601 groups after non-groups, if nil do not order groups at all."
602 (sort (copy-sequence items)
603 (lambda (a b)
604 (let ((typea (nth 1 a)) (typeb (nth 1 b))
605 (namea (nth 0 a)) (nameb (nth 0 b)))
606 (cond ((not order-groups)
607 ;; Since we don't care about A and B order, maybe sort.
608 (when sort-alphabetically
609 (string-lessp namea nameb)))
610 ((eq typea 'custom-group)
611 ;; If B is also a group, maybe sort. Otherwise, order A and B.
612 (if (eq typeb 'custom-group)
613 (when sort-alphabetically
614 (string-lessp namea nameb))
615 (eq order-groups 'first)))
616 ((eq typeb 'custom-group)
617 ;; Since A cannot be a group, order A and B.
618 (eq order-groups 'last))
619 (sort-alphabetically
620 ;; Since A and B cannot be groups, sort.
621 (string-lessp namea nameb)))))))
623 ;;; Custom Mode Commands.
625 (defvar custom-options nil
626 "Customization widgets in the current buffer.")
628 (defun Custom-set ()
629 "Set changes in all modified options."
630 (interactive)
631 (let ((children custom-options))
632 (mapc (lambda (child)
633 (when (eq (widget-get child :custom-state) 'modified)
634 (widget-apply child :custom-set)))
635 children)))
637 (defun Custom-save ()
638 "Set all modified group members and save them."
639 (interactive)
640 (let ((children custom-options))
641 (mapc (lambda (child)
642 (when (memq (widget-get child :custom-state)
643 '(modified set changed rogue))
644 (widget-apply child :custom-save)))
645 children))
646 (custom-save-all))
648 (defvar custom-reset-menu
649 '(("Current" . Custom-reset-current)
650 ("Saved" . Custom-reset-saved)
651 ("Erase Customization (use standard settings)" . Custom-reset-standard))
652 "Alist of actions for the `Reset' button.
653 The key is a string containing the name of the action, the value is a
654 Lisp function taking the widget as an element which will be called
655 when the action is chosen.")
657 (defun custom-reset (event)
658 "Select item from reset menu."
659 (let* ((completion-ignore-case t)
660 (answer (widget-choose "Reset to"
661 custom-reset-menu
662 event)))
663 (if answer
664 (funcall answer))))
666 (defun Custom-reset-current (&rest ignore)
667 "Reset all modified group members to their current value."
668 (interactive)
669 (let ((children custom-options))
670 (mapc (lambda (widget)
671 (if (memq (widget-get widget :custom-state)
672 '(modified changed))
673 (widget-apply widget :custom-reset-current)))
674 children)))
676 (defun Custom-reset-saved (&rest ignore)
677 "Reset all modified or set group members to their saved value."
678 (interactive)
679 (let ((children custom-options))
680 (mapc (lambda (widget)
681 (if (memq (widget-get widget :custom-state)
682 '(modified set changed rogue))
683 (widget-apply widget :custom-reset-saved)))
684 children)))
686 (defun Custom-reset-standard (&rest ignore)
687 "Erase all customization (either current or saved) for the group members.
688 The immediate result is to restore them to their standard settings.
689 This operation eliminates any saved settings for the group members,
690 making them as if they had never been customized at all."
691 (interactive)
692 (let ((children custom-options))
693 (mapc (lambda (widget)
694 (and (widget-apply widget :custom-standard-value)
695 (if (memq (widget-get widget :custom-state)
696 '(modified set changed saved rogue))
697 (widget-apply widget :custom-reset-standard))))
698 children)))
700 ;;; The Customize Commands
702 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
703 "Prompt for a variable and a value and return them as a list.
704 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
705 prompt for the value. The %s escape in PROMPT-VAL is replaced with
706 the name of the variable.
708 If the variable has a `variable-interactive' property, that is used as if
709 it were the arg to `interactive' (which see) to interactively read the value.
711 If the variable has a `custom-type' property, it must be a widget and the
712 `:prompt-value' property of that widget will be used for reading the value.
714 If optional COMMENT argument is non nil, also prompt for a comment and return
715 it as the third element in the list."
716 (let* ((var (read-variable prompt-var))
717 (minibuffer-help-form '(describe-variable var))
718 (val
719 (let ((prop (get var 'variable-interactive))
720 (type (get var 'custom-type))
721 (prompt (format prompt-val var)))
722 (unless (listp type)
723 (setq type (list type)))
724 (cond (prop
725 ;; Use VAR's `variable-interactive' property
726 ;; as an interactive spec for prompting.
727 (call-interactively (list 'lambda '(arg)
728 (list 'interactive prop)
729 'arg)))
730 (type
731 (widget-prompt-value type
732 prompt
733 (if (boundp var)
734 (symbol-value var))
735 (not (boundp var))))
737 (eval-minibuffer prompt))))))
738 (if comment
739 (list var val
740 (read-string "Comment: " (get var 'variable-comment)))
741 (list var val))))
743 ;;;###autoload
744 (defun customize-set-value (variable value &optional comment)
745 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
747 If VARIABLE has a `variable-interactive' property, that is used as if
748 it were the arg to `interactive' (which see) to interactively read the value.
750 If VARIABLE has a `custom-type' property, it must be a widget and the
751 `:prompt-value' property of that widget will be used for reading the value.
753 If given a prefix (or a COMMENT argument), also prompt for a comment."
754 (interactive (custom-prompt-variable "Set variable: "
755 "Set %s to value: "
756 current-prefix-arg))
758 (cond ((string= comment "")
759 (put variable 'variable-comment nil))
760 (comment
761 (put variable 'variable-comment comment)))
762 (set variable value))
764 ;;;###autoload
765 (defun customize-set-variable (variable value &optional comment)
766 "Set the default for VARIABLE to VALUE, and return VALUE.
767 VALUE is a Lisp object.
769 If VARIABLE has a `custom-set' property, that is used for setting
770 VARIABLE, otherwise `set-default' is used.
772 The `customized-value' property of the VARIABLE will be set to a list
773 with a quoted VALUE as its sole list member.
775 If VARIABLE has a `variable-interactive' property, that is used as if
776 it were the arg to `interactive' (which see) to interactively read the value.
778 If VARIABLE has a `custom-type' property, it must be a widget and the
779 `:prompt-value' property of that widget will be used for reading the value.
781 If given a prefix (or a COMMENT argument), also prompt for a comment."
782 (interactive (custom-prompt-variable "Set variable: "
783 "Set customized value for %s to: "
784 current-prefix-arg))
785 (custom-load-symbol variable)
786 (funcall (or (get variable 'custom-set) 'set-default) variable value)
787 (put variable 'customized-value (list (custom-quote value)))
788 (cond ((string= comment "")
789 (put variable 'variable-comment nil)
790 (put variable 'customized-variable-comment nil))
791 (comment
792 (put variable 'variable-comment comment)
793 (put variable 'customized-variable-comment comment)))
794 value)
796 ;;;###autoload
797 (defun customize-save-variable (variable value &optional comment)
798 "Set the default for VARIABLE to VALUE, and save it for future sessions.
799 Return VALUE.
801 If VARIABLE has a `custom-set' property, that is used for setting
802 VARIABLE, otherwise `set-default' is used.
804 The `customized-value' property of the VARIABLE will be set to a list
805 with a quoted VALUE as its sole list member.
807 If VARIABLE has a `variable-interactive' property, that is used as if
808 it were the arg to `interactive' (which see) to interactively read the value.
810 If VARIABLE has a `custom-type' property, it must be a widget and the
811 `:prompt-value' property of that widget will be used for reading the value.
813 If given a prefix (or a COMMENT argument), also prompt for a comment."
814 (interactive (custom-prompt-variable "Set and save variable: "
815 "Set and save value for %s as: "
816 current-prefix-arg))
817 (funcall (or (get variable 'custom-set) 'set-default) variable value)
818 (put variable 'saved-value (list (custom-quote value)))
819 (custom-push-theme 'theme-value variable 'user 'set (list (custom-quote value)))
820 (cond ((string= comment "")
821 (put variable 'variable-comment nil)
822 (put variable 'saved-variable-comment nil))
823 (comment
824 (put variable 'variable-comment comment)
825 (put variable 'saved-variable-comment comment)))
826 (custom-save-all)
827 value)
829 ;;;###autoload
830 (defun customize ()
831 "Select a customization buffer which you can use to set user options.
832 User options are structured into \"groups\".
833 Initially the top-level group `Emacs' and its immediate subgroups
834 are shown; the contents of those subgroups are initially hidden."
835 (interactive)
836 (customize-group 'emacs))
838 ;;;###autoload
839 (defun customize-mode (mode)
840 "Customize options related to the current major mode.
841 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
842 then prompt for the MODE to customize."
843 (interactive
844 (list
845 (let ((completion-regexp-list '("-mode\\'"))
846 (group (custom-group-of-mode major-mode)))
847 (if (and group (not current-prefix-arg))
848 major-mode
849 (intern
850 (completing-read (if group
851 (format "Major mode (default %s): " major-mode)
852 "Major mode: ")
853 obarray
854 'custom-group-of-mode
855 t nil nil (if group (symbol-name major-mode))))))))
856 (customize-group (custom-group-of-mode mode)))
859 ;;;###autoload
860 (defun customize-group (group)
861 "Customize GROUP, which must be a customization group."
862 (interactive (list (let ((completion-ignore-case t))
863 (completing-read "Customize group: (default emacs) "
864 obarray
865 (lambda (symbol)
866 (or (get symbol 'custom-loads)
867 (get symbol 'custom-group)))
868 t))))
869 (when (stringp group)
870 (if (string-equal "" group)
871 (setq group 'emacs)
872 (setq group (intern group))))
873 (let ((name (format "*Customize Group: %s*"
874 (custom-unlispify-tag-name group))))
875 (if (get-buffer name)
876 (pop-to-buffer name)
877 (custom-buffer-create (list (list group 'custom-group))
878 name
879 (concat " for group "
880 (custom-unlispify-tag-name group))))))
882 ;;;###autoload
883 (defun customize-group-other-window (group)
884 "Customize GROUP, which must be a customization group."
885 (interactive (list (let ((completion-ignore-case t))
886 (completing-read "Customize group: (default emacs) "
887 obarray
888 (lambda (symbol)
889 (or (get symbol 'custom-loads)
890 (get symbol 'custom-group)))
891 t))))
892 (when (stringp group)
893 (if (string-equal "" group)
894 (setq group 'emacs)
895 (setq group (intern group))))
896 (let ((name (format "*Customize Group: %s*"
897 (custom-unlispify-tag-name group))))
898 (if (get-buffer name)
899 (let ((window (selected-window))
900 ;; Copied from `custom-buffer-create-other-window'.
901 (pop-up-windows t)
902 (special-display-buffer-names nil)
903 (special-display-regexps nil)
904 (same-window-buffer-names nil)
905 (same-window-regexps nil))
906 (pop-to-buffer name)
907 (select-window window))
908 (custom-buffer-create-other-window
909 (list (list group 'custom-group))
910 name
911 (concat " for group "
912 (custom-unlispify-tag-name group))))))
914 ;;;###autoload
915 (defalias 'customize-variable 'customize-option)
917 ;;;###autoload
918 (defun customize-option (symbol)
919 "Customize SYMBOL, which must be a user option variable."
920 (interactive (custom-variable-prompt))
921 (custom-buffer-create (list (list symbol 'custom-variable))
922 (format "*Customize Option: %s*"
923 (custom-unlispify-tag-name symbol))))
925 ;;;###autoload
926 (defalias 'customize-variable-other-window 'customize-option-other-window)
928 ;;;###autoload
929 (defun customize-option-other-window (symbol)
930 "Customize SYMBOL, which must be a user option variable.
931 Show the buffer in another window, but don't select it."
932 (interactive (custom-variable-prompt))
933 (custom-buffer-create-other-window
934 (list (list symbol 'custom-variable))
935 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
937 (defvar customize-changed-options-previous-release "20.2"
938 "Version for `customize-changed-options' to refer back to by default.")
940 ;;;###autoload
941 (defun customize-changed-options (since-version)
942 "Customize all user option variables changed in Emacs itself.
943 This includes new user option variables and faces, and new
944 customization groups, as well as older options and faces whose default
945 values have changed since the previous major Emacs release.
947 With argument SINCE-VERSION (a string), customize all user option
948 variables that were added (or their meanings were changed) since that
949 version."
951 (interactive "sCustomize options changed, since version (default all versions): ")
952 (if (equal since-version "")
953 (setq since-version nil)
954 (unless (condition-case nil
955 (numberp (read since-version))
956 (error nil))
957 (signal 'wrong-type-argument (list 'numberp since-version))))
958 (unless since-version
959 (setq since-version customize-changed-options-previous-release))
961 ;; Load the information for versions since since-version. We use
962 ;; custom-load-symbol for this.
963 (put 'custom-versions-load-alist 'custom-loads nil)
964 (dolist (elt custom-versions-load-alist)
965 (if (customize-version-lessp since-version (car elt))
966 (dolist (load (cdr elt))
967 (custom-add-load 'custom-versions-load-alist load))))
968 (custom-load-symbol 'custom-versions-load-alist)
969 (put 'custom-versions-load-alist 'custom-loads nil)
971 (let (found)
972 (mapatoms
973 (lambda (symbol)
974 (let ((version (get symbol 'custom-version)))
975 (if version
976 (when (customize-version-lessp since-version version)
977 (if (or (get symbol 'custom-group)
978 (get symbol 'group-documentation))
979 (push (list symbol 'custom-group) found))
980 (if (custom-variable-p symbol)
981 (push (list symbol 'custom-variable) found))
982 (if (custom-facep symbol)
983 (push (list symbol 'custom-face) found)))))))
984 (if found
985 (custom-buffer-create (custom-sort-items found t 'first)
986 "*Customize Changed Options*")
987 (error "No user option defaults have been changed since Emacs %s"
988 since-version))))
990 (defun customize-version-lessp (version1 version2)
991 ;; Why are the versions strings, and given that they are, why aren't
992 ;; they converted to numbers and compared as such here? -- fx
994 ;; In case someone made a mistake and left out the quotes
995 ;; in the :version value.
996 (if (numberp version2)
997 (setq version2 (prin1-to-string version2)))
998 (let (major1 major2 minor1 minor2)
999 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1000 (setq major1 (read (or (match-string 1 version1)
1001 "0")))
1002 (setq minor1 (read (or (match-string 3 version1)
1003 "0")))
1004 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1005 (setq major2 (read (or (match-string 1 version2)
1006 "0")))
1007 (setq minor2 (read (or (match-string 3 version2)
1008 "0")))
1009 (or (< major1 major2)
1010 (and (= major1 major2)
1011 (< minor1 minor2)))))
1013 ;;;###autoload
1014 (defun customize-face (&optional face)
1015 "Customize FACE, which should be a face name or nil.
1016 If FACE is nil, customize all faces.
1018 Interactively, when point is on text which has a face specified,
1019 suggest to customize that face, if it's customizable."
1020 (interactive
1021 (list (read-face-name "Customize face" "all faces" t)))
1022 (if (member face '(nil ""))
1023 (setq face (face-list)))
1024 (if (and (listp face) (null (cdr face)))
1025 (setq face (car face)))
1026 (if (listp face)
1027 (custom-buffer-create (custom-sort-items
1028 (mapcar (lambda (s)
1029 (list s 'custom-face))
1030 face)
1031 t nil)
1032 "*Customize Faces*")
1033 (unless (facep face)
1034 (error "Invalid face %S" face))
1035 (custom-buffer-create (list (list face 'custom-face))
1036 (format "*Customize Face: %s*"
1037 (custom-unlispify-tag-name face)))))
1039 ;;;###autoload
1040 (defun customize-face-other-window (&optional face)
1041 "Show customization buffer for face FACE in other window.
1043 Interactively, when point is on text which has a face specified,
1044 suggest to customize that face, if it's customizable."
1045 (interactive
1046 (list (read-face-name "Customize face" "all faces" t)))
1047 (if (member face '(nil ""))
1048 (setq face (face-list)))
1049 (if (and (listp face) (null (cdr face)))
1050 (setq face (car face)))
1051 (if (listp face)
1052 (custom-buffer-create-other-window
1053 (custom-sort-items
1054 (mapcar (lambda (s)
1055 (list s 'custom-face))
1056 face)
1057 t nil)
1058 "*Customize Faces*")
1059 (unless (facep face)
1060 (error "Invalid face %S" face))
1061 (custom-buffer-create-other-window
1062 (list (list face 'custom-face))
1063 (format "*Customize Face: %s*"
1064 (custom-unlispify-tag-name face)))))
1066 ;;;###autoload
1067 (defun customize-customized ()
1068 "Customize all user options set since the last save in this session."
1069 (interactive)
1070 (let ((found nil))
1071 (mapatoms (lambda (symbol)
1072 (and (or (get symbol 'customized-face)
1073 (get symbol 'customized-face-comment))
1074 (custom-facep symbol)
1075 (push (list symbol 'custom-face) found))
1076 (and (or (get symbol 'customized-value)
1077 (get symbol 'customized-variable-comment))
1078 (boundp symbol)
1079 (push (list symbol 'custom-variable) found))))
1080 (if (not found)
1081 (error "No customized user options")
1082 (custom-buffer-create (custom-sort-items found t nil)
1083 "*Customize Customized*"))))
1085 ;;;###autoload
1086 (defun customize-rogue ()
1087 "Customize all user variable modified outside customize."
1088 (interactive)
1089 (let ((found nil))
1090 (mapatoms (lambda (symbol)
1091 (let ((cval (or (get symbol 'customized-value)
1092 (get symbol 'saved-value)
1093 (get symbol 'standard-value))))
1094 (when (and cval ;Declared with defcustom.
1095 (default-boundp symbol) ;Has a value.
1096 (not (equal (eval (car cval))
1097 ;; Which does not match customize.
1098 (default-value symbol))))
1099 (push (list symbol 'custom-variable) found)))))
1100 (if (not found)
1101 (error "No rogue user options")
1102 (custom-buffer-create (custom-sort-items found t nil)
1103 "*Customize Rogue*"))))
1104 ;;;###autoload
1105 (defun customize-saved ()
1106 "Customize all already saved user options."
1107 (interactive)
1108 (let ((found nil))
1109 (mapatoms (lambda (symbol)
1110 (and (or (get symbol 'saved-face)
1111 (get symbol 'saved-face-comment))
1112 (custom-facep symbol)
1113 (push (list symbol 'custom-face) found))
1114 (and (or (get symbol 'saved-value)
1115 (get symbol 'saved-variable-comment))
1116 (boundp symbol)
1117 (push (list symbol 'custom-variable) found))))
1118 (if (not found )
1119 (error "No saved user options")
1120 (custom-buffer-create (custom-sort-items found t nil)
1121 "*Customize Saved*"))))
1123 ;;;###autoload
1124 (defun customize-apropos (regexp &optional all)
1125 "Customize all user options matching REGEXP.
1126 If ALL is `options', include only options.
1127 If ALL is `faces', include only faces.
1128 If ALL is `groups', include only groups.
1129 If ALL is t (interactively, with prefix arg), include options which are not
1130 user-settable, as well as faces and groups."
1131 (interactive "sCustomize regexp: \nP")
1132 (let ((found nil))
1133 (mapatoms (lambda (symbol)
1134 (when (string-match regexp (symbol-name symbol))
1135 (when (and (not (memq all '(faces options)))
1136 (get symbol 'custom-group))
1137 (push (list symbol 'custom-group) found))
1138 (when (and (not (memq all '(options groups)))
1139 (custom-facep symbol))
1140 (push (list symbol 'custom-face) found))
1141 (when (and (not (memq all '(groups faces)))
1142 (boundp symbol)
1143 (or (get symbol 'saved-value)
1144 (custom-variable-p symbol)
1145 (if (memq all '(nil options))
1146 (user-variable-p symbol)
1147 (get symbol 'variable-documentation))))
1148 (push (list symbol 'custom-variable) found)))))
1149 (if (not found)
1150 (error "No matches")
1151 (custom-buffer-create (custom-sort-items found t
1152 custom-buffer-order-groups)
1153 "*Customize Apropos*"))))
1155 ;;;###autoload
1156 (defun customize-apropos-options (regexp &optional arg)
1157 "Customize all user options matching REGEXP.
1158 With prefix arg, include options which are not user-settable."
1159 (interactive "sCustomize regexp: \nP")
1160 (customize-apropos regexp (or arg 'options)))
1162 ;;;###autoload
1163 (defun customize-apropos-faces (regexp)
1164 "Customize all user faces matching REGEXP."
1165 (interactive "sCustomize regexp: \n")
1166 (customize-apropos regexp 'faces))
1168 ;;;###autoload
1169 (defun customize-apropos-groups (regexp)
1170 "Customize all user groups matching REGEXP."
1171 (interactive "sCustomize regexp: \n")
1172 (customize-apropos regexp 'groups))
1174 ;;; Buffer.
1176 (defcustom custom-buffer-style 'links
1177 "Control the presentation style for customization buffers.
1178 The value should be a symbol, one of:
1180 brackets: groups nest within each other with big horizontal brackets.
1181 links: groups have links to subgroups."
1182 :type '(radio (const brackets)
1183 (const links))
1184 :group 'custom-buffer)
1186 ;; If we pass BUFFER to `bury-buffer', the buffer isn't removed from
1187 ;; the window.
1188 (defun custom-bury-buffer (buffer)
1189 (with-current-buffer buffer
1190 (bury-buffer)))
1192 (defcustom custom-buffer-done-function 'custom-bury-buffer
1193 "*Function called to remove a Custom buffer when the user is done with it.
1194 Called with one argument, the buffer to remove."
1195 :type '(choice (function-item :tag "Bury buffer" custom-bury-buffer)
1196 (function-item :tag "Kill buffer" kill-buffer)
1197 (function :tag "Other"))
1198 :version "21.1"
1199 :group 'custom-buffer)
1201 (defcustom custom-buffer-indent 3
1202 "Number of spaces to indent nested groups."
1203 :type 'integer
1204 :group 'custom-buffer)
1206 (defun custom-get-fresh-buffer (name)
1207 "Get a fresh new buffer with name NAME.
1208 If the buffer already exist, clean it up to be like new.
1209 Beware: it's not quite like new. Good enough for custom, but maybe
1210 not for everybody."
1211 ;; To be more complete, we should also kill all permanent-local variables,
1212 ;; but it's not needed for custom.
1213 (let ((buf (get-buffer name)))
1214 (when (and buf (buffer-local-value 'buffer-file-name buf))
1215 ;; This will check if the file is not saved.
1216 (kill-buffer buf)
1217 (setq buf nil))
1218 (if (null buf)
1219 (get-buffer-create name)
1220 (with-current-buffer buf
1221 (kill-all-local-variables)
1222 (run-hooks 'kill-buffer-hook)
1223 ;; Delete overlays before erasing the buffer so the overlay hooks
1224 ;; don't get run spuriously when we erase the buffer.
1225 (let ((ols (overlay-lists)))
1226 (dolist (ol (nconc (car ols) (cdr ols)))
1227 (delete-overlay ol)))
1228 (erase-buffer)
1229 buf))))
1231 ;;;###autoload
1232 (defun custom-buffer-create (options &optional name description)
1233 "Create a buffer containing OPTIONS.
1234 Optional NAME is the name of the buffer.
1235 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1236 SYMBOL is a customization option, and WIDGET is a widget for editing
1237 that option."
1238 (pop-to-buffer (custom-get-fresh-buffer (or name "*Customization*")))
1239 (custom-buffer-create-internal options description))
1241 ;;;###autoload
1242 (defun custom-buffer-create-other-window (options &optional name description)
1243 "Create a buffer containing OPTIONS.
1244 Optional NAME is the name of the buffer.
1245 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1246 SYMBOL is a customization option, and WIDGET is a widget for editing
1247 that option."
1248 (unless name (setq name "*Customization*"))
1249 (let ((window (selected-window))
1250 (pop-up-windows t)
1251 (special-display-buffer-names nil)
1252 (special-display-regexps nil)
1253 (same-window-buffer-names nil)
1254 (same-window-regexps nil))
1255 (pop-to-buffer (custom-get-fresh-buffer name))
1256 (custom-buffer-create-internal options description)
1257 (select-window window)))
1259 (defcustom custom-reset-button-menu nil
1260 "If non-nil, only show a single reset button in customize buffers.
1261 This button will have a menu with all three reset operations."
1262 :type 'boolean
1263 :group 'custom-buffer)
1265 (defcustom custom-buffer-verbose-help t
1266 "If non-nil, include explanatory text in the customization buffer."
1267 :type 'boolean
1268 :group 'custom-buffer)
1270 (defun Custom-buffer-done (&rest ignore)
1271 "Remove current buffer by calling `custom-buffer-done-function'."
1272 (interactive)
1273 (funcall custom-buffer-done-function (current-buffer)))
1275 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1276 '(("unspecified" . unspecified))))
1277 "If non-nil, indicate active buttons in a `raised-button' style.
1278 Otherwise use brackets."
1279 :type 'boolean
1280 :version "21.1"
1281 :group 'custom-buffer)
1283 (defun custom-buffer-create-internal (options &optional description)
1284 (message "Creating customization buffer...")
1285 (custom-mode)
1286 (if custom-buffer-verbose-help
1287 (progn
1288 (widget-insert "This is a customization buffer")
1289 (if description
1290 (widget-insert description))
1291 (widget-insert (format ".
1292 %s show active fields; type RET or click mouse-1
1293 on an active field to invoke its action. Editing an option value
1294 changes the text in the buffer; invoke the State button and
1295 choose the Set operation to set the option value.
1296 Invoke " (if custom-raised-buttons
1297 "`Raised' buttons"
1298 "Square brackets")))
1299 (widget-create 'info-link
1300 :tag "Help"
1301 :help-echo "Read the online help."
1302 "(emacs)Easy Customization")
1303 (widget-insert " for more information.\n\n")
1304 (message "Creating customization buttons...")
1305 (widget-insert "Operate on everything in this buffer:\n "))
1306 (widget-insert " "))
1307 (widget-create 'push-button
1308 :tag "Set for Current Session"
1309 :help-echo "\
1310 Make your editing in this buffer take effect for this session."
1311 :action (lambda (widget &optional event)
1312 (Custom-set)))
1313 (widget-insert " ")
1314 (widget-create 'push-button
1315 :tag "Save for Future Sessions"
1316 :help-echo "\
1317 Make your editing in this buffer take effect for future Emacs sessions."
1318 :action (lambda (widget &optional event)
1319 (Custom-save)))
1320 (if custom-reset-button-menu
1321 (progn
1322 (widget-insert " ")
1323 (widget-create 'push-button
1324 :tag "Reset"
1325 :help-echo "Show a menu with reset operations."
1326 :mouse-down-action (lambda (&rest junk) t)
1327 :action (lambda (widget &optional event)
1328 (custom-reset event))))
1329 (widget-insert "\n ")
1330 (widget-create 'push-button
1331 :tag "Reset"
1332 :help-echo "\
1333 Reset all edited text in this buffer to reflect current values."
1334 :action 'Custom-reset-current)
1335 (widget-insert " ")
1336 (widget-create 'push-button
1337 :tag "Reset to Saved"
1338 :help-echo "\
1339 Reset all values in this buffer to their saved settings."
1340 :action 'Custom-reset-saved)
1341 (widget-insert " ")
1342 (widget-create 'push-button
1343 :tag "Erase Customization"
1344 :help-echo "\
1345 Un-customize all values in this buffer. They get their standard settings."
1346 :action 'Custom-reset-standard))
1347 (if (not custom-buffer-verbose-help)
1348 (progn
1349 (widget-insert " ")
1350 (widget-create 'info-link
1351 :tag "Help"
1352 :help-echo "Read the online help."
1353 "(emacs)Easy Customization")))
1354 (widget-insert " ")
1355 (widget-create 'push-button
1356 :tag "Finish"
1357 :help-echo
1358 (lambda (&rest ignore)
1359 (cond
1360 ((eq custom-buffer-done-function
1361 'custom-bury-buffer)
1362 "Bury this buffer")
1363 ((eq custom-buffer-done-function 'kill-buffer)
1364 "Kill this buffer")
1365 (t "Finish with this buffer")))
1366 :action #'Custom-buffer-done)
1367 (widget-insert "\n\n")
1368 (message "Creating customization items...")
1369 (buffer-disable-undo)
1370 (setq custom-options
1371 (if (= (length options) 1)
1372 (mapcar (lambda (entry)
1373 (widget-create (nth 1 entry)
1374 :documentation-shown t
1375 :custom-state 'unknown
1376 :tag (custom-unlispify-tag-name
1377 (nth 0 entry))
1378 :value (nth 0 entry)))
1379 options)
1380 (let ((count 0)
1381 (length (length options)))
1382 (mapcar (lambda (entry)
1383 (prog2
1384 (message "Creating customization items ...%2d%%"
1385 (/ (* 100.0 count) length))
1386 (widget-create (nth 1 entry)
1387 :tag (custom-unlispify-tag-name
1388 (nth 0 entry))
1389 :value (nth 0 entry))
1390 (setq count (1+ count))
1391 (unless (eq (preceding-char) ?\n)
1392 (widget-insert "\n"))
1393 (widget-insert "\n")))
1394 options))))
1395 (unless (eq (preceding-char) ?\n)
1396 (widget-insert "\n"))
1397 (message "Creating customization items ...done")
1398 (unless (eq custom-buffer-style 'tree)
1399 (mapc 'custom-magic-reset custom-options))
1400 (message "Creating customization setup...")
1401 (widget-setup)
1402 (buffer-enable-undo)
1403 (goto-char (point-min))
1404 (message "Creating customization buffer...done"))
1406 ;;; The Tree Browser.
1408 ;;;###autoload
1409 (defun customize-browse (&optional group)
1410 "Create a tree browser for the customize hierarchy."
1411 (interactive)
1412 (unless group
1413 (setq group 'emacs))
1414 (let ((name "*Customize Browser*"))
1415 (pop-to-buffer (custom-get-fresh-buffer name)))
1416 (custom-mode)
1417 (widget-insert "\
1418 Square brackets show active fields; type RET or click mouse-1
1419 on an active field to invoke its action.
1420 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1421 (if custom-browse-only-groups
1422 (widget-insert "\
1423 Invoke the [Group] button below to edit that item in another window.\n\n")
1424 (widget-insert "Invoke the ")
1425 (widget-create 'item
1426 :format "%t"
1427 :tag "[Group]"
1428 :tag-glyph "folder")
1429 (widget-insert ", ")
1430 (widget-create 'item
1431 :format "%t"
1432 :tag "[Face]"
1433 :tag-glyph "face")
1434 (widget-insert ", and ")
1435 (widget-create 'item
1436 :format "%t"
1437 :tag "[Option]"
1438 :tag-glyph "option")
1439 (widget-insert " buttons below to edit that
1440 item in another window.\n\n"))
1441 (let ((custom-buffer-style 'tree))
1442 (widget-create 'custom-group
1443 :custom-last t
1444 :custom-state 'unknown
1445 :tag (custom-unlispify-tag-name group)
1446 :value group))
1447 (widget-setup)
1448 (goto-char (point-min)))
1450 (define-widget 'custom-browse-visibility 'item
1451 "Control visibility of items in the customize tree browser."
1452 :format "%[[%t]%]"
1453 :action 'custom-browse-visibility-action)
1455 (defun custom-browse-visibility-action (widget &rest ignore)
1456 (let ((custom-buffer-style 'tree))
1457 (custom-toggle-parent widget)))
1459 (define-widget 'custom-browse-group-tag 'push-button
1460 "Show parent in other window when activated."
1461 :tag "Group"
1462 :tag-glyph "folder"
1463 :action 'custom-browse-group-tag-action)
1465 (defun custom-browse-group-tag-action (widget &rest ignore)
1466 (let ((parent (widget-get widget :parent)))
1467 (customize-group-other-window (widget-value parent))))
1469 (define-widget 'custom-browse-variable-tag 'push-button
1470 "Show parent in other window when activated."
1471 :tag "Option"
1472 :tag-glyph "option"
1473 :action 'custom-browse-variable-tag-action)
1475 (defun custom-browse-variable-tag-action (widget &rest ignore)
1476 (let ((parent (widget-get widget :parent)))
1477 (customize-variable-other-window (widget-value parent))))
1479 (define-widget 'custom-browse-face-tag 'push-button
1480 "Show parent in other window when activated."
1481 :tag "Face"
1482 :tag-glyph "face"
1483 :action 'custom-browse-face-tag-action)
1485 (defun custom-browse-face-tag-action (widget &rest ignore)
1486 (let ((parent (widget-get widget :parent)))
1487 (customize-face-other-window (widget-value parent))))
1489 (defconst custom-browse-alist '((" " "space")
1490 (" | " "vertical")
1491 ("-\\ " "top")
1492 (" |-" "middle")
1493 (" `-" "bottom")))
1495 (defun custom-browse-insert-prefix (prefix)
1496 "Insert PREFIX. On XEmacs convert it to line graphics."
1497 ;; Fixme: do graphics.
1498 (if nil ; (string-match "XEmacs" emacs-version)
1499 (progn
1500 (insert "*")
1501 (while (not (string-equal prefix ""))
1502 (let ((entry (substring prefix 0 3)))
1503 (setq prefix (substring prefix 3))
1504 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1505 (name (nth 1 (assoc entry custom-browse-alist))))
1506 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1507 (overlay-put overlay 'start-open t)
1508 (overlay-put overlay 'end-open t)))))
1509 (insert prefix)))
1511 ;;; Modification of Basic Widgets.
1513 ;; We add extra properties to the basic widgets needed here. This is
1514 ;; fine, as long as we are careful to stay within out own namespace.
1516 ;; We want simple widgets to be displayed by default, but complex
1517 ;; widgets to be hidden.
1519 (widget-put (get 'item 'widget-type) :custom-show t)
1520 (widget-put (get 'editable-field 'widget-type)
1521 :custom-show (lambda (widget value)
1522 (let ((pp (pp-to-string value)))
1523 (cond ((string-match "\n" pp)
1524 nil)
1525 ((> (length pp) 40)
1526 nil)
1527 (t t)))))
1528 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1530 ;;; The `custom-manual' Widget.
1532 (define-widget 'custom-manual 'info-link
1533 "Link to the manual entry for this customization option."
1534 :help-echo "Read the manual entry for this option."
1535 :tag "Manual")
1537 ;;; The `custom-magic' Widget.
1539 (defgroup custom-magic-faces nil
1540 "Faces used by the magic button."
1541 :group 'custom-faces
1542 :group 'custom-buffer)
1544 (defface custom-invalid-face '((((class color))
1545 (:foreground "yellow" :background "red"))
1547 (:weight bold :slant italic :underline t)))
1548 "Face used when the customize item is invalid."
1549 :group 'custom-magic-faces)
1551 (defface custom-rogue-face '((((class color))
1552 (:foreground "pink" :background "black"))
1554 (:underline t)))
1555 "Face used when the customize item is not defined for customization."
1556 :group 'custom-magic-faces)
1558 (defface custom-modified-face '((((class color))
1559 (:foreground "white" :background "blue"))
1561 (:slant italic :bold)))
1562 "Face used when the customize item has been modified."
1563 :group 'custom-magic-faces)
1565 (defface custom-set-face '((((class color))
1566 (:foreground "blue" :background "white"))
1568 (:slant italic)))
1569 "Face used when the customize item has been set."
1570 :group 'custom-magic-faces)
1572 (defface custom-changed-face '((((class color))
1573 (:foreground "white" :background "blue"))
1575 (:slant italic)))
1576 "Face used when the customize item has been changed."
1577 :group 'custom-magic-faces)
1579 (defface custom-saved-face '((t (:underline t)))
1580 "Face used when the customize item has been saved."
1581 :group 'custom-magic-faces)
1583 (defconst custom-magic-alist '((nil "#" underline "\
1584 uninitialized, you should not see this.")
1585 (unknown "?" italic "\
1586 unknown, you should not see this.")
1587 (hidden "-" default "\
1588 hidden, invoke \"Show\" in the previous line to show." "\
1589 group now hidden, invoke \"Show\", above, to show contents.")
1590 (invalid "x" custom-invalid-face "\
1591 the value displayed for this %c is invalid and cannot be set.")
1592 (modified "*" custom-modified-face "\
1593 you have edited the value as text, but you have not set the %c." "\
1594 you have edited something in this group, but not set it.")
1595 (set "+" custom-set-face "\
1596 you have set this %c, but not saved it for future sessions." "\
1597 something in this group has been set, but not saved.")
1598 (changed ":" custom-changed-face "\
1599 this %c has been changed outside the customize buffer." "\
1600 something in this group has been changed outside customize.")
1601 (saved "!" custom-saved-face "\
1602 this %c has been set and saved." "\
1603 something in this group has been set and saved.")
1604 (rogue "@" custom-rogue-face "\
1605 this %c has not been changed with customize." "\
1606 something in this group is not prepared for customization.")
1607 (standard " " nil "\
1608 this %c is unchanged from its standard setting." "\
1609 visible group members are all at standard settings."))
1610 "Alist of customize option states.
1611 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1613 STATE is one of the following symbols:
1615 `nil'
1616 For internal use, should never occur.
1617 `unknown'
1618 For internal use, should never occur.
1619 `hidden'
1620 This item is not being displayed.
1621 `invalid'
1622 This item is modified, but has an invalid form.
1623 `modified'
1624 This item is modified, and has a valid form.
1625 `set'
1626 This item has been set but not saved.
1627 `changed'
1628 The current value of this item has been changed temporarily.
1629 `saved'
1630 This item is marked for saving.
1631 `rogue'
1632 This item has no customization information.
1633 `standard'
1634 This item is unchanged from the standard setting.
1636 MAGIC is a string used to present that state.
1638 FACE is a face used to present the state.
1640 ITEM-DESC is a string describing the state for options.
1642 GROUP-DESC is a string describing the state for groups. If this is
1643 left out, ITEM-DESC will be used.
1645 The string %c in either description will be replaced with the
1646 category of the item. These are `group'. `option', and `face'.
1648 The list should be sorted most significant first.")
1650 (defcustom custom-magic-show 'long
1651 "If non-nil, show textual description of the state.
1652 If `long', show a full-line description, not just one word."
1653 :type '(choice (const :tag "no" nil)
1654 (const long)
1655 (other :tag "short" short))
1656 :group 'custom-buffer)
1658 (defcustom custom-magic-show-hidden '(option face)
1659 "Control whether the State button is shown for hidden items.
1660 The value should be a list with the custom categories where the State
1661 button should be visible. Possible categories are `group', `option',
1662 and `face'."
1663 :type '(set (const group) (const option) (const face))
1664 :group 'custom-buffer)
1666 (defcustom custom-magic-show-button nil
1667 "Show a \"magic\" button indicating the state of each customization option."
1668 :type 'boolean
1669 :group 'custom-buffer)
1671 (define-widget 'custom-magic 'default
1672 "Show and manipulate state for a customization option."
1673 :format "%v"
1674 :action 'widget-parent-action
1675 :notify 'ignore
1676 :value-get 'ignore
1677 :value-create 'custom-magic-value-create
1678 :value-delete 'widget-children-value-delete)
1680 (defun widget-magic-mouse-down-action (widget &optional event)
1681 ;; Non-nil unless hidden.
1682 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1683 :custom-state)
1684 'hidden)))
1686 (defun custom-magic-value-create (widget)
1687 "Create compact status report for WIDGET."
1688 (let* ((parent (widget-get widget :parent))
1689 (state (widget-get parent :custom-state))
1690 (hidden (eq state 'hidden))
1691 (entry (assq state custom-magic-alist))
1692 (magic (nth 1 entry))
1693 (face (nth 2 entry))
1694 (category (widget-get parent :custom-category))
1695 (text (or (and (eq category 'group)
1696 (nth 4 entry))
1697 (nth 3 entry)))
1698 (form (widget-get parent :custom-form))
1699 children)
1700 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1701 (setq text (concat (match-string 1 text)
1702 (symbol-name category)
1703 (match-string 2 text))))
1704 (when (and custom-magic-show
1705 (or (not hidden)
1706 (memq category custom-magic-show-hidden)))
1707 (insert " ")
1708 (when (and (eq category 'group)
1709 (not (and (eq custom-buffer-style 'links)
1710 (> (widget-get parent :custom-level) 1))))
1711 (insert-char ?\ (* custom-buffer-indent
1712 (widget-get parent :custom-level))))
1713 (push (widget-create-child-and-convert
1714 widget 'choice-item
1715 :help-echo "Change the state of this item."
1716 :format (if hidden "%t" "%[%t%]")
1717 :button-prefix 'widget-push-button-prefix
1718 :button-suffix 'widget-push-button-suffix
1719 :mouse-down-action 'widget-magic-mouse-down-action
1720 :tag "State")
1721 children)
1722 (insert ": ")
1723 (let ((start (point)))
1724 (if (eq custom-magic-show 'long)
1725 (insert text)
1726 (insert (symbol-name state)))
1727 (cond ((eq form 'lisp)
1728 (insert " (lisp)"))
1729 ((eq form 'mismatch)
1730 (insert " (mismatch)")))
1731 (put-text-property start (point) 'face 'custom-state-face))
1732 (insert "\n"))
1733 (when (and (eq category 'group)
1734 (not (and (eq custom-buffer-style 'links)
1735 (> (widget-get parent :custom-level) 1))))
1736 (insert-char ?\ (* custom-buffer-indent
1737 (widget-get parent :custom-level))))
1738 (when custom-magic-show-button
1739 (when custom-magic-show
1740 (let ((indent (widget-get parent :indent)))
1741 (when indent
1742 (insert-char ? indent))))
1743 (push (widget-create-child-and-convert
1744 widget 'choice-item
1745 :mouse-down-action 'widget-magic-mouse-down-action
1746 :button-face face
1747 :button-prefix ""
1748 :button-suffix ""
1749 :help-echo "Change the state."
1750 :format (if hidden "%t" "%[%t%]")
1751 :tag (if (memq form '(lisp mismatch))
1752 (concat "(" magic ")")
1753 (concat "[" magic "]")))
1754 children)
1755 (insert " "))
1756 (widget-put widget :children children)))
1758 (defun custom-magic-reset (widget)
1759 "Redraw the :custom-magic property of WIDGET."
1760 (let ((magic (widget-get widget :custom-magic)))
1761 (widget-value-set magic (widget-value magic))))
1763 ;;; The `custom' Widget.
1765 (defface custom-button-face
1766 '((((type x w32 mac) (class color)) ; Like default modeline
1767 (:box (:line-width 2 :style released-button)
1768 :background "lightgrey" :foreground "black"))
1770 nil))
1771 "Face used for buttons in customization buffers."
1772 :version "21.1"
1773 :group 'custom-faces)
1775 (defface custom-button-pressed-face
1776 '((((type x w32 mac) (class color))
1777 (:box (:line-width 2 :style pressed-button)
1778 :background "lightgrey" :foreground "black"))
1780 (:inverse-video t)))
1781 "Face used for buttons in customization buffers."
1782 :version "21.1"
1783 :group 'custom-faces)
1785 (defface custom-documentation-face nil
1786 "Face used for documentation strings in customization buffers."
1787 :group 'custom-faces)
1789 (defface custom-state-face '((((class color)
1790 (background dark))
1791 (:foreground "lime green"))
1792 (((class color)
1793 (background light))
1794 (:foreground "dark green"))
1795 (t nil))
1796 "Face used for State descriptions in the customize buffer."
1797 :group 'custom-faces)
1799 (define-widget 'custom 'default
1800 "Customize a user option."
1801 :format "%v"
1802 :convert-widget 'custom-convert-widget
1803 :notify 'custom-notify
1804 :custom-prefix ""
1805 :custom-level 1
1806 :custom-state 'hidden
1807 :documentation-property 'widget-subclass-responsibility
1808 :value-create 'widget-subclass-responsibility
1809 :value-delete 'widget-children-value-delete
1810 :value-get 'widget-value-value-get
1811 :validate 'widget-children-validate
1812 :match (lambda (widget value) (symbolp value)))
1814 (defun custom-convert-widget (widget)
1815 "Initialize :value and :tag from :args in WIDGET."
1816 (let ((args (widget-get widget :args)))
1817 (when args
1818 (widget-put widget :value (widget-apply widget
1819 :value-to-internal (car args)))
1820 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1821 (widget-put widget :args nil)))
1822 widget)
1824 (defun custom-notify (widget &rest args)
1825 "Keep track of changes."
1826 (let ((state (widget-get widget :custom-state)))
1827 (unless (eq state 'modified)
1828 (unless (memq state '(nil unknown hidden))
1829 (widget-put widget :custom-state 'modified))
1830 (custom-magic-reset widget)
1831 (apply 'widget-default-notify widget args))))
1833 (defun custom-redraw (widget)
1834 "Redraw WIDGET with current settings."
1835 (let ((line (count-lines (point-min) (point)))
1836 (column (current-column))
1837 (pos (point))
1838 (from (marker-position (widget-get widget :from)))
1839 (to (marker-position (widget-get widget :to))))
1840 (save-excursion
1841 (widget-value-set widget (widget-value widget))
1842 (custom-redraw-magic widget))
1843 (when (and (>= pos from) (<= pos to))
1844 (condition-case nil
1845 (progn
1846 (if (> column 0)
1847 (goto-line line)
1848 (goto-line (1+ line)))
1849 (move-to-column column))
1850 (error nil)))))
1852 (defun custom-redraw-magic (widget)
1853 "Redraw WIDGET state with current settings."
1854 (while widget
1855 (let ((magic (widget-get widget :custom-magic)))
1856 (cond (magic
1857 (widget-value-set magic (widget-value magic))
1858 (when (setq widget (widget-get widget :group))
1859 (custom-group-state-update widget)))
1861 (setq widget nil)))))
1862 (widget-setup))
1864 (defun custom-show (widget value)
1865 "Non-nil if WIDGET should be shown with VALUE by default."
1866 (let ((show (widget-get widget :custom-show)))
1867 (cond ((null show)
1868 nil)
1869 ((eq t show)
1872 (funcall show widget value)))))
1874 (defun custom-load-widget (widget)
1875 "Load all dependencies for WIDGET."
1876 (custom-load-symbol (widget-value widget)))
1878 (defun custom-unloaded-symbol-p (symbol)
1879 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
1880 (let ((found nil)
1881 (loads (get symbol 'custom-loads))
1882 load)
1883 (while loads
1884 (setq load (car loads)
1885 loads (cdr loads))
1886 (cond ((symbolp load)
1887 (unless (featurep load)
1888 (setq found t)))
1889 ((assoc load load-history))
1890 ((assoc (locate-library load) load-history)
1891 (message nil))
1893 (setq found t))))
1894 found))
1896 (defun custom-unloaded-widget-p (widget)
1897 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
1898 (custom-unloaded-symbol-p (widget-value widget)))
1900 (defun custom-toggle-hide (widget)
1901 "Toggle visibility of WIDGET."
1902 (custom-load-widget widget)
1903 (let ((state (widget-get widget :custom-state)))
1904 (cond ((memq state '(invalid modified))
1905 (error "There are unset changes"))
1906 ((eq state 'hidden)
1907 (widget-put widget :custom-state 'unknown))
1909 (widget-put widget :documentation-shown nil)
1910 (widget-put widget :custom-state 'hidden)))
1911 (custom-redraw widget)
1912 (widget-setup)))
1914 (defun custom-toggle-parent (widget &rest ignore)
1915 "Toggle visibility of parent of WIDGET."
1916 (custom-toggle-hide (widget-get widget :parent)))
1918 (defun custom-add-see-also (widget &optional prefix)
1919 "Add `See also ...' to WIDGET if there are any links.
1920 Insert PREFIX first if non-nil."
1921 (let* ((symbol (widget-get widget :value))
1922 (links (get symbol 'custom-links))
1923 (many (> (length links) 2))
1924 (buttons (widget-get widget :buttons))
1925 (indent (widget-get widget :indent)))
1926 (when links
1927 (when indent
1928 (insert-char ?\ indent))
1929 (when prefix
1930 (insert prefix))
1931 (insert "See also ")
1932 (while links
1933 (push (widget-create-child-and-convert widget (car links))
1934 buttons)
1935 (setq links (cdr links))
1936 (cond ((null links)
1937 (insert ".\n"))
1938 ((null (cdr links))
1939 (if many
1940 (insert ", and ")
1941 (insert " and ")))
1943 (insert ", "))))
1944 (widget-put widget :buttons buttons))))
1946 (defun custom-add-parent-links (widget &optional initial-string)
1947 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1948 The value if non-nil if any parents were found.
1949 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1950 (let ((name (widget-value widget))
1951 (type (widget-type widget))
1952 (buttons (widget-get widget :buttons))
1953 (start (point))
1954 (parents nil))
1955 (insert (or initial-string "Parent groups:"))
1956 (mapatoms (lambda (symbol)
1957 (let ((entry (assq name (get symbol 'custom-group))))
1958 (when (eq (nth 1 entry) type)
1959 (insert " ")
1960 (push (widget-create-child-and-convert
1961 widget 'custom-group-link
1962 :tag (custom-unlispify-tag-name symbol)
1963 symbol)
1964 buttons)
1965 (setq parents (cons symbol parents))))))
1966 (and (null (get name 'custom-links)) ;No links of its own.
1967 (= (length parents) 1) ;A single parent.
1968 (let* ((links (get (car parents) 'custom-links))
1969 (many (> (length links) 2)))
1970 (when links
1971 (insert "\nParent documentation: ")
1972 (while links
1973 (push (widget-create-child-and-convert widget (car links))
1974 buttons)
1975 (setq links (cdr links))
1976 (cond ((null links)
1977 (insert ".\n"))
1978 ((null (cdr links))
1979 (if many
1980 (insert ", and ")
1981 (insert " and ")))
1983 (insert ", ")))))))
1984 (if parents
1985 (insert "\n")
1986 (delete-region start (point)))
1987 (widget-put widget :buttons buttons)
1988 parents))
1990 ;;; The `custom-comment' Widget.
1992 ;; like the editable field
1993 (defface custom-comment-face '((((class grayscale color)
1994 (background light))
1995 (:background "gray85"))
1996 (((class grayscale color)
1997 (background dark))
1998 (:background "dim gray"))
2000 (:slant italic)))
2001 "Face used for comments on variables or faces"
2002 :version "21.1"
2003 :group 'custom-faces)
2005 ;; like font-lock-comment-face
2006 (defface custom-comment-tag-face
2007 '((((class color) (background dark)) (:foreground "gray80"))
2008 (((class color) (background light)) (:foreground "blue4"))
2009 (((class grayscale) (background light))
2010 (:foreground "DimGray" :weight bold :slant italic))
2011 (((class grayscale) (background dark))
2012 (:foreground "LightGray" :weight bold :slant italic))
2013 (t (:weight bold)))
2014 "Face used for variables or faces comment tags"
2015 :group 'custom-faces)
2017 (define-widget 'custom-comment 'string
2018 "User comment."
2019 :tag "Comment"
2020 :help-echo "Edit a comment here."
2021 :sample-face 'custom-comment-tag-face
2022 :value-face 'custom-comment-face
2023 :shown nil
2024 :create 'custom-comment-create)
2026 (defun custom-comment-create (widget)
2027 (let* ((null-comment (equal "" (widget-value widget))))
2028 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2029 (not null-comment))
2030 (widget-default-create widget)
2031 ;; `widget-default-delete' expects markers in these slots --
2032 ;; maybe it shouldn't.
2033 (widget-put widget :from (point-marker))
2034 (widget-put widget :to (point-marker)))))
2036 (defun custom-comment-hide (widget)
2037 (widget-put (widget-get widget :parent) :comment-shown nil))
2039 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2040 ;; the global custom one
2041 (defun custom-comment-show (widget)
2042 (widget-put widget :comment-shown t)
2043 (custom-redraw widget)
2044 (widget-setup))
2046 (defun custom-comment-invisible-p (widget)
2047 (let ((val (widget-value (widget-get widget :comment-widget))))
2048 (and (equal "" val)
2049 (not (widget-get widget :comment-shown)))))
2051 ;;; The `custom-variable' Widget.
2053 ;; When this was underlined blue, users confused it with a
2054 ;; Mosaic-style hyperlink...
2055 (defface custom-variable-tag-face
2056 `((((class color)
2057 (background dark))
2058 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
2059 (((class color)
2060 (background light))
2061 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
2062 (t (:weight bold)))
2063 "Face used for unpushable variable tags."
2064 :group 'custom-faces)
2066 (defface custom-variable-button-face '((t (:underline t :weight bold)))
2067 "Face used for pushable variable tags."
2068 :group 'custom-faces)
2070 (defcustom custom-variable-default-form 'edit
2071 "Default form of displaying variable values."
2072 :type '(choice (const edit)
2073 (const lisp))
2074 :group 'custom-buffer
2075 :version "20.3")
2077 (define-widget 'custom-variable 'custom
2078 "Customize variable."
2079 :format "%v"
2080 :help-echo "Set or reset this variable."
2081 :documentation-property 'variable-documentation
2082 :custom-category 'option
2083 :custom-state nil
2084 :custom-menu 'custom-variable-menu-create
2085 :custom-form nil ; defaults to value of `custom-variable-default-form'
2086 :value-create 'custom-variable-value-create
2087 :action 'custom-variable-action
2088 :custom-set 'custom-variable-set
2089 :custom-save 'custom-variable-save
2090 :custom-reset-current 'custom-redraw
2091 :custom-reset-saved 'custom-variable-reset-saved
2092 :custom-reset-standard 'custom-variable-reset-standard
2093 :custom-standard-value 'custom-variable-standard-value)
2095 (defun custom-variable-type (symbol)
2096 "Return a widget suitable for editing the value of SYMBOL.
2097 If SYMBOL has a `custom-type' property, use that.
2098 Otherwise, look up symbol in `custom-guess-type-alist'."
2099 (let* ((type (or (get symbol 'custom-type)
2100 (and (not (get symbol 'standard-value))
2101 (custom-guess-type symbol))
2102 'sexp))
2103 (options (get symbol 'custom-options))
2104 (tmp (if (listp type)
2105 (copy-sequence type)
2106 (list type))))
2107 (when options
2108 (widget-put tmp :options options))
2109 tmp))
2111 (defun custom-variable-value-create (widget)
2112 "Here is where you edit the variable's value."
2113 (custom-load-widget widget)
2114 (unless (widget-get widget :custom-form)
2115 (widget-put widget :custom-form custom-variable-default-form))
2116 (let* ((buttons (widget-get widget :buttons))
2117 (children (widget-get widget :children))
2118 (form (widget-get widget :custom-form))
2119 (state (widget-get widget :custom-state))
2120 (symbol (widget-get widget :value))
2121 (tag (widget-get widget :tag))
2122 (type (custom-variable-type symbol))
2123 (conv (widget-convert type))
2124 (get (or (get symbol 'custom-get) 'default-value))
2125 (prefix (widget-get widget :custom-prefix))
2126 (last (widget-get widget :custom-last))
2127 (value (if (default-boundp symbol)
2128 (funcall get symbol)
2129 (widget-get conv :value))))
2130 ;; If the widget is new, the child determines whether it is hidden.
2131 (cond (state)
2132 ((custom-show type value)
2133 (setq state 'unknown))
2135 (setq state 'hidden)))
2136 ;; If we don't know the state, see if we need to edit it in lisp form.
2137 (when (eq state 'unknown)
2138 (unless (widget-apply conv :match value)
2139 ;; (widget-apply (widget-convert type) :match value)
2140 (setq form 'mismatch)))
2141 ;; Now we can create the child widget.
2142 (cond ((eq custom-buffer-style 'tree)
2143 (insert prefix (if last " `--- " " |--- "))
2144 (push (widget-create-child-and-convert
2145 widget 'custom-browse-variable-tag)
2146 buttons)
2147 (insert " " tag "\n")
2148 (widget-put widget :buttons buttons))
2149 ((eq state 'hidden)
2150 ;; Indicate hidden value.
2151 (push (widget-create-child-and-convert
2152 widget 'item
2153 :format "%{%t%}: "
2154 :sample-face 'custom-variable-tag-face
2155 :tag tag
2156 :parent widget)
2157 buttons)
2158 (push (widget-create-child-and-convert
2159 widget 'visibility
2160 :help-echo "Show the value of this option."
2161 :off "Show Value"
2162 :action 'custom-toggle-parent
2163 nil)
2164 buttons))
2165 ((memq form '(lisp mismatch))
2166 ;; In lisp mode edit the saved value when possible.
2167 (let* ((value (cond ((get symbol 'saved-value)
2168 (car (get symbol 'saved-value)))
2169 ((get symbol 'standard-value)
2170 (car (get symbol 'standard-value)))
2171 ((default-boundp symbol)
2172 (custom-quote (funcall get symbol)))
2174 (custom-quote (widget-get conv :value))))))
2175 (insert (symbol-name symbol) ": ")
2176 (push (widget-create-child-and-convert
2177 widget 'visibility
2178 :help-echo "Hide the value of this option."
2179 :on "Hide Value"
2180 :off "Show Value"
2181 :action 'custom-toggle-parent
2183 buttons)
2184 (insert " ")
2185 (push (widget-create-child-and-convert
2186 widget 'sexp
2187 :button-face 'custom-variable-button-face
2188 :format "%v"
2189 :tag (symbol-name symbol)
2190 :parent widget
2191 :value value)
2192 children)))
2194 ;; Edit mode.
2195 (let* ((format (widget-get type :format))
2196 tag-format value-format)
2197 (unless (string-match ":" format)
2198 (error "Bad format"))
2199 (setq tag-format (substring format 0 (match-end 0)))
2200 (setq value-format (substring format (match-end 0)))
2201 (push (widget-create-child-and-convert
2202 widget 'item
2203 :format tag-format
2204 :action 'custom-tag-action
2205 :help-echo "Change value of this option."
2206 :mouse-down-action 'custom-tag-mouse-down-action
2207 :button-face 'custom-variable-button-face
2208 :sample-face 'custom-variable-tag-face
2209 tag)
2210 buttons)
2211 (insert " ")
2212 (push (widget-create-child-and-convert
2213 widget 'visibility
2214 :help-echo "Hide the value of this option."
2215 :on "Hide Value"
2216 :off "Show Value"
2217 :action 'custom-toggle-parent
2219 buttons)
2220 (push (widget-create-child-and-convert
2221 widget type
2222 :format value-format
2223 :value value)
2224 children))))
2225 (unless (eq custom-buffer-style 'tree)
2226 (unless (eq (preceding-char) ?\n)
2227 (widget-insert "\n"))
2228 ;; Create the magic button.
2229 (let ((magic (widget-create-child-and-convert
2230 widget 'custom-magic nil)))
2231 (widget-put widget :custom-magic magic)
2232 (push magic buttons))
2233 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2234 ;; before the call to `widget-default-format-handler'. Otherwise, I
2235 ;; loose my current `buttons'. This function shouldn't be called like
2236 ;; this anyway. The doc string widget should be added like the others.
2237 ;; --dv
2238 (widget-put widget :buttons buttons)
2239 (insert "\n")
2240 ;; Insert documentation.
2241 (widget-default-format-handler widget ?h)
2243 ;; The comment field
2244 (unless (eq state 'hidden)
2245 (let* ((comment (get symbol 'variable-comment))
2246 (comment-widget
2247 (widget-create-child-and-convert
2248 widget 'custom-comment
2249 :parent widget
2250 :value (or comment ""))))
2251 (widget-put widget :comment-widget comment-widget)
2252 ;; Don't push it !!! Custom assumes that the first child is the
2253 ;; value one.
2254 (setq children (append children (list comment-widget)))))
2255 ;; Update the rest of the properties properties.
2256 (widget-put widget :custom-form form)
2257 (widget-put widget :children children)
2258 ;; Now update the state.
2259 (if (eq state 'hidden)
2260 (widget-put widget :custom-state state)
2261 (custom-variable-state-set widget))
2262 ;; See also.
2263 (unless (eq state 'hidden)
2264 (when (eq (widget-get widget :custom-level) 1)
2265 (custom-add-parent-links widget))
2266 (custom-add-see-also widget)))))
2268 (defun custom-tag-action (widget &rest args)
2269 "Pass :action to first child of WIDGET's parent."
2270 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2271 :action args))
2273 (defun custom-tag-mouse-down-action (widget &rest args)
2274 "Pass :mouse-down-action to first child of WIDGET's parent."
2275 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2276 :mouse-down-action args))
2278 (defun custom-variable-state-set (widget)
2279 "Set the state of WIDGET."
2280 (let* ((symbol (widget-value widget))
2281 (get (or (get symbol 'custom-get) 'default-value))
2282 (value (if (default-boundp symbol)
2283 (funcall get symbol)
2284 (widget-get widget :value)))
2285 (comment (get symbol 'variable-comment))
2287 temp
2288 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2289 (setq temp
2290 (get symbol 'customized-variable-comment))
2291 (or tmp temp))
2292 (if (condition-case nil
2293 (and (equal value (eval (car tmp)))
2294 (equal comment temp))
2295 (error nil))
2296 'set
2297 'changed))
2298 ((progn (setq tmp (get symbol 'saved-value))
2299 (setq temp (get symbol 'saved-variable-comment))
2300 (or tmp temp))
2301 (if (condition-case nil
2302 (and (equal value (eval (car tmp)))
2303 (equal comment temp))
2304 (error nil))
2305 'saved
2306 'changed))
2307 ((setq tmp (get symbol 'standard-value))
2308 (if (condition-case nil
2309 (and (equal value (eval (car tmp)))
2310 (equal comment nil))
2311 (error nil))
2312 'standard
2313 'changed))
2314 (t 'rogue))))
2315 (widget-put widget :custom-state state)))
2317 (defun custom-variable-standard-value (widget)
2318 (get (widget-value widget) 'standard-value))
2320 (defvar custom-variable-menu
2321 '(("Set for Current Session" custom-variable-set
2322 (lambda (widget)
2323 (eq (widget-get widget :custom-state) 'modified)))
2324 ("Save for Future Sessions" custom-variable-save
2325 (lambda (widget)
2326 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2327 ("Reset to Current" custom-redraw
2328 (lambda (widget)
2329 (and (default-boundp (widget-value widget))
2330 (memq (widget-get widget :custom-state) '(modified changed)))))
2331 ("Reset to Saved" custom-variable-reset-saved
2332 (lambda (widget)
2333 (and (or (get (widget-value widget) 'saved-value)
2334 (get (widget-value widget) 'saved-variable-comment))
2335 (memq (widget-get widget :custom-state)
2336 '(modified set changed rogue)))))
2337 ("Erase Customization" custom-variable-reset-standard
2338 (lambda (widget)
2339 (and (get (widget-value widget) 'standard-value)
2340 (memq (widget-get widget :custom-state)
2341 '(modified set changed saved rogue)))))
2342 ("Use Backup Value" custom-variable-reset-backup
2343 (lambda (widget)
2344 (get (widget-value widget) 'backup-value)))
2345 ("---" ignore ignore)
2346 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2347 ("---" ignore ignore)
2348 ("Don't show as Lisp expression" custom-variable-edit
2349 (lambda (widget)
2350 (eq (widget-get widget :custom-form) 'lisp)))
2351 ("Show initial Lisp expression" custom-variable-edit-lisp
2352 (lambda (widget)
2353 (eq (widget-get widget :custom-form) 'edit))))
2354 "Alist of actions for the `custom-variable' widget.
2355 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2356 the menu entry, ACTION is the function to call on the widget when the
2357 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2358 widget as an argument, and returns non-nil if ACTION is valid on that
2359 widget. If FILTER is nil, ACTION is always valid.")
2361 (defun custom-variable-action (widget &optional event)
2362 "Show the menu for `custom-variable' WIDGET.
2363 Optional EVENT is the location for the menu."
2364 (if (eq (widget-get widget :custom-state) 'hidden)
2365 (custom-toggle-hide widget)
2366 (unless (eq (widget-get widget :custom-state) 'modified)
2367 (custom-variable-state-set widget))
2368 (custom-redraw-magic widget)
2369 (let* ((completion-ignore-case t)
2370 (answer (widget-choose (concat "Operation on "
2371 (custom-unlispify-tag-name
2372 (widget-get widget :value)))
2373 (custom-menu-filter custom-variable-menu
2374 widget)
2375 event)))
2376 (if answer
2377 (funcall answer widget)))))
2379 (defun custom-variable-edit (widget)
2380 "Edit value of WIDGET."
2381 (widget-put widget :custom-state 'unknown)
2382 (widget-put widget :custom-form 'edit)
2383 (custom-redraw widget))
2385 (defun custom-variable-edit-lisp (widget)
2386 "Edit the Lisp representation of the value of WIDGET."
2387 (widget-put widget :custom-state 'unknown)
2388 (widget-put widget :custom-form 'lisp)
2389 (custom-redraw widget))
2391 (defun custom-variable-set (widget)
2392 "Set the current value for the variable being edited by WIDGET."
2393 (let* ((form (widget-get widget :custom-form))
2394 (state (widget-get widget :custom-state))
2395 (child (car (widget-get widget :children)))
2396 (symbol (widget-value widget))
2397 (set (or (get symbol 'custom-set) 'set-default))
2398 (comment-widget (widget-get widget :comment-widget))
2399 (comment (widget-value comment-widget))
2400 val)
2401 (cond ((eq state 'hidden)
2402 (error "Cannot set hidden variable"))
2403 ((setq val (widget-apply child :validate))
2404 (goto-char (widget-get val :from))
2405 (error "%s" (widget-get val :error)))
2406 ((memq form '(lisp mismatch))
2407 (when (equal comment "")
2408 (setq comment nil)
2409 ;; Make the comment invisible by hand if it's empty
2410 (custom-comment-hide comment-widget))
2411 (custom-variable-backup-value widget)
2412 (funcall set symbol (eval (setq val (widget-value child))))
2413 (put symbol 'customized-value (list val))
2414 (put symbol 'variable-comment comment)
2415 (put symbol 'customized-variable-comment comment))
2417 (when (equal comment "")
2418 (setq comment nil)
2419 ;; Make the comment invisible by hand if it's empty
2420 (custom-comment-hide comment-widget))
2421 (custom-variable-backup-value widget)
2422 (funcall set symbol (setq val (widget-value child)))
2423 (put symbol 'customized-value (list (custom-quote val)))
2424 (put symbol 'variable-comment comment)
2425 (put symbol 'customized-variable-comment comment)))
2426 (custom-variable-state-set widget)
2427 (custom-redraw-magic widget)))
2429 (defun custom-variable-save (widget)
2430 "Set and save the value for the variable being edited by WIDGET."
2431 (let* ((form (widget-get widget :custom-form))
2432 (state (widget-get widget :custom-state))
2433 (child (car (widget-get widget :children)))
2434 (symbol (widget-value widget))
2435 (set (or (get symbol 'custom-set) 'set-default))
2436 (comment-widget (widget-get widget :comment-widget))
2437 (comment (widget-value comment-widget))
2438 val)
2439 (cond ((eq state 'hidden)
2440 (error "Cannot set hidden variable"))
2441 ((setq val (widget-apply child :validate))
2442 (goto-char (widget-get val :from))
2443 (error "Saving %s: %s" symbol (widget-get val :error)))
2444 ((memq form '(lisp mismatch))
2445 (when (equal comment "")
2446 (setq comment nil)
2447 ;; Make the comment invisible by hand if it's empty
2448 (custom-comment-hide comment-widget))
2449 (put symbol 'saved-value (list (widget-value child)))
2450 (custom-push-theme 'theme-value symbol 'user
2451 'set (list (widget-value child)))
2452 (funcall set symbol (eval (widget-value child)))
2453 (put symbol 'variable-comment comment)
2454 (put symbol 'saved-variable-comment comment))
2456 (when (equal comment "")
2457 (setq comment nil)
2458 ;; Make the comment invisible by hand if it's empty
2459 (custom-comment-hide comment-widget))
2460 (put symbol 'saved-value
2461 (list (custom-quote (widget-value child))))
2462 (custom-push-theme 'theme-value symbol 'user
2463 'set (list (custom-quote (widget-value
2464 child))))
2465 (funcall set symbol (widget-value child))
2466 (put symbol 'variable-comment comment)
2467 (put symbol 'saved-variable-comment comment)))
2468 (put symbol 'customized-value nil)
2469 (put symbol 'customized-variable-comment nil)
2470 (custom-save-all)
2471 (custom-variable-state-set widget)
2472 (custom-redraw-magic widget)))
2474 (defun custom-variable-reset-saved (widget)
2475 "Restore the saved value for the variable being edited by WIDGET.
2476 The value that was current before this operation
2477 becomes the backup value, so you can get it again."
2478 (let* ((symbol (widget-value widget))
2479 (set (or (get symbol 'custom-set) 'set-default))
2480 (value (get symbol 'saved-value))
2481 (comment (get symbol 'saved-variable-comment)))
2482 (cond ((or value comment)
2483 (put symbol 'variable-comment comment)
2484 (custom-variable-backup-value widget)
2485 (condition-case nil
2486 (funcall set symbol (eval (car value)))
2487 (error nil)))
2489 (error "No saved value for %s" symbol)))
2490 (put symbol 'customized-value nil)
2491 (put symbol 'customized-variable-comment nil)
2492 (widget-put widget :custom-state 'unknown)
2493 ;; This call will possibly make the comment invisible
2494 (custom-redraw widget)))
2496 (defun custom-variable-reset-standard (widget)
2497 "Restore the standard setting for the variable being edited by WIDGET.
2498 This operation eliminates any saved setting for the variable,
2499 restoring it to the state of a variable that has never been customized.
2500 The value that was current before this operation
2501 becomes the backup value, so you can get it again."
2502 (let* ((symbol (widget-value widget))
2503 (set (or (get symbol 'custom-set) 'set-default)))
2504 (if (get symbol 'standard-value)
2505 (progn
2506 (custom-variable-backup-value widget)
2507 (funcall set symbol (eval (car (get symbol 'standard-value)))))
2508 (error "No standard setting known for %S" symbol))
2509 (put symbol 'variable-comment nil)
2510 (put symbol 'customized-value nil)
2511 (put symbol 'customized-variable-comment nil)
2512 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2513 (put symbol 'saved-value nil)
2514 (custom-push-theme 'theme-value symbol 'user 'reset 'standard)
2515 ;; As a special optimizations we do not (explictly)
2516 ;; save resets to standard when no theme set the value.
2517 (if (null (cdr (get symbol 'theme-value)))
2518 (put symbol 'theme-value nil))
2519 (put symbol 'saved-variable-comment nil)
2520 (custom-save-all))
2521 (widget-put widget :custom-state 'unknown)
2522 ;; This call will possibly make the comment invisible
2523 (custom-redraw widget)))
2525 (defun custom-variable-backup-value (widget)
2526 "Back up the current value for WIDGET's variable.
2527 The backup value is kept in the car of the `backup-value' property."
2528 (let* ((symbol (widget-value widget))
2529 (get (or (get symbol 'custom-get) 'default-value))
2530 (type (custom-variable-type symbol))
2531 (conv (widget-convert type))
2532 (value (if (default-boundp symbol)
2533 (funcall get symbol)
2534 (widget-get conv :value))))
2535 (put symbol 'backup-value (list value))))
2537 (defun custom-variable-reset-backup (widget)
2538 "Restore the backup value for the variable being edited by WIDGET.
2539 The value that was current before this operation
2540 becomes the backup value, so you can use this operation repeatedly
2541 to switch between two values."
2542 (let* ((symbol (widget-value widget))
2543 (set (or (get symbol 'custom-set) 'set-default))
2544 (value (get symbol 'backup-value))
2545 (comment-widget (widget-get widget :comment-widget))
2546 (comment (widget-value comment-widget)))
2547 (if value
2548 (progn
2549 (custom-variable-backup-value widget)
2550 (condition-case nil
2551 (funcall set symbol (car value))
2552 (error nil)))
2553 (error "No backup value for %s" symbol))
2554 (put symbol 'customized-value (list (car value)))
2555 (put symbol 'variable-comment comment)
2556 (put symbol 'customized-variable-comment comment)
2557 (custom-variable-state-set widget)
2558 ;; This call will possibly make the comment invisible
2559 (custom-redraw widget)))
2561 ;;; The `custom-face-edit' Widget.
2563 (define-widget 'custom-face-edit 'checklist
2564 "Edit face attributes."
2565 :format "%t: %v"
2566 :tag "Attributes"
2567 :extra-offset 12
2568 :button-args '(:help-echo "Control whether this attribute has any effect.")
2569 :value-to-internal 'custom-face-edit-fix-value
2570 :match (lambda (widget value)
2571 (widget-checklist-match widget
2572 (custom-face-edit-fix-value widget value)))
2573 :convert-widget 'custom-face-edit-convert-widget
2574 :args (mapcar (lambda (att)
2575 (list 'group
2576 :inline t
2577 :sibling-args (widget-get (nth 1 att) :sibling-args)
2578 (list 'const :format "" :value (nth 0 att))
2579 (nth 1 att)))
2580 custom-face-attributes))
2582 (defun custom-face-edit-fix-value (widget value)
2583 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2584 Also change :reverse-video to :inverse-video."
2585 (if (listp value)
2586 (let (result)
2587 (while value
2588 (let ((key (car value))
2589 (val (car (cdr value))))
2590 (cond ((eq key :italic)
2591 (push :slant result)
2592 (push (if val 'italic 'normal) result))
2593 ((eq key :bold)
2594 (push :weight result)
2595 (push (if val 'bold 'normal) result))
2596 ((eq key :reverse-video)
2597 (push :inverse-video result)
2598 (push val result))
2600 (push key result)
2601 (push val result))))
2602 (setq value (cdr (cdr value))))
2603 (setq result (nreverse result))
2604 result)
2605 value))
2607 (defun custom-face-edit-convert-widget (widget)
2608 "Convert :args as widget types in WIDGET."
2609 (widget-put
2610 widget
2611 :args (mapcar (lambda (arg)
2612 (widget-convert arg
2613 :deactivate 'custom-face-edit-deactivate
2614 :activate 'custom-face-edit-activate
2615 :delete 'custom-face-edit-delete))
2616 (widget-get widget :args)))
2617 widget)
2619 (defun custom-face-edit-deactivate (widget)
2620 "Make face widget WIDGET inactive for user modifications."
2621 (unless (widget-get widget :inactive)
2622 (let ((tag (custom-face-edit-attribute-tag widget))
2623 (from (copy-marker (widget-get widget :from)))
2624 (value (widget-value widget))
2625 (inhibit-read-only t)
2626 (inhibit-modification-hooks t))
2627 (save-excursion
2628 (goto-char from)
2629 (widget-default-delete widget)
2630 (insert tag ": *\n")
2631 (widget-put widget :inactive
2632 (cons value (cons from (- (point) from))))))))
2634 (defun custom-face-edit-activate (widget)
2635 "Make face widget WIDGET inactive for user modifications."
2636 (let ((inactive (widget-get widget :inactive))
2637 (inhibit-read-only t)
2638 (inhibit-modification-hooks t))
2639 (when (consp inactive)
2640 (save-excursion
2641 (goto-char (car (cdr inactive)))
2642 (delete-region (point) (+ (point) (cdr (cdr inactive))))
2643 (widget-put widget :inactive nil)
2644 (widget-apply widget :create)
2645 (widget-value-set widget (car inactive))
2646 (widget-setup)))))
2648 (defun custom-face-edit-delete (widget)
2649 "Remove WIDGET from the buffer."
2650 (let ((inactive (widget-get widget :inactive))
2651 (inhibit-read-only t)
2652 (inhibit-modification-hooks t))
2653 (if (not inactive)
2654 ;; Widget is alive, we don't have to do anything special
2655 (widget-default-delete widget)
2656 ;; WIDGET is already deleted because we did so to inactivate it;
2657 ;; now just get rid of the label we put in its place.
2658 (delete-region (car (cdr inactive))
2659 (+ (car (cdr inactive)) (cdr (cdr inactive))))
2660 (widget-put widget :inactive nil))))
2663 (defun custom-face-edit-attribute-tag (widget)
2664 "Returns the first :tag property in WIDGET or one of its children."
2665 (let ((tag (widget-get widget :tag)))
2666 (or (and (not (equal tag "")) tag)
2667 (let ((children (widget-get widget :children)))
2668 (while (and (null tag) children)
2669 (setq tag (custom-face-edit-attribute-tag (pop children))))
2670 tag))))
2672 ;;; The `custom-display' Widget.
2674 (define-widget 'custom-display 'menu-choice
2675 "Select a display type."
2676 :tag "Display"
2677 :value t
2678 :help-echo "Specify frames where the face attributes should be used."
2679 :args '((const :tag "all" t)
2680 (checklist
2681 :offset 0
2682 :extra-offset 9
2683 :args ((group :sibling-args (:help-echo "\
2684 Only match the specified window systems.")
2685 (const :format "Type: "
2686 type)
2687 (checklist :inline t
2688 :offset 0
2689 (const :format "X "
2690 :sibling-args (:help-echo "\
2691 The X11 Window System.")
2693 (const :format "PM "
2694 :sibling-args (:help-echo "\
2695 OS/2 Presentation Manager.")
2697 (const :format "W32 "
2698 :sibling-args (:help-echo "\
2699 Windows NT/9X.")
2700 w32)
2701 (const :format "MAC "
2702 :sibling-args (:help-echo "\
2703 Macintosh OS.")
2704 mac)
2705 (const :format "DOS "
2706 :sibling-args (:help-echo "\
2707 Plain MS-DOS.")
2709 (const :format "TTY%n"
2710 :sibling-args (:help-echo "\
2711 Plain text terminals.")
2712 tty)))
2713 (group :sibling-args (:help-echo "\
2714 Only match the frames with the specified color support.")
2715 (const :format "Class: "
2716 class)
2717 (checklist :inline t
2718 :offset 0
2719 (const :format "Color "
2720 :sibling-args (:help-echo "\
2721 Match color frames.")
2722 color)
2723 (const :format "Grayscale "
2724 :sibling-args (:help-echo "\
2725 Match grayscale frames.")
2726 grayscale)
2727 (const :format "Monochrome%n"
2728 :sibling-args (:help-echo "\
2729 Match frames with no color support.")
2730 mono)))
2731 (group :sibling-args (:help-echo "\
2732 The minimum number of colors the frame should support.")
2733 (const :format "" min-colors)
2734 (integer :tag "Minimum number of colors" ))
2735 (group :sibling-args (:help-echo "\
2736 Only match frames with the specified intensity.")
2737 (const :format "\
2738 Background brightness: "
2739 background)
2740 (checklist :inline t
2741 :offset 0
2742 (const :format "Light "
2743 :sibling-args (:help-echo "\
2744 Match frames with light backgrounds.")
2745 light)
2746 (const :format "Dark\n"
2747 :sibling-args (:help-echo "\
2748 Match frames with dark backgrounds.")
2749 dark)))
2750 (group :sibling-args (:help-echo "\
2751 Only match frames that support the specified face attributes.")
2752 (const :format "Supports attributes:" supports)
2753 (custom-face-edit :inline t :format "%n%v"))))))
2755 ;;; The `custom-face' Widget.
2757 (defface custom-face-tag-face
2758 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
2759 "Face used for face tags."
2760 :group 'custom-faces)
2762 (defcustom custom-face-default-form 'selected
2763 "Default form of displaying face definition."
2764 :type '(choice (const all)
2765 (const selected)
2766 (const lisp))
2767 :group 'custom-buffer
2768 :version "20.3")
2770 (define-widget 'custom-face 'custom
2771 "Customize face."
2772 :sample-face 'custom-face-tag-face
2773 :help-echo "Set or reset this face."
2774 :documentation-property #'face-doc-string
2775 :value-create 'custom-face-value-create
2776 :action 'custom-face-action
2777 :custom-category 'face
2778 :custom-form nil ; defaults to value of `custom-face-default-form'
2779 :custom-set 'custom-face-set
2780 :custom-save 'custom-face-save
2781 :custom-reset-current 'custom-redraw
2782 :custom-reset-saved 'custom-face-reset-saved
2783 :custom-reset-standard 'custom-face-reset-standard
2784 :custom-standard-value 'custom-face-standard-value
2785 :custom-menu 'custom-face-menu-create)
2787 (define-widget 'custom-face-all 'editable-list
2788 "An editable list of display specifications and attributes."
2789 :entry-format "%i %d %v"
2790 :insert-button-args '(:help-echo "Insert new display specification here.")
2791 :append-button-args '(:help-echo "Append new display specification here.")
2792 :delete-button-args '(:help-echo "Delete this display specification.")
2793 :args '((group :format "%v" custom-display custom-face-edit)))
2795 (defconst custom-face-all (widget-convert 'custom-face-all)
2796 "Converted version of the `custom-face-all' widget.")
2798 (define-widget 'custom-display-unselected 'item
2799 "A display specification that doesn't match the selected display."
2800 :match 'custom-display-unselected-match)
2802 (defun custom-display-unselected-match (widget value)
2803 "Non-nil if VALUE is an unselected display specification."
2804 (not (face-spec-set-match-display value (selected-frame))))
2806 (define-widget 'custom-face-selected 'group
2807 "Edit the attributes of the selected display in a face specification."
2808 :args '((repeat :format ""
2809 :inline t
2810 (group custom-display-unselected sexp))
2811 (group (sexp :format "") custom-face-edit)
2812 (repeat :format ""
2813 :inline t
2814 sexp)))
2816 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2817 "Converted version of the `custom-face-selected' widget.")
2819 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
2820 "Return a canonicalized version of SPEC using.
2821 FILTER-INDEX is the index in the entry for each attribute in
2822 `custom-face-attributes' at which the appropriate filter function can be
2823 found, and DEFAULT-FILTER is the filter to apply for attributes that
2824 don't specify one."
2825 (mapcar (lambda (entry)
2826 ;; Filter a single face-spec entry
2827 (let ((tests (car entry))
2828 (unfiltered-attrs
2829 ;; Handle both old- and new-style attribute syntax
2830 (if (listp (car (cdr entry)))
2831 (car (cdr entry))
2832 (cdr entry)))
2833 (filtered-attrs nil))
2834 ;; Filter each face attribute
2835 (while unfiltered-attrs
2836 (let* ((attr (pop unfiltered-attrs))
2837 (pre-filtered-value (pop unfiltered-attrs))
2838 (filter
2839 (or (nth filter-index (assq attr custom-face-attributes))
2840 default-filter))
2841 (filtered-value
2842 (if filter
2843 (funcall filter pre-filtered-value)
2844 pre-filtered-value)))
2845 (push filtered-value filtered-attrs)
2846 (push attr filtered-attrs)))
2848 (list tests filtered-attrs)))
2849 spec))
2851 (defun custom-pre-filter-face-spec (spec)
2852 "Return SPEC changed as necessary for editing by the face customization widget.
2853 SPEC must be a full face spec."
2854 (custom-filter-face-spec spec 2))
2856 (defun custom-post-filter-face-spec (spec)
2857 "Return the customized SPEC in a form suitable for setting the face."
2858 (custom-filter-face-spec spec 3))
2860 (defun custom-face-value-create (widget)
2861 "Create a list of the display specifications for WIDGET."
2862 (let ((buttons (widget-get widget :buttons))
2863 children
2864 (symbol (widget-get widget :value))
2865 (tag (widget-get widget :tag))
2866 (state (widget-get widget :custom-state))
2867 (begin (point))
2868 (is-last (widget-get widget :custom-last))
2869 (prefix (widget-get widget :custom-prefix)))
2870 (unless tag
2871 (setq tag (prin1-to-string symbol)))
2872 (cond ((eq custom-buffer-style 'tree)
2873 (insert prefix (if is-last " `--- " " |--- "))
2874 (push (widget-create-child-and-convert
2875 widget 'custom-browse-face-tag)
2876 buttons)
2877 (insert " " tag "\n")
2878 (widget-put widget :buttons buttons))
2880 ;; Create tag.
2881 (insert tag)
2882 (widget-specify-sample widget begin (point))
2883 (if (eq custom-buffer-style 'face)
2884 (insert " ")
2885 (if (string-match "face\\'" tag)
2886 (insert ":")
2887 (insert " face: ")))
2888 ;; Sample.
2889 (push (widget-create-child-and-convert widget 'item
2890 :format "(%{%t%})"
2891 :sample-face symbol
2892 :tag "sample")
2893 buttons)
2894 ;; Visibility.
2895 (insert " ")
2896 (push (widget-create-child-and-convert
2897 widget 'visibility
2898 :help-echo "Hide or show this face."
2899 :on "Hide Face"
2900 :off "Show Face"
2901 :action 'custom-toggle-parent
2902 (not (eq state 'hidden)))
2903 buttons)
2904 ;; Magic.
2905 (insert "\n")
2906 (let ((magic (widget-create-child-and-convert
2907 widget 'custom-magic nil)))
2908 (widget-put widget :custom-magic magic)
2909 (push magic buttons))
2910 ;; Update buttons.
2911 (widget-put widget :buttons buttons)
2912 ;; Insert documentation.
2913 (widget-default-format-handler widget ?h)
2914 ;; The comment field
2915 (unless (eq state 'hidden)
2916 (let* ((comment (get symbol 'face-comment))
2917 (comment-widget
2918 (widget-create-child-and-convert
2919 widget 'custom-comment
2920 :parent widget
2921 :value (or comment ""))))
2922 (widget-put widget :comment-widget comment-widget)
2923 (push comment-widget children)))
2924 ;; See also.
2925 (unless (eq state 'hidden)
2926 (when (eq (widget-get widget :custom-level) 1)
2927 (custom-add-parent-links widget))
2928 (custom-add-see-also widget))
2929 ;; Editor.
2930 (unless (eq (preceding-char) ?\n)
2931 (insert "\n"))
2932 (unless (eq state 'hidden)
2933 (message "Creating face editor...")
2934 (custom-load-widget widget)
2935 (unless (widget-get widget :custom-form)
2936 (widget-put widget :custom-form custom-face-default-form))
2937 (let* ((symbol (widget-value widget))
2938 (spec (or (get symbol 'customized-face)
2939 (get symbol 'saved-face)
2940 (get symbol 'face-defface-spec)
2941 ;; Attempt to construct it.
2942 (list (list t (custom-face-attributes-get
2943 symbol (selected-frame))))))
2944 (form (widget-get widget :custom-form))
2945 (indent (widget-get widget :indent))
2946 edit)
2947 ;; If the user has changed this face in some other way,
2948 ;; edit it as the user has specified it.
2949 (if (not (face-spec-match-p symbol spec (selected-frame)))
2950 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
2951 (setq spec (custom-pre-filter-face-spec spec))
2952 (setq edit (widget-create-child-and-convert
2953 widget
2954 (cond ((and (eq form 'selected)
2955 (widget-apply custom-face-selected
2956 :match spec))
2957 (when indent (insert-char ?\ indent))
2958 'custom-face-selected)
2959 ((and (not (eq form 'lisp))
2960 (widget-apply custom-face-all
2961 :match spec))
2962 'custom-face-all)
2964 (when indent (insert-char ?\ indent))
2965 'sexp))
2966 :value spec))
2967 (custom-face-state-set widget)
2968 (push edit children)
2969 (widget-put widget :children children))
2970 (message "Creating face editor...done"))))))
2972 (defvar custom-face-menu
2973 '(("Set for Current Session" custom-face-set)
2974 ("Save for Future Sessions" custom-face-save-command)
2975 ("Reset to Saved" custom-face-reset-saved
2976 (lambda (widget)
2977 (or (get (widget-value widget) 'saved-face)
2978 (get (widget-value widget) 'saved-face-comment))))
2979 ("Erase Customization" custom-face-reset-standard
2980 (lambda (widget)
2981 (get (widget-value widget) 'face-defface-spec)))
2982 ("---" ignore ignore)
2983 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2984 ("---" ignore ignore)
2985 ("Show all display specs" custom-face-edit-all
2986 (lambda (widget)
2987 (not (eq (widget-get widget :custom-form) 'all))))
2988 ("Just current attributes" custom-face-edit-selected
2989 (lambda (widget)
2990 (not (eq (widget-get widget :custom-form) 'selected))))
2991 ("Show as Lisp expression" custom-face-edit-lisp
2992 (lambda (widget)
2993 (not (eq (widget-get widget :custom-form) 'lisp)))))
2994 "Alist of actions for the `custom-face' widget.
2995 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2996 the menu entry, ACTION is the function to call on the widget when the
2997 menu is selected, and FILTER is a predicate which takes a `custom-face'
2998 widget as an argument, and returns non-nil if ACTION is valid on that
2999 widget. If FILTER is nil, ACTION is always valid.")
3001 (defun custom-face-edit-selected (widget)
3002 "Edit selected attributes of the value of WIDGET."
3003 (widget-put widget :custom-state 'unknown)
3004 (widget-put widget :custom-form 'selected)
3005 (custom-redraw widget))
3007 (defun custom-face-edit-all (widget)
3008 "Edit all attributes of the value of WIDGET."
3009 (widget-put widget :custom-state 'unknown)
3010 (widget-put widget :custom-form 'all)
3011 (custom-redraw widget))
3013 (defun custom-face-edit-lisp (widget)
3014 "Edit the Lisp representation of the value of WIDGET."
3015 (widget-put widget :custom-state 'unknown)
3016 (widget-put widget :custom-form 'lisp)
3017 (custom-redraw widget))
3019 (defun custom-face-state-set (widget)
3020 "Set the state of WIDGET."
3021 (let* ((symbol (widget-value widget))
3022 (comment (get symbol 'face-comment))
3023 tmp temp
3024 (state
3025 (cond ((progn
3026 (setq tmp (get symbol 'customized-face))
3027 (setq temp (get symbol 'customized-face-comment))
3028 (or tmp temp))
3029 (if (equal temp comment)
3030 'set
3031 'changed))
3032 ((progn
3033 (setq tmp (get symbol 'saved-face))
3034 (setq temp (get symbol 'saved-face-comment))
3035 (or tmp temp))
3036 (if (equal temp comment)
3037 'saved
3038 'changed))
3039 ((get symbol 'face-defface-spec)
3040 (if (equal comment nil)
3041 'standard
3042 'changed))
3044 'rogue))))
3045 ;; If the user called set-face-attribute to change the default
3046 ;; for new frames, this face is "set outside of Customize".
3047 (if (and (not (eq state 'rogue))
3048 (get symbol 'face-modified))
3049 (setq state 'changed))
3050 (widget-put widget :custom-state state)))
3052 (defun custom-face-action (widget &optional event)
3053 "Show the menu for `custom-face' WIDGET.
3054 Optional EVENT is the location for the menu."
3055 (if (eq (widget-get widget :custom-state) 'hidden)
3056 (custom-toggle-hide widget)
3057 (let* ((completion-ignore-case t)
3058 (symbol (widget-get widget :value))
3059 (answer (widget-choose (concat "Operation on "
3060 (custom-unlispify-tag-name symbol))
3061 (custom-menu-filter custom-face-menu
3062 widget)
3063 event)))
3064 (if answer
3065 (funcall answer widget)))))
3067 (defun custom-face-set (widget)
3068 "Make the face attributes in WIDGET take effect."
3069 (let* ((symbol (widget-value widget))
3070 (child (car (widget-get widget :children)))
3071 (value (custom-post-filter-face-spec (widget-value child)))
3072 (comment-widget (widget-get widget :comment-widget))
3073 (comment (widget-value comment-widget)))
3074 (when (equal comment "")
3075 (setq comment nil)
3076 ;; Make the comment invisible by hand if it's empty
3077 (custom-comment-hide comment-widget))
3078 (put symbol 'customized-face value)
3079 (if (face-spec-choose value)
3080 (face-spec-set symbol value)
3081 ;; face-set-spec ignores empty attribute lists, so just give it
3082 ;; something harmless instead.
3083 (face-spec-set symbol '((t :foreground unspecified))))
3084 (put symbol 'customized-face-comment comment)
3085 (put symbol 'face-comment comment)
3086 (custom-face-state-set widget)
3087 (custom-redraw-magic widget)))
3089 (defun custom-face-save-command (widget)
3090 "Save in `.emacs' the face attributes in WIDGET."
3091 (custom-face-save widget)
3092 (custom-save-all))
3094 (defun custom-face-save (widget)
3095 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3096 (let* ((symbol (widget-value widget))
3097 (child (car (widget-get widget :children)))
3098 (value (custom-post-filter-face-spec (widget-value child)))
3099 (comment-widget (widget-get widget :comment-widget))
3100 (comment (widget-value comment-widget)))
3101 (when (equal comment "")
3102 (setq comment nil)
3103 ;; Make the comment invisible by hand if it's empty
3104 (custom-comment-hide comment-widget))
3105 (if (face-spec-choose value)
3106 (face-spec-set symbol value)
3107 ;; face-set-spec ignores empty attribute lists, so just give it
3108 ;; something harmless instead.
3109 (face-spec-set symbol '((t :foreground unspecified))))
3110 (unless (eq (widget-get widget :custom-state) 'standard)
3111 (put symbol 'saved-face value))
3112 (custom-push-theme 'theme-face symbol 'user 'set value)
3113 (put symbol 'customized-face nil)
3114 (put symbol 'face-comment comment)
3115 (put symbol 'customized-face-comment nil)
3116 (put symbol 'saved-face-comment comment)
3117 (custom-save-all)
3118 (custom-face-state-set widget)
3119 (custom-redraw-magic widget)))
3121 (defun custom-face-reset-saved (widget)
3122 "Restore WIDGET to the face's default attributes."
3123 (let* ((symbol (widget-value widget))
3124 (child (car (widget-get widget :children)))
3125 (value (get symbol 'saved-face))
3126 (comment (get symbol 'saved-face-comment))
3127 (comment-widget (widget-get widget :comment-widget)))
3128 (unless (or value comment)
3129 (error "No saved value for this face"))
3130 (put symbol 'customized-face nil)
3131 (put symbol 'customized-face-comment nil)
3132 (face-spec-set symbol value)
3133 (put symbol 'face-comment comment)
3134 (widget-value-set child value)
3135 ;; This call manages the comment visibility
3136 (widget-value-set comment-widget (or comment ""))
3137 (custom-face-state-set widget)
3138 (custom-redraw-magic widget)))
3140 (defun custom-face-standard-value (widget)
3141 (get (widget-value widget) 'face-defface-spec))
3143 (defun custom-face-reset-standard (widget)
3144 "Restore WIDGET to the face's standard settings.
3145 This operation eliminates any saved setting for the face,
3146 restoring it to the state of a face that has never been customized."
3147 (let* ((symbol (widget-value widget))
3148 (child (car (widget-get widget :children)))
3149 (value (get symbol 'face-defface-spec))
3150 (comment-widget (widget-get widget :comment-widget)))
3151 (unless value
3152 (error "No standard setting for this face"))
3153 (put symbol 'customized-face nil)
3154 (put symbol 'customized-face-comment nil)
3155 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3156 (put symbol 'saved-face nil)
3157 (custom-push-theme 'theme-face symbol 'user 'reset 'standard)
3158 ;; Do not explictly save resets to standards without themes.
3159 (if (null (cdr (get symbol 'theme-face)))
3160 (put symbol 'theme-face nil))
3161 (put symbol 'saved-face-comment nil)
3162 (custom-save-all))
3163 (face-spec-set symbol value)
3164 (put symbol 'face-comment nil)
3165 (widget-value-set child value)
3166 ;; This call manages the comment visibility
3167 (widget-value-set comment-widget "")
3168 (custom-face-state-set widget)
3169 (custom-redraw-magic widget)))
3171 ;;; The `face' Widget.
3173 (define-widget 'face 'default
3174 "Select and customize a face."
3175 :convert-widget 'widget-value-convert-widget
3176 :button-prefix 'widget-push-button-prefix
3177 :button-suffix 'widget-push-button-suffix
3178 :format "%{%t%}: %[select face%] %v"
3179 :tag "Face"
3180 :value 'default
3181 :value-create 'widget-face-value-create
3182 :value-delete 'widget-face-value-delete
3183 :value-get 'widget-value-value-get
3184 :validate 'widget-children-validate
3185 :action 'widget-face-action
3186 :match (lambda (widget value) (symbolp value)))
3188 (defun widget-face-value-create (widget)
3189 "Create a `custom-face' child."
3190 (let* ((symbol (widget-value widget))
3191 (custom-buffer-style 'face)
3192 (child (widget-create-child-and-convert
3193 widget 'custom-face
3194 :custom-level nil
3195 :value symbol)))
3196 (custom-magic-reset child)
3197 (setq custom-options (cons child custom-options))
3198 (widget-put widget :children (list child))))
3200 (defun widget-face-value-delete (widget)
3201 "Remove the child from the options."
3202 (let ((child (car (widget-get widget :children))))
3203 (setq custom-options (delq child custom-options))
3204 (widget-children-value-delete widget)))
3206 (defvar face-history nil
3207 "History of entered face names.")
3209 (defun widget-face-action (widget &optional event)
3210 "Prompt for a face."
3211 (let ((answer (completing-read "Face: "
3212 (mapcar (lambda (face)
3213 (list (symbol-name face)))
3214 (face-list))
3215 nil nil nil
3216 'face-history)))
3217 (unless (zerop (length answer))
3218 (widget-value-set widget (intern answer))
3219 (widget-apply widget :notify widget event)
3220 (widget-setup))))
3222 ;;; The `hook' Widget.
3224 (define-widget 'hook 'list
3225 "A emacs lisp hook"
3226 :value-to-internal (lambda (widget value)
3227 (if (and value (symbolp value))
3228 (list value)
3229 value))
3230 :match (lambda (widget value)
3231 (or (symbolp value)
3232 (widget-group-match widget value)))
3233 ;; Avoid adding undefined functions to the hook, especially for
3234 ;; things like `find-file-hook' or even more basic ones, to avoid
3235 ;; chaos.
3236 :set (lambda (symbol value)
3237 (dolist (elt value)
3238 (if (fboundp elt)
3239 (add-hook symbol elt))))
3240 :convert-widget 'custom-hook-convert-widget
3241 :tag "Hook")
3243 (defun custom-hook-convert-widget (widget)
3244 ;; Handle `:options'.
3245 (let* ((options (widget-get widget :options))
3246 (other `(editable-list :inline t
3247 :entry-format "%i %d%v"
3248 (function :format " %v")))
3249 (args (if options
3250 (list `(checklist :inline t
3251 ,@(mapcar (lambda (entry)
3252 `(function-item ,entry))
3253 options))
3254 other)
3255 (list other))))
3256 (widget-put widget :args args)
3257 widget))
3259 ;;; The `custom-group-link' Widget.
3261 (define-widget 'custom-group-link 'link
3262 "Show parent in other window when activated."
3263 :help-echo "Create customization buffer for this group."
3264 :action 'custom-group-link-action)
3266 (defun custom-group-link-action (widget &rest ignore)
3267 (customize-group (widget-value widget)))
3269 ;;; The `custom-group' Widget.
3271 (defcustom custom-group-tag-faces nil
3272 ;; In XEmacs, this ought to play games with font size.
3273 ;; Fixme: make it do so in Emacs.
3274 "Face used for group tags.
3275 The first member is used for level 1 groups, the second for level 2,
3276 and so forth. The remaining group tags are shown with
3277 `custom-group-tag-face'."
3278 :type '(repeat face)
3279 :group 'custom-faces)
3281 (defface custom-group-tag-face-1
3282 `((((class color)
3283 (background dark))
3284 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3285 (((class color)
3286 (background light))
3287 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3288 (t (:weight bold)))
3289 "Face used for group tags."
3290 :group 'custom-faces)
3292 (defface custom-group-tag-face
3293 `((((class color)
3294 (background dark))
3295 (:foreground "light blue" :weight bold :height 1.2))
3296 (((class color)
3297 (background light))
3298 (:foreground "blue" :weight bold :height 1.2))
3299 (t (:weight bold)))
3300 "Face used for low level group tags."
3301 :group 'custom-faces)
3303 (define-widget 'custom-group 'custom
3304 "Customize group."
3305 :format "%v"
3306 :sample-face-get 'custom-group-sample-face-get
3307 :documentation-property 'group-documentation
3308 :help-echo "Set or reset all members of this group."
3309 :value-create 'custom-group-value-create
3310 :action 'custom-group-action
3311 :custom-category 'group
3312 :custom-set 'custom-group-set
3313 :custom-save 'custom-group-save
3314 :custom-reset-current 'custom-group-reset-current
3315 :custom-reset-saved 'custom-group-reset-saved
3316 :custom-reset-standard 'custom-group-reset-standard
3317 :custom-menu 'custom-group-menu-create)
3319 (defun custom-group-sample-face-get (widget)
3320 ;; Use :sample-face.
3321 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3322 'custom-group-tag-face))
3324 (define-widget 'custom-group-visibility 'visibility
3325 "An indicator and manipulator for hidden group contents."
3326 :create 'custom-group-visibility-create)
3328 (defun custom-group-visibility-create (widget)
3329 (let ((visible (widget-value widget)))
3330 (if visible
3331 (insert "--------")))
3332 (widget-default-create widget))
3334 (defun custom-group-members (symbol groups-only)
3335 "Return SYMBOL's custom group members.
3336 If GROUPS-ONLY non-nil, return only those members that are groups."
3337 (if (not groups-only)
3338 (get symbol 'custom-group)
3339 (let (members)
3340 (dolist (entry (get symbol 'custom-group))
3341 (when (eq (nth 1 entry) 'custom-group)
3342 (push entry members)))
3343 (nreverse members))))
3345 (defun custom-group-value-create (widget)
3346 "Insert a customize group for WIDGET in the current buffer."
3347 (unless (eq (widget-get widget :custom-state) 'hidden)
3348 (custom-load-widget widget))
3349 (let* ((state (widget-get widget :custom-state))
3350 (level (widget-get widget :custom-level))
3351 ;; (indent (widget-get widget :indent))
3352 (prefix (widget-get widget :custom-prefix))
3353 (buttons (widget-get widget :buttons))
3354 (tag (widget-get widget :tag))
3355 (symbol (widget-value widget))
3356 (members (custom-group-members symbol
3357 (and (eq custom-buffer-style 'tree)
3358 custom-browse-only-groups))))
3359 (cond ((and (eq custom-buffer-style 'tree)
3360 (eq state 'hidden)
3361 (or members (custom-unloaded-widget-p widget)))
3362 (custom-browse-insert-prefix prefix)
3363 (push (widget-create-child-and-convert
3364 widget 'custom-browse-visibility
3365 ;; :tag-glyph "plus"
3366 :tag "+")
3367 buttons)
3368 (insert "-- ")
3369 ;; (widget-glyph-insert nil "-- " "horizontal")
3370 (push (widget-create-child-and-convert
3371 widget 'custom-browse-group-tag)
3372 buttons)
3373 (insert " " tag "\n")
3374 (widget-put widget :buttons buttons))
3375 ((and (eq custom-buffer-style 'tree)
3376 (zerop (length members)))
3377 (custom-browse-insert-prefix prefix)
3378 (insert "[ ]-- ")
3379 ;; (widget-glyph-insert nil "[ ]" "empty")
3380 ;; (widget-glyph-insert nil "-- " "horizontal")
3381 (push (widget-create-child-and-convert
3382 widget 'custom-browse-group-tag)
3383 buttons)
3384 (insert " " tag "\n")
3385 (widget-put widget :buttons buttons))
3386 ((eq custom-buffer-style 'tree)
3387 (custom-browse-insert-prefix prefix)
3388 (if (zerop (length members))
3389 (progn
3390 (custom-browse-insert-prefix prefix)
3391 (insert "[ ]-- ")
3392 ;; (widget-glyph-insert nil "[ ]" "empty")
3393 ;; (widget-glyph-insert nil "-- " "horizontal")
3394 (push (widget-create-child-and-convert
3395 widget 'custom-browse-group-tag)
3396 buttons)
3397 (insert " " tag "\n")
3398 (widget-put widget :buttons buttons))
3399 (push (widget-create-child-and-convert
3400 widget 'custom-browse-visibility
3401 ;; :tag-glyph "minus"
3402 :tag "-")
3403 buttons)
3404 (insert "-\\ ")
3405 ;; (widget-glyph-insert nil "-\\ " "top")
3406 (push (widget-create-child-and-convert
3407 widget 'custom-browse-group-tag)
3408 buttons)
3409 (insert " " tag "\n")
3410 (widget-put widget :buttons buttons)
3411 (message "Creating group...")
3412 (let* ((members (custom-sort-items members
3413 custom-browse-sort-alphabetically
3414 custom-browse-order-groups))
3415 (prefixes (widget-get widget :custom-prefixes))
3416 (custom-prefix-list (custom-prefix-add symbol prefixes))
3417 (extra-prefix (if (widget-get widget :custom-last)
3419 " | "))
3420 (prefix (concat prefix extra-prefix))
3421 children entry)
3422 (while members
3423 (setq entry (car members)
3424 members (cdr members))
3425 (push (widget-create-child-and-convert
3426 widget (nth 1 entry)
3427 :group widget
3428 :tag (custom-unlispify-tag-name (nth 0 entry))
3429 :custom-prefixes custom-prefix-list
3430 :custom-level (1+ level)
3431 :custom-last (null members)
3432 :value (nth 0 entry)
3433 :custom-prefix prefix)
3434 children))
3435 (widget-put widget :children (reverse children)))
3436 (message "Creating group...done")))
3437 ;; Nested style.
3438 ((eq state 'hidden)
3439 ;; Create level indicator.
3440 (unless (eq custom-buffer-style 'links)
3441 (insert-char ?\ (* custom-buffer-indent (1- level)))
3442 (insert "-- "))
3443 ;; Create tag.
3444 (let ((begin (point)))
3445 (insert tag)
3446 (widget-specify-sample widget begin (point)))
3447 (insert " group: ")
3448 ;; Create link/visibility indicator.
3449 (if (eq custom-buffer-style 'links)
3450 (push (widget-create-child-and-convert
3451 widget 'custom-group-link
3452 :tag "Go to Group"
3453 symbol)
3454 buttons)
3455 (push (widget-create-child-and-convert
3456 widget 'custom-group-visibility
3457 :help-echo "Show members of this group."
3458 :action 'custom-toggle-parent
3459 (not (eq state 'hidden)))
3460 buttons))
3461 (insert " \n")
3462 ;; Create magic button.
3463 (let ((magic (widget-create-child-and-convert
3464 widget 'custom-magic nil)))
3465 (widget-put widget :custom-magic magic)
3466 (push magic buttons))
3467 ;; Update buttons.
3468 (widget-put widget :buttons buttons)
3469 ;; Insert documentation.
3470 (if (and (eq custom-buffer-style 'links) (> level 1))
3471 (widget-put widget :documentation-indent 0))
3472 (widget-default-format-handler widget ?h))
3473 ;; Nested style.
3474 (t ;Visible.
3475 ;; Add parent groups references above the group.
3476 (if t ;;; This should test that the buffer
3477 ;;; was made to display a group.
3478 (when (eq level 1)
3479 (if (custom-add-parent-links widget
3480 "Go to parent group:")
3481 (insert "\n"))))
3482 ;; Create level indicator.
3483 (insert-char ?\ (* custom-buffer-indent (1- level)))
3484 (insert "/- ")
3485 ;; Create tag.
3486 (let ((start (point)))
3487 (insert tag)
3488 (widget-specify-sample widget start (point)))
3489 (insert " group: ")
3490 ;; Create visibility indicator.
3491 (unless (eq custom-buffer-style 'links)
3492 (insert "--------")
3493 (push (widget-create-child-and-convert
3494 widget 'visibility
3495 :help-echo "Hide members of this group."
3496 :action 'custom-toggle-parent
3497 (not (eq state 'hidden)))
3498 buttons)
3499 (insert " "))
3500 ;; Create more dashes.
3501 ;; Use 76 instead of 75 to compensate for the temporary "<"
3502 ;; added by `widget-insert'.
3503 (insert-char ?- (- 76 (current-column)
3504 (* custom-buffer-indent level)))
3505 (insert "\\\n")
3506 ;; Create magic button.
3507 (let ((magic (widget-create-child-and-convert
3508 widget 'custom-magic
3509 :indent 0
3510 nil)))
3511 (widget-put widget :custom-magic magic)
3512 (push magic buttons))
3513 ;; Update buttons.
3514 (widget-put widget :buttons buttons)
3515 ;; Insert documentation.
3516 (widget-default-format-handler widget ?h)
3517 ;; Parent groups.
3518 (if nil ;;; This should test that the buffer
3519 ;;; was not made to display a group.
3520 (when (eq level 1)
3521 (insert-char ?\ custom-buffer-indent)
3522 (custom-add-parent-links widget)))
3523 (custom-add-see-also widget
3524 (make-string (* custom-buffer-indent level)
3525 ?\ ))
3526 ;; Members.
3527 (message "Creating group...")
3528 (let* ((members (custom-sort-items members
3529 custom-buffer-sort-alphabetically
3530 custom-buffer-order-groups))
3531 (prefixes (widget-get widget :custom-prefixes))
3532 (custom-prefix-list (custom-prefix-add symbol prefixes))
3533 (length (length members))
3534 (count 0)
3535 (children (mapcar (lambda (entry)
3536 (widget-insert "\n")
3537 (message "\
3538 Creating group members... %2d%%"
3539 (/ (* 100.0 count) length))
3540 (setq count (1+ count))
3541 (prog1
3542 (widget-create-child-and-convert
3543 widget (nth 1 entry)
3544 :group widget
3545 :tag (custom-unlispify-tag-name
3546 (nth 0 entry))
3547 :custom-prefixes custom-prefix-list
3548 :custom-level (1+ level)
3549 :value (nth 0 entry))
3550 (unless (eq (preceding-char) ?\n)
3551 (widget-insert "\n"))))
3552 members)))
3553 (message "Creating group magic...")
3554 (mapc 'custom-magic-reset children)
3555 (message "Creating group state...")
3556 (widget-put widget :children children)
3557 (custom-group-state-update widget)
3558 (message "Creating group... done"))
3559 ;; End line
3560 (insert "\n")
3561 (insert-char ?\ (* custom-buffer-indent (1- level)))
3562 (insert "\\- " (widget-get widget :tag) " group end ")
3563 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3564 (insert "/\n")))))
3566 (defvar custom-group-menu
3567 '(("Set for Current Session" custom-group-set
3568 (lambda (widget)
3569 (eq (widget-get widget :custom-state) 'modified)))
3570 ("Save for Future Sessions" custom-group-save
3571 (lambda (widget)
3572 (memq (widget-get widget :custom-state) '(modified set))))
3573 ("Reset to Current" custom-group-reset-current
3574 (lambda (widget)
3575 (memq (widget-get widget :custom-state) '(modified))))
3576 ("Reset to Saved" custom-group-reset-saved
3577 (lambda (widget)
3578 (memq (widget-get widget :custom-state) '(modified set))))
3579 ("Reset to standard setting" custom-group-reset-standard
3580 (lambda (widget)
3581 (memq (widget-get widget :custom-state) '(modified set saved)))))
3582 "Alist of actions for the `custom-group' widget.
3583 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3584 the menu entry, ACTION is the function to call on the widget when the
3585 menu is selected, and FILTER is a predicate which takes a `custom-group'
3586 widget as an argument, and returns non-nil if ACTION is valid on that
3587 widget. If FILTER is nil, ACTION is always valid.")
3589 (defun custom-group-action (widget &optional event)
3590 "Show the menu for `custom-group' WIDGET.
3591 Optional EVENT is the location for the menu."
3592 (if (eq (widget-get widget :custom-state) 'hidden)
3593 (custom-toggle-hide widget)
3594 (let* ((completion-ignore-case t)
3595 (answer (widget-choose (concat "Operation on "
3596 (custom-unlispify-tag-name
3597 (widget-get widget :value)))
3598 (custom-menu-filter custom-group-menu
3599 widget)
3600 event)))
3601 (if answer
3602 (funcall answer widget)))))
3604 (defun custom-group-set (widget)
3605 "Set changes in all modified group members."
3606 (let ((children (widget-get widget :children)))
3607 (mapc (lambda (child)
3608 (when (eq (widget-get child :custom-state) 'modified)
3609 (widget-apply child :custom-set)))
3610 children )))
3612 (defun custom-group-save (widget)
3613 "Save all modified group members."
3614 (let ((children (widget-get widget :children)))
3615 (mapc (lambda (child)
3616 (when (memq (widget-get child :custom-state) '(modified set))
3617 (widget-apply child :custom-save)))
3618 children )))
3620 (defun custom-group-reset-current (widget)
3621 "Reset all modified group members."
3622 (let ((children (widget-get widget :children)))
3623 (mapc (lambda (child)
3624 (when (eq (widget-get child :custom-state) 'modified)
3625 (widget-apply child :custom-reset-current)))
3626 children )))
3628 (defun custom-group-reset-saved (widget)
3629 "Reset all modified or set group members."
3630 (let ((children (widget-get widget :children)))
3631 (mapc (lambda (child)
3632 (when (memq (widget-get child :custom-state) '(modified set))
3633 (widget-apply child :custom-reset-saved)))
3634 children )))
3636 (defun custom-group-reset-standard (widget)
3637 "Reset all modified, set, or saved group members."
3638 (let ((children (widget-get widget :children)))
3639 (mapc (lambda (child)
3640 (when (memq (widget-get child :custom-state)
3641 '(modified set saved))
3642 (widget-apply child :custom-reset-standard)))
3643 children )))
3645 (defun custom-group-state-update (widget)
3646 "Update magic."
3647 (unless (eq (widget-get widget :custom-state) 'hidden)
3648 (let* ((children (widget-get widget :children))
3649 (states (mapcar (lambda (child)
3650 (widget-get child :custom-state))
3651 children))
3652 (magics custom-magic-alist)
3653 (found 'standard))
3654 (while magics
3655 (let ((magic (car (car magics))))
3656 (if (and (not (eq magic 'hidden))
3657 (memq magic states))
3658 (setq found magic
3659 magics nil)
3660 (setq magics (cdr magics)))))
3661 (widget-put widget :custom-state found)))
3662 (custom-magic-reset widget))
3664 ;;; The `custom-save-all' Function.
3665 ;;;###autoload
3666 (defcustom custom-file nil
3667 "File used for storing customization information.
3668 The default is nil, which means to use your init file
3669 as specified by `user-init-file'. If you specify some other file,
3670 you need to explicitly load that file for the settings to take effect.
3672 When you change this variable, look in the previous custom file
3673 \(usually your init file) for the forms `(custom-set-variables ...)'
3674 and `(custom-set-faces ...)', and copy them (whichever ones you find)
3675 to the new custom file. This will preserve your existing customizations."
3676 :type '(choice (const :tag "Your Emacs init file" nil) file)
3677 :group 'customize)
3679 (defun custom-file ()
3680 "Return the file name for saving customizations."
3681 (setq custom-file
3682 (or custom-file
3683 (let ((user-init-file user-init-file)
3684 (default-init-file
3685 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
3686 (when (null user-init-file)
3687 (if (or (file-exists-p default-init-file)
3688 (and (eq system-type 'windows-nt)
3689 (file-exists-p "~/_emacs")))
3690 ;; Started with -q, i.e. the file containing
3691 ;; Custom settings hasn't been read. Saving
3692 ;; settings there would overwrite other settings.
3693 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3694 (setq user-init-file default-init-file))
3695 user-init-file))))
3697 (defun custom-save-delete (symbol)
3698 "Visit `custom-file' and delete all calls to SYMBOL from it.
3699 Leave point at the old location of the first such call,
3700 or (if there were none) at the end of the buffer."
3701 (let ((default-major-mode 'emacs-lisp-mode))
3702 (set-buffer (find-file-noselect (custom-file))))
3703 (goto-char (point-min))
3704 ;; Skip all whitespace and comments.
3705 (while (forward-comment 1))
3706 (or (eobp)
3707 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3708 (let (first)
3709 (catch 'found
3710 (while t ;; We exit this loop only via throw.
3711 ;; Skip all whitespace and comments.
3712 (while (forward-comment 1))
3713 (let ((start (point))
3714 (sexp (condition-case nil
3715 (read (current-buffer))
3716 (end-of-file (throw 'found nil)))))
3717 (when (and (listp sexp)
3718 (eq (car sexp) symbol))
3719 (delete-region start (point))
3720 (unless first
3721 (setq first (point)))))))
3722 (if first
3723 (goto-char first)
3724 ;; Move in front of local variables, otherwise long Custom
3725 ;; entries would make them ineffective.
3726 (let ((pos (point-max))
3727 (case-fold-search t))
3728 (save-excursion
3729 (goto-char (point-max))
3730 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3731 'move)
3732 (when (search-forward "Local Variables:" nil t)
3733 (setq pos (line-beginning-position))))
3734 (goto-char pos)))))
3736 (defun custom-save-variables ()
3737 "Save all customized variables in `custom-file'."
3738 (save-excursion
3739 (custom-save-delete 'custom-load-themes)
3740 (custom-save-delete 'custom-reset-variables)
3741 (custom-save-delete 'custom-set-variables)
3742 (custom-save-loaded-themes)
3743 (custom-save-resets 'theme-value 'custom-reset-variables nil)
3744 (let ((standard-output (current-buffer))
3745 (saved-list (make-list 1 0))
3746 sort-fold-case)
3747 ;; First create a sorted list of saved variables.
3748 (mapatoms
3749 (lambda (symbol)
3750 (if (get symbol 'saved-value)
3751 (nconc saved-list (list symbol)))))
3752 (setq saved-list (sort (cdr saved-list) 'string<))
3753 (unless (bolp)
3754 (princ "\n"))
3755 (princ "(custom-set-variables
3756 ;; custom-set-variables was added by Custom.
3757 ;; If you edit it by hand, you could mess it up, so be careful.
3758 ;; Your init file should contain only one such instance.
3759 ;; If there is more than one, they won't work right.\n")
3760 (dolist (symbol saved-list)
3761 (let ((spec (car-safe (get symbol 'theme-value)))
3762 (value (get symbol 'saved-value))
3763 (requests (get symbol 'custom-requests))
3764 (now (not (or (custom-variable-p symbol)
3765 (and (not (boundp symbol))
3766 (not (eq (get symbol 'force-value)
3767 'rogue))))))
3768 (comment (get symbol 'saved-variable-comment)))
3769 ;; Check `requests'.
3770 (dolist (request requests)
3771 (when (and (symbolp request) (not (featurep request)))
3772 (message "Unknown requested feature: %s" request)
3773 (setq requests (delq request requests))))
3774 (when (or (and spec
3775 (eq (nth 0 spec) 'user)
3776 (eq (nth 1 spec) 'set))
3777 comment
3778 (and (null spec) (get symbol 'saved-value)))
3779 (unless (bolp)
3780 (princ "\n"))
3781 (princ " '(")
3782 (prin1 symbol)
3783 (princ " ")
3784 (prin1 (car value))
3785 (when (or now requests comment)
3786 (princ " ")
3787 (prin1 now)
3788 (when (or requests comment)
3789 (princ " ")
3790 (prin1 requests)
3791 (when comment
3792 (princ " ")
3793 (prin1 comment))))
3794 (princ ")"))))
3795 (if (bolp)
3796 (princ " "))
3797 (princ ")")
3798 (unless (looking-at "\n")
3799 (princ "\n")))))
3801 (defun custom-save-faces ()
3802 "Save all customized faces in `custom-file'."
3803 (save-excursion
3804 (custom-save-delete 'custom-reset-faces)
3805 (custom-save-delete 'custom-set-faces)
3806 (custom-save-resets 'theme-face 'custom-reset-faces '(default))
3807 (let ((standard-output (current-buffer))
3808 (saved-list (make-list 1 0))
3809 sort-fold-case)
3810 ;; First create a sorted list of saved faces.
3811 (mapatoms
3812 (lambda (symbol)
3813 (if (get symbol 'saved-face)
3814 (nconc saved-list (list symbol)))))
3815 (setq saved-list (sort (cdr saved-list) 'string<))
3816 ;; The default face must be first, since it affects the others.
3817 (if (memq 'default saved-list)
3818 (setq saved-list (cons 'default (delq 'default saved-list))))
3819 (unless (bolp)
3820 (princ "\n"))
3821 (princ "(custom-set-faces
3822 ;; custom-set-faces was added by Custom.
3823 ;; If you edit it by hand, you could mess it up, so be careful.
3824 ;; Your init file should contain only one such instance.
3825 ;; If there is more than one, they won't work right.\n")
3826 (dolist (symbol saved-list)
3827 (let ((spec (car-safe (get symbol 'theme-face)))
3828 (value (get symbol 'saved-face))
3829 (now (not (or (get symbol 'face-defface-spec)
3830 (and (not (custom-facep symbol))
3831 (not (get symbol 'force-face))))))
3832 (comment (get symbol 'saved-face-comment)))
3833 (when (or (and spec
3834 (eq (nth 0 spec) 'user)
3835 (eq (nth 1 spec) 'set))
3836 comment
3837 (and (null spec) (get symbol 'saved-face)))
3838 ;; Don't print default face here.
3839 (unless (bolp)
3840 (princ "\n"))
3841 (princ " '(")
3842 (prin1 symbol)
3843 (princ " ")
3844 (prin1 value)
3845 (when (or now comment)
3846 (princ " ")
3847 (prin1 now)
3848 (when comment
3849 (princ " ")
3850 (prin1 comment)))
3851 (princ ")"))))
3852 (if (bolp)
3853 (princ " "))
3854 (princ ")")
3855 (unless (looking-at "\n")
3856 (princ "\n")))))
3858 (defun custom-save-resets (property setter special)
3859 (let (started-writing ignored-special)
3860 ;; (custom-save-delete setter) Done by caller
3861 (let ((standard-output (current-buffer))
3862 (mapper `(lambda (object)
3863 (let ((spec (car-safe (get object (quote ,property)))))
3864 (when (and (not (memq object ignored-special))
3865 (eq (nth 0 spec) 'user)
3866 (eq (nth 1 spec) 'reset))
3867 ;; Do not write reset statements unless necessary.
3868 (unless started-writing
3869 (setq started-writing t)
3870 (unless (bolp)
3871 (princ "\n"))
3872 (princ "(")
3873 (princ (quote ,setter))
3874 (princ "\n '(")
3875 (prin1 object)
3876 (princ " ")
3877 (prin1 (nth 3 spec))
3878 (princ ")")))))))
3879 (mapc mapper special)
3880 (setq ignored-special special)
3881 (mapatoms mapper)
3882 (when started-writing
3883 (princ ")\n")))))
3885 (defun custom-save-loaded-themes ()
3886 (let ((themes (reverse (get 'user 'theme-loads-themes)))
3887 (standard-output (current-buffer)))
3888 (when themes
3889 (unless (bolp) (princ "\n"))
3890 (princ "(custom-load-themes")
3891 (mapc (lambda (theme)
3892 (princ "\n '")
3893 (prin1 theme)) themes)
3894 (princ " )\n"))))
3896 ;;;###autoload
3897 (defun customize-save-customized ()
3898 "Save all user options which have been set in this session."
3899 (interactive)
3900 (mapatoms (lambda (symbol)
3901 (let ((face (get symbol 'customized-face))
3902 (value (get symbol 'customized-value))
3903 (face-comment (get symbol 'customized-face-comment))
3904 (variable-comment
3905 (get symbol 'customized-variable-comment)))
3906 (when face
3907 (put symbol 'saved-face face)
3908 (custom-push-theme 'theme-face symbol 'user 'set value)
3909 (put symbol 'customized-face nil))
3910 (when value
3911 (put symbol 'saved-value value)
3912 (custom-push-theme 'theme-value symbol 'user 'set value)
3913 (put symbol 'customized-value nil))
3914 (when variable-comment
3915 (put symbol 'saved-variable-comment variable-comment)
3916 (put symbol 'customized-variable-comment nil))
3917 (when face-comment
3918 (put symbol 'saved-face-comment face-comment)
3919 (put symbol 'customized-face-comment nil)))))
3920 ;; We really should update all custom buffers here.
3921 (custom-save-all))
3923 ;;;###autoload
3924 (defun custom-save-all ()
3925 "Save all customizations in `custom-file'."
3926 (let ((inhibit-read-only t))
3927 (custom-save-variables)
3928 (custom-save-faces)
3929 (save-excursion
3930 (let ((default-major-mode nil))
3931 (set-buffer (find-file-noselect (custom-file))))
3932 (let ((file-precious-flag t))
3933 (save-buffer)))))
3935 ;;; The Customize Menu.
3937 ;;; Menu support
3939 (defcustom custom-menu-nesting 2
3940 "Maximum nesting in custom menus."
3941 :type 'integer
3942 :group 'custom-menu)
3944 (defun custom-face-menu-create (widget symbol)
3945 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3946 (vector (custom-unlispify-menu-entry symbol)
3947 `(customize-face ',symbol)
3950 (defun custom-variable-menu-create (widget symbol)
3951 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3952 (let ((type (get symbol 'custom-type)))
3953 (unless (listp type)
3954 (setq type (list type)))
3955 (if (and type (widget-get type :custom-menu))
3956 (widget-apply type :custom-menu symbol)
3957 (vector (custom-unlispify-menu-entry symbol)
3958 `(customize-variable ',symbol)
3959 t))))
3961 ;; Add checkboxes to boolean variable entries.
3962 (widget-put (get 'boolean 'widget-type)
3963 :custom-menu (lambda (widget symbol)
3964 (vector (custom-unlispify-menu-entry symbol)
3965 `(customize-variable ',symbol)
3966 ':style 'toggle
3967 ':selected symbol)))
3969 (defun custom-group-menu-create (widget symbol)
3970 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3971 `( ,(custom-unlispify-menu-entry symbol t)
3972 :filter (lambda (&rest junk)
3973 (let ((menu (custom-menu-create ',symbol)))
3974 (if (consp menu) (cdr menu) menu)))))
3976 ;;;###autoload
3977 (defun custom-menu-create (symbol)
3978 "Create menu for customization group SYMBOL.
3979 The menu is in a format applicable to `easy-menu-define'."
3980 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3981 `(customize-group ',symbol)
3982 t)))
3983 (if (and (or (not (boundp 'custom-menu-nesting))
3984 (>= custom-menu-nesting 0))
3985 (progn
3986 (custom-load-symbol symbol)
3987 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
3988 (let ((custom-prefix-list (custom-prefix-add symbol
3989 custom-prefix-list))
3990 (members (custom-sort-items (get symbol 'custom-group)
3991 custom-menu-sort-alphabetically
3992 custom-menu-order-groups)))
3993 `(,(custom-unlispify-menu-entry symbol t)
3994 ,item
3995 "--"
3996 ,@(mapcar (lambda (entry)
3997 (widget-apply (if (listp (nth 1 entry))
3998 (nth 1 entry)
3999 (list (nth 1 entry)))
4000 :custom-menu (nth 0 entry)))
4001 members)))
4002 item)))
4004 ;;;###autoload
4005 (defun customize-menu-create (symbol &optional name)
4006 "Return a customize menu for customization group SYMBOL.
4007 If optional NAME is given, use that as the name of the menu.
4008 Otherwise the menu will be named `Customize'.
4009 The format is suitable for use with `easy-menu-define'."
4010 (unless name
4011 (setq name "Customize"))
4012 `(,name
4013 :filter (lambda (&rest junk)
4014 (let ((menu (custom-menu-create ',symbol)))
4015 (if (consp menu) (cdr menu) menu)))))
4017 ;;; The Custom Mode.
4019 (defvar custom-mode-map nil
4020 "Keymap for `custom-mode'.")
4022 (unless custom-mode-map
4023 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4024 ;; "\r" bindings from the parent map.
4025 (setq custom-mode-map (make-sparse-keymap))
4026 (set-keymap-parent custom-mode-map widget-keymap)
4027 (suppress-keymap custom-mode-map)
4028 (define-key custom-mode-map " " 'scroll-up)
4029 (define-key custom-mode-map "\177" 'scroll-down)
4030 (define-key custom-mode-map "\C-x\C-s" 'Custom-save)
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