(set-visited-file-name, file-expand-wildcards): Fix docstring.
[emacs.git] / lisp / cus-edit.el
blob11b91242cc2d91e1bd3bcb1f6c8d30bc6a1a1861
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 SYMBOL, which should be a face name or nil.
1016 If SYMBOL is nil, customize all faces.
1018 Interactively, when point is on text which has a face specified,
1019 suggest to customized 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 SYMBOL in other window.
1043 Interactively, when point is on text which has a face specified,
1044 suggest to customized 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 has 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 has 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 Only match frames with the specified intensity.")
2733 (const :format "\
2734 Background brightness: "
2735 background)
2736 (checklist :inline t
2737 :offset 0
2738 (const :format "Light "
2739 :sibling-args (:help-echo "\
2740 Match frames with light backgrounds.")
2741 light)
2742 (const :format "Dark\n"
2743 :sibling-args (:help-echo "\
2744 Match frames with dark backgrounds.")
2745 dark)))
2746 (group :sibling-args (:help-echo "\
2747 Only match frames that support the specified face attributes.")
2748 (const :format "Supports attributes:" supports)
2749 (custom-face-edit :inline t :format "%n%v"))))))
2751 ;;; The `custom-face' Widget.
2753 (defface custom-face-tag-face
2754 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
2755 "Face used for face tags."
2756 :group 'custom-faces)
2758 (defcustom custom-face-default-form 'selected
2759 "Default form of displaying face definition."
2760 :type '(choice (const all)
2761 (const selected)
2762 (const lisp))
2763 :group 'custom-buffer
2764 :version "20.3")
2766 (define-widget 'custom-face 'custom
2767 "Customize face."
2768 :sample-face 'custom-face-tag-face
2769 :help-echo "Set or reset this face."
2770 :documentation-property #'face-doc-string
2771 :value-create 'custom-face-value-create
2772 :action 'custom-face-action
2773 :custom-category 'face
2774 :custom-form nil ; defaults to value of `custom-face-default-form'
2775 :custom-set 'custom-face-set
2776 :custom-save 'custom-face-save
2777 :custom-reset-current 'custom-redraw
2778 :custom-reset-saved 'custom-face-reset-saved
2779 :custom-reset-standard 'custom-face-reset-standard
2780 :custom-standard-value 'custom-face-standard-value
2781 :custom-menu 'custom-face-menu-create)
2783 (define-widget 'custom-face-all 'editable-list
2784 "An editable list of display specifications and attributes."
2785 :entry-format "%i %d %v"
2786 :insert-button-args '(:help-echo "Insert new display specification here.")
2787 :append-button-args '(:help-echo "Append new display specification here.")
2788 :delete-button-args '(:help-echo "Delete this display specification.")
2789 :args '((group :format "%v" custom-display custom-face-edit)))
2791 (defconst custom-face-all (widget-convert 'custom-face-all)
2792 "Converted version of the `custom-face-all' widget.")
2794 (define-widget 'custom-display-unselected 'item
2795 "A display specification that doesn't match the selected display."
2796 :match 'custom-display-unselected-match)
2798 (defun custom-display-unselected-match (widget value)
2799 "Non-nil if VALUE is an unselected display specification."
2800 (not (face-spec-set-match-display value (selected-frame))))
2802 (define-widget 'custom-face-selected 'group
2803 "Edit the attributes of the selected display in a face specification."
2804 :args '((repeat :format ""
2805 :inline t
2806 (group custom-display-unselected sexp))
2807 (group (sexp :format "") custom-face-edit)
2808 (repeat :format ""
2809 :inline t
2810 sexp)))
2812 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2813 "Converted version of the `custom-face-selected' widget.")
2815 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
2816 "Return a canonicalized version of SPEC using.
2817 FILTER-INDEX is the index in the entry for each attribute in
2818 `custom-face-attributes' at which the appropriate filter function can be
2819 found, and DEFAULT-FILTER is the filter to apply for attributes that
2820 don't specify one."
2821 (mapcar (lambda (entry)
2822 ;; Filter a single face-spec entry
2823 (let ((tests (car entry))
2824 (unfiltered-attrs
2825 ;; Handle both old- and new-style attribute syntax
2826 (if (listp (car (cdr entry)))
2827 (car (cdr entry))
2828 (cdr entry)))
2829 (filtered-attrs nil))
2830 ;; Filter each face attribute
2831 (while unfiltered-attrs
2832 (let* ((attr (pop unfiltered-attrs))
2833 (pre-filtered-value (pop unfiltered-attrs))
2834 (filter
2835 (or (nth filter-index (assq attr custom-face-attributes))
2836 default-filter))
2837 (filtered-value
2838 (if filter
2839 (funcall filter pre-filtered-value)
2840 pre-filtered-value)))
2841 (push filtered-value filtered-attrs)
2842 (push attr filtered-attrs)))
2844 (list tests filtered-attrs)))
2845 spec))
2847 (defun custom-pre-filter-face-spec (spec)
2848 "Return SPEC changed as necessary for editing by the face customization widget.
2849 SPEC must be a full face spec."
2850 (custom-filter-face-spec spec 2))
2852 (defun custom-post-filter-face-spec (spec)
2853 "Return the customized SPEC in a form suitable for setting the face."
2854 (custom-filter-face-spec spec 3))
2856 (defun custom-face-value-create (widget)
2857 "Create a list of the display specifications for WIDGET."
2858 (let ((buttons (widget-get widget :buttons))
2859 children
2860 (symbol (widget-get widget :value))
2861 (tag (widget-get widget :tag))
2862 (state (widget-get widget :custom-state))
2863 (begin (point))
2864 (is-last (widget-get widget :custom-last))
2865 (prefix (widget-get widget :custom-prefix)))
2866 (unless tag
2867 (setq tag (prin1-to-string symbol)))
2868 (cond ((eq custom-buffer-style 'tree)
2869 (insert prefix (if is-last " `--- " " |--- "))
2870 (push (widget-create-child-and-convert
2871 widget 'custom-browse-face-tag)
2872 buttons)
2873 (insert " " tag "\n")
2874 (widget-put widget :buttons buttons))
2876 ;; Create tag.
2877 (insert tag)
2878 (widget-specify-sample widget begin (point))
2879 (if (eq custom-buffer-style 'face)
2880 (insert " ")
2881 (if (string-match "face\\'" tag)
2882 (insert ":")
2883 (insert " face: ")))
2884 ;; Sample.
2885 (push (widget-create-child-and-convert widget 'item
2886 :format "(%{%t%})"
2887 :sample-face symbol
2888 :tag "sample")
2889 buttons)
2890 ;; Visibility.
2891 (insert " ")
2892 (push (widget-create-child-and-convert
2893 widget 'visibility
2894 :help-echo "Hide or show this face."
2895 :on "Hide Face"
2896 :off "Show Face"
2897 :action 'custom-toggle-parent
2898 (not (eq state 'hidden)))
2899 buttons)
2900 ;; Magic.
2901 (insert "\n")
2902 (let ((magic (widget-create-child-and-convert
2903 widget 'custom-magic nil)))
2904 (widget-put widget :custom-magic magic)
2905 (push magic buttons))
2906 ;; Update buttons.
2907 (widget-put widget :buttons buttons)
2908 ;; Insert documentation.
2909 (widget-default-format-handler widget ?h)
2910 ;; The comment field
2911 (unless (eq state 'hidden)
2912 (let* ((comment (get symbol 'face-comment))
2913 (comment-widget
2914 (widget-create-child-and-convert
2915 widget 'custom-comment
2916 :parent widget
2917 :value (or comment ""))))
2918 (widget-put widget :comment-widget comment-widget)
2919 (push comment-widget children)))
2920 ;; See also.
2921 (unless (eq state 'hidden)
2922 (when (eq (widget-get widget :custom-level) 1)
2923 (custom-add-parent-links widget))
2924 (custom-add-see-also widget))
2925 ;; Editor.
2926 (unless (eq (preceding-char) ?\n)
2927 (insert "\n"))
2928 (unless (eq state 'hidden)
2929 (message "Creating face editor...")
2930 (custom-load-widget widget)
2931 (unless (widget-get widget :custom-form)
2932 (widget-put widget :custom-form custom-face-default-form))
2933 (let* ((symbol (widget-value widget))
2934 (spec (or (get symbol 'customized-face)
2935 (get symbol 'saved-face)
2936 (get symbol 'face-defface-spec)
2937 ;; Attempt to construct it.
2938 (list (list t (custom-face-attributes-get
2939 symbol (selected-frame))))))
2940 (form (widget-get widget :custom-form))
2941 (indent (widget-get widget :indent))
2942 edit)
2943 ;; If the user has changed this face in some other way,
2944 ;; edit it as the user has specified it.
2945 (if (not (face-spec-match-p symbol spec (selected-frame)))
2946 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
2947 (setq spec (custom-pre-filter-face-spec spec))
2948 (setq edit (widget-create-child-and-convert
2949 widget
2950 (cond ((and (eq form 'selected)
2951 (widget-apply custom-face-selected
2952 :match spec))
2953 (when indent (insert-char ?\ indent))
2954 'custom-face-selected)
2955 ((and (not (eq form 'lisp))
2956 (widget-apply custom-face-all
2957 :match spec))
2958 'custom-face-all)
2960 (when indent (insert-char ?\ indent))
2961 'sexp))
2962 :value spec))
2963 (custom-face-state-set widget)
2964 (push edit children)
2965 (widget-put widget :children children))
2966 (message "Creating face editor...done"))))))
2968 (defvar custom-face-menu
2969 '(("Set for Current Session" custom-face-set)
2970 ("Save for Future Sessions" custom-face-save-command)
2971 ("Reset to Saved" custom-face-reset-saved
2972 (lambda (widget)
2973 (or (get (widget-value widget) 'saved-face)
2974 (get (widget-value widget) 'saved-face-comment))))
2975 ("Erase Customization" custom-face-reset-standard
2976 (lambda (widget)
2977 (get (widget-value widget) 'face-defface-spec)))
2978 ("---" ignore ignore)
2979 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2980 ("---" ignore ignore)
2981 ("Show all display specs" custom-face-edit-all
2982 (lambda (widget)
2983 (not (eq (widget-get widget :custom-form) 'all))))
2984 ("Just current attributes" custom-face-edit-selected
2985 (lambda (widget)
2986 (not (eq (widget-get widget :custom-form) 'selected))))
2987 ("Show as Lisp expression" custom-face-edit-lisp
2988 (lambda (widget)
2989 (not (eq (widget-get widget :custom-form) 'lisp)))))
2990 "Alist of actions for the `custom-face' widget.
2991 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2992 the menu entry, ACTION is the function to call on the widget when the
2993 menu is selected, and FILTER is a predicate which takes a `custom-face'
2994 widget as an argument, and returns non-nil if ACTION is valid on that
2995 widget. If FILTER is nil, ACTION is always valid.")
2997 (defun custom-face-edit-selected (widget)
2998 "Edit selected attributes of the value of WIDGET."
2999 (widget-put widget :custom-state 'unknown)
3000 (widget-put widget :custom-form 'selected)
3001 (custom-redraw widget))
3003 (defun custom-face-edit-all (widget)
3004 "Edit all attributes of the value of WIDGET."
3005 (widget-put widget :custom-state 'unknown)
3006 (widget-put widget :custom-form 'all)
3007 (custom-redraw widget))
3009 (defun custom-face-edit-lisp (widget)
3010 "Edit the Lisp representation of the value of WIDGET."
3011 (widget-put widget :custom-state 'unknown)
3012 (widget-put widget :custom-form 'lisp)
3013 (custom-redraw widget))
3015 (defun custom-face-state-set (widget)
3016 "Set the state of WIDGET."
3017 (let* ((symbol (widget-value widget))
3018 (comment (get symbol 'face-comment))
3019 tmp temp
3020 (state
3021 (cond ((progn
3022 (setq tmp (get symbol 'customized-face))
3023 (setq temp (get symbol 'customized-face-comment))
3024 (or tmp temp))
3025 (if (equal temp comment)
3026 'set
3027 'changed))
3028 ((progn
3029 (setq tmp (get symbol 'saved-face))
3030 (setq temp (get symbol 'saved-face-comment))
3031 (or tmp temp))
3032 (if (equal temp comment)
3033 'saved
3034 'changed))
3035 ((get symbol 'face-defface-spec)
3036 (if (equal comment nil)
3037 'standard
3038 'changed))
3040 'rogue))))
3041 ;; If the user called set-face-attribute to change the default
3042 ;; for new frames, this face is "set outside of Customize".
3043 (if (and (not (eq state 'rogue))
3044 (get symbol 'face-modified))
3045 (setq state 'changed))
3046 (widget-put widget :custom-state state)))
3048 (defun custom-face-action (widget &optional event)
3049 "Show the menu for `custom-face' WIDGET.
3050 Optional EVENT is the location for the menu."
3051 (if (eq (widget-get widget :custom-state) 'hidden)
3052 (custom-toggle-hide widget)
3053 (let* ((completion-ignore-case t)
3054 (symbol (widget-get widget :value))
3055 (answer (widget-choose (concat "Operation on "
3056 (custom-unlispify-tag-name symbol))
3057 (custom-menu-filter custom-face-menu
3058 widget)
3059 event)))
3060 (if answer
3061 (funcall answer widget)))))
3063 (defun custom-face-set (widget)
3064 "Make the face attributes in WIDGET take effect."
3065 (let* ((symbol (widget-value widget))
3066 (child (car (widget-get widget :children)))
3067 (value (custom-post-filter-face-spec (widget-value child)))
3068 (comment-widget (widget-get widget :comment-widget))
3069 (comment (widget-value comment-widget)))
3070 (when (equal comment "")
3071 (setq comment nil)
3072 ;; Make the comment invisible by hand if it's empty
3073 (custom-comment-hide comment-widget))
3074 (put symbol 'customized-face value)
3075 (if (face-spec-choose value)
3076 (face-spec-set symbol value)
3077 ;; face-set-spec ignores empty attribute lists, so just give it
3078 ;; something harmless instead.
3079 (face-spec-set symbol '((t :foreground unspecified))))
3080 (put symbol 'customized-face-comment comment)
3081 (put symbol 'face-comment comment)
3082 (custom-face-state-set widget)
3083 (custom-redraw-magic widget)))
3085 (defun custom-face-save-command (widget)
3086 "Save in `.emacs' the face attributes in WIDGET."
3087 (custom-face-save widget)
3088 (custom-save-all))
3090 (defun custom-face-save (widget)
3091 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3092 (let* ((symbol (widget-value widget))
3093 (child (car (widget-get widget :children)))
3094 (value (custom-post-filter-face-spec (widget-value child)))
3095 (comment-widget (widget-get widget :comment-widget))
3096 (comment (widget-value comment-widget)))
3097 (when (equal comment "")
3098 (setq comment nil)
3099 ;; Make the comment invisible by hand if it's empty
3100 (custom-comment-hide comment-widget))
3101 (if (face-spec-choose value)
3102 (face-spec-set symbol value)
3103 ;; face-set-spec ignores empty attribute lists, so just give it
3104 ;; something harmless instead.
3105 (face-spec-set symbol '((t :foreground unspecified))))
3106 (unless (eq (widget-get widget :custom-state) 'standard)
3107 (put symbol 'saved-face value))
3108 (custom-push-theme 'theme-face symbol 'user 'set value)
3109 (put symbol 'customized-face nil)
3110 (put symbol 'face-comment comment)
3111 (put symbol 'customized-face-comment nil)
3112 (put symbol 'saved-face-comment comment)
3113 (custom-save-all)
3114 (custom-face-state-set widget)
3115 (custom-redraw-magic widget)))
3117 (defun custom-face-reset-saved (widget)
3118 "Restore WIDGET to the face's default attributes."
3119 (let* ((symbol (widget-value widget))
3120 (child (car (widget-get widget :children)))
3121 (value (get symbol 'saved-face))
3122 (comment (get symbol 'saved-face-comment))
3123 (comment-widget (widget-get widget :comment-widget)))
3124 (unless (or value comment)
3125 (error "No saved value for this face"))
3126 (put symbol 'customized-face nil)
3127 (put symbol 'customized-face-comment nil)
3128 (face-spec-set symbol value)
3129 (put symbol 'face-comment comment)
3130 (widget-value-set child value)
3131 ;; This call manages the comment visibility
3132 (widget-value-set comment-widget (or comment ""))
3133 (custom-face-state-set widget)
3134 (custom-redraw-magic widget)))
3136 (defun custom-face-standard-value (widget)
3137 (get (widget-value widget) 'face-defface-spec))
3139 (defun custom-face-reset-standard (widget)
3140 "Restore WIDGET to the face's standard settings.
3141 This operation eliminates any saved setting for the face,
3142 restoring it to the state of a face that has never been customized."
3143 (let* ((symbol (widget-value widget))
3144 (child (car (widget-get widget :children)))
3145 (value (get symbol 'face-defface-spec))
3146 (comment-widget (widget-get widget :comment-widget)))
3147 (unless value
3148 (error "No standard setting for this face"))
3149 (put symbol 'customized-face nil)
3150 (put symbol 'customized-face-comment nil)
3151 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3152 (put symbol 'saved-face nil)
3153 (custom-push-theme 'theme-face symbol 'user 'reset 'standard)
3154 ;; Do not explictly save resets to standards without themes.
3155 (if (null (cdr (get symbol 'theme-face)))
3156 (put symbol 'theme-face nil))
3157 (put symbol 'saved-face-comment nil)
3158 (custom-save-all))
3159 (face-spec-set symbol value)
3160 (put symbol 'face-comment nil)
3161 (widget-value-set child value)
3162 ;; This call manages the comment visibility
3163 (widget-value-set comment-widget "")
3164 (custom-face-state-set widget)
3165 (custom-redraw-magic widget)))
3167 ;;; The `face' Widget.
3169 (define-widget 'face 'default
3170 "Select and customize a face."
3171 :convert-widget 'widget-value-convert-widget
3172 :button-prefix 'widget-push-button-prefix
3173 :button-suffix 'widget-push-button-suffix
3174 :format "%{%t%}: %[select face%] %v"
3175 :tag "Face"
3176 :value 'default
3177 :value-create 'widget-face-value-create
3178 :value-delete 'widget-face-value-delete
3179 :value-get 'widget-value-value-get
3180 :validate 'widget-children-validate
3181 :action 'widget-face-action
3182 :match (lambda (widget value) (symbolp value)))
3184 (defun widget-face-value-create (widget)
3185 "Create a `custom-face' child."
3186 (let* ((symbol (widget-value widget))
3187 (custom-buffer-style 'face)
3188 (child (widget-create-child-and-convert
3189 widget 'custom-face
3190 :custom-level nil
3191 :value symbol)))
3192 (custom-magic-reset child)
3193 (setq custom-options (cons child custom-options))
3194 (widget-put widget :children (list child))))
3196 (defun widget-face-value-delete (widget)
3197 "Remove the child from the options."
3198 (let ((child (car (widget-get widget :children))))
3199 (setq custom-options (delq child custom-options))
3200 (widget-children-value-delete widget)))
3202 (defvar face-history nil
3203 "History of entered face names.")
3205 (defun widget-face-action (widget &optional event)
3206 "Prompt for a face."
3207 (let ((answer (completing-read "Face: "
3208 (mapcar (lambda (face)
3209 (list (symbol-name face)))
3210 (face-list))
3211 nil nil nil
3212 'face-history)))
3213 (unless (zerop (length answer))
3214 (widget-value-set widget (intern answer))
3215 (widget-apply widget :notify widget event)
3216 (widget-setup))))
3218 ;;; The `hook' Widget.
3220 (define-widget 'hook 'list
3221 "A emacs lisp hook"
3222 :value-to-internal (lambda (widget value)
3223 (if (and value (symbolp value))
3224 (list value)
3225 value))
3226 :match (lambda (widget value)
3227 (or (symbolp value)
3228 (widget-group-match widget value)))
3229 ;; Avoid adding undefined functions to the hook, especially for
3230 ;; things like `find-file-hook' or even more basic ones, to avoid
3231 ;; chaos.
3232 :set (lambda (symbol value)
3233 (dolist (elt value)
3234 (if (fboundp elt)
3235 (add-hook symbol elt))))
3236 :convert-widget 'custom-hook-convert-widget
3237 :tag "Hook")
3239 (defun custom-hook-convert-widget (widget)
3240 ;; Handle `:options'.
3241 (let* ((options (widget-get widget :options))
3242 (other `(editable-list :inline t
3243 :entry-format "%i %d%v"
3244 (function :format " %v")))
3245 (args (if options
3246 (list `(checklist :inline t
3247 ,@(mapcar (lambda (entry)
3248 `(function-item ,entry))
3249 options))
3250 other)
3251 (list other))))
3252 (widget-put widget :args args)
3253 widget))
3255 ;;; The `custom-group-link' Widget.
3257 (define-widget 'custom-group-link 'link
3258 "Show parent in other window when activated."
3259 :help-echo "Create customization buffer for this group."
3260 :action 'custom-group-link-action)
3262 (defun custom-group-link-action (widget &rest ignore)
3263 (customize-group (widget-value widget)))
3265 ;;; The `custom-group' Widget.
3267 (defcustom custom-group-tag-faces nil
3268 ;; In XEmacs, this ought to play games with font size.
3269 ;; Fixme: make it do so in Emacs.
3270 "Face used for group tags.
3271 The first member is used for level 1 groups, the second for level 2,
3272 and so forth. The remaining group tags are shown with
3273 `custom-group-tag-face'."
3274 :type '(repeat face)
3275 :group 'custom-faces)
3277 (defface custom-group-tag-face-1
3278 `((((class color)
3279 (background dark))
3280 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3281 (((class color)
3282 (background light))
3283 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3284 (t (:weight bold)))
3285 "Face used for group tags."
3286 :group 'custom-faces)
3288 (defface custom-group-tag-face
3289 `((((class color)
3290 (background dark))
3291 (:foreground "light blue" :weight bold :height 1.2))
3292 (((class color)
3293 (background light))
3294 (:foreground "blue" :weight bold :height 1.2))
3295 (t (:weight bold)))
3296 "Face used for low level group tags."
3297 :group 'custom-faces)
3299 (define-widget 'custom-group 'custom
3300 "Customize group."
3301 :format "%v"
3302 :sample-face-get 'custom-group-sample-face-get
3303 :documentation-property 'group-documentation
3304 :help-echo "Set or reset all members of this group."
3305 :value-create 'custom-group-value-create
3306 :action 'custom-group-action
3307 :custom-category 'group
3308 :custom-set 'custom-group-set
3309 :custom-save 'custom-group-save
3310 :custom-reset-current 'custom-group-reset-current
3311 :custom-reset-saved 'custom-group-reset-saved
3312 :custom-reset-standard 'custom-group-reset-standard
3313 :custom-menu 'custom-group-menu-create)
3315 (defun custom-group-sample-face-get (widget)
3316 ;; Use :sample-face.
3317 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3318 'custom-group-tag-face))
3320 (define-widget 'custom-group-visibility 'visibility
3321 "An indicator and manipulator for hidden group contents."
3322 :create 'custom-group-visibility-create)
3324 (defun custom-group-visibility-create (widget)
3325 (let ((visible (widget-value widget)))
3326 (if visible
3327 (insert "--------")))
3328 (widget-default-create widget))
3330 (defun custom-group-members (symbol groups-only)
3331 "Return SYMBOL's custom group members.
3332 If GROUPS-ONLY non-nil, return only those members that are groups."
3333 (if (not groups-only)
3334 (get symbol 'custom-group)
3335 (let (members)
3336 (dolist (entry (get symbol 'custom-group))
3337 (when (eq (nth 1 entry) 'custom-group)
3338 (push entry members)))
3339 (nreverse members))))
3341 (defun custom-group-value-create (widget)
3342 "Insert a customize group for WIDGET in the current buffer."
3343 (unless (eq (widget-get widget :custom-state) 'hidden)
3344 (custom-load-widget widget))
3345 (let* ((state (widget-get widget :custom-state))
3346 (level (widget-get widget :custom-level))
3347 ;; (indent (widget-get widget :indent))
3348 (prefix (widget-get widget :custom-prefix))
3349 (buttons (widget-get widget :buttons))
3350 (tag (widget-get widget :tag))
3351 (symbol (widget-value widget))
3352 (members (custom-group-members symbol
3353 (and (eq custom-buffer-style 'tree)
3354 custom-browse-only-groups))))
3355 (cond ((and (eq custom-buffer-style 'tree)
3356 (eq state 'hidden)
3357 (or members (custom-unloaded-widget-p widget)))
3358 (custom-browse-insert-prefix prefix)
3359 (push (widget-create-child-and-convert
3360 widget 'custom-browse-visibility
3361 ;; :tag-glyph "plus"
3362 :tag "+")
3363 buttons)
3364 (insert "-- ")
3365 ;; (widget-glyph-insert nil "-- " "horizontal")
3366 (push (widget-create-child-and-convert
3367 widget 'custom-browse-group-tag)
3368 buttons)
3369 (insert " " tag "\n")
3370 (widget-put widget :buttons buttons))
3371 ((and (eq custom-buffer-style 'tree)
3372 (zerop (length members)))
3373 (custom-browse-insert-prefix prefix)
3374 (insert "[ ]-- ")
3375 ;; (widget-glyph-insert nil "[ ]" "empty")
3376 ;; (widget-glyph-insert nil "-- " "horizontal")
3377 (push (widget-create-child-and-convert
3378 widget 'custom-browse-group-tag)
3379 buttons)
3380 (insert " " tag "\n")
3381 (widget-put widget :buttons buttons))
3382 ((eq custom-buffer-style 'tree)
3383 (custom-browse-insert-prefix prefix)
3384 (if (zerop (length members))
3385 (progn
3386 (custom-browse-insert-prefix prefix)
3387 (insert "[ ]-- ")
3388 ;; (widget-glyph-insert nil "[ ]" "empty")
3389 ;; (widget-glyph-insert nil "-- " "horizontal")
3390 (push (widget-create-child-and-convert
3391 widget 'custom-browse-group-tag)
3392 buttons)
3393 (insert " " tag "\n")
3394 (widget-put widget :buttons buttons))
3395 (push (widget-create-child-and-convert
3396 widget 'custom-browse-visibility
3397 ;; :tag-glyph "minus"
3398 :tag "-")
3399 buttons)
3400 (insert "-\\ ")
3401 ;; (widget-glyph-insert nil "-\\ " "top")
3402 (push (widget-create-child-and-convert
3403 widget 'custom-browse-group-tag)
3404 buttons)
3405 (insert " " tag "\n")
3406 (widget-put widget :buttons buttons)
3407 (message "Creating group...")
3408 (let* ((members (custom-sort-items members
3409 custom-browse-sort-alphabetically
3410 custom-browse-order-groups))
3411 (prefixes (widget-get widget :custom-prefixes))
3412 (custom-prefix-list (custom-prefix-add symbol prefixes))
3413 (extra-prefix (if (widget-get widget :custom-last)
3415 " | "))
3416 (prefix (concat prefix extra-prefix))
3417 children entry)
3418 (while members
3419 (setq entry (car members)
3420 members (cdr members))
3421 (push (widget-create-child-and-convert
3422 widget (nth 1 entry)
3423 :group widget
3424 :tag (custom-unlispify-tag-name (nth 0 entry))
3425 :custom-prefixes custom-prefix-list
3426 :custom-level (1+ level)
3427 :custom-last (null members)
3428 :value (nth 0 entry)
3429 :custom-prefix prefix)
3430 children))
3431 (widget-put widget :children (reverse children)))
3432 (message "Creating group...done")))
3433 ;; Nested style.
3434 ((eq state 'hidden)
3435 ;; Create level indicator.
3436 (unless (eq custom-buffer-style 'links)
3437 (insert-char ?\ (* custom-buffer-indent (1- level)))
3438 (insert "-- "))
3439 ;; Create tag.
3440 (let ((begin (point)))
3441 (insert tag)
3442 (widget-specify-sample widget begin (point)))
3443 (insert " group: ")
3444 ;; Create link/visibility indicator.
3445 (if (eq custom-buffer-style 'links)
3446 (push (widget-create-child-and-convert
3447 widget 'custom-group-link
3448 :tag "Go to Group"
3449 symbol)
3450 buttons)
3451 (push (widget-create-child-and-convert
3452 widget 'custom-group-visibility
3453 :help-echo "Show members of this group."
3454 :action 'custom-toggle-parent
3455 (not (eq state 'hidden)))
3456 buttons))
3457 (insert " \n")
3458 ;; Create magic button.
3459 (let ((magic (widget-create-child-and-convert
3460 widget 'custom-magic nil)))
3461 (widget-put widget :custom-magic magic)
3462 (push magic buttons))
3463 ;; Update buttons.
3464 (widget-put widget :buttons buttons)
3465 ;; Insert documentation.
3466 (if (and (eq custom-buffer-style 'links) (> level 1))
3467 (widget-put widget :documentation-indent 0))
3468 (widget-default-format-handler widget ?h))
3469 ;; Nested style.
3470 (t ;Visible.
3471 ;; Add parent groups references above the group.
3472 (if t ;;; This should test that the buffer
3473 ;;; was made to display a group.
3474 (when (eq level 1)
3475 (if (custom-add-parent-links widget
3476 "Go to parent group:")
3477 (insert "\n"))))
3478 ;; Create level indicator.
3479 (insert-char ?\ (* custom-buffer-indent (1- level)))
3480 (insert "/- ")
3481 ;; Create tag.
3482 (let ((start (point)))
3483 (insert tag)
3484 (widget-specify-sample widget start (point)))
3485 (insert " group: ")
3486 ;; Create visibility indicator.
3487 (unless (eq custom-buffer-style 'links)
3488 (insert "--------")
3489 (push (widget-create-child-and-convert
3490 widget 'visibility
3491 :help-echo "Hide members of this group."
3492 :action 'custom-toggle-parent
3493 (not (eq state 'hidden)))
3494 buttons)
3495 (insert " "))
3496 ;; Create more dashes.
3497 ;; Use 76 instead of 75 to compensate for the temporary "<"
3498 ;; added by `widget-insert'.
3499 (insert-char ?- (- 76 (current-column)
3500 (* custom-buffer-indent level)))
3501 (insert "\\\n")
3502 ;; Create magic button.
3503 (let ((magic (widget-create-child-and-convert
3504 widget 'custom-magic
3505 :indent 0
3506 nil)))
3507 (widget-put widget :custom-magic magic)
3508 (push magic buttons))
3509 ;; Update buttons.
3510 (widget-put widget :buttons buttons)
3511 ;; Insert documentation.
3512 (widget-default-format-handler widget ?h)
3513 ;; Parent groups.
3514 (if nil ;;; This should test that the buffer
3515 ;;; was not made to display a group.
3516 (when (eq level 1)
3517 (insert-char ?\ custom-buffer-indent)
3518 (custom-add-parent-links widget)))
3519 (custom-add-see-also widget
3520 (make-string (* custom-buffer-indent level)
3521 ?\ ))
3522 ;; Members.
3523 (message "Creating group...")
3524 (let* ((members (custom-sort-items members
3525 custom-buffer-sort-alphabetically
3526 custom-buffer-order-groups))
3527 (prefixes (widget-get widget :custom-prefixes))
3528 (custom-prefix-list (custom-prefix-add symbol prefixes))
3529 (length (length members))
3530 (count 0)
3531 (children (mapcar (lambda (entry)
3532 (widget-insert "\n")
3533 (message "\
3534 Creating group members... %2d%%"
3535 (/ (* 100.0 count) length))
3536 (setq count (1+ count))
3537 (prog1
3538 (widget-create-child-and-convert
3539 widget (nth 1 entry)
3540 :group widget
3541 :tag (custom-unlispify-tag-name
3542 (nth 0 entry))
3543 :custom-prefixes custom-prefix-list
3544 :custom-level (1+ level)
3545 :value (nth 0 entry))
3546 (unless (eq (preceding-char) ?\n)
3547 (widget-insert "\n"))))
3548 members)))
3549 (message "Creating group magic...")
3550 (mapc 'custom-magic-reset children)
3551 (message "Creating group state...")
3552 (widget-put widget :children children)
3553 (custom-group-state-update widget)
3554 (message "Creating group... done"))
3555 ;; End line
3556 (insert "\n")
3557 (insert-char ?\ (* custom-buffer-indent (1- level)))
3558 (insert "\\- " (widget-get widget :tag) " group end ")
3559 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3560 (insert "/\n")))))
3562 (defvar custom-group-menu
3563 '(("Set for Current Session" custom-group-set
3564 (lambda (widget)
3565 (eq (widget-get widget :custom-state) 'modified)))
3566 ("Save for Future Sessions" custom-group-save
3567 (lambda (widget)
3568 (memq (widget-get widget :custom-state) '(modified set))))
3569 ("Reset to Current" custom-group-reset-current
3570 (lambda (widget)
3571 (memq (widget-get widget :custom-state) '(modified))))
3572 ("Reset to Saved" custom-group-reset-saved
3573 (lambda (widget)
3574 (memq (widget-get widget :custom-state) '(modified set))))
3575 ("Reset to standard setting" custom-group-reset-standard
3576 (lambda (widget)
3577 (memq (widget-get widget :custom-state) '(modified set saved)))))
3578 "Alist of actions for the `custom-group' widget.
3579 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3580 the menu entry, ACTION is the function to call on the widget when the
3581 menu is selected, and FILTER is a predicate which takes a `custom-group'
3582 widget as an argument, and returns non-nil if ACTION is valid on that
3583 widget. If FILTER is nil, ACTION is always valid.")
3585 (defun custom-group-action (widget &optional event)
3586 "Show the menu for `custom-group' WIDGET.
3587 Optional EVENT is the location for the menu."
3588 (if (eq (widget-get widget :custom-state) 'hidden)
3589 (custom-toggle-hide widget)
3590 (let* ((completion-ignore-case t)
3591 (answer (widget-choose (concat "Operation on "
3592 (custom-unlispify-tag-name
3593 (widget-get widget :value)))
3594 (custom-menu-filter custom-group-menu
3595 widget)
3596 event)))
3597 (if answer
3598 (funcall answer widget)))))
3600 (defun custom-group-set (widget)
3601 "Set changes in all modified group members."
3602 (let ((children (widget-get widget :children)))
3603 (mapc (lambda (child)
3604 (when (eq (widget-get child :custom-state) 'modified)
3605 (widget-apply child :custom-set)))
3606 children )))
3608 (defun custom-group-save (widget)
3609 "Save all modified group members."
3610 (let ((children (widget-get widget :children)))
3611 (mapc (lambda (child)
3612 (when (memq (widget-get child :custom-state) '(modified set))
3613 (widget-apply child :custom-save)))
3614 children )))
3616 (defun custom-group-reset-current (widget)
3617 "Reset all modified group members."
3618 (let ((children (widget-get widget :children)))
3619 (mapc (lambda (child)
3620 (when (eq (widget-get child :custom-state) 'modified)
3621 (widget-apply child :custom-reset-current)))
3622 children )))
3624 (defun custom-group-reset-saved (widget)
3625 "Reset all modified or set group members."
3626 (let ((children (widget-get widget :children)))
3627 (mapc (lambda (child)
3628 (when (memq (widget-get child :custom-state) '(modified set))
3629 (widget-apply child :custom-reset-saved)))
3630 children )))
3632 (defun custom-group-reset-standard (widget)
3633 "Reset all modified, set, or saved group members."
3634 (let ((children (widget-get widget :children)))
3635 (mapc (lambda (child)
3636 (when (memq (widget-get child :custom-state)
3637 '(modified set saved))
3638 (widget-apply child :custom-reset-standard)))
3639 children )))
3641 (defun custom-group-state-update (widget)
3642 "Update magic."
3643 (unless (eq (widget-get widget :custom-state) 'hidden)
3644 (let* ((children (widget-get widget :children))
3645 (states (mapcar (lambda (child)
3646 (widget-get child :custom-state))
3647 children))
3648 (magics custom-magic-alist)
3649 (found 'standard))
3650 (while magics
3651 (let ((magic (car (car magics))))
3652 (if (and (not (eq magic 'hidden))
3653 (memq magic states))
3654 (setq found magic
3655 magics nil)
3656 (setq magics (cdr magics)))))
3657 (widget-put widget :custom-state found)))
3658 (custom-magic-reset widget))
3660 ;;; The `custom-save-all' Function.
3661 ;;;###autoload
3662 (defcustom custom-file nil
3663 "File used for storing customization information.
3664 The default is nil, which means to use your init file
3665 as specified by `user-init-file'. If you specify some other file,
3666 you need to explicitly load that file for the settings to take effect.
3668 When you change this variable, look in the previous custom file
3669 \(usually your init file) for the forms `(custom-set-variables ...)'
3670 and `(custom-set-faces ...)', and copy them (whichever ones you find)
3671 to the new custom file. This will preserve your existing customizations."
3672 :type '(choice (const :tag "Your Emacs init file" nil) file)
3673 :group 'customize)
3675 (defun custom-file ()
3676 "Return the file name for saving customizations."
3677 (setq custom-file
3678 (or custom-file
3679 (let ((user-init-file user-init-file)
3680 (default-init-file
3681 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
3682 (when (null user-init-file)
3683 (if (or (file-exists-p default-init-file)
3684 (and (eq system-type 'windows-nt)
3685 (file-exists-p "~/_emacs")))
3686 ;; Started with -q, i.e. the file containing
3687 ;; Custom settings hasn't been read. Saving
3688 ;; settings there would overwrite other settings.
3689 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3690 (setq user-init-file default-init-file))
3691 user-init-file))))
3693 (defun custom-save-delete (symbol)
3694 "Visit `custom-file' and delete all calls to SYMBOL from it.
3695 Leave point at the old location of the first such call,
3696 or (if there were none) at the end of the buffer."
3697 (let ((default-major-mode 'emacs-lisp-mode))
3698 (set-buffer (find-file-noselect (custom-file))))
3699 (goto-char (point-min))
3700 ;; Skip all whitespace and comments.
3701 (while (forward-comment 1))
3702 (or (eobp)
3703 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3704 (let (first)
3705 (catch 'found
3706 (while t ;; We exit this loop only via throw.
3707 ;; Skip all whitespace and comments.
3708 (while (forward-comment 1))
3709 (let ((start (point))
3710 (sexp (condition-case nil
3711 (read (current-buffer))
3712 (end-of-file (throw 'found nil)))))
3713 (when (and (listp sexp)
3714 (eq (car sexp) symbol))
3715 (delete-region start (point))
3716 (unless first
3717 (setq first (point)))))))
3718 (if first
3719 (goto-char first)
3720 ;; Move in front of local variables, otherwise long Custom
3721 ;; entries would make them ineffective.
3722 (let ((pos (point-max))
3723 (case-fold-search t))
3724 (save-excursion
3725 (goto-char (point-max))
3726 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3727 'move)
3728 (when (search-forward "Local Variables:" nil t)
3729 (setq pos (line-beginning-position))))
3730 (goto-char pos)))))
3732 (defun custom-save-variables ()
3733 "Save all customized variables in `custom-file'."
3734 (save-excursion
3735 (custom-save-delete 'custom-load-themes)
3736 (custom-save-delete 'custom-reset-variables)
3737 (custom-save-delete 'custom-set-variables)
3738 (custom-save-loaded-themes)
3739 (custom-save-resets 'theme-value 'custom-reset-variables nil)
3740 (let ((standard-output (current-buffer))
3741 (saved-list (make-list 1 0))
3742 sort-fold-case)
3743 ;; First create a sorted list of saved variables.
3744 (mapatoms
3745 (lambda (symbol)
3746 (if (get symbol 'saved-value)
3747 (nconc saved-list (list symbol)))))
3748 (setq saved-list (sort (cdr saved-list) 'string<))
3749 (unless (bolp)
3750 (princ "\n"))
3751 (princ "(custom-set-variables
3752 ;; custom-set-variables was added by Custom.
3753 ;; If you edit it by hand, you could mess it up, so be careful.
3754 ;; Your init file should contain only one such instance.
3755 ;; If there is more than one, they won't work right.\n")
3756 (dolist (symbol saved-list)
3757 (let ((spec (car-safe (get symbol 'theme-value)))
3758 (value (get symbol 'saved-value))
3759 (requests (get symbol 'custom-requests))
3760 (now (not (or (custom-variable-p symbol)
3761 (and (not (boundp symbol))
3762 (not (eq (get symbol 'force-value)
3763 'rogue))))))
3764 (comment (get symbol 'saved-variable-comment)))
3765 ;; Check `requests'.
3766 (dolist (request requests)
3767 (when (and (symbolp request) (not (featurep request)))
3768 (message "Unknown requested feature: %s" request)
3769 (setq requests (delq request requests))))
3770 (when (or (and spec
3771 (eq (nth 0 spec) 'user)
3772 (eq (nth 1 spec) 'set))
3773 comment
3774 (and (null spec) (get symbol 'saved-value)))
3775 (unless (bolp)
3776 (princ "\n"))
3777 (princ " '(")
3778 (prin1 symbol)
3779 (princ " ")
3780 (prin1 (car value))
3781 (when (or now requests comment)
3782 (princ " ")
3783 (prin1 now)
3784 (when (or requests comment)
3785 (princ " ")
3786 (prin1 requests)
3787 (when comment
3788 (princ " ")
3789 (prin1 comment))))
3790 (princ ")"))))
3791 (if (bolp)
3792 (princ " "))
3793 (princ ")")
3794 (unless (looking-at "\n")
3795 (princ "\n")))))
3797 (defun custom-save-faces ()
3798 "Save all customized faces in `custom-file'."
3799 (save-excursion
3800 (custom-save-delete 'custom-reset-faces)
3801 (custom-save-delete 'custom-set-faces)
3802 (custom-save-resets 'theme-face 'custom-reset-faces '(default))
3803 (let ((standard-output (current-buffer))
3804 (saved-list (make-list 1 0))
3805 sort-fold-case)
3806 ;; First create a sorted list of saved faces.
3807 (mapatoms
3808 (lambda (symbol)
3809 (if (get symbol 'saved-face)
3810 (nconc saved-list (list symbol)))))
3811 (setq saved-list (sort (cdr saved-list) 'string<))
3812 ;; The default face must be first, since it affects the others.
3813 (if (memq 'default saved-list)
3814 (setq saved-list (cons 'default (delq 'default saved-list))))
3815 (unless (bolp)
3816 (princ "\n"))
3817 (princ "(custom-set-faces
3818 ;; custom-set-faces was added by Custom.
3819 ;; If you edit it by hand, you could mess it up, so be careful.
3820 ;; Your init file should contain only one such instance.
3821 ;; If there is more than one, they won't work right.\n")
3822 (dolist (symbol saved-list)
3823 (let ((spec (car-safe (get symbol 'theme-face)))
3824 (value (get symbol 'saved-face))
3825 (now (not (or (get symbol 'face-defface-spec)
3826 (and (not (custom-facep symbol))
3827 (not (get symbol 'force-face))))))
3828 (comment (get symbol 'saved-face-comment)))
3829 (when (or (and spec
3830 (eq (nth 0 spec) 'user)
3831 (eq (nth 1 spec) 'set))
3832 comment
3833 (and (null spec) (get symbol 'saved-face)))
3834 ;; Don't print default face here.
3835 (unless (bolp)
3836 (princ "\n"))
3837 (princ " '(")
3838 (prin1 symbol)
3839 (princ " ")
3840 (prin1 value)
3841 (when (or now comment)
3842 (princ " ")
3843 (prin1 now)
3844 (when comment
3845 (princ " ")
3846 (prin1 comment)))
3847 (princ ")"))))
3848 (if (bolp)
3849 (princ " "))
3850 (princ ")")
3851 (unless (looking-at "\n")
3852 (princ "\n")))))
3854 (defun custom-save-resets (property setter special)
3855 (let (started-writing ignored-special)
3856 ;; (custom-save-delete setter) Done by caller
3857 (let ((standard-output (current-buffer))
3858 (mapper `(lambda (object)
3859 (let ((spec (car-safe (get object (quote ,property)))))
3860 (when (and (not (memq object ignored-special))
3861 (eq (nth 0 spec) 'user)
3862 (eq (nth 1 spec) 'reset))
3863 ;; Do not write reset statements unless necessary.
3864 (unless started-writing
3865 (setq started-writing t)
3866 (unless (bolp)
3867 (princ "\n"))
3868 (princ "(")
3869 (princ (quote ,setter))
3870 (princ "\n '(")
3871 (prin1 object)
3872 (princ " ")
3873 (prin1 (nth 3 spec))
3874 (princ ")")))))))
3875 (mapc mapper special)
3876 (setq ignored-special special)
3877 (mapatoms mapper)
3878 (when started-writing
3879 (princ ")\n")))))
3881 (defun custom-save-loaded-themes ()
3882 (let ((themes (reverse (get 'user 'theme-loads-themes)))
3883 (standard-output (current-buffer)))
3884 (when themes
3885 (unless (bolp) (princ "\n"))
3886 (princ "(custom-load-themes")
3887 (mapc (lambda (theme)
3888 (princ "\n '")
3889 (prin1 theme)) themes)
3890 (princ " )\n"))))
3892 ;;;###autoload
3893 (defun customize-save-customized ()
3894 "Save all user options which have been set in this session."
3895 (interactive)
3896 (mapatoms (lambda (symbol)
3897 (let ((face (get symbol 'customized-face))
3898 (value (get symbol 'customized-value))
3899 (face-comment (get symbol 'customized-face-comment))
3900 (variable-comment
3901 (get symbol 'customized-variable-comment)))
3902 (when face
3903 (put symbol 'saved-face face)
3904 (custom-push-theme 'theme-face symbol 'user 'set value)
3905 (put symbol 'customized-face nil))
3906 (when value
3907 (put symbol 'saved-value value)
3908 (custom-push-theme 'theme-value symbol 'user 'set value)
3909 (put symbol 'customized-value nil))
3910 (when variable-comment
3911 (put symbol 'saved-variable-comment variable-comment)
3912 (put symbol 'customized-variable-comment nil))
3913 (when face-comment
3914 (put symbol 'saved-face-comment face-comment)
3915 (put symbol 'customized-face-comment nil)))))
3916 ;; We really should update all custom buffers here.
3917 (custom-save-all))
3919 ;;;###autoload
3920 (defun custom-save-all ()
3921 "Save all customizations in `custom-file'."
3922 (let ((inhibit-read-only t))
3923 (custom-save-variables)
3924 (custom-save-faces)
3925 (save-excursion
3926 (let ((default-major-mode nil))
3927 (set-buffer (find-file-noselect (custom-file))))
3928 (let ((file-precious-flag t))
3929 (save-buffer)))))
3931 ;;; The Customize Menu.
3933 ;;; Menu support
3935 (defcustom custom-menu-nesting 2
3936 "Maximum nesting in custom menus."
3937 :type 'integer
3938 :group 'custom-menu)
3940 (defun custom-face-menu-create (widget symbol)
3941 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3942 (vector (custom-unlispify-menu-entry symbol)
3943 `(customize-face ',symbol)
3946 (defun custom-variable-menu-create (widget symbol)
3947 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3948 (let ((type (get symbol 'custom-type)))
3949 (unless (listp type)
3950 (setq type (list type)))
3951 (if (and type (widget-get type :custom-menu))
3952 (widget-apply type :custom-menu symbol)
3953 (vector (custom-unlispify-menu-entry symbol)
3954 `(customize-variable ',symbol)
3955 t))))
3957 ;; Add checkboxes to boolean variable entries.
3958 (widget-put (get 'boolean 'widget-type)
3959 :custom-menu (lambda (widget symbol)
3960 (vector (custom-unlispify-menu-entry symbol)
3961 `(customize-variable ',symbol)
3962 ':style 'toggle
3963 ':selected symbol)))
3965 (defun custom-group-menu-create (widget symbol)
3966 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3967 `( ,(custom-unlispify-menu-entry symbol t)
3968 :filter (lambda (&rest junk)
3969 (let ((menu (custom-menu-create ',symbol)))
3970 (if (consp menu) (cdr menu) menu)))))
3972 ;;;###autoload
3973 (defun custom-menu-create (symbol)
3974 "Create menu for customization group SYMBOL.
3975 The menu is in a format applicable to `easy-menu-define'."
3976 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3977 `(customize-group ',symbol)
3978 t)))
3979 (if (and (or (not (boundp 'custom-menu-nesting))
3980 (>= custom-menu-nesting 0))
3981 (progn
3982 (custom-load-symbol symbol)
3983 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
3984 (let ((custom-prefix-list (custom-prefix-add symbol
3985 custom-prefix-list))
3986 (members (custom-sort-items (get symbol 'custom-group)
3987 custom-menu-sort-alphabetically
3988 custom-menu-order-groups)))
3989 `(,(custom-unlispify-menu-entry symbol t)
3990 ,item
3991 "--"
3992 ,@(mapcar (lambda (entry)
3993 (widget-apply (if (listp (nth 1 entry))
3994 (nth 1 entry)
3995 (list (nth 1 entry)))
3996 :custom-menu (nth 0 entry)))
3997 members)))
3998 item)))
4000 ;;;###autoload
4001 (defun customize-menu-create (symbol &optional name)
4002 "Return a customize menu for customization group SYMBOL.
4003 If optional NAME is given, use that as the name of the menu.
4004 Otherwise the menu will be named `Customize'.
4005 The format is suitable for use with `easy-menu-define'."
4006 (unless name
4007 (setq name "Customize"))
4008 `(,name
4009 :filter (lambda (&rest junk)
4010 (let ((menu (custom-menu-create ',symbol)))
4011 (if (consp menu) (cdr menu) menu)))))
4013 ;;; The Custom Mode.
4015 (defvar custom-mode-map nil
4016 "Keymap for `custom-mode'.")
4018 (unless custom-mode-map
4019 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4020 ;; "\r" bindings from the parent map.
4021 (setq custom-mode-map (make-sparse-keymap))
4022 (set-keymap-parent custom-mode-map widget-keymap)
4023 (suppress-keymap custom-mode-map)
4024 (define-key custom-mode-map " " 'scroll-up)
4025 (define-key custom-mode-map "\177" 'scroll-down)
4026 (define-key custom-mode-map "\C-x\C-s" 'Custom-save)
4027 (define-key custom-mode-map "q" 'Custom-buffer-done)
4028 (define-key custom-mode-map "u" 'Custom-goto-parent)
4029 (define-key custom-mode-map "n" 'widget-forward)
4030 (define-key custom-mode-map "p" 'widget-backward)
4031 (define-key custom-mode-map [mouse-1] 'Custom-move-and-invoke))
4033 (defun Custom-move-and-invoke (event)
4034 "Move to where you click, and if it is an active field, invoke it."
4035 (interactive "e")
4036 (mouse-set-point event)
4037 (if (widget-event-point event)
4038 (let* ((pos (widget-event-point event))
4039 (button (get-char-property pos 'button)))
4040 (if button
4041 (widget-button-click event)))))
4043 (easy-menu-define Custom-mode-menu
4044 custom-mode-map
4045 "Menu used in customization buffers."
4046 `("Custom"
4047 ,(customize-menu-create 'customize)
4048 ["Set" Custom-set t]
4049 ["Save" Custom-save t]
4050 ["Reset to Current" Custom-reset-current t]
4051 ["Reset to Saved" Custom-reset-saved t]
4052 ["Reset to Standard Settings" Custom-reset-standard t]
4053 ["Info" (Info-goto-node "(emacs)Easy Customization") t]))
4055 (defun Custom-goto-parent ()
4056 "Go to the parent group listed at the top of this buffer.
4057 If several parents are listed, go to the first of them."
4058 (interactive)
4059 (save-excursion
4060 (goto-char (point-min))
4061 (if (search-forward "\nGo to parent group: " nil t)
4062 (let* ((button (get-char-property (point) 'button))
4063 (parent (downcase (widget-get button :tag))))
4064 (customize-group parent)))))
4066 (defcustom custom-mode-hook nil
4067 "Hook called when entering Custom mode."
4068 :type 'hook
4069 :group 'custom-buffer )
4071 (defun custom-state-buffer-message (widget)
4072 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4073 (message "To install your edits, invoke [State] and choose the Set operation")))
4075 (defun custom-mode ()
4076 "Major mode for editing customization buffers.
4078 The following commands are available:
4080 Move to next button or editable field. \\[widget-forward]
4081 Move to previous button or editable field. \\[widget-backward]
4082 \\<widget-field-keymap>\
4083 Complete content of editable text field. \\[widget-complete]
4084 \\<custom-mode-map>\
4085 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4086 Invoke button under point. \\[widget-button-press]
4087 Set all modifications. \\[Custom-set]
4088 Make all modifications default. \\[Custom-save]
4089 Reset all modified options. \\[Custom-reset-current]
4090 Reset all modified or set options. \\[Custom-reset-saved]
4091 Reset all options. \\[Custom-reset-standard]
4093 Entry to this mode calls the value of `custom-mode-hook'
4094 if that value is non-nil."
4095 (kill-all-local-variables)
4096 (setq major-mode 'custom-mode
4097 mode-name "Custom")
4098 (use-local-map custom-mode-map)
4099 (easy-menu-add Custom-mode-menu)
4100 (make-local-variable 'custom-options)
4101 (make-local-variable 'custom-local-buffer)
4102 (make-local-variable 'widget-documentation-face)
4103 (setq widget-documentation-face 'custom-documentation-face)
4104 (make-local-variable 'widget-button-face)
4105 (setq widget-button-face 'custom-button-face)
4106 (set (make-local-variable 'widget-button-pressed-face)
4107 'custom-button-pressed-face)
4108 (set (make-local-variable 'widget-mouse-face)
4109 'custom-button-pressed-face) ; buttons `depress' when moused
4110 ;; When possible, use relief for buttons, not bracketing. This test
4111 ;; may not be optimal.
4112 (when custom-raised-buttons
4113 (set (make-local-variable 'widget-push-button-prefix) "")
4114 (set (make-local-variable 'widget-push-button-suffix) "")
4115 (set (make-local-variable 'widget-link-prefix) "")
4116 (set (make-local-variable 'widget-link-suffix) ""))
4117 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
4118 (run-hooks 'custom-mode-hook))
4120 (put 'custom-mode 'mode-class 'special)
4122 (add-to-list
4123 'debug-ignored-errors
4124 "^No user options have changed defaults in recent Emacs versions$")
4126 ;;; The End.
4128 (provide 'cus-edit)
4130 ;;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4131 ;;; cus-edit.el ends here