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 ;;; Customization Groups.
28 "Customization of the One True Editor."
29 :link
'(custom-manual "(emacs)Top"))
31 ;; Most of these groups are stolen from `finder.el',
33 "Basic text editing facilities."
37 "Abbreviation handling, typing shortcuts, macros."
41 (defgroup matching nil
42 "Various sorts of searching and matching."
45 (defgroup emulations nil
46 "Emulations of other editors."
53 (defgroup outlines nil
54 "Support for hierarchical outlining."
57 (defgroup external nil
58 "Interfacing to external utilities."
62 "Code related to the `bib' bibliography processor."
66 (defgroup processes nil
67 "Process, subshell, compilation, and job control support."
71 (defgroup programming nil
72 "Support for programming in other languages."
75 (defgroup languages nil
76 "Specialized modes for editing programming languages."
80 "Lisp support, including Emacs Lisp."
85 "Support for the C language and related languages."
93 "Support for object-oriented programming."
96 (defgroup applications nil
97 "Applications written in Emacs."
100 (defgroup calendar nil
101 "Calendar and time management support."
102 :group
'applications
)
105 "Modes for electronic-mail handling."
106 :group
'applications
)
109 "Support for netnews reading and posting."
110 :group
'applications
)
113 "Games, jokes and amusements."
114 :group
'applications
)
116 (defgroup development nil
117 "Support for further development of Emacs."
121 "Support for Emacs documentation."
124 (defgroup extensions nil
125 "Emacs Lisp language extensions."
128 (defgroup internal nil
129 "Code for Emacs internals, build process, defaults."
133 "Maintenance aids for the Emacs development group."
137 (defgroup environment nil
138 "Fitting Emacs with its environment."
142 "Communications, networking, remote access to files."
146 (defgroup hardware nil
147 "Support for interfacing with exotic hardware."
150 (defgroup terminals nil
151 "Support for terminal types."
155 "Front-ends/assistants for, or emulators of, UNIX features."
159 "Support code for vms."
163 "Internationalization and alternate character-set support."
168 "Support for Emacs frames and window systems."
172 "Support editing files of data."
180 "Code related to the TeX formatter."
184 "Support for multiple fonts."
187 (defgroup hypermedia nil
188 "Support for links between text or other media types."
192 "Support for on-line help systems."
196 "Code local to your site."
199 (defgroup customize
'((widgets custom-group
))
200 "Customization of the Customization support."
201 :link
'(custom-manual "(custom)Top")
202 :link
'(url-link :tag
"Development Page"
203 "http://www.dina.kvl.dk/~abraham/custom/")
210 (defun custom-quote (sexp)
211 "Quote SEXP iff it is not self quoting."
212 (if (or (memq sexp
'(t nil
))
214 (eq (aref (symbol-name sexp
) 0) ?
:))
216 (memq (car sexp
) '(lambda)))
219 (and (fboundp 'characterp
)
224 (defun custom-split-regexp-maybe (regexp)
225 "If REGEXP is a string, split it to a list at `\\|'.
226 You can get the original back with from the result with:
227 (mapconcat 'identity result \"\\|\")
229 IF REGEXP is not a string, return it unchanged."
233 (while (string-match "\\\\|" regexp start
)
234 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
235 start
(match-end 0)))
236 (nreverse (cons (substring regexp start
) all
)))
239 (defvar custom-prefix-list nil
240 "List of prefixes that should be ignored by `custom-unlispify'")
242 (defcustom custom-unlispify-menu-entries t
243 "Display menu entries as words instead of symbols if non nil."
247 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
248 "Convert symbol into a menu entry."
249 (cond ((not custom-unlispify-menu-entries
)
250 (symbol-name symbol
))
251 ((get symbol
'custom-tag
)
253 (get symbol
'custom-tag
)
254 (concat (get symbol
'custom-tag
) "...")))
257 (set-buffer (get-buffer-create " *Custom-Work*"))
259 (princ symbol
(current-buffer))
260 (goto-char (point-min))
261 (let ((prefixes custom-prefix-list
)
264 (setq prefix
(car prefixes
))
265 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
268 (delete-region (point-min) (point)))
269 (setq prefixes
(cdr prefixes
)))))
270 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
271 (capitalize-region (point-min) (point-max))
273 (goto-char (point-max))
277 (defcustom custom-unlispify-tag-names t
278 "Display tag names as words instead of symbols if non nil."
282 (defun custom-unlispify-tag-name (symbol)
283 "Convert symbol into a menu entry."
284 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
285 (custom-unlispify-menu-entry symbol t
)))
287 (defun custom-prefix-add (symbol prefixes
)
288 ;; Addd SYMBOL to list of ignored PREFIXES.
289 (cons (or (get symbol
'custom-prefix
)
290 (concat (symbol-name symbol
) "-"))
295 (defvar custom-options nil
296 "Customization widgets in the current buffer.")
298 (defvar custom-mode-map nil
299 "Keymap for `custom-mode'.")
301 (unless custom-mode-map
302 (setq custom-mode-map
(make-sparse-keymap))
303 (set-keymap-parent custom-mode-map widget-keymap
)
304 (define-key custom-mode-map
"q" 'bury-buffer
))
306 (easy-menu-define custom-mode-menu
308 "Menu used in customization buffers."
311 ["Save" custom-save t
]
312 ["Reset to Current" custom-reset-current t
]
313 ["Reset to Saved" custom-reset-saved t
]
314 ["Reset to Factory Settings" custom-reset-factory t
]
315 ["Info" (Info-goto-node "(custom)The Customization Buffer") t
]))
317 (defcustom custom-mode-hook nil
318 "Hook called when entering custom-mode."
322 (defun custom-mode ()
323 "Major mode for editing customization buffers.
325 The following commands are available:
327 \\[widget-forward] Move to next button or editable field.
328 \\[widget-backward] Move to previous button or editable field.
329 \\[widget-button-click] Activate button under the mouse pointer.
330 \\[widget-button-press] Activate button under point.
331 \\[custom-set] Set all modifications.
332 \\[custom-save] Make all modifications default.
333 \\[custom-reset-current] Reset all modified options.
334 \\[custom-reset-saved] Reset all modified or set options.
335 \\[custom-reset-factory] Reset all options.
337 Entry to this mode calls the value of `custom-mode-hook'
338 if that value is non-nil."
339 (kill-all-local-variables)
340 (setq major-mode
'custom-mode
342 (use-local-map custom-mode-map
)
343 (easy-menu-add custom-mode-menu
)
344 (make-local-variable 'custom-options
)
345 (run-hooks 'custom-mode-hook
))
347 ;;; Custom Mode Commands.
350 "Set changes in all modified options."
352 (let ((children custom-options
))
353 (mapcar (lambda (child)
354 (when (eq (widget-get child
:custom-state
) 'modified
)
355 (widget-apply child
:custom-set
)))
358 (defun custom-save ()
359 "Set all modified group members and save them."
361 (let ((children custom-options
))
362 (mapcar (lambda (child)
363 (when (memq (widget-get child
:custom-state
) '(modified set
))
364 (widget-apply child
:custom-save
)))
368 (defvar custom-reset-menu
369 '(("Current" . custom-reset-current
)
370 ("Saved" . custom-reset-saved
)
371 ("Factory Settings" . custom-reset-factory
))
372 "Alist of actions for the `Reset' button.
373 The key is a string containing the name of the action, the value is a
374 lisp function taking the widget as an element which will be called
375 when the action is chosen.")
377 (defun custom-reset (event)
378 "Select item from reset menu."
379 (let* ((completion-ignore-case t
)
380 (answer (widget-choose "Reset to"
386 (defun custom-reset-current ()
387 "Reset all modified group members to their current value."
389 (let ((children custom-options
))
390 (mapcar (lambda (child)
391 (when (eq (widget-get child
:custom-state
) 'modified
)
392 (widget-apply child
:custom-reset-current
)))
395 (defun custom-reset-saved ()
396 "Reset all modified or set group members to their saved value."
398 (let ((children custom-options
))
399 (mapcar (lambda (child)
400 (when (eq (widget-get child
:custom-state
) 'modified
)
401 (widget-apply child
:custom-reset-current
)))
404 (defun custom-reset-factory ()
405 "Reset all modified, set, or saved group members to their factory settings."
407 (let ((children custom-options
))
408 (mapcar (lambda (child)
409 (when (eq (widget-get child
:custom-state
) 'modified
)
410 (widget-apply child
:custom-reset-current
)))
413 ;;; The Customize Commands
416 (defun customize (symbol)
417 "Customize SYMBOL, which must be a customization group."
418 (interactive (list (completing-read "Customize group: (default emacs) "
421 (get symbol
'custom-group
))
424 (when (stringp symbol
)
425 (if (string-equal "" symbol
)
427 (setq symbol
(intern symbol
))))
428 (custom-buffer-create (list (list symbol
'custom-group
))))
431 (defun customize-variable (symbol)
432 "Customize SYMBOL, which must be a variable."
434 ;; Code stolen from `help.el'.
435 (let ((v (variable-at-point))
436 (enable-recursive-minibuffers t
)
438 (setq val
(completing-read
440 (format "Customize variable (default %s): " v
)
441 "Customize variable: ")
443 (list (if (equal val
"")
445 (custom-buffer-create (list (list symbol
'custom-variable
))))
448 (defun customize-face (&optional symbol
)
449 "Customize SYMBOL, which should be a face name or nil.
450 If SYMBOL is nil, customize all faces."
451 (interactive (list (completing-read "Customize face: (default all) "
452 obarray
'custom-facep
)))
453 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
455 (message "Looking for faces...")
456 (mapcar (lambda (symbol)
457 (setq found
(cons (list symbol
'custom-face
) found
)))
459 (custom-buffer-create found
))
461 (setq symbol
(intern symbol
)))
462 (unless (symbolp symbol
)
463 (error "Should be a symbol %S" symbol
))
464 (custom-buffer-create (list (list symbol
'custom-face
)))))
467 (defun customize-customized ()
468 "Customize all already customized user options."
471 (mapatoms (lambda (symbol)
472 (and (get symbol
'saved-face
)
473 (custom-facep symbol
)
474 (setq found
(cons (list symbol
'custom-face
) found
)))
475 (and (get symbol
'saved-value
)
478 (cons (list symbol
'custom-variable
) found
)))))
480 (custom-buffer-create found
)
481 (error "No customized user options"))))
484 (defun customize-apropos (regexp &optional all
)
485 "Customize all user options matching REGEXP.
486 If ALL (e.g., started with a prefix key), include options which are not
488 (interactive "sCustomize regexp: \nP")
490 (mapatoms (lambda (symbol)
491 (when (string-match regexp
(symbol-name symbol
))
492 (when (get symbol
'custom-group
)
493 (setq found
(cons (list symbol
'custom-group
) found
)))
494 (when (custom-facep symbol
)
495 (setq found
(cons (list symbol
'custom-face
) found
)))
496 (when (and (boundp symbol
)
497 (or (get symbol
'saved-value
)
498 (get symbol
'factory-value
)
500 (get symbol
'variable-documentation
)
501 (user-variable-p symbol
))))
503 (cons (list symbol
'custom-variable
) found
))))))
505 (custom-buffer-create found
)
506 (error "No matches"))))
509 (defun custom-buffer-create (options)
510 "Create a buffer containing OPTIONS.
511 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
512 SYMBOL is a customization option, and WIDGET is a widget for editing
514 (message "Creating customization buffer...")
515 (kill-buffer (get-buffer-create "*Customization*"))
516 (switch-to-buffer (get-buffer-create "*Customization*"))
518 (widget-insert "This is a customization buffer.
519 Push RET or click mouse-2 on the word ")
520 ;; (put-text-property 1 2 'start-open nil)
521 (widget-create 'info-link
523 :help-echo
"Read the online help."
524 "(custom)The Customization Buffer")
525 (widget-insert " for more information.\n\n")
527 (if (= (length options
) 1)
528 (mapcar (lambda (entry)
529 (widget-create (nth 1 entry
)
530 :custom-state
'unknown
531 :tag
(custom-unlispify-tag-name
533 :value
(nth 0 entry
)))
536 (length (length options
)))
537 (mapcar (lambda (entry)
539 (message "Creating customization items %2d%%..."
540 (/ (* 100.0 count
) length
))
541 (widget-create (nth 1 entry
)
542 :tag
(custom-unlispify-tag-name
544 :value
(nth 0 entry
))
545 (setq count
(1+ count
))
546 (unless (eq (preceding-char) ?
\n)
547 (widget-insert "\n"))
548 (widget-insert "\n")))
550 (unless (eq (preceding-char) ?
\n)
551 (widget-insert "\n"))
553 (message "Creating customization magic...")
554 (mapcar 'custom-magic-reset custom-options
)
555 (message "Creating customization buttons...")
556 (widget-create 'push-button
558 :help-echo
"Set all modifications for this session."
559 :action
(lambda (widget &optional event
)
562 (widget-create 'push-button
565 Make the modifications default for future sessions."
566 :action
(lambda (widget &optional event
)
569 (widget-create 'push-button
571 :help-echo
"Undo all modifications."
572 :action
(lambda (widget &optional event
)
573 (custom-reset event
)))
575 (widget-create 'push-button
577 :help-echo
"Bury the buffer."
578 :action
(lambda (widget &optional event
)
580 ;; Steal button release event.
581 (if (and (fboundp 'button-press-event-p
)
582 (fboundp 'next-command-event
))
585 (button-press-event-p event
)
586 (next-command-event))
588 (when (memq 'down
(event-modifiers event
))
591 (message "Creating customization setup...")
593 (goto-char (point-min))
594 (message "Creating customization buffer...done"))
596 ;;; Modification of Basic Widgets.
598 ;; We add extra properties to the basic widgets needed here. This is
599 ;; fine, as long as we are careful to stay within out own namespace.
601 ;; We want simple widgets to be displayed by default, but complex
602 ;; widgets to be hidden.
604 (widget-put (get 'item
'widget-type
) :custom-show t
)
605 (widget-put (get 'editable-field
'widget-type
)
606 :custom-show
(lambda (widget value
)
607 (let ((pp (pp-to-string value
)))
608 (cond ((string-match "\n" pp
)
613 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
615 ;;; The `custom-manual' Widget.
617 (define-widget 'custom-manual
'info-link
618 "Link to the manual entry for this customization option."
619 :help-echo
"Read the manual entry for this option."
622 ;;; The `custom-magic' Widget.
624 (defface custom-invalid-face
'((((class color
))
625 (:foreground
"yellow" :background
"red"))
627 (:bold t
:italic t
:underline t
)))
628 "Face used when the customize item is invalid.")
630 (defface custom-rogue-face
'((((class color
))
631 (:foreground
"pink" :background
"black"))
634 "Face used when the customize item is not defined for customization.")
636 (defface custom-modified-face
'((((class color
))
637 (:foreground
"white" :background
"blue"))
640 "Face used when the customize item has been modified.")
642 (defface custom-set-face
'((((class color
))
643 (:foreground
"blue" :background
"white"))
646 "Face used when the customize item has been set.")
648 (defface custom-changed-face
'((((class color
))
649 (:foreground
"white" :background
"blue"))
652 "Face used when the customize item has been changed.")
654 (defface custom-saved-face
'((t (:underline t
)))
655 "Face used when the customize item has been saved.")
657 (defcustom custom-magic-alist
'((nil "#" underline
"\
658 uninitialized, you should not see this.")
659 (unknown "?" italic
"\
660 unknown, you should not see this.")
661 (hidden "-" default
"\
662 hidden, press the state button to show.")
663 (invalid "x" custom-invalid-face
"\
664 the value displayed for this item is invalid and cannot be set.")
665 (modified "*" custom-modified-face
"\
666 you have edited the item, and can now set it.")
667 (set "+" custom-set-face
"\
668 you have set this item, but not saved it.")
669 (changed ":" custom-changed-face
"\
670 this item has been changed outside customize.")
671 (saved "!" custom-saved-face
"\
672 this item has been saved.")
673 (rogue "@" custom-rogue-face
"\
674 this item is not prepared for customization.")
676 this item is unchanged from its factory setting."))
677 "Alist of customize option states.
678 Each entry is of the form (STATE MAGIC FACE DESCRIPTION), where
680 STATE is one of the following symbols:
683 For internal use, should never occur.
685 For internal use, should never occur.
687 This item is not being displayed.
689 This item is modified, but has an invalid form.
691 This item is modified, and has a valid form.
693 This item has been set but not saved.
695 The current value of this item has been changed temporarily.
697 This item is marked for saving.
699 This item has no customization information.
701 This item is unchanged from the factory default.
703 MAGIC is a string used to present that state.
705 FACE is a face used to present the state.
707 DESCRIPTION is a string describing the state.
709 The list should be sorted most significant first."
710 :type
'(list (checklist :inline t
712 (string :tag
"Magic")
714 (string :tag
"Description"))
715 (group (const unknown
)
716 (string :tag
"Magic")
718 (string :tag
"Description"))
719 (group (const hidden
)
720 (string :tag
"Magic")
722 (string :tag
"Description"))
723 (group (const invalid
)
724 (string :tag
"Magic")
726 (string :tag
"Description"))
727 (group (const modified
)
728 (string :tag
"Magic")
730 (string :tag
"Description"))
732 (string :tag
"Magic")
734 (string :tag
"Description"))
735 (group (const changed
)
736 (string :tag
"Magic")
738 (string :tag
"Description"))
740 (string :tag
"Magic")
742 (string :tag
"Description"))
744 (string :tag
"Magic")
746 (string :tag
"Description"))
747 (group (const factory
)
748 (string :tag
"Magic")
750 (string :tag
"Description")))
751 (editable-list :inline t
753 (string :tag
"Magic")
755 (string :tag
"Description"))))
758 (defcustom custom-magic-show
'long
759 "Show long description of the state of each customization option."
760 :type
'(choice (const :tag
"no" nil
)
765 (defcustom custom-magic-show-button t
766 "Show a magic button indicating the state of each customization option."
770 (define-widget 'custom-magic
'default
771 "Show and manipulate state for a customization option."
773 :action
'widget-choice-item-action
775 :value-create
'custom-magic-value-create
776 :value-delete
'widget-children-value-delete
)
778 (defun custom-magic-value-create (widget)
779 ;; Create compact status report for WIDGET.
780 (let* ((parent (widget-get widget
:parent
))
781 (state (widget-get parent
:custom-state
))
782 (entry (assq state custom-magic-alist
))
783 (magic (nth 1 entry
))
786 (lisp (eq (widget-get parent
:custom-form
) 'lisp
))
788 (when custom-magic-show
789 (push (widget-create-child-and-convert widget
'choice-item
791 Change the state of this item."
796 (if (eq custom-magic-show
'long
)
798 (insert (symbol-name state
)))
802 (when custom-magic-show-button
803 (when custom-magic-show
804 (let ((indent (widget-get parent
:indent
)))
806 (insert-char ? indent
))))
807 (push (widget-create-child-and-convert widget
'choice-item
809 :help-echo
"Change the state."
812 (concat "(" magic
")")
813 (concat "[" magic
"]")))
816 (widget-put widget
:children children
)))
818 (defun custom-magic-reset (widget)
819 "Redraw the :custom-magic property of WIDGET."
820 (let ((magic (widget-get widget
:custom-magic
)))
821 (widget-value-set magic
(widget-value magic
))))
823 ;;; The `custom-level' Widget.
825 (define-widget 'custom-level
'item
826 "The custom level buttons."
828 :help-echo
"Expand or collapse this item."
829 :action
'custom-level-action
)
831 (defun custom-level-action (widget &optional event
)
832 "Toggle visibility for parent to WIDGET."
833 (let* ((parent (widget-get widget
:parent
))
834 (state (widget-get parent
:custom-state
)))
835 (cond ((memq state
'(invalid modified
))
836 (error "There are unset changes"))
838 (widget-put parent
:custom-state
'unknown
))
840 (widget-put parent
:custom-state
'hidden
)))
841 (custom-redraw parent
)))
843 ;;; The `custom' Widget.
845 (define-widget 'custom
'default
846 "Customize a user option."
847 :convert-widget
'custom-convert-widget
848 :format
"%l%[%t%]: %v%m%h%a"
849 :format-handler
'custom-format-handler
850 :notify
'custom-notify
852 :custom-state
'hidden
853 :documentation-property
'widget-subclass-responsibility
854 :value-create
'widget-subclass-responsibility
855 :value-delete
'widget-children-value-delete
856 :value-get
'widget-item-value-get
857 :validate
'widget-editable-list-validate
858 :match
(lambda (widget value
) (symbolp value
)))
860 (defun custom-convert-widget (widget)
861 ;; Initialize :value and :tag from :args in WIDGET.
862 (let ((args (widget-get widget
:args
)))
864 (widget-put widget
:value
(widget-apply widget
865 :value-to-internal
(car args
)))
866 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
867 (widget-put widget
:args nil
)))
870 (defun custom-format-handler (widget escape
)
871 ;; We recognize extra escape sequences.
872 (let* ((buttons (widget-get widget
:buttons
))
873 (state (widget-get widget
:custom-state
))
874 (level (widget-get widget
:custom-level
)))
875 (cond ((eq escape ?l
)
877 (push (widget-create-child-and-convert
878 widget
'custom-level
(make-string level ?
*))
881 (widget-put widget
:buttons buttons
)))
883 (when (eq state
'hidden
)
884 (widget-insert " ...")))
886 (and (eq (preceding-char) ?
\n)
887 (widget-get widget
:indent
)
888 (insert-char ?
(widget-get widget
:indent
)))
889 (let ((magic (widget-create-child-and-convert
890 widget
'custom-magic nil
)))
891 (widget-put widget
:custom-magic magic
)
893 (widget-put widget
:buttons buttons
)))
895 (let* ((symbol (widget-get widget
:value
))
896 (links (get symbol
'custom-links
))
897 (many (> (length links
) 2)))
899 (and (eq (preceding-char) ?
\n)
900 (widget-get widget
:indent
)
901 (insert-char ?
(widget-get widget
:indent
)))
904 (push (widget-create-child-and-convert widget
(car links
))
906 (setq links
(cdr links
))
915 (widget-put widget
:buttons buttons
))))
917 (widget-default-format-handler widget escape
)))))
919 (defun custom-notify (widget &rest args
)
920 "Keep track of changes."
921 (unless (memq (widget-get widget
:custom-state
) '(nil unknown hidden
))
922 (widget-put widget
:custom-state
'modified
))
923 (let ((buffer-undo-list t
))
924 (custom-magic-reset widget
))
925 (apply 'widget-default-notify widget args
))
927 (defun custom-redraw (widget)
928 "Redraw WIDGET with current settings."
930 (from (marker-position (widget-get widget
:from
)))
931 (to (marker-position (widget-get widget
:to
))))
933 (widget-value-set widget
(widget-value widget
))
934 (custom-redraw-magic widget
))
935 (when (and (>= pos from
) (<= pos to
))
938 (defun custom-redraw-magic (widget)
939 "Redraw WIDGET state with current settings."
941 (let ((magic (widget-get widget
:custom-magic
)))
944 (widget-value-set magic
(widget-value magic
))
945 (when (setq widget
(widget-get widget
:group
))
946 (custom-group-state-update widget
))))
949 (defun custom-show (widget value
)
950 "Non-nil if WIDGET should be shown with VALUE by default."
951 (let ((show (widget-get widget
:custom-show
)))
957 (funcall show widget value
)))))
959 (defun custom-load-symbol (symbol)
960 "Load all dependencies for SYMBOL."
961 (let ((loads (get symbol
'custom-loads
))
964 (setq load
(car loads
)
966 (cond ((symbolp load
)
970 ((assoc load load-history
))
976 (defun custom-load-widget (widget)
977 "Load all dependencies for WIDGET."
978 (custom-load-symbol (widget-value widget
)))
980 ;;; The `custom-variable' Widget.
982 (defface custom-variable-sample-face
'((t (:underline t
)))
983 "Face used for unpushable variable tags."
986 (defface custom-variable-button-face
'((t (:underline t
:bold t
)))
987 "Face used for pushable variable tags."
990 (define-widget 'custom-variable
'custom
991 "Customize variable."
993 :help-echo
"Set or reset this variable."
994 :documentation-property
'variable-documentation
996 :custom-menu
'custom-variable-menu-create
998 :value-create
'custom-variable-value-create
999 :action
'custom-variable-action
1000 :custom-set
'custom-variable-set
1001 :custom-save
'custom-variable-save
1002 :custom-reset-current
'custom-redraw
1003 :custom-reset-saved
'custom-variable-reset-saved
1004 :custom-reset-factory
'custom-variable-reset-factory
)
1006 (defun custom-variable-value-create (widget)
1007 "Here is where you edit the variables value."
1008 (custom-load-widget widget
)
1009 (let* ((buttons (widget-get widget
:buttons
))
1010 (children (widget-get widget
:children
))
1011 (form (widget-get widget
:custom-form
))
1012 (state (widget-get widget
:custom-state
))
1013 (symbol (widget-get widget
:value
))
1014 (options (get symbol
'custom-options
))
1015 (child-type (or (get symbol
'custom-type
) 'sexp
))
1016 (tag (widget-get widget
:tag
))
1017 (type (let ((tmp (if (listp child-type
)
1018 (copy-list child-type
)
1019 (list child-type
))))
1021 (widget-put tmp
:options options
))
1023 (conv (widget-convert type
))
1024 (value (if (default-boundp symbol
)
1025 (default-value symbol
)
1026 (widget-get conv
:value
))))
1027 ;; If the widget is new, the child determine whether it is hidden.
1029 ((custom-show type value
)
1030 (setq state
'unknown
))
1032 (setq state
'hidden
)))
1033 ;; If we don't know the state, see if we need to edit it in lisp form.
1034 (when (eq state
'unknown
)
1035 (unless (widget-apply conv
:match value
)
1036 ;; (widget-apply (widget-convert type) :match value)
1038 ;; Now we can create the child widget.
1039 (cond ((eq state
'hidden
)
1040 ;; Indicate hidden value.
1041 (push (widget-create-child-and-convert
1043 :format
"%{%t%}: ..."
1044 :sample-face
'custom-variable-sample-face
1049 ;; In lisp mode edit the saved value when possible.
1050 (let* ((value (cond ((get symbol
'saved-value
)
1051 (car (get symbol
'saved-value
)))
1052 ((get symbol
'factory-value
)
1053 (car (get symbol
'factory-value
)))
1054 ((default-boundp symbol
)
1055 (custom-quote (default-value symbol
)))
1057 (custom-quote (widget-get conv
:value
))))))
1058 (push (widget-create-child-and-convert
1060 :button-face
'custom-variable-button-face
1061 :tag
(symbol-name symbol
)
1067 (push (widget-create-child-and-convert
1070 :button-face
'custom-variable-button-face
1071 :sample-face
'custom-variable-sample-face
1074 ;; Now update the state.
1075 (unless (eq (preceding-char) ?
\n)
1076 (widget-insert "\n"))
1077 (if (eq state
'hidden
)
1078 (widget-put widget
:custom-state state
)
1079 (custom-variable-state-set widget
))
1080 (widget-put widget
:custom-form form
)
1081 (widget-put widget
:buttons buttons
)
1082 (widget-put widget
:children children
)))
1084 (defun custom-variable-state-set (widget)
1085 "Set the state of WIDGET."
1086 (let* ((symbol (widget-value widget
))
1087 (value (if (default-boundp symbol
)
1088 (default-value symbol
)
1089 (widget-get widget
:value
)))
1091 (state (cond ((setq tmp
(get symbol
'customized-value
))
1092 (if (condition-case nil
1093 (equal value
(eval (car tmp
)))
1097 ((setq tmp
(get symbol
'saved-value
))
1098 (if (condition-case nil
1099 (equal value
(eval (car tmp
)))
1103 ((setq tmp
(get symbol
'factory-value
))
1104 (if (condition-case nil
1105 (equal value
(eval (car tmp
)))
1110 (widget-put widget
:custom-state state
)))
1112 (defvar custom-variable-menu
1113 '(("Edit" . custom-variable-edit
)
1114 ("Edit Lisp" . custom-variable-edit-lisp
)
1115 ("Set" . custom-variable-set
)
1116 ("Save" . custom-variable-save
)
1117 ("Reset to Current" . custom-redraw
)
1118 ("Reset to Saved" . custom-variable-reset-saved
)
1119 ("Reset to Factory Settings" . custom-variable-reset-factory
))
1120 "Alist of actions for the `custom-variable' widget.
1121 The key is a string containing the name of the action, the value is a
1122 lisp function taking the widget as an element which will be called
1123 when the action is chosen.")
1125 (defun custom-variable-action (widget &optional event
)
1126 "Show the menu for `custom-variable' WIDGET.
1127 Optional EVENT is the location for the menu."
1128 (if (eq (widget-get widget
:custom-state
) 'hidden
)
1130 (widget-put widget
:custom-state
'unknown
)
1131 (custom-redraw widget
))
1132 (let* ((completion-ignore-case t
)
1133 (answer (widget-choose (custom-unlispify-tag-name
1134 (widget-get widget
:value
))
1135 custom-variable-menu
1138 (funcall answer widget
)))))
1140 (defun custom-variable-edit (widget)
1141 "Edit value of WIDGET."
1142 (widget-put widget
:custom-state
'unknown
)
1143 (widget-put widget
:custom-form
'edit
)
1144 (custom-redraw widget
))
1146 (defun custom-variable-edit-lisp (widget)
1147 "Edit the lisp representation of the value of WIDGET."
1148 (widget-put widget
:custom-state
'unknown
)
1149 (widget-put widget
:custom-form
'lisp
)
1150 (custom-redraw widget
))
1152 (defun custom-variable-set (widget)
1153 "Set the current value for the variable being edited by WIDGET."
1154 (let ((form (widget-get widget
:custom-form
))
1155 (state (widget-get widget
:custom-state
))
1156 (child (car (widget-get widget
:children
)))
1157 (symbol (widget-value widget
))
1159 (cond ((eq state
'hidden
)
1160 (error "Cannot set hidden variable."))
1161 ((setq val
(widget-apply child
:validate
))
1162 (goto-char (widget-get val
:from
))
1163 (error "%s" (widget-get val
:error
)))
1165 (set symbol
(eval (setq val
(widget-value child
))))
1166 (put symbol
'customized-value
(list val
)))
1168 (set symbol
(setq val
(widget-value child
)))
1169 (put symbol
'customized-value
(list (custom-quote val
)))))
1170 (custom-variable-state-set widget
)
1171 (custom-redraw-magic widget
)))
1173 (defun custom-variable-save (widget)
1174 "Set the default value for the variable being edited by WIDGET."
1175 (let ((form (widget-get widget
:custom-form
))
1176 (state (widget-get widget
:custom-state
))
1177 (child (car (widget-get widget
:children
)))
1178 (symbol (widget-value widget
))
1180 (cond ((eq state
'hidden
)
1181 (error "Cannot set hidden variable."))
1182 ((setq val
(widget-apply child
:validate
))
1183 (goto-char (widget-get val
:from
))
1184 (error "%s" (widget-get val
:error
)))
1186 (put symbol
'saved-value
(list (widget-value child
)))
1187 (set symbol
(eval (widget-value child
))))
1190 'saved-value
(list (custom-quote (widget-value
1192 (set symbol
(widget-value child
))))
1193 (put symbol
'customized-value nil
)
1195 (custom-variable-state-set widget
)
1196 (custom-redraw-magic widget
)))
1198 (defun custom-variable-reset-saved (widget)
1199 "Restore the saved value for the variable being edited by WIDGET."
1200 (let ((symbol (widget-value widget
)))
1201 (if (get symbol
'saved-value
)
1203 (set symbol
(eval (car (get symbol
'saved-value
))))
1205 (error "No saved value for %s" symbol
))
1206 (put symbol
'customized-value nil
)
1207 (widget-put widget
:custom-state
'unknown
)
1208 (custom-redraw widget
)))
1210 (defun custom-variable-reset-factory (widget)
1211 "Restore the factory setting for the variable being edited by WIDGET."
1212 (let ((symbol (widget-value widget
)))
1213 (if (get symbol
'factory-value
)
1214 (set symbol
(eval (car (get symbol
'factory-value
))))
1215 (error "No factory default for %S" symbol
))
1216 (put symbol
'customized-value nil
)
1217 (when (get symbol
'saved-value
)
1218 (put symbol
'saved-value nil
)
1220 (widget-put widget
:custom-state
'unknown
)
1221 (custom-redraw widget
)))
1223 ;;; The `custom-face-edit' Widget.
1225 (define-widget 'custom-face-edit
'checklist
1226 "Edit face attributes."
1230 :button-args
'(:help-echo
"Control whether this attribute have any effect.")
1231 :args
(mapcar (lambda (att)
1234 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
1235 (list 'const
:format
"" :value
(nth 0 att
))
1237 custom-face-attributes
))
1239 ;;; The `custom-display' Widget.
1241 (define-widget 'custom-display
'menu-choice
1242 "Select a display type."
1245 :help-echo
"Specify frames where the face attributes should be used."
1246 :args
'((const :tag
"all" t
)
1250 :args
((group :sibling-args
(:help-echo
"\
1251 Only match the specified window systems.")
1252 (const :format
"Type: "
1254 (checklist :inline t
1257 :sibling-args
(:help-echo
"\
1258 The X11 Window System.")
1260 (const :format
"PM "
1261 :sibling-args
(:help-echo
"\
1262 OS/2 Presentation Manager.")
1264 (const :format
"Win32 "
1265 :sibling-args
(:help-echo
"\
1268 (const :format
"DOS "
1269 :sibling-args
(:help-echo
"\
1272 (const :format
"TTY%n"
1273 :sibling-args
(:help-echo
"\
1274 Plain text terminals.")
1276 (group :sibling-args
(:help-echo
"\
1277 Only match the frames with the specified color support.")
1278 (const :format
"Class: "
1280 (checklist :inline t
1282 (const :format
"Color "
1283 :sibling-args
(:help-echo
"\
1284 Match color frames.")
1286 (const :format
"Grayscale "
1287 :sibling-args
(:help-echo
"\
1288 Match grayscale frames.")
1290 (const :format
"Monochrome%n"
1291 :sibling-args
(:help-echo
"\
1292 Match frames with no color support.")
1294 (group :sibling-args
(:help-echo
"\
1295 Only match frames with the specified intensity.")
1297 Background brightness: "
1299 (checklist :inline t
1301 (const :format
"Light "
1302 :sibling-args
(:help-echo
"\
1303 Match frames with light backgrounds.")
1305 (const :format
"Dark\n"
1306 :sibling-args
(:help-echo
"\
1307 Match frames with dark backgrounds.")
1310 ;;; The `custom-face' Widget.
1312 (defface custom-face-tag-face
'((t (:underline t
)))
1313 "Face used for face tags."
1316 (define-widget 'custom-face
'custom
1318 :format
"%l%{%t%}: %s%m%h%a%v"
1319 :format-handler
'custom-face-format-handler
1320 :sample-face
'custom-face-tag-face
1321 :help-echo
"Set or reset this face."
1322 :documentation-property
'(lambda (face)
1323 (face-doc-string face
))
1324 :value-create
'custom-face-value-create
1325 :action
'custom-face-action
1326 :custom-form
'selected
1327 :custom-set
'custom-face-set
1328 :custom-save
'custom-face-save
1329 :custom-reset-current
'custom-redraw
1330 :custom-reset-saved
'custom-face-reset-saved
1331 :custom-reset-factory
'custom-face-reset-factory
1332 :custom-menu
'custom-face-menu-create
)
1334 (defun custom-face-format-handler (widget escape
)
1335 ;; We recognize extra escape sequences.
1337 (symbol (widget-get widget
:value
)))
1338 (cond ((eq escape ?s
)
1339 (and (string-match "XEmacs" emacs-version
)
1340 ;; XEmacs cannot display initialized faces.
1341 (not (custom-facep symbol
))
1342 (copy-face 'custom-face-empty symbol
))
1343 (setq child
(widget-create-child-and-convert
1345 :format
"(%{%t%})\n"
1349 (custom-format-handler widget escape
)))
1352 :buttons
(cons child
(widget-get widget
:buttons
))))))
1354 (define-widget 'custom-face-all
'editable-list
1355 "An editable list of display specifications and attributes."
1356 :entry-format
"%i %d %v"
1357 :insert-button-args
'(:help-echo
"Insert new display specification here.")
1358 :append-button-args
'(:help-echo
"Append new display specification here.")
1359 :delete-button-args
'(:help-echo
"Delete this display specification.")
1360 :args
'((group :format
"%v" custom-display custom-face-edit
)))
1362 (defconst custom-face-all
(widget-convert 'custom-face-all
)
1363 "Converted version of the `custom-face-all' widget.")
1365 (define-widget 'custom-display-unselected
'item
1366 "A display specification that doesn't match the selected display."
1367 :match
'custom-display-unselected-match
)
1369 (defun custom-display-unselected-match (widget value
)
1370 "Non-nil if VALUE is an unselected display specification."
1372 (eq (length value
) 2)
1373 (not (custom-display-match-frame value
(selected-frame)))))
1375 (define-widget 'custom-face-selected
'group
1376 "Edit the attributes of the selected display in a face specification."
1377 :args
'((repeat :format
""
1379 (group custom-display-unselected sexp
))
1380 (group (sexp :format
"") custom-face-edit
)
1385 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
1386 "Converted version of the `custom-face-selected' widget.")
1388 (defun custom-face-value-create (widget)
1389 ;; Create a list of the display specifications.
1390 (unless (eq (preceding-char) ?
\n)
1392 (when (not (eq (widget-get widget
:custom-state
) 'hidden
))
1393 (message "Creating face editor...")
1394 (custom-load-widget widget
)
1395 (let* ((symbol (widget-value widget
))
1396 (spec (or (get symbol
'saved-face
)
1397 (get symbol
'factory-face
)
1398 ;; Attempt to construct it.
1399 (list (list t
(custom-face-attributes-get
1400 symbol
(selected-frame))))))
1401 (form (widget-get widget
:custom-form
))
1402 (indent (widget-get widget
:indent
))
1403 (edit (widget-create-child-and-convert
1405 (cond ((and (eq form
'selected
)
1406 (widget-apply custom-face-selected
:match spec
))
1407 (when indent
(insert-char ?\ indent
))
1408 'custom-face-selected
)
1409 ((and (not (eq form
'lisp
))
1410 (widget-apply custom-face-all
:match spec
))
1413 (when indent
(insert-char ?\ indent
))
1416 (custom-face-state-set widget
)
1417 (widget-put widget
:children
(list edit
)))
1418 (message "Creating face editor...done")))
1420 (defvar custom-face-menu
1421 '(("Edit Selected" . custom-face-edit-selected
)
1422 ("Edit All" . custom-face-edit-all
)
1423 ("Edit Lisp" . custom-face-edit-lisp
)
1424 ("Set" . custom-face-set
)
1425 ("Save" . custom-face-save
)
1426 ("Reset to Saved" . custom-face-reset-saved
)
1427 ("Reset to Factory Setting" . custom-face-reset-factory
))
1428 "Alist of actions for the `custom-face' widget.
1429 The key is a string containing the name of the action, the value is a
1430 lisp function taking the widget as an element which will be called
1431 when the action is chosen.")
1433 (defun custom-face-edit-selected (widget)
1434 "Edit selected attributes of the value of WIDGET."
1435 (widget-put widget
:custom-state
'unknown
)
1436 (widget-put widget
:custom-form
'selected
)
1437 (custom-redraw widget
))
1439 (defun custom-face-edit-all (widget)
1440 "Edit all attributes of the value of WIDGET."
1441 (widget-put widget
:custom-state
'unknown
)
1442 (widget-put widget
:custom-form
'all
)
1443 (custom-redraw widget
))
1445 (defun custom-face-edit-lisp (widget)
1446 "Edit the lisp representation of the value of WIDGET."
1447 (widget-put widget
:custom-state
'unknown
)
1448 (widget-put widget
:custom-form
'lisp
)
1449 (custom-redraw widget
))
1451 (defun custom-face-state-set (widget)
1452 "Set the state of WIDGET."
1453 (let ((symbol (widget-value widget
)))
1454 (widget-put widget
:custom-state
(cond ((get symbol
'customized-face
)
1456 ((get symbol
'saved-face
)
1458 ((get symbol
'factory-face
)
1463 (defun custom-face-action (widget &optional event
)
1464 "Show the menu for `custom-face' WIDGET.
1465 Optional EVENT is the location for the menu."
1466 (if (eq (widget-get widget
:custom-state
) 'hidden
)
1468 (widget-put widget
:custom-state
'unknown
)
1469 (custom-redraw widget
))
1470 (let* ((completion-ignore-case t
)
1471 (symbol (widget-get widget
:value
))
1472 (answer (widget-choose (custom-unlispify-tag-name symbol
)
1473 custom-face-menu event
)))
1475 (funcall answer widget
)))))
1477 (defun custom-face-set (widget)
1478 "Make the face attributes in WIDGET take effect."
1479 (let* ((symbol (widget-value widget
))
1480 (child (car (widget-get widget
:children
)))
1481 (value (widget-value child
)))
1482 (put symbol
'customized-face value
)
1483 (when (fboundp 'copy-face
)
1484 (copy-face 'custom-face-empty symbol
))
1485 (custom-face-display-set symbol value
)
1486 (custom-face-state-set widget
)
1487 (custom-redraw-magic widget
)))
1489 (defun custom-face-save (widget)
1490 "Make the face attributes in WIDGET default."
1491 (let* ((symbol (widget-value widget
))
1492 (child (car (widget-get widget
:children
)))
1493 (value (widget-value child
)))
1494 (when (fboundp 'copy-face
)
1495 (copy-face 'custom-face-empty symbol
))
1496 (custom-face-display-set symbol value
)
1497 (put symbol
'saved-face value
)
1498 (put symbol
'customized-face nil
)
1499 (custom-face-state-set widget
)
1500 (custom-redraw-magic widget
)))
1502 (defun custom-face-reset-saved (widget)
1503 "Restore WIDGET to the face's default attributes."
1504 (let* ((symbol (widget-value widget
))
1505 (child (car (widget-get widget
:children
)))
1506 (value (get symbol
'saved-face
)))
1508 (error "No saved value for this face"))
1509 (put symbol
'customized-face nil
)
1510 (when (fboundp 'copy-face
)
1511 (copy-face 'custom-face-empty symbol
))
1512 (custom-face-display-set symbol value
)
1513 (widget-value-set child value
)
1514 (custom-face-state-set widget
)
1515 (custom-redraw-magic widget
)))
1517 (defun custom-face-reset-factory (widget)
1518 "Restore WIDGET to the face's factory settings."
1519 (let* ((symbol (widget-value widget
))
1520 (child (car (widget-get widget
:children
)))
1521 (value (get symbol
'factory-face
)))
1523 (error "No factory default for this face"))
1524 (put symbol
'customized-face nil
)
1525 (when (get symbol
'saved-face
)
1526 (put symbol
'saved-face nil
)
1528 (when (fboundp 'copy-face
)
1529 (copy-face 'custom-face-empty symbol
))
1530 (custom-face-display-set symbol value
)
1531 (widget-value-set child value
)
1532 (custom-face-state-set widget
)
1533 (custom-redraw-magic widget
)))
1535 ;;; The `face' Widget.
1537 (define-widget 'face
'default
1538 "Select and customize a face."
1539 :convert-widget
'widget-item-convert-widget
1540 :format
"%[%t%]: %v"
1543 :value-create
'widget-face-value-create
1544 :value-delete
'widget-face-value-delete
1545 :value-get
'widget-item-value-get
1546 :validate
'widget-editable-list-validate
1547 :action
'widget-face-action
1548 :match
'(lambda (widget value
) (symbolp value
)))
1550 (defun widget-face-value-create (widget)
1551 ;; Create a `custom-face' child.
1552 (let* ((symbol (widget-value widget
))
1553 (child (widget-create-child-and-convert
1555 :format
"%t %s%m%h%v"
1558 (custom-magic-reset child
)
1559 (setq custom-options
(cons child custom-options
))
1560 (widget-put widget
:children
(list child
))))
1562 (defun widget-face-value-delete (widget)
1563 ;; Remove the child from the options.
1564 (let ((child (car (widget-get widget
:children
))))
1565 (setq custom-options
(delq child custom-options
))
1566 (widget-children-value-delete widget
)))
1568 (defvar face-history nil
1569 "History of entered face names.")
1571 (defun widget-face-action (widget &optional event
)
1572 "Prompt for a face."
1573 (let ((answer (completing-read "Face: "
1574 (mapcar (lambda (face)
1575 (list (symbol-name face
)))
1579 (unless (zerop (length answer
))
1580 (widget-value-set widget
(intern answer
))
1581 (widget-apply widget
:notify widget event
)
1584 ;;; The `hook' Widget.
1586 (define-widget 'hook
'list
1588 :convert-widget
'custom-hook-convert-widget
1591 (defun custom-hook-convert-widget (widget)
1592 ;; Handle `:custom-options'.
1593 (let* ((options (widget-get widget
:options
))
1594 (other `(editable-list :inline t
1595 :entry-format
"%i %d%v"
1596 (function :format
" %v")))
1598 (list `(checklist :inline t
1599 ,@(mapcar (lambda (entry)
1600 `(function-item ,entry
))
1604 (widget-put widget
:args args
)
1607 ;;; The `custom-group' Widget.
1609 (defcustom custom-group-tag-faces
'(custom-group-tag-face-1)
1610 ;; In XEmacs, this ought to play games with font size.
1611 "Face used for group tags.
1612 The first member is used for level 1 groups, the second for level 2,
1613 and so forth. The remaining group tags are shown with
1614 `custom-group-tag-face'."
1615 :type
'(repeat face
)
1618 (defface custom-group-tag-face-1
'((((class color
)
1620 (:foreground
"pink" :underline t
))
1623 (:foreground
"red" :underline t
))
1625 "Face used for group tags.")
1627 (defface custom-group-tag-face
'((((class color
)
1629 (:foreground
"light blue" :underline t
))
1632 (:foreground
"blue" :underline t
))
1634 "Face used for low level group tags."
1637 (define-widget 'custom-group
'custom
1639 :format
"%l%{%t%}:%L\n%m%h%a%v"
1640 :sample-face-get
'custom-group-sample-face-get
1641 :documentation-property
'group-documentation
1642 :help-echo
"Set or reset all members of this group."
1643 :value-create
'custom-group-value-create
1644 :action
'custom-group-action
1645 :custom-set
'custom-group-set
1646 :custom-save
'custom-group-save
1647 :custom-reset-current
'custom-group-reset-current
1648 :custom-reset-saved
'custom-group-reset-saved
1649 :custom-reset-factory
'custom-group-reset-factory
1650 :custom-menu
'custom-group-menu-create
)
1652 (defun custom-group-sample-face-get (widget)
1653 ;; Use :sample-face.
1654 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
1655 'custom-group-tag-face
))
1657 (defun custom-group-value-create (widget)
1658 (let ((state (widget-get widget
:custom-state
)))
1659 (unless (eq state
'hidden
)
1660 (message "Creating group...")
1661 (custom-load-widget widget
)
1662 (let* ((level (widget-get widget
:custom-level
))
1663 (symbol (widget-value widget
))
1664 (members (get symbol
'custom-group
))
1665 (prefixes (widget-get widget
:custom-prefixes
))
1666 (custom-prefix-list (custom-prefix-add symbol prefixes
))
1667 (length (length members
))
1669 (children (mapcar (lambda (entry)
1670 (widget-insert "\n")
1671 (message "Creating group members... %2d%%"
1672 (/ (* 100.0 count
) length
))
1673 (setq count
(1+ count
))
1675 (widget-create-child-and-convert
1676 widget
(nth 1 entry
)
1678 :tag
(custom-unlispify-tag-name
1680 :custom-prefixes custom-prefix-list
1681 :custom-level
(1+ level
)
1682 :value
(nth 0 entry
))
1683 (unless (eq (preceding-char) ?
\n)
1684 (widget-insert "\n"))))
1686 (message "Creating group magic...")
1687 (mapcar 'custom-magic-reset children
)
1688 (message "Creating group state...")
1689 (widget-put widget
:children children
)
1690 (custom-group-state-update widget
)
1691 (message "Creating group... done")))))
1693 (defvar custom-group-menu
1694 '(("Set" . custom-group-set
)
1695 ("Save" . custom-group-save
)
1696 ("Reset to Current" . custom-group-reset-current
)
1697 ("Reset to Saved" . custom-group-reset-saved
)
1698 ("Reset to Factory" . custom-group-reset-factory
))
1699 "Alist of actions for the `custom-group' widget.
1700 The key is a string containing the name of the action, the value is a
1701 lisp function taking the widget as an element which will be called
1702 when the action is chosen.")
1704 (defun custom-group-action (widget &optional event
)
1705 "Show the menu for `custom-group' WIDGET.
1706 Optional EVENT is the location for the menu."
1707 (if (eq (widget-get widget
:custom-state
) 'hidden
)
1709 (widget-put widget
:custom-state
'unknown
)
1710 (custom-redraw widget
))
1711 (let* ((completion-ignore-case t
)
1712 (answer (widget-choose (custom-unlispify-tag-name
1713 (widget-get widget
:value
))
1717 (funcall answer widget
)))))
1719 (defun custom-group-set (widget)
1720 "Set changes in all modified group members."
1721 (let ((children (widget-get widget
:children
)))
1722 (mapcar (lambda (child)
1723 (when (eq (widget-get child
:custom-state
) 'modified
)
1724 (widget-apply child
:custom-set
)))
1727 (defun custom-group-save (widget)
1728 "Save all modified group members."
1729 (let ((children (widget-get widget
:children
)))
1730 (mapcar (lambda (child)
1731 (when (memq (widget-get child
:custom-state
) '(modified set
))
1732 (widget-apply child
:custom-save
)))
1735 (defun custom-group-reset-current (widget)
1736 "Reset all modified group members."
1737 (let ((children (widget-get widget
:children
)))
1738 (mapcar (lambda (child)
1739 (when (eq (widget-get child
:custom-state
) 'modified
)
1740 (widget-apply child
:custom-reset-current
)))
1743 (defun custom-group-reset-saved (widget)
1744 "Reset all modified or set group members."
1745 (let ((children (widget-get widget
:children
)))
1746 (mapcar (lambda (child)
1747 (when (memq (widget-get child
:custom-state
) '(modified set
))
1748 (widget-apply child
:custom-reset-saved
)))
1751 (defun custom-group-reset-factory (widget)
1752 "Reset all modified, set, or saved group members."
1753 (let ((children (widget-get widget
:children
)))
1754 (mapcar (lambda (child)
1755 (when (memq (widget-get child
:custom-state
)
1756 '(modified set saved
))
1757 (widget-apply child
:custom-reset-factory
)))
1760 (defun custom-group-state-update (widget)
1762 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
1763 (let* ((children (widget-get widget
:children
))
1764 (states (mapcar (lambda (child)
1765 (widget-get child
:custom-state
))
1767 (magics custom-magic-alist
)
1770 (let ((magic (car (car magics
))))
1771 (if (and (not (eq magic
'hidden
))
1772 (memq magic states
))
1775 (setq magics
(cdr magics
)))))
1776 (widget-put widget
:custom-state found
)))
1777 (custom-magic-reset widget
))
1779 ;;; The `custom-save-all' Function.
1781 (defcustom custom-file
"~/.emacs"
1782 "File used for storing customization information.
1783 If you change this from the default \"~/.emacs\" you need to
1784 explicitly load that file for the settings to take effect."
1788 (defun custom-save-delete (symbol)
1789 "Delete the call to SYMBOL form `custom-file'.
1790 Leave point at the location of the call, or after the last expression."
1791 (set-buffer (find-file-noselect custom-file
))
1792 (goto-char (point-min))
1795 (let ((sexp (condition-case nil
1796 (read (current-buffer))
1797 (end-of-file (throw 'found nil
)))))
1798 (when (and (listp sexp
)
1799 (eq (car sexp
) symbol
))
1800 (delete-region (save-excursion
1804 (throw 'found nil
))))))
1806 (defun custom-save-variables ()
1807 "Save all customized variables in `custom-file'."
1809 (custom-save-delete 'custom-set-variables
)
1810 (let ((standard-output (current-buffer)))
1813 (princ "(custom-set-variables")
1814 (mapatoms (lambda (symbol)
1815 (let ((value (get symbol
'saved-value
)))
1821 (if (or (get symbol
'factory-value
)
1822 (and (not (boundp symbol
))
1823 (not (get symbol
'force-value
))))
1827 (unless (looking-at "\n")
1830 (defun custom-save-faces ()
1831 "Save all customized faces in `custom-file'."
1833 (custom-save-delete 'custom-set-faces
)
1834 (let ((standard-output (current-buffer)))
1837 (princ "(custom-set-faces")
1838 (mapatoms (lambda (symbol)
1839 (let ((value (get symbol
'saved-face
)))
1845 (if (or (get symbol
'factory-face
)
1846 (and (not (custom-facep symbol
))
1847 (not (get symbol
'force-face
))))
1851 (unless (looking-at "\n")
1855 (defun custom-save-all ()
1856 "Save all customizations in `custom-file'."
1857 (custom-save-variables)
1860 (set-buffer (find-file-noselect custom-file
))
1863 ;;; The Customize Menu.
1865 (defcustom custom-menu-nesting
2
1866 "Maximum nesting in custom menus."
1870 (defun custom-face-menu-create (widget symbol
)
1871 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
1872 (vector (custom-unlispify-menu-entry symbol
)
1873 `(custom-buffer-create '((,symbol custom-face
)))
1876 (defun custom-variable-menu-create (widget symbol
)
1877 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
1878 (let ((type (get symbol
'custom-type
)))
1879 (unless (listp type
)
1880 (setq type
(list type
)))
1881 (if (and type
(widget-get type
:custom-menu
))
1882 (widget-apply type
:custom-menu symbol
)
1883 (vector (custom-unlispify-menu-entry symbol
)
1884 `(custom-buffer-create '((,symbol custom-variable
)))
1887 (widget-put (get 'boolean
'widget-type
)
1888 :custom-menu
(lambda (widget symbol
)
1889 (vector (custom-unlispify-menu-entry symbol
)
1890 `(custom-buffer-create
1891 '((,symbol custom-variable
)))
1893 ':selected symbol
)))
1895 (if (string-match "XEmacs" emacs-version
)
1896 ;; XEmacs can create menus dynamically.
1897 (defun custom-group-menu-create (widget symbol
)
1898 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
1899 `( ,(custom-unlispify-menu-entry symbol t
)
1900 :filter
(lambda (&rest junk
)
1901 (cdr (custom-menu-create ',symbol
)))))
1903 (defun custom-group-menu-create (widget symbol
)
1904 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
1905 ;; Limit the nesting.
1906 (let ((custom-menu-nesting (1- custom-menu-nesting
)))
1907 (custom-menu-create symbol
))))
1909 (defun custom-menu-create (symbol &optional name
)
1910 "Create menu for customization group SYMBOL.
1911 If optional NAME is given, use that as the name of the menu.
1912 Otherwise make up a name from SYMBOL.
1913 The menu is in a format applicable to `easy-menu-define'."
1915 (setq name
(custom-unlispify-menu-entry symbol
)))
1916 (let ((item (vector name
1917 `(custom-buffer-create '((,symbol custom-group
)))
1919 (if (and (>= custom-menu-nesting
0)
1920 (< (length (get symbol
'custom-group
)) widget-menu-max-size
))
1921 (let ((custom-prefix-list (custom-prefix-add symbol
1922 custom-prefix-list
)))
1923 (custom-load-symbol symbol
)
1924 `(,(custom-unlispify-menu-entry symbol t
)
1927 ,@(mapcar (lambda (entry)
1928 (widget-apply (if (listp (nth 1 entry
))
1930 (list (nth 1 entry
)))
1931 :custom-menu
(nth 0 entry
)))
1932 (get symbol
'custom-group
))))
1936 (defun custom-menu-update (event)
1937 "Update customize menu."
1939 (add-hook 'custom-define-hook
'custom-menu-reset
)
1940 (let* ((emacs (widget-apply '(custom-group) :custom-menu
'emacs
))
1941 (menu `(,(car custom-help-menu
)
1943 ,@(cdr (cdr custom-help-menu
)))))
1944 (let ((map (easy-menu-create-keymaps (car menu
) (cdr menu
))))
1945 (define-key global-map
[menu-bar help-menu customize-menu
]
1946 (cons (car menu
) map
)))))
1951 (defun custom-make-dependencies ()
1952 "Batch function to extract custom dependencies from .el files.
1953 Usage: emacs -batch *.el -f custom-make-dependencies > deps.el"
1954 (let ((buffers (buffer-list)))
1956 (set-buffer (car buffers
))
1957 (setq buffers
(cdr buffers
))
1958 (let ((file (buffer-file-name)))
1959 (when (and file
(string-match "\\`\\(.*\\)\\.el\\'" file
))
1960 (goto-char (point-min))
1962 (let ((name (file-name-nondirectory (match-string 1 file
))))
1964 (let ((expr (read (current-buffer))))
1965 (when (and (listp expr
)
1966 (memq (car expr
) '(defcustom defface defgroup
)))
1968 (put (nth 1 expr
) 'custom-where name
)))))
1970 (mapatoms (lambda (symbol)
1971 (let ((members (get symbol
'custom-group
))
1976 (princ " 'custom-loads '(")
1978 (setq item
(car (car members
))
1979 members
(cdr members
)
1980 where
(get item
'custom-where
))
1981 (unless (or (null where
)
1982 (member where found
))
1986 (push where found
)))
1993 ;; cus-edit.el ends here