1 ;;; cus-edit.el --- Tools for customizing 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
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This file implements the code to create and edit customize buffers.
31 ;; No commands should have names starting with `custom-' because
32 ;; that interferes with completion. Use `customize-' for commands
33 ;; that the user will run with M-x, and `Custom-' for interactive commands.
40 (defvar custom-versions-load-alist
)) ; from cus-load
50 (put 'custom-define-hook
'custom-type
'hook
)
51 (put 'custom-define-hook
'standard-value
'(nil))
52 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
54 ;;; Customization Groups.
57 "Customization of the One True Editor."
58 :link
'(custom-manual "(emacs)Top"))
60 ;; Most of these groups are stolen from `finder.el',
62 "Basic text editing facilities."
66 "Abbreviation handling, typing shortcuts, macros."
70 (defgroup matching nil
71 "Various sorts of searching and matching."
74 (defgroup emulations nil
75 "Emulations of other editors."
82 (defgroup outlines nil
83 "Support for hierarchical outlining."
86 (defgroup external nil
87 "Interfacing to external utilities."
91 "Code related to the `bib' bibliography processor."
95 (defgroup processes nil
96 "Process, subshell, compilation, and job control support."
100 (defgroup convenience nil
101 "Convenience features for faster editing."
104 (defgroup programming nil
105 "Support for programming in other languages."
108 (defgroup languages nil
109 "Specialized modes for editing programming languages."
113 "Lisp support, including Emacs Lisp."
118 "Support for the C language and related languages."
126 "Support for object-oriented programming."
129 (defgroup applications nil
130 "Applications written in Emacs."
133 (defgroup calendar nil
134 "Calendar and time management support."
135 :group
'applications
)
138 "Modes for electronic-mail handling."
139 :group
'applications
)
142 "Support for netnews reading and posting."
143 :group
'applications
)
146 "Games, jokes and amusements."
147 :group
'applications
)
149 (defgroup development nil
150 "Support for further development of Emacs."
154 "Support for Emacs documentation."
157 (defgroup extensions nil
158 "Emacs Lisp language extensions."
161 (defgroup internal nil
162 "Code for Emacs internals, build process, defaults."
166 "Maintenance aids for the Emacs development group."
170 (defgroup environment nil
171 "Fitting Emacs with its environment."
175 "Communications, networking, remote access to files."
179 (defgroup hardware nil
180 "Support for interfacing with exotic hardware."
183 (defgroup terminals nil
184 "Support for terminal types."
188 "Front-ends/assistants for, or emulators of, UNIX features."
192 "Support code for vms."
196 "Internationalization and alternate character-set support."
201 "The X Window system."
205 "Support for Emacs frames and window systems."
209 "Support editing files of data."
213 "Support editing files."
221 "Code related to the TeX formatter."
225 "Support for multiple fonts."
228 (defgroup hypermedia nil
229 "Support for links between text or other media types."
233 "Support for on-line help systems."
236 (defgroup multimedia nil
237 "Non-textual support, specifically images and sound."
241 "Code local to your site."
244 (defgroup customize
'((widgets custom-group
))
245 "Customization of the Customization support."
246 :link
'(custom-manual "(elisp)Customization")
247 :link
'(url-link :tag
"(Old?) Development Page"
248 "http://www.dina.kvl.dk/~abraham/custom/")
252 (defgroup custom-faces nil
253 "Faces used by customize."
257 (defgroup custom-browse nil
258 "Control customize browser."
262 (defgroup custom-buffer nil
263 "Control customize buffers."
267 (defgroup custom-menu nil
268 "Control customize menus."
272 (defgroup abbrev-mode nil
273 "Word abbreviations mode."
277 "Storage allocation and gc for GNU Emacs Lisp interpreter."
278 :tag
"Storage Allocation"
282 "Undoing changes in buffers."
285 (defgroup modeline nil
286 "Content of the modeline."
290 "Indenting and filling text."
293 (defgroup editing-basics nil
294 "Most basic editing facilities."
297 (defgroup display nil
298 "How characters are displayed in buffers."
301 (defgroup execute nil
302 "Executing external commands."
305 (defgroup installation nil
306 "The Emacs installation."
314 "Internal Emacs limits."
318 "Debugging Emacs itself."
321 (defgroup minibuffer nil
322 "Controling the behaviour of the minibuffer."
325 (defgroup keyboard nil
326 "Input from the keyboard."
330 "Input from the mouse."
334 "Input from the menus."
337 (defgroup auto-save nil
338 "Preventing accidential loss of data."
341 (defgroup processes-basics nil
342 "Basic stuff dealing with processes."
346 "MULE Emacs internationalization."
349 (defgroup windows nil
350 "Windows within a frame."
355 (defun custom-quote (sexp)
356 "Quote SEXP iff it is not self quoting."
357 (if (or (memq sexp
'(t nil
))
360 (memq (car sexp
) '(lambda)))
364 ;;; (and (fboundp 'characterp)
365 ;;; (characterp sexp))
370 (defun custom-split-regexp-maybe (regexp)
371 "If REGEXP is a string, split it to a list at `\\|'.
372 You can get the original back with from the result with:
373 (mapconcat 'identity result \"\\|\")
375 IF REGEXP is not a string, return it unchanged."
379 (while (string-match "\\\\|" regexp start
)
380 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
381 start
(match-end 0)))
382 (nreverse (cons (substring regexp start
) all
)))
385 (defun custom-variable-prompt ()
386 "Prompt for a variable, defaulting to the variable at point.
387 Return a list suitable for use in `interactive'."
388 (let ((v (variable-at-point))
389 (enable-recursive-minibuffers t
)
391 (setq val
(completing-read
393 (format "Customize option: (default %s) " v
)
394 "Customize variable: ")
395 obarray
(lambda (symbol)
397 (or (get symbol
'custom-type
)
398 (get symbol
'custom-loads
)
399 (get symbol
'standard-value
)))) t
))
400 (list (if (equal val
"")
401 (if (symbolp v
) v nil
)
404 (defun custom-menu-filter (menu widget
)
405 "Convert MENU to the form used by `widget-choose'.
406 MENU should be in the same format as `custom-variable-menu'.
407 WIDGET is the widget to apply the filter entries of MENU on."
409 current name action filter
)
411 (setq current
(car menu
)
413 action
(nth 1 current
)
414 filter
(nth 2 current
)
416 (if (or (null filter
) (funcall filter widget
))
417 (push (cons name action
) result
)
423 (defvar custom-prefix-list nil
424 "List of prefixes that should be ignored by `custom-unlispify'.")
426 (defcustom custom-unlispify-menu-entries t
427 "Display menu entries as words instead of symbols if non nil."
431 (defcustom custom-unlispify-remove-prefixes nil
432 "Non-nil means remove group prefixes from option names in buffer."
436 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
437 "Convert SYMBOL into a menu entry."
438 (cond ((not custom-unlispify-menu-entries
)
439 (symbol-name symbol
))
440 ((get symbol
'custom-tag
)
442 (get symbol
'custom-tag
)
443 (concat (get symbol
'custom-tag
) "...")))
446 (set-buffer (get-buffer-create " *Custom-Work*"))
448 (princ symbol
(current-buffer))
449 (goto-char (point-min))
450 (when (and (eq (get symbol
'custom-type
) 'boolean
)
451 (re-search-forward "-p\\'" nil t
))
452 (replace-match "" t t
)
453 (goto-char (point-min)))
454 (if custom-unlispify-remove-prefixes
455 (let ((prefixes custom-prefix-list
)
458 (setq prefix
(car prefixes
))
459 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
462 (delete-region (point-min) (point)))
463 (setq prefixes
(cdr prefixes
))))))
464 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
465 (capitalize-region (point-min) (point-max))
467 (goto-char (point-max))
471 (defcustom custom-unlispify-tag-names t
472 "Display tag names as words instead of symbols if non nil."
473 :group
'custom-buffer
476 (defun custom-unlispify-tag-name (symbol)
477 "Convert SYMBOL into a menu entry."
478 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
479 (custom-unlispify-menu-entry symbol t
)))
481 (defun custom-prefix-add (symbol prefixes
)
482 "Add SYMBOL to list of ignored PREFIXES."
483 (cons (or (get symbol
'custom-prefix
)
484 (concat (symbol-name symbol
) "-"))
489 (defcustom custom-guess-name-alist
494 ("-function\\'" function
)
495 ("-functions\\'" (repeat function
))
496 ("-list\\'" (repeat sexp
))
497 ("-alist\\'" (repeat (cons sexp sexp
))))
498 "Alist of (MATCH TYPE).
500 MATCH should be a regexp matching the name of a symbol, and TYPE should
501 be a widget suitable for editing the value of that symbol. The TYPE
502 of the first entry where MATCH matches the name of the symbol will be
505 This is used for guessing the type of variables not declared with
507 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
510 (defcustom custom-guess-doc-alist
511 '(("\\`\\*?Non-nil " boolean
))
512 "Alist of (MATCH TYPE).
514 MATCH should be a regexp matching a documentation string, and TYPE
515 should be a widget suitable for editing the value of a variable with
516 that documentation string. The TYPE of the first entry where MATCH
517 matches the name of the symbol will be used.
519 This is used for guessing the type of variables not declared with
521 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
524 (defun custom-guess-type (symbol)
525 "Guess a widget suitable for editing the value of SYMBOL.
526 This is done by matching SYMBOL with `custom-guess-name-alist' and
527 if that fails, the doc string with `custom-guess-doc-alist'."
528 (let ((name (symbol-name symbol
))
529 (names custom-guess-name-alist
)
532 (setq current
(car names
)
534 (when (string-match (nth 0 current
) name
)
535 (setq found
(nth 1 current
)
538 (let ((doc (documentation-property symbol
'variable-documentation
))
539 (docs custom-guess-doc-alist
))
542 (setq current
(car docs
)
544 (when (string-match (nth 0 current
) doc
)
545 (setq found
(nth 1 current
)
551 (defcustom custom-browse-sort-alphabetically nil
552 "If non-nil, sort members of each customization group alphabetically."
554 :group
'custom-browse
)
556 (defcustom custom-browse-order-groups nil
557 "If non-nil, order group members within each customization group.
558 If `first', order groups before non-groups.
559 If `last', order groups after non-groups."
560 :type
'(choice (const first
)
562 (const :tag
"none" nil
))
563 :group
'custom-browse
)
565 (defcustom custom-browse-only-groups nil
566 "If non-nil, show group members only within each customization group."
568 :group
'custom-browse
)
570 (defcustom custom-buffer-sort-alphabetically nil
571 "If non-nil, sort members of each customization group alphabetically."
573 :group
'custom-buffer
)
575 (defcustom custom-buffer-order-groups
'last
576 "If non-nil, order group members within each customization group.
577 If `first', order groups before non-groups.
578 If `last', order groups after non-groups."
579 :type
'(choice (const first
)
581 (const :tag
"none" nil
))
582 :group
'custom-buffer
)
584 (defcustom custom-menu-sort-alphabetically nil
585 "If non-nil, sort members of each customization group alphabetically."
589 (defcustom custom-menu-order-groups
'first
590 "If non-nil, order group members within each customization group.
591 If `first', order groups before non-groups.
592 If `last', order groups after non-groups."
593 :type
'(choice (const first
)
595 (const :tag
"none" nil
))
598 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
600 (defun custom-sort-items (items sort-alphabetically order-groups
)
601 "Return a sorted copy of ITEMS.
602 ITEMS should be a `custom-group' property.
603 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
604 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
605 groups after non-groups, if nil do not order groups at all."
606 (sort (copy-sequence items
)
608 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
609 (namea (nth 0 a
)) (nameb (nth 0 b
)))
610 (cond ((not order-groups
)
611 ;; Since we don't care about A and B order, maybe sort.
612 (when sort-alphabetically
613 (string-lessp namea nameb
)))
614 ((eq typea
'custom-group
)
615 ;; If B is also a group, maybe sort. Otherwise, order A and B.
616 (if (eq typeb
'custom-group
)
617 (when sort-alphabetically
618 (string-lessp namea nameb
))
619 (eq order-groups
'first
)))
620 ((eq typeb
'custom-group
)
621 ;; Since A cannot be a group, order A and B.
622 (eq order-groups
'last
))
624 ;; Since A and B cannot be groups, sort.
625 (string-lessp namea nameb
)))))))
627 ;;; Custom Mode Commands.
629 (defvar custom-options nil
630 "Customization widgets in the current buffer.")
633 "Set changes in all modified options."
635 (let ((children custom-options
))
636 (mapc (lambda (child)
637 (when (eq (widget-get child
:custom-state
) 'modified
)
638 (widget-apply child
:custom-set
)))
641 (defun Custom-save ()
642 "Set all modified group members and save them."
644 (let ((children custom-options
))
645 (mapc (lambda (child)
646 (when (memq (widget-get child
:custom-state
)
647 '(modified set changed rogue
))
648 (widget-apply child
:custom-save
)))
652 (defvar custom-reset-menu
653 '(("Current" . Custom-reset-current
)
654 ("Saved" . Custom-reset-saved
)
655 ("Erase Customization (use standard settings)" . Custom-reset-standard
))
656 "Alist of actions for the `Reset' button.
657 The key is a string containing the name of the action, the value is a
658 Lisp function taking the widget as an element which will be called
659 when the action is chosen.")
661 (defun custom-reset (event)
662 "Select item from reset menu."
663 (let* ((completion-ignore-case t
)
664 (answer (widget-choose "Reset to"
670 (defun Custom-reset-current (&rest ignore
)
671 "Reset all modified group members to their current value."
673 (let ((children custom-options
))
674 (mapc (lambda (widget)
675 (and (default-boundp (widget-value widget
))
676 (if (memq (widget-get widget
:custom-state
)
678 (widget-apply widget
:custom-reset-current
))))
681 (defun Custom-reset-saved (&rest ignore
)
682 "Reset all modified or set group members to their saved value."
684 (let ((children custom-options
))
685 (mapc (lambda (widget)
686 (and (get (widget-value widget
) 'saved-value
)
687 (if (memq (widget-get widget
:custom-state
)
688 '(modified set changed rogue
))
689 (widget-apply widget
:custom-reset-saved
))))
692 (defun Custom-reset-standard (&rest ignore
)
693 "Erase all customization (either current or saved) for the group members.
694 The immediate result is to restore them to their standard settings.
695 This operation eliminates any saved settings for the group members,
696 making them as if they had never been customized at all."
698 (let ((children custom-options
))
699 (mapc (lambda (widget)
700 (and (get (widget-value widget
) 'standard-value
)
701 (if (memq (widget-get widget
:custom-state
)
702 '(modified set changed saved rogue
))
703 (widget-apply widget
:custom-reset-standard
))))
706 ;;; The Customize Commands
708 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
709 "Prompt for a variable and a value and return them as a list.
710 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
711 prompt for the value. The %s escape in PROMPT-VAL is replaced with
712 the name of the variable.
714 If the variable has a `variable-interactive' property, that is used as if
715 it were the arg to `interactive' (which see) to interactively read the value.
717 If the variable has a `custom-type' property, it must be a widget and the
718 `:prompt-value' property of that widget will be used for reading the value.
720 If optional COMMENT argument is non nil, also prompt for a comment and return
721 it as the third element in the list."
722 (let* ((var (read-variable prompt-var
))
723 (minibuffer-help-form '(describe-variable var
))
725 (let ((prop (get var
'variable-interactive
))
726 (type (get var
'custom-type
))
727 (prompt (format prompt-val var
)))
729 (setq type
(list type
)))
731 ;; Use VAR's `variable-interactive' property
732 ;; as an interactive spec for prompting.
733 (call-interactively (list 'lambda
'(arg)
734 (list 'interactive prop
)
737 (widget-prompt-value type
743 (eval-minibuffer prompt
))))))
746 (read-string "Comment: " (get var
'variable-comment
)))
750 (defun customize-set-value (var val
&optional comment
)
751 "Set VARIABLE to VALUE. VALUE is a Lisp object.
753 If VARIABLE has a `variable-interactive' property, that is used as if
754 it were the arg to `interactive' (which see) to interactively read the value.
756 If VARIABLE has a `custom-type' property, it must be a widget and the
757 `:prompt-value' property of that widget will be used for reading the value.
759 If given a prefix (or a COMMENT argument), also prompt for a comment."
760 (interactive (custom-prompt-variable "Set variable: "
765 (cond ((string= comment
"")
766 (put var
'variable-comment nil
))
768 (put var
'variable-comment comment
))))
771 (defun customize-set-variable (variable value
&optional comment
)
772 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
774 If VARIABLE has a `custom-set' property, that is used for setting
775 VARIABLE, otherwise `set-default' is used.
777 The `customized-value' property of the VARIABLE will be set to a list
778 with a quoted VALUE as its sole list member.
780 If VARIABLE has a `variable-interactive' property, that is used as if
781 it were the arg to `interactive' (which see) to interactively read the value.
783 If VARIABLE has a `custom-type' property, it must be a widget and the
784 `:prompt-value' property of that widget will be used for reading the value.
786 If given a prefix (or a COMMENT argument), also prompt for a comment."
787 (interactive (custom-prompt-variable "Set variable: "
788 "Set customized value for %s to: "
790 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
791 (put variable
'customized-value
(list (custom-quote value
)))
792 (cond ((string= comment
"")
793 (put variable
'variable-comment nil
)
794 (put variable
'customized-variable-comment nil
))
796 (put variable
'variable-comment comment
)
797 (put variable
'customized-variable-comment comment
))))
800 (defun customize-save-variable (var value
&optional comment
)
801 "Set the default for VARIABLE to VALUE, and save it for future sessions.
802 If VARIABLE has a `custom-set' property, that is used for setting
803 VARIABLE, otherwise `set-default' is used.
805 The `customized-value' property of the VARIABLE will be set to a list
806 with a quoted VALUE as its sole list member.
808 If VARIABLE has a `variable-interactive' property, that is used as if
809 it were the arg to `interactive' (which see) to interactively read the value.
811 If VARIABLE has a `custom-type' property, it must be a widget and the
812 `:prompt-value' property of that widget will be used for reading the value.
814 If given a prefix (or a COMMENT argument), also prompt for a comment."
815 (interactive (custom-prompt-variable "Set and ave variable: "
816 "Set and save value for %s as: "
818 (funcall (or (get var
'custom-set
) 'set-default
) var value
)
819 (put var
'saved-value
(list (custom-quote value
)))
820 (cond ((string= comment
"")
821 (put var
'variable-comment nil
)
822 (put var
'saved-variable-comment nil
))
824 (put var
'variable-comment comment
)
825 (put var
'saved-variable-comment comment
)))
830 "Select a customization buffer which you can use to set user options.
831 User options are structured into \"groups\".
832 Initially the top-level group `Emacs' and its immediate subgroups
833 are shown; the contents of those subgroups are initially hidden."
835 (customize-group 'emacs
))
838 (defun customize-group (group)
839 "Customize GROUP, which must be a customization group."
840 (interactive (list (let ((completion-ignore-case t
))
841 (completing-read "Customize group: (default emacs) "
844 (or (get symbol
'custom-loads
)
845 (get symbol
'custom-group
)))
847 (when (stringp group
)
848 (if (string-equal "" group
)
850 (setq group
(intern group
))))
851 (or (get group
'custom-group
)
852 (custom-load-symbol group
))
853 (let ((name (format "*Customize Group: %s*"
854 (custom-unlispify-tag-name group
))))
855 (if (get-buffer name
)
857 (custom-buffer-create (list (list group
'custom-group
))
859 (concat " for group "
860 (custom-unlispify-tag-name group
))))))
863 (defun customize-group-other-window (group)
864 "Customize GROUP, which must be a customization group."
865 (interactive (list (let ((completion-ignore-case t
))
866 (completing-read "Customize group: (default emacs) "
869 (or (get symbol
'custom-loads
)
870 (get symbol
'custom-group
)))
872 (when (stringp group
)
873 (if (string-equal "" group
)
875 (setq group
(intern group
))))
876 (or (get group
'custom-group
)
877 (custom-load-symbol group
))
878 (let ((name (format "*Customize Group: %s*"
879 (custom-unlispify-tag-name group
))))
880 (if (get-buffer name
)
881 (let ((window (selected-window)))
883 (select-window window
))
884 (custom-buffer-create-other-window
885 (list (list group
'custom-group
))
887 (concat " for group "
888 (custom-unlispify-tag-name group
))))))
891 (defalias 'customize-variable
'customize-option
)
894 (defun customize-option (symbol)
895 "Customize SYMBOL, which must be a user option variable."
896 (interactive (custom-variable-prompt))
897 ;; If we don't have SYMBOL's real definition loaded,
899 (unless (get symbol
'custom-type
)
900 (let ((loaddefs-file (locate-library "loaddefs.el" t
))
902 ;; See if it is autoloaded from some library.
905 (insert-file-contents loaddefs-file
)
906 (when (re-search-forward (concat "^(defvar " (symbol-name symbol
))
908 (search-backward "\n;;; Generated autoloads from ")
909 (goto-char (match-end 0))
910 (setq file
(buffer-substring (point)
911 (progn (end-of-line) (point)))))))
912 ;; If it is, load that library.
914 (when (string-match "\\.el\\'" file
)
915 (setq file
(substring file
0 (match-beginning 0))))
917 (unless (get symbol
'custom-type
)
918 (error "Variable %s cannot be customized" symbol
))
919 (custom-buffer-create (list (list symbol
'custom-variable
))
920 (format "*Customize Option: %s*"
921 (custom-unlispify-tag-name symbol
))))
923 (defvar customize-changed-options-previous-release
"20.2"
924 "Version for `customize-changed-options' to refer back to by default.")
927 (defun customize-changed-options (since-version)
928 "Customize all user option variables changed in Emacs itself.
929 This includes new user option variables and faces, and new
930 customization groups, as well as older options and faces whose default
931 values have changed since the previous major Emacs release.
933 With argument SINCE-VERSION (a string), customize all user option
934 variables that were added (or their meanings were changed) since that
937 (interactive "sCustomize options changed, since version (default all versions): ")
938 (if (equal since-version
"")
939 (setq since-version nil
)
940 (unless (condition-case nil
941 (numberp (read since-version
))
943 (signal 'wrong-type-argument
(list 'numberp since-version
))))
944 (unless since-version
945 (setq since-version customize-changed-options-previous-release
))
948 (mapatoms (lambda (symbol)
949 (and (or (boundp symbol
)
950 ;; For variables not yet loaded.
951 (get symbol
'standard-value
)
952 ;; For groups the previous test fails, this one
953 ;; could be used to determine if symbol is a
954 ;; group. Is there a better way for this?
955 (get symbol
'group-documentation
))
956 (let ((version (get symbol
'custom-version
)))
958 (or (null since-version
)
959 (customize-version-lessp since-version version
))
960 (if (member version versions
)
962 ;;; Collect all versions that we use.
963 (push version versions
))))
965 ;; We have to set the right thing here,
966 ;; depending if we have a group or a
968 (if (get symbol
'group-documentation
)
969 (cons (list symbol
'custom-group
) found
)
970 (cons (list symbol
'custom-variable
) found
))))))
972 (error "No user option defaults have been changed since Emacs %s"
977 (cdr (assoc (car versions
) custom-versions-load-alist
)))
979 (setq versions
(cdr versions
)))
980 (put 'custom-versions-load-alist
'custom-loads
981 ;; Get all the files that correspond to element from the
982 ;; VERSIONS list. This could use some simplification.
983 (apply 'nconc flist
)))
984 ;; Because we set all the files needed to be loaded as a
985 ;; `custom-loads' property to `custom-versions-load-alist' this
986 ;; call will actually load them.
987 (custom-load-symbol 'custom-versions-load-alist
)
989 (put 'custom-versions-load-alist
'custom-loads nil
)
990 (custom-buffer-create (custom-sort-items found t
'first
)
991 "*Customize Changed Options*"))))
993 (defun customize-version-lessp (version1 version2
)
994 ;; Why are the versions strings, and given that they are, why aren't
995 ;; they converted to numbers and compared as such here? -- fx
997 ;; In case someone made a mistake and left out the quotes
998 ;; in the :version value.
999 (if (numberp version2
)
1000 (setq version2
(prin1-to-string version2
)))
1001 (let (major1 major2 minor1 minor2
)
1002 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1003 (setq major1
(read (or (match-string 1 version1
)
1005 (setq minor1
(read (or (match-string 3 version1
)
1007 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1008 (setq major2
(read (or (match-string 1 version2
)
1010 (setq minor2
(read (or (match-string 3 version2
)
1012 (or (< major1 major2
)
1013 (and (= major1 major2
)
1014 (< minor1 minor2
)))))
1017 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1020 (defun customize-option-other-window (symbol)
1021 "Customize SYMBOL, which must be a user option variable.
1022 Show the buffer in another window, but don't select it."
1023 (interactive (custom-variable-prompt))
1024 (custom-buffer-create-other-window
1025 (list (list symbol
'custom-variable
))
1026 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol
))))
1029 (defun customize-face (&optional symbol
)
1030 "Customize SYMBOL, which should be a face name or nil.
1031 If SYMBOL is nil, customize all faces."
1032 (interactive (list (completing-read "Customize face: (default all) "
1033 obarray
'custom-facep t
)))
1034 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
1035 (custom-buffer-create (custom-sort-items
1036 (mapcar (lambda (symbol)
1037 (list symbol
'custom-face
))
1040 "*Customize Faces*")
1041 (when (stringp symbol
)
1042 (setq symbol
(intern symbol
)))
1043 (unless (symbolp symbol
)
1044 (error "Should be a symbol %S" symbol
))
1045 (custom-buffer-create (list (list symbol
'custom-face
))
1046 (format "*Customize Face: %s*"
1047 (custom-unlispify-tag-name symbol
)))))
1050 (defun customize-face-other-window (&optional symbol
)
1051 "Show customization buffer for face SYMBOL in other window."
1052 (interactive (list (completing-read "Customize face: "
1053 obarray
'custom-facep t
)))
1054 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
1056 (if (stringp symbol
)
1057 (setq symbol
(intern symbol
)))
1058 (unless (symbolp symbol
)
1059 (error "Should be a symbol %S" symbol
))
1060 (custom-buffer-create-other-window
1061 (list (list symbol
'custom-face
))
1062 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol
)))))
1065 (defun customize-customized ()
1066 "Customize all user options set since the last save in this session."
1069 (mapatoms (lambda (symbol)
1070 (and (or (get symbol
'customized-face
)
1071 (get symbol
'customized-face-comment
))
1072 (custom-facep symbol
)
1073 (push (list symbol
'custom-face
) found
))
1074 (and (or (get symbol
'customized-value
)
1075 (get symbol
'customized-variable-comment
))
1077 (push (list symbol
'custom-variable
) found
))))
1079 (error "No customized user options")
1080 (custom-buffer-create (custom-sort-items found t nil
)
1081 "*Customize Customized*"))))
1084 (defun customize-saved ()
1085 "Customize all already saved user options."
1088 (mapatoms (lambda (symbol)
1089 (and (or (get symbol
'saved-face
)
1090 (get symbol
'saved-face-comment
))
1091 (custom-facep symbol
)
1092 (push (list symbol
'custom-face
) found
))
1093 (and (or (get symbol
'saved-value
)
1094 (get symbol
'saved-variable-comment
))
1096 (push (list symbol
'custom-variable
) found
))))
1098 (error "No saved user options")
1099 (custom-buffer-create (custom-sort-items found t nil
)
1100 "*Customize Saved*"))))
1103 (defun customize-apropos (regexp &optional all
)
1104 "Customize all user options matching REGEXP.
1105 If ALL is `options', include only options.
1106 If ALL is `faces', include only faces.
1107 If ALL is `groups', include only groups.
1108 If ALL is t (interactively, with prefix arg), include options which are not
1109 user-settable, as well as faces and groups."
1110 (interactive "sCustomize regexp: \nP")
1112 (mapatoms (lambda (symbol)
1113 (when (string-match regexp
(symbol-name symbol
))
1114 (when (and (not (memq all
'(faces options
)))
1115 (get symbol
'custom-group
))
1116 (push (list symbol
'custom-group
) found
))
1117 (when (and (not (memq all
'(options groups
)))
1118 (custom-facep symbol
))
1119 (push (list symbol
'custom-face
) found
))
1120 (when (and (not (memq all
'(groups faces
)))
1122 (or (get symbol
'saved-value
)
1123 (get symbol
'standard-value
)
1124 (if (memq all
'(nil options
))
1125 (user-variable-p symbol
)
1126 (get symbol
'variable-documentation
))))
1127 (push (list symbol
'custom-variable
) found
)))))
1129 (error "No matches")
1130 (custom-buffer-create (custom-sort-items found t
1131 custom-buffer-order-groups
)
1132 "*Customize Apropos*"))))
1135 (defun customize-apropos-options (regexp &optional arg
)
1136 "Customize all user options matching REGEXP.
1137 With prefix arg, include options which are not user-settable."
1138 (interactive "sCustomize regexp: \nP")
1139 (customize-apropos regexp
(or arg
'options
)))
1142 (defun customize-apropos-faces (regexp)
1143 "Customize all user faces matching REGEXP."
1144 (interactive "sCustomize regexp: \n")
1145 (customize-apropos regexp
'faces
))
1148 (defun customize-apropos-groups (regexp)
1149 "Customize all user groups matching REGEXP."
1150 (interactive "sCustomize regexp: \n")
1151 (customize-apropos regexp
'groups
))
1155 (defcustom custom-buffer-style
'links
1156 "Control the presentation style for customization buffers.
1157 The value should be a symbol, one of:
1159 brackets: groups nest within each other with big horizontal brackets.
1160 links: groups have links to subgroups."
1161 :type
'(radio (const brackets
)
1163 :group
'custom-buffer
)
1165 ;; If we pass BUFFER to `bury-buffer', the buffer isn't removed from
1167 (defun custom-bury-buffer (buffer)
1170 (defcustom custom-buffer-done-function
'custom-bury-buffer
1171 "*Function called to remove a Custom buffer when the user is done with it.
1172 Called with one argument, the buffer to remove."
1173 :type
'(choice (function-item :tag
"Bury buffer" custom-bury-buffer
)
1174 (function-item :tag
"Kill buffer" kill-buffer
)
1175 (function :tag
"Other"))
1177 :group
'custom-buffer
)
1179 (defcustom custom-buffer-indent
3
1180 "Number of spaces to indent nested groups."
1182 :group
'custom-buffer
)
1185 (defun custom-buffer-create (options &optional name description
)
1186 "Create a buffer containing OPTIONS.
1187 Optional NAME is the name of the buffer.
1188 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1189 SYMBOL is a customization option, and WIDGET is a widget for editing
1191 (unless name
(setq name
"*Customization*"))
1192 (kill-buffer (get-buffer-create name
))
1193 (pop-to-buffer (get-buffer-create name
))
1194 (custom-buffer-create-internal options description
))
1197 (defun custom-buffer-create-other-window (options &optional name description
)
1198 "Create a buffer containing OPTIONS.
1199 Optional NAME is the name of the buffer.
1200 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1201 SYMBOL is a customization option, and WIDGET is a widget for editing
1203 (unless name
(setq name
"*Customization*"))
1204 (kill-buffer (get-buffer-create name
))
1205 (let ((window (selected-window))
1207 (special-display-buffer-names nil
)
1208 (special-display-regexps nil
)
1209 (same-window-buffer-names nil
)
1210 (same-window-regexps nil
))
1211 (pop-to-buffer (get-buffer-create name
))
1212 (custom-buffer-create-internal options description
)
1213 (select-window window
)))
1215 (defcustom custom-reset-button-menu nil
1216 "If non-nil, only show a single reset button in customize buffers.
1217 This button will have a menu with all three reset operations."
1219 :group
'custom-buffer
)
1221 (defun Custom-buffer-done (&rest ignore
)
1222 "Remove current buffer by calling `custom-buffer-done-function'."
1224 (funcall custom-buffer-done-function
(current-buffer)))
1226 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1227 '(("unspecified" . unspecified
))))
1228 "If non-nil, indicate active buttons in a `raised-button' style.
1229 Otherwise use brackets."
1232 :group
'custom-buffer
)
1234 (defun custom-buffer-create-internal (options &optional description
)
1235 (message "Creating customization buffer...")
1237 (widget-insert "This is a customization buffer")
1239 (widget-insert description
))
1240 (widget-insert (format ".
1241 %s show active fields; type RET or click mouse-1
1242 on an active field to invoke its action. Editing an option value
1243 changes the text in the buffer; invoke the State button and
1244 choose the Set operation to set the option value.
1245 Invoke " (if custom-raised-buttons
1247 "Square brackets")))
1248 (widget-create 'info-link
1250 :help-echo
"Read the online help."
1251 "(emacs)Easy Customization")
1252 (widget-insert " for more information.\n\n")
1253 (message "Creating customization buttons...")
1254 (widget-insert "Operate on everything in this buffer:\n ")
1255 (widget-create 'push-button
1256 :tag
"Set for Current Session"
1258 Make your editing in this buffer take effect for this session."
1259 :action
(lambda (widget &optional event
)
1262 (widget-create 'push-button
1263 :tag
"Save for Future Sessions"
1265 Make your editing in this buffer take effect for future Emacs sessions."
1266 :action
(lambda (widget &optional event
)
1268 (if custom-reset-button-menu
1271 (widget-create 'push-button
1273 :help-echo
"Show a menu with reset operations."
1274 :mouse-down-action
(lambda (&rest junk
) t
)
1275 :action
(lambda (widget &optional event
)
1276 (custom-reset event
))))
1277 (widget-insert "\n ")
1278 (widget-create 'push-button
1281 Reset all edited text in this buffer to reflect current values."
1282 :action
'Custom-reset-current
)
1284 (widget-create 'push-button
1285 :tag
"Reset to Saved"
1287 Reset all values in this buffer to their saved settings."
1288 :action
'Custom-reset-saved
)
1290 (widget-create 'push-button
1291 :tag
"Erase Customization"
1293 Un-customize all values in this buffer. They get their standard settings."
1294 :action
'Custom-reset-standard
))
1296 (widget-create 'push-button
1299 (lambda (&rest ignore
)
1301 ((eq custom-buffer-done-function
1302 'custom-bury-buffer
)
1304 ((eq custom-buffer-done-function
'kill-buffer
)
1306 (t "Finish with this buffer")))
1307 :action
#'Custom-buffer-done
)
1308 (widget-insert "\n\n")
1309 (message "Creating customization items...")
1310 (buffer-disable-undo)
1311 (setq custom-options
1312 (if (= (length options
) 1)
1313 (mapcar (lambda (entry)
1314 (widget-create (nth 1 entry
)
1315 :documentation-shown t
1316 :custom-state
'unknown
1317 :tag
(custom-unlispify-tag-name
1319 :value
(nth 0 entry
)))
1322 (length (length options
)))
1323 (mapcar (lambda (entry)
1325 (message "Creating customization items ...%2d%%"
1326 (/ (* 100.0 count
) length
))
1327 (widget-create (nth 1 entry
)
1328 :tag
(custom-unlispify-tag-name
1330 :value
(nth 0 entry
))
1331 (setq count
(1+ count
))
1332 (unless (eq (preceding-char) ?
\n)
1333 (widget-insert "\n"))
1334 (widget-insert "\n")))
1336 (unless (eq (preceding-char) ?
\n)
1337 (widget-insert "\n"))
1338 (message "Creating customization items ...%2d%%done" 100)
1339 (unless (eq custom-buffer-style
'tree
)
1340 (mapc 'custom-magic-reset custom-options
))
1341 (message "Creating customization setup...")
1343 (buffer-enable-undo)
1344 (goto-char (point-min))
1345 (message "Creating customization buffer...done"))
1347 ;;; The Tree Browser.
1350 (defun customize-browse (&optional group
)
1351 "Create a tree browser for the customize hierarchy."
1354 (setq group
'emacs
))
1355 (let ((name "*Customize Browser*"))
1356 (kill-buffer (get-buffer-create name
))
1357 (pop-to-buffer (get-buffer-create name
)))
1360 Square brackets show active fields; type RET or click mouse-1
1361 on an active field to invoke its action.
1362 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1363 (if custom-browse-only-groups
1365 Invoke the [Group] button below to edit that item in another window.\n\n")
1366 (widget-insert "Invoke the ")
1367 (widget-create 'item
1370 :tag-glyph
"folder")
1371 (widget-insert ", ")
1372 (widget-create 'item
1376 (widget-insert ", and ")
1377 (widget-create 'item
1380 :tag-glyph
"option")
1381 (widget-insert " buttons below to edit that
1382 item in another window.\n\n"))
1383 (let ((custom-buffer-style 'tree
))
1384 (widget-create 'custom-group
1386 :custom-state
'unknown
1387 :tag
(custom-unlispify-tag-name group
)
1389 (goto-char (point-min)))
1391 (define-widget 'custom-browse-visibility
'item
1392 "Control visibility of items in the customize tree browser."
1394 :action
'custom-browse-visibility-action
)
1396 (defun custom-browse-visibility-action (widget &rest ignore
)
1397 (let ((custom-buffer-style 'tree
))
1398 (custom-toggle-parent widget
)))
1400 (define-widget 'custom-browse-group-tag
'push-button
1401 "Show parent in other window when activated."
1404 :action
'custom-browse-group-tag-action
)
1406 (defun custom-browse-group-tag-action (widget &rest ignore
)
1407 (let ((parent (widget-get widget
:parent
)))
1408 (customize-group-other-window (widget-value parent
))))
1410 (define-widget 'custom-browse-variable-tag
'push-button
1411 "Show parent in other window when activated."
1414 :action
'custom-browse-variable-tag-action
)
1416 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1417 (let ((parent (widget-get widget
:parent
)))
1418 (customize-variable-other-window (widget-value parent
))))
1420 (define-widget 'custom-browse-face-tag
'push-button
1421 "Show parent in other window when activated."
1424 :action
'custom-browse-face-tag-action
)
1426 (defun custom-browse-face-tag-action (widget &rest ignore
)
1427 (let ((parent (widget-get widget
:parent
)))
1428 (customize-face-other-window (widget-value parent
))))
1430 (defconst custom-browse-alist
'((" " "space")
1436 (defun custom-browse-insert-prefix (prefix)
1437 "Insert PREFIX. On XEmacs convert it to line graphics."
1438 ;; Fixme: do graphics.
1439 (if nil
; (string-match "XEmacs" emacs-version)
1442 (while (not (string-equal prefix
""))
1443 (let ((entry (substring prefix
0 3)))
1444 (setq prefix
(substring prefix
3))
1445 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1446 (name (nth 1 (assoc entry custom-browse-alist
))))
1447 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1448 (overlay-put overlay
'start-open t
)
1449 (overlay-put overlay
'end-open t
)))))
1452 ;;; Modification of Basic Widgets.
1454 ;; We add extra properties to the basic widgets needed here. This is
1455 ;; fine, as long as we are careful to stay within out own namespace.
1457 ;; We want simple widgets to be displayed by default, but complex
1458 ;; widgets to be hidden.
1460 (widget-put (get 'item
'widget-type
) :custom-show t
)
1461 (widget-put (get 'editable-field
'widget-type
)
1462 :custom-show
(lambda (widget value
)
1463 (let ((pp (pp-to-string value
)))
1464 (cond ((string-match "\n" pp
)
1469 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1471 ;;; The `custom-manual' Widget.
1473 (define-widget 'custom-manual
'info-link
1474 "Link to the manual entry for this customization option."
1475 :help-echo
"Read the manual entry for this option."
1478 ;;; The `custom-magic' Widget.
1480 (defgroup custom-magic-faces nil
1481 "Faces used by the magic button."
1482 :group
'custom-faces
1483 :group
'custom-buffer
)
1485 (defface custom-invalid-face
'((((class color
))
1486 (:foreground
"yellow" :background
"red"))
1488 (:bold t
:italic t
:underline t
)))
1489 "Face used when the customize item is invalid."
1490 :group
'custom-magic-faces
)
1492 (defface custom-rogue-face
'((((class color
))
1493 (:foreground
"pink" :background
"black"))
1496 "Face used when the customize item is not defined for customization."
1497 :group
'custom-magic-faces
)
1499 (defface custom-modified-face
'((((class color
))
1500 (:foreground
"white" :background
"blue"))
1503 "Face used when the customize item has been modified."
1504 :group
'custom-magic-faces
)
1506 (defface custom-set-face
'((((class color
))
1507 (:foreground
"blue" :background
"white"))
1510 "Face used when the customize item has been set."
1511 :group
'custom-magic-faces
)
1513 (defface custom-changed-face
'((((class color
))
1514 (:foreground
"white" :background
"blue"))
1517 "Face used when the customize item has been changed."
1518 :group
'custom-magic-faces
)
1520 (defface custom-saved-face
'((t (:underline t
)))
1521 "Face used when the customize item has been saved."
1522 :group
'custom-magic-faces
)
1524 (defconst custom-magic-alist
'((nil "#" underline
"\
1525 uninitialized, you should not see this.")
1526 (unknown "?" italic
"\
1527 unknown, you should not see this.")
1528 (hidden "-" default
"\
1529 hidden, invoke \"Show\" in the previous line to show." "\
1530 group now hidden, invoke \"Show\", above, to show contents.")
1531 (invalid "x" custom-invalid-face
"\
1532 the value displayed for this %c is invalid and cannot be set.")
1533 (modified "*" custom-modified-face
"\
1534 you have edited the value as text, but you have not set the %c." "\
1535 you have edited something in this group, but not set it.")
1536 (set "+" custom-set-face
"\
1537 you have set this %c, but not saved it for future sessions." "\
1538 something in this group has been set, but not saved.")
1539 (changed ":" custom-changed-face
"\
1540 this %c has been changed outside the customize buffer." "\
1541 something in this group has been changed outside customize.")
1542 (saved "!" custom-saved-face
"\
1543 this %c has been set and saved." "\
1544 something in this group has been set and saved.")
1545 (rogue "@" custom-rogue-face
"\
1546 this %c has not been changed with customize." "\
1547 something in this group is not prepared for customization.")
1548 (standard " " nil
"\
1549 this %c is unchanged from its standard setting." "\
1550 visible group members are all at standard settings."))
1551 "Alist of customize option states.
1552 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1554 STATE is one of the following symbols:
1557 For internal use, should never occur.
1559 For internal use, should never occur.
1561 This item is not being displayed.
1563 This item is modified, but has an invalid form.
1565 This item is modified, and has a valid form.
1567 This item has been set but not saved.
1569 The current value of this item has been changed temporarily.
1571 This item is marked for saving.
1573 This item has no customization information.
1575 This item is unchanged from the standard setting.
1577 MAGIC is a string used to present that state.
1579 FACE is a face used to present the state.
1581 ITEM-DESC is a string describing the state for options.
1583 GROUP-DESC is a string describing the state for groups. If this is
1584 left out, ITEM-DESC will be used.
1586 The string %c in either description will be replaced with the
1587 category of the item. These are `group'. `option', and `face'.
1589 The list should be sorted most significant first.")
1591 (defcustom custom-magic-show
'long
1592 "If non-nil, show textual description of the state.
1593 If `long', show a full-line description, not just one word."
1594 :type
'(choice (const :tag
"no" nil
)
1596 (other :tag
"short" short
))
1597 :group
'custom-buffer
)
1599 (defcustom custom-magic-show-hidden
'(option face
)
1600 "Control whether the State button is shown for hidden items.
1601 The value should be a list with the custom categories where the State
1602 button should be visible. Possible categories are `group', `option',
1604 :type
'(set (const group
) (const option
) (const face
))
1605 :group
'custom-buffer
)
1607 (defcustom custom-magic-show-button nil
1608 "Show a \"magic\" button indicating the state of each customization option."
1610 :group
'custom-buffer
)
1612 (define-widget 'custom-magic
'default
1613 "Show and manipulate state for a customization option."
1615 :action
'widget-parent-action
1618 :value-create
'custom-magic-value-create
1619 :value-delete
'widget-children-value-delete
)
1621 (defun widget-magic-mouse-down-action (widget &optional event
)
1622 ;; Non-nil unless hidden.
1623 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1627 (defun custom-magic-value-create (widget)
1628 "Create compact status report for WIDGET."
1629 (let* ((parent (widget-get widget
:parent
))
1630 (state (widget-get parent
:custom-state
))
1631 (hidden (eq state
'hidden
))
1632 (entry (assq state custom-magic-alist
))
1633 (magic (nth 1 entry
))
1634 (face (nth 2 entry
))
1635 (category (widget-get parent
:custom-category
))
1636 (text (or (and (eq category
'group
)
1639 (form (widget-get parent
:custom-form
))
1641 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1642 (setq text
(concat (match-string 1 text
)
1643 (symbol-name category
)
1644 (match-string 2 text
))))
1645 (when (and custom-magic-show
1647 (memq category custom-magic-show-hidden
)))
1649 (when (and (eq category
'group
)
1650 (not (and (eq custom-buffer-style
'links
)
1651 (> (widget-get parent
:custom-level
) 1))))
1652 (insert-char ?\
(* custom-buffer-indent
1653 (widget-get parent
:custom-level
))))
1654 (push (widget-create-child-and-convert
1656 :help-echo
"Change the state of this item."
1657 :format
(if hidden
"%t" "%[%t%]")
1658 :button-prefix
'widget-push-button-prefix
1659 :button-suffix
'widget-push-button-suffix
1660 :mouse-down-action
'widget-magic-mouse-down-action
1664 (let ((start (point)))
1665 (if (eq custom-magic-show
'long
)
1667 (insert (symbol-name state
)))
1668 (cond ((eq form
'lisp
)
1670 ((eq form
'mismatch
)
1671 (insert " (mismatch)")))
1672 (put-text-property start
(point) 'face
'custom-state-face
))
1674 (when (and (eq category
'group
)
1675 (not (and (eq custom-buffer-style
'links
)
1676 (> (widget-get parent
:custom-level
) 1))))
1677 (insert-char ?\
(* custom-buffer-indent
1678 (widget-get parent
:custom-level
))))
1679 (when custom-magic-show-button
1680 (when custom-magic-show
1681 (let ((indent (widget-get parent
:indent
)))
1683 (insert-char ? indent
))))
1684 (push (widget-create-child-and-convert
1686 :mouse-down-action
'widget-magic-mouse-down-action
1690 :help-echo
"Change the state."
1691 :format
(if hidden
"%t" "%[%t%]")
1692 :tag
(if (memq form
'(lisp mismatch
))
1693 (concat "(" magic
")")
1694 (concat "[" magic
"]")))
1697 (widget-put widget
:children children
)))
1699 (defun custom-magic-reset (widget)
1700 "Redraw the :custom-magic property of WIDGET."
1701 (let ((magic (widget-get widget
:custom-magic
)))
1702 (widget-value-set magic
(widget-value magic
))))
1704 ;;; The `custom' Widget.
1706 (defface custom-button-face
1707 '((((type x w32 mac
) (class color
)) ; Like default modeline
1708 (:box
(:line-width
2 :style released-button
)
1709 :background
"lightgrey" :foreground
"black"))
1712 "Face used for buttons in customization buffers."
1714 :group
'custom-faces
)
1716 (defface custom-button-pressed-face
1717 '((((type x w32 mac
) (class color
))
1718 (:box
(:line-width
2 :style pressed-button
)
1719 :background
"lightgrey" :foreground
"black"))
1721 (:inverse-video t
)))
1722 "Face used for buttons in customization buffers."
1724 :group
'custom-faces
)
1726 (defface custom-documentation-face nil
1727 "Face used for documentation strings in customization buffers."
1728 :group
'custom-faces
)
1730 (defface custom-state-face
'((((class color
)
1732 (:foreground
"lime green"))
1735 (:foreground
"dark green"))
1737 "Face used for State descriptions in the customize buffer."
1738 :group
'custom-faces
)
1740 (define-widget 'custom
'default
1741 "Customize a user option."
1743 :convert-widget
'custom-convert-widget
1744 :notify
'custom-notify
1747 :custom-state
'hidden
1748 :documentation-property
'widget-subclass-responsibility
1749 :value-create
'widget-subclass-responsibility
1750 :value-delete
'widget-children-value-delete
1751 :value-get
'widget-value-value-get
1752 :validate
'widget-children-validate
1753 :match
(lambda (widget value
) (symbolp value
)))
1755 (defun custom-convert-widget (widget)
1756 "Initialize :value and :tag from :args in WIDGET."
1757 (let ((args (widget-get widget
:args
)))
1759 (widget-put widget
:value
(widget-apply widget
1760 :value-to-internal
(car args
)))
1761 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1762 (widget-put widget
:args nil
)))
1765 (defun custom-notify (widget &rest args
)
1766 "Keep track of changes."
1767 (let ((state (widget-get widget
:custom-state
)))
1768 (unless (eq state
'modified
)
1769 (unless (memq state
'(nil unknown hidden
))
1770 (widget-put widget
:custom-state
'modified
))
1771 (custom-magic-reset widget
)
1772 (apply 'widget-default-notify widget args
))))
1774 (defun custom-redraw (widget)
1775 "Redraw WIDGET with current settings."
1776 (let ((line (count-lines (point-min) (point)))
1777 (column (current-column))
1779 (from (marker-position (widget-get widget
:from
)))
1780 (to (marker-position (widget-get widget
:to
))))
1782 (widget-value-set widget
(widget-value widget
))
1783 (custom-redraw-magic widget
))
1784 (when (and (>= pos from
) (<= pos to
))
1789 (goto-line (1+ line
)))
1790 (move-to-column column
))
1793 (defun custom-redraw-magic (widget)
1794 "Redraw WIDGET state with current settings."
1796 (let ((magic (widget-get widget
:custom-magic
)))
1798 (widget-value-set magic
(widget-value magic
))
1799 (when (setq widget
(widget-get widget
:group
))
1800 (custom-group-state-update widget
)))
1802 (setq widget nil
)))))
1805 (defun custom-show (widget value
)
1806 "Non-nil if WIDGET should be shown with VALUE by default."
1807 (let ((show (widget-get widget
:custom-show
)))
1813 (funcall show widget value
)))))
1815 (defvar custom-load-recursion nil
1816 "Hack to avoid recursive dependencies.")
1818 (defun custom-load-symbol (symbol)
1819 "Load all dependencies for SYMBOL."
1820 (unless custom-load-recursion
1821 (let ((custom-load-recursion t
)
1822 (loads (get symbol
'custom-loads
))
1825 (setq load
(car loads
)
1827 (cond ((symbolp load
)
1831 ;; Don't reload a file already loaded.
1832 ((and (boundp 'preloaded-file-list
)
1833 (member load preloaded-file-list
)))
1834 ((assoc load load-history
))
1835 ((assoc (locate-library load
) load-history
))
1838 ;; Without this, we would load cus-edit recursively.
1839 ;; We are still loading it when we call this,
1840 ;; and it is not in load-history yet.
1841 (or (equal load
"cus-edit")
1842 (load-library load
))
1845 (defun custom-load-widget (widget)
1846 "Load all dependencies for WIDGET."
1847 (custom-load-symbol (widget-value widget
)))
1849 (defun custom-unloaded-symbol-p (symbol)
1850 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1852 (loads (get symbol
'custom-loads
))
1855 (setq load
(car loads
)
1857 (cond ((symbolp load
)
1858 (unless (featurep load
)
1860 ((assoc load load-history
))
1861 ((assoc (locate-library load
) load-history
)
1867 (defun custom-unloaded-widget-p (widget)
1868 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1869 (custom-unloaded-symbol-p (widget-value widget
)))
1871 (defun custom-toggle-hide (widget)
1872 "Toggle visibility of WIDGET."
1873 (custom-load-widget widget
)
1874 (let ((state (widget-get widget
:custom-state
)))
1875 (cond ((memq state
'(invalid modified
))
1876 (error "There are unset changes"))
1878 (widget-put widget
:custom-state
'unknown
))
1880 (widget-put widget
:documentation-shown nil
)
1881 (widget-put widget
:custom-state
'hidden
)))
1882 (custom-redraw widget
)
1885 (defun custom-toggle-parent (widget &rest ignore
)
1886 "Toggle visibility of parent of WIDGET."
1887 (custom-toggle-hide (widget-get widget
:parent
)))
1889 (defun custom-add-see-also (widget &optional prefix
)
1890 "Add `See also ...' to WIDGET if there are any links.
1891 Insert PREFIX first if non-nil."
1892 (let* ((symbol (widget-get widget
:value
))
1893 (links (get symbol
'custom-links
))
1894 (many (> (length links
) 2))
1895 (buttons (widget-get widget
:buttons
))
1896 (indent (widget-get widget
:indent
)))
1899 (insert-char ?\ indent
))
1902 (insert "See also ")
1904 (push (widget-create-child-and-convert widget
(car links
))
1906 (setq links
(cdr links
))
1915 (widget-put widget
:buttons buttons
))))
1917 (defun custom-add-parent-links (widget &optional initial-string
)
1918 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1919 The value if non-nil if any parents were found.
1920 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1921 (let ((name (widget-value widget
))
1922 (type (widget-type widget
))
1923 (buttons (widget-get widget
:buttons
))
1926 (insert (or initial-string
"Parent groups:"))
1927 (mapatoms (lambda (symbol)
1928 (let ((entry (assq name
(get symbol
'custom-group
))))
1929 (when (eq (nth 1 entry
) type
)
1931 (push (widget-create-child-and-convert
1932 widget
'custom-group-link
1933 :tag
(custom-unlispify-tag-name symbol
)
1937 (widget-put widget
:buttons buttons
)
1940 (delete-region start
(point)))
1943 ;;; The `custom-comment' Widget.
1945 ;; like the editable field
1946 (defface custom-comment-face
'((((class grayscale color
)
1948 (:background
"gray85"))
1949 (((class grayscale color
)
1951 (:background
"dim gray"))
1954 "Face used for comments on variables or faces"
1956 :group
'custom-faces
)
1958 ;; like font-lock-comment-face
1959 (defface custom-comment-tag-face
1960 '((((class color
) (background dark
)) (:foreground
"gray80"))
1961 (((class color
) (background light
)) (:foreground
"blue4"))
1962 (((class grayscale
) (background light
))
1963 (:foreground
"DimGray" :bold t
:italic t
))
1964 (((class grayscale
) (background dark
))
1965 (:foreground
"LightGray" :bold t
:italic t
))
1967 "Face used for variables or faces comment tags"
1968 :group
'custom-faces
)
1970 (define-widget 'custom-comment
'string
1973 :help-echo
"Edit a comment here."
1974 :sample-face
'custom-comment-tag-face
1975 :value-face
'custom-comment-face
1977 :create
'custom-comment-create
)
1979 (defun custom-comment-create (widget)
1980 (let* ((null-comment (equal "" (widget-value widget
))))
1981 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
1983 (widget-default-create widget
)
1984 ;; `widget-default-delete' expects markers in these slots --
1985 ;; maybe it shouldn't.
1986 (widget-put widget
:from
(point-marker))
1987 (widget-put widget
:to
(point-marker)))))
1989 (defun custom-comment-hide (widget)
1990 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
1992 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
1993 ;; the global custom one
1994 (defun custom-comment-show (widget)
1995 (widget-put widget
:comment-shown t
)
1996 (custom-redraw widget
)
1999 (defun custom-comment-invisible-p (widget)
2000 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2002 (not (widget-get widget
:comment-shown
)))))
2004 ;;; The `custom-variable' Widget.
2006 ;; When this was underlined blue, users confused it with a
2007 ;; Mosaic-style hyperlink...
2008 (defface custom-variable-tag-face
2011 (:foreground
"light blue" :bold t
:height
1.2 :inherit variable-pitch
))
2014 (:foreground
"blue" :bold t
:height
1.2 :inherit variable-pitch
))
2016 "Face used for unpushable variable tags."
2017 :group
'custom-faces
)
2019 (defface custom-variable-button-face
'((t (:underline t
:bold t
)))
2020 "Face used for pushable variable tags."
2021 :group
'custom-faces
)
2023 (defcustom custom-variable-default-form
'edit
2024 "Default form of displaying variable values."
2025 :type
'(choice (const edit
)
2027 :group
'custom-buffer
2030 (define-widget 'custom-variable
'custom
2031 "Customize variable."
2033 :help-echo
"Set or reset this variable."
2034 :documentation-property
'variable-documentation
2035 :custom-category
'option
2037 :custom-menu
'custom-variable-menu-create
2038 :custom-form nil
; defaults to value of `custom-variable-default-form'
2039 :value-create
'custom-variable-value-create
2040 :action
'custom-variable-action
2041 :custom-set
'custom-variable-set
2042 :custom-save
'custom-variable-save
2043 :custom-reset-current
'custom-redraw
2044 :custom-reset-saved
'custom-variable-reset-saved
2045 :custom-reset-standard
'custom-variable-reset-standard
)
2047 (defun custom-variable-type (symbol)
2048 "Return a widget suitable for editing the value of SYMBOL.
2049 If SYMBOL has a `custom-type' property, use that.
2050 Otherwise, look up symbol in `custom-guess-type-alist'."
2051 (let* ((type (or (get symbol
'custom-type
)
2052 (and (not (get symbol
'standard-value
))
2053 (custom-guess-type symbol
))
2055 (options (get symbol
'custom-options
))
2056 (tmp (if (listp type
)
2057 (copy-sequence type
)
2060 (widget-put tmp
:options options
))
2063 (defun custom-variable-value-create (widget)
2064 "Here is where you edit the variable's value."
2065 (custom-load-widget widget
)
2066 (unless (widget-get widget
:custom-form
)
2067 (widget-put widget
:custom-form custom-variable-default-form
))
2068 (let* ((buttons (widget-get widget
:buttons
))
2069 (children (widget-get widget
:children
))
2070 (form (widget-get widget
:custom-form
))
2071 (state (widget-get widget
:custom-state
))
2072 (symbol (widget-get widget
:value
))
2073 (tag (widget-get widget
:tag
))
2074 (type (custom-variable-type symbol
))
2075 (conv (widget-convert type
))
2076 (get (or (get symbol
'custom-get
) 'default-value
))
2077 (prefix (widget-get widget
:custom-prefix
))
2078 (last (widget-get widget
:custom-last
))
2079 (value (if (default-boundp symbol
)
2080 (funcall get symbol
)
2081 (widget-get conv
:value
))))
2082 ;; If the widget is new, the child determines whether it is hidden.
2084 ((custom-show type value
)
2085 (setq state
'unknown
))
2087 (setq state
'hidden
)))
2088 ;; If we don't know the state, see if we need to edit it in lisp form.
2089 (when (eq state
'unknown
)
2090 (unless (widget-apply conv
:match value
)
2091 ;; (widget-apply (widget-convert type) :match value)
2092 (setq form
'mismatch
)))
2093 ;; Now we can create the child widget.
2094 (cond ((eq custom-buffer-style
'tree
)
2095 (insert prefix
(if last
" `--- " " |--- "))
2096 (push (widget-create-child-and-convert
2097 widget
'custom-browse-variable-tag
)
2099 (insert " " tag
"\n")
2100 (widget-put widget
:buttons buttons
))
2102 ;; Indicate hidden value.
2103 (push (widget-create-child-and-convert
2106 :sample-face
'custom-variable-tag-face
2110 (push (widget-create-child-and-convert
2112 :help-echo
"Show the value of this option."
2113 :action
'custom-toggle-parent
2116 ((memq form
'(lisp mismatch
))
2117 ;; In lisp mode edit the saved value when possible.
2118 (let* ((value (cond ((get symbol
'saved-value
)
2119 (car (get symbol
'saved-value
)))
2120 ((get symbol
'standard-value
)
2121 (car (get symbol
'standard-value
)))
2122 ((default-boundp symbol
)
2123 (custom-quote (funcall get symbol
)))
2125 (custom-quote (widget-get conv
:value
))))))
2126 (insert (symbol-name symbol
) ": ")
2127 (push (widget-create-child-and-convert
2129 :help-echo
"Hide the value of this option."
2130 :action
'custom-toggle-parent
2134 (push (widget-create-child-and-convert
2136 :button-face
'custom-variable-button-face
2138 :tag
(symbol-name symbol
)
2144 (let* ((format (widget-get type
:format
))
2145 tag-format value-format
)
2146 (unless (string-match ":" format
)
2147 (error "Bad format"))
2148 (setq tag-format
(substring format
0 (match-end 0)))
2149 (setq value-format
(substring format
(match-end 0)))
2150 (push (widget-create-child-and-convert
2153 :action
'custom-tag-action
2154 :help-echo
"Change value of this option."
2155 :mouse-down-action
'custom-tag-mouse-down-action
2156 :button-face
'custom-variable-button-face
2157 :sample-face
'custom-variable-tag-face
2161 (push (widget-create-child-and-convert
2163 :help-echo
"Hide the value of this option."
2164 :action
'custom-toggle-parent
2167 (push (widget-create-child-and-convert
2169 :format value-format
2172 (unless (eq custom-buffer-style
'tree
)
2173 (unless (eq (preceding-char) ?
\n)
2174 (widget-insert "\n"))
2175 ;; Create the magic button.
2176 (let ((magic (widget-create-child-and-convert
2177 widget
'custom-magic nil
)))
2178 (widget-put widget
:custom-magic magic
)
2179 (push magic buttons
))
2180 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2181 ;; before the call to `widget-default-format-handler'. Otherwise, I
2182 ;; loose my current `buttons'. This function shouldn't be called like
2183 ;; this anyway. The doc string widget should be added like the others.
2185 (widget-put widget
:buttons buttons
)
2186 ;; Insert documentation.
2187 (widget-default-format-handler widget ?h
)
2189 ;; The comment field
2190 (unless (eq state
'hidden
)
2191 (let* ((comment (get symbol
'variable-comment
))
2193 (widget-create-child-and-convert
2194 widget
'custom-comment
2196 :value
(or comment
""))))
2197 (widget-put widget
:comment-widget comment-widget
)
2198 ;; Don't push it !!! Custom assumes that the first child is the
2200 (setq children
(append children
(list comment-widget
)))))
2201 ;; Update the rest of the properties properties.
2202 (widget-put widget
:custom-form form
)
2203 (widget-put widget
:children children
)
2204 ;; Now update the state.
2205 (if (eq state
'hidden
)
2206 (widget-put widget
:custom-state state
)
2207 (custom-variable-state-set widget
))
2209 (unless (eq state
'hidden
)
2210 (when (eq (widget-get widget
:custom-level
) 1)
2211 (custom-add-parent-links widget
))
2212 (custom-add-see-also widget
)))))
2214 (defun custom-tag-action (widget &rest args
)
2215 "Pass :action to first child of WIDGET's parent."
2216 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2219 (defun custom-tag-mouse-down-action (widget &rest args
)
2220 "Pass :mouse-down-action to first child of WIDGET's parent."
2221 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2222 :mouse-down-action args
))
2224 (defun custom-variable-state-set (widget)
2225 "Set the state of WIDGET."
2226 (let* ((symbol (widget-value widget
))
2227 (get (or (get symbol
'custom-get
) 'default-value
))
2228 (value (if (default-boundp symbol
)
2229 (funcall get symbol
)
2230 (widget-get widget
:value
)))
2231 (comment (get symbol
'variable-comment
))
2234 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2236 (get symbol
'customized-variable-comment
))
2238 (if (condition-case nil
2239 (and (equal value
(eval (car tmp
)))
2240 (equal comment temp
))
2244 ((progn (setq tmp
(get symbol
'saved-value
))
2245 (setq temp
(get symbol
'saved-variable-comment
))
2247 (if (condition-case nil
2248 (and (equal value
(eval (car tmp
)))
2249 (equal comment temp
))
2253 ((setq tmp
(get symbol
'standard-value
))
2254 (if (condition-case nil
2255 (and (equal value
(eval (car tmp
)))
2256 (equal comment nil
))
2261 (widget-put widget
:custom-state state
)))
2263 (defvar custom-variable-menu
2264 '(("Set for Current Session" custom-variable-set
2266 (eq (widget-get widget
:custom-state
) 'modified
)))
2267 ("Save for Future Sessions" custom-variable-save
2269 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
2270 ("Reset to Current" custom-redraw
2272 (and (default-boundp (widget-value widget
))
2273 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2274 ("Reset to Saved" custom-variable-reset-saved
2276 (and (or (get (widget-value widget
) 'saved-value
)
2277 (get (widget-value widget
) 'saved-variable-comment
))
2278 (memq (widget-get widget
:custom-state
)
2279 '(modified set changed rogue
)))))
2280 ("Erase Customization" custom-variable-reset-standard
2282 (and (get (widget-value widget
) 'standard-value
)
2283 (memq (widget-get widget
:custom-state
)
2284 '(modified set changed saved rogue
)))))
2285 ("---" ignore ignore
)
2286 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2287 ("---" ignore ignore
)
2288 ("Don't show as Lisp expression" custom-variable-edit
2290 (eq (widget-get widget
:custom-form
) 'lisp
)))
2291 ("Show initial Lisp expression" custom-variable-edit-lisp
2293 (eq (widget-get widget
:custom-form
) 'edit
))))
2294 "Alist of actions for the `custom-variable' widget.
2295 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2296 the menu entry, ACTION is the function to call on the widget when the
2297 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2298 widget as an argument, and returns non-nil if ACTION is valid on that
2299 widget. If FILTER is nil, ACTION is always valid.")
2301 (defun custom-variable-action (widget &optional event
)
2302 "Show the menu for `custom-variable' WIDGET.
2303 Optional EVENT is the location for the menu."
2304 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2305 (custom-toggle-hide widget
)
2306 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2307 (custom-variable-state-set widget
))
2308 (custom-redraw-magic widget
)
2309 (let* ((completion-ignore-case t
)
2310 (answer (widget-choose (concat "Operation on "
2311 (custom-unlispify-tag-name
2312 (widget-get widget
:value
)))
2313 (custom-menu-filter custom-variable-menu
2317 (funcall answer widget
)))))
2319 (defun custom-variable-edit (widget)
2320 "Edit value of WIDGET."
2321 (widget-put widget
:custom-state
'unknown
)
2322 (widget-put widget
:custom-form
'edit
)
2323 (custom-redraw widget
))
2325 (defun custom-variable-edit-lisp (widget)
2326 "Edit the Lisp representation of the value of WIDGET."
2327 (widget-put widget
:custom-state
'unknown
)
2328 (widget-put widget
:custom-form
'lisp
)
2329 (custom-redraw widget
))
2331 (defun custom-variable-set (widget)
2332 "Set the current value for the variable being edited by WIDGET."
2333 (let* ((form (widget-get widget
:custom-form
))
2334 (state (widget-get widget
:custom-state
))
2335 (child (car (widget-get widget
:children
)))
2336 (symbol (widget-value widget
))
2337 (set (or (get symbol
'custom-set
) 'set-default
))
2338 (comment-widget (widget-get widget
:comment-widget
))
2339 (comment (widget-value comment-widget
))
2341 (cond ((eq state
'hidden
)
2342 (error "Cannot set hidden variable"))
2343 ((setq val
(widget-apply child
:validate
))
2344 (goto-char (widget-get val
:from
))
2345 (error "%s" (widget-get val
:error
)))
2346 ((memq form
'(lisp mismatch
))
2347 (when (equal comment
"")
2349 ;; Make the comment invisible by hand if it's empty
2350 (custom-comment-hide comment-widget
))
2351 (funcall set symbol
(eval (setq val
(widget-value child
))))
2352 (put symbol
'customized-value
(list val
))
2353 (put symbol
'variable-comment comment
)
2354 (put symbol
'customized-variable-comment comment
))
2356 (when (equal comment
"")
2358 ;; Make the comment invisible by hand if it's empty
2359 (custom-comment-hide comment-widget
))
2360 (funcall set symbol
(setq val
(widget-value child
)))
2361 (put symbol
'customized-value
(list (custom-quote val
)))
2362 (put symbol
'variable-comment comment
)
2363 (put symbol
'customized-variable-comment comment
)))
2364 (custom-variable-state-set widget
)
2365 (custom-redraw-magic widget
)))
2367 (defun custom-variable-save (widget)
2368 "Set and save the value for the variable being edited by WIDGET."
2369 (let* ((form (widget-get widget
:custom-form
))
2370 (state (widget-get widget
:custom-state
))
2371 (child (car (widget-get widget
:children
)))
2372 (symbol (widget-value widget
))
2373 (set (or (get symbol
'custom-set
) 'set-default
))
2374 (comment-widget (widget-get widget
:comment-widget
))
2375 (comment (widget-value comment-widget
))
2377 (cond ((eq state
'hidden
)
2378 (error "Cannot set hidden variable"))
2379 ((setq val
(widget-apply child
:validate
))
2380 (goto-char (widget-get val
:from
))
2381 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2382 ((memq form
'(lisp mismatch
))
2383 (when (equal comment
"")
2385 ;; Make the comment invisible by hand if it's empty
2386 (custom-comment-hide comment-widget
))
2387 (put symbol
'saved-value
(list (widget-value child
)))
2388 (funcall set symbol
(eval (widget-value child
)))
2389 (put symbol
'variable-comment comment
)
2390 (put symbol
'saved-variable-comment comment
))
2392 (when (equal comment
"")
2394 ;; Make the comment invisible by hand if it's empty
2395 (custom-comment-hide comment-widget
))
2396 (put symbol
'saved-value
2397 (list (custom-quote (widget-value child
))))
2398 (funcall set symbol
(widget-value child
))
2399 (put symbol
'variable-comment comment
)
2400 (put symbol
'saved-variable-comment comment
)))
2401 (put symbol
'customized-value nil
)
2402 (put symbol
'customized-variable-comment nil
)
2404 (custom-variable-state-set widget
)
2405 (custom-redraw-magic widget
)))
2407 (defun custom-variable-reset-saved (widget)
2408 "Restore the saved value for the variable being edited by WIDGET."
2409 (let* ((symbol (widget-value widget
))
2410 (set (or (get symbol
'custom-set
) 'set-default
))
2411 (value (get symbol
'saved-value
))
2412 (comment (get symbol
'saved-variable-comment
)))
2413 (cond ((or value comment
)
2414 (put symbol
'variable-comment comment
)
2416 (funcall set symbol
(eval (car value
)))
2419 (error "No saved value for %s" symbol
)))
2420 (put symbol
'customized-value nil
)
2421 (put symbol
'customized-variable-comment nil
)
2422 (widget-put widget
:custom-state
'unknown
)
2423 ;; This call will possibly make the comment invisible
2424 (custom-redraw widget
)))
2426 (defun custom-variable-reset-standard (widget)
2427 "Restore the standard setting for the variable being edited by WIDGET.
2428 This operation eliminates any saved setting for the variable,
2429 restoring it to the state of a variable that has never been customized."
2430 (let* ((symbol (widget-value widget
))
2431 (set (or (get symbol
'custom-set
) 'set-default
)))
2432 (if (get symbol
'standard-value
)
2433 (funcall set symbol
(eval (car (get symbol
'standard-value
))))
2434 (error "No standard setting known for %S" symbol
))
2435 (put symbol
'variable-comment nil
)
2436 (put symbol
'customized-value nil
)
2437 (put symbol
'customized-variable-comment nil
)
2438 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2439 (put symbol
'saved-value nil
)
2440 (put symbol
'saved-variable-comment nil
)
2442 (widget-put widget
:custom-state
'unknown
)
2443 ;; This call will possibly make the comment invisible
2444 (custom-redraw widget
)))
2446 ;;; The `custom-face-edit' Widget.
2448 (define-widget 'custom-face-edit
'checklist
2449 "Edit face attributes."
2453 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2454 :args
(mapcar (lambda (att)
2457 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2458 (list 'const
:format
"" :value
(nth 0 att
))
2460 custom-face-attributes
))
2462 ;;; The `custom-display' Widget.
2464 (define-widget 'custom-display
'menu-choice
2465 "Select a display type."
2468 :help-echo
"Specify frames where the face attributes should be used."
2469 :args
'((const :tag
"all" t
)
2473 :args
((group :sibling-args
(:help-echo
"\
2474 Only match the specified window systems.")
2475 (const :format
"Type: "
2477 (checklist :inline t
2480 :sibling-args
(:help-echo
"\
2481 The X11 Window System.")
2483 (const :format
"PM "
2484 :sibling-args
(:help-echo
"\
2485 OS/2 Presentation Manager.")
2487 (const :format
"W32 "
2488 :sibling-args
(:help-echo
"\
2491 (const :format
"DOS "
2492 :sibling-args
(:help-echo
"\
2495 (const :format
"TTY%n"
2496 :sibling-args
(:help-echo
"\
2497 Plain text terminals.")
2499 (group :sibling-args
(:help-echo
"\
2500 Only match the frames with the specified color support.")
2501 (const :format
"Class: "
2503 (checklist :inline t
2505 (const :format
"Color "
2506 :sibling-args
(:help-echo
"\
2507 Match color frames.")
2509 (const :format
"Grayscale "
2510 :sibling-args
(:help-echo
"\
2511 Match grayscale frames.")
2513 (const :format
"Monochrome%n"
2514 :sibling-args
(:help-echo
"\
2515 Match frames with no color support.")
2517 (group :sibling-args
(:help-echo
"\
2518 Only match frames with the specified intensity.")
2520 Background brightness: "
2522 (checklist :inline t
2524 (const :format
"Light "
2525 :sibling-args
(:help-echo
"\
2526 Match frames with light backgrounds.")
2528 (const :format
"Dark\n"
2529 :sibling-args
(:help-echo
"\
2530 Match frames with dark backgrounds.")
2533 ;;; The `custom-face' Widget.
2535 (defface custom-face-tag-face
2536 `((t (:bold t
:height
1.2 :inherit variable-pitch
)))
2537 "Face used for face tags."
2538 :group
'custom-faces
)
2540 (defcustom custom-face-default-form
'selected
2541 "Default form of displaying face definition."
2542 :type
'(choice (const all
)
2545 :group
'custom-buffer
2548 (define-widget 'custom-face
'custom
2550 :sample-face
'custom-face-tag-face
2551 :help-echo
"Set or reset this face."
2552 :documentation-property
#'face-doc-string
2553 :value-create
'custom-face-value-create
2554 :action
'custom-face-action
2555 :custom-category
'face
2556 :custom-form nil
; defaults to value of `custom-face-default-form'
2557 :custom-set
'custom-face-set
2558 :custom-save
'custom-face-save
2559 :custom-reset-current
'custom-redraw
2560 :custom-reset-saved
'custom-face-reset-saved
2561 :custom-reset-standard
'custom-face-reset-standard
2562 :custom-menu
'custom-face-menu-create
)
2564 (define-widget 'custom-face-all
'editable-list
2565 "An editable list of display specifications and attributes."
2566 :entry-format
"%i %d %v"
2567 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2568 :append-button-args
'(:help-echo
"Append new display specification here.")
2569 :delete-button-args
'(:help-echo
"Delete this display specification.")
2570 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2572 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2573 "Converted version of the `custom-face-all' widget.")
2575 (define-widget 'custom-display-unselected
'item
2576 "A display specification that doesn't match the selected display."
2577 :match
'custom-display-unselected-match
)
2579 (defun custom-display-unselected-match (widget value
)
2580 "Non-nil if VALUE is an unselected display specification."
2581 (not (face-spec-set-match-display value
(selected-frame))))
2583 (define-widget 'custom-face-selected
'group
2584 "Edit the attributes of the selected display in a face specification."
2585 :args
'((repeat :format
""
2587 (group custom-display-unselected sexp
))
2588 (group (sexp :format
"") custom-face-edit
)
2593 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2594 "Converted version of the `custom-face-selected' widget.")
2596 (defun custom-filter-face-spec (spec filter-index default-filter
)
2597 "Return a canonicalized version of SPEC using.
2598 FILTER-INDEX is the index in the entry for each attribute in
2599 `custom-face-attributes' at which the appropriate filter function can be
2600 found, and DEFAULT-FILTER is the filter to apply for attributes that
2602 (mapcar (lambda (entry)
2603 ;; Filter a single face-spec entry
2604 (let ((tests (car entry
))
2606 ;; Handle both old- and new-style attribute syntax
2607 (if (listp (car (cdr entry
)))
2610 (filtered-attrs nil
))
2611 ;; Filter each face attribute
2612 (while unfiltered-attrs
2613 (let* ((attr (pop unfiltered-attrs
))
2614 (pre-filtered-value (pop unfiltered-attrs
))
2616 (or (nth filter-index
(assq attr custom-face-attributes
))
2620 (funcall filter pre-filtered-value
)
2621 pre-filtered-value
)))
2622 (push filtered-value filtered-attrs
)
2623 (push attr filtered-attrs
)))
2625 (list tests filtered-attrs
)))
2628 (defun custom-pre-filter-face-spec (spec)
2629 "Return SPEC changed as necessary for editing by the face customization widget.
2630 SPEC must be a full face spec."
2631 (custom-filter-face-spec
2634 (cond ((eq value
'unspecified
) nil
)
2635 ((eq value nil
) 'off
)
2638 (defun custom-post-filter-face-spec (spec)
2639 "Return the customized SPEC in a form suitable for setting the face."
2640 (custom-filter-face-spec
2643 (cond ((eq value nil
) 'unspecified
)
2644 ((eq value
'off
) nil
)
2647 (defun custom-face-value-create (widget)
2648 "Create a list of the display specifications for WIDGET."
2649 (let ((buttons (widget-get widget
:buttons
))
2651 (symbol (widget-get widget
:value
))
2652 (tag (widget-get widget
:tag
))
2653 (state (widget-get widget
:custom-state
))
2655 (is-last (widget-get widget
:custom-last
))
2656 (prefix (widget-get widget
:custom-prefix
)))
2658 (setq tag
(prin1-to-string symbol
)))
2659 (cond ((eq custom-buffer-style
'tree
)
2660 (insert prefix
(if is-last
" `--- " " |--- "))
2661 (push (widget-create-child-and-convert
2662 widget
'custom-browse-face-tag
)
2664 (insert " " tag
"\n")
2665 (widget-put widget
:buttons buttons
))
2669 (widget-specify-sample widget begin
(point))
2670 (if (eq custom-buffer-style
'face
)
2672 (if (string-match "face\\'" tag
)
2674 (insert " face: ")))
2676 (push (widget-create-child-and-convert widget
'item
2683 (push (widget-create-child-and-convert
2685 :help-echo
"Hide or show this face."
2686 :action
'custom-toggle-parent
2687 (not (eq state
'hidden
)))
2691 (let ((magic (widget-create-child-and-convert
2692 widget
'custom-magic nil
)))
2693 (widget-put widget
:custom-magic magic
)
2694 (push magic buttons
))
2696 (widget-put widget
:buttons buttons
)
2697 ;; Insert documentation.
2698 (widget-default-format-handler widget ?h
)
2699 ;; The comment field
2700 (unless (eq state
'hidden
)
2701 (let* ((comment (get symbol
'face-comment
))
2703 (widget-create-child-and-convert
2704 widget
'custom-comment
2706 :value
(or comment
""))))
2707 (widget-put widget
:comment-widget comment-widget
)
2708 (push comment-widget children
)))
2710 (unless (eq state
'hidden
)
2711 (when (eq (widget-get widget
:custom-level
) 1)
2712 (custom-add-parent-links widget
))
2713 (custom-add-see-also widget
))
2715 (unless (eq (preceding-char) ?
\n)
2717 (unless (eq state
'hidden
)
2718 (message "Creating face editor...")
2719 (custom-load-widget widget
)
2720 (unless (widget-get widget
:custom-form
)
2721 (widget-put widget
:custom-form custom-face-default-form
))
2722 (let* ((symbol (widget-value widget
))
2723 (spec (or (get symbol
'saved-face
)
2724 (get symbol
'face-defface-spec
)
2725 ;; Attempt to construct it.
2726 (list (list t
(custom-face-attributes-get
2727 symbol
(selected-frame))))))
2728 (form (widget-get widget
:custom-form
))
2729 (indent (widget-get widget
:indent
))
2731 ;; If the user has changed this face in some other way,
2732 ;; edit it as the user has specified it.
2733 (if (not (face-spec-match-p symbol spec
(selected-frame)))
2734 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
2735 (setq spec
(custom-pre-filter-face-spec spec
))
2736 (setq edit
(widget-create-child-and-convert
2738 (cond ((and (eq form
'selected
)
2739 (widget-apply custom-face-selected
2741 (when indent
(insert-char ?\ indent
))
2742 'custom-face-selected
)
2743 ((and (not (eq form
'lisp
))
2744 (widget-apply custom-face-all
2748 (when indent
(insert-char ?\ indent
))
2751 (custom-face-state-set widget
)
2752 (push edit children
)
2753 (widget-put widget
:children children
))
2754 (message "Creating face editor...done"))))))
2756 (defvar custom-face-menu
2757 '(("Set for Current Session" custom-face-set
)
2758 ("Save for Future Sessions" custom-face-save-command
)
2759 ("Reset to Saved" custom-face-reset-saved
2761 (or (get (widget-value widget
) 'saved-face
)
2762 (get (widget-value widget
) 'saved-face-comment
))))
2763 ("Erase Customization" custom-face-reset-standard
2765 (get (widget-value widget
) 'face-defface-spec
)))
2766 ("---" ignore ignore
)
2767 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2768 ("---" ignore ignore
)
2769 ("Show all display specs" custom-face-edit-all
2771 (not (eq (widget-get widget
:custom-form
) 'all
))))
2772 ("Just current attributes" custom-face-edit-selected
2774 (not (eq (widget-get widget
:custom-form
) 'selected
))))
2775 ("Show as Lisp expression" custom-face-edit-lisp
2777 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
2778 "Alist of actions for the `custom-face' widget.
2779 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2780 the menu entry, ACTION is the function to call on the widget when the
2781 menu is selected, and FILTER is a predicate which takes a `custom-face'
2782 widget as an argument, and returns non-nil if ACTION is valid on that
2783 widget. If FILTER is nil, ACTION is always valid.")
2785 (defun custom-face-edit-selected (widget)
2786 "Edit selected attributes of the value of WIDGET."
2787 (widget-put widget
:custom-state
'unknown
)
2788 (widget-put widget
:custom-form
'selected
)
2789 (custom-redraw widget
))
2791 (defun custom-face-edit-all (widget)
2792 "Edit all attributes of the value of WIDGET."
2793 (widget-put widget
:custom-state
'unknown
)
2794 (widget-put widget
:custom-form
'all
)
2795 (custom-redraw widget
))
2797 (defun custom-face-edit-lisp (widget)
2798 "Edit the Lisp representation of the value of WIDGET."
2799 (widget-put widget
:custom-state
'unknown
)
2800 (widget-put widget
:custom-form
'lisp
)
2801 (custom-redraw widget
))
2803 (defun custom-face-state-set (widget)
2804 "Set the state of WIDGET."
2805 (let* ((symbol (widget-value widget
))
2806 (comment (get symbol
'face-comment
))
2808 (widget-put widget
:custom-state
2810 (setq tmp
(get symbol
'customized-face
))
2811 (setq temp
(get symbol
'customized-face-comment
))
2813 (if (equal temp comment
)
2817 (setq tmp
(get symbol
'saved-face
))
2818 (setq temp
(get symbol
'saved-face-comment
))
2820 (if (equal temp comment
)
2823 ((get symbol
'face-defface-spec
)
2824 (if (equal comment nil
)
2830 (defun custom-face-action (widget &optional event
)
2831 "Show the menu for `custom-face' WIDGET.
2832 Optional EVENT is the location for the menu."
2833 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2834 (custom-toggle-hide widget
)
2835 (let* ((completion-ignore-case t
)
2836 (symbol (widget-get widget
:value
))
2837 (answer (widget-choose (concat "Operation on "
2838 (custom-unlispify-tag-name symbol
))
2839 (custom-menu-filter custom-face-menu
2843 (funcall answer widget
)))))
2845 (defun custom-face-set (widget)
2846 "Make the face attributes in WIDGET take effect."
2847 (let* ((symbol (widget-value widget
))
2848 (child (car (widget-get widget
:children
)))
2849 (value (custom-post-filter-face-spec (widget-value child
)))
2850 (comment-widget (widget-get widget
:comment-widget
))
2851 (comment (widget-value comment-widget
)))
2852 (when (equal comment
"")
2854 ;; Make the comment invisible by hand if it's empty
2855 (custom-comment-hide comment-widget
))
2856 (put symbol
'customized-face value
)
2857 (if (face-spec-choose value
)
2858 (face-spec-set symbol value
)
2859 ;; face-set-spec ignores empty attribute lists, so just give it
2860 ;; something harmless instead.
2861 (face-spec-set symbol
'((t :foreground unspecified
))))
2862 (put symbol
'customized-face-comment comment
)
2863 (put symbol
'face-comment comment
)
2864 (custom-face-state-set widget
)
2865 (custom-redraw-magic widget
)))
2867 (defun custom-face-save-command (widget)
2868 "Save in `.emacs' the face attributes in WIDGET."
2869 (custom-face-save widget
)
2872 (defun custom-face-save (widget)
2873 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2874 (let* ((symbol (widget-value widget
))
2875 (child (car (widget-get widget
:children
)))
2876 (value (custom-post-filter-face-spec (widget-value child
)))
2877 (comment-widget (widget-get widget
:comment-widget
))
2878 (comment (widget-value comment-widget
)))
2879 (when (equal comment
"")
2881 ;; Make the comment invisible by hand if it's empty
2882 (custom-comment-hide comment-widget
))
2883 (if (face-spec-choose value
)
2884 (face-spec-set symbol value
)
2885 ;; face-set-spec ignores empty attribute lists, so just give it
2886 ;; something harmless instead.
2887 (face-spec-set symbol
'((t :foreground unspecified
))))
2888 (put symbol
'saved-face value
)
2889 (put symbol
'customized-face nil
)
2890 (put symbol
'face-comment comment
)
2891 (put symbol
'customized-face-comment nil
)
2892 (put symbol
'saved-face-comment comment
)
2894 (custom-face-state-set widget
)
2895 (custom-redraw-magic widget
)))
2897 (defun custom-face-reset-saved (widget)
2898 "Restore WIDGET to the face's default attributes."
2899 (let* ((symbol (widget-value widget
))
2900 (child (car (widget-get widget
:children
)))
2901 (value (get symbol
'saved-face
))
2902 (comment (get symbol
'saved-face-comment
))
2903 (comment-widget (widget-get widget
:comment-widget
)))
2904 (unless (or value comment
)
2905 (error "No saved value for this face"))
2906 (put symbol
'customized-face nil
)
2907 (put symbol
'customized-face-comment nil
)
2908 (face-spec-set symbol value
)
2909 (put symbol
'face-comment comment
)
2910 (widget-value-set child value
)
2911 ;; This call manages the comment visibility
2912 (widget-value-set comment-widget
(or comment
""))
2913 (custom-face-state-set widget
)
2914 (custom-redraw-magic widget
)))
2916 (defun custom-face-reset-standard (widget)
2917 "Restore WIDGET to the face's standard settings.
2918 This operation eliminates any saved setting for the face,
2919 restoring it to the state of a face that has never been customized."
2920 (let* ((symbol (widget-value widget
))
2921 (child (car (widget-get widget
:children
)))
2922 (value (get symbol
'face-defface-spec
))
2923 (comment-widget (widget-get widget
:comment-widget
)))
2925 (error "No standard setting for this face"))
2926 (put symbol
'customized-face nil
)
2927 (put symbol
'customized-face-comment nil
)
2928 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
2929 (put symbol
'saved-face nil
)
2930 (put symbol
'saved-face-comment nil
)
2932 (face-spec-set symbol value
)
2933 (put symbol
'face-comment nil
)
2934 (widget-value-set child value
)
2935 ;; This call manages the comment visibility
2936 (widget-value-set comment-widget
"")
2937 (custom-face-state-set widget
)
2938 (custom-redraw-magic widget
)))
2940 ;;; The `face' Widget.
2942 (define-widget 'face
'default
2943 "Select and customize a face."
2944 :convert-widget
'widget-value-convert-widget
2945 :button-prefix
'widget-push-button-prefix
2946 :button-suffix
'widget-push-button-suffix
2947 :format
"%{%t%}: %[select face%] %v"
2950 :value-create
'widget-face-value-create
2951 :value-delete
'widget-face-value-delete
2952 :value-get
'widget-value-value-get
2953 :validate
'widget-children-validate
2954 :action
'widget-face-action
2955 :match
(lambda (widget value
) (symbolp value
)))
2957 (defun widget-face-value-create (widget)
2958 "Create a `custom-face' child."
2959 (let* ((symbol (widget-value widget
))
2960 (custom-buffer-style 'face
)
2961 (child (widget-create-child-and-convert
2965 (custom-magic-reset child
)
2966 (setq custom-options
(cons child custom-options
))
2967 (widget-put widget
:children
(list child
))))
2969 (defun widget-face-value-delete (widget)
2970 "Remove the child from the options."
2971 (let ((child (car (widget-get widget
:children
))))
2972 (setq custom-options
(delq child custom-options
))
2973 (widget-children-value-delete widget
)))
2975 (defvar face-history nil
2976 "History of entered face names.")
2978 (defun widget-face-action (widget &optional event
)
2979 "Prompt for a face."
2980 (let ((answer (completing-read "Face: "
2981 (mapcar (lambda (face)
2982 (list (symbol-name face
)))
2986 (unless (zerop (length answer
))
2987 (widget-value-set widget
(intern answer
))
2988 (widget-apply widget
:notify widget event
)
2991 ;;; The `hook' Widget.
2993 (define-widget 'hook
'list
2995 :value-to-internal
(lambda (widget value
)
2996 (if (and value
(symbolp value
))
2999 :match
(lambda (widget value
)
3001 (widget-group-match widget value
)))
3002 ;; Avoid adding undefined functions to the hook, especially for
3003 ;; things like `find-file-hook' or even more basic ones, to avoid
3005 :set
(lambda (symbol value
)
3008 (add-hook symbol elt
))))
3009 :convert-widget
'custom-hook-convert-widget
3012 (defun custom-hook-convert-widget (widget)
3013 ;; Handle `:options'.
3014 (let* ((options (widget-get widget
:options
))
3015 (other `(editable-list :inline t
3016 :entry-format
"%i %d%v"
3017 (function :format
" %v")))
3019 (list `(checklist :inline t
3020 ,@(mapcar (lambda (entry)
3021 `(function-item ,entry
))
3025 (widget-put widget
:args args
)
3028 ;;; The `custom-group-link' Widget.
3030 (define-widget 'custom-group-link
'link
3031 "Show parent in other window when activated."
3032 :help-echo
"Create customization buffer for this group."
3033 :action
'custom-group-link-action
)
3035 (defun custom-group-link-action (widget &rest ignore
)
3036 (customize-group (widget-value widget
)))
3038 ;;; The `custom-group' Widget.
3040 (defcustom custom-group-tag-faces nil
3041 ;; In XEmacs, this ought to play games with font size.
3042 ;; Fixme: make it do so in Emacs.
3043 "Face used for group tags.
3044 The first member is used for level 1 groups, the second for level 2,
3045 and so forth. The remaining group tags are shown with
3046 `custom-group-tag-face'."
3047 :type
'(repeat face
)
3048 :group
'custom-faces
)
3050 (defface custom-group-tag-face-1
3053 (:foreground
"pink" :bold t
:height
1.2 :inherit variable-pitch
))
3056 (:foreground
"red" :bold t
:height
1.2 :inherit variable-pitch
))
3058 "Face used for group tags."
3059 :group
'custom-faces
)
3061 (defface custom-group-tag-face
3064 (:foreground
"light blue" :bold t
:height
1.2))
3067 (:foreground
"blue" :bold t
:height
1.2))
3069 "Face used for low level group tags."
3070 :group
'custom-faces
)
3072 (define-widget 'custom-group
'custom
3075 :sample-face-get
'custom-group-sample-face-get
3076 :documentation-property
'group-documentation
3077 :help-echo
"Set or reset all members of this group."
3078 :value-create
'custom-group-value-create
3079 :action
'custom-group-action
3080 :custom-category
'group
3081 :custom-set
'custom-group-set
3082 :custom-save
'custom-group-save
3083 :custom-reset-current
'custom-group-reset-current
3084 :custom-reset-saved
'custom-group-reset-saved
3085 :custom-reset-standard
'custom-group-reset-standard
3086 :custom-menu
'custom-group-menu-create
)
3088 (defun custom-group-sample-face-get (widget)
3089 ;; Use :sample-face.
3090 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3091 'custom-group-tag-face
))
3093 (define-widget 'custom-group-visibility
'visibility
3094 "An indicator and manipulator for hidden group contents."
3095 :create
'custom-group-visibility-create
)
3097 (defun custom-group-visibility-create (widget)
3098 (let ((visible (widget-value widget
)))
3100 (insert "--------")))
3101 (widget-default-create widget
))
3103 (defun custom-group-members (symbol groups-only
)
3104 "Return SYMBOL's custom group members.
3105 If GROUPS-ONLY non-nil, return only those members that are groups."
3106 (if (not groups-only
)
3107 (get symbol
'custom-group
)
3109 (dolist (entry (get symbol
'custom-group
))
3110 (when (eq (nth 1 entry
) 'custom-group
)
3111 (push entry members
)))
3112 (nreverse members
))))
3114 (defun custom-group-value-create (widget)
3115 "Insert a customize group for WIDGET in the current buffer."
3116 (let* ((state (widget-get widget
:custom-state
))
3117 (level (widget-get widget
:custom-level
))
3118 ;; (indent (widget-get widget :indent))
3119 (prefix (widget-get widget
:custom-prefix
))
3120 (buttons (widget-get widget
:buttons
))
3121 (tag (widget-get widget
:tag
))
3122 (symbol (widget-value widget
))
3123 (members (custom-group-members symbol
3124 (and (eq custom-buffer-style
'tree
)
3125 custom-browse-only-groups
))))
3126 (cond ((and (eq custom-buffer-style
'tree
)
3128 (or members
(custom-unloaded-widget-p widget
)))
3129 (custom-browse-insert-prefix prefix
)
3130 (push (widget-create-child-and-convert
3131 widget
'custom-browse-visibility
3132 ;; :tag-glyph "plus"
3136 ;; (widget-glyph-insert nil "-- " "horizontal")
3137 (push (widget-create-child-and-convert
3138 widget
'custom-browse-group-tag
)
3140 (insert " " tag
"\n")
3141 (widget-put widget
:buttons buttons
))
3142 ((and (eq custom-buffer-style
'tree
)
3143 (zerop (length members
)))
3144 (custom-browse-insert-prefix prefix
)
3146 ;; (widget-glyph-insert nil "[ ]" "empty")
3147 ;; (widget-glyph-insert nil "-- " "horizontal")
3148 (push (widget-create-child-and-convert
3149 widget
'custom-browse-group-tag
)
3151 (insert " " tag
"\n")
3152 (widget-put widget
:buttons buttons
))
3153 ((eq custom-buffer-style
'tree
)
3154 (custom-browse-insert-prefix prefix
)
3155 (custom-load-widget widget
)
3156 (if (zerop (length members
))
3158 (custom-browse-insert-prefix prefix
)
3160 ;; (widget-glyph-insert nil "[ ]" "empty")
3161 ;; (widget-glyph-insert nil "-- " "horizontal")
3162 (push (widget-create-child-and-convert
3163 widget
'custom-browse-group-tag
)
3165 (insert " " tag
"\n")
3166 (widget-put widget
:buttons buttons
))
3167 (push (widget-create-child-and-convert
3168 widget
'custom-browse-visibility
3169 ;; :tag-glyph "minus"
3173 ;; (widget-glyph-insert nil "-\\ " "top")
3174 (push (widget-create-child-and-convert
3175 widget
'custom-browse-group-tag
)
3177 (insert " " tag
"\n")
3178 (widget-put widget
:buttons buttons
)
3179 (message "Creating group...")
3180 (let* ((members (custom-sort-items members
3181 custom-browse-sort-alphabetically
3182 custom-browse-order-groups
))
3183 (prefixes (widget-get widget
:custom-prefixes
))
3184 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3185 (extra-prefix (if (widget-get widget
:custom-last
)
3188 (prefix (concat prefix extra-prefix
))
3191 (setq entry
(car members
)
3192 members
(cdr members
))
3193 (push (widget-create-child-and-convert
3194 widget
(nth 1 entry
)
3196 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3197 :custom-prefixes custom-prefix-list
3198 :custom-level
(1+ level
)
3199 :custom-last
(null members
)
3200 :value
(nth 0 entry
)
3201 :custom-prefix prefix
)
3203 (widget-put widget
:children
(reverse children
)))
3204 (message "Creating group...done")))
3207 ;; Create level indicator.
3208 (unless (eq custom-buffer-style
'links
)
3209 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3212 (let ((begin (point)))
3214 (widget-specify-sample widget begin
(point)))
3216 ;; Create link/visibility indicator.
3217 (if (eq custom-buffer-style
'links
)
3218 (push (widget-create-child-and-convert
3219 widget
'custom-group-link
3223 (push (widget-create-child-and-convert
3224 widget
'custom-group-visibility
3225 :help-echo
"Show members of this group."
3226 :action
'custom-toggle-parent
3227 (not (eq state
'hidden
)))
3230 ;; Create magic button.
3231 (let ((magic (widget-create-child-and-convert
3232 widget
'custom-magic nil
)))
3233 (widget-put widget
:custom-magic magic
)
3234 (push magic buttons
))
3236 (widget-put widget
:buttons buttons
)
3237 ;; Insert documentation.
3238 (if (and (eq custom-buffer-style
'links
) (> level
1))
3239 (widget-put widget
:documentation-indent
0))
3240 (widget-default-format-handler widget ?h
))
3243 ;; Add parent groups references above the group.
3244 (if t
;;; This should test that the buffer
3245 ;;; was made to display a group.
3247 (if (custom-add-parent-links widget
3248 "Go to parent group:")
3250 ;; Create level indicator.
3251 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3254 (let ((start (point)))
3256 (widget-specify-sample widget start
(point)))
3258 ;; Create visibility indicator.
3259 (unless (eq custom-buffer-style
'links
)
3261 (push (widget-create-child-and-convert
3263 :help-echo
"Hide members of this group."
3264 :action
'custom-toggle-parent
3265 (not (eq state
'hidden
)))
3268 ;; Create more dashes.
3269 ;; Use 76 instead of 75 to compensate for the temporary "<"
3270 ;; added by `widget-insert'.
3271 (insert-char ?-
(- 76 (current-column)
3272 (* custom-buffer-indent level
)))
3274 ;; Create magic button.
3275 (let ((magic (widget-create-child-and-convert
3276 widget
'custom-magic
3279 (widget-put widget
:custom-magic magic
)
3280 (push magic buttons
))
3282 (widget-put widget
:buttons buttons
)
3283 ;; Insert documentation.
3284 (widget-default-format-handler widget ?h
)
3286 (if nil
;;; This should test that the buffer
3287 ;;; was not made to display a group.
3289 (insert-char ?\ custom-buffer-indent
)
3290 (custom-add-parent-links widget
)))
3291 (custom-add-see-also widget
3292 (make-string (* custom-buffer-indent level
)
3295 (message "Creating group...")
3296 (custom-load-widget widget
)
3297 (let* ((members (custom-sort-items members
3298 custom-buffer-sort-alphabetically
3299 custom-buffer-order-groups
))
3300 (prefixes (widget-get widget
:custom-prefixes
))
3301 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3302 (length (length members
))
3304 (children (mapcar (lambda (entry)
3305 (widget-insert "\n")
3307 Creating group members... %2d%%"
3308 (/ (* 100.0 count
) length
))
3309 (setq count
(1+ count
))
3311 (widget-create-child-and-convert
3312 widget
(nth 1 entry
)
3314 :tag
(custom-unlispify-tag-name
3316 :custom-prefixes custom-prefix-list
3317 :custom-level
(1+ level
)
3318 :value
(nth 0 entry
))
3319 (unless (eq (preceding-char) ?
\n)
3320 (widget-insert "\n"))))
3322 (message "Creating group magic...")
3323 (mapc 'custom-magic-reset children
)
3324 (message "Creating group state...")
3325 (widget-put widget
:children children
)
3326 (custom-group-state-update widget
)
3327 (message "Creating group... done"))
3330 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3331 (insert "\\- " (widget-get widget
:tag
) " group end ")
3332 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3335 (defvar custom-group-menu
3336 '(("Set for Current Session" custom-group-set
3338 (eq (widget-get widget
:custom-state
) 'modified
)))
3339 ("Save for Future Sessions" custom-group-save
3341 (memq (widget-get widget
:custom-state
) '(modified set
))))
3342 ("Reset to Current" custom-group-reset-current
3344 (memq (widget-get widget
:custom-state
) '(modified))))
3345 ("Reset to Saved" custom-group-reset-saved
3347 (memq (widget-get widget
:custom-state
) '(modified set
))))
3348 ("Reset to standard setting" custom-group-reset-standard
3350 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
3351 "Alist of actions for the `custom-group' widget.
3352 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3353 the menu entry, ACTION is the function to call on the widget when the
3354 menu is selected, and FILTER is a predicate which takes a `custom-group'
3355 widget as an argument, and returns non-nil if ACTION is valid on that
3356 widget. If FILTER is nil, ACTION is always valid.")
3358 (defun custom-group-action (widget &optional event
)
3359 "Show the menu for `custom-group' WIDGET.
3360 Optional EVENT is the location for the menu."
3361 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3362 (custom-toggle-hide widget
)
3363 (let* ((completion-ignore-case t
)
3364 (answer (widget-choose (concat "Operation on "
3365 (custom-unlispify-tag-name
3366 (widget-get widget
:value
)))
3367 (custom-menu-filter custom-group-menu
3371 (funcall answer widget
)))))
3373 (defun custom-group-set (widget)
3374 "Set changes in all modified group members."
3375 (let ((children (widget-get widget
:children
)))
3376 (mapc (lambda (child)
3377 (when (eq (widget-get child
:custom-state
) 'modified
)
3378 (widget-apply child
:custom-set
)))
3381 (defun custom-group-save (widget)
3382 "Save all modified group members."
3383 (let ((children (widget-get widget
:children
)))
3384 (mapc (lambda (child)
3385 (when (memq (widget-get child
:custom-state
) '(modified set
))
3386 (widget-apply child
:custom-save
)))
3389 (defun custom-group-reset-current (widget)
3390 "Reset all modified group members."
3391 (let ((children (widget-get widget
:children
)))
3392 (mapc (lambda (child)
3393 (when (eq (widget-get child
:custom-state
) 'modified
)
3394 (widget-apply child
:custom-reset-current
)))
3397 (defun custom-group-reset-saved (widget)
3398 "Reset all modified or set group members."
3399 (let ((children (widget-get widget
:children
)))
3400 (mapc (lambda (child)
3401 (when (memq (widget-get child
:custom-state
) '(modified set
))
3402 (widget-apply child
:custom-reset-saved
)))
3405 (defun custom-group-reset-standard (widget)
3406 "Reset all modified, set, or saved group members."
3407 (let ((children (widget-get widget
:children
)))
3408 (mapc (lambda (child)
3409 (when (memq (widget-get child
:custom-state
)
3410 '(modified set saved
))
3411 (widget-apply child
:custom-reset-standard
)))
3414 (defun custom-group-state-update (widget)
3416 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3417 (let* ((children (widget-get widget
:children
))
3418 (states (mapcar (lambda (child)
3419 (widget-get child
:custom-state
))
3421 (magics custom-magic-alist
)
3424 (let ((magic (car (car magics
))))
3425 (if (and (not (eq magic
'hidden
))
3426 (memq magic states
))
3429 (setq magics
(cdr magics
)))))
3430 (widget-put widget
:custom-state found
)))
3431 (custom-magic-reset widget
))
3433 ;;; The `custom-save-all' Function.
3435 (defcustom custom-file nil
3436 "File used for storing customization information.
3437 The default is nil, which means to use your init file
3438 as specified by `user-init-file'. If you specify some other file,
3439 you need to explicitly load that file for the settings to take effect.
3441 When you change this variable, look in the previous custom file
3442 \(usually your init file) for the forms `(custom-set-variables ...)'
3443 and `(custom-set-faces ...)', and copy them (whichever ones you find)
3444 to the new custom file. This will preserve your existing customizations."
3445 :type
'(choice (const :tag
"Your Emacs init file" nil
) file
)
3448 (defun custom-file ()
3449 "Return the file name for saving customizations."
3453 (read-file-name "File for customizations: "
3454 "~/" nil nil
".emacs"))))
3456 (defun custom-save-delete (symbol)
3457 "Visit `custom-file' and delete all calls to SYMBOL from it.
3458 Leave point at the old location of the first such call,
3459 or (if there were none) at the end of the buffer."
3460 (let ((default-major-mode))
3461 (set-buffer (find-file-noselect (custom-file))))
3462 (goto-char (point-min))
3463 ;; Skip all whitespace and comments.
3464 (while (forward-comment 1))
3466 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3469 (while t
;; We exit this loop only via throw.
3470 ;; Skip all whitespace and comments.
3471 (while (forward-comment 1))
3472 (let ((start (point))
3473 (sexp (condition-case nil
3474 (read (current-buffer))
3475 (end-of-file (throw 'found nil
)))))
3476 (when (and (listp sexp
)
3477 (eq (car sexp
) symbol
))
3478 (delete-region start
(point))
3480 (setq first
(point)))))))
3483 (goto-char (point-max)))))
3485 (defun custom-save-variables ()
3486 "Save all customized variables in `custom-file'."
3488 (custom-save-delete 'custom-set-variables
)
3489 (let ((standard-output (current-buffer))
3490 (saved-list (make-list 1 0))
3492 ;; First create a sorted list of saved variables.
3495 (if (get symbol
'saved-value
)
3496 (nconc saved-list
(list symbol
)))))
3497 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3500 (princ "(custom-set-variables
3501 ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
3502 ;; Your init file should contain only one such instance.\n")
3505 (let ((value (get symbol
'saved-value
))
3506 (requests (get symbol
'custom-requests
))
3507 (now (not (or (get symbol
'standard-value
)
3508 (and (not (boundp symbol
))
3509 (not (get symbol
'force-value
))))))
3510 (comment (get symbol
'saved-variable-comment
))
3512 (when (or value comment
)
3519 (cond ((or now requests comment
)
3524 (cond ((or requests comment
)
3543 (unless (looking-at "\n")
3546 (defun custom-save-faces ()
3547 "Save all customized faces in `custom-file'."
3549 (custom-save-delete 'custom-set-faces
)
3550 (let ((standard-output (current-buffer))
3551 (saved-list (make-list 1 0))
3553 ;; First create a sorted list of saved faces.
3556 (if (get symbol
'saved-face
)
3557 (nconc saved-list
(list symbol
)))))
3558 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3559 ;; The default face must be first, since it affects the others.
3560 (if (memq 'default saved-list
)
3561 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
3564 (princ "(custom-set-faces
3565 ;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
3566 ;; Your init file should contain only one such instance.\n")
3569 (let ((value (get symbol
'saved-face
))
3570 (now (not (or (get 'default
'face-defface-spec
)
3571 (and (not (custom-facep 'default
))
3572 (not (get 'default
'force-face
))))))
3573 (comment (get 'default
'saved-face-comment
)))
3574 (unless (eq symbol
'default
))
3575 ;; Don't print default face here.
3582 (cond ((or now comment
)
3599 (unless (looking-at "\n")
3603 (defun customize-save-customized ()
3604 "Save all user options which have been set in this session."
3606 (mapatoms (lambda (symbol)
3607 (let ((face (get symbol
'customized-face
))
3608 (value (get symbol
'customized-value
))
3609 (face-comment (get symbol
'customized-face-comment
))
3611 (get symbol
'customized-variable-comment
)))
3613 (put symbol
'saved-face face
)
3614 (put symbol
'customized-face nil
))
3616 (put symbol
'saved-value value
)
3617 (put symbol
'customized-value nil
))
3618 (when variable-comment
3619 (put symbol
'saved-variable-comment variable-comment
)
3620 (put symbol
'customized-variable-comment nil
))
3622 (put symbol
'saved-face-comment face-comment
)
3623 (put symbol
'customized-face-comment nil
)))))
3624 ;; We really should update all custom buffers here.
3628 (defun custom-save-all ()
3629 "Save all customizations in `custom-file'."
3630 (let ((inhibit-read-only t
))
3631 (custom-save-variables)
3634 (let ((default-major-mode nil
))
3635 (set-buffer (find-file-noselect (custom-file))))
3638 ;;; The Customize Menu.
3642 (defcustom custom-menu-nesting
2
3643 "Maximum nesting in custom menus."
3645 :group
'custom-menu
)
3647 (defun custom-face-menu-create (widget symbol
)
3648 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3649 (vector (custom-unlispify-menu-entry symbol
)
3650 `(customize-face ',symbol
)
3653 (defun custom-variable-menu-create (widget symbol
)
3654 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3655 (let ((type (get symbol
'custom-type
)))
3656 (unless (listp type
)
3657 (setq type
(list type
)))
3658 (if (and type
(widget-get type
:custom-menu
))
3659 (widget-apply type
:custom-menu symbol
)
3660 (vector (custom-unlispify-menu-entry symbol
)
3661 `(customize-variable ',symbol
)
3664 ;; Add checkboxes to boolean variable entries.
3665 (widget-put (get 'boolean
'widget-type
)
3666 :custom-menu
(lambda (widget symbol
)
3667 (vector (custom-unlispify-menu-entry symbol
)
3668 `(customize-variable ',symbol
)
3670 ':selected symbol
)))
3672 (defun custom-group-menu-create (widget symbol
)
3673 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3674 `( ,(custom-unlispify-menu-entry symbol t
)
3675 :filter
(lambda (&rest junk
)
3676 (cdr (custom-menu-create ',symbol
)))))
3679 (defun custom-menu-create (symbol)
3680 "Create menu for customization group SYMBOL.
3681 The menu is in a format applicable to `easy-menu-define'."
3682 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
3683 `(customize-group ',symbol
)
3685 (if (and (or (not (boundp 'custom-menu-nesting
))
3686 (>= custom-menu-nesting
0))
3687 (< (length (get symbol
'custom-group
)) widget-menu-max-size
))
3688 (let ((custom-prefix-list (custom-prefix-add symbol
3689 custom-prefix-list
))
3690 (members (custom-sort-items (get symbol
'custom-group
)
3691 custom-menu-sort-alphabetically
3692 custom-menu-order-groups
)))
3693 (custom-load-symbol symbol
)
3694 `(,(custom-unlispify-menu-entry symbol t
)
3697 ,@(mapcar (lambda (entry)
3698 (widget-apply (if (listp (nth 1 entry
))
3700 (list (nth 1 entry
)))
3701 :custom-menu
(nth 0 entry
)))
3706 (defun customize-menu-create (symbol &optional name
)
3707 "Return a customize menu for customization group SYMBOL.
3708 If optional NAME is given, use that as the name of the menu.
3709 Otherwise the menu will be named `Customize'.
3710 The format is suitable for use with `easy-menu-define'."
3712 (setq name
"Customize"))
3714 :filter
(lambda (&rest junk
)
3715 (custom-menu-create ',symbol
))))
3717 ;;; The Custom Mode.
3719 (defvar custom-mode-map nil
3720 "Keymap for `custom-mode'.")
3722 (unless custom-mode-map
3723 ;; This keymap should be dense, but a dense keymap would prevent inheriting
3724 ;; "\r" bindings from the parent map.
3725 (setq custom-mode-map
(make-sparse-keymap))
3726 (set-keymap-parent custom-mode-map widget-keymap
)
3727 (suppress-keymap custom-mode-map
)
3728 (define-key custom-mode-map
" " 'scroll-up
)
3729 (define-key custom-mode-map
"\177" 'scroll-down
)
3730 (define-key custom-mode-map
"q" 'Custom-buffer-done
)
3731 (define-key custom-mode-map
"u" 'Custom-goto-parent
)
3732 (define-key custom-mode-map
"n" 'widget-forward
)
3733 (define-key custom-mode-map
"p" 'widget-backward
)
3734 (define-key custom-mode-map
[mouse-1
] 'Custom-move-and-invoke
))
3736 (defun Custom-move-and-invoke (event)
3737 "Move to where you click, and if it is an active field, invoke it."
3739 (mouse-set-point event
)
3740 (if (widget-event-point event
)
3741 (let* ((pos (widget-event-point event
))
3742 (button (get-char-property pos
'button
)))
3744 (widget-button-click event
)))))
3746 (easy-menu-define Custom-mode-menu
3748 "Menu used in customization buffers."
3750 ,(customize-menu-create 'customize
)
3751 ["Set" Custom-set t
]
3752 ["Save" Custom-save t
]
3753 ["Reset to Current" Custom-reset-current t
]
3754 ["Reset to Saved" Custom-reset-saved t
]
3755 ["Reset to Standard Settings" Custom-reset-standard t
]
3756 ["Info" (Info-goto-node "(emacs)Easy Customization") t
]))
3758 (defun Custom-goto-parent ()
3759 "Go to the parent group listed at the top of this buffer.
3760 If several parents are listed, go to the first of them."
3763 (goto-char (point-min))
3764 (if (search-forward "\nGo to parent group: " nil t
)
3765 (let* ((button (get-char-property (point) 'button
))
3766 (parent (downcase (widget-get button
:tag
))))
3767 (customize-group parent
)))))
3769 (defcustom custom-mode-hook nil
3770 "Hook called when entering Custom mode."
3772 :group
'custom-buffer
)
3774 (defun custom-state-buffer-message (widget)
3775 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
3776 (message "To install your edits, invoke [State] and choose the Set operation")))
3778 (defun custom-mode ()
3779 "Major mode for editing customization buffers.
3781 The following commands are available:
3783 Move to next button or editable field. \\[widget-forward]
3784 Move to previous button or editable field. \\[widget-backward]
3785 \\<widget-field-keymap>\
3786 Complete content of editable text field. \\[widget-complete]
3787 \\<custom-mode-map>\
3788 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3789 Invoke button under point. \\[widget-button-press]
3790 Set all modifications. \\[Custom-set]
3791 Make all modifications default. \\[Custom-save]
3792 Reset all modified options. \\[Custom-reset-current]
3793 Reset all modified or set options. \\[Custom-reset-saved]
3794 Reset all options. \\[Custom-reset-standard]
3796 Entry to this mode calls the value of `custom-mode-hook'
3797 if that value is non-nil."
3798 (kill-all-local-variables)
3799 (setq major-mode
'custom-mode
3801 (use-local-map custom-mode-map
)
3802 (easy-menu-add Custom-mode-menu
)
3803 (make-local-variable 'custom-options
)
3804 (make-local-variable 'widget-documentation-face
)
3805 (setq widget-documentation-face
'custom-documentation-face
)
3806 (make-local-variable 'widget-button-face
)
3807 (setq widget-button-face
'custom-button-face
)
3808 (set (make-local-variable 'widget-button-pressed-face
)
3809 'custom-button-pressed-face
)
3810 (set (make-local-variable 'widget-mouse-face
)
3811 'custom-button-pressed-face
) ; buttons `depress' when moused
3812 ;; When possible, use relief for buttons, not bracketing. This test
3813 ;; may not be optimal.
3814 (when custom-raised-buttons
3815 (set (make-local-variable 'widget-push-button-prefix
) "")
3816 (set (make-local-variable 'widget-push-button-suffix
) "")
3817 (set (make-local-variable 'widget-link-prefix
) "")
3818 (set (make-local-variable 'widget-link-suffix
) ""))
3819 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
3820 (run-hooks 'custom-mode-hook
))
3822 (put 'custom-mode
'mode-class
'special
)
3825 'debug-ignored-errors
3826 "^No user options have changed defaults in recent Emacs versions$")
3832 ;;; cus-edit.el ends here