1 ;;; cus-edit.el --- Tools for customizating Emacs and Lisp packages.
3 ;; Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: help, faces
7 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ (probably obsolete)
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)
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.
28 ;; This file implements the code to create and edit customize buffers.
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.
43 (defvar custom-versions-load-alist
)) ; from cus-load
53 (put 'custom-define-hook
'custom-type
'hook
)
54 (put 'custom-define-hook
'standard-value
'(nil))
55 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
57 ;;; Customization Groups.
60 "Customization of the One True Editor."
61 :link
'(custom-manual "(emacs)Top"))
63 ;; Most of these groups are stolen from `finder.el',
65 "Basic text editing facilities."
69 "Abbreviation handling, typing shortcuts, macros."
73 (defgroup matching nil
74 "Various sorts of searching and matching."
77 (defgroup emulations nil
78 "Emulations of other editors."
85 (defgroup outlines nil
86 "Support for hierarchical outlining."
89 (defgroup external nil
90 "Interfacing to external utilities."
94 "Code related to the `bib' bibliography processor."
98 (defgroup processes nil
99 "Process, subshell, compilation, and job control support."
103 (defgroup convenience nil
104 "Convenience features for faster editing."
107 (defgroup programming nil
108 "Support for programming in other languages."
111 (defgroup languages nil
112 "Specialized modes for editing programming languages."
116 "Lisp support, including Emacs Lisp."
121 "Support for the C language and related languages."
129 "Support for object-oriented programming."
132 (defgroup applications nil
133 "Applications written in Emacs."
136 (defgroup calendar nil
137 "Calendar and time management support."
138 :group
'applications
)
141 "Modes for electronic-mail handling."
142 :group
'applications
)
145 "Support for netnews reading and posting."
146 :group
'applications
)
149 "Games, jokes and amusements."
150 :group
'applications
)
152 (defgroup development nil
153 "Support for further development of Emacs."
157 "Support for Emacs documentation."
160 (defgroup extensions nil
161 "Emacs Lisp language extensions."
164 (defgroup internal nil
165 "Code for Emacs internals, build process, defaults."
169 "Maintenance aids for the Emacs development group."
173 (defgroup environment nil
174 "Fitting Emacs with its environment."
178 "Communications, networking, remote access to files."
182 (defgroup hardware nil
183 "Support for interfacing with exotic hardware."
186 (defgroup terminals nil
187 "Support for terminal types."
191 "Front-ends/assistants for, or emulators of, UNIX features."
195 "Support code for vms."
199 "Internationalization and alternate character-set support."
204 "The X Window system."
208 "Support for Emacs frames and window systems."
212 "Support editing files of data."
216 "Support editing files."
224 "Code related to the TeX formatter."
228 "Support for multiple fonts."
231 (defgroup hypermedia nil
232 "Support for links between text or other media types."
236 "Support for on-line help systems."
239 (defgroup multimedia nil
240 "Non-textual support, specifically images and sound."
244 "Code local to your site."
247 (defgroup customize
'((widgets custom-group
))
248 "Customization of the Customization support."
249 :link
'(custom-manual "(elisp)Customization")
250 :link
'(url-link :tag
"(Old?) Development Page"
251 "http://www.dina.kvl.dk/~abraham/custom/")
255 (defgroup custom-faces nil
256 "Faces used by customize."
260 (defgroup custom-browse nil
261 "Control customize browser."
265 (defgroup custom-buffer nil
266 "Control customize buffers."
270 (defgroup custom-menu nil
271 "Control customize menus."
275 (defgroup abbrev-mode nil
276 "Word abbreviations mode."
280 "Storage allocation and gc for GNU Emacs Lisp interpreter."
281 :tag
"Storage Allocation"
285 "Undoing changes in buffers."
288 (defgroup modeline nil
289 "Content of the modeline."
293 "Indenting and filling text."
296 (defgroup editing-basics nil
297 "Most basic editing facilities."
300 (defgroup display nil
301 "How characters are displayed in buffers."
304 (defgroup execute nil
305 "Executing external commands."
308 (defgroup installation nil
309 "The Emacs installation."
317 "Internal Emacs limits."
321 "Debugging Emacs itself."
324 (defgroup minibuffer nil
325 "Controling the behaviour of the minibuffer."
328 (defgroup keyboard nil
329 "Input from the keyboard."
333 "Input from the mouse."
337 "Input from the menus."
340 (defgroup auto-save nil
341 "Preventing accidential loss of data."
344 (defgroup processes-basics nil
345 "Basic stuff dealing with processes."
349 "MULE Emacs internationalization."
352 (defgroup windows nil
353 "Windows within a frame."
358 (defun custom-quote (sexp)
359 "Quote SEXP iff it is not self quoting."
360 (if (or (memq sexp
'(t nil
))
362 (eq (aref (symbol-name sexp
) 0) ?
:))
364 (memq (car sexp
) '(lambda)))
368 ;;; (and (fboundp 'characterp)
369 ;;; (characterp sexp))
374 (defun custom-split-regexp-maybe (regexp)
375 "If REGEXP is a string, split it to a list at `\\|'.
376 You can get the original back with from the result with:
377 (mapconcat 'identity result \"\\|\")
379 IF REGEXP is not a string, return it unchanged."
383 (while (string-match "\\\\|" regexp start
)
384 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
385 start
(match-end 0)))
386 (nreverse (cons (substring regexp start
) all
)))
389 (defun custom-variable-prompt ()
390 ;; Code stolen from `help.el'.
391 "Prompt for a variable, defaulting to the variable at point.
392 Return a list suitable for use in `interactive'."
393 (let ((v (variable-at-point))
394 (enable-recursive-minibuffers t
)
396 (setq val
(completing-read
398 (format "Customize option: (default %s) " v
)
399 "Customize variable: ")
400 obarray
(lambda (symbol)
402 (or (get symbol
'custom-type
)
403 (get symbol
'custom-loads
)
404 (user-variable-p symbol
)))) t
))
405 (list (if (equal val
"")
406 (if (symbolp v
) v nil
)
409 (defun custom-menu-filter (menu widget
)
410 "Convert MENU to the form used by `widget-choose'.
411 MENU should be in the same format as `custom-variable-menu'.
412 WIDGET is the widget to apply the filter entries of MENU on."
414 current name action filter
)
416 (setq current
(car menu
)
418 action
(nth 1 current
)
419 filter
(nth 2 current
)
421 (if (or (null filter
) (funcall filter widget
))
422 (push (cons name action
) result
)
428 (defvar custom-prefix-list nil
429 "List of prefixes that should be ignored by `custom-unlispify'")
431 (defcustom custom-unlispify-menu-entries t
432 "Display menu entries as words instead of symbols if non nil."
436 (defcustom custom-unlispify-remove-prefixes nil
437 "Non-nil means remove group prefixes from option names in buffer."
441 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
442 "Convert symbol into a menu entry."
443 (cond ((not custom-unlispify-menu-entries
)
444 (symbol-name symbol
))
445 ((get symbol
'custom-tag
)
447 (get symbol
'custom-tag
)
448 (concat (get symbol
'custom-tag
) "...")))
451 (set-buffer (get-buffer-create " *Custom-Work*"))
453 (princ symbol
(current-buffer))
454 (goto-char (point-min))
455 (when (and (eq (get symbol
'custom-type
) 'boolean
)
456 (re-search-forward "-p\\'" nil t
))
457 (replace-match "" t t
)
458 (goto-char (point-min)))
459 (if custom-unlispify-remove-prefixes
460 (let ((prefixes custom-prefix-list
)
463 (setq prefix
(car prefixes
))
464 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
467 (delete-region (point-min) (point)))
468 (setq prefixes
(cdr prefixes
))))))
469 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
470 (capitalize-region (point-min) (point-max))
472 (goto-char (point-max))
476 (defcustom custom-unlispify-tag-names t
477 "Display tag names as words instead of symbols if non nil."
478 :group
'custom-buffer
481 (defun custom-unlispify-tag-name (symbol)
482 "Convert symbol into a menu entry."
483 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
484 (custom-unlispify-menu-entry symbol t
)))
486 (defun custom-prefix-add (symbol prefixes
)
487 ;; Addd SYMBOL to list of ignored PREFIXES.
488 (cons (or (get symbol
'custom-prefix
)
489 (concat (symbol-name symbol
) "-"))
494 (defcustom custom-guess-name-alist
499 ("-function\\'" function
)
500 ("-functions\\'" (repeat function
))
501 ("-list\\'" (repeat sexp
))
502 ("-alist\\'" (repeat (cons sexp sexp
))))
503 "Alist of (MATCH TYPE).
505 MATCH should be a regexp matching the name of a symbol, and TYPE should
506 be a widget suitable for editing the value of that symbol. The TYPE
507 of the first entry where MATCH matches the name of the symbol will be
510 This is used for guessing the type of variables not declared with
512 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
515 (defcustom custom-guess-doc-alist
516 '(("\\`\\*?Non-nil " boolean
))
517 "Alist of (MATCH TYPE).
519 MATCH should be a regexp matching a documentation string, and TYPE
520 should be a widget suitable for editing the value of a variable with
521 that documentation string. The TYPE of the first entry where MATCH
522 matches the name of the symbol will be used.
524 This is used for guessing the type of variables not declared with
526 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
529 (defun custom-guess-type (symbol)
530 "Guess a widget suitable for editing the value of SYMBOL.
531 This is done by matching SYMBOL with `custom-guess-name-alist' and
532 if that fails, the doc string with `custom-guess-doc-alist'."
533 (let ((name (symbol-name symbol
))
534 (names custom-guess-name-alist
)
537 (setq current
(car names
)
539 (when (string-match (nth 0 current
) name
)
540 (setq found
(nth 1 current
)
543 (let ((doc (documentation-property symbol
'variable-documentation
))
544 (docs custom-guess-doc-alist
))
547 (setq current
(car docs
)
549 (when (string-match (nth 0 current
) doc
)
550 (setq found
(nth 1 current
)
556 (defcustom custom-browse-sort-alphabetically nil
557 "If non-nil, sort members of each customization group alphabetically."
559 :group
'custom-browse
)
561 (defcustom custom-browse-order-groups nil
562 "If non-nil, order group members within each customization group.
563 If `first', order groups before non-groups.
564 If `last', order groups after non-groups."
565 :type
'(choice (const first
)
567 (const :tag
"none" nil
))
568 :group
'custom-browse
)
570 (defcustom custom-browse-only-groups nil
571 "If non-nil, show group members only within each customization group."
573 :group
'custom-browse
)
575 (defcustom custom-buffer-sort-alphabetically nil
576 "If non-nil, sort members of each customization group alphabetically."
578 :group
'custom-buffer
)
580 (defcustom custom-buffer-order-groups
'last
581 "If non-nil, order group members within each customization group.
582 If `first', order groups before non-groups.
583 If `last', order groups after non-groups."
584 :type
'(choice (const first
)
586 (const :tag
"none" nil
))
587 :group
'custom-buffer
)
589 (defcustom custom-menu-sort-alphabetically nil
590 "If non-nil, sort members of each customization group alphabetically."
594 (defcustom custom-menu-order-groups
'first
595 "If non-nil, order group members within each customization group.
596 If `first', order groups before non-groups.
597 If `last', order groups after non-groups."
598 :type
'(choice (const first
)
600 (const :tag
"none" nil
))
603 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
605 (defun custom-sort-items (items sort-alphabetically order-groups
)
606 "Return a sorted copy of ITEMS.
607 ITEMS should be a `custom-group' property.
608 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
609 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
610 groups after non-groups, if nil do not order groups at all."
611 (sort (copy-sequence items
)
613 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
614 (namea (symbol-name (nth 0 a
))) (nameb (symbol-name (nth 0 b
))))
615 (cond ((not order-groups
)
616 ;; Since we don't care about A and B order, maybe sort.
617 (when sort-alphabetically
618 (string-lessp namea nameb
)))
619 ((eq typea
'custom-group
)
620 ;; If B is also a group, maybe sort. Otherwise, order A and B.
621 (if (eq typeb
'custom-group
)
622 (when sort-alphabetically
623 (string-lessp namea nameb
))
624 (eq order-groups
'first
)))
625 ((eq typeb
'custom-group
)
626 ;; Since A cannot be a group, order A and B.
627 (eq order-groups
'last
))
629 ;; Since A and B cannot be groups, sort.
630 (string-lessp namea nameb
)))))))
632 ;;; Custom Mode Commands.
634 (defvar custom-options nil
635 "Customization widgets in the current buffer.")
638 "Set changes in all modified options."
640 (let ((children custom-options
))
641 (mapcar (lambda (child)
642 (when (eq (widget-get child
:custom-state
) 'modified
)
643 (widget-apply child
:custom-set
)))
646 (defun Custom-save ()
647 "Set all modified group members and save them."
649 (let ((children custom-options
))
650 (mapcar (lambda (child)
651 (when (memq (widget-get child
:custom-state
)
652 '(modified set changed rogue
))
653 (widget-apply child
:custom-save
)))
657 (defvar custom-reset-menu
658 '(("Current" . Custom-reset-current
)
659 ("Saved" . Custom-reset-saved
)
660 ("Erase Customization (use standard settings)" . Custom-reset-standard
))
661 "Alist of actions for the `Reset' button.
662 The key is a string containing the name of the action, the value is a
663 lisp function taking the widget as an element which will be called
664 when the action is chosen.")
666 (defun custom-reset (event)
667 "Select item from reset menu."
668 (let* ((completion-ignore-case t
)
669 (answer (widget-choose "Reset to"
675 (defun Custom-reset-current (&rest ignore
)
676 "Reset all modified group members to their current value."
678 (let ((children custom-options
))
679 (mapcar (lambda (widget)
680 (and (default-boundp (widget-value widget
))
681 (if (memq (widget-get widget
:custom-state
)
683 (widget-apply widget
:custom-reset-current
))))
686 (defun Custom-reset-saved (&rest ignore
)
687 "Reset all modified or set group members to their saved value."
689 (let ((children custom-options
))
690 (mapcar (lambda (widget)
691 (and (get (widget-value widget
) 'saved-value
)
692 (if (memq (widget-get widget
:custom-state
)
693 '(modified set changed rogue
))
694 (widget-apply widget
:custom-reset-saved
))))
697 (defun Custom-reset-standard (&rest ignore
)
698 "Erase all customization (either current or saved) for the group members.
699 The immediate result is to restore them to their standard settings.
700 This operation eliminates any saved settings for the group members,
701 making them as if they had never been customized at all."
703 (let ((children custom-options
))
704 (mapcar (lambda (widget)
705 (and (get (widget-value widget
) 'standard-value
)
706 (if (memq (widget-get widget
:custom-state
)
707 '(modified set changed saved rogue
))
708 (widget-apply widget
:custom-reset-standard
))))
711 ;;; The Customize Commands
713 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
714 "Prompt for a variable and a value and return them as a list.
715 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
716 prompt for the value. The %s escape in PROMPT-VAL is replaced with
717 the name of the variable.
719 If the variable has a `variable-interactive' property, that is used as if
720 it were the arg to `interactive' (which see) to interactively read the value.
722 If the variable has a `custom-type' property, it must be a widget and the
723 `:prompt-value' property of that widget will be used for reading the value.
725 If optional COMMENT argument is non nil, also prompt for a comment and return
726 it as the third element in the list."
727 (let* ((var (read-variable prompt-var
))
728 (minibuffer-help-form '(describe-variable var
))
730 (let ((prop (get var
'variable-interactive
))
731 (type (get var
'custom-type
))
732 (prompt (format prompt-val var
)))
734 (setq type
(list type
)))
736 ;; Use VAR's `variable-interactive' property
737 ;; as an interactive spec for prompting.
738 (call-interactively (list 'lambda
'(arg)
739 (list 'interactive prop
)
742 (widget-prompt-value type
748 (eval-minibuffer prompt
))))))
751 (read-string "Comment: " (get var
'variable-comment
)))
755 (defun customize-set-value (var val
&optional comment
)
756 "Set VARIABLE to VALUE. VALUE is a Lisp object.
758 If VARIABLE has a `variable-interactive' property, that is used as if
759 it were the arg to `interactive' (which see) to interactively read the value.
761 If VARIABLE has a `custom-type' property, it must be a widget and the
762 `:prompt-value' property of that widget will be used for reading the value.
764 If given a prefix (or a COMMENT argument), also prompt for a comment."
765 (interactive (custom-prompt-variable "Set variable: "
770 (cond ((string= comment
"")
771 (put var
'variable-comment nil
))
773 (put var
'variable-comment comment
))))
776 (defun customize-set-variable (var val
&optional comment
)
777 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
779 If VARIABLE has a `custom-set' property, that is used for setting
780 VARIABLE, otherwise `set-default' is used.
782 The `customized-value' property of the VARIABLE will be set to a list
783 with a quoted VALUE as its sole list member.
785 If VARIABLE has a `variable-interactive' property, that is used as if
786 it were the arg to `interactive' (which see) to interactively read the value.
788 If VARIABLE has a `custom-type' property, it must be a widget and the
789 `:prompt-value' property of that widget will be used for reading the value.
791 If given a prefix (or a COMMENT argument), also prompt for a comment."
792 (interactive (custom-prompt-variable "Set variable: "
793 "Set customized value for %s to: "
795 (funcall (or (get var
'custom-set
) 'set-default
) var val
)
796 (put var
'customized-value
(list (custom-quote val
)))
797 (cond ((string= comment
"")
798 (put var
'variable-comment nil
)
799 (put var
'customized-variable-comment nil
))
801 (put var
'variable-comment comment
)
802 (put var
'customized-variable-comment comment
))))
805 (defun customize-save-variable (var val
&optional comment
)
806 "Set the default for VARIABLE to VALUE, and save it for future sessions.
807 If VARIABLE has a `custom-set' property, that is used for setting
808 VARIABLE, otherwise `set-default' is used.
810 The `customized-value' property of the VARIABLE will be set to a list
811 with a quoted VALUE as its sole list member.
813 If VARIABLE has a `variable-interactive' property, that is used as if
814 it were the arg to `interactive' (which see) to interactively read the value.
816 If VARIABLE has a `custom-type' property, it must be a widget and the
817 `:prompt-value' property of that widget will be used for reading the value.
819 If given a prefix (or a COMMENT argument), also prompt for a comment."
820 (interactive (custom-prompt-variable "Set and ave variable: "
821 "Set and save value for %s as: "
823 (funcall (or (get var
'custom-set
) 'set-default
) var val
)
824 (put var
'saved-value
(list (custom-quote val
)))
825 (cond ((string= comment
"")
826 (put var
'variable-comment nil
)
827 (put var
'saved-variable-comment nil
))
829 (put var
'variable-comment comment
)
830 (put var
'saved-variable-comment comment
)))
835 "Select a customization buffer which you can use to set user options.
836 User options are structured into \"groups\".
837 Initially the top-level group `Emacs' and its immediate subgroups
838 are shown; the contents of those subgroups are initially hidden."
840 (customize-group 'emacs
))
843 (defun customize-group (group)
844 "Customize GROUP, which must be a customization group."
845 (interactive (list (let ((completion-ignore-case t
))
846 (completing-read "Customize group: (default emacs) "
849 (or (get symbol
'custom-loads
)
850 (get symbol
'custom-group
)))
852 (when (stringp group
)
853 (if (string-equal "" group
)
855 (setq group
(intern group
))))
856 (or (get group
'custom-group
)
857 (custom-load-symbol group
))
858 (let ((name (format "*Customize Group: %s*"
859 (custom-unlispify-tag-name group
))))
860 (if (get-buffer name
)
862 (custom-buffer-create (list (list group
'custom-group
))
864 (concat " for group "
865 (custom-unlispify-tag-name group
))))))
868 (defun customize-group-other-window (group)
869 "Customize GROUP, which must be a customization group."
870 (interactive (list (let ((completion-ignore-case t
))
871 (completing-read "Customize group: (default emacs) "
874 (or (get symbol
'custom-loads
)
875 (get symbol
'custom-group
)))
877 (when (stringp group
)
878 (if (string-equal "" group
)
880 (setq group
(intern group
))))
881 (or (get group
'custom-group
)
882 (custom-load-symbol group
))
883 (let ((name (format "*Customize Group: %s*"
884 (custom-unlispify-tag-name group
))))
885 (if (get-buffer name
)
886 (let ((window (selected-window)))
888 (select-window window
))
889 (custom-buffer-create-other-window
890 (list (list group
'custom-group
))
892 (concat " for group "
893 (custom-unlispify-tag-name group
))))))
896 (defalias 'customize-variable
'customize-option
)
899 (defun customize-option (symbol)
900 "Customize SYMBOL, which must be a user option variable."
901 (interactive (custom-variable-prompt))
902 ;; If we don't have SYMBOL's real definition loaded,
904 (unless (get symbol
'custom-type
)
905 (let ((loaddefs-file (locate-library "loaddefs.el" t
))
907 ;; See if it is autoloaded from some library.
910 (insert-file-contents loaddefs-file
)
911 (when (re-search-forward (concat "^(defvar " (symbol-name symbol
))
913 (search-backward "\n;;; Generated autoloads from ")
914 (goto-char (match-end 0))
915 (setq file
(buffer-substring (point)
916 (progn (end-of-line) (point)))))))
917 ;; If it is, load that library.
919 (when (string-match "\\.el\\'" file
)
920 (setq file
(substring file
0 (match-beginning 0))))
922 (unless (get symbol
'custom-type
)
923 (error "Variable %s cannot be customized" symbol
))
924 (custom-buffer-create (list (list symbol
'custom-variable
))
925 (format "*Customize Option: %s*"
926 (custom-unlispify-tag-name symbol
))))
928 (defvar customize-changed-options-previous-release
"20.2"
929 "Version for `customize-changed-options' to refer back to by default.")
932 (defun customize-changed-options (since-version)
933 "Customize all user option variables changed in Emacs itself.
934 This includes new user option variables and faces, and new
935 customization groups, as well as older options and faces whose default
936 values have changed since the previous major Emacs release.
938 With argument SINCE-VERSION (a string), customize all user option
939 variables that were added (or their meanings were changed) since that
942 (interactive "sCustomize options changed, since version (default all versions): ")
943 (if (equal since-version
"")
944 (setq since-version nil
))
945 (unless since-version
946 (setq since-version customize-changed-options-previous-release
))
949 (mapatoms (lambda (symbol)
950 (and (or (boundp symbol
)
951 ;; For variables not yet loaded.
952 (get symbol
'standard-value
)
953 ;; For groups the previous test fails, this one
954 ;; could be used to determine if symbol is a
955 ;; group. Is there a better way for this?
956 (get symbol
'group-documentation
))
957 (let ((version (get symbol
'custom-version
)))
959 (or (null since-version
)
960 (customize-version-lessp since-version version
))
961 (if (member version versions
)
963 ;;; Collect all versions that we use.
964 (push version versions
))))
966 ;; We have to set the right thing here,
967 ;; depending if we have a group or a
969 (if (get symbol
'group-documentation
)
970 (cons (list symbol
'custom-group
) found
)
971 (cons (list symbol
'custom-variable
) found
))))))
973 (error "No user option defaults have been changed since Emacs %s"
978 (cdr (assoc (car versions
) custom-versions-load-alist
)))
980 (setq versions
(cdr versions
)))
981 (put 'custom-versions-load-alist
'custom-loads
982 ;; Get all the files that correspond to element from the
983 ;; VERSIONS list. This could use some simplification.
984 (apply 'nconc flist
)))
985 ;; Because we set all the files needed to be loaded as a
986 ;; `custom-loads' property to `custom-versions-load-alist' this
987 ;; call will actually load them.
988 (custom-load-symbol 'custom-versions-load-alist
)
990 (put 'custom-versions-load-alist
'custom-loads nil
)
991 (custom-buffer-create (custom-sort-items found t
'first
)
992 "*Customize Changed Options*"))))
994 (defun customize-version-lessp (version1 version2
)
995 ;; In case someone made a mistake and left out the quotes
996 ;; in the :version value.
997 (if (numberp version2
)
998 (setq version2
(prin1-to-string version2
)))
999 (let (major1 major2 minor1 minor2
)
1000 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1
)
1001 (setq major1
(read (match-string 1 version1
)))
1002 (setq minor1
(read (match-string 2 version1
)))
1003 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2
)
1004 (setq major2
(read (match-string 1 version2
)))
1005 (setq minor2
(read (match-string 2 version2
)))
1006 (or (< major1 major2
)
1007 (and (= major1 major2
)
1008 (< minor1 minor2
)))))
1011 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1014 (defun customize-option-other-window (symbol)
1015 "Customize SYMBOL, which must be a user option variable.
1016 Show the buffer in another window, but don't select it."
1017 (interactive (custom-variable-prompt))
1018 (custom-buffer-create-other-window
1019 (list (list symbol
'custom-variable
))
1020 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol
))))
1023 (defun customize-face (&optional symbol
)
1024 "Customize SYMBOL, which should be a face name or nil.
1025 If SYMBOL is nil, customize all faces."
1026 (interactive (list (completing-read "Customize face: (default all) "
1027 obarray
'custom-facep t
)))
1028 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
1029 (custom-buffer-create (custom-sort-items
1030 (mapcar (lambda (symbol)
1031 (list symbol
'custom-face
))
1034 "*Customize Faces*")
1035 (when (stringp symbol
)
1036 (setq symbol
(intern symbol
)))
1037 (unless (symbolp symbol
)
1038 (error "Should be a symbol %S" symbol
))
1039 (custom-buffer-create (list (list symbol
'custom-face
))
1040 (format "*Customize Face: %s*"
1041 (custom-unlispify-tag-name symbol
)))))
1044 (defun customize-face-other-window (&optional symbol
)
1045 "Show customization buffer for FACE in other window."
1046 (interactive (list (completing-read "Customize face: "
1047 obarray
'custom-facep t
)))
1048 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
1050 (if (stringp symbol
)
1051 (setq symbol
(intern symbol
)))
1052 (unless (symbolp symbol
)
1053 (error "Should be a symbol %S" symbol
))
1054 (custom-buffer-create-other-window
1055 (list (list symbol
'custom-face
))
1056 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol
)))))
1059 (defun customize-customized ()
1060 "Customize all user options set since the last save in this session."
1063 (mapatoms (lambda (symbol)
1064 (and (or (get symbol
'customized-face
)
1065 (get symbol
'customized-face-comment
))
1066 (custom-facep symbol
)
1067 (push (list symbol
'custom-face
) found
))
1068 (and (or (get symbol
'customized-value
)
1069 (get symbol
'customized-variable-comment
))
1071 (push (list symbol
'custom-variable
) found
))))
1073 (error "No customized user options")
1074 (custom-buffer-create (custom-sort-items found t nil
)
1075 "*Customize Customized*"))))
1078 (defun customize-saved ()
1079 "Customize all already saved user options."
1082 (mapatoms (lambda (symbol)
1083 (and (or (get symbol
'saved-face
)
1084 (get symbol
'saved-face-comment
))
1085 (custom-facep symbol
)
1086 (push (list symbol
'custom-face
) found
))
1087 (and (or (get symbol
'saved-value
)
1088 (get symbol
'saved-variable-comment
))
1090 (push (list symbol
'custom-variable
) found
))))
1092 (error "No saved user options")
1093 (custom-buffer-create (custom-sort-items found t nil
)
1094 "*Customize Saved*"))))
1097 (defun customize-apropos (regexp &optional all
)
1098 "Customize all user options matching REGEXP.
1099 If ALL is `options', include only options.
1100 If ALL is `faces', include only faces.
1101 If ALL is `groups', include only groups.
1102 If ALL is t (interactively, with prefix arg), include options which are not
1103 user-settable, as well as faces and groups."
1104 (interactive "sCustomize regexp: \nP")
1106 (mapatoms (lambda (symbol)
1107 (when (string-match regexp
(symbol-name symbol
))
1108 (when (and (not (memq all
'(faces options
)))
1109 (get symbol
'custom-group
))
1110 (push (list symbol
'custom-group
) found
))
1111 (when (and (not (memq all
'(options groups
)))
1112 (custom-facep symbol
))
1113 (push (list symbol
'custom-face
) found
))
1114 (when (and (not (memq all
'(groups faces
)))
1116 (or (get symbol
'saved-value
)
1117 (get symbol
'standard-value
)
1118 (if (memq all
'(nil options
))
1119 (user-variable-p symbol
)
1120 (get symbol
'variable-documentation
))))
1121 (push (list symbol
'custom-variable
) found
)))))
1123 (error "No matches")
1124 (custom-buffer-create (custom-sort-items found t
1125 custom-buffer-order-groups
)
1126 "*Customize Apropos*"))))
1129 (defun customize-apropos-options (regexp &optional arg
)
1130 "Customize all user options matching REGEXP.
1131 With prefix arg, include options which are not user-settable."
1132 (interactive "sCustomize regexp: \nP")
1133 (customize-apropos regexp
(or arg
'options
)))
1136 (defun customize-apropos-faces (regexp)
1137 "Customize all user faces matching REGEXP."
1138 (interactive "sCustomize regexp: \n")
1139 (customize-apropos regexp
'faces
))
1142 (defun customize-apropos-groups (regexp)
1143 "Customize all user groups matching REGEXP."
1144 (interactive "sCustomize regexp: \n")
1145 (customize-apropos regexp
'groups
))
1149 (defcustom custom-buffer-style
'links
1150 "Control the presentation style for customization buffers.
1151 The value should be a symbol, one of:
1153 brackets: groups nest within each other with big horizontal brackets.
1154 links: groups have links to subgroups."
1155 :type
'(radio (const brackets
)
1157 :group
'custom-buffer
)
1159 ;; If we pass BUFFER to `bury-buffer', the buffer isn't removed from
1161 (defun custom-bury-buffer (buffer)
1164 (defcustom custom-buffer-done-function
'custom-bury-buffer
1165 "*Function called to remove a Custom buffer when the user is done with it.
1166 Called with one argument, the buffer to remove."
1167 :type
'(choice (function-item :tag
"Bury buffer" custom-bury-buffer
)
1168 (function-item :tag
"Kill buffer" kill-buffer
)
1169 (function :tag
"Other"))
1171 :group
'custom-buffer
)
1173 (defcustom custom-buffer-indent
3
1174 "Number of spaces to indent nested groups."
1176 :group
'custom-buffer
)
1179 (defun custom-buffer-create (options &optional name description
)
1180 "Create a buffer containing OPTIONS.
1181 Optional NAME is the name of the buffer.
1182 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1183 SYMBOL is a customization option, and WIDGET is a widget for editing
1185 (unless name
(setq name
"*Customization*"))
1186 (kill-buffer (get-buffer-create name
))
1187 (pop-to-buffer (get-buffer-create name
))
1188 (custom-buffer-create-internal options description
))
1191 (defun custom-buffer-create-other-window (options &optional name description
)
1192 "Create a buffer containing OPTIONS.
1193 Optional NAME is the name of the buffer.
1194 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1195 SYMBOL is a customization option, and WIDGET is a widget for editing
1197 (unless name
(setq name
"*Customization*"))
1198 (kill-buffer (get-buffer-create name
))
1199 (let ((window (selected-window))
1201 (special-display-buffer-names nil
)
1202 (special-display-regexps nil
)
1203 (same-window-buffer-names nil
)
1204 (same-window-regexps nil
))
1205 (pop-to-buffer (get-buffer-create name
))
1206 (custom-buffer-create-internal options description
)
1207 (select-window window
)))
1209 (defcustom custom-reset-button-menu nil
1210 "If non-nil, only show a single reset button in customize buffers.
1211 This button will have a menu with all three reset operations."
1213 :group
'custom-buffer
)
1215 (defun Custom-buffer-done (&rest ignore
)
1216 "Remove current buffer by calling `custom-buffer-done-function'."
1218 (funcall custom-buffer-done-function
(current-buffer)))
1220 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1221 '(("unspecified" . unspecified
))))
1222 "If non-nil, indicate active buttons in a `raised-button' style.
1223 Otherwise use brackets."
1226 :group
'custom-buffer
)
1228 (defun custom-buffer-create-internal (options &optional description
)
1229 (message "Creating customization buffer...")
1231 (widget-insert "This is a customization buffer")
1233 (widget-insert description
))
1234 (widget-insert (format ".
1235 %s show active fields; type RET or click mouse-1
1236 on an active field to invoke its action. Editing an option value
1237 changes the text in the buffer; invoke the State button and
1238 choose the Set operation to set the option value.
1239 Invoke " (if custom-raised-buttons
1241 "Square brackets")))
1242 (widget-create 'info-link
1244 :help-echo
"Read the online help."
1245 "(emacs)Easy Customization")
1246 (widget-insert " for more information.\n\n")
1247 (message "Creating customization buttons...")
1248 (widget-insert "Operate on everything in this buffer:\n ")
1249 (widget-create 'push-button
1250 :tag
"Set for Current Session"
1252 Make your editing in this buffer take effect for this session."
1253 :action
(lambda (widget &optional event
)
1256 (widget-create 'push-button
1257 :tag
"Save for Future Sessions"
1259 Make your editing in this buffer take effect for future Emacs sessions."
1260 :action
(lambda (widget &optional event
)
1262 (if custom-reset-button-menu
1265 (widget-create 'push-button
1267 :help-echo
"Show a menu with reset operations."
1268 :mouse-down-action
(lambda (&rest junk
) t
)
1269 :action
(lambda (widget &optional event
)
1270 (custom-reset event
))))
1271 (widget-insert "\n ")
1272 (widget-create 'push-button
1275 Reset all edited text in this buffer to reflect current values."
1276 :action
'Custom-reset-current
)
1278 (widget-create 'push-button
1279 :tag
"Reset to Saved"
1281 Reset all values in this buffer to their saved settings."
1282 :action
'Custom-reset-saved
)
1284 (widget-create 'push-button
1285 :tag
"Erase Customization"
1287 Un-customize all values in this buffer. They get their standard settings."
1288 :action
'Custom-reset-standard
))
1290 (widget-create 'push-button
1292 :help-echo
"Bury or kill the buffer."
1293 :action
#'Custom-buffer-done
)
1294 (widget-insert "\n\n")
1295 (message "Creating customization items...")
1296 (setq custom-options
1297 (if (= (length options
) 1)
1298 (mapcar (lambda (entry)
1299 (widget-create (nth 1 entry
)
1300 :documentation-shown t
1301 :custom-state
'unknown
1302 :tag
(custom-unlispify-tag-name
1304 :value
(nth 0 entry
)))
1307 (length (length options
)))
1308 (mapcar (lambda (entry)
1310 (message "Creating customization items ...%2d%%"
1311 (/ (* 100.0 count
) length
))
1312 (widget-create (nth 1 entry
)
1313 :tag
(custom-unlispify-tag-name
1315 :value
(nth 0 entry
))
1316 (setq count
(1+ count
))
1317 (unless (eq (preceding-char) ?
\n)
1318 (widget-insert "\n"))
1319 (widget-insert "\n")))
1321 (unless (eq (preceding-char) ?
\n)
1322 (widget-insert "\n"))
1323 (message "Creating customization items ...%2d%%done" 100)
1324 (unless (eq custom-buffer-style
'tree
)
1325 (mapcar 'custom-magic-reset custom-options
))
1326 (message "Creating customization setup...")
1328 (goto-char (point-min))
1329 (message "Creating customization buffer...done"))
1331 ;;; The Tree Browser.
1334 (defun customize-browse (&optional group
)
1335 "Create a tree browser for the customize hierarchy."
1338 (setq group
'emacs
))
1339 (let ((name "*Customize Browser*"))
1340 (kill-buffer (get-buffer-create name
))
1341 (pop-to-buffer (get-buffer-create name
)))
1344 Square brackets show active fields; type RET or click mouse-1
1345 on an active field to invoke its action.
1346 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1347 (if custom-browse-only-groups
1349 Invoke the [Group] button below to edit that item in another window.\n\n")
1350 (widget-insert "Invoke the ")
1351 (widget-create 'item
1354 :tag-glyph
"folder")
1355 (widget-insert ", ")
1356 (widget-create 'item
1360 (widget-insert ", and ")
1361 (widget-create 'item
1364 :tag-glyph
"option")
1365 (widget-insert " buttons below to edit that
1366 item in another window.\n\n"))
1367 (let ((custom-buffer-style 'tree
))
1368 (widget-create 'custom-group
1370 :custom-state
'unknown
1371 :tag
(custom-unlispify-tag-name group
)
1373 (goto-char (point-min)))
1375 (define-widget 'custom-browse-visibility
'item
1376 "Control visibility of items in the customize tree browser."
1378 :action
'custom-browse-visibility-action
)
1380 (defun custom-browse-visibility-action (widget &rest ignore
)
1381 (let ((custom-buffer-style 'tree
))
1382 (custom-toggle-parent widget
)))
1384 (define-widget 'custom-browse-group-tag
'push-button
1385 "Show parent in other window when activated."
1388 :action
'custom-browse-group-tag-action
)
1390 (defun custom-browse-group-tag-action (widget &rest ignore
)
1391 (let ((parent (widget-get widget
:parent
)))
1392 (customize-group-other-window (widget-value parent
))))
1394 (define-widget 'custom-browse-variable-tag
'push-button
1395 "Show parent in other window when activated."
1398 :action
'custom-browse-variable-tag-action
)
1400 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1401 (let ((parent (widget-get widget
:parent
)))
1402 (customize-variable-other-window (widget-value parent
))))
1404 (define-widget 'custom-browse-face-tag
'push-button
1405 "Show parent in other window when activated."
1408 :action
'custom-browse-face-tag-action
)
1410 (defun custom-browse-face-tag-action (widget &rest ignore
)
1411 (let ((parent (widget-get widget
:parent
)))
1412 (customize-face-other-window (widget-value parent
))))
1414 (defconst custom-browse-alist
'((" " "space")
1420 (defun custom-browse-insert-prefix (prefix)
1421 "Insert PREFIX. On XEmacs convert it to line graphics."
1422 ;; Fixme: do graphics.
1423 (if nil
; (string-match "XEmacs" emacs-version)
1426 (while (not (string-equal prefix
""))
1427 (let ((entry (substring prefix
0 3)))
1428 (setq prefix
(substring prefix
3))
1429 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1430 (name (nth 1 (assoc entry custom-browse-alist
))))
1431 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1432 (overlay-put overlay
'start-open t
)
1433 (overlay-put overlay
'end-open t
)))))
1436 ;;; Modification of Basic Widgets.
1438 ;; We add extra properties to the basic widgets needed here. This is
1439 ;; fine, as long as we are careful to stay within out own namespace.
1441 ;; We want simple widgets to be displayed by default, but complex
1442 ;; widgets to be hidden.
1444 (widget-put (get 'item
'widget-type
) :custom-show t
)
1445 (widget-put (get 'editable-field
'widget-type
)
1446 :custom-show
(lambda (widget value
)
1447 (let ((pp (pp-to-string value
)))
1448 (cond ((string-match "\n" pp
)
1453 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1455 ;;; The `custom-manual' Widget.
1457 (define-widget 'custom-manual
'info-link
1458 "Link to the manual entry for this customization option."
1459 :help-echo
"Read the manual entry for this option."
1462 ;;; The `custom-magic' Widget.
1464 (defgroup custom-magic-faces nil
1465 "Faces used by the magic button."
1466 :group
'custom-faces
1467 :group
'custom-buffer
)
1469 (defface custom-invalid-face
'((((class color
))
1470 (:foreground
"yellow" :background
"red"))
1472 (:bold t
:italic t
:underline t
)))
1473 "Face used when the customize item is invalid."
1474 :group
'custom-magic-faces
)
1476 (defface custom-rogue-face
'((((class color
))
1477 (:foreground
"pink" :background
"black"))
1480 "Face used when the customize item is not defined for customization."
1481 :group
'custom-magic-faces
)
1483 (defface custom-modified-face
'((((class color
))
1484 (:foreground
"white" :background
"blue"))
1487 "Face used when the customize item has been modified."
1488 :group
'custom-magic-faces
)
1490 (defface custom-set-face
'((((class color
))
1491 (:foreground
"blue" :background
"white"))
1494 "Face used when the customize item has been set."
1495 :group
'custom-magic-faces
)
1497 (defface custom-changed-face
'((((class color
))
1498 (:foreground
"white" :background
"blue"))
1501 "Face used when the customize item has been changed."
1502 :group
'custom-magic-faces
)
1504 (defface custom-saved-face
'((t (:underline t
)))
1505 "Face used when the customize item has been saved."
1506 :group
'custom-magic-faces
)
1508 (defconst custom-magic-alist
'((nil "#" underline
"\
1509 uninitialized, you should not see this.")
1510 (unknown "?" italic
"\
1511 unknown, you should not see this.")
1512 (hidden "-" default
"\
1513 hidden, invoke \"Show\" in the previous line to show." "\
1514 group now hidden, invoke \"Show\", above, to show contents.")
1515 (invalid "x" custom-invalid-face
"\
1516 the value displayed for this %c is invalid and cannot be set.")
1517 (modified "*" custom-modified-face
"\
1518 you have edited the value as text, but you have not set the %c." "\
1519 you have edited something in this group, but not set it.")
1520 (set "+" custom-set-face
"\
1521 you have set this %c, but not saved it for future sessions." "\
1522 something in this group has been set, but not saved.")
1523 (changed ":" custom-changed-face
"\
1524 this %c has been changed outside the customize buffer." "\
1525 something in this group has been changed outside customize.")
1526 (saved "!" custom-saved-face
"\
1527 this %c has been set and saved." "\
1528 something in this group has been set and saved.")
1529 (rogue "@" custom-rogue-face
"\
1530 this %c has not been changed with customize." "\
1531 something in this group is not prepared for customization.")
1532 (standard " " nil
"\
1533 this %c is unchanged from its standard setting." "\
1534 visible group members are all at standard settings."))
1535 "Alist of customize option states.
1536 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1538 STATE is one of the following symbols:
1541 For internal use, should never occur.
1543 For internal use, should never occur.
1545 This item is not being displayed.
1547 This item is modified, but has an invalid form.
1549 This item is modified, and has a valid form.
1551 This item has been set but not saved.
1553 The current value of this item has been changed temporarily.
1555 This item is marked for saving.
1557 This item has no customization information.
1559 This item is unchanged from the standard setting.
1561 MAGIC is a string used to present that state.
1563 FACE is a face used to present the state.
1565 ITEM-DESC is a string describing the state for options.
1567 GROUP-DESC is a string describing the state for groups. If this is
1568 left out, ITEM-DESC will be used.
1570 The string %c in either description will be replaced with the
1571 category of the item. These are `group'. `option', and `face'.
1573 The list should be sorted most significant first.")
1575 (defcustom custom-magic-show
'long
1576 "If non-nil, show textual description of the state.
1577 If `long', show a full-line description, not just one word."
1578 :type
'(choice (const :tag
"no" nil
)
1580 (other :tag
"short" short
))
1581 :group
'custom-buffer
)
1583 (defcustom custom-magic-show-hidden
'(option face
)
1584 "Control whether the State button is shown for hidden items.
1585 The value should be a list with the custom categories where the State
1586 button should be visible. Possible categories are `group', `option',
1588 :type
'(set (const group
) (const option
) (const face
))
1589 :group
'custom-buffer
)
1591 (defcustom custom-magic-show-button nil
1592 "Show a \"magic\" button indicating the state of each customization option."
1594 :group
'custom-buffer
)
1596 (define-widget 'custom-magic
'default
1597 "Show and manipulate state for a customization option."
1599 :action
'widget-parent-action
1602 :value-create
'custom-magic-value-create
1603 :value-delete
'widget-children-value-delete
)
1605 (defun widget-magic-mouse-down-action (widget &optional event
)
1606 ;; Non-nil unless hidden.
1607 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1611 (defun custom-magic-value-create (widget)
1612 ;; Create compact status report for WIDGET.
1613 (let* ((parent (widget-get widget
:parent
))
1614 (state (widget-get parent
:custom-state
))
1615 (hidden (eq state
'hidden
))
1616 (entry (assq state custom-magic-alist
))
1617 (magic (nth 1 entry
))
1618 (face (nth 2 entry
))
1619 (category (widget-get parent
:custom-category
))
1620 (text (or (and (eq category
'group
)
1623 (form (widget-get parent
:custom-form
))
1625 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1626 (setq text
(concat (match-string 1 text
)
1627 (symbol-name category
)
1628 (match-string 2 text
))))
1629 (when (and custom-magic-show
1631 (memq category custom-magic-show-hidden
)))
1633 (when (and (eq category
'group
)
1634 (not (and (eq custom-buffer-style
'links
)
1635 (> (widget-get parent
:custom-level
) 1))))
1636 (insert-char ?\
(* custom-buffer-indent
1637 (widget-get parent
:custom-level
))))
1638 (push (widget-create-child-and-convert
1640 :help-echo
"Change the state of this item."
1641 :format
(if hidden
"%t" "%[%t%]")
1642 :button-prefix
'widget-push-button-prefix
1643 :button-suffix
'widget-push-button-suffix
1644 :mouse-down-action
'widget-magic-mouse-down-action
1648 (let ((start (point)))
1649 (if (eq custom-magic-show
'long
)
1651 (insert (symbol-name state
)))
1652 (cond ((eq form
'lisp
)
1654 ((eq form
'mismatch
)
1655 (insert " (mismatch)")))
1656 (put-text-property start
(point) 'face
'custom-state-face
))
1658 (when (and (eq category
'group
)
1659 (not (and (eq custom-buffer-style
'links
)
1660 (> (widget-get parent
:custom-level
) 1))))
1661 (insert-char ?\
(* custom-buffer-indent
1662 (widget-get parent
:custom-level
))))
1663 (when custom-magic-show-button
1664 (when custom-magic-show
1665 (let ((indent (widget-get parent
:indent
)))
1667 (insert-char ? indent
))))
1668 (push (widget-create-child-and-convert
1670 :mouse-down-action
'widget-magic-mouse-down-action
1674 :help-echo
"Change the state."
1675 :format
(if hidden
"%t" "%[%t%]")
1676 :tag
(if (memq form
'(lisp mismatch
))
1677 (concat "(" magic
")")
1678 (concat "[" magic
"]")))
1681 (widget-put widget
:children children
)))
1683 (defun custom-magic-reset (widget)
1684 "Redraw the :custom-magic property of WIDGET."
1685 (let ((magic (widget-get widget
:custom-magic
)))
1686 (widget-value-set magic
(widget-value magic
))))
1688 ;;; The `custom' Widget.
1690 (defface custom-button-face
1691 '((((type x
) (class color
)) ; Like default modeline
1692 (:box
(:line-width
2 :style released-button
) :background
"lightgrey"))
1695 "Face used for buttons in customization buffers."
1697 :group
'custom-faces
)
1699 (defface custom-button-pressed-face
1700 '((((type x
) (class color
))
1701 (:box
(:line-width
2 :style pressed-button
) :background
"lightgrey"))
1703 (:inverse-video t
)))
1704 "Face used for buttons in customization buffers."
1706 :group
'custom-faces
)
1708 (defface custom-documentation-face nil
1709 "Face used for documentation strings in customization buffers."
1710 :group
'custom-faces
)
1712 (defface custom-state-face
'((((class color
)
1714 (:foreground
"lime green"))
1717 (:foreground
"dark green"))
1719 "Face used for State descriptions in the customize buffer."
1720 :group
'custom-faces
)
1722 (define-widget 'custom
'default
1723 "Customize a user option."
1725 :convert-widget
'custom-convert-widget
1726 :notify
'custom-notify
1729 :custom-state
'hidden
1730 :documentation-property
'widget-subclass-responsibility
1731 :value-create
'widget-subclass-responsibility
1732 :value-delete
'widget-children-value-delete
1733 :value-get
'widget-value-value-get
1734 :validate
'widget-children-validate
1735 :match
(lambda (widget value
) (symbolp value
)))
1737 (defun custom-convert-widget (widget)
1738 ;; Initialize :value and :tag from :args in WIDGET.
1739 (let ((args (widget-get widget
:args
)))
1741 (widget-put widget
:value
(widget-apply widget
1742 :value-to-internal
(car args
)))
1743 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1744 (widget-put widget
:args nil
)))
1747 (defun custom-notify (widget &rest args
)
1748 "Keep track of changes."
1749 (let ((state (widget-get widget
:custom-state
)))
1750 (unless (eq state
'modified
)
1751 (unless (memq state
'(nil unknown hidden
))
1752 (widget-put widget
:custom-state
'modified
))
1753 (custom-magic-reset widget
)
1754 (apply 'widget-default-notify widget args
))))
1756 (defun custom-redraw (widget)
1757 "Redraw WIDGET with current settings."
1758 (let ((line (count-lines (point-min) (point)))
1759 (column (current-column))
1761 (from (marker-position (widget-get widget
:from
)))
1762 (to (marker-position (widget-get widget
:to
))))
1764 (widget-value-set widget
(widget-value widget
))
1765 (custom-redraw-magic widget
))
1766 (when (and (>= pos from
) (<= pos to
))
1771 (goto-line (1+ line
)))
1772 (move-to-column column
))
1775 (defun custom-redraw-magic (widget)
1776 "Redraw WIDGET state with current settings."
1778 (let ((magic (widget-get widget
:custom-magic
)))
1780 (widget-value-set magic
(widget-value magic
))
1781 (when (setq widget
(widget-get widget
:group
))
1782 (custom-group-state-update widget
)))
1784 (setq widget nil
)))))
1787 (defun custom-show (widget value
)
1788 "Non-nil if WIDGET should be shown with VALUE by default."
1789 (let ((show (widget-get widget
:custom-show
)))
1795 (funcall show widget value
)))))
1797 (defvar custom-load-recursion nil
1798 "Hack to avoid recursive dependencies.")
1800 (defun custom-load-symbol (symbol)
1801 "Load all dependencies for SYMBOL."
1802 (unless custom-load-recursion
1803 (let ((custom-load-recursion t
)
1804 (loads (get symbol
'custom-loads
))
1807 (setq load
(car loads
)
1809 (cond ((symbolp load
)
1813 ;; Don't reload a file already loaded.
1814 ((and (boundp 'preloaded-file-list
)
1815 (member load preloaded-file-list
)))
1816 ((assoc load load-history
))
1817 ((assoc (locate-library load
) load-history
))
1820 ;; Without this, we would load cus-edit recursively.
1821 ;; We are still loading it when we call this,
1822 ;; and it is not in load-history yet.
1823 (or (equal load
"cus-edit")
1824 (load-library load
))
1827 (defun custom-load-widget (widget)
1828 "Load all dependencies for WIDGET."
1829 (custom-load-symbol (widget-value widget
)))
1831 (defun custom-unloaded-symbol-p (symbol)
1832 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1834 (loads (get symbol
'custom-loads
))
1837 (setq load
(car loads
)
1839 (cond ((symbolp load
)
1840 (unless (featurep load
)
1842 ((assoc load load-history
))
1843 ((assoc (locate-library load
) load-history
)
1849 (defun custom-unloaded-widget-p (widget)
1850 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1851 (custom-unloaded-symbol-p (widget-value widget
)))
1853 (defun custom-toggle-hide (widget)
1854 "Toggle visibility of WIDGET."
1855 (custom-load-widget widget
)
1856 (let ((state (widget-get widget
:custom-state
)))
1857 (cond ((memq state
'(invalid modified
))
1858 (error "There are unset changes"))
1860 (widget-put widget
:custom-state
'unknown
))
1862 (widget-put widget
:documentation-shown nil
)
1863 (widget-put widget
:custom-state
'hidden
)))
1864 (custom-redraw widget
)
1867 (defun custom-toggle-parent (widget &rest ignore
)
1868 "Toggle visibility of parent of WIDGET."
1869 (custom-toggle-hide (widget-get widget
:parent
)))
1871 (defun custom-add-see-also (widget &optional prefix
)
1872 "Add `See also ...' to WIDGET if there are any links.
1873 Insert PREFIX first if non-nil."
1874 (let* ((symbol (widget-get widget
:value
))
1875 (links (get symbol
'custom-links
))
1876 (many (> (length links
) 2))
1877 (buttons (widget-get widget
:buttons
))
1878 (indent (widget-get widget
:indent
)))
1881 (insert-char ?\ indent
))
1884 (insert "See also ")
1886 (push (widget-create-child-and-convert widget
(car links
))
1888 (setq links
(cdr links
))
1897 (widget-put widget
:buttons buttons
))))
1899 (defun custom-add-parent-links (widget &optional initial-string
)
1900 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1901 The value if non-nil if any parents were found.
1902 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1903 (let ((name (widget-value widget
))
1904 (type (widget-type widget
))
1905 (buttons (widget-get widget
:buttons
))
1908 (insert (or initial-string
"Parent groups:"))
1909 (mapatoms (lambda (symbol)
1910 (let ((entry (assq name
(get symbol
'custom-group
))))
1911 (when (eq (nth 1 entry
) type
)
1913 (push (widget-create-child-and-convert
1914 widget
'custom-group-link
1915 :tag
(custom-unlispify-tag-name symbol
)
1919 (widget-put widget
:buttons buttons
)
1922 (delete-region start
(point)))
1925 ;;; The `custom-comment' Widget.
1927 ;; like the editable field
1928 (defface custom-comment-face
'((((class grayscale color
)
1930 (:background
"gray85"))
1931 (((class grayscale color
)
1933 (:background
"dim gray"))
1936 "Face used for comments on variables or faces"
1938 :group
'custom-faces
)
1940 ;; like font-lock-comment-face
1941 (defface custom-comment-tag-face
1942 '((((class color
) (background dark
)) (:foreground
"gray80"))
1943 (((class color
) (background light
)) (:foreground
"blue4"))
1944 (((class grayscale
) (background light
))
1945 (:foreground
"DimGray" :bold t
:italic t
))
1946 (((class grayscale
) (background dark
))
1947 (:foreground
"LightGray" :bold t
:italic t
))
1949 "Face used for variables or faces comment tags"
1950 :group
'custom-faces
)
1952 (define-widget 'custom-comment
'string
1955 :help-echo
"Edit a comment here."
1956 :sample-face
'custom-comment-tag-face
1957 :value-face
'custom-comment-face
1959 :create
'custom-comment-create
)
1961 (defun custom-comment-create (widget)
1962 (let* ((null-comment (equal "" (widget-value widget
))))
1963 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
1965 (widget-default-create widget
)
1966 ;; `widget-default-delete' expects markers in these slots --
1967 ;; maybe it shouldn't.
1968 (widget-put widget
:from
(point-marker))
1969 (widget-put widget
:to
(point-marker)))))
1971 (defun custom-comment-hide (widget)
1972 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
1974 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
1975 ;; the global custom one
1976 (defun custom-comment-show (widget)
1977 (widget-put widget
:comment-shown t
)
1978 (custom-redraw widget
)
1981 (defun custom-comment-invisible-p (widget)
1982 (let ((val (widget-value (widget-get widget
:comment-widget
))))
1984 (not (widget-get widget
:comment-shown
)))))
1986 ;;; The `custom-variable' Widget.
1988 (defface custom-variable-tag-face
'((((class color
)
1990 (:foreground
"light blue" :underline t
))
1993 (:foreground
"blue" :underline t
))
1995 "Face used for unpushable variable tags."
1996 :group
'custom-faces
)
1998 (defface custom-variable-button-face
'((t (:underline t
:bold t
)))
1999 "Face used for pushable variable tags."
2000 :group
'custom-faces
)
2002 (defcustom custom-variable-default-form
'edit
2003 "Default form of displaying variable values."
2004 :type
'(choice (const edit
)
2006 :group
'custom-buffer
2009 (define-widget 'custom-variable
'custom
2010 "Customize variable."
2012 :help-echo
"Set or reset this variable."
2013 :documentation-property
'variable-documentation
2014 :custom-category
'option
2016 :custom-menu
'custom-variable-menu-create
2017 :custom-form nil
; defaults to value of `custom-variable-default-form'
2018 :value-create
'custom-variable-value-create
2019 :action
'custom-variable-action
2020 :custom-set
'custom-variable-set
2021 :custom-save
'custom-variable-save
2022 :custom-reset-current
'custom-redraw
2023 :custom-reset-saved
'custom-variable-reset-saved
2024 :custom-reset-standard
'custom-variable-reset-standard
)
2026 (defun custom-variable-type (symbol)
2027 "Return a widget suitable for editing the value of SYMBOL.
2028 If SYMBOL has a `custom-type' property, use that.
2029 Otherwise, look up symbol in `custom-guess-type-alist'."
2030 (let* ((type (or (get symbol
'custom-type
)
2031 (and (not (get symbol
'standard-value
))
2032 (custom-guess-type symbol
))
2034 (options (get symbol
'custom-options
))
2035 (tmp (if (listp type
)
2036 (copy-sequence type
)
2039 (widget-put tmp
:options options
))
2042 (defun custom-variable-value-create (widget)
2043 "Here is where you edit the variable's value."
2044 (custom-load-widget widget
)
2045 (unless (widget-get widget
:custom-form
)
2046 (widget-put widget
:custom-form custom-variable-default-form
))
2047 (let* ((buttons (widget-get widget
:buttons
))
2048 (children (widget-get widget
:children
))
2049 (form (widget-get widget
:custom-form
))
2050 (state (widget-get widget
:custom-state
))
2051 (symbol (widget-get widget
:value
))
2052 (tag (widget-get widget
:tag
))
2053 (type (custom-variable-type symbol
))
2054 (conv (widget-convert type
))
2055 (get (or (get symbol
'custom-get
) 'default-value
))
2056 (prefix (widget-get widget
:custom-prefix
))
2057 (last (widget-get widget
:custom-last
))
2058 (value (if (default-boundp symbol
)
2059 (funcall get symbol
)
2060 (widget-get conv
:value
))))
2061 ;; If the widget is new, the child determines whether it is hidden.
2063 ((custom-show type value
)
2064 (setq state
'unknown
))
2066 (setq state
'hidden
)))
2067 ;; If we don't know the state, see if we need to edit it in lisp form.
2068 (when (eq state
'unknown
)
2069 (unless (widget-apply conv
:match value
)
2070 ;; (widget-apply (widget-convert type) :match value)
2071 (setq form
'mismatch
)))
2072 ;; Now we can create the child widget.
2073 (cond ((eq custom-buffer-style
'tree
)
2074 (insert prefix
(if last
" `--- " " |--- "))
2075 (push (widget-create-child-and-convert
2076 widget
'custom-browse-variable-tag
)
2078 (insert " " tag
"\n")
2079 (widget-put widget
:buttons buttons
))
2081 ;; Indicate hidden value.
2082 (push (widget-create-child-and-convert
2085 :sample-face
'custom-variable-tag-face
2089 (push (widget-create-child-and-convert
2091 :help-echo
"Show the value of this option."
2092 :action
'custom-toggle-parent
2095 ((memq form
'(lisp mismatch
))
2096 ;; In lisp mode edit the saved value when possible.
2097 (let* ((value (cond ((get symbol
'saved-value
)
2098 (car (get symbol
'saved-value
)))
2099 ((get symbol
'standard-value
)
2100 (car (get symbol
'standard-value
)))
2101 ((default-boundp symbol
)
2102 (custom-quote (funcall get symbol
)))
2104 (custom-quote (widget-get conv
:value
))))))
2105 (insert (symbol-name symbol
) ": ")
2106 (push (widget-create-child-and-convert
2108 :help-echo
"Hide the value of this option."
2109 :action
'custom-toggle-parent
2113 (push (widget-create-child-and-convert
2115 :button-face
'custom-variable-button-face
2117 :tag
(symbol-name symbol
)
2123 (let* ((format (widget-get type
:format
))
2124 tag-format value-format
)
2125 (unless (string-match ":" format
)
2126 (error "Bad format"))
2127 (setq tag-format
(substring format
0 (match-end 0)))
2128 (setq value-format
(substring format
(match-end 0)))
2129 (push (widget-create-child-and-convert
2132 :action
'custom-tag-action
2133 :help-echo
"Change value of this option."
2134 :mouse-down-action
'custom-tag-mouse-down-action
2135 :button-face
'custom-variable-button-face
2136 :sample-face
'custom-variable-tag-face
2140 (push (widget-create-child-and-convert
2142 :help-echo
"Hide the value of this option."
2143 :action
'custom-toggle-parent
2146 (push (widget-create-child-and-convert
2148 :format value-format
2151 (unless (eq custom-buffer-style
'tree
)
2152 (unless (eq (preceding-char) ?
\n)
2153 (widget-insert "\n"))
2154 ;; Create the magic button.
2155 (let ((magic (widget-create-child-and-convert
2156 widget
'custom-magic nil
)))
2157 (widget-put widget
:custom-magic magic
)
2158 (push magic buttons
))
2159 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2160 ;; before the call to `widget-default-format-handler'. Otherwise, I
2161 ;; loose my current `buttons'. This function shouldn't be called like
2162 ;; this anyway. The doc string widget should be added like the others.
2164 (widget-put widget
:buttons buttons
)
2165 ;; Insert documentation.
2166 (widget-default-format-handler widget ?h
)
2168 ;; The comment field
2169 (unless (eq state
'hidden
)
2170 (let* ((comment (get symbol
'variable-comment
))
2172 (widget-create-child-and-convert
2173 widget
'custom-comment
2175 :value
(or comment
""))))
2176 (widget-put widget
:comment-widget comment-widget
)
2177 ;; Don't push it !!! Custom assumes that the first child is the
2179 (setq children
(append children
(list comment-widget
)))))
2180 ;; Update the rest of the properties properties.
2181 (widget-put widget
:custom-form form
)
2182 (widget-put widget
:children children
)
2183 ;; Now update the state.
2184 (if (eq state
'hidden
)
2185 (widget-put widget
:custom-state state
)
2186 (custom-variable-state-set widget
))
2188 (unless (eq state
'hidden
)
2189 (when (eq (widget-get widget
:custom-level
) 1)
2190 (custom-add-parent-links widget
))
2191 (custom-add-see-also widget
)))))
2193 (defun custom-tag-action (widget &rest args
)
2194 "Pass :action to first child of WIDGET's parent."
2195 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2198 (defun custom-tag-mouse-down-action (widget &rest args
)
2199 "Pass :mouse-down-action to first child of WIDGET's parent."
2200 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2201 :mouse-down-action args
))
2203 (defun custom-variable-state-set (widget)
2204 "Set the state of WIDGET."
2205 (let* ((symbol (widget-value widget
))
2206 (get (or (get symbol
'custom-get
) 'default-value
))
2207 (value (if (default-boundp symbol
)
2208 (funcall get symbol
)
2209 (widget-get widget
:value
)))
2210 (comment (get symbol
'variable-comment
))
2213 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2215 (get symbol
'customized-variable-comment
))
2217 (if (condition-case nil
2218 (and (equal value
(eval (car tmp
)))
2219 (equal comment temp
))
2223 ((progn (setq tmp
(get symbol
'saved-value
))
2224 (setq temp
(get symbol
'saved-variable-comment
))
2226 (if (condition-case nil
2227 (and (equal value
(eval (car tmp
)))
2228 (equal comment temp
))
2232 ((setq tmp
(get symbol
'standard-value
))
2233 (if (condition-case nil
2234 (and (equal value
(eval (car tmp
)))
2235 (equal comment nil
))
2240 (widget-put widget
:custom-state state
)))
2242 (defvar custom-variable-menu
2243 '(("Set for Current Session" custom-variable-set
2245 (eq (widget-get widget
:custom-state
) 'modified
)))
2246 ("Save for Future Sessions" custom-variable-save
2248 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
2249 ("Reset to Current" custom-redraw
2251 (and (default-boundp (widget-value widget
))
2252 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2253 ("Reset to Saved" custom-variable-reset-saved
2255 (and (or (get (widget-value widget
) 'saved-value
)
2256 (get (widget-value widget
) 'saved-variable-comment
))
2257 (memq (widget-get widget
:custom-state
)
2258 '(modified set changed rogue
)))))
2259 ("Erase Customization" custom-variable-reset-standard
2261 (and (get (widget-value widget
) 'standard-value
)
2262 (memq (widget-get widget
:custom-state
)
2263 '(modified set changed saved rogue
)))))
2264 ("---" ignore ignore
)
2265 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2266 ("---" ignore ignore
)
2267 ("Don't show as Lisp expression" custom-variable-edit
2269 (eq (widget-get widget
:custom-form
) 'lisp
)))
2270 ("Show initial Lisp expression" custom-variable-edit-lisp
2272 (eq (widget-get widget
:custom-form
) 'edit
))))
2273 "Alist of actions for the `custom-variable' widget.
2274 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2275 the menu entry, ACTION is the function to call on the widget when the
2276 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2277 widget as an argument, and returns non-nil if ACTION is valid on that
2278 widget. If FILTER is nil, ACTION is always valid.")
2280 (defun custom-variable-action (widget &optional event
)
2281 "Show the menu for `custom-variable' WIDGET.
2282 Optional EVENT is the location for the menu."
2283 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2284 (custom-toggle-hide widget
)
2285 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2286 (custom-variable-state-set widget
))
2287 (custom-redraw-magic widget
)
2288 (let* ((completion-ignore-case t
)
2289 (answer (widget-choose (concat "Operation on "
2290 (custom-unlispify-tag-name
2291 (widget-get widget
:value
)))
2292 (custom-menu-filter custom-variable-menu
2296 (funcall answer widget
)))))
2298 (defun custom-variable-edit (widget)
2299 "Edit value of WIDGET."
2300 (widget-put widget
:custom-state
'unknown
)
2301 (widget-put widget
:custom-form
'edit
)
2302 (custom-redraw widget
))
2304 (defun custom-variable-edit-lisp (widget)
2305 "Edit the lisp representation of the value of WIDGET."
2306 (widget-put widget
:custom-state
'unknown
)
2307 (widget-put widget
:custom-form
'lisp
)
2308 (custom-redraw widget
))
2310 (defun custom-variable-set (widget)
2311 "Set the current value for the variable being edited by WIDGET."
2312 (let* ((form (widget-get widget
:custom-form
))
2313 (state (widget-get widget
:custom-state
))
2314 (child (car (widget-get widget
:children
)))
2315 (symbol (widget-value widget
))
2316 (set (or (get symbol
'custom-set
) 'set-default
))
2317 (comment-widget (widget-get widget
:comment-widget
))
2318 (comment (widget-value comment-widget
))
2320 (cond ((eq state
'hidden
)
2321 (error "Cannot set hidden variable"))
2322 ((setq val
(widget-apply child
:validate
))
2323 (goto-char (widget-get val
:from
))
2324 (error "%s" (widget-get val
:error
)))
2325 ((memq form
'(lisp mismatch
))
2326 (when (equal comment
"")
2328 ;; Make the comment invisible by hand if it's empty
2329 (custom-comment-hide comment-widget
))
2330 (funcall set symbol
(eval (setq val
(widget-value child
))))
2331 (put symbol
'customized-value
(list val
))
2332 (put symbol
'variable-comment comment
)
2333 (put symbol
'customized-variable-comment comment
))
2335 (when (equal comment
"")
2337 ;; Make the comment invisible by hand if it's empty
2338 (custom-comment-hide comment-widget
))
2339 (funcall set symbol
(setq val
(widget-value child
)))
2340 (put symbol
'customized-value
(list (custom-quote val
)))
2341 (put symbol
'variable-comment comment
)
2342 (put symbol
'customized-variable-comment comment
)))
2343 (custom-variable-state-set widget
)
2344 (custom-redraw-magic widget
)))
2346 (defun custom-variable-save (widget)
2347 "Set and save the value for the variable being edited by WIDGET."
2348 (let* ((form (widget-get widget
:custom-form
))
2349 (state (widget-get widget
:custom-state
))
2350 (child (car (widget-get widget
:children
)))
2351 (symbol (widget-value widget
))
2352 (set (or (get symbol
'custom-set
) 'set-default
))
2353 (comment-widget (widget-get widget
:comment-widget
))
2354 (comment (widget-value comment-widget
))
2356 (cond ((eq state
'hidden
)
2357 (error "Cannot set hidden variable"))
2358 ((setq val
(widget-apply child
:validate
))
2359 (goto-char (widget-get val
:from
))
2360 (error "%s" (widget-get val
:error
)))
2361 ((memq form
'(lisp mismatch
))
2362 (when (equal comment
"")
2364 ;; Make the comment invisible by hand if it's empty
2365 (custom-comment-hide comment-widget
))
2366 (put symbol
'saved-value
(list (widget-value child
)))
2367 (funcall set symbol
(eval (widget-value child
)))
2368 (put symbol
'variable-comment comment
)
2369 (put symbol
'saved-variable-comment comment
))
2371 (when (equal comment
"")
2373 ;; Make the comment invisible by hand if it's empty
2374 (custom-comment-hide comment-widget
))
2375 (put symbol
'saved-value
2376 (list (custom-quote (widget-value child
))))
2377 (funcall set symbol
(widget-value child
))
2378 (put symbol
'variable-comment comment
)
2379 (put symbol
'saved-variable-comment comment
)))
2380 (put symbol
'customized-value nil
)
2381 (put symbol
'customized-variable-comment nil
)
2383 (custom-variable-state-set widget
)
2384 (custom-redraw-magic widget
)))
2386 (defun custom-variable-reset-saved (widget)
2387 "Restore the saved value for the variable being edited by WIDGET."
2388 (let* ((symbol (widget-value widget
))
2389 (set (or (get symbol
'custom-set
) 'set-default
))
2390 (comment-widget (widget-get widget
:comment-widget
))
2391 (value (get symbol
'saved-value
))
2392 (comment (get symbol
'saved-variable-comment
)))
2393 (cond ((or value comment
)
2394 (put symbol
'variable-comment comment
)
2396 (funcall set symbol
(eval (car value
)))
2399 (error "No saved value for %s" symbol
)))
2400 (put symbol
'customized-value nil
)
2401 (put symbol
'customized-variable-comment nil
)
2402 (widget-put widget
:custom-state
'unknown
)
2403 ;; This call will possibly make the comment invisible
2404 (custom-redraw widget
)))
2406 (defun custom-variable-reset-standard (widget)
2407 "Restore the standard setting for the variable being edited by WIDGET.
2408 This operation eliminates any saved setting for the variable,
2409 restoring it to the state of a variable that has never been customized."
2410 (let* ((symbol (widget-value widget
))
2411 (set (or (get symbol
'custom-set
) 'set-default
))
2412 (comment-widget (widget-get widget
:comment-widget
)))
2413 (if (get symbol
'standard-value
)
2414 (funcall set symbol
(eval (car (get symbol
'standard-value
))))
2415 (error "No standard setting known for %S" symbol
))
2416 (put symbol
'variable-comment nil
)
2417 (put symbol
'customized-value nil
)
2418 (put symbol
'customized-variable-comment nil
)
2419 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2420 (put symbol
'saved-value nil
)
2421 (put symbol
'saved-variable-comment nil
)
2423 (widget-put widget
:custom-state
'unknown
)
2424 ;; This call will possibly make the comment invisible
2425 (custom-redraw widget
)))
2427 ;;; The `custom-face-edit' Widget.
2429 (define-widget 'custom-face-edit
'checklist
2430 "Edit face attributes."
2434 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2435 :args
(mapcar (lambda (att)
2438 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2439 (list 'const
:format
"" :value
(nth 0 att
))
2441 custom-face-attributes
))
2443 ;;; The `custom-display' Widget.
2445 (define-widget 'custom-display
'menu-choice
2446 "Select a display type."
2449 :help-echo
"Specify frames where the face attributes should be used."
2450 :args
'((const :tag
"all" t
)
2454 :args
((group :sibling-args
(:help-echo
"\
2455 Only match the specified window systems.")
2456 (const :format
"Type: "
2458 (checklist :inline t
2461 :sibling-args
(:help-echo
"\
2462 The X11 Window System.")
2464 (const :format
"PM "
2465 :sibling-args
(:help-echo
"\
2466 OS/2 Presentation Manager.")
2468 (const :format
"W32 "
2469 :sibling-args
(:help-echo
"\
2472 (const :format
"DOS "
2473 :sibling-args
(:help-echo
"\
2476 (const :format
"TTY%n"
2477 :sibling-args
(:help-echo
"\
2478 Plain text terminals.")
2480 (group :sibling-args
(:help-echo
"\
2481 Only match the frames with the specified color support.")
2482 (const :format
"Class: "
2484 (checklist :inline t
2486 (const :format
"Color "
2487 :sibling-args
(:help-echo
"\
2488 Match color frames.")
2490 (const :format
"Grayscale "
2491 :sibling-args
(:help-echo
"\
2492 Match grayscale frames.")
2494 (const :format
"Monochrome%n"
2495 :sibling-args
(:help-echo
"\
2496 Match frames with no color support.")
2498 (group :sibling-args
(:help-echo
"\
2499 Only match frames with the specified intensity.")
2501 Background brightness: "
2503 (checklist :inline t
2505 (const :format
"Light "
2506 :sibling-args
(:help-echo
"\
2507 Match frames with light backgrounds.")
2509 (const :format
"Dark\n"
2510 :sibling-args
(:help-echo
"\
2511 Match frames with dark backgrounds.")
2514 ;;; The `custom-face' Widget.
2516 (defface custom-face-tag-face
'((t (:underline t
)))
2517 "Face used for face tags."
2518 :group
'custom-faces
)
2520 (defcustom custom-face-default-form
'selected
2521 "Default form of displaying face definition."
2522 :type
'(choice (const all
)
2525 :group
'custom-buffer
2528 (define-widget 'custom-face
'custom
2530 :sample-face
'custom-face-tag-face
2531 :help-echo
"Set or reset this face."
2532 :documentation-property
'(lambda (face)
2533 (face-doc-string face
))
2534 :value-create
'custom-face-value-create
2535 :action
'custom-face-action
2536 :custom-category
'face
2537 :custom-form nil
; defaults to value of `custom-face-default-form'
2538 :custom-set
'custom-face-set
2539 :custom-save
'custom-face-save
2540 :custom-reset-current
'custom-redraw
2541 :custom-reset-saved
'custom-face-reset-saved
2542 :custom-reset-standard
'custom-face-reset-standard
2543 :custom-menu
'custom-face-menu-create
)
2545 (define-widget 'custom-face-all
'editable-list
2546 "An editable list of display specifications and attributes."
2547 :entry-format
"%i %d %v"
2548 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2549 :append-button-args
'(:help-echo
"Append new display specification here.")
2550 :delete-button-args
'(:help-echo
"Delete this display specification.")
2551 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2553 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2554 "Converted version of the `custom-face-all' widget.")
2556 (define-widget 'custom-display-unselected
'item
2557 "A display specification that doesn't match the selected display."
2558 :match
'custom-display-unselected-match
)
2560 (defun custom-display-unselected-match (widget value
)
2561 "Non-nil if VALUE is an unselected display specification."
2562 (not (face-spec-set-match-display value
(selected-frame))))
2564 (define-widget 'custom-face-selected
'group
2565 "Edit the attributes of the selected display in a face specification."
2566 :args
'((repeat :format
""
2568 (group custom-display-unselected sexp
))
2569 (group (sexp :format
"") custom-face-edit
)
2574 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2575 "Converted version of the `custom-face-selected' widget.")
2577 (defun custom-face-value-create (widget)
2578 "Create a list of the display specifications for WIDGET."
2579 (let ((buttons (widget-get widget
:buttons
))
2581 (symbol (widget-get widget
:value
))
2582 (tag (widget-get widget
:tag
))
2583 (state (widget-get widget
:custom-state
))
2585 (is-last (widget-get widget
:custom-last
))
2586 (prefix (widget-get widget
:custom-prefix
)))
2588 (setq tag
(prin1-to-string symbol
)))
2589 (cond ((eq custom-buffer-style
'tree
)
2590 (insert prefix
(if is-last
" `--- " " |--- "))
2591 (push (widget-create-child-and-convert
2592 widget
'custom-browse-face-tag
)
2594 (insert " " tag
"\n")
2595 (widget-put widget
:buttons buttons
))
2599 (if (eq custom-buffer-style
'face
)
2601 (widget-specify-sample widget begin
(point))
2604 (push (widget-create-child-and-convert widget
'item
2611 (push (widget-create-child-and-convert
2613 :help-echo
"Hide or show this face."
2614 :action
'custom-toggle-parent
2615 (not (eq state
'hidden
)))
2619 (let ((magic (widget-create-child-and-convert
2620 widget
'custom-magic nil
)))
2621 (widget-put widget
:custom-magic magic
)
2622 (push magic buttons
))
2624 (widget-put widget
:buttons buttons
)
2625 ;; Insert documentation.
2626 (widget-default-format-handler widget ?h
)
2627 ;; The comment field
2628 (unless (eq state
'hidden
)
2629 (let* ((comment (get symbol
'face-comment
))
2631 (widget-create-child-and-convert
2632 widget
'custom-comment
2634 :value
(or comment
""))))
2635 (widget-put widget
:comment-widget comment-widget
)
2636 (push comment-widget children
)))
2638 (unless (eq state
'hidden
)
2639 (when (eq (widget-get widget
:custom-level
) 1)
2640 (custom-add-parent-links widget
))
2641 (custom-add-see-also widget
))
2643 (unless (eq (preceding-char) ?
\n)
2645 (unless (eq state
'hidden
)
2646 (message "Creating face editor...")
2647 (custom-load-widget widget
)
2648 (unless (widget-get widget
:custom-form
)
2649 (widget-put widget
:custom-form custom-face-default-form
))
2650 (let* ((symbol (widget-value widget
))
2651 (spec (or (get symbol
'saved-face
)
2652 (get symbol
'face-defface-spec
)
2653 ;; Attempt to construct it.
2654 (list (list t
(custom-face-attributes-get
2655 symbol
(selected-frame))))))
2656 (form (widget-get widget
:custom-form
))
2657 (indent (widget-get widget
:indent
))
2659 ;; If the user has changed this face in some other way,
2660 ;; edit it as the user has specified it.
2661 (if (not (face-spec-match-p symbol spec
(selected-frame)))
2662 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
2663 (setq edit
(widget-create-child-and-convert
2665 (cond ((and (eq form
'selected
)
2666 (widget-apply custom-face-selected
2668 (when indent
(insert-char ?\ indent
))
2669 'custom-face-selected
)
2670 ((and (not (eq form
'lisp
))
2671 (widget-apply custom-face-all
2675 (when indent
(insert-char ?\ indent
))
2678 (custom-face-state-set widget
)
2679 (push edit children
)
2680 (widget-put widget
:children children
))
2681 (message "Creating face editor...done"))))))
2683 (defvar custom-face-menu
2684 '(("Set for Current Session" custom-face-set
)
2685 ("Save for Future Sessions" custom-face-save-command
)
2686 ("Reset to Saved" custom-face-reset-saved
2688 (or (get (widget-value widget
) 'saved-face
)
2689 (get (widget-value widget
) 'saved-face-comment
))))
2690 ("Erase Customization" custom-face-reset-standard
2692 (get (widget-value widget
) 'face-defface-spec
)))
2693 ("---" ignore ignore
)
2694 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2695 ("---" ignore ignore
)
2696 ("Show all display specs" custom-face-edit-all
2698 (not (eq (widget-get widget
:custom-form
) 'all
))))
2699 ("Just current attributes" custom-face-edit-selected
2701 (not (eq (widget-get widget
:custom-form
) 'selected
))))
2702 ("Show as Lisp expression" custom-face-edit-lisp
2704 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
2705 "Alist of actions for the `custom-face' widget.
2706 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2707 the menu entry, ACTION is the function to call on the widget when the
2708 menu is selected, and FILTER is a predicate which takes a `custom-face'
2709 widget as an argument, and returns non-nil if ACTION is valid on that
2710 widget. If FILTER is nil, ACTION is always valid.")
2712 (defun custom-face-edit-selected (widget)
2713 "Edit selected attributes of the value of WIDGET."
2714 (widget-put widget
:custom-state
'unknown
)
2715 (widget-put widget
:custom-form
'selected
)
2716 (custom-redraw widget
))
2718 (defun custom-face-edit-all (widget)
2719 "Edit all attributes of the value of WIDGET."
2720 (widget-put widget
:custom-state
'unknown
)
2721 (widget-put widget
:custom-form
'all
)
2722 (custom-redraw widget
))
2724 (defun custom-face-edit-lisp (widget)
2725 "Edit the lisp representation of the value of WIDGET."
2726 (widget-put widget
:custom-state
'unknown
)
2727 (widget-put widget
:custom-form
'lisp
)
2728 (custom-redraw widget
))
2730 (defun custom-face-state-set (widget)
2731 "Set the state of WIDGET."
2732 (let* ((symbol (widget-value widget
))
2733 (comment (get symbol
'face-comment
))
2735 (widget-put widget
:custom-state
2737 (setq tmp
(get symbol
'customized-face
))
2738 (setq temp
(get symbol
'customized-face-comment
))
2740 (if (equal temp comment
)
2744 (setq tmp
(get symbol
'saved-face
))
2745 (setq temp
(get symbol
'saved-face-comment
))
2747 (if (equal temp comment
)
2750 ((get symbol
'face-defface-spec
)
2751 (if (equal comment nil
)
2757 (defun custom-face-action (widget &optional event
)
2758 "Show the menu for `custom-face' WIDGET.
2759 Optional EVENT is the location for the menu."
2760 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2761 (custom-toggle-hide widget
)
2762 (let* ((completion-ignore-case t
)
2763 (symbol (widget-get widget
:value
))
2764 (answer (widget-choose (concat "Operation on "
2765 (custom-unlispify-tag-name symbol
))
2766 (custom-menu-filter custom-face-menu
2770 (funcall answer widget
)))))
2772 (defun custom-face-set (widget)
2773 "Make the face attributes in WIDGET take effect."
2774 (let* ((symbol (widget-value widget
))
2775 (child (car (widget-get widget
:children
)))
2776 (value (widget-value child
))
2777 (comment-widget (widget-get widget
:comment-widget
))
2778 (comment (widget-value comment-widget
)))
2779 (when (equal comment
"")
2781 ;; Make the comment invisible by hand if it's empty
2782 (custom-comment-hide comment-widget
))
2783 (put symbol
'customized-face value
)
2784 (face-spec-set symbol value
)
2785 (put symbol
'customized-face-comment comment
)
2786 (put symbol
'face-comment comment
)
2787 (custom-face-state-set widget
)
2788 (custom-redraw-magic widget
)))
2790 (defun custom-face-save-command (widget)
2791 "Save in `.emacs' the face attributes in WIDGET."
2792 (custom-face-save widget
)
2795 (defun custom-face-save (widget)
2796 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2797 (let* ((symbol (widget-value widget
))
2798 (child (car (widget-get widget
:children
)))
2799 (value (widget-value child
))
2800 (comment-widget (widget-get widget
:comment-widget
))
2801 (comment (widget-value comment-widget
)))
2802 (when (equal comment
"")
2804 ;; Make the comment invisible by hand if it's empty
2805 (custom-comment-hide comment-widget
))
2806 (face-spec-set symbol value
)
2807 (put symbol
'saved-face value
)
2808 (put symbol
'customized-face nil
)
2809 (put symbol
'face-comment comment
)
2810 (put symbol
'customized-face-comment nil
)
2811 (put symbol
'saved-face-comment comment
)
2813 (custom-face-state-set widget
)
2814 (custom-redraw-magic widget
)))
2816 (defun custom-face-reset-saved (widget)
2817 "Restore WIDGET to the face's default attributes."
2818 (let* ((symbol (widget-value widget
))
2819 (child (car (widget-get widget
:children
)))
2820 (value (get symbol
'saved-face
))
2821 (comment (get symbol
'saved-face-comment
))
2822 (comment-widget (widget-get widget
:comment-widget
)))
2823 (unless (or value comment
)
2824 (error "No saved value for this face"))
2825 (put symbol
'customized-face nil
)
2826 (put symbol
'customized-face-comment nil
)
2827 (face-spec-set symbol value
)
2828 (put symbol
'face-comment comment
)
2829 (widget-value-set child value
)
2830 ;; This call manages the comment visibility
2831 (widget-value-set comment-widget
(or comment
""))
2832 (custom-face-state-set widget
)
2833 (custom-redraw-magic widget
)))
2835 (defun custom-face-reset-standard (widget)
2836 "Restore WIDGET to the face's standard settings.
2837 This operation eliminates any saved setting for the face,
2838 restoring it to the state of a face that has never been customized."
2839 (let* ((symbol (widget-value widget
))
2840 (child (car (widget-get widget
:children
)))
2841 (value (get symbol
'face-defface-spec
))
2842 (comment-widget (widget-get widget
:comment-widget
)))
2844 (error "No standard setting for this face"))
2845 (put symbol
'customized-face nil
)
2846 (put symbol
'customized-face-comment nil
)
2847 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
2848 (put symbol
'saved-face nil
)
2849 (put symbol
'saved-face-comment nil
)
2851 (face-spec-set symbol value
)
2852 (put symbol
'face-comment nil
)
2853 (widget-value-set child value
)
2854 ;; This call manages the comment visibility
2855 (widget-value-set comment-widget
"")
2856 (custom-face-state-set widget
)
2857 (custom-redraw-magic widget
)))
2859 ;;; The `face' Widget.
2861 (define-widget 'face
'default
2862 "Select and customize a face."
2863 :convert-widget
'widget-value-convert-widget
2864 :button-prefix
'widget-push-button-prefix
2865 :button-suffix
'widget-push-button-suffix
2866 :format
"%t: %[select face%] %v"
2869 :value-create
'widget-face-value-create
2870 :value-delete
'widget-face-value-delete
2871 :value-get
'widget-value-value-get
2872 :validate
'widget-children-validate
2873 :action
'widget-face-action
2874 :match
'(lambda (widget value
) (symbolp value
)))
2876 (defun widget-face-value-create (widget)
2877 ;; Create a `custom-face' child.
2878 (let* ((symbol (widget-value widget
))
2879 (custom-buffer-style 'face
)
2880 (child (widget-create-child-and-convert
2884 (custom-magic-reset child
)
2885 (setq custom-options
(cons child custom-options
))
2886 (widget-put widget
:children
(list child
))))
2888 (defun widget-face-value-delete (widget)
2889 ;; Remove the child from the options.
2890 (let ((child (car (widget-get widget
:children
))))
2891 (setq custom-options
(delq child custom-options
))
2892 (widget-children-value-delete widget
)))
2894 (defvar face-history nil
2895 "History of entered face names.")
2897 (defun widget-face-action (widget &optional event
)
2898 "Prompt for a face."
2899 (let ((answer (completing-read "Face: "
2900 (mapcar (lambda (face)
2901 (list (symbol-name face
)))
2905 (unless (zerop (length answer
))
2906 (widget-value-set widget
(intern answer
))
2907 (widget-apply widget
:notify widget event
)
2910 ;;; The `hook' Widget.
2912 (define-widget 'hook
'list
2914 :value-to-internal
(lambda (widget value
)
2915 (if (and value
(symbolp value
))
2918 :match
(lambda (widget value
)
2920 (widget-group-match widget value
)))
2921 :convert-widget
'custom-hook-convert-widget
2924 (defun custom-hook-convert-widget (widget)
2925 ;; Handle `:options'.
2926 (let* ((options (widget-get widget
:options
))
2927 (other `(editable-list :inline t
2928 :entry-format
"%i %d%v"
2929 (function :format
" %v")))
2931 (list `(checklist :inline t
2932 ,@(mapcar (lambda (entry)
2933 `(function-item ,entry
))
2937 (widget-put widget
:args args
)
2940 ;;; The `custom-group-link' Widget.
2942 (define-widget 'custom-group-link
'link
2943 "Show parent in other window when activated."
2944 :help-echo
"Create customization buffer for this group."
2945 :action
'custom-group-link-action
)
2947 (defun custom-group-link-action (widget &rest ignore
)
2948 (customize-group (widget-value widget
)))
2950 ;;; The `custom-group' Widget.
2952 (defcustom custom-group-tag-faces nil
2953 ;; In XEmacs, this ought to play games with font size.
2954 ;; Fixme: make it do so in Emacs.
2955 "Face used for group tags.
2956 The first member is used for level 1 groups, the second for level 2,
2957 and so forth. The remaining group tags are shown with
2958 `custom-group-tag-face'."
2959 :type
'(repeat face
)
2960 :group
'custom-faces
)
2962 (defface custom-group-tag-face-1
'((((class color
)
2964 (:foreground
"pink" :underline t
))
2967 (:foreground
"red" :underline t
))
2969 "Face used for group tags.")
2971 (defface custom-group-tag-face
'((((class color
)
2973 (:foreground
"light blue" :underline t
))
2976 (:foreground
"blue" :underline t
))
2978 "Face used for low level group tags."
2979 :group
'custom-faces
)
2981 (define-widget 'custom-group
'custom
2984 :sample-face-get
'custom-group-sample-face-get
2985 :documentation-property
'group-documentation
2986 :help-echo
"Set or reset all members of this group."
2987 :value-create
'custom-group-value-create
2988 :action
'custom-group-action
2989 :custom-category
'group
2990 :custom-set
'custom-group-set
2991 :custom-save
'custom-group-save
2992 :custom-reset-current
'custom-group-reset-current
2993 :custom-reset-saved
'custom-group-reset-saved
2994 :custom-reset-standard
'custom-group-reset-standard
2995 :custom-menu
'custom-group-menu-create
)
2997 (defun custom-group-sample-face-get (widget)
2998 ;; Use :sample-face.
2999 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3000 'custom-group-tag-face
))
3002 (define-widget 'custom-group-visibility
'visibility
3003 "An indicator and manipulator for hidden group contents."
3004 :create
'custom-group-visibility-create
)
3006 (defun custom-group-visibility-create (widget)
3007 (let ((visible (widget-value widget
)))
3009 (insert "--------")))
3010 (widget-default-create widget
))
3012 (defun custom-group-members (symbol groups-only
)
3013 "Return SYMBOL's custom group members.
3014 If GROUPS-ONLY non-nil, return only those members that are groups."
3015 (if (not groups-only
)
3016 (get symbol
'custom-group
)
3018 (dolist (entry (get symbol
'custom-group
))
3019 (when (eq (nth 1 entry
) 'custom-group
)
3020 (push entry members
)))
3021 (nreverse members
))))
3023 (defun custom-group-value-create (widget)
3024 "Insert a customize group for WIDGET in the current buffer."
3025 (let* ((state (widget-get widget
:custom-state
))
3026 (level (widget-get widget
:custom-level
))
3027 ;; (indent (widget-get widget :indent))
3028 (prefix (widget-get widget
:custom-prefix
))
3029 (buttons (widget-get widget
:buttons
))
3030 (tag (widget-get widget
:tag
))
3031 (symbol (widget-value widget
))
3032 (members (custom-group-members symbol
3033 (and (eq custom-buffer-style
'tree
)
3034 custom-browse-only-groups
))))
3035 (cond ((and (eq custom-buffer-style
'tree
)
3037 (or members
(custom-unloaded-widget-p widget
)))
3038 (custom-browse-insert-prefix prefix
)
3039 (push (widget-create-child-and-convert
3040 widget
'custom-browse-visibility
3041 ;; :tag-glyph "plus"
3045 ;; (widget-glyph-insert nil "-- " "horizontal")
3046 (push (widget-create-child-and-convert
3047 widget
'custom-browse-group-tag
)
3049 (insert " " tag
"\n")
3050 (widget-put widget
:buttons buttons
))
3051 ((and (eq custom-buffer-style
'tree
)
3052 (zerop (length members
)))
3053 (custom-browse-insert-prefix prefix
)
3055 ;; (widget-glyph-insert nil "[ ]" "empty")
3056 ;; (widget-glyph-insert nil "-- " "horizontal")
3057 (push (widget-create-child-and-convert
3058 widget
'custom-browse-group-tag
)
3060 (insert " " tag
"\n")
3061 (widget-put widget
:buttons buttons
))
3062 ((eq custom-buffer-style
'tree
)
3063 (custom-browse-insert-prefix prefix
)
3064 (custom-load-widget widget
)
3065 (if (zerop (length members
))
3067 (custom-browse-insert-prefix prefix
)
3069 ;; (widget-glyph-insert nil "[ ]" "empty")
3070 ;; (widget-glyph-insert nil "-- " "horizontal")
3071 (push (widget-create-child-and-convert
3072 widget
'custom-browse-group-tag
)
3074 (insert " " tag
"\n")
3075 (widget-put widget
:buttons buttons
))
3076 (push (widget-create-child-and-convert
3077 widget
'custom-browse-visibility
3078 ;; :tag-glyph "minus"
3082 ;; (widget-glyph-insert nil "-\\ " "top")
3083 (push (widget-create-child-and-convert
3084 widget
'custom-browse-group-tag
)
3086 (insert " " tag
"\n")
3087 (widget-put widget
:buttons buttons
)
3088 (message "Creating group...")
3089 (let* ((members (custom-sort-items members
3090 custom-browse-sort-alphabetically
3091 custom-browse-order-groups
))
3092 (prefixes (widget-get widget
:custom-prefixes
))
3093 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3094 (extra-prefix (if (widget-get widget
:custom-last
)
3097 (prefix (concat prefix extra-prefix
))
3100 (setq entry
(car members
)
3101 members
(cdr members
))
3102 (push (widget-create-child-and-convert
3103 widget
(nth 1 entry
)
3105 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3106 :custom-prefixes custom-prefix-list
3107 :custom-level
(1+ level
)
3108 :custom-last
(null members
)
3109 :value
(nth 0 entry
)
3110 :custom-prefix prefix
)
3112 (widget-put widget
:children
(reverse children
)))
3113 (message "Creating group...done")))
3116 ;; Create level indicator.
3117 (unless (eq custom-buffer-style
'links
)
3118 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3121 (let ((begin (point)))
3123 (widget-specify-sample widget begin
(point)))
3125 ;; Create link/visibility indicator.
3126 (if (eq custom-buffer-style
'links
)
3127 (push (widget-create-child-and-convert
3128 widget
'custom-group-link
3132 (push (widget-create-child-and-convert
3133 widget
'custom-group-visibility
3134 :help-echo
"Show members of this group."
3135 :action
'custom-toggle-parent
3136 (not (eq state
'hidden
)))
3139 ;; Create magic button.
3140 (let ((magic (widget-create-child-and-convert
3141 widget
'custom-magic nil
)))
3142 (widget-put widget
:custom-magic magic
)
3143 (push magic buttons
))
3145 (widget-put widget
:buttons buttons
)
3146 ;; Insert documentation.
3147 (if (and (eq custom-buffer-style
'links
) (> level
1))
3148 (widget-put widget
:documentation-indent
0))
3149 (widget-default-format-handler widget ?h
))
3152 ;; Add parent groups references above the group.
3153 (if t
;;; This should test that the buffer
3154 ;;; was made to display a group.
3156 (if (custom-add-parent-links widget
3157 "Go to parent group:")
3159 ;; Create level indicator.
3160 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3163 (let ((start (point)))
3165 (widget-specify-sample widget start
(point)))
3167 ;; Create visibility indicator.
3168 (unless (eq custom-buffer-style
'links
)
3170 (push (widget-create-child-and-convert
3172 :help-echo
"Hide members of this group."
3173 :action
'custom-toggle-parent
3174 (not (eq state
'hidden
)))
3177 ;; Create more dashes.
3178 ;; Use 76 instead of 75 to compensate for the temporary "<"
3179 ;; added by `widget-insert'.
3180 (insert-char ?-
(- 76 (current-column)
3181 (* custom-buffer-indent level
)))
3183 ;; Create magic button.
3184 (let ((magic (widget-create-child-and-convert
3185 widget
'custom-magic
3188 (widget-put widget
:custom-magic magic
)
3189 (push magic buttons
))
3191 (widget-put widget
:buttons buttons
)
3192 ;; Insert documentation.
3193 (widget-default-format-handler widget ?h
)
3195 (if nil
;;; This should test that the buffer
3196 ;;; was not made to display a group.
3198 (insert-char ?\ custom-buffer-indent
)
3199 (custom-add-parent-links widget
)))
3200 (custom-add-see-also widget
3201 (make-string (* custom-buffer-indent level
)
3204 (message "Creating group...")
3205 (custom-load-widget widget
)
3206 (let* ((members (custom-sort-items members
3207 custom-buffer-sort-alphabetically
3208 custom-buffer-order-groups
))
3209 (prefixes (widget-get widget
:custom-prefixes
))
3210 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3211 (length (length members
))
3213 (children (mapcar (lambda (entry)
3214 (widget-insert "\n")
3216 Creating group members... %2d%%"
3217 (/ (* 100.0 count
) length
))
3218 (setq count
(1+ count
))
3220 (widget-create-child-and-convert
3221 widget
(nth 1 entry
)
3223 :tag
(custom-unlispify-tag-name
3225 :custom-prefixes custom-prefix-list
3226 :custom-level
(1+ level
)
3227 :value
(nth 0 entry
))
3228 (unless (eq (preceding-char) ?
\n)
3229 (widget-insert "\n"))))
3231 (message "Creating group magic...")
3232 (mapcar 'custom-magic-reset children
)
3233 (message "Creating group state...")
3234 (widget-put widget
:children children
)
3235 (custom-group-state-update widget
)
3236 (message "Creating group... done"))
3239 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3240 (insert "\\- " (widget-get widget
:tag
) " group end ")
3241 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3244 (defvar custom-group-menu
3245 '(("Set for Current Session" custom-group-set
3247 (eq (widget-get widget
:custom-state
) 'modified
)))
3248 ("Save for Future Sessions" custom-group-save
3250 (memq (widget-get widget
:custom-state
) '(modified set
))))
3251 ("Reset to Current" custom-group-reset-current
3253 (memq (widget-get widget
:custom-state
) '(modified))))
3254 ("Reset to Saved" custom-group-reset-saved
3256 (memq (widget-get widget
:custom-state
) '(modified set
))))
3257 ("Reset to standard setting" custom-group-reset-standard
3259 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
3260 "Alist of actions for the `custom-group' widget.
3261 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3262 the menu entry, ACTION is the function to call on the widget when the
3263 menu is selected, and FILTER is a predicate which takes a `custom-group'
3264 widget as an argument, and returns non-nil if ACTION is valid on that
3265 widget. If FILTER is nil, ACTION is always valid.")
3267 (defun custom-group-action (widget &optional event
)
3268 "Show the menu for `custom-group' WIDGET.
3269 Optional EVENT is the location for the menu."
3270 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3271 (custom-toggle-hide widget
)
3272 (let* ((completion-ignore-case t
)
3273 (answer (widget-choose (concat "Operation on "
3274 (custom-unlispify-tag-name
3275 (widget-get widget
:value
)))
3276 (custom-menu-filter custom-group-menu
3280 (funcall answer widget
)))))
3282 (defun custom-group-set (widget)
3283 "Set changes in all modified group members."
3284 (let ((children (widget-get widget
:children
)))
3285 (mapcar (lambda (child)
3286 (when (eq (widget-get child
:custom-state
) 'modified
)
3287 (widget-apply child
:custom-set
)))
3290 (defun custom-group-save (widget)
3291 "Save all modified group members."
3292 (let ((children (widget-get widget
:children
)))
3293 (mapcar (lambda (child)
3294 (when (memq (widget-get child
:custom-state
) '(modified set
))
3295 (widget-apply child
:custom-save
)))
3298 (defun custom-group-reset-current (widget)
3299 "Reset all modified group members."
3300 (let ((children (widget-get widget
:children
)))
3301 (mapcar (lambda (child)
3302 (when (eq (widget-get child
:custom-state
) 'modified
)
3303 (widget-apply child
:custom-reset-current
)))
3306 (defun custom-group-reset-saved (widget)
3307 "Reset all modified or set group members."
3308 (let ((children (widget-get widget
:children
)))
3309 (mapcar (lambda (child)
3310 (when (memq (widget-get child
:custom-state
) '(modified set
))
3311 (widget-apply child
:custom-reset-saved
)))
3314 (defun custom-group-reset-standard (widget)
3315 "Reset all modified, set, or saved group members."
3316 (let ((children (widget-get widget
:children
)))
3317 (mapcar (lambda (child)
3318 (when (memq (widget-get child
:custom-state
)
3319 '(modified set saved
))
3320 (widget-apply child
:custom-reset-standard
)))
3323 (defun custom-group-state-update (widget)
3325 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3326 (let* ((children (widget-get widget
:children
))
3327 (states (mapcar (lambda (child)
3328 (widget-get child
:custom-state
))
3330 (magics custom-magic-alist
)
3333 (let ((magic (car (car magics
))))
3334 (if (and (not (eq magic
'hidden
))
3335 (memq magic states
))
3338 (setq magics
(cdr magics
)))))
3339 (widget-put widget
:custom-state found
)))
3340 (custom-magic-reset widget
))
3342 ;;; The `custom-save-all' Function.
3344 (defcustom custom-file nil
3345 "File used for storing customization information.
3346 The default is nil, which means to use your init file
3347 as specified by `user-init-file'. If you specify some other file,
3348 you need to explicitly load that file for the settings to take effect.
3350 When you change this variable, look in the previous custom file
3351 \(usually your init file) for the forms `(custom-set-variables ...)'
3352 and `(custom-set-faces ...)', and copy them (whichever ones you find)
3353 to the new custom file. This will preserve your existing customizations."
3354 :type
'(choice (const :tag
"Your Emacs init file" nil
) file
)
3357 (defun custom-file ()
3358 "Return the file name for saving customizations."
3362 (read-file-name "File for customizations: "
3363 "~/" nil nil
".emacs"))))
3365 (defun custom-save-delete (symbol)
3366 "Visit `custom-file' and delete all calls to SYMBOL from it.
3367 Leave point at the old location of the first such call,
3368 or (if there were none) at the end of the buffer."
3369 (let ((default-major-mode))
3370 (set-buffer (find-file-noselect (custom-file))))
3371 (goto-char (point-min))
3372 ;; Skip all whitespace and comments.
3373 (while (forward-comment 1))
3375 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3378 (while t
;; We exit this loop only via throw.
3379 ;; Skip all whitespace and comments.
3380 (while (forward-comment 1))
3381 (let ((start (point))
3382 (sexp (condition-case nil
3383 (read (current-buffer))
3384 (end-of-file (throw 'found nil
)))))
3385 (when (and (listp sexp
)
3386 (eq (car sexp
) symbol
))
3387 (delete-region start
(point))
3389 (setq first
(point)))))))
3392 (goto-char (point-max)))))
3394 (defun custom-save-variables ()
3395 "Save all customized variables in `custom-file'."
3397 (custom-save-delete 'custom-set-variables
)
3398 (let ((standard-output (current-buffer))
3399 (saved-list (make-list 1 0))
3401 ;; First create a sorted list of saved variables.
3404 (if (get symbol
'saved-value
)
3405 (nconc saved-list
(list symbol
)))))
3406 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3409 (princ "(custom-set-variables
3410 ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
3411 ;; Your init file must only contain one such instance.\n")
3414 (let ((value (get symbol
'saved-value
))
3415 (requests (get symbol
'custom-requests
))
3416 (now (not (or (get symbol
'standard-value
)
3417 (and (not (boundp symbol
))
3418 (not (get symbol
'force-value
))))))
3419 (comment (get symbol
'saved-variable-comment
))
3421 (when (or value comment
)
3428 (cond ((or now requests comment
)
3433 (cond ((or requests comment
)
3452 (unless (looking-at "\n")
3455 (defun custom-save-faces ()
3456 "Save all customized faces in `custom-file'."
3458 (custom-save-delete 'custom-set-faces
)
3459 (let ((standard-output (current-buffer))
3460 (saved-list (make-list 1 0))
3462 ;; First create a sorted list of saved faces.
3465 (if (get symbol
'saved-face
)
3466 (nconc saved-list
(list symbol
)))))
3467 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3468 ;; The default face must be first, since it affects the others.
3469 (if (memq 'default saved-list
)
3470 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
3473 (princ "(custom-set-faces
3474 ;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
3475 ;; Your init file must only contain one such instance.\n")
3478 (let ((value (get symbol
'saved-face
))
3479 (now (not (or (get 'default
'face-defface-spec
)
3480 (and (not (custom-facep 'default
))
3481 (not (get 'default
'force-face
))))))
3482 (comment (get 'default
'saved-face-comment
)))
3483 (unless (eq symbol
'default
))
3484 ;; Don't print default face here.
3491 (cond ((or now comment
)
3508 (unless (looking-at "\n")
3512 (defun customize-save-customized ()
3513 "Save all user options which have been set in this session."
3515 (mapatoms (lambda (symbol)
3516 (let ((face (get symbol
'customized-face
))
3517 (value (get symbol
'customized-value
))
3518 (face-comment (get symbol
'customized-face-comment
))
3520 (get symbol
'customized-variable-comment
)))
3522 (put symbol
'saved-face face
)
3523 (put symbol
'customized-face nil
))
3525 (put symbol
'saved-value value
)
3526 (put symbol
'customized-value nil
))
3527 (when variable-comment
3528 (put symbol
'saved-variable-comment variable-comment
)
3529 (put symbol
'customized-variable-comment nil
))
3531 (put symbol
'saved-face-comment face-comment
)
3532 (put symbol
'customized-face-comment nil
)))))
3533 ;; We really should update all custom buffers here.
3537 (defun custom-save-all ()
3538 "Save all customizations in `custom-file'."
3539 (let ((inhibit-read-only t
))
3540 (custom-save-variables)
3543 (let ((default-major-mode nil
))
3544 (set-buffer (find-file-noselect (custom-file))))
3547 ;;; The Customize Menu.
3551 (defcustom custom-menu-nesting
2
3552 "Maximum nesting in custom menus."
3554 :group
'custom-menu
)
3556 (defun custom-face-menu-create (widget symbol
)
3557 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3558 (vector (custom-unlispify-menu-entry symbol
)
3559 `(customize-face ',symbol
)
3562 (defun custom-variable-menu-create (widget symbol
)
3563 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3564 (let ((type (get symbol
'custom-type
)))
3565 (unless (listp type
)
3566 (setq type
(list type
)))
3567 (if (and type
(widget-get type
:custom-menu
))
3568 (widget-apply type
:custom-menu symbol
)
3569 (vector (custom-unlispify-menu-entry symbol
)
3570 `(customize-variable ',symbol
)
3573 ;; Add checkboxes to boolean variable entries.
3574 (widget-put (get 'boolean
'widget-type
)
3575 :custom-menu
(lambda (widget symbol
)
3576 (vector (custom-unlispify-menu-entry symbol
)
3577 `(customize-variable ',symbol
)
3579 ':selected symbol
)))
3581 ;; Fixme: sort out use of :filter in Emacs 21.
3582 (if nil
; (string-match "XEmacs" emacs-version)
3583 ;; XEmacs can create menus dynamically.
3584 (defun custom-group-menu-create (widget symbol
)
3585 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3586 `( ,(custom-unlispify-menu-entry symbol t
)
3587 :filter
(lambda (&rest junk
)
3588 (cdr (custom-menu-create ',symbol
)))))
3590 (defun custom-group-menu-create (widget symbol
)
3591 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3592 ;; Limit the nesting.
3593 (let ((custom-menu-nesting (1- custom-menu-nesting
)))
3594 (custom-menu-create symbol
))))
3597 (defun custom-menu-create (symbol)
3598 "Create menu for customization group SYMBOL.
3599 The menu is in a format applicable to `easy-menu-define'."
3600 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
3601 `(customize-group ',symbol
)
3603 (if (and (or (not (boundp 'custom-menu-nesting
))
3604 (>= custom-menu-nesting
0))
3605 (< (length (get symbol
'custom-group
)) widget-menu-max-size
))
3606 (let ((custom-prefix-list (custom-prefix-add symbol
3607 custom-prefix-list
))
3608 (members (custom-sort-items (get symbol
'custom-group
)
3609 custom-menu-sort-alphabetically
3610 custom-menu-order-groups
)))
3611 (custom-load-symbol symbol
)
3612 `(,(custom-unlispify-menu-entry symbol t
)
3615 ,@(mapcar (lambda (entry)
3616 (widget-apply (if (listp (nth 1 entry
))
3618 (list (nth 1 entry
)))
3619 :custom-menu
(nth 0 entry
)))
3624 (defun customize-menu-create (symbol &optional name
)
3625 "Return a customize menu for customization group SYMBOL.
3626 If optional NAME is given, use that as the name of the menu.
3627 Otherwise the menu will be named `Customize'.
3628 The format is suitable for use with `easy-menu-define'."
3630 (setq name
"Customize"))
3631 ;; Fixme: sort out use of :filter in Emacs 21.
3632 (if nil
;(string-match "XEmacs" emacs-version)
3633 ;; We can delay it under XEmacs.
3635 :filter
(lambda (&rest junk
)
3636 (cdr (custom-menu-create ',symbol
))))
3637 ;; But we must create it now under Emacs.
3638 (cons name
(cdr (custom-menu-create symbol
)))))
3640 ;;; The Custom Mode.
3642 (defvar custom-mode-map nil
3643 "Keymap for `custom-mode'.")
3645 (unless custom-mode-map
3646 (setq custom-mode-map
(make-sparse-keymap))
3647 (set-keymap-parent custom-mode-map widget-keymap
)
3648 (suppress-keymap custom-mode-map
)
3649 (define-key custom-mode-map
" " 'scroll-up
)
3650 (define-key custom-mode-map
"\177" 'scroll-down
)
3651 (define-key custom-mode-map
"q" 'Custom-buffer-done
)
3652 (define-key custom-mode-map
"u" 'Custom-goto-parent
)
3653 (define-key custom-mode-map
"n" 'widget-forward
)
3654 (define-key custom-mode-map
"p" 'widget-backward
)
3655 (define-key custom-mode-map
[mouse-1
] 'Custom-move-and-invoke
))
3657 (defun Custom-move-and-invoke (event)
3658 "Move to where you click, and if it is an active field, invoke it."
3660 (mouse-set-point event
)
3661 (if (widget-event-point event
)
3662 (let* ((pos (widget-event-point event
))
3663 (button (get-char-property pos
'button
)))
3665 (widget-button-click event
)))))
3667 (easy-menu-define Custom-mode-menu
3669 "Menu used in customization buffers."
3671 ,(customize-menu-create 'customize
)
3672 ["Set" Custom-set t
]
3673 ["Save" Custom-save t
]
3674 ["Reset to Current" Custom-reset-current t
]
3675 ["Reset to Saved" Custom-reset-saved t
]
3676 ["Reset to Standard Settings" Custom-reset-standard t
]
3677 ["Info" (Info-goto-node "(emacs)Easy Customization") t
]))
3679 (defun Custom-goto-parent ()
3680 "Go to the parent group listed at the top of this buffer.
3681 If several parents are listed, go to the first of them."
3684 (goto-char (point-min))
3685 (if (search-forward "\nGo to parent group: " nil t
)
3686 (let* ((button (get-char-property (point) 'button
))
3687 (parent (downcase (widget-get button
:tag
))))
3688 (customize-group parent
)))))
3690 (defcustom custom-mode-hook nil
3691 "Hook called when entering Custom mode."
3693 :group
'custom-buffer
)
3695 (defun custom-state-buffer-message (widget)
3696 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
3697 (message "To install your edits, invoke [State] and choose the Set operation")))
3699 (defun custom-mode ()
3700 "Major mode for editing customization buffers.
3702 The following commands are available:
3704 Move to next button or editable field. \\[widget-forward]
3705 Move to previous button or editable field. \\[widget-backward]
3706 \\<widget-field-keymap>\
3707 Complete content of editable text field. \\[widget-complete]
3708 \\<custom-mode-map>\
3709 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3710 Invoke button under point. \\[widget-button-press]
3711 Set all modifications. \\[Custom-set]
3712 Make all modifications default. \\[Custom-save]
3713 Reset all modified options. \\[Custom-reset-current]
3714 Reset all modified or set options. \\[Custom-reset-saved]
3715 Reset all options. \\[Custom-reset-standard]
3717 Entry to this mode calls the value of `custom-mode-hook'
3718 if that value is non-nil."
3719 (kill-all-local-variables)
3720 (setq major-mode
'custom-mode
3722 (use-local-map custom-mode-map
)
3723 (easy-menu-add Custom-mode-menu
)
3724 (make-local-variable 'custom-options
)
3725 (make-local-variable 'widget-documentation-face
)
3726 (setq widget-documentation-face
'custom-documentation-face
)
3727 (make-local-variable 'widget-button-face
)
3728 (setq widget-button-face
'custom-button-face
)
3729 (set (make-local-variable 'widget-button-pressed-face
)
3730 'custom-button-pressed-face
)
3731 (set (make-local-variable 'widget-mouse-face
)
3732 'custom-button-pressed-face
) ; buttons `depress' when moused
3733 ;; When possible, use relief for buttons, not bracketing. This test
3734 ;; may not be optimal.
3735 (when custom-raised-buttons
3736 (set (make-local-variable 'widget-push-button-prefix
) "")
3737 (set (make-local-variable 'widget-push-button-suffix
) "")
3738 (set (make-local-variable 'widget-link-prefix
) "")
3739 (set (make-local-variable 'widget-link-suffix
) ""))
3740 (make-local-hook 'widget-edit-functions
)
3741 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
3742 (run-hooks 'custom-mode-hook
))
3748 ;;; cus-edit.el ends here