annotate lisp/custom/custom-edit.el @ 22:8fc7fe29b841 r19-15b94

Import from CVS: tag r19-15b94
author cvs
date Mon, 13 Aug 2007 08:50:29 +0200
parents 859a2309aef8
children 4103f0995bd7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1 ;;; custom-edit.el --- Tools for customization Emacs.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
2 ;;
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
4 ;;
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
6 ;; Keywords: help, faces
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
7 ;; Version: 1.40
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
9
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
10 ;;; Commentary:
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
11 ;;
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
12 ;; See `custom.el'.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
13
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
14 ;;; Code:
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
15
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
16 (require 'custom)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
17 (require 'widget-edit)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
18 (require 'easymenu)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
19
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
20 (define-widget-keywords :custom-prefixes :custom-menu :custom-show
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
21 :custom-magic :custom-state :custom-level :custom-form
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
22 :custom-set :custom-save :custom-reset-current :custom-reset-saved
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
23 :custom-reset-factory)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
24
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
25 ;;; Utilities.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
26
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
27 (defun custom-quote (sexp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
28 "Quote SEXP iff it is not self quoting."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
29 (if (or (memq sexp '(t nil))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
30 (and (symbolp sexp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
31 (eq (aref (symbol-name sexp) 0) ?:))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
32 (and (listp sexp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
33 (memq (car sexp) '(lambda)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
34 (stringp sexp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
35 (numberp sexp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
36 (and (fboundp 'characterp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
37 (characterp sexp)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
38 sexp
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
39 (list 'quote sexp)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
40
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
41 (defun custom-split-regexp-maybe (regexp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
42 "If REGEXP is a string, split it to a list at `\\|'.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
43 You can get the original back with from the result with:
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
44 (mapconcat 'identity result \"\\|\")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
45
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
46 IF REGEXP is not a string, return it unchanged."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
47 (if (stringp regexp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
48 (let ((start 0)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
49 all)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
50 (while (string-match "\\\\|" regexp start)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
51 (setq all (cons (substring regexp start (match-beginning 0)) all)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
52 start (match-end 0)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
53 (nreverse (cons (substring regexp start) all)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
54 regexp))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
55
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
56 (defvar custom-prefix-list nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
57 "List of prefixes that should be ignored by `custom-unlispify'")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
58
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
59 (defcustom custom-unlispify-menu-entries t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
60 "Display menu entries as words instead of symbols if non nil."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
61 :group 'customize
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
62 :type 'boolean)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
63
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
64 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
65 "Convert symbol into a menu entry."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
66 (cond ((not custom-unlispify-menu-entries)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
67 (symbol-name symbol))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
68 ((get symbol 'custom-tag)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
69 (if no-suffix
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
70 (get symbol 'custom-tag)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
71 (concat (get symbol 'custom-tag) "...")))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
72 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
73 (save-excursion
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
74 (set-buffer (get-buffer-create " *Custom-Work*"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
75 (erase-buffer)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
76 (princ symbol (current-buffer))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
77 (goto-char (point-min))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
78 (let ((prefixes custom-prefix-list)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
79 prefix)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
80 (while prefixes
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
81 (setq prefix (car prefixes))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
82 (if (search-forward prefix (+ (point) (length prefix)) t)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
83 (progn
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
84 (setq prefixes nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
85 (delete-region (point-min) (point)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
86 (setq prefixes (cdr prefixes)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
87 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
88 (capitalize-region (point-min) (point-max))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
89 (unless no-suffix
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
90 (goto-char (point-max))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
91 (insert "..."))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
92 (buffer-string)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
93
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
94 (defcustom custom-unlispify-tag-names t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
95 "Display tag names as words instead of symbols if non nil."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
96 :group 'customize
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
97 :type 'boolean)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
98
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
99 (defun custom-unlispify-tag-name (symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
100 "Convert symbol into a menu entry."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
101 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
102 (custom-unlispify-menu-entry symbol t)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
103
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
104 (defun custom-prefix-add (symbol prefixes)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
105 ;; Addd SYMBOL to list of ignored PREFIXES.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
106 (cons (or (get symbol 'custom-prefix)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
107 (concat (symbol-name symbol) "-"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
108 prefixes))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
109
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
110 ;;; The Custom Mode.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
111
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
112 (defvar custom-options nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
113 "Customization widgets in the current buffer.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
114
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
115 (defvar custom-mode-map nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
116 "Keymap for `custom-mode'.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
117
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
118 (unless custom-mode-map
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
119 (setq custom-mode-map (make-sparse-keymap))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
120 (set-keymap-parent custom-mode-map widget-keymap))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
121
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
122 (easy-menu-define custom-mode-menu
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
123 custom-mode-map
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
124 "Menu used in customization buffers."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
125 '("Custom"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
126 ["Set" custom-set t]
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
127 ["Save" custom-save t]
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
128 ["Reset to Current" custom-reset-current t]
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
129 ["Reset to Saved" custom-reset-saved t]
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
130 ["Reset to Factory Settings" custom-reset-factory t]
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
131 ["Info" (Info-goto-node "(custom)The Customization Buffer") t]))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
132
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
133 (defcustom custom-mode-hook nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
134 "Hook called when entering custom-mode."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
135 :type 'hook
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
136 :group 'customize)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
137
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
138 (defun custom-mode ()
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
139 "Major mode for editing customization buffers.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
140
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
141 The following commands are available:
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
142
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
143 \\[widget-forward] Move to next button or editable field.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
144 \\[widget-backward] Move to previous button or editable field.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
145 \\[widget-button-click] Activate button under the mouse pointer.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
146 \\[widget-button-press] Activate button under point.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
147 \\[custom-set] Set all modifications.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
148 \\[custom-save] Make all modifications default.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
149 \\[custom-reset-current] Reset all modified options.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
150 \\[custom-reset-saved] Reset all modified or set options.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
151 \\[custom-reset-factory] Reset all options.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
152
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
153 Entry to this mode calls the value of `custom-mode-hook'
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
154 if that value is non-nil."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
155 (kill-all-local-variables)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
156 (setq major-mode 'custom-mode
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
157 mode-name "Custom")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
158 (use-local-map custom-mode-map)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
159 (easy-menu-add custom-mode-menu)
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
160 (make-local-variable 'custom-options)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
161 (run-hooks 'custom-mode-hook))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
162
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
163 ;;; Custom Mode Commands.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
164
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
165 (defun custom-set ()
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
166 "Set changes in all modified options."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
167 (interactive)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
168 (let ((children custom-options))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
169 (mapcar (lambda (child)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
170 (when (eq (widget-get child :custom-state) 'modified)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
171 (widget-apply child :custom-set)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
172 children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
173
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
174 (defun custom-save ()
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
175 "Set all modified group members and save them."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
176 (interactive)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
177 (let ((children custom-options))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
178 (mapcar (lambda (child)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
179 (when (memq (widget-get child :custom-state) '(modified set))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
180 (widget-apply child :custom-save)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
181 children))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
182 (custom-save-all))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
183
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
184 (defvar custom-reset-menu
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
185 '(("Current" . custom-reset-current)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
186 ("Saved" . custom-reset-saved)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
187 ("Factory Settings" . custom-reset-factory))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
188 "Alist of actions for the `Reset' button.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
189 The key is a string containing the name of the action, the value is a
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
190 lisp function taking the widget as an element which will be called
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
191 when the action is chosen.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
192
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
193 (defun custom-reset (event)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
194 "Select item from reset menu."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
195 (let* ((completion-ignore-case t)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
196 (answer (widget-choose "Reset to"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
197 custom-reset-menu
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
198 event)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
199 (if answer
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
200 (funcall answer))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
201
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
202 (defun custom-reset-current ()
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
203 "Reset all modified group members to their current value."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
204 (interactive)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
205 (let ((children custom-options))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
206 (mapcar (lambda (child)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
207 (when (eq (widget-get child :custom-state) 'modified)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
208 (widget-apply child :custom-reset-current)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
209 children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
210
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
211 (defun custom-reset-saved ()
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
212 "Reset all modified or set group members to their saved value."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
213 (interactive)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
214 (let ((children custom-options))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
215 (mapcar (lambda (child)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
216 (when (eq (widget-get child :custom-state) 'modified)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
217 (widget-apply child :custom-reset-current)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
218 children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
219
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
220 (defun custom-reset-factory ()
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
221 "Reset all modified, set, or saved group members to their factory settings."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
222 (interactive)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
223 (let ((children custom-options))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
224 (mapcar (lambda (child)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
225 (when (eq (widget-get child :custom-state) 'modified)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
226 (widget-apply child :custom-reset-current)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
227 children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
228
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
229 ;;; The Customize Commands
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
230
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
231 ;;;###autoload
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
232 (defun customize (symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
233 "Customize SYMBOL, which must be a customization group."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
234 (interactive (list (completing-read "Customize group: (default emacs) "
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
235 obarray
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
236 (lambda (symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
237 (get symbol 'custom-group))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
238 t)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
239
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
240 (when (stringp symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
241 (if (string-equal "" symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
242 (setq symbol 'emacs)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
243 (setq symbol (intern symbol))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
244 (custom-buffer-create (list (list symbol 'custom-group))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
245
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
246 ;;;###autoload
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
247 (defun customize-variable (symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
248 "Customize SYMBOL, which must be a variable."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
249 (interactive
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
250 ;; Code stolen from `help.el'.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
251 (let ((v (variable-at-point))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
252 (enable-recursive-minibuffers t)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
253 val)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
254 (setq val (completing-read
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
255 (if v
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
256 (format "Customize variable (default %s): " v)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
257 "Customize variable: ")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
258 obarray 'boundp t))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
259 (list (if (equal val "")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
260 v (intern val)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
261 (custom-buffer-create (list (list symbol 'custom-variable))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
262
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
263 ;;;###autoload
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
264 (defun customize-face (symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
265 "Customize FACE."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
266 (interactive (list (completing-read "Customize face: "
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
267 obarray 'custom-facep)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
268 (if (stringp symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
269 (setq symbol (intern symbol)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
270 (unless (symbolp symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
271 (error "Should be a symbol %S" symbol))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
272 (custom-buffer-create (list (list symbol 'custom-face))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
273
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
274 ;;;###autoload
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
275 (defun customize-customized ()
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
276 "Customize all already customized user options."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
277 (interactive)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
278 (let ((found nil))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
279 (mapatoms (lambda (symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
280 (and (get symbol 'saved-face)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
281 (custom-facep symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
282 (setq found (cons (list symbol 'custom-face) found)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
283 (and (get symbol 'saved-value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
284 (boundp symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
285 (setq found
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
286 (cons (list symbol 'custom-variable) found)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
287 (if found
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
288 (custom-buffer-create found)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
289 (error "No customized user options"))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
290
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
291 ;;;###autoload
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
292 (defun customize-apropos (regexp &optional all)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
293 "Customize all user options matching REGEXP.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
294 If ALL (e.g., started with a prefix key), include options which are not
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
295 user-settable."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
296 (interactive "sCustomize regexp: \nP")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
297 (let ((found nil))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
298 (mapatoms (lambda (symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
299 (when (string-match regexp (symbol-name symbol))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
300 (when (get symbol 'custom-group)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
301 (setq found (cons (list symbol 'custom-group) found)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
302 (when (custom-facep symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
303 (setq found (cons (list symbol 'custom-face) found)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
304 (when (and (boundp symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
305 (or (get symbol 'saved-value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
306 (get symbol 'factory-value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
307 (if all
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
308 (get symbol 'variable-documentation)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
309 (user-variable-p symbol))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
310 (setq found
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
311 (cons (list symbol 'custom-variable) found))))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
312 (if found
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
313 (custom-buffer-create found)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
314 (error "No matches"))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
315
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
316 ;;;###autoload
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
317 (defun custom-buffer-create (options)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
318 "Create a buffer containing OPTIONS.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
319 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
320 SYMBOL is a customization option, and WIDGET is a widget for editing
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
321 that option."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
322 (kill-buffer (get-buffer-create "*Customization*"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
323 (switch-to-buffer (get-buffer-create "*Customization*"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
324 (custom-mode)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
325 (widget-insert "This is a customization buffer.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
326 Push RET or click mouse-2 on the word ")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
327 (widget-create 'info-link
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
328 :tag "help"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
329 :help-echo "Push me for help."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
330 "(custom)The Customization Buffer")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
331 (widget-insert " for more information.\n\n")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
332 (setq custom-options
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
333 (mapcar (lambda (entry)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
334 (prog1
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
335 (if (> (length options) 1)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
336 (widget-create (nth 1 entry)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
337 :tag (custom-unlispify-tag-name
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
338 (nth 0 entry))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
339 :value (nth 0 entry))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
340 ;; If there is only one entry, don't hide it!
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
341 (widget-create (nth 1 entry)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
342 :custom-state 'unknown
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
343 :tag (custom-unlispify-tag-name
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
344 (nth 0 entry))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
345 :value (nth 0 entry)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
346 (unless (eq (preceding-char) ?\n)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
347 (widget-insert "\n"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
348 (widget-insert "\n")))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
349 options))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
350 (mapcar 'custom-magic-reset custom-options)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
351 (widget-create 'push-button
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
352 :tag "Set"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
353 :help-echo "Push me to set all modifications."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
354 :action (lambda (widget &optional event)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
355 (custom-set)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
356 (widget-insert " ")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
357 (widget-create 'push-button
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
358 :tag "Save"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
359 :help-echo "Push me to make the modifications default."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
360 :action (lambda (widget &optional event)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
361 (custom-save)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
362 (widget-insert " ")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
363 (widget-create 'push-button
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
364 :tag "Reset"
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
365 :help-echo "Push me to undo all modifications."
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
366 :action (lambda (widget &optional event)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
367 (custom-reset event)))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
368 (widget-insert " ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
369 (widget-create 'push-button
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
370 :tag "Done"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
371 :help-echo "Push me to bury the buffer."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
372 :action (lambda (widget &optional event)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
373 (bury-buffer)))
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
374 (widget-insert "\n")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
375 (widget-setup))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
376
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
377 ;;; Modification of Basic Widgets.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
378 ;;
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
379 ;; We add extra properties to the basic widgets needed here. This is
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
380 ;; fine, as long as we are careful to stay within out own namespace.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
381 ;;
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
382 ;; We want simple widgets to be displayed by default, but complex
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
383 ;; widgets to be hidden.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
384
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
385 (widget-put (get 'item 'widget-type) :custom-show t)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
386 (widget-put (get 'editable-field 'widget-type)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
387 :custom-show (lambda (widget value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
388 (let ((pp (pp-to-string value)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
389 (cond ((string-match "\n" pp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
390 nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
391 ((> (length pp) 40)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
392 nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
393 (t t)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
394 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
395
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
396 ;;; The `custom-manual' Widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
397
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
398 (define-widget 'custom-manual 'info-link
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
399 "Link to the manual entry for this customization option."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
400 :help-echo "Push me to read the manual."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
401 :tag "Manual")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
402
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
403 ;;; The `custom-magic' Widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
404
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
405 (defface custom-invalid-face '((((class color))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
406 (:foreground "yellow" :background "red"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
407 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
408 (:bold t :italic t :underline t)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
409 "Face used when the customize item is invalid.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
410
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
411 (defface custom-rogue-face '((((class color))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
412 (:foreground "pink" :background "black"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
413 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
414 (:underline t)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
415 "Face used when the customize item is not defined for customization.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
416
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
417 (defface custom-modified-face '((((class color))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
418 (:foreground "white" :background "blue"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
419 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
420 (:italic t :bold)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
421 "Face used when the customize item has been modified.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
422
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
423 (defface custom-set-face '((((class color))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
424 (:foreground "blue" :background "white"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
425 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
426 (:italic t)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
427 "Face used when the customize item has been set.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
428
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
429 (defface custom-changed-face '((((class color))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
430 (:foreground "white" :background "blue"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
431 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
432 (:italic t)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
433 "Face used when the customize item has been changed.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
434
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
435 (defface custom-saved-face '((t (:underline t)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
436 "Face used when the customize item has been saved.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
437
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
438 (defcustom custom-magic-alist '((nil "#" underline "\
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
439 uninitialized, you should not see this.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
440 (unknown "?" italic "\
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
441 unknown, you should not see this.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
442 (hidden "-" default "\
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
443 hidden, press the state button to show.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
444 (invalid "x" custom-invalid-face "\
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
445 the value displayed for this item is invalid and cannot be set.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
446 (modified "*" custom-modified-face "\
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
447 you have edited the item, and can now set it.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
448 (set "+" custom-set-face "\
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
449 you have set this item, but not saved it.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
450 (changed ":" custom-changed-face "\
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
451 this item has been changed outside customize.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
452 (saved "!" custom-saved-face "\
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
453 this item has been saved.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
454 (rogue "@" custom-rogue-face "\
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
455 this item is not prepared for customization.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
456 (factory " " nil "\
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
457 this item is unchanged from its factory setting."))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
458 "Alist of customize option states.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
459 Each entry is of the form (STATE MAGIC FACE DESCRIPTION), where
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
460
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
461 STATE is one of the following symbols:
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
462
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
463 `nil'
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
464 For internal use, should never occur.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
465 `unknown'
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
466 For internal use, should never occur.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
467 `hidden'
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
468 This item is not being displayed.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
469 `invalid'
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
470 This item is modified, but has an invalid form.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
471 `modified'
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
472 This item is modified, and has a valid form.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
473 `set'
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
474 This item has been set but not saved.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
475 `changed'
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
476 The current value of this item has been changed temporarily.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
477 `saved'
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
478 This item is marked for saving.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
479 `rogue'
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
480 This item has no customization information.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
481 `factory'
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
482 This item is unchanged from the factory default.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
483
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
484 MAGIC is a string used to present that state.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
485
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
486 FACE is a face used to present the state.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
487
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
488 DESCRIPTION is a string describing the state.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
489
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
490 The list should be sorted most significant first."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
491 :type '(list (checklist :inline t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
492 (group (const nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
493 (string :tag "Magic")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
494 face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
495 (string :tag "Description"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
496 (group (const unknown)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
497 (string :tag "Magic")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
498 face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
499 (string :tag "Description"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
500 (group (const hidden)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
501 (string :tag "Magic")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
502 face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
503 (string :tag "Description"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
504 (group (const invalid)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
505 (string :tag "Magic")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
506 face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
507 (string :tag "Description"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
508 (group (const modified)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
509 (string :tag "Magic")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
510 face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
511 (string :tag "Description"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
512 (group (const set)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
513 (string :tag "Magic")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
514 face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
515 (string :tag "Description"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
516 (group (const changed)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
517 (string :tag "Magic")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
518 face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
519 (string :tag "Description"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
520 (group (const saved)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
521 (string :tag "Magic")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
522 face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
523 (string :tag "Description"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
524 (group (const rogue)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
525 (string :tag "Magic")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
526 face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
527 (string :tag "Description"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
528 (group (const factory)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
529 (string :tag "Magic")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
530 face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
531 (string :tag "Description")))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
532 (editable-list :inline t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
533 (group symbol
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
534 (string :tag "Magic")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
535 face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
536 (string :tag "Description"))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
537 :group 'customize)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
538
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
539 (defcustom custom-magic-show 'long
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
540 "Show long description of the state of each customization option."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
541 :type '(choice (const :tag "no" nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
542 (const short)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
543 (const long))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
544 :group 'customize)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
545
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
546 (defcustom custom-magic-show-button t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
547 "Show a magic button indicating the state of each customization option."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
548 :type 'boolean
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
549 :group 'customize)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
550
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
551 (define-widget 'custom-magic 'default
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
552 "Show and manipulate state for a customization option."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
553 :format "%v"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
554 :action 'widget-choice-item-action
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
555 :value-get 'ignore
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
556 :value-create 'custom-magic-value-create
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
557 :value-delete 'widget-children-value-delete)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
558
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
559 (defun custom-magic-value-create (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
560 ;; Create compact status report for WIDGET.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
561 (let* ((parent (widget-get widget :parent))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
562 (state (widget-get parent :custom-state))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
563 (entry (assq state custom-magic-alist))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
564 (magic (nth 1 entry))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
565 (face (nth 2 entry))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
566 (text (nth 3 entry))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
567 (lisp (eq (widget-get parent :custom-form) 'lisp))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
568 children)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
569 (when custom-magic-show
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
570 (push (widget-create-child-and-convert widget 'choice-item
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
571 :help-echo "\
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
572 Push me to change the state of this item."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
573 :format "%[%t%]"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
574 :tag "State")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
575 children)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
576 (insert ": ")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
577 (if (eq custom-magic-show 'long)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
578 (insert text)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
579 (insert (symbol-name state)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
580 (when lisp
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
581 (insert " (lisp)"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
582 (insert "\n"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
583 (when custom-magic-show-button
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
584 (when custom-magic-show
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
585 (let ((indent (widget-get parent :indent)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
586 (when indent
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
587 (insert-char ? indent))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
588 (push (widget-create-child-and-convert widget 'choice-item
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
589 :button-face face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
590 :help-echo "\
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
591 Push me to change the state."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
592 :format "%[%t%]"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
593 :tag (if lisp
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
594 (concat "(" magic ")")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
595 (concat "[" magic "]")))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
596 children)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
597 (insert " "))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
598 (widget-put widget :children children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
599
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
600 (defun custom-magic-reset (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
601 "Redraw the :custom-magic property of WIDGET."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
602 (let ((magic (widget-get widget :custom-magic)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
603 (widget-value-set magic (widget-value magic))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
604
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
605 ;;; The `custom-level' Widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
606
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
607 (define-widget 'custom-level 'item
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
608 "The custom level buttons."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
609 :format "%[%t%]"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
610 :help-echo "Push me to expand or collapse this item."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
611 :action 'custom-level-action)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
612
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
613 (defun custom-level-action (widget &optional event)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
614 "Toggle visibility for parent to WIDGET."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
615 (let* ((parent (widget-get widget :parent))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
616 (state (widget-get parent :custom-state)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
617 (cond ((memq state '(invalid modified))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
618 (error "There are unset changes"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
619 ((eq state 'hidden)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
620 (widget-put parent :custom-state 'unknown))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
621 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
622 (widget-put parent :custom-state 'hidden)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
623 (custom-redraw parent)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
624
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
625 ;;; The `custom' Widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
626
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
627 (define-widget 'custom 'default
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
628 "Customize a user option."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
629 :convert-widget 'custom-convert-widget
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
630 :format "%l%[%t%]: %v%m%h%a"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
631 :format-handler 'custom-format-handler
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
632 :notify 'custom-notify
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
633 :custom-level 1
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
634 :custom-state 'hidden
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
635 :documentation-property 'widget-subclass-responsibility
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
636 :value-create 'widget-subclass-responsibility
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
637 :value-delete 'widget-children-value-delete
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
638 :value-get 'widget-item-value-get
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
639 :validate 'widget-editable-list-validate
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
640 :match (lambda (widget value) (symbolp value)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
641
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
642 (defun custom-convert-widget (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
643 ;; Initialize :value and :tag from :args in WIDGET.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
644 (let ((args (widget-get widget :args)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
645 (when args
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
646 (widget-put widget :value (widget-apply widget
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
647 :value-to-internal (car args)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
648 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
649 (widget-put widget :args nil)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
650 widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
651
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
652 (defun custom-format-handler (widget escape)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
653 ;; We recognize extra escape sequences.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
654 (let* ((buttons (widget-get widget :buttons))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
655 (state (widget-get widget :custom-state))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
656 (level (widget-get widget :custom-level)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
657 (cond ((eq escape ?l)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
658 (when level
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
659 (push (widget-create-child-and-convert
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
660 widget 'custom-level (make-string level ?*))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
661 buttons)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
662 (widget-insert " ")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
663 (widget-put widget :buttons buttons)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
664 ((eq escape ?L)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
665 (when (eq state 'hidden)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
666 (widget-insert " ...")))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
667 ((eq escape ?m)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
668 (and (eq (preceding-char) ?\n)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
669 (widget-get widget :indent)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
670 (insert-char ? (widget-get widget :indent)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
671 (let ((magic (widget-create-child-and-convert
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
672 widget 'custom-magic nil)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
673 (widget-put widget :custom-magic magic)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
674 (push magic buttons)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
675 (widget-put widget :buttons buttons)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
676 ((eq escape ?a)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
677 (let* ((symbol (widget-get widget :value))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
678 (links (get symbol 'custom-links))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
679 (many (> (length links) 2)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
680 (when links
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
681 (and (eq (preceding-char) ?\n)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
682 (widget-get widget :indent)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
683 (insert-char ? (widget-get widget :indent)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
684 (insert "See also ")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
685 (while links
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
686 (push (widget-create-child-and-convert widget (car links))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
687 buttons)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
688 (setq links (cdr links))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
689 (cond ((null links)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
690 (insert ".\n"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
691 ((null (cdr links))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
692 (if many
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
693 (insert ", and ")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
694 (insert " and ")))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
695 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
696 (insert ", "))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
697 (widget-put widget :buttons buttons))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
698 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
699 (widget-default-format-handler widget escape)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
700
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
701 (defun custom-notify (widget &rest args)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
702 "Keep track of changes."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
703 (widget-put widget :custom-state 'modified)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
704 (let ((buffer-undo-list t))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
705 (custom-magic-reset widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
706 (apply 'widget-default-notify widget args))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
707
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
708 (defun custom-redraw (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
709 "Redraw WIDGET with current settings."
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
710 (let ((pos (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
711 (from (marker-position (widget-get widget :from)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
712 (to (marker-position (widget-get widget :to))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
713 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
714 (widget-value-set widget (widget-value widget))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
715 (custom-redraw-magic widget))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
716 (when (and (>= pos from) (<= pos to))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
717 (goto-char pos))))
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
718
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
719 (defun custom-redraw-magic (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
720 "Redraw WIDGET state with current settings."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
721 (while widget
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
722 (let ((magic (widget-get widget :custom-magic)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
723 (unless magic
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
724 (debug))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
725 (widget-value-set magic (widget-value magic))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
726 (when (setq widget (widget-get widget :group))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
727 (custom-group-state-update widget))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
728 (widget-setup))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
729
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
730 (defun custom-show (widget value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
731 "Non-nil if WIDGET should be shown with VALUE by default."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
732 (let ((show (widget-get widget :custom-show)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
733 (cond ((null show)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
734 nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
735 ((eq t show)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
736 t)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
737 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
738 (funcall show widget value)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
739
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
740 (defun custom-load-symbol (symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
741 "Load all dependencies for SYMBOL."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
742 (let ((loads (get symbol 'custom-loads))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
743 load)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
744 (while loads
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
745 (setq load (car loads)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
746 loads (cdr loads))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
747 (cond ((symbolp load)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
748 (condition-case nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
749 (require load)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
750 (error nil)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
751 ((assoc load load-history))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
752 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
753 (condition-case nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
754 (load-library load)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
755 (error nil)))))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
756
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
757 (defun custom-load-widget (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
758 "Load all dependencies for WIDGET."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
759 (custom-load-symbol (widget-value widget)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
760
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
761 ;;; The `custom-variable' Widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
762
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
763 (defface custom-variable-sample-face '((t (:underline t)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
764 "Face used for unpushable variable tags."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
765 :group 'customize)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
766
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
767 (defface custom-variable-button-face '((t (:underline t :bold t)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
768 "Face used for pushable variable tags."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
769 :group 'customize)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
770
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
771 (define-widget 'custom-variable 'custom
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
772 "Customize variable."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
773 :format "%l%v%m%h%a"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
774 :help-echo "Push me to set or reset this variable."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
775 :documentation-property 'variable-documentation
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
776 :custom-state nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
777 :custom-menu 'custom-variable-menu-create
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
778 :custom-form 'edit
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
779 :value-create 'custom-variable-value-create
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
780 :action 'custom-variable-action
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
781 :custom-set 'custom-variable-set
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
782 :custom-save 'custom-variable-save
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
783 :custom-reset-current 'custom-redraw
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
784 :custom-reset-saved 'custom-variable-reset-saved
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
785 :custom-reset-factory 'custom-variable-reset-factory)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
786
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
787 (defun custom-variable-value-create (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
788 "Here is where you edit the variables value."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
789 (custom-load-widget widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
790 (let* ((buttons (widget-get widget :buttons))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
791 (children (widget-get widget :children))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
792 (form (widget-get widget :custom-form))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
793 (state (widget-get widget :custom-state))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
794 (symbol (widget-get widget :value))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
795 (options (get symbol 'custom-options))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
796 (child-type (or (get symbol 'custom-type) 'sexp))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
797 (tag (widget-get widget :tag))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
798 (type (let ((tmp (if (listp child-type)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
799 (copy-list child-type)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
800 (list child-type))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
801 (when options
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
802 (widget-put tmp :options options))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
803 tmp))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
804 (conv (widget-convert type))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
805 (value (if (default-boundp symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
806 (default-value symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
807 (widget-get conv :value))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
808 ;; If the widget is new, the child determine whether it is hidden.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
809 (cond (state)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
810 ((custom-show type value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
811 (setq state 'unknown))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
812 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
813 (setq state 'hidden)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
814 ;; If we don't know the state, see if we need to edit it in lisp form.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
815 (when (eq state 'unknown)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
816 (unless (widget-apply conv :match value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
817 ;; (widget-apply (widget-convert type) :match value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
818 (setq form 'lisp)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
819 ;; Now we can create the child widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
820 (cond ((eq state 'hidden)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
821 ;; Indicate hidden value.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
822 (push (widget-create-child-and-convert
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
823 widget 'item
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
824 :format "%{%t%}: ..."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
825 :sample-face 'custom-variable-sample-face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
826 :tag tag
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
827 :parent widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
828 children))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
829 ((eq form 'lisp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
830 ;; In lisp mode edit the saved value when possible.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
831 (let* ((value (cond ((get symbol 'saved-value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
832 (car (get symbol 'saved-value)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
833 ((get symbol 'factory-value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
834 (car (get symbol 'factory-value)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
835 ((default-boundp symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
836 (custom-quote (default-value symbol)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
837 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
838 (custom-quote (widget-get conv :value))))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
839 (push (widget-create-child-and-convert
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
840 widget 'sexp
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
841 :button-face 'custom-variable-button-face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
842 :tag (symbol-name symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
843 :parent widget
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
844 :value value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
845 children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
846 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
847 ;; Edit mode.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
848 (push (widget-create-child-and-convert
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
849 widget type
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
850 :tag tag
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
851 :button-face 'custom-variable-button-face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
852 :sample-face 'custom-variable-sample-face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
853 :value value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
854 children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
855 ;; Now update the state.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
856 (unless (eq (preceding-char) ?\n)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
857 (widget-insert "\n"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
858 (if (eq state 'hidden)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
859 (widget-put widget :custom-state state)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
860 (custom-variable-state-set widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
861 (widget-put widget :custom-form form)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
862 (widget-put widget :buttons buttons)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
863 (widget-put widget :children children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
864
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
865 (defun custom-variable-state-set (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
866 "Set the state of WIDGET."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
867 (let* ((symbol (widget-value widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
868 (value (if (default-boundp symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
869 (default-value symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
870 (widget-get widget :value)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
871 tmp
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
872 (state (cond ((setq tmp (get symbol 'customized-value))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
873 (if (condition-case nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
874 (equal value (eval (car tmp)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
875 (error nil))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
876 'set
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
877 'changed))
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
878 ((setq tmp (get symbol 'saved-value))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
879 (if (condition-case nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
880 (equal value (eval (car tmp)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
881 (error nil))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
882 'saved
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
883 'changed))
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
884 ((setq tmp (get symbol 'factory-value))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
885 (if (condition-case nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
886 (equal value (eval (car tmp)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
887 (error nil))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
888 'factory
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
889 'changed))
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
890 (t 'rogue))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
891 (widget-put widget :custom-state state)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
892
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
893 (defvar custom-variable-menu
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
894 '(("Edit" . custom-variable-edit)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
895 ("Edit Lisp" . custom-variable-edit-lisp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
896 ("Set" . custom-variable-set)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
897 ("Save" . custom-variable-save)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
898 ("Reset to Current" . custom-redraw)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
899 ("Reset to Saved" . custom-variable-reset-saved)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
900 ("Reset to Factory Settings" . custom-variable-reset-factory))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
901 "Alist of actions for the `custom-variable' widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
902 The key is a string containing the name of the action, the value is a
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
903 lisp function taking the widget as an element which will be called
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
904 when the action is chosen.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
905
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
906 (defun custom-variable-action (widget &optional event)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
907 "Show the menu for `custom-variable' WIDGET.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
908 Optional EVENT is the location for the menu."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
909 (if (eq (widget-get widget :custom-state) 'hidden)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
910 (progn
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
911 (widget-put widget :custom-state 'unknown)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
912 (custom-redraw widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
913 (let* ((completion-ignore-case t)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
914 (answer (widget-choose (capitalize
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
915 (symbol-name (widget-get widget :value)))
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
916 custom-variable-menu
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
917 event)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
918 (if answer
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
919 (funcall answer widget)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
920
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
921 (defun custom-variable-edit (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
922 "Edit value of WIDGET."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
923 (widget-put widget :custom-state 'unknown)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
924 (widget-put widget :custom-form 'edit)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
925 (custom-redraw widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
926
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
927 (defun custom-variable-edit-lisp (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
928 "Edit the lisp representation of the value of WIDGET."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
929 (widget-put widget :custom-state 'unknown)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
930 (widget-put widget :custom-form 'lisp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
931 (custom-redraw widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
932
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
933 (defun custom-variable-set (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
934 "Set the current value for the variable being edited by WIDGET."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
935 (let ((form (widget-get widget :custom-form))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
936 (state (widget-get widget :custom-state))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
937 (child (car (widget-get widget :children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
938 (symbol (widget-value widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
939 val)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
940 (cond ((eq state 'hidden)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
941 (error "Cannot set hidden variable."))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
942 ((setq val (widget-apply child :validate))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
943 (goto-char (widget-get val :from))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
944 (error "%s" (widget-get val :error)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
945 ((eq form 'lisp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
946 (set symbol (eval (setq val (widget-value child))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
947 (put symbol 'customized-value (list val)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
948 (t
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
949 (set symbol (setq val (widget-value child)))
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
950 (put symbol 'customized-value (list (custom-quote val)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
951 (custom-variable-state-set widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
952 (custom-redraw-magic widget)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
953
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
954 (defun custom-variable-save (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
955 "Set the default value for the variable being edited by WIDGET."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
956 (let ((form (widget-get widget :custom-form))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
957 (state (widget-get widget :custom-state))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
958 (child (car (widget-get widget :children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
959 (symbol (widget-value widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
960 val)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
961 (cond ((eq state 'hidden)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
962 (error "Cannot set hidden variable."))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
963 ((setq val (widget-apply child :validate))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
964 (goto-char (widget-get val :from))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
965 (error "%s" (widget-get val :error)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
966 ((eq form 'lisp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
967 (put symbol 'saved-value (list (widget-value child)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
968 (set symbol (eval (widget-value child))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
969 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
970 (put symbol
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
971 'saved-value (list (custom-quote (widget-value
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
972 child))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
973 (set symbol (widget-value child))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
974 (put symbol 'customized-value nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
975 (custom-save-all)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
976 (custom-variable-state-set widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
977 (custom-redraw-magic widget)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
978
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
979 (defun custom-variable-reset-saved (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
980 "Restore the saved value for the variable being edited by WIDGET."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
981 (let ((symbol (widget-value widget)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
982 (if (get symbol 'saved-value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
983 (condition-case nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
984 (set symbol (eval (car (get symbol 'saved-value))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
985 (error nil))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
986 (error "No saved value for %s" symbol))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
987 (put symbol 'customized-value nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
988 (widget-put widget :custom-state 'unknown)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
989 (custom-redraw widget)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
990
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
991 (defun custom-variable-reset-factory (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
992 "Restore the factory setting for the variable being edited by WIDGET."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
993 (let ((symbol (widget-value widget)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
994 (if (get symbol 'factory-value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
995 (set symbol (eval (car (get symbol 'factory-value))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
996 (error "No factory default for %S" symbol))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
997 (put symbol 'customized-value nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
998 (when (get symbol 'saved-value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
999 (put symbol 'saved-value nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1000 (custom-save-all))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1001 (widget-put widget :custom-state 'unknown)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1002 (custom-redraw widget)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1003
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1004 ;;; The `custom-face-edit' Widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1005
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1006 (defvar custom-face-edit-args
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1007 (mapcar (lambda (att)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1008 (list 'group
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1009 :inline t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1010 (list 'const :format "" :value (nth 0 att))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1011 (nth 1 att)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1012 custom-face-attributes))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1013
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1014 (define-widget 'custom-face-edit 'checklist
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1015 "Edit face attributes."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1016 :format "%t: %v"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1017 :tag "Attributes"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1018 :extra-offset 12
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1019 :args (mapcar (lambda (att)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1020 (list 'group
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1021 :inline t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1022 (list 'const :format "" :value (nth 0 att))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1023 (nth 1 att)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1024 custom-face-attributes))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1025
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1026 ;;; The `custom-display' Widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1027
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1028 (define-widget 'custom-display 'menu-choice
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1029 "Select a display type."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1030 :tag "Display"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1031 :value t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1032 :args '((const :tag "all" t)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1033 (checklist :offset 0
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1034 :extra-offset 9
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1035 :args ((group (const :format "Type: " type)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1036 (checklist :inline t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1037 :offset 0
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1038 (const :format "X "
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1039 x)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1040 (const :format "PM "
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1041 pm)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1042 (const :format "Win32 "
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1043 win32)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1044 (const :format "DOS "
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1045 pc)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1046 (const :format "TTY%n"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1047 tty)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1048 (group (const :format "Class: " class)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1049 (checklist :inline t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1050 :offset 0
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1051 (const :format "Color "
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1052 color)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1053 (const :format
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1054 "Grayscale "
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1055 grayscale)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1056 (const :format "Monochrome%n"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1057 mono)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1058 (group (const :format "Background: " background)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1059 (checklist :inline t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1060 :offset 0
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1061 (const :format "Light "
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1062 light)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1063 (const :format "Dark\n"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1064 dark)))))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1065
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1066 ;;; The `custom-face' Widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1067
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1068 (defface custom-face-tag-face '((t (:underline t)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1069 "Face used for face tags."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1070 :group 'customize)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1071
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1072 (define-widget 'custom-face 'custom
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1073 "Customize face."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1074 :format "%l%{%t%}: %s%m%h%a%v"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1075 :format-handler 'custom-face-format-handler
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1076 :sample-face 'custom-face-tag-face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1077 :help-echo "Push me to set or reset this face."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1078 :documentation-property 'face-documentation
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1079 :value-create 'custom-face-value-create
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1080 :action 'custom-face-action
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1081 :custom-set 'custom-face-set
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1082 :custom-save 'custom-face-save
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1083 :custom-reset-current 'custom-redraw
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1084 :custom-reset-saved 'custom-face-reset-saved
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1085 :custom-reset-factory 'custom-face-reset-factory
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1086 :custom-menu 'custom-face-menu-create)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1087
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1088 (defun custom-face-format-handler (widget escape)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1089 ;; We recognize extra escape sequences.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1090 (let (child
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1091 (symbol (widget-get widget :value)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1092 (cond ((eq escape ?s)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1093 (and (string-match "XEmacs" emacs-version)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1094 ;; XEmacs cannot display initialized faces.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1095 (not (custom-facep symbol))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1096 (copy-face 'custom-face-empty symbol))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1097 (setq child (widget-create-child-and-convert
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1098 widget 'item
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1099 :format "(%{%t%})\n"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1100 :sample-face symbol
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1101 :tag "sample")))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1102 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1103 (custom-format-handler widget escape)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1104 (when child
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1105 (widget-put widget
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1106 :buttons (cons child (widget-get widget :buttons))))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1107
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1108 (defun custom-face-value-create (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1109 ;; Create a list of the display specifications.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1110 (unless (eq (preceding-char) ?\n)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1111 (insert "\n"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1112 (when (not (eq (widget-get widget :custom-state) 'hidden))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1113 (custom-load-widget widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1114 (let* ((symbol (widget-value widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1115 (edit (widget-create-child-and-convert
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1116 widget 'editable-list
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1117 :entry-format "%i %d %v"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1118 :value (or (get symbol 'saved-face)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1119 (get symbol 'factory-face))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1120 '(group :format "%v"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1121 custom-display custom-face-edit))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1122 (custom-face-state-set widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1123 (widget-put widget :children (list edit)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1124
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1125 (defvar custom-face-menu
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1126 '(("Set" . custom-face-set)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1127 ("Save" . custom-face-save)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1128 ("Reset to Saved" . custom-face-reset-saved)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1129 ("Reset to Factory Setting" . custom-face-reset-factory))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1130 "Alist of actions for the `custom-face' widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1131 The key is a string containing the name of the action, the value is a
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1132 lisp function taking the widget as an element which will be called
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1133 when the action is chosen.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1134
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1135 (defun custom-face-state-set (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1136 "Set the state of WIDGET."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1137 (let ((symbol (widget-value widget)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1138 (widget-put widget :custom-state (cond ((get symbol 'customized-face)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1139 'set)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1140 ((get symbol 'saved-face)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1141 'saved)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1142 ((get symbol 'factory-face)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1143 'factory)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1144 (t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1145 'rogue)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1146
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1147 (defun custom-face-action (widget &optional event)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1148 "Show the menu for `custom-face' WIDGET.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1149 Optional EVENT is the location for the menu."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1150 (if (eq (widget-get widget :custom-state) 'hidden)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1151 (progn
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1152 (widget-put widget :custom-state 'unknown)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1153 (custom-redraw widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1154 (let* ((completion-ignore-case t)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1155 (symbol (widget-get widget :value))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
1156 (answer (widget-choose (capitalize (symbol-name symbol))
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1157 custom-face-menu event)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1158 (if answer
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1159 (funcall answer widget)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1160
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1161 (defun custom-face-set (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1162 "Make the face attributes in WIDGET take effect."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1163 (let* ((symbol (widget-value widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1164 (child (car (widget-get widget :children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1165 (value (widget-value child)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1166 (put symbol 'customized-face value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1167 (custom-face-display-set symbol value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1168 (custom-face-state-set widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1169 (custom-redraw-magic widget)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1170
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1171 (defun custom-face-save (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1172 "Make the face attributes in WIDGET default."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1173 (let* ((symbol (widget-value widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1174 (child (car (widget-get widget :children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1175 (value (widget-value child)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1176 (custom-face-display-set symbol value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1177 (put symbol 'saved-face value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1178 (put symbol 'customized-face nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1179 (custom-face-state-set widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1180 (custom-redraw-magic widget)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1181
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1182 (defun custom-face-reset-saved (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1183 "Restore WIDGET to the face's default attributes."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1184 (let* ((symbol (widget-value widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1185 (child (car (widget-get widget :children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1186 (value (get symbol 'saved-face)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1187 (unless value
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1188 (error "No saved value for this face"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1189 (put symbol 'customized-face nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1190 (custom-face-display-set symbol value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1191 (widget-value-set child value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1192 (custom-face-state-set widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1193 (custom-redraw-magic widget)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1194
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1195 (defun custom-face-reset-factory (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1196 "Restore WIDGET to the face's factory settings."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1197 (let* ((symbol (widget-value widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1198 (child (car (widget-get widget :children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1199 (value (get symbol 'factory-face)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1200 (unless value
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1201 (error "No factory default for this face"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1202 (put symbol 'customized-face nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1203 (when (get symbol 'saved-face)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1204 (put symbol 'saved-face nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1205 (custom-save-all))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1206 (custom-face-display-set symbol value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1207 (widget-value-set child value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1208 (custom-face-state-set widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1209 (custom-redraw-magic widget)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1210
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1211 ;;; The `face' Widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1212
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1213 (define-widget 'face 'default
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1214 "Select and customize a face."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1215 :convert-widget 'widget-item-convert-widget
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1216 :format "%[%t%]: %v"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1217 :tag "Face"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1218 :value 'default
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1219 :value-create 'widget-face-value-create
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1220 :value-delete 'widget-face-value-delete
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1221 :value-get 'widget-item-value-get
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1222 :validate 'widget-editable-list-validate
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1223 :action 'widget-face-action
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1224 :match '(lambda (widget value) (symbolp value)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1225
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1226 (defun widget-face-value-create (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1227 ;; Create a `custom-face' child.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1228 (let* ((symbol (widget-value widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1229 (child (widget-create-child-and-convert
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1230 widget 'custom-face
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1231 :format "%t %s%m%h%v"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1232 :custom-level nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1233 :value symbol)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1234 (custom-magic-reset child)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1235 (setq custom-options (cons child custom-options))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1236 (widget-put widget :children (list child))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1237
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1238 (defun widget-face-value-delete (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1239 ;; Remove the child from the options.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1240 (let ((child (car (widget-get widget :children))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1241 (setq custom-options (delq child custom-options))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1242 (widget-children-value-delete widget)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1243
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1244 (defvar face-history nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1245 "History of entered face names.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1246
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1247 (defun widget-face-action (widget &optional event)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1248 "Prompt for a face."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1249 (let ((answer (completing-read "Face: "
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1250 (mapcar (lambda (face)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1251 (list (symbol-name face)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1252 (face-list))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1253 nil nil nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1254 'face-history)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1255 (unless (zerop (length answer))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1256 (widget-value-set widget (intern answer))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1257 (widget-apply widget :notify widget event)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1258 (widget-setup))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1259
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1260 ;;; The `hook' Widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1261
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1262 (define-widget 'hook 'list
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1263 "A emacs lisp hook"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1264 :convert-widget 'custom-hook-convert-widget
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1265 :tag "Hook")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1266
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1267 (defun custom-hook-convert-widget (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1268 ;; Handle `:custom-options'.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1269 (let* ((options (widget-get widget :options))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1270 (other `(editable-list :inline t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1271 :entry-format "%i %d%v"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1272 (function :format " %v")))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1273 (args (if options
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1274 (list `(checklist :inline t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1275 ,@(mapcar (lambda (entry)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1276 `(function-item ,entry))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1277 options))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1278 other)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1279 (list other))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1280 (widget-put widget :args args)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1281 widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1282
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1283 ;;; The `custom-group' Widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1284
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1285 (defcustom custom-group-tag-faces '(custom-group-tag-face-1)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1286 ;; In XEmacs, this ought to play games with font size.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1287 "Face used for group tags.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1288 The first member is used for level 1 groups, the second for level 2,
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1289 and so forth. The remaining group tags are shown with
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1290 `custom-group-tag-face'."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1291 :type '(repeat face)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1292 :group 'customize)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1293
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1294 (defface custom-group-tag-face-1 '((((class color)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1295 (background dark))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1296 (:foreground "pink" :underline t))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1297 (((class color)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1298 (background light))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1299 (:foreground "red" :underline t))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1300 (t (:underline t)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1301 "Face used for group tags.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1302
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1303 (defface custom-group-tag-face '((((class color)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1304 (background dark))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1305 (:foreground "light blue" :underline t))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1306 (((class color)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1307 (background light))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1308 (:foreground "blue" :underline t))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1309 (t (:underline t)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1310 "Face used for low level group tags."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1311 :group 'customize)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1312
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1313 (define-widget 'custom-group 'custom
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1314 "Customize group."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1315 :format "%l%{%t%}:%L\n%m%h%a%v"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1316 :sample-face-get 'custom-group-sample-face-get
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1317 :documentation-property 'group-documentation
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1318 :help-echo "Push me to set or reset all members of this group."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1319 :value-create 'custom-group-value-create
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1320 :action 'custom-group-action
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1321 :custom-set 'custom-group-set
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1322 :custom-save 'custom-group-save
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1323 :custom-reset-current 'custom-group-reset-current
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1324 :custom-reset-saved 'custom-group-reset-saved
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1325 :custom-reset-factory 'custom-group-reset-factory
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1326 :custom-menu 'custom-group-menu-create)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1327
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1328 (defun custom-group-sample-face-get (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1329 ;; Use :sample-face.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1330 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1331 'custom-group-tag-face))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1332
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1333 (defun custom-group-value-create (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1334 (let ((state (widget-get widget :custom-state)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1335 (unless (eq state 'hidden)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1336 (custom-load-widget widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1337 (let* ((level (widget-get widget :custom-level))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1338 (symbol (widget-value widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1339 (members (get symbol 'custom-group))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1340 (prefixes (widget-get widget :custom-prefixes))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1341 (custom-prefix-list (custom-prefix-add symbol prefixes))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1342 (children (mapcar (lambda (entry)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1343 (widget-insert "\n")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1344 (prog1
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1345 (widget-create-child-and-convert
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1346 widget (nth 1 entry)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1347 :group widget
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1348 :tag (custom-unlispify-tag-name
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1349 (nth 0 entry))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1350 :custom-prefixes custom-prefix-list
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1351 :custom-level (1+ level)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1352 :value (nth 0 entry))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1353 (unless (eq (preceding-char) ?\n)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1354 (widget-insert "\n"))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1355 members)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1356 (mapcar 'custom-magic-reset children)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1357 (widget-put widget :children children)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1358 (custom-group-state-update widget)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1359
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1360 (defvar custom-group-menu
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1361 '(("Set" . custom-group-set)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1362 ("Save" . custom-group-save)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1363 ("Reset to Current" . custom-group-reset-current)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1364 ("Reset to Saved" . custom-group-reset-saved)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1365 ("Reset to Factory" . custom-group-reset-factory))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1366 "Alist of actions for the `custom-group' widget.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1367 The key is a string containing the name of the action, the value is a
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1368 lisp function taking the widget as an element which will be called
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1369 when the action is chosen.")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1370
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1371 (defun custom-group-action (widget &optional event)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1372 "Show the menu for `custom-group' WIDGET.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1373 Optional EVENT is the location for the menu."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1374 (if (eq (widget-get widget :custom-state) 'hidden)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1375 (progn
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1376 (widget-put widget :custom-state 'unknown)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1377 (custom-redraw widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1378 (let* ((completion-ignore-case t)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
1379 (answer (widget-choose (capitalize
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 20
diff changeset
1380 (symbol-name (widget-get widget :value)))
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1381 custom-group-menu
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1382 event)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1383 (if answer
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1384 (funcall answer widget)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1385
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1386 (defun custom-group-set (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1387 "Set changes in all modified group members."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1388 (let ((children (widget-get widget :children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1389 (mapcar (lambda (child)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1390 (when (eq (widget-get child :custom-state) 'modified)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1391 (widget-apply child :custom-set)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1392 children )))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1393
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1394 (defun custom-group-save (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1395 "Save all modified group members."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1396 (let ((children (widget-get widget :children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1397 (mapcar (lambda (child)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1398 (when (memq (widget-get child :custom-state) '(modified set))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1399 (widget-apply child :custom-save)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1400 children )))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1401
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1402 (defun custom-group-reset-current (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1403 "Reset all modified group members."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1404 (let ((children (widget-get widget :children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1405 (mapcar (lambda (child)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1406 (when (eq (widget-get child :custom-state) 'modified)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1407 (widget-apply child :custom-reset-current)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1408 children )))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1409
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1410 (defun custom-group-reset-saved (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1411 "Reset all modified or set group members."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1412 (let ((children (widget-get widget :children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1413 (mapcar (lambda (child)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1414 (when (memq (widget-get child :custom-state) '(modified set))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1415 (widget-apply child :custom-reset-saved)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1416 children )))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1417
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1418 (defun custom-group-reset-factory (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1419 "Reset all modified, set, or saved group members."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1420 (let ((children (widget-get widget :children)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1421 (mapcar (lambda (child)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1422 (when (memq (widget-get child :custom-state)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1423 '(modified set saved))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1424 (widget-apply child :custom-reset-factory)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1425 children )))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1426
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1427 (defun custom-group-state-update (widget)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1428 "Update magic."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1429 (unless (eq (widget-get widget :custom-state) 'hidden)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1430 (let* ((children (widget-get widget :children))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1431 (states (mapcar (lambda (child)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1432 (widget-get child :custom-state))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1433 children))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1434 (magics custom-magic-alist)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1435 (found 'factory))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1436 (while magics
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1437 (let ((magic (car (car magics))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1438 (if (and (not (eq magic 'hidden))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1439 (memq magic states))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1440 (setq found magic
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1441 magics nil)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1442 (setq magics (cdr magics)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1443 (widget-put widget :custom-state found)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1444 (custom-magic-reset widget))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1445
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1446 ;;; The `custom-save-all' Function.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1447
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1448 (defcustom custom-file "~/.emacs"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1449 "File used for storing customization information.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1450 If you change this from the default \"~/.emacs\" you need to
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1451 explicitly load that file for the settings to take effect."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1452 :type 'file
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1453 :group 'customize)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1454
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1455 (defun custom-save-delete (symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1456 "Delete the call to SYMBOL form `custom-file'.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1457 Leave point at the location of the call, or after the last expression."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1458 (set-buffer (find-file-noselect custom-file))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1459 (goto-char (point-min))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1460 (catch 'found
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1461 (while t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1462 (let ((sexp (condition-case nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1463 (read (current-buffer))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1464 (end-of-file (throw 'found nil)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1465 (when (and (listp sexp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1466 (eq (car sexp) symbol))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1467 (delete-region (save-excursion
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1468 (backward-sexp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1469 (point))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1470 (point))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1471 (throw 'found nil))))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1472
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1473 (defun custom-save-variables ()
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1474 "Save all customized variables in `custom-file'."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1475 (save-excursion
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1476 (custom-save-delete 'custom-set-variables)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1477 (let ((standard-output (current-buffer)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1478 (unless (bolp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1479 (princ "\n"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1480 (princ "(custom-set-variables")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1481 (mapatoms (lambda (symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1482 (let ((value (get symbol 'saved-value)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1483 (when value
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1484 (princ "\n '(")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1485 (princ symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1486 (princ " ")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1487 (prin1 (car value))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1488 (if (or (get symbol 'factory-value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1489 (and (not (boundp symbol))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1490 (not (get symbol 'force-value))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1491 (princ ")")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1492 (princ " t)"))))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1493 (princ ")")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1494 (unless (eolp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1495 (princ "\n")))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1496
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1497 (defun custom-save-faces ()
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1498 "Save all customized faces in `custom-file'."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1499 (save-excursion
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1500 (custom-save-delete 'custom-set-faces)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1501 (let ((standard-output (current-buffer)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1502 (unless (bolp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1503 (princ "\n"))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1504 (princ "(custom-set-faces")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1505 (mapatoms (lambda (symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1506 (let ((value (get symbol 'saved-face)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1507 (when value
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1508 (princ "\n '(")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1509 (princ symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1510 (princ " ")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1511 (prin1 value)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1512 (if (or (get symbol 'factory-face)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1513 (and (not (custom-facep symbol))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1514 (not (get symbol 'force-face))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1515 (princ ")")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1516 (princ " t)"))))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1517 (princ ")")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1518 (unless (eolp)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1519 (princ "\n")))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1520
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1521 (defun custom-save-all ()
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1522 "Save all customizations in `custom-file'."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1523 (custom-save-variables)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1524 (custom-save-faces)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1525 (save-excursion
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1526 (set-buffer (find-file-noselect custom-file))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1527 (save-buffer)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1528
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1529 ;;; The Customize Menu.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1530
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1531 (defcustom custom-menu-nesting 2
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1532 "Maximum nesting in custom menus."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1533 :type 'integer
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1534 :group 'customize)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1535
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1536 (defun custom-face-menu-create (widget symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1537 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1538 (vector (custom-unlispify-menu-entry symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1539 `(custom-buffer-create '((,symbol custom-face)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1540 t))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1541
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1542 (defun custom-variable-menu-create (widget symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1543 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1544 (let ((type (get symbol 'custom-type)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1545 (unless (listp type)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1546 (setq type (list type)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1547 (if (and type (widget-get type :custom-menu))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1548 (widget-apply type :custom-menu symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1549 (vector (custom-unlispify-menu-entry symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1550 `(custom-buffer-create '((,symbol custom-variable)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1551 t))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1552
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1553 (widget-put (get 'boolean 'widget-type)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1554 :custom-menu (lambda (widget symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1555 (vector (custom-unlispify-menu-entry symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1556 `(custom-buffer-create
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1557 '((,symbol custom-variable)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1558 ':style 'toggle
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1559 ':selected symbol)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1560
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1561 (defun custom-group-menu-create (widget symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1562 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1563 (custom-menu-create symbol))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1564
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1565 (defun custom-menu-create (symbol &optional name)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1566 "Create menu for customization group SYMBOL.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1567 If optional NAME is given, use that as the name of the menu.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1568 Otherwise make up a name from SYMBOL.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1569 The menu is in a format applicable to `easy-menu-define'."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1570 (unless name
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1571 (setq name (custom-unlispify-menu-entry symbol)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1572 (let ((item (vector name
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1573 `(custom-buffer-create '((,symbol custom-group)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1574 t)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1575 (if (and (> custom-menu-nesting 0)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1576 (< (length (get symbol 'custom-group)) widget-menu-max-size))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1577 (let ((custom-menu-nesting (1- custom-menu-nesting))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1578 (custom-prefix-list (custom-prefix-add symbol
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1579 custom-prefix-list)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1580 (custom-load-symbol symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1581 `(,(custom-unlispify-menu-entry symbol t)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1582 ,item
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1583 "--"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1584 ,@(mapcar (lambda (entry)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1585 (widget-apply (if (listp (nth 1 entry))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1586 (nth 1 entry)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1587 (list (nth 1 entry)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1588 :custom-menu (nth 0 entry)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1589 (get symbol 'custom-group))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1590 item)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1591
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1592 ;;;###autoload
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1593 (defun custom-menu-update ()
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1594 "Update customize menu."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1595 (interactive)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1596 (add-hook 'custom-define-hook 'custom-menu-reset)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1597 (let ((menu `(,(car custom-help-menu)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1598 ,(widget-apply '(custom-group) :custom-menu 'emacs)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1599 ,@(cdr (cdr custom-help-menu)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1600 (if (fboundp 'add-submenu)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1601 (add-submenu '("Help") menu)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1602 (define-key global-map [menu-bar help-menu customize-menu]
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1603 (cons (car menu) (easy-menu-create-keymaps (car menu) (cdr menu)))))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1604
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1605 ;;; Dependencies.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1606
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1607 ;;;###autoload
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1608 (defun custom-make-dependencies ()
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1609 "Batch function to extract custom dependencies from .el files.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1610 Usage: emacs -batch *.el -f custom-make-dependencies > deps.el"
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1611 (let ((buffers (buffer-list)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1612 (while buffers
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1613 (set-buffer (car buffers))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1614 (setq buffers (cdr buffers))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1615 (let ((file (buffer-file-name)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1616 (when (and file (string-match "\\`\\(.*\\)\\.el\\'" file))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1617 (goto-char (point-min))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1618 (condition-case nil
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1619 (let ((name (file-name-nondirectory (match-string 1 file))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1620 (while t
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1621 (let ((expr (read (current-buffer))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1622 (when (and (listp expr)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1623 (memq (car expr) '(defcustom defface defgroup)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1624 (eval expr)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1625 (put (nth 1 expr) 'custom-where name)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1626 (error nil))))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1627 (mapatoms (lambda (symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1628 (let ((members (get symbol 'custom-group))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1629 item where found)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1630 (when members
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1631 (princ "(put '")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1632 (princ symbol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1633 (princ " 'custom-loads '(")
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1634 (while members
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1635 (setq item (car (car members))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1636 members (cdr members)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1637 where (get item 'custom-where))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1638 (unless (or (null where)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1639 (member where found))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1640 (when found
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1641 (princ " "))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1642 (prin1 where)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1643 (push where found)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1644 (princ "))\n"))))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1645
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1646 ;;; The End.
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1647
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1648 (provide 'custom-edit)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1649
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents:
diff changeset
1650 ;; custom-edit.el ends here