1 ;;; cus-edit.el --- Tools for customization Emacs.
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: help, faces
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
20 (define-widget-keywords :custom-prefixes
:custom-menu
:custom-show
21 :custom-magic
:custom-state
:custom-level
:custom-form
22 :custom-set
:custom-save
:custom-reset-current
:custom-reset-saved
23 :custom-reset-factory
)
25 (put 'custom-define-hook
'custom-type
'hook
)
26 (put 'custom-define-hook
'factory-value
'(nil))
27 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
29 ;;; Customization Groups.
32 "Customization of the One True Editor."
33 :link
'(custom-manual "(emacs)Top"))
35 ;; Most of these groups are stolen from `finder.el',
37 "Basic text editing facilities."
41 "Abbreviation handling, typing shortcuts, macros."
45 (defgroup matching nil
46 "Various sorts of searching and matching."
49 (defgroup emulations nil
50 "Emulations of other editors."
57 (defgroup outlines nil
58 "Support for hierarchical outlining."
61 (defgroup external nil
62 "Interfacing to external utilities."
66 "Code related to the `bib' bibliography processor."
70 (defgroup processes nil
71 "Process, subshell, compilation, and job control support."
75 (defgroup programming nil
76 "Support for programming in other languages."
79 (defgroup languages nil
80 "Specialized modes for editing programming languages."
84 "Lisp support, including Emacs Lisp."
89 "Support for the C language and related languages."
97 "Support for object-oriented programming."
100 (defgroup applications nil
101 "Applications written in Emacs."
104 (defgroup calendar nil
105 "Calendar and time management support."
106 :group
'applications
)
109 "Modes for electronic-mail handling."
110 :group
'applications
)
113 "Support for netnews reading and posting."
114 :group
'applications
)
117 "Games, jokes and amusements."
118 :group
'applications
)
120 (defgroup development nil
121 "Support for further development of Emacs."
125 "Support for Emacs documentation."
128 (defgroup extensions nil
129 "Emacs Lisp language extensions."
132 (defgroup internal nil
133 "Code for Emacs internals, build process, defaults."
137 "Maintenance aids for the Emacs development group."
141 (defgroup environment nil
142 "Fitting Emacs with its environment."
146 "Communications, networking, remote access to files."
150 (defgroup hardware nil
151 "Support for interfacing with exotic hardware."
154 (defgroup terminals nil
155 "Support for terminal types."
159 "Front-ends/assistants for, or emulators of, UNIX features."
163 "Support code for vms."
167 "Internationalization and alternate character-set support."
172 "Support for Emacs frames and window systems."
176 "Support editing files of data."
184 "Code related to the TeX formatter."
188 "Support for multiple fonts."
191 (defgroup hypermedia nil
192 "Support for links between text or other media types."
196 "Support for on-line help systems."
200 "Code local to your site."
203 (defgroup customize
'((widgets custom-group
))
204 "Customization of the Customization support."
205 :link
'(custom-manual "(custom)Top")
206 :link
'(url-link :tag
"Development Page"
207 "http://www.dina.kvl.dk/~abraham/custom/")
211 (defgroup custom-faces nil
212 "Faces used by customize."
216 (defgroup abbrev-mode nil
217 "Word abbreviations mode."
221 "Storage allocation and gc for GNU Emacs Lisp interpreter."
222 :tag
"Storage Allocation"
226 "Undoing changes in buffers."
229 (defgroup modeline nil
230 "Content of the modeline."
234 "Indenting and filling text."
237 (defgroup editing-basics nil
238 "Most basic editing facilities."
241 (defgroup display nil
242 "How characters are displayed in buffers."
245 (defgroup execute nil
246 "Executing external commands."
249 (defgroup installation nil
250 "The Emacs installation."
258 "Internal Emacs limits."
262 "Debugging Emacs itself."
265 (defgroup minibuffer nil
266 "Controling the behaviour of the minibuffer."
269 (defgroup keyboard nil
270 "Input from the keyboard."
274 "Input from the mouse."
278 "Input from the menus."
281 (defgroup auto-save nil
282 "Preventing accidential loss of data."
285 (defgroup processes-basics nil
286 "Basic stuff dealing with processes."
289 (defgroup windows nil
290 "Windows within a frame."
295 (defun custom-quote (sexp)
296 "Quote SEXP iff it is not self quoting."
297 (if (or (memq sexp
'(t nil
))
299 (eq (aref (symbol-name sexp
) 0) ?
:))
301 (memq (car sexp
) '(lambda)))
304 (and (fboundp 'characterp
)
309 (defun custom-split-regexp-maybe (regexp)
310 "If REGEXP is a string, split it to a list at `\\|'.
311 You can get the original back with from the result with:
312 (mapconcat 'identity result \"\\|\")
314 IF REGEXP is not a string, return it unchanged."
318 (while (string-match "\\\\|" regexp start
)
319 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
320 start
(match-end 0)))
321 (nreverse (cons (substring regexp start
) all
)))
324 (defun custom-variable-prompt ()
325 ;; Code stolen from `help.el'.
326 "Prompt for a variable, defaulting to the variable at point.
327 Return a list suitable for use in `interactive'."
328 (let ((v (variable-at-point))
329 (enable-recursive-minibuffers t
)
331 (setq val
(completing-read
333 (format "Customize variable (default %s): " v
)
334 "Customize variable: ")
336 (list (if (equal val
"")
341 (defvar custom-prefix-list nil
342 "List of prefixes that should be ignored by `custom-unlispify'")
344 (defcustom custom-unlispify-menu-entries t
345 "Display menu entries as words instead of symbols if non nil."
349 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
350 "Convert symbol into a menu entry."
351 (cond ((not custom-unlispify-menu-entries
)
352 (symbol-name symbol
))
353 ((get symbol
'custom-tag
)
355 (get symbol
'custom-tag
)
356 (concat (get symbol
'custom-tag
) "...")))
359 (set-buffer (get-buffer-create " *Custom-Work*"))
361 (princ symbol
(current-buffer))
362 (goto-char (point-min))
363 (when (and (eq (get symbol
'custom-type
) 'boolean
)
364 (re-search-forward "-p\\'" nil t
))
365 (replace-match "" t t
)
366 (goto-char (point-min)))
367 (let ((prefixes custom-prefix-list
)
370 (setq prefix
(car prefixes
))
371 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
374 (delete-region (point-min) (point)))
375 (setq prefixes
(cdr prefixes
)))))
376 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
377 (capitalize-region (point-min) (point-max))
379 (goto-char (point-max))
383 (defcustom custom-unlispify-tag-names t
384 "Display tag names as words instead of symbols if non nil."
388 (defun custom-unlispify-tag-name (symbol)
389 "Convert symbol into a menu entry."
390 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
391 (custom-unlispify-menu-entry symbol t
)))
393 (defun custom-prefix-add (symbol prefixes
)
394 ;; Addd SYMBOL to list of ignored PREFIXES.
395 (cons (or (get symbol
'custom-prefix
)
396 (concat (symbol-name symbol
) "-"))
401 (defcustom custom-guess-name-alist
406 ("-function\\'" function
)
407 ("-functions\\'" (repeat function
))
408 ("-list\\'" (repeat sexp
))
409 ("-alist\\'" (repeat (cons sexp sexp
))))
410 "Alist of (MATCH TYPE).
412 MATCH should be a regexp matching the name of a symbol, and TYPE should
413 be a widget suitable for editing the value of that symbol. The TYPE
414 of the first entry where MATCH matches the name of the symbol will be
417 This is used for guessing the type of variables not declared with
419 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
422 (defcustom custom-guess-doc-alist
423 '(("\\`\\*?Non-nil " boolean
))
424 "Alist of (MATCH TYPE).
426 MATCH should be a regexp matching a documentation string, and TYPE
427 should be a widget suitable for editing the value of a variable with
428 that documentation string. The TYPE of the first entry where MATCH
429 matches the name of the symbol will be used.
431 This is used for guessing the type of variables not declared with
433 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
436 (defun custom-guess-type (symbol)
437 "Guess a widget suitable for editing the value of SYMBOL.
438 This is done by matching SYMBOL with `custom-guess-name-alist' and
439 if that fails, the doc string with `custom-guess-doc-alist'."
440 (let ((name (symbol-name symbol
))
441 (names custom-guess-name-alist
)
444 (setq current
(car names
)
446 (when (string-match (nth 0 current
) name
)
447 (setq found
(nth 1 current
)
450 (let ((doc (documentation-property symbol
'variable-documentation
))
451 (docs custom-guess-doc-alist
))
454 (setq current
(car docs
)
456 (when (string-match (nth 0 current
) doc
)
457 (setq found
(nth 1 current
)
461 ;;; Custom Mode Commands.
463 (defvar custom-options nil
464 "Customization widgets in the current buffer.")
467 "Set changes in all modified options."
469 (let ((children custom-options
))
470 (mapcar (lambda (child)
471 (when (eq (widget-get child
:custom-state
) 'modified
)
472 (widget-apply child
:custom-set
)))
475 (defun custom-save ()
476 "Set all modified group members and save them."
478 (let ((children custom-options
))
479 (mapcar (lambda (child)
480 (when (memq (widget-get child
:custom-state
) '(modified set
))
481 (widget-apply child
:custom-save
)))
485 (defvar custom-reset-menu
486 '(("Current" . custom-reset-current
)
487 ("Saved" . custom-reset-saved
)
488 ("Factory Settings" . custom-reset-factory
))
489 "Alist of actions for the `Reset' button.
490 The key is a string containing the name of the action, the value is a
491 lisp function taking the widget as an element which will be called
492 when the action is chosen.")
494 (defun custom-reset (event)
495 "Select item from reset menu."
496 (let* ((completion-ignore-case t
)
497 (answer (widget-choose "Reset to"
503 (defun custom-reset-current ()
504 "Reset all modified group members to their current value."
506 (let ((children custom-options
))
507 (mapcar (lambda (child)
508 (when (eq (widget-get child
:custom-state
) 'modified
)
509 (widget-apply child
:custom-reset-current
)))
512 (defun custom-reset-saved ()
513 "Reset all modified or set group members to their saved value."
515 (let ((children custom-options
))
516 (mapcar (lambda (child)
517 (when (eq (widget-get child
:custom-state
) 'modified
)
518 (widget-apply child
:custom-reset-current
)))
521 (defun custom-reset-factory ()
522 "Reset all modified, set, or saved group members to their factory settings."
524 (let ((children custom-options
))
525 (mapcar (lambda (child)
526 (when (eq (widget-get child
:custom-state
) 'modified
)
527 (widget-apply child
:custom-reset-current
)))
530 ;;; The Customize Commands
533 (defun customize (symbol)
534 "Customize SYMBOL, which must be a customization group."
535 (interactive (list (completing-read "Customize group: (default emacs) "
538 (get symbol
'custom-group
))
541 (when (stringp symbol
)
542 (if (string-equal "" symbol
)
544 (setq symbol
(intern symbol
))))
545 (custom-buffer-create (list (list symbol
'custom-group
))))
548 (defun customize-variable (symbol)
549 "Customize SYMBOL, which must be a variable."
550 (interactive (custom-variable-prompt))
551 (custom-buffer-create (list (list symbol
'custom-variable
))))
554 (defun customize-variable-other-window (symbol)
555 "Customize SYMBOL, which must be a variable.
556 Show the buffer in another window, but don't select it."
557 (interactive (custom-variable-prompt))
558 (custom-buffer-create-other-window (list (list symbol
'custom-variable
))))
561 (defun customize-face (&optional symbol
)
562 "Customize SYMBOL, which should be a face name or nil.
563 If SYMBOL is nil, customize all faces."
564 (interactive (list (completing-read "Customize face: (default all) "
565 obarray
'custom-facep
)))
566 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
568 (message "Looking for faces...")
569 (mapcar (lambda (symbol)
570 (setq found
(cons (list symbol
'custom-face
) found
)))
571 (nreverse (mapcar 'intern
572 (sort (mapcar 'symbol-name
(face-list))
575 (custom-buffer-create found
))
577 (setq symbol
(intern symbol
)))
578 (unless (symbolp symbol
)
579 (error "Should be a symbol %S" symbol
))
580 (custom-buffer-create (list (list symbol
'custom-face
)))))
583 (defun customize-face-other-window (&optional symbol
)
584 "Show customization buffer for FACE in other window."
585 (interactive (list (completing-read "Customize face: "
586 obarray
'custom-facep
)))
587 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
590 (setq symbol
(intern symbol
)))
591 (unless (symbolp symbol
)
592 (error "Should be a symbol %S" symbol
))
593 (custom-buffer-create-other-window (list (list symbol
'custom-face
)))))
596 (defun customize-customized ()
597 "Customize all already customized user options."
600 (mapatoms (lambda (symbol)
601 (and (get symbol
'saved-face
)
602 (custom-facep symbol
)
603 (setq found
(cons (list symbol
'custom-face
) found
)))
604 (and (get symbol
'saved-value
)
607 (cons (list symbol
'custom-variable
) found
)))))
609 (custom-buffer-create found
)
610 (error "No customized user options"))))
613 (defun customize-apropos (regexp &optional all
)
614 "Customize all user options matching REGEXP.
615 If ALL (e.g., started with a prefix key), include options which are not
617 (interactive "sCustomize regexp: \nP")
619 (mapatoms (lambda (symbol)
620 (when (string-match regexp
(symbol-name symbol
))
621 (when (get symbol
'custom-group
)
622 (setq found
(cons (list symbol
'custom-group
) found
)))
623 (when (custom-facep symbol
)
624 (setq found
(cons (list symbol
'custom-face
) found
)))
625 (when (and (boundp symbol
)
626 (or (get symbol
'saved-value
)
627 (get symbol
'factory-value
)
629 (get symbol
'variable-documentation
)
630 (user-variable-p symbol
))))
632 (cons (list symbol
'custom-variable
) found
))))))
634 (custom-buffer-create found
)
635 (error "No matches"))))
638 (defun custom-buffer-create (options)
639 "Create a buffer containing OPTIONS.
640 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
641 SYMBOL is a customization option, and WIDGET is a widget for editing
643 (kill-buffer (get-buffer-create "*Customization*"))
644 (switch-to-buffer (get-buffer-create "*Customization*"))
645 (custom-buffer-create-internal options
))
647 (defun custom-buffer-create-other-window (options)
648 "Create a buffer containing OPTIONS.
649 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
650 SYMBOL is a customization option, and WIDGET is a widget for editing
652 (kill-buffer (get-buffer-create "*Customization*"))
653 (let ((window (selected-window)))
654 (switch-to-buffer-other-window (get-buffer-create "*Customization*"))
655 (custom-buffer-create-internal options
)
656 (select-window window
)))
659 (defun custom-buffer-create-internal (options)
660 (message "Creating customization buffer...")
662 (widget-insert "This is a customization buffer.
663 Push RET or click mouse-2 on the word ")
664 ;; (put-text-property 1 2 'start-open nil)
665 (widget-create 'info-link
667 :help-echo
"Read the online help."
668 "(custom)The Customization Buffer")
669 (widget-insert " for more information.\n\n")
671 (if (= (length options
) 1)
672 (mapcar (lambda (entry)
673 (widget-create (nth 1 entry
)
674 :custom-state
'unknown
675 :tag
(custom-unlispify-tag-name
677 :value
(nth 0 entry
)))
680 (length (length options
)))
681 (mapcar (lambda (entry)
683 (message "Creating customization items %2d%%..."
684 (/ (* 100.0 count
) length
))
685 (widget-create (nth 1 entry
)
686 :tag
(custom-unlispify-tag-name
688 :value
(nth 0 entry
))
689 (setq count
(1+ count
))
690 (unless (eq (preceding-char) ?
\n)
691 (widget-insert "\n"))
692 (widget-insert "\n")))
694 (unless (eq (preceding-char) ?
\n)
695 (widget-insert "\n"))
697 (message "Creating customization magic...")
698 (mapcar 'custom-magic-reset custom-options
)
699 (message "Creating customization buttons...")
700 (widget-create 'push-button
702 :help-echo
"Set all modifications for this session."
703 :action
(lambda (widget &optional event
)
706 (widget-create 'push-button
709 Make the modifications default for future sessions."
710 :action
(lambda (widget &optional event
)
713 (widget-create 'push-button
715 :help-echo
"Undo all modifications."
716 :action
(lambda (widget &optional event
)
717 (custom-reset event
)))
719 (widget-create 'push-button
721 :help-echo
"Bury the buffer."
722 :action
(lambda (widget &optional event
)
724 ;; Steal button release event.
725 (if (and (fboundp 'button-press-event-p
)
726 (fboundp 'next-command-event
))
729 (button-press-event-p event
)
730 (next-command-event))
732 (when (memq 'down
(event-modifiers event
))
735 (message "Creating customization setup...")
737 (goto-char (point-min))
738 (message "Creating customization buffer...done"))
740 ;;; Modification of Basic Widgets.
742 ;; We add extra properties to the basic widgets needed here. This is
743 ;; fine, as long as we are careful to stay within out own namespace.
745 ;; We want simple widgets to be displayed by default, but complex
746 ;; widgets to be hidden.
748 (widget-put (get 'item
'widget-type
) :custom-show t
)
749 (widget-put (get 'editable-field
'widget-type
)
750 :custom-show
(lambda (widget value
)
751 (let ((pp (pp-to-string value
)))
752 (cond ((string-match "\n" pp
)
757 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
759 ;;; The `custom-manual' Widget.
761 (define-widget 'custom-manual
'info-link
762 "Link to the manual entry for this customization option."
763 :help-echo
"Read the manual entry for this option."
766 ;;; The `custom-magic' Widget.
768 (defface custom-invalid-face
'((((class color
))
769 (:foreground
"yellow" :background
"red"))
771 (:bold t
:italic t
:underline t
)))
772 "Face used when the customize item is invalid.")
774 (defface custom-rogue-face
'((((class color
))
775 (:foreground
"pink" :background
"black"))
778 "Face used when the customize item is not defined for customization.")
780 (defface custom-modified-face
'((((class color
))
781 (:foreground
"white" :background
"blue"))
784 "Face used when the customize item has been modified.")
786 (defface custom-set-face
'((((class color
))
787 (:foreground
"blue" :background
"white"))
790 "Face used when the customize item has been set.")
792 (defface custom-changed-face
'((((class color
))
793 (:foreground
"white" :background
"blue"))
796 "Face used when the customize item has been changed.")
798 (defface custom-saved-face
'((t (:underline t
)))
799 "Face used when the customize item has been saved.")
801 (defcustom custom-magic-alist
'((nil "#" underline
"\
802 uninitialized, you should not see this.")
803 (unknown "?" italic
"\
804 unknown, you should not see this.")
805 (hidden "-" default
"\
806 hidden, press the state button to show.")
807 (invalid "x" custom-invalid-face
"\
808 the value displayed for this item is invalid and cannot be set.")
809 (modified "*" custom-modified-face
"\
810 you have edited the item, and can now set it.")
811 (set "+" custom-set-face
"\
812 you have set this item, but not saved it.")
813 (changed ":" custom-changed-face
"\
814 this item has been changed outside customize.")
815 (saved "!" custom-saved-face
"\
816 this item has been saved.")
817 (rogue "@" custom-rogue-face
"\
818 this item is not prepared for customization.")
820 this item is unchanged from its factory setting."))
821 "Alist of customize option states.
822 Each entry is of the form (STATE MAGIC FACE DESCRIPTION), where
824 STATE is one of the following symbols:
827 For internal use, should never occur.
829 For internal use, should never occur.
831 This item is not being displayed.
833 This item is modified, but has an invalid form.
835 This item is modified, and has a valid form.
837 This item has been set but not saved.
839 The current value of this item has been changed temporarily.
841 This item is marked for saving.
843 This item has no customization information.
845 This item is unchanged from the factory default.
847 MAGIC is a string used to present that state.
849 FACE is a face used to present the state.
851 DESCRIPTION is a string describing the state.
853 The list should be sorted most significant first."
854 :type
'(list (checklist :inline t
856 (string :tag
"Magic")
858 (string :tag
"Description"))
859 (group (const unknown
)
860 (string :tag
"Magic")
862 (string :tag
"Description"))
863 (group (const hidden
)
864 (string :tag
"Magic")
866 (string :tag
"Description"))
867 (group (const invalid
)
868 (string :tag
"Magic")
870 (string :tag
"Description"))
871 (group (const modified
)
872 (string :tag
"Magic")
874 (string :tag
"Description"))
876 (string :tag
"Magic")
878 (string :tag
"Description"))
879 (group (const changed
)
880 (string :tag
"Magic")
882 (string :tag
"Description"))
884 (string :tag
"Magic")
886 (string :tag
"Description"))
888 (string :tag
"Magic")
890 (string :tag
"Description"))
891 (group (const factory
)
892 (string :tag
"Magic")
894 (string :tag
"Description")))
895 (editable-list :inline t
897 (string :tag
"Magic")
899 (string :tag
"Description"))))
901 :group
'custom-faces
)
903 (defcustom custom-magic-show
'long
904 "Show long description of the state of each customization option."
905 :type
'(choice (const :tag
"no" nil
)
910 (defcustom custom-magic-show-button t
911 "Show a magic button indicating the state of each customization option."
915 (define-widget 'custom-magic
'default
916 "Show and manipulate state for a customization option."
918 :action
'widget-choice-item-action
920 :value-create
'custom-magic-value-create
921 :value-delete
'widget-children-value-delete
)
923 (defun custom-magic-value-create (widget)
924 ;; Create compact status report for WIDGET.
925 (let* ((parent (widget-get widget
:parent
))
926 (state (widget-get parent
:custom-state
))
927 (entry (assq state custom-magic-alist
))
928 (magic (nth 1 entry
))
931 (lisp (eq (widget-get parent
:custom-form
) 'lisp
))
933 (when custom-magic-show
934 (push (widget-create-child-and-convert widget
'choice-item
936 Change the state of this item."
941 (if (eq custom-magic-show
'long
)
943 (insert (symbol-name state
)))
947 (when custom-magic-show-button
948 (when custom-magic-show
949 (let ((indent (widget-get parent
:indent
)))
951 (insert-char ? indent
))))
952 (push (widget-create-child-and-convert widget
'choice-item
954 :help-echo
"Change the state."
957 (concat "(" magic
")")
958 (concat "[" magic
"]")))
961 (widget-put widget
:children children
)))
963 (defun custom-magic-reset (widget)
964 "Redraw the :custom-magic property of WIDGET."
965 (let ((magic (widget-get widget
:custom-magic
)))
966 (widget-value-set magic
(widget-value magic
))))
968 ;;; The `custom-level' Widget.
970 (define-widget 'custom-level
'item
971 "The custom level buttons."
973 :help-echo
"Expand or collapse this item."
974 :action
'custom-level-action
)
976 (defun custom-level-action (widget &optional event
)
977 "Toggle visibility for parent to WIDGET."
978 (let* ((parent (widget-get widget
:parent
))
979 (state (widget-get parent
:custom-state
)))
980 (cond ((memq state
'(invalid modified
))
981 (error "There are unset changes"))
983 (widget-put parent
:custom-state
'unknown
))
985 (widget-put parent
:custom-state
'hidden
)))
986 (custom-redraw parent
)))
988 ;;; The `custom' Widget.
990 (define-widget 'custom
'default
991 "Customize a user option."
992 :convert-widget
'custom-convert-widget
993 :format
"%l%[%t%]: %v%m%h%a"
994 :format-handler
'custom-format-handler
995 :notify
'custom-notify
997 :custom-state
'hidden
998 :documentation-property
'widget-subclass-responsibility
999 :value-create
'widget-subclass-responsibility
1000 :value-delete
'widget-children-value-delete
1001 :value-get
'widget-item-value-get
1002 :validate
'widget-editable-list-validate
1003 :match
(lambda (widget value
) (symbolp value
)))
1005 (defun custom-convert-widget (widget)
1006 ;; Initialize :value and :tag from :args in WIDGET.
1007 (let ((args (widget-get widget
:args
)))
1009 (widget-put widget
:value
(widget-apply widget
1010 :value-to-internal
(car args
)))
1011 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1012 (widget-put widget
:args nil
)))
1015 (defun custom-format-handler (widget escape
)
1016 ;; We recognize extra escape sequences.
1017 (let* ((buttons (widget-get widget
:buttons
))
1018 (state (widget-get widget
:custom-state
))
1019 (level (widget-get widget
:custom-level
)))
1020 (cond ((eq escape ?l
)
1022 (push (widget-create-child-and-convert
1023 widget
'custom-level
(make-string level ?
*))
1026 (widget-put widget
:buttons buttons
)))
1028 (when (eq state
'hidden
)
1029 (widget-insert " ...")))
1031 (and (eq (preceding-char) ?
\n)
1032 (widget-get widget
:indent
)
1033 (insert-char ?
(widget-get widget
:indent
)))
1034 (let ((magic (widget-create-child-and-convert
1035 widget
'custom-magic nil
)))
1036 (widget-put widget
:custom-magic magic
)
1037 (push magic buttons
)
1038 (widget-put widget
:buttons buttons
)))
1040 (let* ((symbol (widget-get widget
:value
))
1041 (links (get symbol
'custom-links
))
1042 (many (> (length links
) 2)))
1044 (and (eq (preceding-char) ?
\n)
1045 (widget-get widget
:indent
)
1046 (insert-char ?
(widget-get widget
:indent
)))
1047 (insert "See also ")
1049 (push (widget-create-child-and-convert widget
(car links
))
1051 (setq links
(cdr links
))
1060 (widget-put widget
:buttons buttons
))))
1062 (widget-default-format-handler widget escape
)))))
1064 (defun custom-notify (widget &rest args
)
1065 "Keep track of changes."
1066 (unless (memq (widget-get widget
:custom-state
) '(nil unknown hidden
))
1067 (widget-put widget
:custom-state
'modified
))
1068 (let ((buffer-undo-list t
))
1069 (custom-magic-reset widget
))
1070 (apply 'widget-default-notify widget args
))
1072 (defun custom-redraw (widget)
1073 "Redraw WIDGET with current settings."
1075 (from (marker-position (widget-get widget
:from
)))
1076 (to (marker-position (widget-get widget
:to
))))
1078 (widget-value-set widget
(widget-value widget
))
1079 (custom-redraw-magic widget
))
1080 (when (and (>= pos from
) (<= pos to
))
1083 (defun custom-redraw-magic (widget)
1084 "Redraw WIDGET state with current settings."
1086 (let ((magic (widget-get widget
:custom-magic
)))
1089 (widget-value-set magic
(widget-value magic
))
1090 (when (setq widget
(widget-get widget
:group
))
1091 (custom-group-state-update widget
))))
1094 (defun custom-show (widget value
)
1095 "Non-nil if WIDGET should be shown with VALUE by default."
1096 (let ((show (widget-get widget
:custom-show
)))
1102 (funcall show widget value
)))))
1104 (defvar custom-load-recursion nil
1105 "Hack to avoid recursive dependencies.")
1107 (defun custom-load-symbol (symbol)
1108 "Load all dependencies for SYMBOL."
1109 (unless custom-load-recursion
1110 (let ((custom-load-recursion t
)
1111 (loads (get symbol
'custom-loads
))
1114 (setq load
(car loads
)
1116 (cond ((symbolp load
)
1120 ((assoc load load-history
))
1126 (defun custom-load-widget (widget)
1127 "Load all dependencies for WIDGET."
1128 (custom-load-symbol (widget-value widget
)))
1130 ;;; The `custom-variable' Widget.
1132 (defface custom-variable-sample-face
'((t (:underline t
)))
1133 "Face used for unpushable variable tags."
1134 :group
'custom-faces
)
1136 (defface custom-variable-button-face
'((t (:underline t
:bold t
)))
1137 "Face used for pushable variable tags."
1138 :group
'custom-faces
)
1140 (define-widget 'custom-variable
'custom
1141 "Customize variable."
1142 :format
"%l%v%m%h%a"
1143 :help-echo
"Set or reset this variable."
1144 :documentation-property
'variable-documentation
1146 :custom-menu
'custom-variable-menu-create
1148 :value-create
'custom-variable-value-create
1149 :action
'custom-variable-action
1150 :custom-set
'custom-variable-set
1151 :custom-save
'custom-variable-save
1152 :custom-reset-current
'custom-redraw
1153 :custom-reset-saved
'custom-variable-reset-saved
1154 :custom-reset-factory
'custom-variable-reset-factory
)
1156 (defun custom-variable-type (symbol)
1157 "Return a widget suitable for editing the value of SYMBOL.
1158 If SYMBOL has a `custom-type' property, use that.
1159 Otherwise, look up symbol in `custom-guess-type-alist'."
1160 (let* ((type (or (get symbol
'custom-type
)
1161 (and (not (get symbol
'factory-value
))
1162 (custom-guess-type symbol
))
1164 (options (get symbol
'custom-options
))
1165 (tmp (if (listp type
)
1169 (widget-put tmp
:options options
))
1172 (defun custom-variable-value-create (widget)
1173 "Here is where you edit the variables value."
1174 (custom-load-widget widget
)
1175 (let* ((buttons (widget-get widget
:buttons
))
1176 (children (widget-get widget
:children
))
1177 (form (widget-get widget
:custom-form
))
1178 (state (widget-get widget
:custom-state
))
1179 (symbol (widget-get widget
:value
))
1180 (tag (widget-get widget
:tag
))
1181 (type (custom-variable-type symbol
))
1182 (conv (widget-convert type
))
1183 (value (if (default-boundp symbol
)
1184 (default-value symbol
)
1185 (widget-get conv
:value
))))
1186 ;; If the widget is new, the child determine whether it is hidden.
1188 ((custom-show type value
)
1189 (setq state
'unknown
))
1191 (setq state
'hidden
)))
1192 ;; If we don't know the state, see if we need to edit it in lisp form.
1193 (when (eq state
'unknown
)
1194 (unless (widget-apply conv
:match value
)
1195 ;; (widget-apply (widget-convert type) :match value)
1197 ;; Now we can create the child widget.
1198 (cond ((eq state
'hidden
)
1199 ;; Indicate hidden value.
1200 (push (widget-create-child-and-convert
1202 :format
"%{%t%}: ..."
1203 :sample-face
'custom-variable-sample-face
1208 ;; In lisp mode edit the saved value when possible.
1209 (let* ((value (cond ((get symbol
'saved-value
)
1210 (car (get symbol
'saved-value
)))
1211 ((get symbol
'factory-value
)
1212 (car (get symbol
'factory-value
)))
1213 ((default-boundp symbol
)
1214 (custom-quote (default-value symbol
)))
1216 (custom-quote (widget-get conv
:value
))))))
1217 (push (widget-create-child-and-convert
1219 :button-face
'custom-variable-button-face
1220 :tag
(symbol-name symbol
)
1226 (push (widget-create-child-and-convert
1229 :button-face
'custom-variable-button-face
1230 :sample-face
'custom-variable-sample-face
1233 ;; Now update the state.
1234 (unless (eq (preceding-char) ?
\n)
1235 (widget-insert "\n"))
1236 (if (eq state
'hidden
)
1237 (widget-put widget
:custom-state state
)
1238 (custom-variable-state-set widget
))
1239 (widget-put widget
:custom-form form
)
1240 (widget-put widget
:buttons buttons
)
1241 (widget-put widget
:children children
)))
1243 (defun custom-variable-state-set (widget)
1244 "Set the state of WIDGET."
1245 (let* ((symbol (widget-value widget
))
1246 (value (if (default-boundp symbol
)
1247 (default-value symbol
)
1248 (widget-get widget
:value
)))
1250 (state (cond ((setq tmp
(get symbol
'customized-value
))
1251 (if (condition-case nil
1252 (equal value
(eval (car tmp
)))
1256 ((setq tmp
(get symbol
'saved-value
))
1257 (if (condition-case nil
1258 (equal value
(eval (car tmp
)))
1262 ((setq tmp
(get symbol
'factory-value
))
1263 (if (condition-case nil
1264 (equal value
(eval (car tmp
)))
1269 (widget-put widget
:custom-state state
)))
1271 (defvar custom-variable-menu
1272 '(("Edit" . custom-variable-edit
)
1273 ("Edit Lisp" . custom-variable-edit-lisp
)
1274 ("Set" . custom-variable-set
)
1275 ("Save" . custom-variable-save
)
1276 ("Reset to Current" . custom-redraw
)
1277 ("Reset to Saved" . custom-variable-reset-saved
)
1278 ("Reset to Factory Settings" . custom-variable-reset-factory
))
1279 "Alist of actions for the `custom-variable' widget.
1280 The key is a string containing the name of the action, the value is a
1281 lisp function taking the widget as an element which will be called
1282 when the action is chosen.")
1284 (defun custom-variable-action (widget &optional event
)
1285 "Show the menu for `custom-variable' WIDGET.
1286 Optional EVENT is the location for the menu."
1287 (if (eq (widget-get widget
:custom-state
) 'hidden
)
1289 (widget-put widget
:custom-state
'unknown
)
1290 (custom-redraw widget
))
1291 (let* ((completion-ignore-case t
)
1292 (answer (widget-choose (custom-unlispify-tag-name
1293 (widget-get widget
:value
))
1294 custom-variable-menu
1297 (funcall answer widget
)))))
1299 (defun custom-variable-edit (widget)
1300 "Edit value of WIDGET."
1301 (widget-put widget
:custom-state
'unknown
)
1302 (widget-put widget
:custom-form
'edit
)
1303 (custom-redraw widget
))
1305 (defun custom-variable-edit-lisp (widget)
1306 "Edit the lisp representation of the value of WIDGET."
1307 (widget-put widget
:custom-state
'unknown
)
1308 (widget-put widget
:custom-form
'lisp
)
1309 (custom-redraw widget
))
1311 (defun custom-variable-set (widget)
1312 "Set the current value for the variable being edited by WIDGET."
1313 (let ((form (widget-get widget
:custom-form
))
1314 (state (widget-get widget
:custom-state
))
1315 (child (car (widget-get widget
:children
)))
1316 (symbol (widget-value widget
))
1318 (cond ((eq state
'hidden
)
1319 (error "Cannot set hidden variable."))
1320 ((setq val
(widget-apply child
:validate
))
1321 (goto-char (widget-get val
:from
))
1322 (error "%s" (widget-get val
:error
)))
1324 (set-default symbol
(eval (setq val
(widget-value child
))))
1325 (put symbol
'customized-value
(list val
)))
1327 (set-default symbol
(setq val
(widget-value child
)))
1328 (put symbol
'customized-value
(list (custom-quote val
)))))
1329 (custom-variable-state-set widget
)
1330 (custom-redraw-magic widget
)))
1332 (defun custom-variable-save (widget)
1333 "Set the default value for the variable being edited by WIDGET."
1334 (let ((form (widget-get widget
:custom-form
))
1335 (state (widget-get widget
:custom-state
))
1336 (child (car (widget-get widget
:children
)))
1337 (symbol (widget-value widget
))
1339 (cond ((eq state
'hidden
)
1340 (error "Cannot set hidden variable."))
1341 ((setq val
(widget-apply child
:validate
))
1342 (goto-char (widget-get val
:from
))
1343 (error "%s" (widget-get val
:error
)))
1345 (put symbol
'saved-value
(list (widget-value child
)))
1346 (set-default symbol
(eval (widget-value child
))))
1349 'saved-value
(list (custom-quote (widget-value
1351 (set-default symbol
(widget-value child
))))
1352 (put symbol
'customized-value nil
)
1354 (custom-variable-state-set widget
)
1355 (custom-redraw-magic widget
)))
1357 (defun custom-variable-reset-saved (widget)
1358 "Restore the saved value for the variable being edited by WIDGET."
1359 (let ((symbol (widget-value widget
)))
1360 (if (get symbol
'saved-value
)
1362 (set-default symbol
(eval (car (get symbol
'saved-value
))))
1364 (error "No saved value for %s" symbol
))
1365 (put symbol
'customized-value nil
)
1366 (widget-put widget
:custom-state
'unknown
)
1367 (custom-redraw widget
)))
1369 (defun custom-variable-reset-factory (widget)
1370 "Restore the factory setting for the variable being edited by WIDGET."
1371 (let ((symbol (widget-value widget
)))
1372 (if (get symbol
'factory-value
)
1373 (set-default symbol
(eval (car (get symbol
'factory-value
))))
1374 (error "No factory default for %S" symbol
))
1375 (put symbol
'customized-value nil
)
1376 (when (get symbol
'saved-value
)
1377 (put symbol
'saved-value nil
)
1379 (widget-put widget
:custom-state
'unknown
)
1380 (custom-redraw widget
)))
1382 ;;; The `custom-face-edit' Widget.
1384 (define-widget 'custom-face-edit
'checklist
1385 "Edit face attributes."
1389 :button-args
'(:help-echo
"Control whether this attribute have any effect.")
1390 :args
(mapcar (lambda (att)
1393 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
1394 (list 'const
:format
"" :value
(nth 0 att
))
1396 custom-face-attributes
))
1398 ;;; The `custom-display' Widget.
1400 (define-widget 'custom-display
'menu-choice
1401 "Select a display type."
1404 :help-echo
"Specify frames where the face attributes should be used."
1405 :args
'((const :tag
"all" t
)
1409 :args
((group :sibling-args
(:help-echo
"\
1410 Only match the specified window systems.")
1411 (const :format
"Type: "
1413 (checklist :inline t
1416 :sibling-args
(:help-echo
"\
1417 The X11 Window System.")
1419 (const :format
"PM "
1420 :sibling-args
(:help-echo
"\
1421 OS/2 Presentation Manager.")
1423 (const :format
"Win32 "
1424 :sibling-args
(:help-echo
"\
1427 (const :format
"DOS "
1428 :sibling-args
(:help-echo
"\
1431 (const :format
"TTY%n"
1432 :sibling-args
(:help-echo
"\
1433 Plain text terminals.")
1435 (group :sibling-args
(:help-echo
"\
1436 Only match the frames with the specified color support.")
1437 (const :format
"Class: "
1439 (checklist :inline t
1441 (const :format
"Color "
1442 :sibling-args
(:help-echo
"\
1443 Match color frames.")
1445 (const :format
"Grayscale "
1446 :sibling-args
(:help-echo
"\
1447 Match grayscale frames.")
1449 (const :format
"Monochrome%n"
1450 :sibling-args
(:help-echo
"\
1451 Match frames with no color support.")
1453 (group :sibling-args
(:help-echo
"\
1454 Only match frames with the specified intensity.")
1456 Background brightness: "
1458 (checklist :inline t
1460 (const :format
"Light "
1461 :sibling-args
(:help-echo
"\
1462 Match frames with light backgrounds.")
1464 (const :format
"Dark\n"
1465 :sibling-args
(:help-echo
"\
1466 Match frames with dark backgrounds.")
1469 ;;; The `custom-face' Widget.
1471 (defface custom-face-tag-face
'((t (:underline t
)))
1472 "Face used for face tags."
1473 :group
'custom-faces
)
1475 (define-widget 'custom-face
'custom
1477 :format
"%l%{%t%}: %s%m%h%a%v"
1478 :format-handler
'custom-face-format-handler
1479 :sample-face
'custom-face-tag-face
1480 :help-echo
"Set or reset this face."
1481 :documentation-property
'(lambda (face)
1482 (face-doc-string face
))
1483 :value-create
'custom-face-value-create
1484 :action
'custom-face-action
1485 :custom-form
'selected
1486 :custom-set
'custom-face-set
1487 :custom-save
'custom-face-save
1488 :custom-reset-current
'custom-redraw
1489 :custom-reset-saved
'custom-face-reset-saved
1490 :custom-reset-factory
'custom-face-reset-factory
1491 :custom-menu
'custom-face-menu-create
)
1493 (defun custom-face-format-handler (widget escape
)
1494 ;; We recognize extra escape sequences.
1496 (symbol (widget-get widget
:value
)))
1497 (cond ((eq escape ?s
)
1498 (and (string-match "XEmacs" emacs-version
)
1499 ;; XEmacs cannot display initialized faces.
1500 (not (custom-facep symbol
))
1501 (copy-face 'custom-face-empty symbol
))
1502 (setq child
(widget-create-child-and-convert
1504 :format
"(%{%t%})\n"
1508 (custom-format-handler widget escape
)))
1511 :buttons
(cons child
(widget-get widget
:buttons
))))))
1513 (define-widget 'custom-face-all
'editable-list
1514 "An editable list of display specifications and attributes."
1515 :entry-format
"%i %d %v"
1516 :insert-button-args
'(:help-echo
"Insert new display specification here.")
1517 :append-button-args
'(:help-echo
"Append new display specification here.")
1518 :delete-button-args
'(:help-echo
"Delete this display specification.")
1519 :args
'((group :format
"%v" custom-display custom-face-edit
)))
1521 (defconst custom-face-all
(widget-convert 'custom-face-all
)
1522 "Converted version of the `custom-face-all' widget.")
1524 (define-widget 'custom-display-unselected
'item
1525 "A display specification that doesn't match the selected display."
1526 :match
'custom-display-unselected-match
)
1528 (defun custom-display-unselected-match (widget value
)
1529 "Non-nil if VALUE is an unselected display specification."
1531 (eq (length value
) 2)
1532 (not (custom-display-match-frame value
(selected-frame)))))
1534 (define-widget 'custom-face-selected
'group
1535 "Edit the attributes of the selected display in a face specification."
1536 :args
'((repeat :format
""
1538 (group custom-display-unselected sexp
))
1539 (group (sexp :format
"") custom-face-edit
)
1544 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
1545 "Converted version of the `custom-face-selected' widget.")
1547 (defun custom-face-value-create (widget)
1548 ;; Create a list of the display specifications.
1549 (unless (eq (preceding-char) ?
\n)
1551 (when (not (eq (widget-get widget
:custom-state
) 'hidden
))
1552 (message "Creating face editor...")
1553 (custom-load-widget widget
)
1554 (let* ((symbol (widget-value widget
))
1555 (spec (or (get symbol
'saved-face
)
1556 (get symbol
'factory-face
)
1557 ;; Attempt to construct it.
1558 (list (list t
(custom-face-attributes-get
1559 symbol
(selected-frame))))))
1560 (form (widget-get widget
:custom-form
))
1561 (indent (widget-get widget
:indent
))
1562 (edit (widget-create-child-and-convert
1564 (cond ((and (eq form
'selected
)
1565 (widget-apply custom-face-selected
:match spec
))
1566 (when indent
(insert-char ?\ indent
))
1567 'custom-face-selected
)
1568 ((and (not (eq form
'lisp
))
1569 (widget-apply custom-face-all
:match spec
))
1572 (when indent
(insert-char ?\ indent
))
1575 (custom-face-state-set widget
)
1576 (widget-put widget
:children
(list edit
)))
1577 (message "Creating face editor...done")))
1579 (defvar custom-face-menu
1580 '(("Edit Selected" . custom-face-edit-selected
)
1581 ("Edit All" . custom-face-edit-all
)
1582 ("Edit Lisp" . custom-face-edit-lisp
)
1583 ("Set" . custom-face-set
)
1584 ("Save" . custom-face-save
)
1585 ("Reset to Saved" . custom-face-reset-saved
)
1586 ("Reset to Factory Setting" . custom-face-reset-factory
))
1587 "Alist of actions for the `custom-face' widget.
1588 The key is a string containing the name of the action, the value is a
1589 lisp function taking the widget as an element which will be called
1590 when the action is chosen.")
1592 (defun custom-face-edit-selected (widget)
1593 "Edit selected attributes of the value of WIDGET."
1594 (widget-put widget
:custom-state
'unknown
)
1595 (widget-put widget
:custom-form
'selected
)
1596 (custom-redraw widget
))
1598 (defun custom-face-edit-all (widget)
1599 "Edit all attributes of the value of WIDGET."
1600 (widget-put widget
:custom-state
'unknown
)
1601 (widget-put widget
:custom-form
'all
)
1602 (custom-redraw widget
))
1604 (defun custom-face-edit-lisp (widget)
1605 "Edit the lisp representation of the value of WIDGET."
1606 (widget-put widget
:custom-state
'unknown
)
1607 (widget-put widget
:custom-form
'lisp
)
1608 (custom-redraw widget
))
1610 (defun custom-face-state-set (widget)
1611 "Set the state of WIDGET."
1612 (let ((symbol (widget-value widget
)))
1613 (widget-put widget
:custom-state
(cond ((get symbol
'customized-face
)
1615 ((get symbol
'saved-face
)
1617 ((get symbol
'factory-face
)
1622 (defun custom-face-action (widget &optional event
)
1623 "Show the menu for `custom-face' WIDGET.
1624 Optional EVENT is the location for the menu."
1625 (if (eq (widget-get widget
:custom-state
) 'hidden
)
1627 (widget-put widget
:custom-state
'unknown
)
1628 (custom-redraw widget
))
1629 (let* ((completion-ignore-case t
)
1630 (symbol (widget-get widget
:value
))
1631 (answer (widget-choose (custom-unlispify-tag-name symbol
)
1632 custom-face-menu event
)))
1634 (funcall answer widget
)))))
1636 (defun custom-face-set (widget)
1637 "Make the face attributes in WIDGET take effect."
1638 (let* ((symbol (widget-value widget
))
1639 (child (car (widget-get widget
:children
)))
1640 (value (widget-value child
)))
1641 (put symbol
'customized-face value
)
1642 (when (fboundp 'copy-face
)
1643 (copy-face 'custom-face-empty symbol
))
1644 (custom-face-display-set symbol value
)
1645 (custom-face-state-set widget
)
1646 (custom-redraw-magic widget
)))
1648 (defun custom-face-save (widget)
1649 "Make the face attributes in WIDGET default."
1650 (let* ((symbol (widget-value widget
))
1651 (child (car (widget-get widget
:children
)))
1652 (value (widget-value child
)))
1653 (when (fboundp 'copy-face
)
1654 (copy-face 'custom-face-empty symbol
))
1655 (custom-face-display-set symbol value
)
1656 (put symbol
'saved-face value
)
1657 (put symbol
'customized-face nil
)
1658 (custom-face-state-set widget
)
1659 (custom-redraw-magic widget
)))
1661 (defun custom-face-reset-saved (widget)
1662 "Restore WIDGET to the face's default attributes."
1663 (let* ((symbol (widget-value widget
))
1664 (child (car (widget-get widget
:children
)))
1665 (value (get symbol
'saved-face
)))
1667 (error "No saved value for this face"))
1668 (put symbol
'customized-face nil
)
1669 (when (fboundp 'copy-face
)
1670 (copy-face 'custom-face-empty symbol
))
1671 (custom-face-display-set symbol value
)
1672 (widget-value-set child value
)
1673 (custom-face-state-set widget
)
1674 (custom-redraw-magic widget
)))
1676 (defun custom-face-reset-factory (widget)
1677 "Restore WIDGET to the face's factory settings."
1678 (let* ((symbol (widget-value widget
))
1679 (child (car (widget-get widget
:children
)))
1680 (value (get symbol
'factory-face
)))
1682 (error "No factory default for this face"))
1683 (put symbol
'customized-face nil
)
1684 (when (get symbol
'saved-face
)
1685 (put symbol
'saved-face nil
)
1687 (when (fboundp 'copy-face
)
1688 (copy-face 'custom-face-empty symbol
))
1689 (custom-face-display-set symbol value
)
1690 (widget-value-set child value
)
1691 (custom-face-state-set widget
)
1692 (custom-redraw-magic widget
)))
1694 ;;; The `face' Widget.
1696 (define-widget 'face
'default
1697 "Select and customize a face."
1698 :convert-widget
'widget-item-convert-widget
1699 :format
"%[%t%]: %v"
1702 :value-create
'widget-face-value-create
1703 :value-delete
'widget-face-value-delete
1704 :value-get
'widget-item-value-get
1705 :validate
'widget-editable-list-validate
1706 :action
'widget-face-action
1707 :match
'(lambda (widget value
) (symbolp value
)))
1709 (defun widget-face-value-create (widget)
1710 ;; Create a `custom-face' child.
1711 (let* ((symbol (widget-value widget
))
1712 (child (widget-create-child-and-convert
1714 :format
"%t %s%m%h%v"
1717 (custom-magic-reset child
)
1718 (setq custom-options
(cons child custom-options
))
1719 (widget-put widget
:children
(list child
))))
1721 (defun widget-face-value-delete (widget)
1722 ;; Remove the child from the options.
1723 (let ((child (car (widget-get widget
:children
))))
1724 (setq custom-options
(delq child custom-options
))
1725 (widget-children-value-delete widget
)))
1727 (defvar face-history nil
1728 "History of entered face names.")
1730 (defun widget-face-action (widget &optional event
)
1731 "Prompt for a face."
1732 (let ((answer (completing-read "Face: "
1733 (mapcar (lambda (face)
1734 (list (symbol-name face
)))
1738 (unless (zerop (length answer
))
1739 (widget-value-set widget
(intern answer
))
1740 (widget-apply widget
:notify widget event
)
1743 ;;; The `hook' Widget.
1745 (define-widget 'hook
'list
1747 :convert-widget
'custom-hook-convert-widget
1750 (defun custom-hook-convert-widget (widget)
1751 ;; Handle `:custom-options'.
1752 (let* ((options (widget-get widget
:options
))
1753 (other `(editable-list :inline t
1754 :entry-format
"%i %d%v"
1755 (function :format
" %v")))
1757 (list `(checklist :inline t
1758 ,@(mapcar (lambda (entry)
1759 `(function-item ,entry
))
1763 (widget-put widget
:args args
)
1766 ;;; The `custom-group' Widget.
1768 (defcustom custom-group-tag-faces
'(custom-group-tag-face-1)
1769 ;; In XEmacs, this ought to play games with font size.
1770 "Face used for group tags.
1771 The first member is used for level 1 groups, the second for level 2,
1772 and so forth. The remaining group tags are shown with
1773 `custom-group-tag-face'."
1774 :type
'(repeat face
)
1775 :group
'custom-faces
)
1777 (defface custom-group-tag-face-1
'((((class color
)
1779 (:foreground
"pink" :underline t
))
1782 (:foreground
"red" :underline t
))
1784 "Face used for group tags.")
1786 (defface custom-group-tag-face
'((((class color
)
1788 (:foreground
"light blue" :underline t
))
1791 (:foreground
"blue" :underline t
))
1793 "Face used for low level group tags."
1794 :group
'custom-faces
)
1796 (define-widget 'custom-group
'custom
1798 :format
"%l%{%t%}:%L\n%m%h%a%v"
1799 :sample-face-get
'custom-group-sample-face-get
1800 :documentation-property
'group-documentation
1801 :help-echo
"Set or reset all members of this group."
1802 :value-create
'custom-group-value-create
1803 :action
'custom-group-action
1804 :custom-set
'custom-group-set
1805 :custom-save
'custom-group-save
1806 :custom-reset-current
'custom-group-reset-current
1807 :custom-reset-saved
'custom-group-reset-saved
1808 :custom-reset-factory
'custom-group-reset-factory
1809 :custom-menu
'custom-group-menu-create
)
1811 (defun custom-group-sample-face-get (widget)
1812 ;; Use :sample-face.
1813 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
1814 'custom-group-tag-face
))
1816 (defun custom-group-value-create (widget)
1817 (let ((state (widget-get widget
:custom-state
)))
1818 (unless (eq state
'hidden
)
1819 (message "Creating group...")
1820 (custom-load-widget widget
)
1821 (let* ((level (widget-get widget
:custom-level
))
1822 (symbol (widget-value widget
))
1823 (members (get symbol
'custom-group
))
1824 (prefixes (widget-get widget
:custom-prefixes
))
1825 (custom-prefix-list (custom-prefix-add symbol prefixes
))
1826 (length (length members
))
1828 (children (mapcar (lambda (entry)
1829 (widget-insert "\n")
1830 (message "Creating group members... %2d%%"
1831 (/ (* 100.0 count
) length
))
1832 (setq count
(1+ count
))
1834 (widget-create-child-and-convert
1835 widget
(nth 1 entry
)
1837 :tag
(custom-unlispify-tag-name
1839 :custom-prefixes custom-prefix-list
1840 :custom-level
(1+ level
)
1841 :value
(nth 0 entry
))
1842 (unless (eq (preceding-char) ?
\n)
1843 (widget-insert "\n"))))
1845 (message "Creating group magic...")
1846 (mapcar 'custom-magic-reset children
)
1847 (message "Creating group state...")
1848 (widget-put widget
:children children
)
1849 (custom-group-state-update widget
)
1850 (message "Creating group... done")))))
1852 (defvar custom-group-menu
1853 '(("Set" . custom-group-set
)
1854 ("Save" . custom-group-save
)
1855 ("Reset to Current" . custom-group-reset-current
)
1856 ("Reset to Saved" . custom-group-reset-saved
)
1857 ("Reset to Factory" . custom-group-reset-factory
))
1858 "Alist of actions for the `custom-group' widget.
1859 The key is a string containing the name of the action, the value is a
1860 lisp function taking the widget as an element which will be called
1861 when the action is chosen.")
1863 (defun custom-group-action (widget &optional event
)
1864 "Show the menu for `custom-group' WIDGET.
1865 Optional EVENT is the location for the menu."
1866 (if (eq (widget-get widget
:custom-state
) 'hidden
)
1868 (widget-put widget
:custom-state
'unknown
)
1869 (custom-redraw widget
))
1870 (let* ((completion-ignore-case t
)
1871 (answer (widget-choose (custom-unlispify-tag-name
1872 (widget-get widget
:value
))
1876 (funcall answer widget
)))))
1878 (defun custom-group-set (widget)
1879 "Set changes in all modified group members."
1880 (let ((children (widget-get widget
:children
)))
1881 (mapcar (lambda (child)
1882 (when (eq (widget-get child
:custom-state
) 'modified
)
1883 (widget-apply child
:custom-set
)))
1886 (defun custom-group-save (widget)
1887 "Save all modified group members."
1888 (let ((children (widget-get widget
:children
)))
1889 (mapcar (lambda (child)
1890 (when (memq (widget-get child
:custom-state
) '(modified set
))
1891 (widget-apply child
:custom-save
)))
1894 (defun custom-group-reset-current (widget)
1895 "Reset all modified group members."
1896 (let ((children (widget-get widget
:children
)))
1897 (mapcar (lambda (child)
1898 (when (eq (widget-get child
:custom-state
) 'modified
)
1899 (widget-apply child
:custom-reset-current
)))
1902 (defun custom-group-reset-saved (widget)
1903 "Reset all modified or set group members."
1904 (let ((children (widget-get widget
:children
)))
1905 (mapcar (lambda (child)
1906 (when (memq (widget-get child
:custom-state
) '(modified set
))
1907 (widget-apply child
:custom-reset-saved
)))
1910 (defun custom-group-reset-factory (widget)
1911 "Reset all modified, set, or saved group members."
1912 (let ((children (widget-get widget
:children
)))
1913 (mapcar (lambda (child)
1914 (when (memq (widget-get child
:custom-state
)
1915 '(modified set saved
))
1916 (widget-apply child
:custom-reset-factory
)))
1919 (defun custom-group-state-update (widget)
1921 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
1922 (let* ((children (widget-get widget
:children
))
1923 (states (mapcar (lambda (child)
1924 (widget-get child
:custom-state
))
1926 (magics custom-magic-alist
)
1929 (let ((magic (car (car magics
))))
1930 (if (and (not (eq magic
'hidden
))
1931 (memq magic states
))
1934 (setq magics
(cdr magics
)))))
1935 (widget-put widget
:custom-state found
)))
1936 (custom-magic-reset widget
))
1938 ;;; The `custom-save-all' Function.
1940 (defcustom custom-file
"~/.emacs"
1941 "File used for storing customization information.
1942 If you change this from the default \"~/.emacs\" you need to
1943 explicitly load that file for the settings to take effect."
1947 (defun custom-save-delete (symbol)
1948 "Delete the call to SYMBOL form `custom-file'.
1949 Leave point at the location of the call, or after the last expression."
1950 (set-buffer (find-file-noselect custom-file
))
1951 (goto-char (point-min))
1954 (let ((sexp (condition-case nil
1955 (read (current-buffer))
1956 (end-of-file (throw 'found nil
)))))
1957 (when (and (listp sexp
)
1958 (eq (car sexp
) symbol
))
1959 (delete-region (save-excursion
1963 (throw 'found nil
))))))
1965 (defun custom-save-variables ()
1966 "Save all customized variables in `custom-file'."
1968 (custom-save-delete 'custom-set-variables
)
1969 (let ((standard-output (current-buffer)))
1972 (princ "(custom-set-variables")
1973 (mapatoms (lambda (symbol)
1974 (let ((value (get symbol
'saved-value
)))
1980 (if (or (get symbol
'factory-value
)
1981 (and (not (boundp symbol
))
1982 (not (get symbol
'force-value
))))
1986 (unless (looking-at "\n")
1989 (defun custom-save-faces ()
1990 "Save all customized faces in `custom-file'."
1992 (custom-save-delete 'custom-set-faces
)
1993 (let ((standard-output (current-buffer)))
1996 (princ "(custom-set-faces")
1997 (let ((value (get 'default
'saved-face
)))
1998 ;; The default face must be first, since it affects the others.
2000 (princ "\n '(default ")
2002 (if (or (get 'default
'factory-face
)
2003 (and (not (custom-facep 'default
))
2004 (not (get 'default
'force-face
))))
2007 (mapatoms (lambda (symbol)
2008 (let ((value (get symbol
'saved-face
)))
2009 (when (and (not (eq symbol
'default
))
2010 ;; Don't print default face here.
2016 (if (or (get symbol
'factory-face
)
2017 (and (not (custom-facep symbol
))
2018 (not (get symbol
'force-face
))))
2022 (unless (looking-at "\n")
2026 (defun custom-save-all ()
2027 "Save all customizations in `custom-file'."
2028 (custom-save-variables)
2031 (set-buffer (find-file-noselect custom-file
))
2034 ;;; The Customize Menu.
2038 (unless (string-match "XEmacs" emacs-version
)
2039 (defconst custom-help-menu
'("Customize"
2040 ["Update menu..." custom-menu-update t
]
2041 ["Group..." customize t
]
2042 ["Variable..." customize-variable t
]
2043 ["Face..." customize-face t
]
2044 ["Saved..." customize-customized t
]
2045 ["Apropos..." customize-apropos t
])
2046 ;; This menu should be identical to the one defined in `menu-bar.el'.
2049 (defun custom-menu-reset ()
2050 "Reset customize menu."
2051 (remove-hook 'custom-define-hook
'custom-menu-reset
)
2052 (define-key global-map
[menu-bar help-menu customize-menu
]
2053 (cons (car custom-help-menu
)
2054 (easy-menu-create-keymaps (car custom-help-menu
)
2055 (cdr custom-help-menu
)))))
2057 (defun custom-menu-update (event)
2058 "Update customize menu."
2060 (add-hook 'custom-define-hook
'custom-menu-reset
)
2061 (let* ((emacs (widget-apply '(custom-group) :custom-menu
'emacs
))
2062 (menu `(,(car custom-help-menu
)
2064 ,@(cdr (cdr custom-help-menu
)))))
2065 (let ((map (easy-menu-create-keymaps (car menu
) (cdr menu
))))
2066 (define-key global-map
[menu-bar help-menu customize-menu
]
2067 (cons (car menu
) map
)))))
2069 (defcustom custom-menu-nesting
2
2070 "Maximum nesting in custom menus."
2074 (defun custom-face-menu-create (widget symbol
)
2075 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
2076 (vector (custom-unlispify-menu-entry symbol
)
2077 `(custom-buffer-create '((,symbol custom-face
)))
2080 (defun custom-variable-menu-create (widget symbol
)
2081 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
2082 (let ((type (get symbol
'custom-type
)))
2083 (unless (listp type
)
2084 (setq type
(list type
)))
2085 (if (and type
(widget-get type
:custom-menu
))
2086 (widget-apply type
:custom-menu symbol
)
2087 (vector (custom-unlispify-menu-entry symbol
)
2088 `(custom-buffer-create '((,symbol custom-variable
)))
2091 ;; Add checkboxes to boolean variable entries.
2092 (widget-put (get 'boolean
'widget-type
)
2093 :custom-menu
(lambda (widget symbol
)
2094 (vector (custom-unlispify-menu-entry symbol
)
2095 `(custom-buffer-create
2096 '((,symbol custom-variable
)))
2098 ':selected symbol
)))
2100 (if (string-match "XEmacs" emacs-version
)
2101 ;; XEmacs can create menus dynamically.
2102 (defun custom-group-menu-create (widget symbol
)
2103 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
2104 `( ,(custom-unlispify-menu-entry symbol t
)
2105 :filter
(lambda (&rest junk
)
2106 (cdr (custom-menu-create ',symbol
)))))
2108 (defun custom-group-menu-create (widget symbol
)
2109 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
2110 ;; Limit the nesting.
2111 (let ((custom-menu-nesting (1- custom-menu-nesting
)))
2112 (custom-menu-create symbol
))))
2115 (defun custom-menu-create (symbol)
2116 "Create menu for customization group SYMBOL.
2117 The menu is in a format applicable to `easy-menu-define'."
2118 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
2119 `(custom-buffer-create '((,symbol custom-group
)))
2121 (if (and (or (not (boundp 'custom-menu-nesting
))
2122 (>= custom-menu-nesting
0))
2123 (< (length (get symbol
'custom-group
)) widget-menu-max-size
))
2124 (let ((custom-prefix-list (custom-prefix-add symbol
2125 custom-prefix-list
)))
2126 (custom-load-symbol symbol
)
2127 `(,(custom-unlispify-menu-entry symbol t
)
2130 ,@(mapcar (lambda (entry)
2131 (widget-apply (if (listp (nth 1 entry
))
2133 (list (nth 1 entry
)))
2134 :custom-menu
(nth 0 entry
)))
2135 (get symbol
'custom-group
))))
2139 (defun customize-menu-create (symbol &optional name
)
2140 "Return a customize menu for customization group SYMBOL.
2141 If optional NAME is given, use that as the name of the menu.
2142 Otherwise the menu will be named `Customize'.
2143 The format is suitable for use with `easy-menu-define'."
2145 (setq name
"Customize"))
2146 (if (string-match "XEmacs" emacs-version
)
2147 ;; We can delay it under XEmacs.
2149 :filter
(lambda (&rest junk
)
2150 (cdr (custom-menu-create ',symbol
))))
2151 ;; But we must create it now under Emacs.
2152 (cons name
(cdr (custom-menu-create symbol
)))))
2154 ;;; The Custom Mode.
2156 (defvar custom-mode-map nil
2157 "Keymap for `custom-mode'.")
2159 (unless custom-mode-map
2160 (setq custom-mode-map
(make-sparse-keymap))
2161 (set-keymap-parent custom-mode-map widget-keymap
)
2162 (define-key custom-mode-map
"q" 'bury-buffer
))
2164 (easy-menu-define custom-mode-customize-menu
2166 "Menu used in customization buffers."
2167 (customize-menu-create 'customize
))
2169 (easy-menu-define custom-mode-menu
2171 "Menu used in customization buffers."
2173 ["Set" custom-set t
]
2174 ["Save" custom-save t
]
2175 ["Reset to Current" custom-reset-current t
]
2176 ["Reset to Saved" custom-reset-saved t
]
2177 ["Reset to Factory Settings" custom-reset-factory t
]
2178 ["Info" (Info-goto-node "(custom)The Customization Buffer") t
]))
2180 (defcustom custom-mode-hook nil
2181 "Hook called when entering custom-mode."
2185 (defun custom-mode ()
2186 "Major mode for editing customization buffers.
2188 The following commands are available:
2190 Move to next button or editable field. \\[widget-forward]
2191 Move to previous button or editable field. \\[widget-backward]
2192 Activate button under the mouse pointer. \\[widget-button-click]
2193 Activate button under point. \\[widget-button-press]
2194 Set all modifications. \\[custom-set]
2195 Make all modifications default. \\[custom-save]
2196 Reset all modified options. \\[custom-reset-current]
2197 Reset all modified or set options. \\[custom-reset-saved]
2198 Reset all options. \\[custom-reset-factory]
2200 Entry to this mode calls the value of `custom-mode-hook'
2201 if that value is non-nil."
2202 (kill-all-local-variables)
2203 (setq major-mode
'custom-mode
2205 (use-local-map custom-mode-map
)
2206 (easy-menu-add custom-mode-customize-menu
)
2207 (easy-menu-add custom-mode-menu
)
2208 (make-local-variable 'custom-options
)
2209 (run-hooks 'custom-mode-hook
))
2215 ;; cus-edit.el ends here