1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002 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."
434 :group
'custom-buffer
437 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
438 "Convert SYMBOL into a menu entry."
439 (cond ((not custom-unlispify-menu-entries
)
440 (symbol-name symbol
))
441 ((get symbol
'custom-tag
)
443 (get symbol
'custom-tag
)
444 (concat (get symbol
'custom-tag
) "...")))
447 (set-buffer (get-buffer-create " *Custom-Work*"))
449 (princ symbol
(current-buffer))
450 (goto-char (point-min))
451 ;; FIXME: Boolean variables are not predicates, so they shouldn't
452 ;; end with `-p'. -stef
453 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
454 ;; (re-search-forward "-p\\'" nil t))
455 ;; (replace-match "" t t)
456 ;; (goto-char (point-min)))
457 (if custom-unlispify-remove-prefixes
458 (let ((prefixes custom-prefix-list
)
461 (setq prefix
(car prefixes
))
462 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
465 (delete-region (point-min) (point)))
466 (setq prefixes
(cdr prefixes
))))))
467 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
468 (capitalize-region (point-min) (point-max))
470 (goto-char (point-max))
474 (defcustom custom-unlispify-tag-names t
475 "Display tag names as words instead of symbols if non nil."
476 :group
'custom-buffer
479 (defun custom-unlispify-tag-name (symbol)
480 "Convert SYMBOL into a menu entry."
481 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
482 (custom-unlispify-menu-entry symbol t
)))
484 (defun custom-prefix-add (symbol prefixes
)
485 "Add SYMBOL to list of ignored PREFIXES."
486 (cons (or (get symbol
'custom-prefix
)
487 (concat (symbol-name symbol
) "-"))
492 (defcustom custom-guess-name-alist
497 ("-function\\'" function
)
498 ("-functions\\'" (repeat function
))
499 ("-list\\'" (repeat sexp
))
500 ("-alist\\'" (repeat (cons sexp sexp
))))
501 "Alist of (MATCH TYPE).
503 MATCH should be a regexp matching the name of a symbol, and TYPE should
504 be a widget suitable for editing the value of that symbol. The TYPE
505 of the first entry where MATCH matches the name of the symbol will be
508 This is used for guessing the type of variables not declared with
510 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
513 (defcustom custom-guess-doc-alist
514 '(("\\`\\*?Non-nil " boolean
))
515 "Alist of (MATCH TYPE).
517 MATCH should be a regexp matching a documentation string, and TYPE
518 should be a widget suitable for editing the value of a variable with
519 that documentation string. The TYPE of the first entry where MATCH
520 matches the name of the symbol will be used.
522 This is used for guessing the type of variables not declared with
524 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
527 (defun custom-guess-type (symbol)
528 "Guess a widget suitable for editing the value of SYMBOL.
529 This is done by matching SYMBOL with `custom-guess-name-alist' and
530 if that fails, the doc string with `custom-guess-doc-alist'."
531 (let ((name (symbol-name symbol
))
532 (names custom-guess-name-alist
)
535 (setq current
(car names
)
537 (when (string-match (nth 0 current
) name
)
538 (setq found
(nth 1 current
)
541 (let ((doc (documentation-property symbol
'variable-documentation
))
542 (docs custom-guess-doc-alist
))
545 (setq current
(car docs
)
547 (when (string-match (nth 0 current
) doc
)
548 (setq found
(nth 1 current
)
554 (defcustom custom-browse-sort-alphabetically nil
555 "If non-nil, sort members of each customization group alphabetically."
557 :group
'custom-browse
)
559 (defcustom custom-browse-order-groups nil
560 "If non-nil, order group members within each customization group.
561 If `first', order groups before non-groups.
562 If `last', order groups after non-groups."
563 :type
'(choice (const first
)
565 (const :tag
"none" nil
))
566 :group
'custom-browse
)
568 (defcustom custom-browse-only-groups nil
569 "If non-nil, show group members only within each customization group."
571 :group
'custom-browse
)
573 (defcustom custom-buffer-sort-alphabetically nil
574 "If non-nil, sort members of each customization group alphabetically."
576 :group
'custom-buffer
)
578 (defcustom custom-buffer-order-groups
'last
579 "If non-nil, order group members within each customization group.
580 If `first', order groups before non-groups.
581 If `last', order groups after non-groups."
582 :type
'(choice (const first
)
584 (const :tag
"none" nil
))
585 :group
'custom-buffer
)
587 (defcustom custom-menu-sort-alphabetically nil
588 "If non-nil, sort members of each customization group alphabetically."
592 (defcustom custom-menu-order-groups
'first
593 "If non-nil, order group members within each customization group.
594 If `first', order groups before non-groups.
595 If `last', order groups after non-groups."
596 :type
'(choice (const first
)
598 (const :tag
"none" nil
))
601 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
603 (defun custom-sort-items (items sort-alphabetically order-groups
)
604 "Return a sorted copy of ITEMS.
605 ITEMS should be a `custom-group' property.
606 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
607 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
608 groups after non-groups, if nil do not order groups at all."
609 (sort (copy-sequence items
)
611 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
612 (namea (nth 0 a
)) (nameb (nth 0 b
)))
613 (cond ((not order-groups
)
614 ;; Since we don't care about A and B order, maybe sort.
615 (when sort-alphabetically
616 (string-lessp namea nameb
)))
617 ((eq typea
'custom-group
)
618 ;; If B is also a group, maybe sort. Otherwise, order A and B.
619 (if (eq typeb
'custom-group
)
620 (when sort-alphabetically
621 (string-lessp namea nameb
))
622 (eq order-groups
'first
)))
623 ((eq typeb
'custom-group
)
624 ;; Since A cannot be a group, order A and B.
625 (eq order-groups
'last
))
627 ;; Since A and B cannot be groups, sort.
628 (string-lessp namea nameb
)))))))
630 ;;; Custom Mode Commands.
632 (defvar custom-options nil
633 "Customization widgets in the current buffer.")
636 "Set changes in all modified options."
638 (let ((children custom-options
))
639 (mapc (lambda (child)
640 (when (eq (widget-get child
:custom-state
) 'modified
)
641 (widget-apply child
:custom-set
)))
644 (defun Custom-save ()
645 "Set all modified group members and save them."
647 (let ((children custom-options
))
648 (mapc (lambda (child)
649 (when (memq (widget-get child
:custom-state
)
650 '(modified set changed rogue
))
651 (widget-apply child
:custom-save
)))
655 (defvar custom-reset-menu
656 '(("Current" . Custom-reset-current
)
657 ("Saved" . Custom-reset-saved
)
658 ("Erase Customization (use standard settings)" . Custom-reset-standard
))
659 "Alist of actions for the `Reset' button.
660 The key is a string containing the name of the action, the value is a
661 Lisp function taking the widget as an element which will be called
662 when the action is chosen.")
664 (defun custom-reset (event)
665 "Select item from reset menu."
666 (let* ((completion-ignore-case t
)
667 (answer (widget-choose "Reset to"
673 (defun Custom-reset-current (&rest ignore
)
674 "Reset all modified group members to their current value."
676 (let ((children custom-options
))
677 (mapc (lambda (widget)
678 (and (default-boundp (widget-value widget
))
679 (if (memq (widget-get widget
:custom-state
)
681 (widget-apply widget
:custom-reset-current
))))
684 (defun Custom-reset-saved (&rest ignore
)
685 "Reset all modified or set group members to their saved value."
687 (let ((children custom-options
))
688 (mapc (lambda (widget)
689 (and (get (widget-value widget
) 'saved-value
)
690 (if (memq (widget-get widget
:custom-state
)
691 '(modified set changed rogue
))
692 (widget-apply widget
:custom-reset-saved
))))
695 (defun Custom-reset-standard (&rest ignore
)
696 "Erase all customization (either current or saved) for the group members.
697 The immediate result is to restore them to their standard settings.
698 This operation eliminates any saved settings for the group members,
699 making them as if they had never been customized at all."
701 (let ((children custom-options
))
702 (mapc (lambda (widget)
703 (and (widget-apply widget
:custom-standard-value
)
704 (if (memq (widget-get widget
:custom-state
)
705 '(modified set changed saved rogue
))
706 (widget-apply widget
:custom-reset-standard
))))
709 ;;; The Customize Commands
711 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
712 "Prompt for a variable and a value and return them as a list.
713 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
714 prompt for the value. The %s escape in PROMPT-VAL is replaced with
715 the name of the variable.
717 If the variable has a `variable-interactive' property, that is used as if
718 it were the arg to `interactive' (which see) to interactively read the value.
720 If the variable has a `custom-type' property, it must be a widget and the
721 `:prompt-value' property of that widget will be used for reading the value.
723 If optional COMMENT argument is non nil, also prompt for a comment and return
724 it as the third element in the list."
725 (let* ((var (read-variable prompt-var
))
726 (minibuffer-help-form '(describe-variable var
))
728 (let ((prop (get var
'variable-interactive
))
729 (type (get var
'custom-type
))
730 (prompt (format prompt-val var
)))
732 (setq type
(list type
)))
734 ;; Use VAR's `variable-interactive' property
735 ;; as an interactive spec for prompting.
736 (call-interactively (list 'lambda
'(arg)
737 (list 'interactive prop
)
740 (widget-prompt-value type
746 (eval-minibuffer prompt
))))))
749 (read-string "Comment: " (get var
'variable-comment
)))
753 (defun customize-set-value (variable value
&optional comment
)
754 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
756 If VARIABLE has a `variable-interactive' property, that is used as if
757 it were the arg to `interactive' (which see) to interactively read the value.
759 If VARIABLE has a `custom-type' property, it must be a widget and the
760 `:prompt-value' property of that widget will be used for reading the value.
762 If given a prefix (or a COMMENT argument), also prompt for a comment."
763 (interactive (custom-prompt-variable "Set variable: "
767 (cond ((string= comment
"")
768 (put variable
'variable-comment nil
))
770 (put variable
'variable-comment comment
)))
771 (set variable value
))
774 (defun customize-set-variable (variable value
&optional comment
)
775 "Set the default for VARIABLE to VALUE, and return VALUE.
776 VALUE is a Lisp object.
778 If VARIABLE has a `custom-set' property, that is used for setting
779 VARIABLE, otherwise `set-default' is used.
781 The `customized-value' property of the VARIABLE will be set to a list
782 with a quoted VALUE as its sole list member.
784 If VARIABLE has a `variable-interactive' property, that is used as if
785 it were the arg to `interactive' (which see) to interactively read the value.
787 If VARIABLE has a `custom-type' property, it must be a widget and the
788 `:prompt-value' property of that widget will be used for reading the value.
790 If given a prefix (or a COMMENT argument), also prompt for a comment."
791 (interactive (custom-prompt-variable "Set variable: "
792 "Set customized value for %s to: "
794 (custom-load-symbol variable
)
795 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
796 (put variable
'customized-value
(list (custom-quote value
)))
797 (cond ((string= comment
"")
798 (put variable
'variable-comment nil
)
799 (put variable
'customized-variable-comment nil
))
801 (put variable
'variable-comment comment
)
802 (put variable
'customized-variable-comment comment
)))
806 (defun customize-save-variable (variable value
&optional comment
)
807 "Set the default for VARIABLE to VALUE, and save it for future sessions.
810 If VARIABLE has a `custom-set' property, that is used for setting
811 VARIABLE, otherwise `set-default' is used.
813 The `customized-value' property of the VARIABLE will be set to a list
814 with a quoted VALUE as its sole list member.
816 If VARIABLE has a `variable-interactive' property, that is used as if
817 it were the arg to `interactive' (which see) to interactively read the value.
819 If VARIABLE has a `custom-type' property, it must be a widget and the
820 `:prompt-value' property of that widget will be used for reading the value.
822 If given a prefix (or a COMMENT argument), also prompt for a comment."
823 (interactive (custom-prompt-variable "Set and save variable: "
824 "Set and save value for %s as: "
826 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
827 (put variable
'saved-value
(list (custom-quote value
)))
828 (cond ((string= comment
"")
829 (put variable
'variable-comment nil
)
830 (put variable
'saved-variable-comment nil
))
832 (put variable
'variable-comment comment
)
833 (put variable
'saved-variable-comment comment
)))
839 "Select a customization buffer which you can use to set user options.
840 User options are structured into \"groups\".
841 Initially the top-level group `Emacs' and its immediate subgroups
842 are shown; the contents of those subgroups are initially hidden."
844 (customize-group 'emacs
))
847 (defun customize-group (group)
848 "Customize GROUP, which must be a customization group."
849 (interactive (list (let ((completion-ignore-case t
))
850 (completing-read "Customize group: (default emacs) "
853 (or (get symbol
'custom-loads
)
854 (get symbol
'custom-group
)))
856 (when (stringp group
)
857 (if (string-equal "" group
)
859 (setq group
(intern group
))))
860 (or (get group
'custom-group
)
861 (custom-load-symbol group
))
862 (let ((name (format "*Customize Group: %s*"
863 (custom-unlispify-tag-name group
))))
864 (if (get-buffer name
)
866 (custom-buffer-create (list (list group
'custom-group
))
868 (concat " for group "
869 (custom-unlispify-tag-name group
))))))
872 (defun customize-group-other-window (group)
873 "Customize GROUP, which must be a customization group."
874 (interactive (list (let ((completion-ignore-case t
))
875 (completing-read "Customize group: (default emacs) "
878 (or (get symbol
'custom-loads
)
879 (get symbol
'custom-group
)))
881 (when (stringp group
)
882 (if (string-equal "" group
)
884 (setq group
(intern group
))))
885 (or (get group
'custom-group
)
886 (custom-load-symbol group
))
887 (let ((name (format "*Customize Group: %s*"
888 (custom-unlispify-tag-name group
))))
889 (if (get-buffer name
)
890 (let ((window (selected-window)))
892 (select-window window
))
893 (custom-buffer-create-other-window
894 (list (list group
'custom-group
))
896 (concat " for group "
897 (custom-unlispify-tag-name group
))))))
900 (defalias 'customize-variable
'customize-option
)
903 (defun customize-option (symbol)
904 "Customize SYMBOL, which must be a user option variable."
905 (interactive (custom-variable-prompt))
906 ;; If we don't have SYMBOL's real definition loaded,
908 (unless (get symbol
'custom-type
)
909 (let ((loaddefs-file (locate-library "loaddefs.el" t
))
911 ;; See if it is autoloaded from some library.
914 (insert-file-contents loaddefs-file
)
915 (when (re-search-forward (concat "^(defvar " (symbol-name symbol
))
917 (search-backward "\n;;; Generated autoloads from ")
918 (goto-char (match-end 0))
919 (setq file
(buffer-substring (point)
920 (progn (end-of-line) (point)))))))
921 ;; If it is, load that library.
923 (when (string-match "\\.el\\'" file
)
924 (setq file
(substring file
0 (match-beginning 0))))
926 (unless (get symbol
'custom-type
)
927 (error "Variable %s cannot be customized" symbol
))
928 (custom-buffer-create (list (list symbol
'custom-variable
))
929 (format "*Customize Option: %s*"
930 (custom-unlispify-tag-name symbol
))))
932 (defvar customize-changed-options-previous-release
"20.2"
933 "Version for `customize-changed-options' to refer back to by default.")
936 (defun customize-changed-options (since-version)
937 "Customize all user option variables changed in Emacs itself.
938 This includes new user option variables and faces, and new
939 customization groups, as well as older options and faces whose default
940 values have changed since the previous major Emacs release.
942 With argument SINCE-VERSION (a string), customize all user option
943 variables that were added (or their meanings were changed) since that
946 (interactive "sCustomize options changed, since version (default all versions): ")
947 (if (equal since-version
"")
948 (setq since-version nil
)
949 (unless (condition-case nil
950 (numberp (read since-version
))
952 (signal 'wrong-type-argument
(list 'numberp since-version
))))
953 (unless since-version
954 (setq since-version customize-changed-options-previous-release
))
957 (mapatoms (lambda (symbol)
958 (and (or (boundp symbol
)
959 ;; For variables not yet loaded.
960 (get symbol
'standard-value
)
961 ;; For groups the previous test fails, this one
962 ;; could be used to determine if symbol is a
963 ;; group. Is there a better way for this?
964 (get symbol
'group-documentation
))
965 (let ((version (get symbol
'custom-version
)))
967 (or (null since-version
)
968 (customize-version-lessp since-version version
))
969 (if (member version versions
)
971 ;;; Collect all versions that we use.
972 (push version versions
))))
974 ;; We have to set the right thing here,
975 ;; depending if we have a group or a
977 (if (get symbol
'group-documentation
)
978 (cons (list symbol
'custom-group
) found
)
979 (cons (list symbol
'custom-variable
) found
))))))
981 (error "No user option defaults have been changed since Emacs %s"
986 (cdr (assoc (car versions
) custom-versions-load-alist
)))
988 (setq versions
(cdr versions
)))
989 (put 'custom-versions-load-alist
'custom-loads
990 ;; Get all the files that correspond to element from the
991 ;; VERSIONS list. This could use some simplification.
992 (apply 'nconc flist
)))
993 ;; Because we set all the files needed to be loaded as a
994 ;; `custom-loads' property to `custom-versions-load-alist' this
995 ;; call will actually load them.
996 (custom-load-symbol 'custom-versions-load-alist
)
998 (put 'custom-versions-load-alist
'custom-loads nil
)
999 (custom-buffer-create (custom-sort-items found t
'first
)
1000 "*Customize Changed Options*"))))
1002 (defun customize-version-lessp (version1 version2
)
1003 ;; Why are the versions strings, and given that they are, why aren't
1004 ;; they converted to numbers and compared as such here? -- fx
1006 ;; In case someone made a mistake and left out the quotes
1007 ;; in the :version value.
1008 (if (numberp version2
)
1009 (setq version2
(prin1-to-string version2
)))
1010 (let (major1 major2 minor1 minor2
)
1011 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1012 (setq major1
(read (or (match-string 1 version1
)
1014 (setq minor1
(read (or (match-string 3 version1
)
1016 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1017 (setq major2
(read (or (match-string 1 version2
)
1019 (setq minor2
(read (or (match-string 3 version2
)
1021 (or (< major1 major2
)
1022 (and (= major1 major2
)
1023 (< minor1 minor2
)))))
1026 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1029 (defun customize-option-other-window (symbol)
1030 "Customize SYMBOL, which must be a user option variable.
1031 Show the buffer in another window, but don't select it."
1032 (interactive (custom-variable-prompt))
1033 (custom-buffer-create-other-window
1034 (list (list symbol
'custom-variable
))
1035 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol
))))
1038 (defun customize-face (&optional face
)
1039 "Customize SYMBOL, which should be a face name or nil.
1040 If SYMBOL is nil, customize all faces.
1042 Interactively, when point is on text which has a face specified,
1043 suggest to customized that face, if it's customizable."
1045 (list (read-face-name "Customize face" "all faces" t
)))
1046 (if (member face
'(nil ""))
1047 (setq face
(face-list)))
1048 (if (and (listp face
) (null (cdr face
)))
1049 (setq face
(car face
)))
1051 (custom-buffer-create (custom-sort-items
1053 (list s
'custom-face
))
1056 "*Customize Faces*")
1057 (unless (facep face
)
1058 (error "Invalid face %S"))
1059 (custom-buffer-create (list (list face
'custom-face
))
1060 (format "*Customize Face: %s*"
1061 (custom-unlispify-tag-name face
)))))
1064 (defun customize-face-other-window (&optional face
)
1065 "Show customization buffer for face SYMBOL in other window.
1067 Interactively, when point is on text which has a face specified,
1068 suggest to customized that face, if it's customizable."
1070 (list (read-face-name "Customize face" "all faces" t
)))
1071 (if (member face
'(nil ""))
1072 (setq face
(face-list)))
1073 (if (and (listp face
) (null (cdr face
)))
1074 (setq face
(car face
)))
1076 (custom-buffer-create-other-window
1079 (list s
'custom-face
))
1082 "*Customize Faces*")
1083 (unless (facep face
)
1084 (error "Invalid face %S"))
1085 (custom-buffer-create-other-window
1086 (list (list face
'custom-face
))
1087 (format "*Customize Face: %s*"
1088 (custom-unlispify-tag-name face
)))))
1091 (defun customize-customized ()
1092 "Customize all user options set since the last save in this session."
1095 (mapatoms (lambda (symbol)
1096 (and (or (get symbol
'customized-face
)
1097 (get symbol
'customized-face-comment
))
1098 (custom-facep symbol
)
1099 (push (list symbol
'custom-face
) found
))
1100 (and (or (get symbol
'customized-value
)
1101 (get symbol
'customized-variable-comment
))
1103 (push (list symbol
'custom-variable
) found
))))
1105 (error "No customized user options")
1106 (custom-buffer-create (custom-sort-items found t nil
)
1107 "*Customize Customized*"))))
1110 (defun customize-saved ()
1111 "Customize all already saved user options."
1114 (mapatoms (lambda (symbol)
1115 (and (or (get symbol
'saved-face
)
1116 (get symbol
'saved-face-comment
))
1117 (custom-facep symbol
)
1118 (push (list symbol
'custom-face
) found
))
1119 (and (or (get symbol
'saved-value
)
1120 (get symbol
'saved-variable-comment
))
1122 (push (list symbol
'custom-variable
) found
))))
1124 (error "No saved user options")
1125 (custom-buffer-create (custom-sort-items found t nil
)
1126 "*Customize Saved*"))))
1129 (defun customize-apropos (regexp &optional all
)
1130 "Customize all user options matching REGEXP.
1131 If ALL is `options', include only options.
1132 If ALL is `faces', include only faces.
1133 If ALL is `groups', include only groups.
1134 If ALL is t (interactively, with prefix arg), include options which are not
1135 user-settable, as well as faces and groups."
1136 (interactive "sCustomize regexp: \nP")
1138 (mapatoms (lambda (symbol)
1139 (when (string-match regexp
(symbol-name symbol
))
1140 (when (and (not (memq all
'(faces options
)))
1141 (get symbol
'custom-group
))
1142 (push (list symbol
'custom-group
) found
))
1143 (when (and (not (memq all
'(options groups
)))
1144 (custom-facep symbol
))
1145 (push (list symbol
'custom-face
) found
))
1146 (when (and (not (memq all
'(groups faces
)))
1148 (or (get symbol
'saved-value
)
1149 (get symbol
'standard-value
)
1150 (if (memq all
'(nil options
))
1151 (user-variable-p symbol
)
1152 (get symbol
'variable-documentation
))))
1153 (push (list symbol
'custom-variable
) found
)))))
1155 (error "No matches")
1156 (custom-buffer-create (custom-sort-items found t
1157 custom-buffer-order-groups
)
1158 "*Customize Apropos*"))))
1161 (defun customize-apropos-options (regexp &optional arg
)
1162 "Customize all user options matching REGEXP.
1163 With prefix arg, include options which are not user-settable."
1164 (interactive "sCustomize regexp: \nP")
1165 (customize-apropos regexp
(or arg
'options
)))
1168 (defun customize-apropos-faces (regexp)
1169 "Customize all user faces matching REGEXP."
1170 (interactive "sCustomize regexp: \n")
1171 (customize-apropos regexp
'faces
))
1174 (defun customize-apropos-groups (regexp)
1175 "Customize all user groups matching REGEXP."
1176 (interactive "sCustomize regexp: \n")
1177 (customize-apropos regexp
'groups
))
1181 (defcustom custom-buffer-style
'links
1182 "Control the presentation style for customization buffers.
1183 The value should be a symbol, one of:
1185 brackets: groups nest within each other with big horizontal brackets.
1186 links: groups have links to subgroups."
1187 :type
'(radio (const brackets
)
1189 :group
'custom-buffer
)
1191 ;; If we pass BUFFER to `bury-buffer', the buffer isn't removed from
1193 (defun custom-bury-buffer (buffer)
1196 (defcustom custom-buffer-done-function
'custom-bury-buffer
1197 "*Function called to remove a Custom buffer when the user is done with it.
1198 Called with one argument, the buffer to remove."
1199 :type
'(choice (function-item :tag
"Bury buffer" custom-bury-buffer
)
1200 (function-item :tag
"Kill buffer" kill-buffer
)
1201 (function :tag
"Other"))
1203 :group
'custom-buffer
)
1205 (defcustom custom-buffer-indent
3
1206 "Number of spaces to indent nested groups."
1208 :group
'custom-buffer
)
1211 (defun custom-buffer-create (options &optional name description
)
1212 "Create a buffer containing OPTIONS.
1213 Optional NAME is the name of the buffer.
1214 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1215 SYMBOL is a customization option, and WIDGET is a widget for editing
1217 (unless name
(setq name
"*Customization*"))
1218 (kill-buffer (get-buffer-create name
))
1219 (pop-to-buffer (get-buffer-create name
))
1220 (custom-buffer-create-internal options description
))
1223 (defun custom-buffer-create-other-window (options &optional name description
)
1224 "Create a buffer containing OPTIONS.
1225 Optional NAME is the name of the buffer.
1226 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1227 SYMBOL is a customization option, and WIDGET is a widget for editing
1229 (unless name
(setq name
"*Customization*"))
1230 (kill-buffer (get-buffer-create name
))
1231 (let ((window (selected-window))
1233 (special-display-buffer-names nil
)
1234 (special-display-regexps nil
)
1235 (same-window-buffer-names nil
)
1236 (same-window-regexps nil
))
1237 (pop-to-buffer (get-buffer-create name
))
1238 (custom-buffer-create-internal options description
)
1239 (select-window window
)))
1241 (defcustom custom-reset-button-menu nil
1242 "If non-nil, only show a single reset button in customize buffers.
1243 This button will have a menu with all three reset operations."
1245 :group
'custom-buffer
)
1247 (defcustom custom-buffer-verbose-help t
1248 "If non-nil, include explanatory text in the customization buffer."
1250 :group
'custom-buffer
)
1252 (defun Custom-buffer-done (&rest ignore
)
1253 "Remove current buffer by calling `custom-buffer-done-function'."
1255 (funcall custom-buffer-done-function
(current-buffer)))
1257 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1258 '(("unspecified" . unspecified
))))
1259 "If non-nil, indicate active buttons in a `raised-button' style.
1260 Otherwise use brackets."
1263 :group
'custom-buffer
)
1265 (defun custom-buffer-create-internal (options &optional description
)
1266 (message "Creating customization buffer...")
1268 (if custom-buffer-verbose-help
1270 (widget-insert "This is a customization buffer")
1272 (widget-insert description
))
1273 (widget-insert (format ".
1274 %s show active fields; type RET or click mouse-1
1275 on an active field to invoke its action. Editing an option value
1276 changes the text in the buffer; invoke the State button and
1277 choose the Set operation to set the option value.
1278 Invoke " (if custom-raised-buttons
1280 "Square brackets")))
1281 (widget-create 'info-link
1283 :help-echo
"Read the online help."
1284 "(emacs)Easy Customization")
1285 (widget-insert " for more information.\n\n")
1286 (message "Creating customization buttons...")
1287 (widget-insert "Operate on everything in this buffer:\n "))
1288 (widget-insert " "))
1289 (widget-create 'push-button
1290 :tag
"Set for Current Session"
1292 Make your editing in this buffer take effect for this session."
1293 :action
(lambda (widget &optional event
)
1296 (widget-create 'push-button
1297 :tag
"Save for Future Sessions"
1299 Make your editing in this buffer take effect for future Emacs sessions."
1300 :action
(lambda (widget &optional event
)
1302 (if custom-reset-button-menu
1305 (widget-create 'push-button
1307 :help-echo
"Show a menu with reset operations."
1308 :mouse-down-action
(lambda (&rest junk
) t
)
1309 :action
(lambda (widget &optional event
)
1310 (custom-reset event
))))
1311 (widget-insert "\n ")
1312 (widget-create 'push-button
1315 Reset all edited text in this buffer to reflect current values."
1316 :action
'Custom-reset-current
)
1318 (widget-create 'push-button
1319 :tag
"Reset to Saved"
1321 Reset all values in this buffer to their saved settings."
1322 :action
'Custom-reset-saved
)
1324 (widget-create 'push-button
1325 :tag
"Erase Customization"
1327 Un-customize all values in this buffer. They get their standard settings."
1328 :action
'Custom-reset-standard
))
1329 (if (not custom-buffer-verbose-help
)
1332 (widget-create 'info-link
1334 :help-echo
"Read the online help."
1335 "(emacs)Easy Customization")))
1337 (widget-create 'push-button
1340 (lambda (&rest ignore
)
1342 ((eq custom-buffer-done-function
1343 'custom-bury-buffer
)
1345 ((eq custom-buffer-done-function
'kill-buffer
)
1347 (t "Finish with this buffer")))
1348 :action
#'Custom-buffer-done
)
1349 (widget-insert "\n\n")
1350 (message "Creating customization items...")
1351 (buffer-disable-undo)
1352 (setq custom-options
1353 (if (= (length options
) 1)
1354 (mapcar (lambda (entry)
1355 (widget-create (nth 1 entry
)
1356 :documentation-shown t
1357 :custom-state
'unknown
1358 :tag
(custom-unlispify-tag-name
1360 :value
(nth 0 entry
)))
1363 (length (length options
)))
1364 (mapcar (lambda (entry)
1366 (message "Creating customization items ...%2d%%"
1367 (/ (* 100.0 count
) length
))
1368 (widget-create (nth 1 entry
)
1369 :tag
(custom-unlispify-tag-name
1371 :value
(nth 0 entry
))
1372 (setq count
(1+ count
))
1373 (unless (eq (preceding-char) ?
\n)
1374 (widget-insert "\n"))
1375 (widget-insert "\n")))
1377 (unless (eq (preceding-char) ?
\n)
1378 (widget-insert "\n"))
1379 (message "Creating customization items ...done")
1380 (unless (eq custom-buffer-style
'tree
)
1381 (mapc 'custom-magic-reset custom-options
))
1382 (message "Creating customization setup...")
1384 (buffer-enable-undo)
1385 (goto-char (point-min))
1386 (message "Creating customization buffer...done"))
1388 ;;; The Tree Browser.
1391 (defun customize-browse (&optional group
)
1392 "Create a tree browser for the customize hierarchy."
1395 (setq group
'emacs
))
1396 (let ((name "*Customize Browser*"))
1397 (kill-buffer (get-buffer-create name
))
1398 (pop-to-buffer (get-buffer-create name
)))
1401 Square brackets show active fields; type RET or click mouse-1
1402 on an active field to invoke its action.
1403 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1404 (if custom-browse-only-groups
1406 Invoke the [Group] button below to edit that item in another window.\n\n")
1407 (widget-insert "Invoke the ")
1408 (widget-create 'item
1411 :tag-glyph
"folder")
1412 (widget-insert ", ")
1413 (widget-create 'item
1417 (widget-insert ", and ")
1418 (widget-create 'item
1421 :tag-glyph
"option")
1422 (widget-insert " buttons below to edit that
1423 item in another window.\n\n"))
1424 (let ((custom-buffer-style 'tree
))
1425 (widget-create 'custom-group
1427 :custom-state
'unknown
1428 :tag
(custom-unlispify-tag-name group
)
1430 (goto-char (point-min)))
1432 (define-widget 'custom-browse-visibility
'item
1433 "Control visibility of items in the customize tree browser."
1435 :action
'custom-browse-visibility-action
)
1437 (defun custom-browse-visibility-action (widget &rest ignore
)
1438 (let ((custom-buffer-style 'tree
))
1439 (custom-toggle-parent widget
)))
1441 (define-widget 'custom-browse-group-tag
'push-button
1442 "Show parent in other window when activated."
1445 :action
'custom-browse-group-tag-action
)
1447 (defun custom-browse-group-tag-action (widget &rest ignore
)
1448 (let ((parent (widget-get widget
:parent
)))
1449 (customize-group-other-window (widget-value parent
))))
1451 (define-widget 'custom-browse-variable-tag
'push-button
1452 "Show parent in other window when activated."
1455 :action
'custom-browse-variable-tag-action
)
1457 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1458 (let ((parent (widget-get widget
:parent
)))
1459 (customize-variable-other-window (widget-value parent
))))
1461 (define-widget 'custom-browse-face-tag
'push-button
1462 "Show parent in other window when activated."
1465 :action
'custom-browse-face-tag-action
)
1467 (defun custom-browse-face-tag-action (widget &rest ignore
)
1468 (let ((parent (widget-get widget
:parent
)))
1469 (customize-face-other-window (widget-value parent
))))
1471 (defconst custom-browse-alist
'((" " "space")
1477 (defun custom-browse-insert-prefix (prefix)
1478 "Insert PREFIX. On XEmacs convert it to line graphics."
1479 ;; Fixme: do graphics.
1480 (if nil
; (string-match "XEmacs" emacs-version)
1483 (while (not (string-equal prefix
""))
1484 (let ((entry (substring prefix
0 3)))
1485 (setq prefix
(substring prefix
3))
1486 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1487 (name (nth 1 (assoc entry custom-browse-alist
))))
1488 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1489 (overlay-put overlay
'start-open t
)
1490 (overlay-put overlay
'end-open t
)))))
1493 ;;; Modification of Basic Widgets.
1495 ;; We add extra properties to the basic widgets needed here. This is
1496 ;; fine, as long as we are careful to stay within out own namespace.
1498 ;; We want simple widgets to be displayed by default, but complex
1499 ;; widgets to be hidden.
1501 (widget-put (get 'item
'widget-type
) :custom-show t
)
1502 (widget-put (get 'editable-field
'widget-type
)
1503 :custom-show
(lambda (widget value
)
1504 (let ((pp (pp-to-string value
)))
1505 (cond ((string-match "\n" pp
)
1510 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1512 ;;; The `custom-manual' Widget.
1514 (define-widget 'custom-manual
'info-link
1515 "Link to the manual entry for this customization option."
1516 :help-echo
"Read the manual entry for this option."
1519 ;;; The `custom-magic' Widget.
1521 (defgroup custom-magic-faces nil
1522 "Faces used by the magic button."
1523 :group
'custom-faces
1524 :group
'custom-buffer
)
1526 (defface custom-invalid-face
'((((class color
))
1527 (:foreground
"yellow" :background
"red"))
1529 (:weight bold
:slant italic
:underline t
)))
1530 "Face used when the customize item is invalid."
1531 :group
'custom-magic-faces
)
1533 (defface custom-rogue-face
'((((class color
))
1534 (:foreground
"pink" :background
"black"))
1537 "Face used when the customize item is not defined for customization."
1538 :group
'custom-magic-faces
)
1540 (defface custom-modified-face
'((((class color
))
1541 (:foreground
"white" :background
"blue"))
1543 (:slant italic
:bold
)))
1544 "Face used when the customize item has been modified."
1545 :group
'custom-magic-faces
)
1547 (defface custom-set-face
'((((class color
))
1548 (:foreground
"blue" :background
"white"))
1551 "Face used when the customize item has been set."
1552 :group
'custom-magic-faces
)
1554 (defface custom-changed-face
'((((class color
))
1555 (:foreground
"white" :background
"blue"))
1558 "Face used when the customize item has been changed."
1559 :group
'custom-magic-faces
)
1561 (defface custom-saved-face
'((t (:underline t
)))
1562 "Face used when the customize item has been saved."
1563 :group
'custom-magic-faces
)
1565 (defconst custom-magic-alist
'((nil "#" underline
"\
1566 uninitialized, you should not see this.")
1567 (unknown "?" italic
"\
1568 unknown, you should not see this.")
1569 (hidden "-" default
"\
1570 hidden, invoke \"Show\" in the previous line to show." "\
1571 group now hidden, invoke \"Show\", above, to show contents.")
1572 (invalid "x" custom-invalid-face
"\
1573 the value displayed for this %c is invalid and cannot be set.")
1574 (modified "*" custom-modified-face
"\
1575 you have edited the value as text, but you have not set the %c." "\
1576 you have edited something in this group, but not set it.")
1577 (set "+" custom-set-face
"\
1578 you have set this %c, but not saved it for future sessions." "\
1579 something in this group has been set, but not saved.")
1580 (changed ":" custom-changed-face
"\
1581 this %c has been changed outside the customize buffer." "\
1582 something in this group has been changed outside customize.")
1583 (saved "!" custom-saved-face
"\
1584 this %c has been set and saved." "\
1585 something in this group has been set and saved.")
1586 (rogue "@" custom-rogue-face
"\
1587 this %c has not been changed with customize." "\
1588 something in this group is not prepared for customization.")
1589 (standard " " nil
"\
1590 this %c is unchanged from its standard setting." "\
1591 visible group members are all at standard settings."))
1592 "Alist of customize option states.
1593 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1595 STATE is one of the following symbols:
1598 For internal use, should never occur.
1600 For internal use, should never occur.
1602 This item is not being displayed.
1604 This item is modified, but has an invalid form.
1606 This item is modified, and has a valid form.
1608 This item has been set but not saved.
1610 The current value of this item has been changed temporarily.
1612 This item is marked for saving.
1614 This item has no customization information.
1616 This item is unchanged from the standard setting.
1618 MAGIC is a string used to present that state.
1620 FACE is a face used to present the state.
1622 ITEM-DESC is a string describing the state for options.
1624 GROUP-DESC is a string describing the state for groups. If this is
1625 left out, ITEM-DESC will be used.
1627 The string %c in either description will be replaced with the
1628 category of the item. These are `group'. `option', and `face'.
1630 The list should be sorted most significant first.")
1632 (defcustom custom-magic-show
'long
1633 "If non-nil, show textual description of the state.
1634 If `long', show a full-line description, not just one word."
1635 :type
'(choice (const :tag
"no" nil
)
1637 (other :tag
"short" short
))
1638 :group
'custom-buffer
)
1640 (defcustom custom-magic-show-hidden
'(option face
)
1641 "Control whether the State button is shown for hidden items.
1642 The value should be a list with the custom categories where the State
1643 button should be visible. Possible categories are `group', `option',
1645 :type
'(set (const group
) (const option
) (const face
))
1646 :group
'custom-buffer
)
1648 (defcustom custom-magic-show-button nil
1649 "Show a \"magic\" button indicating the state of each customization option."
1651 :group
'custom-buffer
)
1653 (define-widget 'custom-magic
'default
1654 "Show and manipulate state for a customization option."
1656 :action
'widget-parent-action
1659 :value-create
'custom-magic-value-create
1660 :value-delete
'widget-children-value-delete
)
1662 (defun widget-magic-mouse-down-action (widget &optional event
)
1663 ;; Non-nil unless hidden.
1664 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1668 (defun custom-magic-value-create (widget)
1669 "Create compact status report for WIDGET."
1670 (let* ((parent (widget-get widget
:parent
))
1671 (state (widget-get parent
:custom-state
))
1672 (hidden (eq state
'hidden
))
1673 (entry (assq state custom-magic-alist
))
1674 (magic (nth 1 entry
))
1675 (face (nth 2 entry
))
1676 (category (widget-get parent
:custom-category
))
1677 (text (or (and (eq category
'group
)
1680 (form (widget-get parent
:custom-form
))
1682 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1683 (setq text
(concat (match-string 1 text
)
1684 (symbol-name category
)
1685 (match-string 2 text
))))
1686 (when (and custom-magic-show
1688 (memq category custom-magic-show-hidden
)))
1690 (when (and (eq category
'group
)
1691 (not (and (eq custom-buffer-style
'links
)
1692 (> (widget-get parent
:custom-level
) 1))))
1693 (insert-char ?\
(* custom-buffer-indent
1694 (widget-get parent
:custom-level
))))
1695 (push (widget-create-child-and-convert
1697 :help-echo
"Change the state of this item."
1698 :format
(if hidden
"%t" "%[%t%]")
1699 :button-prefix
'widget-push-button-prefix
1700 :button-suffix
'widget-push-button-suffix
1701 :mouse-down-action
'widget-magic-mouse-down-action
1705 (let ((start (point)))
1706 (if (eq custom-magic-show
'long
)
1708 (insert (symbol-name state
)))
1709 (cond ((eq form
'lisp
)
1711 ((eq form
'mismatch
)
1712 (insert " (mismatch)")))
1713 (put-text-property start
(point) 'face
'custom-state-face
))
1715 (when (and (eq category
'group
)
1716 (not (and (eq custom-buffer-style
'links
)
1717 (> (widget-get parent
:custom-level
) 1))))
1718 (insert-char ?\
(* custom-buffer-indent
1719 (widget-get parent
:custom-level
))))
1720 (when custom-magic-show-button
1721 (when custom-magic-show
1722 (let ((indent (widget-get parent
:indent
)))
1724 (insert-char ? indent
))))
1725 (push (widget-create-child-and-convert
1727 :mouse-down-action
'widget-magic-mouse-down-action
1731 :help-echo
"Change the state."
1732 :format
(if hidden
"%t" "%[%t%]")
1733 :tag
(if (memq form
'(lisp mismatch
))
1734 (concat "(" magic
")")
1735 (concat "[" magic
"]")))
1738 (widget-put widget
:children children
)))
1740 (defun custom-magic-reset (widget)
1741 "Redraw the :custom-magic property of WIDGET."
1742 (let ((magic (widget-get widget
:custom-magic
)))
1743 (widget-value-set magic
(widget-value magic
))))
1745 ;;; The `custom' Widget.
1747 (defface custom-button-face
1748 '((((type x w32 mac
) (class color
)) ; Like default modeline
1749 (:box
(:line-width
2 :style released-button
)
1750 :background
"lightgrey" :foreground
"black"))
1753 "Face used for buttons in customization buffers."
1755 :group
'custom-faces
)
1757 (defface custom-button-pressed-face
1758 '((((type x w32 mac
) (class color
))
1759 (:box
(:line-width
2 :style pressed-button
)
1760 :background
"lightgrey" :foreground
"black"))
1762 (:inverse-video t
)))
1763 "Face used for buttons in customization buffers."
1765 :group
'custom-faces
)
1767 (defface custom-documentation-face nil
1768 "Face used for documentation strings in customization buffers."
1769 :group
'custom-faces
)
1771 (defface custom-state-face
'((((class color
)
1773 (:foreground
"lime green"))
1776 (:foreground
"dark green"))
1778 "Face used for State descriptions in the customize buffer."
1779 :group
'custom-faces
)
1781 (define-widget 'custom
'default
1782 "Customize a user option."
1784 :convert-widget
'custom-convert-widget
1785 :notify
'custom-notify
1788 :custom-state
'hidden
1789 :documentation-property
'widget-subclass-responsibility
1790 :value-create
'widget-subclass-responsibility
1791 :value-delete
'widget-children-value-delete
1792 :value-get
'widget-value-value-get
1793 :validate
'widget-children-validate
1794 :match
(lambda (widget value
) (symbolp value
)))
1796 (defun custom-convert-widget (widget)
1797 "Initialize :value and :tag from :args in WIDGET."
1798 (let ((args (widget-get widget
:args
)))
1800 (widget-put widget
:value
(widget-apply widget
1801 :value-to-internal
(car args
)))
1802 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1803 (widget-put widget
:args nil
)))
1806 (defun custom-notify (widget &rest args
)
1807 "Keep track of changes."
1808 (let ((state (widget-get widget
:custom-state
)))
1809 (unless (eq state
'modified
)
1810 (unless (memq state
'(nil unknown hidden
))
1811 (widget-put widget
:custom-state
'modified
))
1812 (custom-magic-reset widget
)
1813 (apply 'widget-default-notify widget args
))))
1815 (defun custom-redraw (widget)
1816 "Redraw WIDGET with current settings."
1817 (let ((line (count-lines (point-min) (point)))
1818 (column (current-column))
1820 (from (marker-position (widget-get widget
:from
)))
1821 (to (marker-position (widget-get widget
:to
))))
1823 (widget-value-set widget
(widget-value widget
))
1824 (custom-redraw-magic widget
))
1825 (when (and (>= pos from
) (<= pos to
))
1830 (goto-line (1+ line
)))
1831 (move-to-column column
))
1834 (defun custom-redraw-magic (widget)
1835 "Redraw WIDGET state with current settings."
1837 (let ((magic (widget-get widget
:custom-magic
)))
1839 (widget-value-set magic
(widget-value magic
))
1840 (when (setq widget
(widget-get widget
:group
))
1841 (custom-group-state-update widget
)))
1843 (setq widget nil
)))))
1846 (defun custom-show (widget value
)
1847 "Non-nil if WIDGET should be shown with VALUE by default."
1848 (let ((show (widget-get widget
:custom-show
)))
1854 (funcall show widget value
)))))
1856 (defun custom-load-widget (widget)
1857 "Load all dependencies for WIDGET."
1858 (custom-load-symbol (widget-value widget
)))
1860 (defun custom-unloaded-symbol-p (symbol)
1861 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1863 (loads (get symbol
'custom-loads
))
1866 (setq load
(car loads
)
1868 (cond ((symbolp load
)
1869 (unless (featurep load
)
1871 ((assoc load load-history
))
1872 ((assoc (locate-library load
) load-history
)
1878 (defun custom-unloaded-widget-p (widget)
1879 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1880 (custom-unloaded-symbol-p (widget-value widget
)))
1882 (defun custom-toggle-hide (widget)
1883 "Toggle visibility of WIDGET."
1884 (custom-load-widget widget
)
1885 (let ((state (widget-get widget
:custom-state
)))
1886 (cond ((memq state
'(invalid modified
))
1887 (error "There are unset changes"))
1889 (widget-put widget
:custom-state
'unknown
))
1891 (widget-put widget
:documentation-shown nil
)
1892 (widget-put widget
:custom-state
'hidden
)))
1893 (custom-redraw widget
)
1896 (defun custom-toggle-parent (widget &rest ignore
)
1897 "Toggle visibility of parent of WIDGET."
1898 (custom-toggle-hide (widget-get widget
:parent
)))
1900 (defun custom-add-see-also (widget &optional prefix
)
1901 "Add `See also ...' to WIDGET if there are any links.
1902 Insert PREFIX first if non-nil."
1903 (let* ((symbol (widget-get widget
:value
))
1904 (links (get symbol
'custom-links
))
1905 (many (> (length links
) 2))
1906 (buttons (widget-get widget
:buttons
))
1907 (indent (widget-get widget
:indent
)))
1910 (insert-char ?\ indent
))
1913 (insert "See also ")
1915 (push (widget-create-child-and-convert widget
(car links
))
1917 (setq links
(cdr links
))
1926 (widget-put widget
:buttons buttons
))))
1928 (defun custom-add-parent-links (widget &optional initial-string
)
1929 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1930 The value if non-nil if any parents were found.
1931 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1932 (let ((name (widget-value widget
))
1933 (type (widget-type widget
))
1934 (buttons (widget-get widget
:buttons
))
1937 (insert (or initial-string
"Parent groups:"))
1938 (mapatoms (lambda (symbol)
1939 (let ((entry (assq name
(get symbol
'custom-group
))))
1940 (when (eq (nth 1 entry
) type
)
1942 (push (widget-create-child-and-convert
1943 widget
'custom-group-link
1944 :tag
(custom-unlispify-tag-name symbol
)
1948 (widget-put widget
:buttons buttons
)
1951 (delete-region start
(point)))
1954 ;;; The `custom-comment' Widget.
1956 ;; like the editable field
1957 (defface custom-comment-face
'((((class grayscale color
)
1959 (:background
"gray85"))
1960 (((class grayscale color
)
1962 (:background
"dim gray"))
1965 "Face used for comments on variables or faces"
1967 :group
'custom-faces
)
1969 ;; like font-lock-comment-face
1970 (defface custom-comment-tag-face
1971 '((((class color
) (background dark
)) (:foreground
"gray80"))
1972 (((class color
) (background light
)) (:foreground
"blue4"))
1973 (((class grayscale
) (background light
))
1974 (:foreground
"DimGray" :weight bold
:slant italic
))
1975 (((class grayscale
) (background dark
))
1976 (:foreground
"LightGray" :weight bold
:slant italic
))
1978 "Face used for variables or faces comment tags"
1979 :group
'custom-faces
)
1981 (define-widget 'custom-comment
'string
1984 :help-echo
"Edit a comment here."
1985 :sample-face
'custom-comment-tag-face
1986 :value-face
'custom-comment-face
1988 :create
'custom-comment-create
)
1990 (defun custom-comment-create (widget)
1991 (let* ((null-comment (equal "" (widget-value widget
))))
1992 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
1994 (widget-default-create widget
)
1995 ;; `widget-default-delete' expects markers in these slots --
1996 ;; maybe it shouldn't.
1997 (widget-put widget
:from
(point-marker))
1998 (widget-put widget
:to
(point-marker)))))
2000 (defun custom-comment-hide (widget)
2001 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2003 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2004 ;; the global custom one
2005 (defun custom-comment-show (widget)
2006 (widget-put widget
:comment-shown t
)
2007 (custom-redraw widget
)
2010 (defun custom-comment-invisible-p (widget)
2011 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2013 (not (widget-get widget
:comment-shown
)))))
2015 ;;; The `custom-variable' Widget.
2017 ;; When this was underlined blue, users confused it with a
2018 ;; Mosaic-style hyperlink...
2019 (defface custom-variable-tag-face
2022 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2025 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2027 "Face used for unpushable variable tags."
2028 :group
'custom-faces
)
2030 (defface custom-variable-button-face
'((t (:underline t
:weight bold
)))
2031 "Face used for pushable variable tags."
2032 :group
'custom-faces
)
2034 (defcustom custom-variable-default-form
'edit
2035 "Default form of displaying variable values."
2036 :type
'(choice (const edit
)
2038 :group
'custom-buffer
2041 (define-widget 'custom-variable
'custom
2042 "Customize variable."
2044 :help-echo
"Set or reset this variable."
2045 :documentation-property
'variable-documentation
2046 :custom-category
'option
2048 :custom-menu
'custom-variable-menu-create
2049 :custom-form nil
; defaults to value of `custom-variable-default-form'
2050 :value-create
'custom-variable-value-create
2051 :action
'custom-variable-action
2052 :custom-set
'custom-variable-set
2053 :custom-save
'custom-variable-save
2054 :custom-reset-current
'custom-redraw
2055 :custom-reset-saved
'custom-variable-reset-saved
2056 :custom-reset-standard
'custom-variable-reset-standard
2057 :custom-standard-value
'custom-variable-standard-value
)
2059 (defun custom-variable-type (symbol)
2060 "Return a widget suitable for editing the value of SYMBOL.
2061 If SYMBOL has a `custom-type' property, use that.
2062 Otherwise, look up symbol in `custom-guess-type-alist'."
2063 (let* ((type (or (get symbol
'custom-type
)
2064 (and (not (get symbol
'standard-value
))
2065 (custom-guess-type symbol
))
2067 (options (get symbol
'custom-options
))
2068 (tmp (if (listp type
)
2069 (copy-sequence type
)
2072 (widget-put tmp
:options options
))
2075 (defun custom-variable-value-create (widget)
2076 "Here is where you edit the variable's value."
2077 (custom-load-widget widget
)
2078 (unless (widget-get widget
:custom-form
)
2079 (widget-put widget
:custom-form custom-variable-default-form
))
2080 (let* ((buttons (widget-get widget
:buttons
))
2081 (children (widget-get widget
:children
))
2082 (form (widget-get widget
:custom-form
))
2083 (state (widget-get widget
:custom-state
))
2084 (symbol (widget-get widget
:value
))
2085 (tag (widget-get widget
:tag
))
2086 (type (custom-variable-type symbol
))
2087 (conv (widget-convert type
))
2088 (get (or (get symbol
'custom-get
) 'default-value
))
2089 (prefix (widget-get widget
:custom-prefix
))
2090 (last (widget-get widget
:custom-last
))
2091 (value (if (default-boundp symbol
)
2092 (funcall get symbol
)
2093 (widget-get conv
:value
))))
2094 ;; If the widget is new, the child determines whether it is hidden.
2096 ((custom-show type value
)
2097 (setq state
'unknown
))
2099 (setq state
'hidden
)))
2100 ;; If we don't know the state, see if we need to edit it in lisp form.
2101 (when (eq state
'unknown
)
2102 (unless (widget-apply conv
:match value
)
2103 ;; (widget-apply (widget-convert type) :match value)
2104 (setq form
'mismatch
)))
2105 ;; Now we can create the child widget.
2106 (cond ((eq custom-buffer-style
'tree
)
2107 (insert prefix
(if last
" `--- " " |--- "))
2108 (push (widget-create-child-and-convert
2109 widget
'custom-browse-variable-tag
)
2111 (insert " " tag
"\n")
2112 (widget-put widget
:buttons buttons
))
2114 ;; Indicate hidden value.
2115 (push (widget-create-child-and-convert
2118 :sample-face
'custom-variable-tag-face
2122 (push (widget-create-child-and-convert
2124 :help-echo
"Show the value of this option."
2126 :action
'custom-toggle-parent
2129 ((memq form
'(lisp mismatch
))
2130 ;; In lisp mode edit the saved value when possible.
2131 (let* ((value (cond ((get symbol
'saved-value
)
2132 (car (get symbol
'saved-value
)))
2133 ((get symbol
'standard-value
)
2134 (car (get symbol
'standard-value
)))
2135 ((default-boundp symbol
)
2136 (custom-quote (funcall get symbol
)))
2138 (custom-quote (widget-get conv
:value
))))))
2139 (insert (symbol-name symbol
) ": ")
2140 (push (widget-create-child-and-convert
2142 :help-echo
"Hide the value of this option."
2145 :action
'custom-toggle-parent
2149 (push (widget-create-child-and-convert
2151 :button-face
'custom-variable-button-face
2153 :tag
(symbol-name symbol
)
2159 (let* ((format (widget-get type
:format
))
2160 tag-format value-format
)
2161 (unless (string-match ":" format
)
2162 (error "Bad format"))
2163 (setq tag-format
(substring format
0 (match-end 0)))
2164 (setq value-format
(substring format
(match-end 0)))
2165 (push (widget-create-child-and-convert
2168 :action
'custom-tag-action
2169 :help-echo
"Change value of this option."
2170 :mouse-down-action
'custom-tag-mouse-down-action
2171 :button-face
'custom-variable-button-face
2172 :sample-face
'custom-variable-tag-face
2176 (push (widget-create-child-and-convert
2178 :help-echo
"Hide the value of this option."
2181 :action
'custom-toggle-parent
2184 (push (widget-create-child-and-convert
2186 :format value-format
2189 (unless (eq custom-buffer-style
'tree
)
2190 (unless (eq (preceding-char) ?
\n)
2191 (widget-insert "\n"))
2192 ;; Create the magic button.
2193 (let ((magic (widget-create-child-and-convert
2194 widget
'custom-magic nil
)))
2195 (widget-put widget
:custom-magic magic
)
2196 (push magic buttons
))
2197 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2198 ;; before the call to `widget-default-format-handler'. Otherwise, I
2199 ;; loose my current `buttons'. This function shouldn't be called like
2200 ;; this anyway. The doc string widget should be added like the others.
2202 (widget-put widget
:buttons buttons
)
2204 ;; Insert documentation.
2205 (widget-default-format-handler widget ?h
)
2207 ;; The comment field
2208 (unless (eq state
'hidden
)
2209 (let* ((comment (get symbol
'variable-comment
))
2211 (widget-create-child-and-convert
2212 widget
'custom-comment
2214 :value
(or comment
""))))
2215 (widget-put widget
:comment-widget comment-widget
)
2216 ;; Don't push it !!! Custom assumes that the first child is the
2218 (setq children
(append children
(list comment-widget
)))))
2219 ;; Update the rest of the properties properties.
2220 (widget-put widget
:custom-form form
)
2221 (widget-put widget
:children children
)
2222 ;; Now update the state.
2223 (if (eq state
'hidden
)
2224 (widget-put widget
:custom-state state
)
2225 (custom-variable-state-set widget
))
2227 (unless (eq state
'hidden
)
2228 (when (eq (widget-get widget
:custom-level
) 1)
2229 (custom-add-parent-links widget
))
2230 (custom-add-see-also widget
)))))
2232 (defun custom-tag-action (widget &rest args
)
2233 "Pass :action to first child of WIDGET's parent."
2234 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2237 (defun custom-tag-mouse-down-action (widget &rest args
)
2238 "Pass :mouse-down-action to first child of WIDGET's parent."
2239 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2240 :mouse-down-action args
))
2242 (defun custom-variable-state-set (widget)
2243 "Set the state of WIDGET."
2244 (let* ((symbol (widget-value widget
))
2245 (get (or (get symbol
'custom-get
) 'default-value
))
2246 (value (if (default-boundp symbol
)
2247 (funcall get symbol
)
2248 (widget-get widget
:value
)))
2249 (comment (get symbol
'variable-comment
))
2252 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2254 (get symbol
'customized-variable-comment
))
2256 (if (condition-case nil
2257 (and (equal value
(eval (car tmp
)))
2258 (equal comment temp
))
2262 ((progn (setq tmp
(get symbol
'saved-value
))
2263 (setq temp
(get symbol
'saved-variable-comment
))
2265 (if (condition-case nil
2266 (and (equal value
(eval (car tmp
)))
2267 (equal comment temp
))
2271 ((setq tmp
(get symbol
'standard-value
))
2272 (if (condition-case nil
2273 (and (equal value
(eval (car tmp
)))
2274 (equal comment nil
))
2279 (widget-put widget
:custom-state state
)))
2281 (defun custom-variable-standard-value (widget)
2282 (get (widget-value widget
) 'standard-value
))
2284 (defvar custom-variable-menu
2285 '(("Set for Current Session" custom-variable-set
2287 (eq (widget-get widget
:custom-state
) 'modified
)))
2288 ("Save for Future Sessions" custom-variable-save
2290 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
2291 ("Reset to Current" custom-redraw
2293 (and (default-boundp (widget-value widget
))
2294 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2295 ("Reset to Saved" custom-variable-reset-saved
2297 (and (or (get (widget-value widget
) 'saved-value
)
2298 (get (widget-value widget
) 'saved-variable-comment
))
2299 (memq (widget-get widget
:custom-state
)
2300 '(modified set changed rogue
)))))
2301 ("Erase Customization" custom-variable-reset-standard
2303 (and (get (widget-value widget
) 'standard-value
)
2304 (memq (widget-get widget
:custom-state
)
2305 '(modified set changed saved rogue
)))))
2306 ("---" ignore ignore
)
2307 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2308 ("---" ignore ignore
)
2309 ("Don't show as Lisp expression" custom-variable-edit
2311 (eq (widget-get widget
:custom-form
) 'lisp
)))
2312 ("Show initial Lisp expression" custom-variable-edit-lisp
2314 (eq (widget-get widget
:custom-form
) 'edit
))))
2315 "Alist of actions for the `custom-variable' widget.
2316 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2317 the menu entry, ACTION is the function to call on the widget when the
2318 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2319 widget as an argument, and returns non-nil if ACTION is valid on that
2320 widget. If FILTER is nil, ACTION is always valid.")
2322 (defun custom-variable-action (widget &optional event
)
2323 "Show the menu for `custom-variable' WIDGET.
2324 Optional EVENT is the location for the menu."
2325 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2326 (custom-toggle-hide widget
)
2327 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2328 (custom-variable-state-set widget
))
2329 (custom-redraw-magic widget
)
2330 (let* ((completion-ignore-case t
)
2331 (answer (widget-choose (concat "Operation on "
2332 (custom-unlispify-tag-name
2333 (widget-get widget
:value
)))
2334 (custom-menu-filter custom-variable-menu
2338 (funcall answer widget
)))))
2340 (defun custom-variable-edit (widget)
2341 "Edit value of WIDGET."
2342 (widget-put widget
:custom-state
'unknown
)
2343 (widget-put widget
:custom-form
'edit
)
2344 (custom-redraw widget
))
2346 (defun custom-variable-edit-lisp (widget)
2347 "Edit the Lisp representation of the value of WIDGET."
2348 (widget-put widget
:custom-state
'unknown
)
2349 (widget-put widget
:custom-form
'lisp
)
2350 (custom-redraw widget
))
2352 (defun custom-variable-set (widget)
2353 "Set the current value for the variable being edited by WIDGET."
2354 (let* ((form (widget-get widget
:custom-form
))
2355 (state (widget-get widget
:custom-state
))
2356 (child (car (widget-get widget
:children
)))
2357 (symbol (widget-value widget
))
2358 (set (or (get symbol
'custom-set
) 'set-default
))
2359 (comment-widget (widget-get widget
:comment-widget
))
2360 (comment (widget-value comment-widget
))
2362 (cond ((eq state
'hidden
)
2363 (error "Cannot set hidden variable"))
2364 ((setq val
(widget-apply child
:validate
))
2365 (goto-char (widget-get val
:from
))
2366 (error "%s" (widget-get val
:error
)))
2367 ((memq form
'(lisp mismatch
))
2368 (when (equal comment
"")
2370 ;; Make the comment invisible by hand if it's empty
2371 (custom-comment-hide comment-widget
))
2372 (funcall set symbol
(eval (setq val
(widget-value child
))))
2373 (put symbol
'customized-value
(list val
))
2374 (put symbol
'variable-comment comment
)
2375 (put symbol
'customized-variable-comment comment
))
2377 (when (equal comment
"")
2379 ;; Make the comment invisible by hand if it's empty
2380 (custom-comment-hide comment-widget
))
2381 (funcall set symbol
(setq val
(widget-value child
)))
2382 (put symbol
'customized-value
(list (custom-quote val
)))
2383 (put symbol
'variable-comment comment
)
2384 (put symbol
'customized-variable-comment comment
)))
2385 (custom-variable-state-set widget
)
2386 (custom-redraw-magic widget
)))
2388 (defun custom-variable-save (widget)
2389 "Set and save the value for the variable being edited by WIDGET."
2390 (let* ((form (widget-get widget
:custom-form
))
2391 (state (widget-get widget
:custom-state
))
2392 (child (car (widget-get widget
:children
)))
2393 (symbol (widget-value widget
))
2394 (set (or (get symbol
'custom-set
) 'set-default
))
2395 (comment-widget (widget-get widget
:comment-widget
))
2396 (comment (widget-value comment-widget
))
2398 (cond ((eq state
'hidden
)
2399 (error "Cannot set hidden variable"))
2400 ((setq val
(widget-apply child
:validate
))
2401 (goto-char (widget-get val
:from
))
2402 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2403 ((memq form
'(lisp mismatch
))
2404 (when (equal comment
"")
2406 ;; Make the comment invisible by hand if it's empty
2407 (custom-comment-hide comment-widget
))
2408 (put symbol
'saved-value
(list (widget-value child
)))
2409 (funcall set symbol
(eval (widget-value child
)))
2410 (put symbol
'variable-comment comment
)
2411 (put symbol
'saved-variable-comment comment
))
2413 (when (equal comment
"")
2415 ;; Make the comment invisible by hand if it's empty
2416 (custom-comment-hide comment-widget
))
2417 (put symbol
'saved-value
2418 (list (custom-quote (widget-value child
))))
2419 (funcall set symbol
(widget-value child
))
2420 (put symbol
'variable-comment comment
)
2421 (put symbol
'saved-variable-comment comment
)))
2422 (put symbol
'customized-value nil
)
2423 (put symbol
'customized-variable-comment nil
)
2425 (custom-variable-state-set widget
)
2426 (custom-redraw-magic widget
)))
2428 (defun custom-variable-reset-saved (widget)
2429 "Restore the saved value for the variable being edited by WIDGET."
2430 (let* ((symbol (widget-value widget
))
2431 (set (or (get symbol
'custom-set
) 'set-default
))
2432 (value (get symbol
'saved-value
))
2433 (comment (get symbol
'saved-variable-comment
)))
2434 (cond ((or value comment
)
2435 (put symbol
'variable-comment comment
)
2437 (funcall set symbol
(eval (car value
)))
2440 (error "No saved value for %s" symbol
)))
2441 (put symbol
'customized-value nil
)
2442 (put symbol
'customized-variable-comment nil
)
2443 (widget-put widget
:custom-state
'unknown
)
2444 ;; This call will possibly make the comment invisible
2445 (custom-redraw widget
)))
2447 (defun custom-variable-reset-standard (widget)
2448 "Restore the standard setting for the variable being edited by WIDGET.
2449 This operation eliminates any saved setting for the variable,
2450 restoring it to the state of a variable that has never been customized."
2451 (let* ((symbol (widget-value widget
))
2452 (set (or (get symbol
'custom-set
) 'set-default
)))
2453 (if (get symbol
'standard-value
)
2454 (funcall set symbol
(eval (car (get symbol
'standard-value
))))
2455 (error "No standard setting known for %S" symbol
))
2456 (put symbol
'variable-comment nil
)
2457 (put symbol
'customized-value nil
)
2458 (put symbol
'customized-variable-comment nil
)
2459 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2460 (put symbol
'saved-value nil
)
2461 (put symbol
'saved-variable-comment nil
)
2463 (widget-put widget
:custom-state
'unknown
)
2464 ;; This call will possibly make the comment invisible
2465 (custom-redraw widget
)))
2467 ;;; The `custom-face-edit' Widget.
2469 (define-widget 'custom-face-edit
'checklist
2470 "Edit face attributes."
2474 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2475 :value-to-internal
'custom-face-edit-fix-value
2476 :match
(lambda (widget value
)
2477 (widget-checklist-match widget
2478 (custom-face-edit-fix-value widget value
)))
2479 :convert-widget
'custom-face-edit-convert-widget
2480 :args
(mapcar (lambda (att)
2483 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2484 (list 'const
:format
"" :value
(nth 0 att
))
2486 custom-face-attributes
))
2488 (defun custom-face-edit-fix-value (widget value
)
2489 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form."
2493 (let ((key (car value
))
2494 (val (car (cdr value
))))
2495 (cond ((eq key
:italic
)
2496 (push :slant result
)
2497 (push (if val
'italic
'normal
) result
))
2499 (push :weight result
)
2500 (push (if val
'bold
'normal
) result
))
2503 (push val result
))))
2504 (setq value
(cdr (cdr value
))))
2505 (setq result
(nreverse result
))
2509 (defun custom-face-edit-convert-widget (widget)
2510 "Convert :args as widget types in WIDGET."
2513 :args
(mapcar (lambda (arg)
2515 :deactivate
'custom-face-edit-deactivate
2516 :activate
'custom-face-edit-activate
2517 :delete
'custom-face-edit-delete
))
2518 (widget-get widget
:args
)))
2521 (defun custom-face-edit-deactivate (widget)
2522 "Make face widget WIDGET inactive for user modifications."
2523 (unless (widget-get widget
:inactive
)
2524 (let ((tag (custom-face-edit-attribute-tag widget
))
2525 (from (copy-marker (widget-get widget
:from
)))
2526 (to (widget-get widget
:to
))
2527 (value (widget-value widget
))
2528 (inhibit-read-only t
)
2529 (inhibit-modification-hooks t
))
2532 (widget-default-delete widget
)
2533 (insert tag
": *\n")
2534 (widget-put widget
:inactive
2535 (cons value
(cons from
(- (point) from
))))))))
2537 (defun custom-face-edit-activate (widget)
2538 "Make face widget WIDGET inactive for user modifications."
2539 (let ((inactive (widget-get widget
:inactive
))
2540 (inhibit-read-only t
)
2541 (inhibit-modification-hooks t
))
2542 (when (consp inactive
)
2544 (goto-char (car (cdr inactive
)))
2545 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
2546 (widget-put widget
:inactive nil
)
2547 (widget-apply widget
:create
)
2548 (widget-value-set widget
(car inactive
))
2551 (defun custom-face-edit-delete (widget)
2552 "Remove widget from the buffer."
2553 (let ((inactive (widget-get widget
:inactive
))
2554 (inhibit-read-only t
)
2555 (inhibit-modification-hooks t
))
2557 ;; Widget is alive, we don't have to do anything special
2558 (widget-default-delete widget
)
2559 ;; WIDGET is already deleted because we did so to inactivate it;
2560 ;; now just get rid of the label we put in its place.
2561 (delete-region (car (cdr inactive
))
2562 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
2563 (widget-put widget
:inactive nil
))))
2566 (defun custom-face-edit-attribute-tag (widget)
2567 "Returns the first :tag property in WIDGET or one of its children."
2568 (let ((tag (widget-get widget
:tag
)))
2569 (or (and (not (equal tag
"")) tag
)
2570 (let ((children (widget-get widget
:children
)))
2571 (while (and (null tag
) children
)
2572 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
2575 ;;; The `custom-display' Widget.
2577 (define-widget 'custom-display
'menu-choice
2578 "Select a display type."
2581 :help-echo
"Specify frames where the face attributes should be used."
2582 :args
'((const :tag
"all" t
)
2586 :args
((group :sibling-args
(:help-echo
"\
2587 Only match the specified window systems.")
2588 (const :format
"Type: "
2590 (checklist :inline t
2593 :sibling-args
(:help-echo
"\
2594 The X11 Window System.")
2596 (const :format
"PM "
2597 :sibling-args
(:help-echo
"\
2598 OS/2 Presentation Manager.")
2600 (const :format
"W32 "
2601 :sibling-args
(:help-echo
"\
2604 (const :format
"DOS "
2605 :sibling-args
(:help-echo
"\
2608 (const :format
"TTY%n"
2609 :sibling-args
(:help-echo
"\
2610 Plain text terminals.")
2612 (group :sibling-args
(:help-echo
"\
2613 Only match the frames with the specified color support.")
2614 (const :format
"Class: "
2616 (checklist :inline t
2618 (const :format
"Color "
2619 :sibling-args
(:help-echo
"\
2620 Match color frames.")
2622 (const :format
"Grayscale "
2623 :sibling-args
(:help-echo
"\
2624 Match grayscale frames.")
2626 (const :format
"Monochrome%n"
2627 :sibling-args
(:help-echo
"\
2628 Match frames with no color support.")
2630 (group :sibling-args
(:help-echo
"\
2631 Only match frames with the specified intensity.")
2633 Background brightness: "
2635 (checklist :inline t
2637 (const :format
"Light "
2638 :sibling-args
(:help-echo
"\
2639 Match frames with light backgrounds.")
2641 (const :format
"Dark\n"
2642 :sibling-args
(:help-echo
"\
2643 Match frames with dark backgrounds.")
2645 (group :sibling-args
(:help-echo
"\
2646 Only match frames that support the specified face attributes.")
2647 (const :format
"Supports attributes:" supports
)
2648 (custom-face-edit :inline t
:format
"%n%v"))))))
2650 ;;; The `custom-face' Widget.
2652 (defface custom-face-tag-face
2653 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
2654 "Face used for face tags."
2655 :group
'custom-faces
)
2657 (defcustom custom-face-default-form
'selected
2658 "Default form of displaying face definition."
2659 :type
'(choice (const all
)
2662 :group
'custom-buffer
2665 (define-widget 'custom-face
'custom
2667 :sample-face
'custom-face-tag-face
2668 :help-echo
"Set or reset this face."
2669 :documentation-property
#'face-doc-string
2670 :value-create
'custom-face-value-create
2671 :action
'custom-face-action
2672 :custom-category
'face
2673 :custom-form nil
; defaults to value of `custom-face-default-form'
2674 :custom-set
'custom-face-set
2675 :custom-save
'custom-face-save
2676 :custom-reset-current
'custom-redraw
2677 :custom-reset-saved
'custom-face-reset-saved
2678 :custom-reset-standard
'custom-face-reset-standard
2679 :custom-standard-value
'custom-face-standard-value
2680 :custom-menu
'custom-face-menu-create
)
2682 (define-widget 'custom-face-all
'editable-list
2683 "An editable list of display specifications and attributes."
2684 :entry-format
"%i %d %v"
2685 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2686 :append-button-args
'(:help-echo
"Append new display specification here.")
2687 :delete-button-args
'(:help-echo
"Delete this display specification.")
2688 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2690 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2691 "Converted version of the `custom-face-all' widget.")
2693 (define-widget 'custom-display-unselected
'item
2694 "A display specification that doesn't match the selected display."
2695 :match
'custom-display-unselected-match
)
2697 (defun custom-display-unselected-match (widget value
)
2698 "Non-nil if VALUE is an unselected display specification."
2699 (not (face-spec-set-match-display value
(selected-frame))))
2701 (define-widget 'custom-face-selected
'group
2702 "Edit the attributes of the selected display in a face specification."
2703 :args
'((repeat :format
""
2705 (group custom-display-unselected sexp
))
2706 (group (sexp :format
"") custom-face-edit
)
2711 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2712 "Converted version of the `custom-face-selected' widget.")
2714 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
2715 "Return a canonicalized version of SPEC using.
2716 FILTER-INDEX is the index in the entry for each attribute in
2717 `custom-face-attributes' at which the appropriate filter function can be
2718 found, and DEFAULT-FILTER is the filter to apply for attributes that
2720 (mapcar (lambda (entry)
2721 ;; Filter a single face-spec entry
2722 (let ((tests (car entry
))
2724 ;; Handle both old- and new-style attribute syntax
2725 (if (listp (car (cdr entry
)))
2728 (filtered-attrs nil
))
2729 ;; Filter each face attribute
2730 (while unfiltered-attrs
2731 (let* ((attr (pop unfiltered-attrs
))
2732 (pre-filtered-value (pop unfiltered-attrs
))
2734 (or (nth filter-index
(assq attr custom-face-attributes
))
2738 (funcall filter pre-filtered-value
)
2739 pre-filtered-value
)))
2740 (push filtered-value filtered-attrs
)
2741 (push attr filtered-attrs
)))
2743 (list tests filtered-attrs
)))
2746 (defun custom-pre-filter-face-spec (spec)
2747 "Return SPEC changed as necessary for editing by the face customization widget.
2748 SPEC must be a full face spec."
2749 (custom-filter-face-spec spec
2))
2751 (defun custom-post-filter-face-spec (spec)
2752 "Return the customized SPEC in a form suitable for setting the face."
2753 (custom-filter-face-spec spec
3))
2755 (defun custom-face-value-create (widget)
2756 "Create a list of the display specifications for WIDGET."
2757 (let ((buttons (widget-get widget
:buttons
))
2759 (symbol (widget-get widget
:value
))
2760 (tag (widget-get widget
:tag
))
2761 (state (widget-get widget
:custom-state
))
2763 (is-last (widget-get widget
:custom-last
))
2764 (prefix (widget-get widget
:custom-prefix
)))
2766 (setq tag
(prin1-to-string symbol
)))
2767 (cond ((eq custom-buffer-style
'tree
)
2768 (insert prefix
(if is-last
" `--- " " |--- "))
2769 (push (widget-create-child-and-convert
2770 widget
'custom-browse-face-tag
)
2772 (insert " " tag
"\n")
2773 (widget-put widget
:buttons buttons
))
2777 (widget-specify-sample widget begin
(point))
2778 (if (eq custom-buffer-style
'face
)
2780 (if (string-match "face\\'" tag
)
2782 (insert " face: ")))
2784 (push (widget-create-child-and-convert widget
'item
2791 (push (widget-create-child-and-convert
2793 :help-echo
"Hide or show this face."
2796 :action
'custom-toggle-parent
2797 (not (eq state
'hidden
)))
2801 (let ((magic (widget-create-child-and-convert
2802 widget
'custom-magic nil
)))
2803 (widget-put widget
:custom-magic magic
)
2804 (push magic buttons
))
2806 (widget-put widget
:buttons buttons
)
2807 ;; Insert documentation.
2808 (widget-default-format-handler widget ?h
)
2809 ;; The comment field
2810 (unless (eq state
'hidden
)
2811 (let* ((comment (get symbol
'face-comment
))
2813 (widget-create-child-and-convert
2814 widget
'custom-comment
2816 :value
(or comment
""))))
2817 (widget-put widget
:comment-widget comment-widget
)
2818 (push comment-widget children
)))
2820 (unless (eq state
'hidden
)
2821 (when (eq (widget-get widget
:custom-level
) 1)
2822 (custom-add-parent-links widget
))
2823 (custom-add-see-also widget
))
2825 (unless (eq (preceding-char) ?
\n)
2827 (unless (eq state
'hidden
)
2828 (message "Creating face editor...")
2829 (custom-load-widget widget
)
2830 (unless (widget-get widget
:custom-form
)
2831 (widget-put widget
:custom-form custom-face-default-form
))
2832 (let* ((symbol (widget-value widget
))
2833 (spec (or (get symbol
'customized-face
)
2834 (get symbol
'saved-face
)
2835 (get symbol
'face-defface-spec
)
2836 ;; Attempt to construct it.
2837 (list (list t
(custom-face-attributes-get
2838 symbol
(selected-frame))))))
2839 (form (widget-get widget
:custom-form
))
2840 (indent (widget-get widget
:indent
))
2842 ;; If the user has changed this face in some other way,
2843 ;; edit it as the user has specified it.
2844 (if (not (face-spec-match-p symbol spec
(selected-frame)))
2845 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
2846 (setq spec
(custom-pre-filter-face-spec spec
))
2847 (setq edit
(widget-create-child-and-convert
2849 (cond ((and (eq form
'selected
)
2850 (widget-apply custom-face-selected
2852 (when indent
(insert-char ?\ indent
))
2853 'custom-face-selected
)
2854 ((and (not (eq form
'lisp
))
2855 (widget-apply custom-face-all
2859 (when indent
(insert-char ?\ indent
))
2862 (custom-face-state-set widget
)
2863 (push edit children
)
2864 (widget-put widget
:children children
))
2865 (message "Creating face editor...done"))))))
2867 (defvar custom-face-menu
2868 '(("Set for Current Session" custom-face-set
)
2869 ("Save for Future Sessions" custom-face-save-command
)
2870 ("Reset to Saved" custom-face-reset-saved
2872 (or (get (widget-value widget
) 'saved-face
)
2873 (get (widget-value widget
) 'saved-face-comment
))))
2874 ("Erase Customization" custom-face-reset-standard
2876 (get (widget-value widget
) 'face-defface-spec
)))
2877 ("---" ignore ignore
)
2878 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2879 ("---" ignore ignore
)
2880 ("Show all display specs" custom-face-edit-all
2882 (not (eq (widget-get widget
:custom-form
) 'all
))))
2883 ("Just current attributes" custom-face-edit-selected
2885 (not (eq (widget-get widget
:custom-form
) 'selected
))))
2886 ("Show as Lisp expression" custom-face-edit-lisp
2888 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
2889 "Alist of actions for the `custom-face' widget.
2890 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2891 the menu entry, ACTION is the function to call on the widget when the
2892 menu is selected, and FILTER is a predicate which takes a `custom-face'
2893 widget as an argument, and returns non-nil if ACTION is valid on that
2894 widget. If FILTER is nil, ACTION is always valid.")
2896 (defun custom-face-edit-selected (widget)
2897 "Edit selected attributes of the value of WIDGET."
2898 (widget-put widget
:custom-state
'unknown
)
2899 (widget-put widget
:custom-form
'selected
)
2900 (custom-redraw widget
))
2902 (defun custom-face-edit-all (widget)
2903 "Edit all attributes of the value of WIDGET."
2904 (widget-put widget
:custom-state
'unknown
)
2905 (widget-put widget
:custom-form
'all
)
2906 (custom-redraw widget
))
2908 (defun custom-face-edit-lisp (widget)
2909 "Edit the Lisp representation of the value of WIDGET."
2910 (widget-put widget
:custom-state
'unknown
)
2911 (widget-put widget
:custom-form
'lisp
)
2912 (custom-redraw widget
))
2914 (defun custom-face-state-set (widget)
2915 "Set the state of WIDGET."
2916 (let* ((symbol (widget-value widget
))
2917 (comment (get symbol
'face-comment
))
2919 (widget-put widget
:custom-state
2921 (setq tmp
(get symbol
'customized-face
))
2922 (setq temp
(get symbol
'customized-face-comment
))
2924 (if (equal temp comment
)
2928 (setq tmp
(get symbol
'saved-face
))
2929 (setq temp
(get symbol
'saved-face-comment
))
2931 (if (equal temp comment
)
2934 ((get symbol
'face-defface-spec
)
2935 (if (equal comment nil
)
2941 (defun custom-face-action (widget &optional event
)
2942 "Show the menu for `custom-face' WIDGET.
2943 Optional EVENT is the location for the menu."
2944 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2945 (custom-toggle-hide widget
)
2946 (let* ((completion-ignore-case t
)
2947 (symbol (widget-get widget
:value
))
2948 (answer (widget-choose (concat "Operation on "
2949 (custom-unlispify-tag-name symbol
))
2950 (custom-menu-filter custom-face-menu
2954 (funcall answer widget
)))))
2956 (defun custom-face-set (widget)
2957 "Make the face attributes in WIDGET take effect."
2958 (let* ((symbol (widget-value widget
))
2959 (child (car (widget-get widget
:children
)))
2960 (value (custom-post-filter-face-spec (widget-value child
)))
2961 (comment-widget (widget-get widget
:comment-widget
))
2962 (comment (widget-value comment-widget
)))
2963 (when (equal comment
"")
2965 ;; Make the comment invisible by hand if it's empty
2966 (custom-comment-hide comment-widget
))
2967 (put symbol
'customized-face value
)
2968 (if (face-spec-choose value
)
2969 (face-spec-set symbol value
)
2970 ;; face-set-spec ignores empty attribute lists, so just give it
2971 ;; something harmless instead.
2972 (face-spec-set symbol
'((t :foreground unspecified
))))
2973 (put symbol
'customized-face-comment comment
)
2974 (put symbol
'face-comment comment
)
2975 (custom-face-state-set widget
)
2976 (custom-redraw-magic widget
)))
2978 (defun custom-face-save-command (widget)
2979 "Save in `.emacs' the face attributes in WIDGET."
2980 (custom-face-save widget
)
2983 (defun custom-face-save (widget)
2984 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2985 (let* ((symbol (widget-value widget
))
2986 (child (car (widget-get widget
:children
)))
2987 (value (custom-post-filter-face-spec (widget-value child
)))
2988 (comment-widget (widget-get widget
:comment-widget
))
2989 (comment (widget-value comment-widget
)))
2990 (when (equal comment
"")
2992 ;; Make the comment invisible by hand if it's empty
2993 (custom-comment-hide comment-widget
))
2994 (if (face-spec-choose value
)
2995 (face-spec-set symbol value
)
2996 ;; face-set-spec ignores empty attribute lists, so just give it
2997 ;; something harmless instead.
2998 (face-spec-set symbol
'((t :foreground unspecified
))))
2999 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3000 (put symbol
'saved-face value
))
3001 (put symbol
'customized-face nil
)
3002 (put symbol
'face-comment comment
)
3003 (put symbol
'customized-face-comment nil
)
3004 (put symbol
'saved-face-comment comment
)
3006 (custom-face-state-set widget
)
3007 (custom-redraw-magic widget
)))
3009 (defun custom-face-reset-saved (widget)
3010 "Restore WIDGET to the face's default attributes."
3011 (let* ((symbol (widget-value widget
))
3012 (child (car (widget-get widget
:children
)))
3013 (value (get symbol
'saved-face
))
3014 (comment (get symbol
'saved-face-comment
))
3015 (comment-widget (widget-get widget
:comment-widget
)))
3016 (unless (or value comment
)
3017 (error "No saved value for this face"))
3018 (put symbol
'customized-face nil
)
3019 (put symbol
'customized-face-comment nil
)
3020 (face-spec-set symbol value
)
3021 (put symbol
'face-comment comment
)
3022 (widget-value-set child value
)
3023 ;; This call manages the comment visibility
3024 (widget-value-set comment-widget
(or comment
""))
3025 (custom-face-state-set widget
)
3026 (custom-redraw-magic widget
)))
3028 (defun custom-face-standard-value (widget)
3029 (get (widget-value widget
) 'face-defface-spec
))
3031 (defun custom-face-reset-standard (widget)
3032 "Restore WIDGET to the face's standard settings.
3033 This operation eliminates any saved setting for the face,
3034 restoring it to the state of a face that has never been customized."
3035 (let* ((symbol (widget-value widget
))
3036 (child (car (widget-get widget
:children
)))
3037 (value (get symbol
'face-defface-spec
))
3038 (comment-widget (widget-get widget
:comment-widget
)))
3040 (error "No standard setting for this face"))
3041 (put symbol
'customized-face nil
)
3042 (put symbol
'customized-face-comment nil
)
3043 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3044 (put symbol
'saved-face nil
)
3045 (put symbol
'saved-face-comment nil
)
3047 (face-spec-set symbol value
)
3048 (put symbol
'face-comment nil
)
3049 (widget-value-set child value
)
3050 ;; This call manages the comment visibility
3051 (widget-value-set comment-widget
"")
3052 (custom-face-state-set widget
)
3053 (custom-redraw-magic widget
)))
3055 ;;; The `face' Widget.
3057 (define-widget 'face
'default
3058 "Select and customize a face."
3059 :convert-widget
'widget-value-convert-widget
3060 :button-prefix
'widget-push-button-prefix
3061 :button-suffix
'widget-push-button-suffix
3062 :format
"%{%t%}: %[select face%] %v"
3065 :value-create
'widget-face-value-create
3066 :value-delete
'widget-face-value-delete
3067 :value-get
'widget-value-value-get
3068 :validate
'widget-children-validate
3069 :action
'widget-face-action
3070 :match
(lambda (widget value
) (symbolp value
)))
3072 (defun widget-face-value-create (widget)
3073 "Create a `custom-face' child."
3074 (let* ((symbol (widget-value widget
))
3075 (custom-buffer-style 'face
)
3076 (child (widget-create-child-and-convert
3080 (custom-magic-reset child
)
3081 (setq custom-options
(cons child custom-options
))
3082 (widget-put widget
:children
(list child
))))
3084 (defun widget-face-value-delete (widget)
3085 "Remove the child from the options."
3086 (let ((child (car (widget-get widget
:children
))))
3087 (setq custom-options
(delq child custom-options
))
3088 (widget-children-value-delete widget
)))
3090 (defvar face-history nil
3091 "History of entered face names.")
3093 (defun widget-face-action (widget &optional event
)
3094 "Prompt for a face."
3095 (let ((answer (completing-read "Face: "
3096 (mapcar (lambda (face)
3097 (list (symbol-name face
)))
3101 (unless (zerop (length answer
))
3102 (widget-value-set widget
(intern answer
))
3103 (widget-apply widget
:notify widget event
)
3106 ;;; The `hook' Widget.
3108 (define-widget 'hook
'list
3110 :value-to-internal
(lambda (widget value
)
3111 (if (and value
(symbolp value
))
3114 :match
(lambda (widget value
)
3116 (widget-group-match widget value
)))
3117 ;; Avoid adding undefined functions to the hook, especially for
3118 ;; things like `find-file-hook' or even more basic ones, to avoid
3120 :set
(lambda (symbol value
)
3123 (add-hook symbol elt
))))
3124 :convert-widget
'custom-hook-convert-widget
3127 (defun custom-hook-convert-widget (widget)
3128 ;; Handle `:options'.
3129 (let* ((options (widget-get widget
:options
))
3130 (other `(editable-list :inline t
3131 :entry-format
"%i %d%v"
3132 (function :format
" %v")))
3134 (list `(checklist :inline t
3135 ,@(mapcar (lambda (entry)
3136 `(function-item ,entry
))
3140 (widget-put widget
:args args
)
3143 ;;; The `custom-group-link' Widget.
3145 (define-widget 'custom-group-link
'link
3146 "Show parent in other window when activated."
3147 :help-echo
"Create customization buffer for this group."
3148 :action
'custom-group-link-action
)
3150 (defun custom-group-link-action (widget &rest ignore
)
3151 (customize-group (widget-value widget
)))
3153 ;;; The `custom-group' Widget.
3155 (defcustom custom-group-tag-faces nil
3156 ;; In XEmacs, this ought to play games with font size.
3157 ;; Fixme: make it do so in Emacs.
3158 "Face used for group tags.
3159 The first member is used for level 1 groups, the second for level 2,
3160 and so forth. The remaining group tags are shown with
3161 `custom-group-tag-face'."
3162 :type
'(repeat face
)
3163 :group
'custom-faces
)
3165 (defface custom-group-tag-face-1
3168 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3171 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3173 "Face used for group tags."
3174 :group
'custom-faces
)
3176 (defface custom-group-tag-face
3179 (:foreground
"light blue" :weight bold
:height
1.2))
3182 (:foreground
"blue" :weight bold
:height
1.2))
3184 "Face used for low level group tags."
3185 :group
'custom-faces
)
3187 (define-widget 'custom-group
'custom
3190 :sample-face-get
'custom-group-sample-face-get
3191 :documentation-property
'group-documentation
3192 :help-echo
"Set or reset all members of this group."
3193 :value-create
'custom-group-value-create
3194 :action
'custom-group-action
3195 :custom-category
'group
3196 :custom-set
'custom-group-set
3197 :custom-save
'custom-group-save
3198 :custom-reset-current
'custom-group-reset-current
3199 :custom-reset-saved
'custom-group-reset-saved
3200 :custom-reset-standard
'custom-group-reset-standard
3201 :custom-menu
'custom-group-menu-create
)
3203 (defun custom-group-sample-face-get (widget)
3204 ;; Use :sample-face.
3205 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3206 'custom-group-tag-face
))
3208 (define-widget 'custom-group-visibility
'visibility
3209 "An indicator and manipulator for hidden group contents."
3210 :create
'custom-group-visibility-create
)
3212 (defun custom-group-visibility-create (widget)
3213 (let ((visible (widget-value widget
)))
3215 (insert "--------")))
3216 (widget-default-create widget
))
3218 (defun custom-group-members (symbol groups-only
)
3219 "Return SYMBOL's custom group members.
3220 If GROUPS-ONLY non-nil, return only those members that are groups."
3221 (if (not groups-only
)
3222 (get symbol
'custom-group
)
3224 (dolist (entry (get symbol
'custom-group
))
3225 (when (eq (nth 1 entry
) 'custom-group
)
3226 (push entry members
)))
3227 (nreverse members
))))
3229 (defun custom-group-value-create (widget)
3230 "Insert a customize group for WIDGET in the current buffer."
3231 (let* ((state (widget-get widget
:custom-state
))
3232 (level (widget-get widget
:custom-level
))
3233 ;; (indent (widget-get widget :indent))
3234 (prefix (widget-get widget
:custom-prefix
))
3235 (buttons (widget-get widget
:buttons
))
3236 (tag (widget-get widget
:tag
))
3237 (symbol (widget-value widget
))
3238 (members (custom-group-members symbol
3239 (and (eq custom-buffer-style
'tree
)
3240 custom-browse-only-groups
))))
3241 (cond ((and (eq custom-buffer-style
'tree
)
3243 (or members
(custom-unloaded-widget-p widget
)))
3244 (custom-browse-insert-prefix prefix
)
3245 (push (widget-create-child-and-convert
3246 widget
'custom-browse-visibility
3247 ;; :tag-glyph "plus"
3251 ;; (widget-glyph-insert nil "-- " "horizontal")
3252 (push (widget-create-child-and-convert
3253 widget
'custom-browse-group-tag
)
3255 (insert " " tag
"\n")
3256 (widget-put widget
:buttons buttons
))
3257 ((and (eq custom-buffer-style
'tree
)
3258 (zerop (length members
)))
3259 (custom-browse-insert-prefix prefix
)
3261 ;; (widget-glyph-insert nil "[ ]" "empty")
3262 ;; (widget-glyph-insert nil "-- " "horizontal")
3263 (push (widget-create-child-and-convert
3264 widget
'custom-browse-group-tag
)
3266 (insert " " tag
"\n")
3267 (widget-put widget
:buttons buttons
))
3268 ((eq custom-buffer-style
'tree
)
3269 (custom-browse-insert-prefix prefix
)
3270 (custom-load-widget widget
)
3271 (if (zerop (length members
))
3273 (custom-browse-insert-prefix prefix
)
3275 ;; (widget-glyph-insert nil "[ ]" "empty")
3276 ;; (widget-glyph-insert nil "-- " "horizontal")
3277 (push (widget-create-child-and-convert
3278 widget
'custom-browse-group-tag
)
3280 (insert " " tag
"\n")
3281 (widget-put widget
:buttons buttons
))
3282 (push (widget-create-child-and-convert
3283 widget
'custom-browse-visibility
3284 ;; :tag-glyph "minus"
3288 ;; (widget-glyph-insert nil "-\\ " "top")
3289 (push (widget-create-child-and-convert
3290 widget
'custom-browse-group-tag
)
3292 (insert " " tag
"\n")
3293 (widget-put widget
:buttons buttons
)
3294 (message "Creating group...")
3295 (let* ((members (custom-sort-items members
3296 custom-browse-sort-alphabetically
3297 custom-browse-order-groups
))
3298 (prefixes (widget-get widget
:custom-prefixes
))
3299 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3300 (extra-prefix (if (widget-get widget
:custom-last
)
3303 (prefix (concat prefix extra-prefix
))
3306 (setq entry
(car members
)
3307 members
(cdr members
))
3308 (push (widget-create-child-and-convert
3309 widget
(nth 1 entry
)
3311 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3312 :custom-prefixes custom-prefix-list
3313 :custom-level
(1+ level
)
3314 :custom-last
(null members
)
3315 :value
(nth 0 entry
)
3316 :custom-prefix prefix
)
3318 (widget-put widget
:children
(reverse children
)))
3319 (message "Creating group...done")))
3322 ;; Create level indicator.
3323 (unless (eq custom-buffer-style
'links
)
3324 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3327 (let ((begin (point)))
3329 (widget-specify-sample widget begin
(point)))
3331 ;; Create link/visibility indicator.
3332 (if (eq custom-buffer-style
'links
)
3333 (push (widget-create-child-and-convert
3334 widget
'custom-group-link
3338 (push (widget-create-child-and-convert
3339 widget
'custom-group-visibility
3340 :help-echo
"Show members of this group."
3341 :action
'custom-toggle-parent
3342 (not (eq state
'hidden
)))
3345 ;; Create magic button.
3346 (let ((magic (widget-create-child-and-convert
3347 widget
'custom-magic nil
)))
3348 (widget-put widget
:custom-magic magic
)
3349 (push magic buttons
))
3351 (widget-put widget
:buttons buttons
)
3352 ;; Insert documentation.
3353 (if (and (eq custom-buffer-style
'links
) (> level
1))
3354 (widget-put widget
:documentation-indent
0))
3355 (widget-default-format-handler widget ?h
))
3358 ;; Add parent groups references above the group.
3359 (if t
;;; This should test that the buffer
3360 ;;; was made to display a group.
3362 (if (custom-add-parent-links widget
3363 "Go to parent group:")
3365 ;; Create level indicator.
3366 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3369 (let ((start (point)))
3371 (widget-specify-sample widget start
(point)))
3373 ;; Create visibility indicator.
3374 (unless (eq custom-buffer-style
'links
)
3376 (push (widget-create-child-and-convert
3378 :help-echo
"Hide members of this group."
3379 :action
'custom-toggle-parent
3380 (not (eq state
'hidden
)))
3383 ;; Create more dashes.
3384 ;; Use 76 instead of 75 to compensate for the temporary "<"
3385 ;; added by `widget-insert'.
3386 (insert-char ?-
(- 76 (current-column)
3387 (* custom-buffer-indent level
)))
3389 ;; Create magic button.
3390 (let ((magic (widget-create-child-and-convert
3391 widget
'custom-magic
3394 (widget-put widget
:custom-magic magic
)
3395 (push magic buttons
))
3397 (widget-put widget
:buttons buttons
)
3398 ;; Insert documentation.
3399 (widget-default-format-handler widget ?h
)
3401 (if nil
;;; This should test that the buffer
3402 ;;; was not made to display a group.
3404 (insert-char ?\ custom-buffer-indent
)
3405 (custom-add-parent-links widget
)))
3406 (custom-add-see-also widget
3407 (make-string (* custom-buffer-indent level
)
3410 (message "Creating group...")
3411 (custom-load-widget widget
)
3412 (let* ((members (custom-sort-items members
3413 custom-buffer-sort-alphabetically
3414 custom-buffer-order-groups
))
3415 (prefixes (widget-get widget
:custom-prefixes
))
3416 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3417 (length (length members
))
3419 (children (mapcar (lambda (entry)
3420 (widget-insert "\n")
3422 Creating group members... %2d%%"
3423 (/ (* 100.0 count
) length
))
3424 (setq count
(1+ count
))
3426 (widget-create-child-and-convert
3427 widget
(nth 1 entry
)
3429 :tag
(custom-unlispify-tag-name
3431 :custom-prefixes custom-prefix-list
3432 :custom-level
(1+ level
)
3433 :value
(nth 0 entry
))
3434 (unless (eq (preceding-char) ?
\n)
3435 (widget-insert "\n"))))
3437 (message "Creating group magic...")
3438 (mapc 'custom-magic-reset children
)
3439 (message "Creating group state...")
3440 (widget-put widget
:children children
)
3441 (custom-group-state-update widget
)
3442 (message "Creating group... done"))
3445 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3446 (insert "\\- " (widget-get widget
:tag
) " group end ")
3447 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3450 (defvar custom-group-menu
3451 '(("Set for Current Session" custom-group-set
3453 (eq (widget-get widget
:custom-state
) 'modified
)))
3454 ("Save for Future Sessions" custom-group-save
3456 (memq (widget-get widget
:custom-state
) '(modified set
))))
3457 ("Reset to Current" custom-group-reset-current
3459 (memq (widget-get widget
:custom-state
) '(modified))))
3460 ("Reset to Saved" custom-group-reset-saved
3462 (memq (widget-get widget
:custom-state
) '(modified set
))))
3463 ("Reset to standard setting" custom-group-reset-standard
3465 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
3466 "Alist of actions for the `custom-group' widget.
3467 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3468 the menu entry, ACTION is the function to call on the widget when the
3469 menu is selected, and FILTER is a predicate which takes a `custom-group'
3470 widget as an argument, and returns non-nil if ACTION is valid on that
3471 widget. If FILTER is nil, ACTION is always valid.")
3473 (defun custom-group-action (widget &optional event
)
3474 "Show the menu for `custom-group' WIDGET.
3475 Optional EVENT is the location for the menu."
3476 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3477 (custom-toggle-hide widget
)
3478 (let* ((completion-ignore-case t
)
3479 (answer (widget-choose (concat "Operation on "
3480 (custom-unlispify-tag-name
3481 (widget-get widget
:value
)))
3482 (custom-menu-filter custom-group-menu
3486 (funcall answer widget
)))))
3488 (defun custom-group-set (widget)
3489 "Set changes in all modified group members."
3490 (let ((children (widget-get widget
:children
)))
3491 (mapc (lambda (child)
3492 (when (eq (widget-get child
:custom-state
) 'modified
)
3493 (widget-apply child
:custom-set
)))
3496 (defun custom-group-save (widget)
3497 "Save all modified group members."
3498 (let ((children (widget-get widget
:children
)))
3499 (mapc (lambda (child)
3500 (when (memq (widget-get child
:custom-state
) '(modified set
))
3501 (widget-apply child
:custom-save
)))
3504 (defun custom-group-reset-current (widget)
3505 "Reset all modified group members."
3506 (let ((children (widget-get widget
:children
)))
3507 (mapc (lambda (child)
3508 (when (eq (widget-get child
:custom-state
) 'modified
)
3509 (widget-apply child
:custom-reset-current
)))
3512 (defun custom-group-reset-saved (widget)
3513 "Reset all modified or set group members."
3514 (let ((children (widget-get widget
:children
)))
3515 (mapc (lambda (child)
3516 (when (memq (widget-get child
:custom-state
) '(modified set
))
3517 (widget-apply child
:custom-reset-saved
)))
3520 (defun custom-group-reset-standard (widget)
3521 "Reset all modified, set, or saved group members."
3522 (let ((children (widget-get widget
:children
)))
3523 (mapc (lambda (child)
3524 (when (memq (widget-get child
:custom-state
)
3525 '(modified set saved
))
3526 (widget-apply child
:custom-reset-standard
)))
3529 (defun custom-group-state-update (widget)
3531 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3532 (let* ((children (widget-get widget
:children
))
3533 (states (mapcar (lambda (child)
3534 (widget-get child
:custom-state
))
3536 (magics custom-magic-alist
)
3539 (let ((magic (car (car magics
))))
3540 (if (and (not (eq magic
'hidden
))
3541 (memq magic states
))
3544 (setq magics
(cdr magics
)))))
3545 (widget-put widget
:custom-state found
)))
3546 (custom-magic-reset widget
))
3548 ;;; The `custom-save-all' Function.
3550 (defcustom custom-file nil
3551 "File used for storing customization information.
3552 The default is nil, which means to use your init file
3553 as specified by `user-init-file'. If you specify some other file,
3554 you need to explicitly load that file for the settings to take effect.
3556 When you change this variable, look in the previous custom file
3557 \(usually your init file) for the forms `(custom-set-variables ...)'
3558 and `(custom-set-faces ...)', and copy them (whichever ones you find)
3559 to the new custom file. This will preserve your existing customizations."
3560 :type
'(choice (const :tag
"Your Emacs init file" nil
) file
)
3563 (defun custom-file ()
3564 "Return the file name for saving customizations."
3567 (let ((user-init-file user-init-file
)
3569 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
3570 (when (null user-init-file
)
3571 (if (or (file-exists-p default-init-file
)
3572 (and (eq system-type
'windows-nt
)
3573 (file-exists-p "~/_emacs")))
3574 ;; Started with -q, i.e. the file containing
3575 ;; Custom settings hasn't been read. Saving
3576 ;; settings there would overwrite other settings.
3577 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3578 (setq user-init-file default-init-file
))
3581 (defun custom-save-delete (symbol)
3582 "Visit `custom-file' and delete all calls to SYMBOL from it.
3583 Leave point at the old location of the first such call,
3584 or (if there were none) at the end of the buffer."
3585 (let ((default-major-mode))
3586 (set-buffer (find-file-noselect (custom-file))))
3587 (goto-char (point-min))
3588 ;; Skip all whitespace and comments.
3589 (while (forward-comment 1))
3591 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3594 (while t
;; We exit this loop only via throw.
3595 ;; Skip all whitespace and comments.
3596 (while (forward-comment 1))
3597 (let ((start (point))
3598 (sexp (condition-case nil
3599 (read (current-buffer))
3600 (end-of-file (throw 'found nil
)))))
3601 (when (and (listp sexp
)
3602 (eq (car sexp
) symbol
))
3603 (delete-region start
(point))
3605 (setq first
(point)))))))
3608 ;; Move in front of local variables, otherwise long Custom
3609 ;; entries would make them ineffective.
3610 (let ((pos (point-max))
3611 (case-fold-search t
))
3613 (goto-char (point-max))
3614 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3616 (when (search-forward "Local Variables:" nil t
)
3617 (setq pos
(line-beginning-position))))
3620 (defun custom-save-variables ()
3621 "Save all customized variables in `custom-file'."
3623 (custom-save-delete 'custom-set-variables
)
3624 (let ((standard-output (current-buffer))
3625 (saved-list (make-list 1 0))
3627 ;; First create a sorted list of saved variables.
3630 (if (get symbol
'saved-value
)
3631 (nconc saved-list
(list symbol
)))))
3632 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3635 (princ "(custom-set-variables
3636 ;; custom-set-variables was added by Custom.
3637 ;; If you edit it by hand, you could mess it up, so be careful.
3638 ;; Your init file should contain only one such instance.
3639 ;; If there is more than one, they won't work right.\n")
3642 (let ((value (get symbol
'saved-value
))
3643 (requests (get symbol
'custom-requests
))
3644 (now (not (or (get symbol
'standard-value
)
3645 (and (not (boundp symbol
))
3646 (not (get symbol
'force-value
))))))
3647 (comment (get symbol
'saved-variable-comment
))
3649 (when (or value comment
)
3656 (cond ((or now requests comment
)
3661 (cond ((or requests comment
)
3680 (unless (looking-at "\n")
3683 (defun custom-save-faces ()
3684 "Save all customized faces in `custom-file'."
3686 (custom-save-delete 'custom-set-faces
)
3687 (let ((standard-output (current-buffer))
3688 (saved-list (make-list 1 0))
3690 ;; First create a sorted list of saved faces.
3693 (if (get symbol
'saved-face
)
3694 (nconc saved-list
(list symbol
)))))
3695 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3696 ;; The default face must be first, since it affects the others.
3697 (if (memq 'default saved-list
)
3698 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
3701 (princ "(custom-set-faces
3702 ;; custom-set-faces was added by Custom.
3703 ;; If you edit it by hand, you could mess it up, so be careful.
3704 ;; Your init file should contain only one such instance.
3705 ;; If there is more than one, they won't work right.\n")
3708 (let ((value (get symbol
'saved-face
))
3709 (now (not (or (get symbol
'face-defface-spec
)
3710 (and (not (custom-facep symbol
))
3711 (not (get symbol
'force-face
))))))
3712 (comment (get symbol
'saved-face-comment
)))
3713 ;; Don't print default face here.
3720 (cond ((or now comment
)
3737 (unless (looking-at "\n")
3741 (defun customize-save-customized ()
3742 "Save all user options which have been set in this session."
3744 (mapatoms (lambda (symbol)
3745 (let ((face (get symbol
'customized-face
))
3746 (value (get symbol
'customized-value
))
3747 (face-comment (get symbol
'customized-face-comment
))
3749 (get symbol
'customized-variable-comment
)))
3751 (put symbol
'saved-face face
)
3752 (put symbol
'customized-face nil
))
3754 (put symbol
'saved-value value
)
3755 (put symbol
'customized-value nil
))
3756 (when variable-comment
3757 (put symbol
'saved-variable-comment variable-comment
)
3758 (put symbol
'customized-variable-comment nil
))
3760 (put symbol
'saved-face-comment face-comment
)
3761 (put symbol
'customized-face-comment nil
)))))
3762 ;; We really should update all custom buffers here.
3766 (defun custom-save-all ()
3767 "Save all customizations in `custom-file'."
3768 (let ((inhibit-read-only t
))
3769 (custom-save-variables)
3772 (let ((default-major-mode nil
))
3773 (set-buffer (find-file-noselect (custom-file))))
3774 (let ((file-precious-flag t
))
3777 ;;; The Customize Menu.
3781 (defcustom custom-menu-nesting
2
3782 "Maximum nesting in custom menus."
3784 :group
'custom-menu
)
3786 (defun custom-face-menu-create (widget symbol
)
3787 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3788 (vector (custom-unlispify-menu-entry symbol
)
3789 `(customize-face ',symbol
)
3792 (defun custom-variable-menu-create (widget symbol
)
3793 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3794 (let ((type (get symbol
'custom-type
)))
3795 (unless (listp type
)
3796 (setq type
(list type
)))
3797 (if (and type
(widget-get type
:custom-menu
))
3798 (widget-apply type
:custom-menu symbol
)
3799 (vector (custom-unlispify-menu-entry symbol
)
3800 `(customize-variable ',symbol
)
3803 ;; Add checkboxes to boolean variable entries.
3804 (widget-put (get 'boolean
'widget-type
)
3805 :custom-menu
(lambda (widget symbol
)
3806 (vector (custom-unlispify-menu-entry symbol
)
3807 `(customize-variable ',symbol
)
3809 ':selected symbol
)))
3811 (defun custom-group-menu-create (widget symbol
)
3812 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3813 `( ,(custom-unlispify-menu-entry symbol t
)
3814 :filter
(lambda (&rest junk
)
3815 (let ((menu (custom-menu-create ',symbol
)))
3816 (if (consp menu
) (cdr menu
) menu
)))))
3819 (defun custom-menu-create (symbol)
3820 "Create menu for customization group SYMBOL.
3821 The menu is in a format applicable to `easy-menu-define'."
3822 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
3823 `(customize-group ',symbol
)
3825 (if (and (or (not (boundp 'custom-menu-nesting
))
3826 (>= custom-menu-nesting
0))
3827 (< (length (get symbol
'custom-group
)) widget-menu-max-size
))
3828 (let ((custom-prefix-list (custom-prefix-add symbol
3829 custom-prefix-list
))
3830 (members (custom-sort-items (get symbol
'custom-group
)
3831 custom-menu-sort-alphabetically
3832 custom-menu-order-groups
)))
3833 (custom-load-symbol symbol
)
3834 `(,(custom-unlispify-menu-entry symbol t
)
3837 ,@(mapcar (lambda (entry)
3838 (widget-apply (if (listp (nth 1 entry
))
3840 (list (nth 1 entry
)))
3841 :custom-menu
(nth 0 entry
)))
3846 (defun customize-menu-create (symbol &optional name
)
3847 "Return a customize menu for customization group SYMBOL.
3848 If optional NAME is given, use that as the name of the menu.
3849 Otherwise the menu will be named `Customize'.
3850 The format is suitable for use with `easy-menu-define'."
3852 (setq name
"Customize"))
3854 :filter
(lambda (&rest junk
)
3855 (let ((menu (custom-menu-create ',symbol
)))
3856 (if (consp menu
) (cdr menu
) menu
)))))
3858 ;;; The Custom Mode.
3860 (defvar custom-mode-map nil
3861 "Keymap for `custom-mode'.")
3863 (unless custom-mode-map
3864 ;; This keymap should be dense, but a dense keymap would prevent inheriting
3865 ;; "\r" bindings from the parent map.
3866 (setq custom-mode-map
(make-sparse-keymap))
3867 (set-keymap-parent custom-mode-map widget-keymap
)
3868 (suppress-keymap custom-mode-map
)
3869 (define-key custom-mode-map
" " 'scroll-up
)
3870 (define-key custom-mode-map
"\177" 'scroll-down
)
3871 (define-key custom-mode-map
"q" 'Custom-buffer-done
)
3872 (define-key custom-mode-map
"u" 'Custom-goto-parent
)
3873 (define-key custom-mode-map
"n" 'widget-forward
)
3874 (define-key custom-mode-map
"p" 'widget-backward
)
3875 (define-key custom-mode-map
[mouse-1
] 'Custom-move-and-invoke
))
3877 (defun Custom-move-and-invoke (event)
3878 "Move to where you click, and if it is an active field, invoke it."
3880 (mouse-set-point event
)
3881 (if (widget-event-point event
)
3882 (let* ((pos (widget-event-point event
))
3883 (button (get-char-property pos
'button
)))
3885 (widget-button-click event
)))))
3887 (easy-menu-define Custom-mode-menu
3889 "Menu used in customization buffers."
3891 ,(customize-menu-create 'customize
)
3892 ["Set" Custom-set t
]
3893 ["Save" Custom-save t
]
3894 ["Reset to Current" Custom-reset-current t
]
3895 ["Reset to Saved" Custom-reset-saved t
]
3896 ["Reset to Standard Settings" Custom-reset-standard t
]
3897 ["Info" (Info-goto-node "(emacs)Easy Customization") t
]))
3899 (defun Custom-goto-parent ()
3900 "Go to the parent group listed at the top of this buffer.
3901 If several parents are listed, go to the first of them."
3904 (goto-char (point-min))
3905 (if (search-forward "\nGo to parent group: " nil t
)
3906 (let* ((button (get-char-property (point) 'button
))
3907 (parent (downcase (widget-get button
:tag
))))
3908 (customize-group parent
)))))
3910 (defcustom custom-mode-hook nil
3911 "Hook called when entering Custom mode."
3913 :group
'custom-buffer
)
3915 (defun custom-state-buffer-message (widget)
3916 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
3917 (message "To install your edits, invoke [State] and choose the Set operation")))
3919 (defun custom-mode ()
3920 "Major mode for editing customization buffers.
3922 The following commands are available:
3924 Move to next button or editable field. \\[widget-forward]
3925 Move to previous button or editable field. \\[widget-backward]
3926 \\<widget-field-keymap>\
3927 Complete content of editable text field. \\[widget-complete]
3928 \\<custom-mode-map>\
3929 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3930 Invoke button under point. \\[widget-button-press]
3931 Set all modifications. \\[Custom-set]
3932 Make all modifications default. \\[Custom-save]
3933 Reset all modified options. \\[Custom-reset-current]
3934 Reset all modified or set options. \\[Custom-reset-saved]
3935 Reset all options. \\[Custom-reset-standard]
3937 Entry to this mode calls the value of `custom-mode-hook'
3938 if that value is non-nil."
3939 (kill-all-local-variables)
3940 (setq major-mode
'custom-mode
3942 (use-local-map custom-mode-map
)
3943 (easy-menu-add Custom-mode-menu
)
3944 (make-local-variable 'custom-options
)
3945 (make-local-variable 'widget-documentation-face
)
3946 (setq widget-documentation-face
'custom-documentation-face
)
3947 (make-local-variable 'widget-button-face
)
3948 (setq widget-button-face
'custom-button-face
)
3949 (set (make-local-variable 'widget-button-pressed-face
)
3950 'custom-button-pressed-face
)
3951 (set (make-local-variable 'widget-mouse-face
)
3952 'custom-button-pressed-face
) ; buttons `depress' when moused
3953 ;; When possible, use relief for buttons, not bracketing. This test
3954 ;; may not be optimal.
3955 (when custom-raised-buttons
3956 (set (make-local-variable 'widget-push-button-prefix
) "")
3957 (set (make-local-variable 'widget-push-button-suffix
) "")
3958 (set (make-local-variable 'widget-link-prefix
) "")
3959 (set (make-local-variable 'widget-link-suffix
) ""))
3960 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
3961 (run-hooks 'custom-mode-hook
))
3963 (put 'custom-mode
'mode-class
'special
)
3966 'debug-ignored-errors
3967 "^No user options have changed defaults in recent Emacs versions$")
3973 ;;; cus-edit.el ends here