428
|
1 ;;; cus-edit.el --- Tools for customizating Emacs and Lisp packages.
|
|
2 ;;
|
438
|
3 ;; Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
|
428
|
4 ;;
|
|
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
|
|
6 ;; Maintainer: Hrvoje Niksic <hniksic@xemacs.org>
|
|
7 ;; Keywords: help, faces
|
|
8 ;; Version: 1.9960-x
|
|
9 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
|
|
10
|
|
11 ;; This file is part of XEmacs.
|
|
12
|
|
13 ;; XEmacs is free software; you can redistribute it and/or modify
|
|
14 ;; it under the terms of the GNU General Public License as published by
|
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
|
18 ;; XEmacs is distributed in the hope that it will be useful,
|
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 ;; GNU General Public License for more details.
|
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
|
24 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
26 ;; Boston, MA 02111-1307, USA.
|
|
27
|
|
28 ;;; Commentary:
|
|
29 ;;
|
|
30 ;; This file implements the code to create and edit customize buffers.
|
|
31 ;;
|
|
32 ;; See `custom.el'.
|
|
33
|
|
34 ;; No commands should have names starting with `custom-' because
|
|
35 ;; that interferes with completion. Use `customize-' for commands
|
|
36 ;; that the user will run with M-x, and `Custom-' for interactive commands.
|
|
37
|
|
38 ;; NOTE: In many places within this file we use `mapatoms', which is
|
|
39 ;; very slow in an average XEmacs because of the large number of
|
|
40 ;; symbols requiring a large number of funcalls -- XEmacs with Gnus
|
|
41 ;; can grow to some 17000 symbols without ever doing anything fancy.
|
|
42 ;; It would probably pay off to make a hash table of symbols known to
|
|
43 ;; Custom, similar to custom-group-hash-table.
|
|
44
|
|
45 ;; This is not top priority, because none of the functions that do
|
|
46 ;; mapatoms are speed-critical (the one that was now uses
|
|
47 ;; custom-group-hash-table), but it would be nice to have.
|
|
48
|
|
49
|
|
50 ;;; Code:
|
|
51
|
|
52 (require 'cus-face)
|
|
53 (require 'wid-edit)
|
|
54 (require 'easymenu)
|
|
55
|
|
56 (require 'cus-load)
|
|
57 (require 'cus-start)
|
442
|
58 (require 'cus-file)
|
428
|
59
|
|
60 ;; Huh? This looks dirty!
|
|
61 (put 'custom-define-hook 'custom-type 'hook)
|
|
62 (put 'custom-define-hook 'standard-value '(nil))
|
|
63 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
|
|
64
|
|
65 ;;; Customization Groups.
|
|
66
|
|
67 (defgroup emacs nil
|
|
68 "Customization of the One True Editor."
|
|
69 :link '(custom-manual "(XEmacs)Top"))
|
|
70
|
|
71 ;; Most of these groups are stolen from `finder.el',
|
|
72 (defgroup editing nil
|
|
73 "Basic text editing facilities."
|
|
74 :group 'emacs)
|
|
75
|
|
76 (defgroup matching nil
|
|
77 "Various sorts of searching and matching."
|
|
78 :group 'editing)
|
|
79
|
|
80 (defgroup emulations nil
|
|
81 "Emulations of other editors."
|
|
82 :group 'editing)
|
|
83
|
|
84 (defgroup outlines nil
|
|
85 "Support for hierarchical outlining."
|
|
86 :group 'editing)
|
|
87
|
|
88 (defgroup external nil
|
|
89 "Interfacing to external utilities."
|
|
90 :group 'emacs)
|
|
91
|
|
92 (defgroup bib nil
|
|
93 "Code related to the `bib' bibliography processor."
|
|
94 :tag "Bibliography"
|
|
95 :group 'external)
|
|
96
|
|
97 (defgroup programming nil
|
|
98 "Support for programming in other languages."
|
|
99 :group 'emacs)
|
|
100
|
|
101 (defgroup languages nil
|
|
102 "Specialized modes for editing programming languages."
|
|
103 :group 'programming)
|
|
104
|
|
105 ;; #### This should be in cc-vars.el
|
|
106 (defgroup c nil
|
|
107 "Support for the C language and related languages."
|
|
108 :group 'languages)
|
|
109
|
|
110 (defgroup tools nil
|
|
111 "Programming tools."
|
|
112 :group 'programming)
|
|
113
|
|
114 (defgroup oop nil
|
|
115 "Support for object-oriented programming."
|
|
116 :group 'programming)
|
|
117
|
|
118 (defgroup applications nil
|
|
119 "Applications written in Emacs."
|
|
120 :group 'emacs)
|
|
121
|
|
122 ;; #### This should be in calendar.el
|
|
123 (defgroup calendar nil
|
|
124 "Calendar and time management support."
|
|
125 :group 'applications)
|
|
126
|
|
127 (defgroup mail nil
|
|
128 "Modes for electronic-mail handling."
|
|
129 :group 'applications)
|
|
130
|
|
131 (defgroup news nil
|
|
132 "Support for netnews reading and posting."
|
|
133 :group 'applications)
|
|
134
|
|
135 (defgroup games nil
|
|
136 "Games, jokes and amusements."
|
|
137 :group 'applications)
|
|
138
|
|
139 (defgroup development nil
|
|
140 "Support for further development of Emacs."
|
|
141 :group 'emacs)
|
|
142
|
|
143 (defgroup docs nil
|
|
144 "Support for Emacs documentation."
|
|
145 :group 'development)
|
|
146
|
|
147 (defgroup extensions nil
|
|
148 "Emacs Lisp language extensions."
|
|
149 :group 'development)
|
|
150
|
|
151 (defgroup internal nil
|
|
152 "Code for Emacs internals, build process, defaults."
|
|
153 :group 'development)
|
|
154
|
|
155 (defgroup maint nil
|
|
156 "Maintenance aids for the Emacs development group."
|
|
157 :tag "Maintenance"
|
|
158 :group 'development)
|
|
159
|
|
160 (defgroup environment nil
|
|
161 "Fitting Emacs with its environment."
|
|
162 :group 'emacs)
|
|
163
|
|
164 (defgroup comm nil
|
|
165 "Communications, networking, remote access to files."
|
|
166 :tag "Communication"
|
|
167 :group 'environment)
|
|
168
|
|
169 (defgroup hardware nil
|
|
170 "Support for interfacing with exotic hardware."
|
|
171 :group 'environment)
|
|
172
|
|
173 (defgroup terminals nil
|
|
174 "Support for terminal types."
|
|
175 :group 'environment)
|
|
176
|
|
177 (defgroup unix nil
|
|
178 "Front-ends/assistants for, or emulators of, UNIX features."
|
|
179 :group 'environment)
|
|
180
|
|
181 (defgroup i18n nil
|
|
182 "Internationalization and alternate character-set support."
|
|
183 :group 'environment
|
|
184 :group 'editing)
|
|
185
|
|
186 (defgroup data nil
|
|
187 "Support editing files of data."
|
|
188 :group 'emacs)
|
|
189
|
|
190 (defgroup wp nil
|
|
191 "Word processing."
|
|
192 :group 'emacs)
|
|
193
|
|
194 (defgroup tex nil
|
|
195 "Code related to the TeX formatter."
|
|
196 :group 'wp)
|
|
197
|
|
198 (defgroup hypermedia nil
|
|
199 "Support for links between text or other media types."
|
|
200 :group 'emacs)
|
|
201
|
|
202 (defgroup local nil
|
|
203 "Code local to your site."
|
|
204 :group 'emacs)
|
|
205
|
|
206 (defgroup customize '((widgets custom-group))
|
|
207 "Customization of the Customization support."
|
|
208 :link '(custom-manual "(custom)Top")
|
|
209 :link '(url-link :tag "Development Page"
|
|
210 "http://www.dina.kvl.dk/~abraham/custom/")
|
|
211 :prefix "custom-"
|
|
212 :group 'help)
|
|
213
|
|
214 (defgroup custom-faces nil
|
|
215 "Faces used by customize."
|
|
216 :group 'customize
|
|
217 :group 'faces)
|
|
218
|
|
219 (defgroup custom-browse nil
|
|
220 "Control customize browser."
|
|
221 :prefix "custom-"
|
|
222 :group 'customize)
|
|
223
|
|
224 (defgroup custom-buffer nil
|
|
225 "Control customize buffers."
|
|
226 :prefix "custom-"
|
|
227 :group 'customize)
|
|
228
|
|
229 (defgroup custom-menu nil
|
|
230 "Control customize menus."
|
|
231 :prefix "custom-"
|
|
232 :group 'customize)
|
|
233
|
|
234 (defgroup alloc nil
|
613
|
235 "Storage allocation and gc for XEmacs Lisp interpreter."
|
428
|
236 :tag "Storage Allocation"
|
|
237 :group 'internal)
|
|
238
|
|
239 (defgroup undo nil
|
|
240 "Undoing changes in buffers."
|
|
241 :group 'editing)
|
|
242
|
|
243 (defgroup editing-basics nil
|
|
244 "Most basic editing facilities."
|
|
245 :group 'editing)
|
|
246
|
|
247 (defgroup display nil
|
|
248 "How characters are displayed in buffers."
|
|
249 :group 'environment)
|
|
250
|
|
251 (defgroup installation nil
|
|
252 "The Emacs installation."
|
|
253 :group 'environment)
|
|
254
|
|
255 (defgroup limits nil
|
|
256 "Internal Emacs limits."
|
|
257 :group 'internal)
|
|
258
|
|
259 (defgroup debug nil
|
|
260 "Debugging Emacs itself."
|
|
261 :group 'development)
|
|
262
|
|
263 (defgroup mule nil
|
|
264 "Mule XEmacs internationalization."
|
|
265 :group 'i18n)
|
|
266
|
|
267
|
|
268 ;;; Utilities.
|
|
269
|
|
270 (defun custom-quote (sexp)
|
|
271 "Quote SEXP iff it is not self quoting."
|
|
272 (if (or (memq sexp '(t nil))
|
|
273 (keywordp sexp)
|
|
274 (eq (car-safe sexp) 'lambda)
|
|
275 (stringp sexp)
|
|
276 (numberp sexp)
|
|
277 (characterp sexp)
|
|
278 (vectorp sexp)
|
|
279 (bit-vector-p sexp))
|
|
280 sexp
|
|
281 (list 'quote sexp)))
|
|
282
|
|
283 (defun custom-split-regexp-maybe (regexp)
|
|
284 "If REGEXP is a string, split it to a list at `\\|'.
|
|
285 You can get the original back with from the result with:
|
|
286 (mapconcat #'identity result \"\\|\")
|
|
287
|
|
288 IF REGEXP is not a string, return it unchanged."
|
|
289 (if (stringp regexp)
|
|
290 (split-string regexp "\\\\|")
|
|
291 regexp))
|
|
292
|
|
293 (defun custom-variable-prompt ()
|
|
294 ;; Code stolen from `help.el'.
|
|
295 "Prompt for a variable, defaulting to the variable at point.
|
|
296 Return a list suitable for use in `interactive'."
|
|
297 (let ((v (variable-at-point))
|
|
298 (enable-recursive-minibuffers t)
|
|
299 val)
|
|
300 (setq val (completing-read
|
|
301 (if (symbolp v)
|
|
302 (format "Customize variable: (default %s) " v)
|
|
303 "Customize variable: ")
|
|
304 obarray (lambda (symbol)
|
|
305 (and (boundp symbol)
|
|
306 (or (get symbol 'custom-type)
|
476
|
307 (user-variable-p symbol))))
|
456
|
308 t nil nil (and v (symbol-name v))))
|
428
|
309 (list (if (equal val "")
|
|
310 (if (symbolp v) v nil)
|
|
311 (intern val)))))
|
|
312
|
|
313 ;; Here we take not only the actual groups, but the loads, too.
|
|
314 (defun custom-group-prompt (prompt)
|
|
315 "Read group from minibuffer."
|
|
316 (let ((completion-ignore-case t))
|
|
317 (list (completing-read
|
|
318 prompt obarray
|
|
319 (lambda (symbol)
|
|
320 (or (get symbol 'custom-group)
|
|
321 (get symbol 'custom-loads)))
|
|
322 t))))
|
|
323
|
|
324 (defun custom-menu-filter (menu widget)
|
|
325 "Convert MENU to the form used by `widget-choose'.
|
|
326 MENU should be in the same format as `custom-variable-menu'.
|
|
327 WIDGET is the widget to apply the filter entries of MENU on."
|
|
328 (let ((result nil)
|
|
329 current name action filter)
|
|
330 (while menu
|
|
331 (setq current (car menu)
|
|
332 name (nth 0 current)
|
|
333 action (nth 1 current)
|
|
334 filter (nth 2 current)
|
|
335 menu (cdr menu))
|
|
336 (if (or (null filter) (funcall filter widget))
|
|
337 (push (cons name action) result)
|
|
338 (push name result)))
|
|
339 (nreverse result)))
|
|
340
|
|
341
|
|
342 ;;; Unlispify.
|
|
343
|
|
344 (defvar custom-prefix-list nil
|
|
345 "List of prefixes that should be ignored by `custom-unlispify'")
|
|
346
|
848
|
347 (defcustom custom-save-pretty-print t
|
|
348 "Non-nil means pretty-print values of customized variables if available."
|
|
349 :group 'customize
|
|
350 :type 'boolean)
|
|
351
|
|
352
|
428
|
353 (defcustom custom-unlispify-menu-entries t
|
|
354 "Display menu entries as words instead of symbols if non nil."
|
|
355 :group 'custom-menu
|
|
356 :type 'boolean)
|
|
357
|
|
358 (defcustom custom-unlispify-remove-prefixes t
|
|
359 "Non-nil means remove group prefixes from option names in buffers and menus.
|
|
360 This only has an effect when `custom-unlispify-tag-names' or
|
|
361 `custom-unlispify-menu-entries' is on."
|
|
362 :group 'custom-menu
|
|
363 :type 'boolean)
|
|
364
|
|
365 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
|
|
366 "Convert symbol into a menu entry."
|
|
367 (cond ((not custom-unlispify-menu-entries)
|
|
368 (symbol-name symbol))
|
|
369 ((get symbol 'custom-tag)
|
|
370 (if no-suffix
|
|
371 (get symbol 'custom-tag)
|
|
372 (concat (get symbol 'custom-tag) "...")))
|
|
373 (t
|
|
374 (with-current-buffer (get-buffer-create " *Custom-Work*")
|
|
375 (erase-buffer)
|
|
376 (princ symbol (current-buffer))
|
|
377 (goto-char (point-min))
|
|
378 (when (and (eq (get symbol 'custom-type) 'boolean)
|
|
379 (re-search-forward "-p\\'" nil t))
|
|
380 (replace-match "" t t)
|
|
381 (goto-char (point-min)))
|
|
382 (when custom-unlispify-remove-prefixes
|
|
383 (let ((prefixes custom-prefix-list)
|
|
384 prefix)
|
|
385 (while prefixes
|
|
386 (setq prefix (car prefixes))
|
|
387 (if (search-forward prefix (+ (point) (length prefix)) t)
|
|
388 (progn
|
|
389 (setq prefixes nil)
|
|
390 (delete-region (point-min) (point)))
|
|
391 (setq prefixes (cdr prefixes))))))
|
|
392 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
|
|
393 (capitalize-region (point-min) (point-max))
|
|
394 (unless no-suffix
|
|
395 (goto-char (point-max))
|
|
396 (insert "..."))
|
|
397 (buffer-string)))))
|
|
398
|
|
399 (defcustom custom-unlispify-tag-names t
|
|
400 "Display tag names as words instead of symbols if non nil."
|
|
401 :group 'custom-buffer
|
|
402 :type 'boolean)
|
|
403
|
|
404 (defun custom-unlispify-tag-name (symbol)
|
|
405 "Convert symbol into a menu entry."
|
|
406 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
|
|
407 (custom-unlispify-menu-entry symbol t)))
|
|
408
|
|
409 (defun custom-prefix-add (symbol prefixes)
|
440
|
410 ;; Add SYMBOL to list of ignored PREFIXES.
|
428
|
411 (cons (or (get symbol 'custom-prefix)
|
|
412 (concat (symbol-name symbol) "-"))
|
|
413 prefixes))
|
|
414
|
|
415
|
|
416 ;;; Guess.
|
|
417
|
|
418 (defcustom custom-guess-name-alist
|
|
419 '(("-p\\'" boolean)
|
|
420 ("-hooks?\\'" hook)
|
|
421 ("-face\\'" face)
|
|
422 ("-file\\'" file)
|
|
423 ("-function\\'" function)
|
|
424 ("-functions\\'" (repeat function))
|
|
425 ("-list\\'" (repeat sexp))
|
|
426 ("-alist\\'" (repeat (cons sexp sexp))))
|
|
427 "Alist of (MATCH TYPE).
|
|
428
|
|
429 MATCH should be a regexp matching the name of a symbol, and TYPE should
|
|
430 be a widget suitable for editing the value of that symbol. The TYPE
|
|
431 of the first entry where MATCH matches the name of the symbol will be
|
|
432 used.
|
|
433
|
|
434 This is used for guessing the type of variables not declared with
|
|
435 customize."
|
|
436 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
|
|
437 :group 'customize)
|
|
438
|
|
439 (defcustom custom-guess-doc-alist
|
|
440 '(("\\`\\*?Non-nil " boolean))
|
|
441 "Alist of (MATCH TYPE).
|
|
442
|
|
443 MATCH should be a regexp matching a documentation string, and TYPE
|
|
444 should be a widget suitable for editing the value of a variable with
|
|
445 that documentation string. The TYPE of the first entry where MATCH
|
|
446 matches the name of the symbol will be used.
|
|
447
|
|
448 This is used for guessing the type of variables not declared with
|
|
449 customize."
|
|
450 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
|
|
451 :group 'customize)
|
|
452
|
|
453 (defun custom-guess-type (symbol)
|
|
454 "Guess a widget suitable for editing the value of SYMBOL.
|
|
455 This is done by matching SYMBOL with `custom-guess-name-alist' and
|
|
456 if that fails, the doc string with `custom-guess-doc-alist'."
|
|
457 (let ((name (symbol-name symbol))
|
|
458 (names custom-guess-name-alist)
|
|
459 current found)
|
|
460 (while names
|
|
461 (setq current (car names)
|
|
462 names (cdr names))
|
|
463 (when (string-match (nth 0 current) name)
|
|
464 (setq found (nth 1 current)
|
|
465 names nil)))
|
|
466 (unless found
|
|
467 (let ((doc (documentation-property symbol 'variable-documentation))
|
|
468 (docs custom-guess-doc-alist))
|
|
469 (when doc
|
|
470 (while docs
|
|
471 (setq current (car docs)
|
|
472 docs (cdr docs))
|
|
473 (when (string-match (nth 0 current) doc)
|
|
474 (setq found (nth 1 current)
|
|
475 docs nil))))))
|
|
476 found))
|
|
477
|
|
478
|
|
479 ;;; Sorting.
|
|
480
|
|
481 (defcustom custom-browse-sort-alphabetically nil
|
|
482 "If non-nil, sort members of each customization group alphabetically."
|
|
483 :type 'boolean
|
|
484 :group 'custom-browse)
|
|
485
|
|
486 (defcustom custom-browse-order-groups nil
|
|
487 "If non-nil, order group members within each customization group.
|
|
488 If `first', order groups before non-groups.
|
|
489 If `last', order groups after non-groups."
|
|
490 :type '(choice (const first)
|
|
491 (const last)
|
|
492 (const :tag "none" nil))
|
|
493 :group 'custom-browse)
|
|
494
|
|
495 (defcustom custom-browse-only-groups nil
|
|
496 "If non-nil, show group members only within each customization group."
|
|
497 :type 'boolean
|
|
498 :group 'custom-browse)
|
|
499
|
|
500 (defcustom custom-buffer-sort-alphabetically nil
|
|
501 "If non-nil, sort members of each customization group alphabetically."
|
|
502 :type 'boolean
|
|
503 :group 'custom-buffer)
|
|
504
|
|
505 (defcustom custom-buffer-order-groups 'last
|
|
506 "If non-nil, order group members within each customization group.
|
|
507 If `first', order groups before non-groups.
|
|
508 If `last', order groups after non-groups."
|
|
509 :type '(choice (const first)
|
|
510 (const last)
|
|
511 (const :tag "none" nil))
|
|
512 :group 'custom-buffer)
|
|
513
|
|
514 (defcustom custom-menu-sort-alphabetically nil
|
|
515 "If non-nil, sort members of each customization group alphabetically."
|
|
516 :type 'boolean
|
|
517 :group 'custom-menu)
|
|
518
|
|
519 (defcustom custom-menu-order-groups 'first
|
|
520 "If non-nil, order group members within each customization group.
|
|
521 If `first', order groups before non-groups.
|
|
522 If `last', order groups after non-groups."
|
|
523 :type '(choice (const first)
|
|
524 (const last)
|
|
525 (const :tag "none" nil))
|
|
526 :group 'custom-menu)
|
|
527
|
|
528 (defun custom-sort-items (items sort-alphabetically order-groups)
|
|
529 "Return a sorted copy of ITEMS.
|
|
530 ITEMS should be a `custom-group' property.
|
|
531 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
|
|
532 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
|
|
533 groups after non-groups, if nil do not order groups at all."
|
|
534 (sort (copy-sequence items)
|
|
535 (lambda (a b)
|
|
536 (let ((typea (nth 1 a)) (typeb (nth 1 b))
|
|
537 (namea (symbol-name (nth 0 a))) (nameb (symbol-name (nth 0 b))))
|
|
538 (cond ((not order-groups)
|
|
539 ;; Since we don't care about A and B order, maybe sort.
|
|
540 (when sort-alphabetically
|
|
541 (string-lessp namea nameb)))
|
|
542 ((eq typea 'custom-group)
|
|
543 ;; If B is also a group, maybe sort. Otherwise, order A and B.
|
|
544 (if (eq typeb 'custom-group)
|
|
545 (when sort-alphabetically
|
|
546 (string-lessp namea nameb))
|
|
547 (eq order-groups 'first)))
|
|
548 ((eq typeb 'custom-group)
|
|
549 ;; Since A cannot be a group, order A and B.
|
|
550 (eq order-groups 'last))
|
|
551 (sort-alphabetically
|
|
552 ;; Since A and B cannot be groups, sort.
|
|
553 (string-lessp namea nameb)))))))
|
|
554
|
|
555
|
|
556 ;;; Custom Mode Commands.
|
|
557
|
|
558 (defvar custom-options nil
|
|
559 "Customization widgets in the current buffer.")
|
|
560
|
|
561 (defun Custom-set ()
|
|
562 "Set changes in all modified options."
|
|
563 (interactive)
|
|
564 (let ((children custom-options))
|
|
565 (mapc (lambda (child)
|
|
566 (when (eq (widget-get child :custom-state) 'modified)
|
|
567 (widget-apply child :custom-set)))
|
|
568 children)))
|
|
569
|
|
570 (defun Custom-save ()
|
480
|
571 "Set all modified options and save them."
|
428
|
572 (interactive)
|
480
|
573 (let ((all-children custom-options)
|
|
574 children)
|
428
|
575 (mapc (lambda (child)
|
|
576 (when (memq (widget-get child :custom-state) '(modified set))
|
480
|
577 (push child children)))
|
|
578 all-children)
|
|
579 (let ((the-children children)
|
|
580 child)
|
|
581 (while (setq child (pop the-children))
|
|
582 (widget-apply child :custom-pre-save)))
|
|
583 (custom-save-all)
|
|
584 (let ((the-children children)
|
|
585 child)
|
|
586 (while (setq child (pop the-children))
|
|
587 (widget-apply child :custom-post-save)))
|
|
588 ))
|
428
|
589
|
|
590 (defvar custom-reset-menu
|
|
591 '(("Current" . Custom-reset-current)
|
|
592 ("Saved" . Custom-reset-saved)
|
|
593 ("Standard Settings" . Custom-reset-standard))
|
|
594 "Alist of actions for the `Reset' button.
|
|
595 The key is a string containing the name of the action, the value is a
|
|
596 lisp function taking the widget as an element which will be called
|
|
597 when the action is chosen.")
|
|
598
|
|
599 (defun custom-reset (event)
|
|
600 "Select item from reset menu."
|
|
601 (let* ((completion-ignore-case t)
|
|
602 (answer (widget-choose "Reset to"
|
|
603 custom-reset-menu
|
|
604 event)))
|
|
605 (if answer
|
|
606 (funcall answer))))
|
|
607
|
|
608 (defun Custom-reset-current (&rest ignore)
|
|
609 "Reset all modified group members to their current value."
|
|
610 (interactive)
|
|
611 (let ((children custom-options))
|
|
612 (mapc (lambda (child)
|
|
613 (when (eq (widget-get child :custom-state) 'modified)
|
|
614 (widget-apply child :custom-reset-current)))
|
|
615 children)))
|
|
616
|
|
617 (defun Custom-reset-saved (&rest ignore)
|
|
618 "Reset all modified or set group members to their saved value."
|
|
619 (interactive)
|
|
620 (let ((children custom-options))
|
|
621 (mapc (lambda (child)
|
|
622 (when (eq (widget-get child :custom-state) 'modified)
|
|
623 (widget-apply child :custom-reset-saved)))
|
|
624 children)))
|
|
625
|
|
626 (defun Custom-reset-standard (&rest ignore)
|
|
627 "Reset all modified, set, or saved group members to their standard settings."
|
|
628 (interactive)
|
480
|
629 (let ((all-children custom-options)
|
|
630 children must-save)
|
428
|
631 (mapc (lambda (child)
|
476
|
632 (when (memq (widget-get child :custom-state) '(modified set saved))
|
480
|
633 (push child children)))
|
|
634 all-children)
|
|
635 (let ((the-children children)
|
|
636 child)
|
|
637 (while (setq child (pop the-children))
|
|
638 (and (widget-apply child :custom-pre-reset-standard)
|
|
639 (setq must-save t))))
|
|
640 (and must-save (custom-save-all))
|
|
641 (let ((the-children children)
|
|
642 child)
|
|
643 (while (setq child (pop the-children))
|
|
644 (widget-apply child :custom-post-reset-standard)))
|
|
645 ))
|
428
|
646
|
|
647
|
|
648 ;;; The Customize Commands
|
|
649
|
|
650 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
|
|
651 "Prompt for a variable and a value and return them as a list.
|
|
652 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
|
|
653 prompt for the value. The %s escape in PROMPT-VAL is replaced with
|
|
654 the name of the variable.
|
|
655
|
|
656 If the variable has a `variable-interactive' property, that is used as if
|
|
657 it were the arg to `interactive' (which see) to interactively read the value.
|
|
658
|
|
659 If the variable has a `custom-type' property, it must be a widget and the
|
|
660 `:prompt-value' property of that widget will be used for reading the value.
|
|
661
|
|
662 If optional COMMENT argument is non nil, also prompt for a comment and return
|
|
663 it as the third element in the list."
|
|
664 (let* ((var (read-variable prompt-var))
|
|
665 (minibuffer-help-form '(describe-variable var))
|
|
666 (val
|
|
667 (let ((prop (get var 'variable-interactive))
|
|
668 (type (get var 'custom-type))
|
|
669 (prompt (format prompt-val var)))
|
|
670 (unless (listp type)
|
|
671 (setq type (list type)))
|
|
672 (cond (prop
|
|
673 ;; Use VAR's `variable-interactive' property
|
|
674 ;; as an interactive spec for prompting.
|
|
675 (call-interactively (list 'lambda '(arg)
|
|
676 (list 'interactive prop)
|
|
677 'arg)))
|
|
678 (type
|
|
679 (widget-prompt-value type
|
|
680 prompt
|
|
681 (if (boundp var)
|
|
682 (symbol-value var))
|
|
683 (not (boundp var))))
|
|
684 (t
|
|
685 (eval-minibuffer prompt))))))
|
|
686 (if comment
|
|
687 (list var val
|
|
688 (read-string "Comment: " (get var 'variable-comment)))
|
|
689 (list var val))
|
|
690 ))
|
|
691
|
|
692 ;;;###autoload
|
|
693 (defun customize-set-value (var val &optional comment)
|
|
694 "Set VARIABLE to VALUE. VALUE is a Lisp object.
|
|
695
|
|
696 If VARIABLE has a `variable-interactive' property, that is used as if
|
|
697 it were the arg to `interactive' (which see) to interactively read the value.
|
|
698
|
|
699 If VARIABLE has a `custom-type' property, it must be a widget and the
|
|
700 `:prompt-value' property of that widget will be used for reading the value.
|
|
701
|
|
702 If given a prefix (or a COMMENT argument), also prompt for a comment."
|
|
703 (interactive (custom-prompt-variable "Set variable: "
|
|
704 "Set %s to value: "
|
|
705 current-prefix-arg))
|
|
706
|
|
707 (set var val)
|
|
708 (cond ((string= comment "")
|
|
709 (put var 'variable-comment nil))
|
|
710 (comment
|
|
711 (put var 'variable-comment comment))))
|
|
712
|
|
713 ;;;###autoload
|
444
|
714 (defun customize-set-variable (variable value &optional comment)
|
|
715 "Set the default for VARIABLE to VALUE. VALUE is any Lisp object.
|
428
|
716
|
|
717 If VARIABLE has a `custom-set' property, that is used for setting
|
|
718 VARIABLE, otherwise `set-default' is used.
|
|
719
|
|
720 The `customized-value' property of the VARIABLE will be set to a list
|
|
721 with a quoted VALUE as its sole list member.
|
|
722
|
|
723 If VARIABLE has a `variable-interactive' property, that is used as if
|
|
724 it were the arg to `interactive' (which see) to interactively read the value.
|
|
725
|
|
726 If VARIABLE has a `custom-type' property, it must be a widget and the
|
|
727 `:prompt-value' property of that widget will be used for reading the value.
|
|
728
|
|
729 If given a prefix (or a COMMENT argument), also prompt for a comment."
|
|
730 (interactive (custom-prompt-variable "Set variable: "
|
|
731 "Set customized value for %s to: "
|
|
732 current-prefix-arg))
|
444
|
733 (funcall (or (get variable 'custom-set) 'set-default) variable value)
|
|
734 (put variable 'customized-value (list (custom-quote value)))
|
428
|
735 (cond ((string= comment "")
|
444
|
736 (put variable 'variable-comment nil)
|
|
737 (put variable 'customized-variable-comment nil))
|
428
|
738 (comment
|
444
|
739 (put variable 'variable-comment comment)
|
|
740 (put variable 'customized-variable-comment comment))))
|
428
|
741
|
|
742
|
|
743 ;;;###autoload
|
444
|
744 (defun customize-save-variable (variable value &optional comment)
|
428
|
745 "Set the default for VARIABLE to VALUE, and save it for future sessions.
|
|
746 If VARIABLE has a `custom-set' property, that is used for setting
|
|
747 VARIABLE, otherwise `set-default' is used.
|
|
748
|
|
749 The `customized-value' property of the VARIABLE will be set to a list
|
|
750 with a quoted VALUE as its sole list member.
|
|
751
|
|
752 If VARIABLE has a `variable-interactive' property, that is used as if
|
|
753 it were the arg to `interactive' (which see) to interactively read the value.
|
|
754
|
|
755 If VARIABLE has a `custom-type' property, it must be a widget and the
|
|
756 `:prompt-value' property of that widget will be used for reading the value.
|
|
757
|
|
758 If given a prefix (or a COMMENT argument), also prompt for a comment."
|
782
|
759 (interactive (custom-prompt-variable "Set and save variable: "
|
428
|
760 "Set and save value for %s as: "
|
|
761 current-prefix-arg))
|
444
|
762 (funcall (or (get variable 'custom-set) 'set-default) variable value)
|
|
763 (put variable 'saved-value (list (custom-quote value)))
|
|
764 (custom-push-theme 'theme-value variable 'user 'set (list (custom-quote value)))
|
428
|
765 (cond ((string= comment "")
|
444
|
766 (put variable 'variable-comment nil)
|
|
767 (put variable 'saved-variable-comment nil))
|
428
|
768 (comment
|
444
|
769 (put variable 'variable-comment comment)
|
|
770 (put variable 'saved-variable-comment comment)))
|
428
|
771 (custom-save-all))
|
|
772
|
|
773 ;;;###autoload
|
|
774 (defun customize (group)
|
|
775 "Select a customization buffer which you can use to set user options.
|
|
776 User options are structured into \"groups\".
|
|
777 The default group is `Emacs'."
|
|
778 (interactive (custom-group-prompt
|
|
779 "Customize group: (default emacs) "))
|
|
780 (when (stringp group)
|
|
781 (if (string-equal "" group)
|
|
782 (setq group 'emacs)
|
|
783 (setq group (intern group))))
|
|
784 (let ((name (format "*Customize Group: %s*"
|
|
785 (custom-unlispify-tag-name group))))
|
|
786 (if (get-buffer name)
|
|
787 (switch-to-buffer name)
|
|
788 (custom-buffer-create (list (list group 'custom-group))
|
|
789 name
|
|
790 (concat " for group "
|
|
791 (custom-unlispify-tag-name group))))))
|
|
792
|
|
793 ;;;###autoload
|
|
794 (defalias 'customize-group 'customize)
|
|
795
|
|
796 ;;;###autoload
|
|
797 (defun customize-other-window (symbol)
|
|
798 "Customize SYMBOL, which must be a customization group."
|
|
799 (interactive (custom-group-prompt
|
|
800 "Customize group: (default emacs) "))
|
|
801 (when (stringp symbol)
|
|
802 (if (string-equal "" symbol)
|
|
803 (setq symbol 'emacs)
|
|
804 (setq symbol (intern symbol))))
|
|
805 (custom-buffer-create-other-window
|
|
806 (list (list symbol 'custom-group))
|
|
807 (format "*Customize Group: %s*" (custom-unlispify-tag-name symbol))))
|
|
808
|
|
809 ;;;###autoload
|
|
810 (defalias 'customize-group-other-window 'customize-other-window)
|
|
811
|
|
812 ;;;###autoload
|
|
813 (defalias 'customize-option 'customize-variable)
|
|
814
|
|
815 ;;;###autoload
|
|
816 (defun customize-variable (symbol)
|
|
817 "Customize SYMBOL, which must be a user option variable."
|
|
818 (interactive (custom-variable-prompt))
|
|
819 (custom-buffer-create (list (list symbol 'custom-variable))
|
|
820 (format "*Customize Variable: %s*"
|
|
821 (custom-unlispify-tag-name symbol))))
|
|
822
|
|
823 ;;;###autoload
|
|
824 (defun customize-changed-options (since-version)
|
|
825 "Customize all user option variables whose default values changed recently.
|
|
826 This means, in other words, variables defined with a `:version' keyword."
|
|
827 (interactive "sCustomize options changed, since version (default all versions): ")
|
|
828 (if (equal since-version "")
|
|
829 (setq since-version nil))
|
|
830 (let ((found nil))
|
|
831 (mapatoms (lambda (symbol)
|
|
832 (and (boundp symbol)
|
|
833 (let ((version (get symbol 'custom-version)))
|
|
834 (and version
|
|
835 (or (null since-version)
|
|
836 (customize-version-lessp since-version version))))
|
|
837 (push (list symbol 'custom-variable) found))))
|
|
838 (unless found
|
|
839 (error "No user options have changed defaults %s"
|
|
840 (if since-version
|
|
841 (format "since XEmacs %s" since-version)
|
|
842 "in recent Emacs versions")))
|
|
843 (custom-buffer-create (custom-sort-items found t nil)
|
|
844 "*Customize Changed Options*")))
|
|
845
|
|
846 (defun customize-version-lessp (version1 version2)
|
|
847 (let (major1 major2 minor1 minor2)
|
|
848 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1)
|
|
849 (setq major1 (read (match-string 1 version1)))
|
|
850 (setq minor1 (read (match-string 2 version1)))
|
|
851 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2)
|
|
852 (setq major2 (read (match-string 1 version2)))
|
|
853 (setq minor2 (read (match-string 2 version2)))
|
|
854 (or (< major1 major2)
|
|
855 (and (= major1 major2)
|
|
856 (< minor1 minor2)))))
|
|
857
|
|
858 ;;;###autoload
|
|
859 (defalias 'customize-variable-other-window 'customize-option-other-window)
|
|
860
|
|
861 ;;;###autoload
|
|
862 (defun customize-option-other-window (symbol)
|
|
863 "Customize SYMBOL, which must be a user option variable.
|
|
864 Show the buffer in another window, but don't select it."
|
|
865 (interactive (custom-variable-prompt))
|
|
866 (custom-buffer-create-other-window
|
|
867 (list (list symbol 'custom-variable))
|
|
868 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
|
|
869
|
|
870 ;;;###autoload
|
|
871 (defun customize-face (&optional symbol)
|
|
872 "Customize SYMBOL, which should be a face name or nil.
|
|
873 If SYMBOL is nil, customize all faces."
|
|
874 (interactive (list (completing-read "Customize face: (default all) "
|
|
875 obarray 'find-face)))
|
|
876 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
|
|
877 (custom-buffer-create (custom-sort-items
|
|
878 (mapcar (lambda (symbol)
|
|
879 (list symbol 'custom-face))
|
|
880 (face-list))
|
|
881 t nil)
|
|
882 "*Customize Faces*")
|
|
883 (when (stringp symbol)
|
|
884 (setq symbol (intern symbol)))
|
|
885 (check-argument-type 'symbolp symbol)
|
|
886 (custom-buffer-create (list (list symbol 'custom-face))
|
|
887 (format "*Customize Face: %s*"
|
|
888 (custom-unlispify-tag-name symbol)))))
|
|
889
|
|
890 ;;;###autoload
|
|
891 (defun customize-face-other-window (&optional symbol)
|
|
892 "Show customization buffer for FACE in other window."
|
|
893 (interactive (list (completing-read "Customize face: "
|
|
894 obarray 'find-face)))
|
|
895 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
|
|
896 ()
|
|
897 (if (stringp symbol)
|
|
898 (setq symbol (intern symbol)))
|
|
899 (check-argument-type 'symbolp symbol)
|
|
900 (custom-buffer-create-other-window
|
|
901 (list (list symbol 'custom-face))
|
|
902 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol)))))
|
|
903
|
|
904 ;;;###autoload
|
|
905 (defun customize-customized ()
|
|
906 "Customize all user options set since the last save in this session."
|
|
907 (interactive)
|
|
908 (let ((found nil))
|
|
909 (mapatoms (lambda (symbol)
|
|
910 (and (or (get symbol 'customized-face)
|
|
911 (get symbol 'customized-face-comment))
|
|
912 (find-face symbol)
|
|
913 (push (list symbol 'custom-face) found))
|
|
914 (and (or (get symbol 'customized-value)
|
|
915 (get symbol 'customized-variable-comment))
|
|
916 (boundp symbol)
|
|
917 (push (list symbol 'custom-variable) found))))
|
|
918 (if (not found)
|
|
919 (error "No customized user options")
|
|
920 (custom-buffer-create (custom-sort-items found t nil)
|
|
921 "*Customize Customized*"))))
|
|
922
|
|
923 ;;;###autoload
|
|
924 (defun customize-saved ()
|
|
925 "Customize all already saved user options."
|
|
926 (interactive)
|
|
927 (let ((found nil))
|
|
928 (mapatoms (lambda (symbol)
|
|
929 (and (or (get symbol 'saved-face)
|
|
930 (get symbol 'saved-face-comment))
|
|
931 (find-face symbol)
|
|
932 (push (list symbol 'custom-face) found))
|
|
933 (and (or (get symbol 'saved-value)
|
|
934 (get symbol 'saved-variable-comment))
|
|
935 (boundp symbol)
|
|
936 (push (list symbol 'custom-variable) found))))
|
|
937 (if (not found )
|
|
938 (error "No saved user options")
|
|
939 (custom-buffer-create (custom-sort-items found t nil)
|
|
940 "*Customize Saved*"))))
|
|
941
|
|
942 ;;;###autoload
|
1655
|
943 (defalias 'apropos-customize 'customize-apropos)
|
|
944
|
|
945 ;;;###autoload
|
428
|
946 (defun customize-apropos (regexp &optional all)
|
|
947 "Customize all user options matching REGEXP.
|
|
948 If ALL is `options', include only options.
|
|
949 If ALL is `faces', include only faces.
|
|
950 If ALL is `groups', include only groups.
|
|
951 If ALL is t (interactively, with prefix arg), include options which are not
|
|
952 user-settable, as well as faces and groups."
|
|
953 (interactive "sCustomize regexp: \nP")
|
|
954 (let ((found nil))
|
|
955 (mapatoms (lambda (symbol)
|
|
956 (when (string-match regexp (symbol-name symbol))
|
|
957 (when (and (not (memq all '(faces options)))
|
|
958 (get symbol 'custom-group))
|
|
959 (push (list symbol 'custom-group) found))
|
|
960 (when (and (not (memq all '(options groups)))
|
|
961 (find-face symbol))
|
|
962 (push (list symbol 'custom-face) found))
|
|
963 (when (and (not (memq all '(groups faces)))
|
|
964 (boundp symbol)
|
|
965 (or (get symbol 'saved-value)
|
|
966 (get symbol 'standard-value)
|
|
967 (if (memq all '(nil options))
|
|
968 (user-variable-p symbol)
|
|
969 (get symbol 'variable-documentation))))
|
|
970 (push (list symbol 'custom-variable) found)))))
|
|
971 (if (not found)
|
|
972 (error "No matches")
|
|
973 (custom-buffer-create (custom-sort-items found t
|
|
974 custom-buffer-order-groups)
|
|
975 "*Customize Apropos*"))))
|
|
976
|
|
977 ;;;###autoload
|
|
978 (defun customize-apropos-options (regexp &optional arg)
|
|
979 "Customize all user options matching REGEXP.
|
|
980 With prefix arg, include options which are not user-settable."
|
|
981 (interactive "sCustomize regexp: \nP")
|
|
982 (customize-apropos regexp (or arg 'options)))
|
|
983
|
|
984 ;;;###autoload
|
|
985 (defun customize-apropos-faces (regexp)
|
|
986 "Customize all user faces matching REGEXP."
|
|
987 (interactive "sCustomize regexp: \n")
|
|
988 (customize-apropos regexp 'faces))
|
|
989
|
|
990 ;;;###autoload
|
|
991 (defun customize-apropos-groups (regexp)
|
|
992 "Customize all user groups matching REGEXP."
|
|
993 (interactive "sCustomize regexp: \n")
|
|
994 (customize-apropos regexp 'groups))
|
|
995
|
|
996
|
|
997 ;;; Buffer.
|
|
998
|
|
999 (defcustom custom-buffer-style 'links
|
|
1000 "*Control the presentation style for customization buffers.
|
|
1001 The value should be a symbol, one of:
|
|
1002
|
|
1003 brackets: groups nest within each other with big horizontal brackets.
|
|
1004 links: groups have links to subgroups."
|
|
1005 :type '(radio (const :tag "brackets: Groups nest within each others" brackets)
|
|
1006 (const :tag "links: Group have links to subgroups" links))
|
|
1007 :group 'custom-buffer)
|
|
1008
|
|
1009 (defcustom custom-buffer-done-function 'kill-buffer
|
|
1010 "*Function to be used to remove the buffer when the user is done with it.
|
|
1011 Choices include `kill-buffer' (the default) and `bury-buffer'.
|
|
1012 The function will be called with one argument, the buffer to remove."
|
|
1013 :type '(radio (function-item kill-buffer)
|
|
1014 (function-item bury-buffer)
|
|
1015 (function :tag "Other" nil))
|
|
1016 :group 'custom-buffer)
|
|
1017
|
|
1018 (defcustom custom-buffer-indent 3
|
|
1019 "Number of spaces to indent nested groups."
|
|
1020 :type 'integer
|
|
1021 :group 'custom-buffer)
|
|
1022
|
|
1023 ;;;###autoload
|
|
1024 (defun custom-buffer-create (options &optional name description)
|
|
1025 "Create a buffer containing OPTIONS.
|
|
1026 Optional NAME is the name of the buffer.
|
|
1027 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
|
|
1028 SYMBOL is a customization option, and WIDGET is a widget for editing
|
|
1029 that option."
|
|
1030 (unless name (setq name "*Customization*"))
|
|
1031 (kill-buffer (get-buffer-create name))
|
|
1032 (switch-to-buffer (get-buffer-create name))
|
|
1033 (custom-buffer-create-internal options description))
|
|
1034
|
|
1035 ;;;###autoload
|
|
1036 (defun custom-buffer-create-other-window (options &optional name description)
|
|
1037 "Create a buffer containing OPTIONS.
|
|
1038 Optional NAME is the name of the buffer.
|
|
1039 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
|
|
1040 SYMBOL is a customization option, and WIDGET is a widget for editing
|
|
1041 that option."
|
|
1042 (unless name (setq name "*Customization*"))
|
|
1043 (kill-buffer (get-buffer-create name))
|
|
1044 (let ((window (selected-window)))
|
|
1045 (switch-to-buffer-other-window (get-buffer-create name))
|
|
1046 (custom-buffer-create-internal options description)
|
|
1047 (select-window window)))
|
|
1048
|
|
1049 (defcustom custom-reset-button-menu t
|
|
1050 "If non-nil, only show a single reset button in customize buffers.
|
|
1051 This button will have a menu with all three reset operations."
|
|
1052 :type 'boolean
|
|
1053 :group 'custom-buffer)
|
|
1054
|
|
1055 (defconst custom-skip-messages 5)
|
|
1056
|
|
1057 (defun Custom-buffer-done ()
|
|
1058 "Remove current buffer.
|
|
1059 This works by calling the function specified by
|
|
1060 `custom-buffer-done-function'."
|
|
1061 (interactive)
|
|
1062 (funcall custom-buffer-done-function (current-buffer)))
|
|
1063
|
|
1064 (defun custom-buffer-create-buttons ()
|
|
1065 (message "Creating customization buttons...")
|
|
1066 (widget-insert "\nOperate on everything in this buffer:\n ")
|
|
1067 (widget-create 'push-button
|
|
1068 :tag "Set"
|
|
1069 :help-echo "\
|
|
1070 Make your editing in this buffer take effect for this session"
|
|
1071 :action (lambda (widget &optional event)
|
|
1072 (Custom-set)))
|
|
1073 (widget-insert " ")
|
|
1074 (widget-create 'push-button
|
|
1075 :tag "Save"
|
|
1076 :help-echo "\
|
|
1077 Make your editing in this buffer take effect for future Emacs sessions"
|
|
1078 :action (lambda (widget &optional event)
|
|
1079 (Custom-save)))
|
|
1080 (if custom-reset-button-menu
|
|
1081 (progn
|
|
1082 (widget-insert " ")
|
|
1083 (widget-create 'push-button
|
|
1084 :tag "Reset"
|
|
1085 :tag-glyph '("reset-up" "reset-down")
|
|
1086 :help-echo "Show a menu with reset operations"
|
|
1087 :mouse-down-action (lambda (&rest junk) t)
|
|
1088 :action (lambda (widget &optional event)
|
|
1089 (custom-reset event))))
|
|
1090 (widget-insert " ")
|
|
1091 (widget-create 'push-button
|
|
1092 :tag "Reset"
|
|
1093 :help-echo "\
|
|
1094 Reset all edited text in this buffer to reflect current values"
|
|
1095 :action 'Custom-reset-current)
|
|
1096 (widget-insert " ")
|
|
1097 (widget-create 'push-button
|
|
1098 :tag "Reset to Saved"
|
|
1099 :help-echo "\
|
|
1100 Reset all values in this buffer to their saved settings"
|
|
1101 :action 'Custom-reset-saved)
|
|
1102 (widget-insert " ")
|
|
1103 (widget-create 'push-button
|
|
1104 :tag "Reset to Standard"
|
|
1105 :help-echo "\
|
|
1106 Reset all values in this buffer to their standard settings"
|
|
1107 :action 'Custom-reset-standard))
|
|
1108 (widget-insert " ")
|
|
1109 (widget-create 'push-button
|
|
1110 :tag "Done"
|
|
1111 :help-echo "Remove the buffer"
|
|
1112 :action (lambda (widget &optional event)
|
|
1113 (Custom-buffer-done)))
|
|
1114 (widget-insert "\n"))
|
|
1115
|
|
1116 (defcustom custom-novice t
|
|
1117 "If non-nil, show help message at top of customize buffers."
|
|
1118 :type 'boolean
|
|
1119 :group 'custom-buffer)
|
|
1120
|
|
1121 (defcustom custom-display-global-buttons 'top
|
|
1122 "If `nil' don't display the global buttons. If `top' display at the
|
|
1123 beginning of custom buffers. If `bottom', display at the end."
|
|
1124 :type '(choice (const top)
|
|
1125 (const bottom)
|
|
1126 (const :tag "don't" nil))
|
|
1127 :group 'custom-buffer)
|
|
1128
|
|
1129 (defun custom-buffer-create-internal (options &optional description)
|
|
1130 (message "Creating customization buffer...")
|
|
1131 (custom-mode)
|
|
1132 (widget-insert "This is a customization buffer")
|
|
1133 (if description
|
|
1134 (widget-insert description))
|
|
1135 (when custom-novice
|
|
1136 (widget-insert ".\n\
|
|
1137 Type RET or click button2 on an active field to invoke its action.
|
|
1138 Invoke ")
|
|
1139 (widget-create 'info-link
|
|
1140 :tag "Help"
|
|
1141 :help-echo "Read the online help"
|
|
1142 "(XEmacs)Easy Customization")
|
|
1143 (widget-insert " for more information."))
|
|
1144 (widget-insert "\n")
|
|
1145 (if (equal custom-display-global-buttons 'top)
|
|
1146 (custom-buffer-create-buttons))
|
|
1147 (widget-insert "\n")
|
|
1148 (message "Creating customization items...")
|
|
1149 (setq custom-options
|
|
1150 (if (= (length options) 1)
|
|
1151 (mapcar (lambda (entry)
|
|
1152 (widget-create (nth 1 entry)
|
|
1153 :documentation-shown t
|
|
1154 :custom-state 'unknown
|
|
1155 :tag (custom-unlispify-tag-name
|
|
1156 (nth 0 entry))
|
|
1157 :value (nth 0 entry)))
|
|
1158 options)
|
|
1159 (let ((count 0)
|
|
1160 (length (length options)))
|
|
1161 (mapcar (lambda (entry)
|
|
1162 (prog2
|
|
1163 (display-message
|
|
1164 'progress
|
|
1165 (format "Creating customization items %2d%%..."
|
|
1166 (/ (* 100.0 count) length)))
|
|
1167 (widget-create (nth 1 entry)
|
|
1168 :tag (custom-unlispify-tag-name
|
|
1169 (nth 0 entry))
|
|
1170 :value (nth 0 entry))
|
|
1171 (incf count)
|
|
1172 (unless (eq (preceding-char) ?\n)
|
|
1173 (widget-insert "\n"))
|
|
1174 (widget-insert "\n")))
|
|
1175 options))))
|
|
1176 (unless (eq (preceding-char) ?\n)
|
|
1177 (widget-insert "\n"))
|
|
1178 (if (equal custom-display-global-buttons 'bottom)
|
|
1179 (custom-buffer-create-buttons))
|
|
1180 (display-message 'progress
|
|
1181 (format
|
|
1182 "Creating customization items %2d%%...done" 100))
|
|
1183 (unless (eq custom-buffer-style 'tree)
|
|
1184 (mapc 'custom-magic-reset custom-options))
|
|
1185 (message "Creating customization setup...")
|
|
1186 (widget-setup)
|
|
1187 (goto-char (point-min))
|
|
1188 (message "Creating customization buffer...done"))
|
|
1189
|
|
1190
|
|
1191 ;;; The Tree Browser.
|
|
1192
|
|
1193 ;;;###autoload
|
|
1194 (defun customize-browse (&optional group)
|
|
1195 "Create a tree browser for the customize hierarchy."
|
|
1196 (interactive)
|
|
1197 (unless group
|
|
1198 (setq group 'emacs))
|
|
1199 (let ((name "*Customize Browser*"))
|
|
1200 (kill-buffer (get-buffer-create name))
|
|
1201 (switch-to-buffer (get-buffer-create name)))
|
|
1202 (custom-mode)
|
|
1203 (widget-insert "\
|
|
1204 Square brackets show active fields; type RET or click button2
|
|
1205 on an active field to invoke its action.
|
|
1206 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
|
|
1207 (if custom-browse-only-groups
|
|
1208 (widget-insert "\
|
|
1209 Invoke the [Group] button below to edit that item in another window.\n\n")
|
|
1210 (widget-insert "Invoke the ")
|
|
1211 (widget-create 'item
|
|
1212 :format "%t"
|
|
1213 :tag "[Group]"
|
|
1214 :tag-glyph "folder")
|
|
1215 (widget-insert ", ")
|
|
1216 (widget-create 'item
|
|
1217 :format "%t"
|
|
1218 :tag "[Face]"
|
|
1219 :tag-glyph "face")
|
|
1220 (widget-insert ", and ")
|
|
1221 (widget-create 'item
|
|
1222 :format "%t"
|
|
1223 :tag "[Option]"
|
|
1224 :tag-glyph "option")
|
|
1225 (widget-insert " buttons below to edit that
|
|
1226 item in another window.\n\n"))
|
|
1227 (let ((custom-buffer-style 'tree))
|
|
1228 (widget-create 'custom-group
|
|
1229 :custom-last t
|
|
1230 :custom-state 'unknown
|
|
1231 :tag (custom-unlispify-tag-name group)
|
|
1232 :value group))
|
|
1233 (widget-add-change)
|
|
1234 (goto-char (point-min)))
|
|
1235
|
|
1236 (define-widget 'custom-browse-visibility 'item
|
|
1237 "Control visibility of of items in the customize tree browser."
|
|
1238 :format "%[[%t]%]"
|
|
1239 :action 'custom-browse-visibility-action)
|
|
1240
|
|
1241 (defun custom-browse-visibility-action (widget &rest ignore)
|
|
1242 (let ((custom-buffer-style 'tree))
|
|
1243 (custom-toggle-parent widget)))
|
|
1244
|
|
1245 (define-widget 'custom-browse-group-tag 'push-button
|
|
1246 "Show parent in other window when activated."
|
|
1247 :tag "Group"
|
|
1248 :tag-glyph "folder"
|
|
1249 :action 'custom-browse-group-tag-action)
|
|
1250
|
|
1251 (defun custom-browse-group-tag-action (widget &rest ignore)
|
|
1252 (let ((parent (widget-get widget :parent)))
|
|
1253 (customize-group-other-window (widget-value parent))))
|
|
1254
|
|
1255 (define-widget 'custom-browse-variable-tag 'push-button
|
|
1256 "Show parent in other window when activated."
|
|
1257 :tag "Option"
|
|
1258 :tag-glyph "option"
|
|
1259 :action 'custom-browse-variable-tag-action)
|
|
1260
|
|
1261 (defun custom-browse-variable-tag-action (widget &rest ignore)
|
|
1262 (let ((parent (widget-get widget :parent)))
|
|
1263 (customize-variable-other-window (widget-value parent))))
|
|
1264
|
|
1265 (define-widget 'custom-browse-face-tag 'push-button
|
|
1266 "Show parent in other window when activated."
|
|
1267 :tag "Face"
|
|
1268 :tag-glyph "face"
|
|
1269 :action 'custom-browse-face-tag-action)
|
|
1270
|
|
1271 (defun custom-browse-face-tag-action (widget &rest ignore)
|
|
1272 (let ((parent (widget-get widget :parent)))
|
|
1273 (customize-face-other-window (widget-value parent))))
|
|
1274
|
|
1275 (defconst custom-browse-alist '((" " "space")
|
|
1276 (" | " "vertical")
|
|
1277 ("-\\ " "top")
|
|
1278 (" |-" "middle")
|
|
1279 (" `-" "bottom")))
|
|
1280
|
|
1281 (defun custom-browse-insert-prefix (prefix)
|
|
1282 "Insert PREFIX. On XEmacs convert it to line graphics."
|
440
|
1283 ;; #### Unfinished.
|
428
|
1284 (if nil ; (string-match "XEmacs" emacs-version)
|
|
1285 (progn
|
|
1286 (insert "*")
|
|
1287 (while (not (string-equal prefix ""))
|
|
1288 (let ((entry (substring prefix 0 3)))
|
|
1289 (setq prefix (substring prefix 3))
|
|
1290 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
|
|
1291 (name (nth 1 (assoc entry custom-browse-alist))))
|
|
1292 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
|
|
1293 (overlay-put overlay 'start-open t)
|
|
1294 (overlay-put overlay 'end-open t)))))
|
|
1295 (insert prefix)))
|
|
1296
|
|
1297
|
|
1298 ;;; Modification of Basic Widgets.
|
|
1299 ;;
|
|
1300 ;; We add extra properties to the basic widgets needed here. This is
|
|
1301 ;; fine, as long as we are careful to stay within out own namespace.
|
|
1302 ;;
|
|
1303 ;; We want simple widgets to be displayed by default, but complex
|
|
1304 ;; widgets to be hidden.
|
|
1305
|
|
1306 (widget-put (get 'item 'widget-type) :custom-show t)
|
|
1307 (widget-put (get 'editable-field 'widget-type)
|
|
1308 :custom-show (lambda (widget value)
|
|
1309 ;; This used to call pp-to-string
|
|
1310 (let ((pp (widget-prettyprint-to-string value)))
|
|
1311 (cond ((string-match "\n" pp)
|
|
1312 nil)
|
|
1313 ((> (length pp) 40)
|
|
1314 nil)
|
|
1315 (t t)))))
|
|
1316 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
|
|
1317
|
|
1318 ;;; The `custom-manual' Widget.
|
|
1319
|
|
1320 (define-widget 'custom-manual 'info-link
|
|
1321 "Link to the manual entry for this customization option."
|
|
1322 :tag "Manual")
|
|
1323
|
|
1324 ;;; The `custom-magic' Widget.
|
|
1325
|
|
1326 (defgroup custom-magic-faces nil
|
|
1327 "Faces used by the magic button."
|
|
1328 :group 'custom-faces
|
|
1329 :group 'custom-buffer)
|
|
1330
|
|
1331 (defface custom-invalid-face '((((class color))
|
|
1332 (:foreground "yellow" :background "red"))
|
|
1333 (t
|
|
1334 (:bold t :italic t :underline t)))
|
|
1335 "Face used when the customize item is invalid."
|
|
1336 :group 'custom-magic-faces)
|
|
1337
|
|
1338 (defface custom-rogue-face '((((class color))
|
|
1339 (:foreground "pink" :background "black"))
|
|
1340 (t
|
|
1341 (:underline t)))
|
|
1342 "Face used when the customize item is not defined for customization."
|
|
1343 :group 'custom-magic-faces)
|
|
1344
|
|
1345 (defface custom-modified-face '((((class color))
|
|
1346 (:foreground "white" :background "blue"))
|
|
1347 (t
|
|
1348 (:italic t :bold)))
|
|
1349 "Face used when the customize item has been modified."
|
|
1350 :group 'custom-magic-faces)
|
|
1351
|
|
1352 (defface custom-set-face '((((class color))
|
|
1353 (:foreground "blue" :background "white"))
|
|
1354 (t
|
|
1355 (:italic t)))
|
|
1356 "Face used when the customize item has been set."
|
|
1357 :group 'custom-magic-faces)
|
|
1358
|
|
1359 (defface custom-changed-face '((((class color))
|
|
1360 (:foreground "white" :background "blue"))
|
|
1361 (t
|
|
1362 (:italic t)))
|
|
1363 "Face used when the customize item has been changed."
|
|
1364 :group 'custom-magic-faces)
|
|
1365
|
|
1366 (defface custom-saved-face '((t (:underline t)))
|
|
1367 "Face used when the customize item has been saved."
|
|
1368 :group 'custom-magic-faces)
|
|
1369
|
|
1370 (defconst custom-magic-alist '((nil "#" underline "\
|
|
1371 uninitialized, you should not see this.")
|
|
1372 (unknown "?" italic "\
|
|
1373 unknown, you should not see this.")
|
|
1374 (hidden "-" default "\
|
|
1375 hidden, invoke \"Show\" button in the previous line to show." "\
|
|
1376 group now hidden, invoke the above \"Show\" button to show contents.")
|
|
1377 (invalid "x" custom-invalid-face "\
|
|
1378 the value displayed for this %c is invalid and cannot be set.")
|
|
1379 (modified "*" custom-modified-face "\
|
|
1380 you have edited the value as text, but you have not set the %c." "\
|
|
1381 you have edited something in this group, but not set it.")
|
|
1382 (set "+" custom-set-face "\
|
|
1383 you have set this %c, but not saved it for future sessions." "\
|
|
1384 something in this group has been set, but not saved.")
|
|
1385 (changed ":" custom-changed-face "\
|
|
1386 this %c has been changed outside the customize buffer." "\
|
|
1387 something in this group has been changed outside customize.")
|
|
1388 (saved "!" custom-saved-face "\
|
|
1389 this %c has been set and saved." "\
|
|
1390 something in this group has been set and saved.")
|
|
1391 (rogue "@" custom-rogue-face "\
|
|
1392 this %c has not been changed with customize." "\
|
|
1393 something in this group is not prepared for customization.")
|
|
1394 (standard " " nil "\
|
|
1395 this %c is unchanged from its standard setting." "\
|
|
1396 visible group members are all at standard settings."))
|
|
1397 "Alist of customize option states.
|
|
1398 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
|
|
1399
|
|
1400 STATE is one of the following symbols:
|
|
1401
|
|
1402 `nil'
|
|
1403 For internal use, should never occur.
|
|
1404 `unknown'
|
|
1405 For internal use, should never occur.
|
|
1406 `hidden'
|
|
1407 This item is not being displayed.
|
|
1408 `invalid'
|
|
1409 This item is modified, but has an invalid form.
|
|
1410 `modified'
|
|
1411 This item is modified, and has a valid form.
|
|
1412 `set'
|
|
1413 This item has been set but not saved.
|
|
1414 `changed'
|
|
1415 The current value of this item has been changed temporarily.
|
|
1416 `saved'
|
|
1417 This item is marked for saving.
|
|
1418 `rogue'
|
|
1419 This item has no customization information.
|
|
1420 `standard'
|
|
1421 This item is unchanged from the standard setting.
|
|
1422
|
|
1423 MAGIC is a string used to present that state.
|
|
1424
|
|
1425 FACE is a face used to present the state.
|
|
1426
|
|
1427 ITEM-DESC is a string describing the state for options.
|
|
1428
|
|
1429 GROUP-DESC is a string describing the state for groups. If this is
|
|
1430 left out, ITEM-DESC will be used.
|
|
1431
|
|
1432 The string %c in either description will be replaced with the
|
|
1433 category of the item. These are `group'. `option', and `face'.
|
|
1434
|
|
1435 The list should be sorted most significant first.")
|
|
1436
|
|
1437 (defcustom custom-magic-show 'long
|
|
1438 "If non-nil, show textual description of the state.
|
|
1439 If `long', show a full-line description, not just one word."
|
|
1440 :type '(choice (const :tag "no" nil)
|
|
1441 (const short)
|
|
1442 (const long))
|
|
1443 :group 'custom-buffer)
|
|
1444
|
|
1445 (defcustom custom-magic-show-hidden '(option face)
|
|
1446 "Control whether the State button is shown for hidden items.
|
|
1447 The value should be a list with the custom categories where the State
|
|
1448 button should be visible. Possible categories are `group', `option',
|
|
1449 and `face'."
|
|
1450 :type '(set (const group) (const option) (const face))
|
|
1451 :group 'custom-buffer)
|
|
1452
|
|
1453 (defcustom custom-magic-show-button nil
|
|
1454 "Show a \"magic\" button indicating the state of each customization option."
|
|
1455 :type 'boolean
|
|
1456 :group 'custom-buffer)
|
|
1457
|
|
1458 (define-widget 'custom-magic 'default
|
|
1459 "Show and manipulate state for a customization option."
|
|
1460 :format "%v"
|
|
1461 :action 'widget-parent-action
|
|
1462 :notify 'ignore
|
|
1463 :value-get 'ignore
|
|
1464 :value-create 'custom-magic-value-create
|
|
1465 :value-delete 'widget-children-value-delete)
|
|
1466
|
|
1467 (defun widget-magic-mouse-down-action (widget &optional event)
|
|
1468 ;; Non-nil unless hidden.
|
|
1469 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
|
|
1470 :custom-state)
|
|
1471 'hidden)))
|
|
1472
|
|
1473 (defun custom-magic-value-create (widget)
|
|
1474 ;; Create compact status report for WIDGET.
|
|
1475 (let* ((parent (widget-get widget :parent))
|
|
1476 (state (widget-get parent :custom-state))
|
|
1477 (hidden (eq state 'hidden))
|
|
1478 (entry (assq state custom-magic-alist))
|
|
1479 (magic (nth 1 entry))
|
|
1480 (face (nth 2 entry))
|
|
1481 (category (widget-get parent :custom-category))
|
|
1482 (text (or (and (eq category 'group)
|
|
1483 (nth 4 entry))
|
|
1484 (nth 3 entry)))
|
|
1485 (form (widget-get parent :custom-form))
|
|
1486 children)
|
|
1487 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
|
|
1488 (setq text (concat (match-string 1 text)
|
|
1489 (symbol-name category)
|
|
1490 (match-string 2 text))))
|
|
1491 (when (and custom-magic-show
|
|
1492 (or (not hidden)
|
|
1493 (memq category custom-magic-show-hidden)))
|
|
1494 (insert " ")
|
|
1495 (when (and (eq category 'group)
|
|
1496 (not (and (eq custom-buffer-style 'links)
|
|
1497 (> (widget-get parent :custom-level) 1))))
|
|
1498 (insert-char ?\ (* custom-buffer-indent
|
|
1499 (widget-get parent :custom-level))))
|
|
1500 (push (widget-create-child-and-convert
|
|
1501 widget 'choice-item
|
|
1502 :help-echo "Change the state of this item"
|
|
1503 :format (if hidden "%t" "%[%t%]")
|
|
1504 :button-prefix 'widget-push-button-prefix
|
|
1505 :button-suffix 'widget-push-button-suffix
|
|
1506 :mouse-down-action 'widget-magic-mouse-down-action
|
|
1507 :tag "State"
|
|
1508 ;;:tag-glyph (or hidden '("state-up" "state-down"))
|
|
1509 )
|
|
1510 children)
|
|
1511 (insert ": ")
|
|
1512 (let ((start (point)))
|
|
1513 (if (eq custom-magic-show 'long)
|
|
1514 (insert text)
|
|
1515 (insert (symbol-name state)))
|
|
1516 (cond ((eq form 'lisp)
|
|
1517 (insert " (lisp)"))
|
|
1518 ((eq form 'mismatch)
|
|
1519 (insert " (mismatch)")))
|
|
1520 (put-text-property start (point) 'face 'custom-state-face))
|
|
1521 (insert "\n"))
|
|
1522 (when (and (eq category 'group)
|
|
1523 (not (and (eq custom-buffer-style 'links)
|
|
1524 (> (widget-get parent :custom-level) 1))))
|
|
1525 (insert-char ?\ (* custom-buffer-indent
|
|
1526 (widget-get parent :custom-level))))
|
|
1527 (when custom-magic-show-button
|
|
1528 (when custom-magic-show
|
|
1529 (let ((indent (widget-get parent :indent)))
|
|
1530 (when indent
|
|
1531 (insert-char ?\ indent))))
|
|
1532 (push (widget-create-child-and-convert
|
|
1533 widget 'choice-item
|
|
1534 :mouse-down-action 'widget-magic-mouse-down-action
|
|
1535 :button-face face
|
|
1536 :button-prefix ""
|
|
1537 :button-suffix ""
|
|
1538 :help-echo "Change the state"
|
|
1539 :format (if hidden "%t" "%[%t%]")
|
|
1540 :tag (if (memq form '(lisp mismatch))
|
|
1541 (concat "(" magic ")")
|
|
1542 (concat "[" magic "]")))
|
|
1543 children)
|
|
1544 (insert " "))
|
|
1545 (widget-put widget :children children)))
|
|
1546
|
|
1547 (defun custom-magic-reset (widget)
|
|
1548 "Redraw the :custom-magic property of WIDGET."
|
|
1549 (let ((magic (widget-get widget :custom-magic)))
|
|
1550 (widget-value-set magic (widget-value magic))))
|
|
1551
|
|
1552 ;;; The `custom' Widget.
|
|
1553
|
|
1554 (defface custom-button-face '((t (:bold t)))
|
|
1555 "Face used for buttons in customization buffers."
|
|
1556 :group 'custom-faces)
|
|
1557
|
|
1558 (defface custom-documentation-face nil
|
|
1559 "Face used for documentation strings in customization buffers."
|
|
1560 :group 'custom-faces)
|
|
1561
|
|
1562 (defface custom-state-face '((((class color)
|
|
1563 (background dark))
|
|
1564 (:foreground "lime green"))
|
|
1565 (((class color)
|
|
1566 (background light))
|
|
1567 (:foreground "dark green"))
|
|
1568 (t nil))
|
|
1569 "Face used for State descriptions in the customize buffer."
|
|
1570 :group 'custom-faces)
|
|
1571
|
|
1572 (define-widget 'custom 'default
|
|
1573 "Customize a user option."
|
|
1574 :format "%v"
|
|
1575 :convert-widget 'custom-convert-widget
|
|
1576 :notify 'custom-notify
|
|
1577 :custom-prefix ""
|
|
1578 :custom-level 1
|
|
1579 :custom-state 'hidden
|
|
1580 :documentation-property 'widget-subclass-responsibility
|
|
1581 :value-create 'widget-subclass-responsibility
|
|
1582 :value-delete 'widget-children-value-delete
|
|
1583 :value-get 'widget-value-value-get
|
|
1584 :validate 'widget-children-validate
|
|
1585 :match (lambda (widget value) (symbolp value)))
|
|
1586
|
|
1587 (defun custom-convert-widget (widget)
|
|
1588 ;; Initialize :value and :tag from :args in WIDGET.
|
|
1589 (let ((args (widget-get widget :args)))
|
|
1590 (when args
|
|
1591 (widget-put widget :value (widget-apply widget
|
|
1592 :value-to-internal (car args)))
|
|
1593 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
|
|
1594 (widget-put widget :args nil)))
|
|
1595 widget)
|
|
1596
|
|
1597 (defun custom-notify (widget &rest args)
|
|
1598 "Keep track of changes."
|
|
1599 (let ((state (widget-get widget :custom-state)))
|
|
1600 (unless (eq state 'modified)
|
|
1601 (unless (memq state '(nil unknown hidden))
|
|
1602 (widget-put widget :custom-state 'modified))
|
|
1603 (custom-magic-reset widget)
|
|
1604 (apply 'widget-default-notify widget args))))
|
|
1605
|
|
1606 (defun custom-redraw (widget)
|
|
1607 "Redraw WIDGET with current settings."
|
|
1608 (let ((line (count-lines (point-min) (point)))
|
|
1609 (column (current-column))
|
|
1610 (pos (point))
|
|
1611 (from (marker-position (widget-get widget :from)))
|
|
1612 (to (marker-position (widget-get widget :to))))
|
|
1613 (save-excursion
|
|
1614 (widget-value-set widget (widget-value widget))
|
|
1615 (custom-redraw-magic widget))
|
|
1616 (when (and (>= pos from) (<= pos to))
|
|
1617 (condition-case nil
|
|
1618 (progn
|
|
1619 (if (> column 0)
|
|
1620 (goto-line line)
|
|
1621 (goto-line (1+ line)))
|
|
1622 (move-to-column column))
|
|
1623 (error nil)))))
|
|
1624
|
|
1625 (defun custom-redraw-magic (widget)
|
|
1626 "Redraw WIDGET state with current settings."
|
|
1627 (while widget
|
|
1628 (let ((magic (widget-get widget :custom-magic)))
|
|
1629 (cond (magic
|
|
1630 (widget-value-set magic (widget-value magic))
|
|
1631 (when (setq widget (widget-get widget :group))
|
|
1632 (custom-group-state-update widget)))
|
|
1633 (t
|
|
1634 (setq widget nil)))))
|
|
1635 (widget-setup))
|
|
1636
|
|
1637 (defun custom-show (widget value)
|
|
1638 "Non-nil if WIDGET should be shown with VALUE by default."
|
|
1639 (let ((show (widget-get widget :custom-show)))
|
|
1640 (cond ((null show)
|
|
1641 nil)
|
|
1642 ((eq t show)
|
|
1643 t)
|
|
1644 (t
|
|
1645 (funcall show widget value)))))
|
|
1646
|
|
1647 (defvar custom-load-recursion nil
|
|
1648 "Hack to avoid recursive dependencies.")
|
|
1649
|
|
1650 (defun custom-load-symbol (symbol)
|
|
1651 "Load all dependencies for SYMBOL."
|
|
1652 (unless custom-load-recursion
|
|
1653 (let ((custom-load-recursion t)
|
|
1654 (loads (get symbol 'custom-loads))
|
|
1655 load)
|
|
1656 (while loads
|
|
1657 (setq load (car loads)
|
|
1658 loads (cdr loads))
|
|
1659 (cond ((symbolp load)
|
|
1660 (condition-case nil
|
|
1661 (require load)
|
|
1662 (error nil)))
|
|
1663 ;; Don't reload a file already loaded.
|
|
1664 ((and (boundp 'preloaded-file-list)
|
|
1665 (member load preloaded-file-list)))
|
|
1666 ((assoc load load-history))
|
|
1667 ((assoc (locate-library load) load-history))
|
|
1668 (t
|
|
1669 (condition-case nil
|
|
1670 ;; Without this, we would load cus-edit recursively.
|
|
1671 ;; We are still loading it when we call this,
|
|
1672 ;; and it is not in load-history yet.
|
|
1673 (or (equal load "cus-edit")
|
|
1674 (load-library load))
|
|
1675 (error nil))))))))
|
|
1676
|
|
1677 (defun custom-load-widget (widget)
|
|
1678 "Load all dependencies for WIDGET."
|
|
1679 (custom-load-symbol (widget-value widget)))
|
|
1680
|
|
1681 (defun custom-unloaded-symbol-p (symbol)
|
|
1682 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
|
|
1683 (let ((found nil)
|
|
1684 (loads (get symbol 'custom-loads))
|
|
1685 load)
|
|
1686 (while loads
|
|
1687 (setq load (car loads)
|
|
1688 loads (cdr loads))
|
|
1689 (cond ((symbolp load)
|
|
1690 (unless (featurep load)
|
|
1691 (setq found t)))
|
|
1692 ((assoc load load-history))
|
|
1693 ((assoc (locate-library load) load-history)
|
|
1694 ;; #### WTF???
|
|
1695 (message nil))
|
|
1696 (t
|
|
1697 (setq found t))))
|
|
1698 found))
|
|
1699
|
|
1700 (defun custom-unloaded-widget-p (widget)
|
|
1701 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
|
|
1702 (custom-unloaded-symbol-p (widget-value widget)))
|
|
1703
|
|
1704 (defun custom-toggle-hide (widget)
|
|
1705 "Toggle visibility of WIDGET."
|
|
1706 (custom-load-widget widget)
|
|
1707 (let ((state (widget-get widget :custom-state)))
|
|
1708 (cond ((memq state '(invalid modified))
|
|
1709 (error "There are unset changes"))
|
|
1710 ((eq state 'hidden)
|
|
1711 (widget-put widget :custom-state 'unknown))
|
|
1712 (t
|
|
1713 (widget-put widget :documentation-shown nil)
|
|
1714 (widget-put widget :custom-state 'hidden)))
|
|
1715 (custom-redraw widget)
|
|
1716 (widget-setup)))
|
|
1717
|
|
1718 (defun custom-toggle-parent (widget &rest ignore)
|
|
1719 "Toggle visibility of parent of WIDGET."
|
|
1720 (custom-toggle-hide (widget-get widget :parent)))
|
|
1721
|
|
1722 (defun custom-add-see-also (widget &optional prefix)
|
|
1723 "Add `See also ...' to WIDGET if there are any links.
|
|
1724 Insert PREFIX first if non-nil."
|
|
1725 (let* ((symbol (widget-get widget :value))
|
|
1726 (links (get symbol 'custom-links))
|
|
1727 (many (> (length links) 2))
|
|
1728 (buttons (widget-get widget :buttons))
|
|
1729 (indent (widget-get widget :indent)))
|
|
1730 (when links
|
|
1731 (when indent
|
|
1732 (insert-char ?\ indent))
|
|
1733 (when prefix
|
|
1734 (insert prefix))
|
|
1735 (insert "See also ")
|
|
1736 (while links
|
|
1737 (push (widget-create-child-and-convert widget (car links))
|
|
1738 buttons)
|
|
1739 (setq links (cdr links))
|
|
1740 (cond ((null links)
|
|
1741 (insert ".\n"))
|
|
1742 ((null (cdr links))
|
|
1743 (if many
|
|
1744 (insert ", and ")
|
|
1745 (insert " and ")))
|
|
1746 (t
|
|
1747 (insert ", "))))
|
|
1748 (widget-put widget :buttons buttons))))
|
|
1749
|
|
1750 (defun custom-add-parent-links (widget &optional initial-string)
|
|
1751 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
|
|
1752 The value if non-nil if any parents were found.
|
|
1753 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
|
|
1754 (let ((name (widget-value widget))
|
|
1755 (type (widget-type widget))
|
|
1756 (buttons (widget-get widget :buttons))
|
|
1757 (start (point))
|
|
1758 found)
|
|
1759 (insert (or initial-string "Parent groups:"))
|
|
1760 (maphash (lambda (group ignore)
|
|
1761 (let ((entry (assq name (get group 'custom-group))))
|
|
1762 (when (eq (nth 1 entry) type)
|
|
1763 (insert " ")
|
|
1764 (push (widget-create-child-and-convert
|
|
1765 widget 'custom-group-link
|
|
1766 :tag (custom-unlispify-tag-name group)
|
|
1767 group)
|
|
1768 buttons)
|
|
1769 (setq found t))))
|
|
1770 custom-group-hash-table)
|
|
1771 (widget-put widget :buttons buttons)
|
|
1772 (if found
|
|
1773 (insert "\n")
|
|
1774 (delete-region start (point)))
|
|
1775 found))
|
|
1776
|
|
1777 ;;; The `custom-comment' Widget.
|
|
1778
|
|
1779 ;; like the editable field
|
|
1780 (defface custom-comment-face '((((class grayscale color)
|
|
1781 (background light))
|
|
1782 (:background "gray85"))
|
|
1783 (((class grayscale color)
|
|
1784 (background dark))
|
|
1785 (:background "dim gray"))
|
|
1786 (t
|
|
1787 (:italic t)))
|
|
1788 "Face used for comments on variables or faces"
|
|
1789 :group 'custom-faces)
|
|
1790
|
|
1791 ;; like font-lock-comment-face
|
|
1792 (defface custom-comment-tag-face
|
|
1793 '((((class color) (background dark)) (:foreground "gray80"))
|
|
1794 (((class color) (background light)) (:foreground "blue4"))
|
|
1795 (((class grayscale) (background light))
|
|
1796 (:foreground "DimGray" :bold t :italic t))
|
|
1797 (((class grayscale) (background dark))
|
|
1798 (:foreground "LightGray" :bold t :italic t))
|
|
1799 (t (:bold t)))
|
|
1800 "Face used for variables or faces comment tags"
|
|
1801 :group 'custom-faces)
|
|
1802
|
|
1803 (define-widget 'custom-comment 'string
|
|
1804 "User comment"
|
|
1805 :tag "Comment"
|
|
1806 :help-echo "Edit a comment here"
|
|
1807 :sample-face 'custom-comment-tag-face
|
|
1808 :value-face 'custom-comment-face
|
|
1809 :value-set 'custom-comment-value-set
|
|
1810 :create 'custom-comment-create
|
|
1811 :delete 'custom-comment-delete)
|
|
1812
|
|
1813 (defun custom-comment-create (widget)
|
|
1814 (let (ext)
|
|
1815 (widget-default-create widget)
|
|
1816 (widget-put widget :comment-extent
|
|
1817 (setq ext (make-extent (widget-get widget :from)
|
|
1818 (widget-get widget :to))))
|
|
1819 (set-extent-property ext 'start-open t)
|
|
1820 (when (equal (widget-get widget :value) "")
|
|
1821 (set-extent-property ext 'invisible t))
|
|
1822 ))
|
|
1823
|
|
1824 (defun custom-comment-delete (widget)
|
|
1825 (widget-default-delete widget)
|
|
1826 (delete-extent (widget-get widget :comment-extent)))
|
|
1827
|
|
1828 (defun custom-comment-value-set (widget value)
|
|
1829 (widget-default-value-set widget value)
|
|
1830 (if (equal value "")
|
|
1831 (set-extent-property (widget-get widget :comment-extent)
|
|
1832 'invisible t)
|
|
1833 (set-extent-property (widget-get widget :comment-extent)
|
|
1834 'invisible nil)))
|
|
1835
|
|
1836 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
|
|
1837 ;; the global custom one
|
|
1838 (defun custom-comment-show (widget)
|
|
1839 (set-extent-property
|
|
1840 (widget-get (widget-get widget :comment-widget) :comment-extent)
|
|
1841 'invisible nil))
|
|
1842
|
|
1843 (defun custom-comment-invisible-p (widget)
|
|
1844 (extent-property
|
|
1845 (widget-get (widget-get widget :comment-widget) :comment-extent)
|
|
1846 'invisible))
|
|
1847
|
|
1848 ;;; The `custom-variable' Widget.
|
|
1849
|
|
1850 (defface custom-variable-tag-face '((((class color)
|
|
1851 (background dark))
|
|
1852 (:foreground "light blue" :underline t))
|
|
1853 (((class color)
|
|
1854 (background light))
|
|
1855 (:foreground "blue" :underline t))
|
|
1856 (t (:underline t)))
|
|
1857 "Face used for unpushable variable tags."
|
|
1858 :group 'custom-faces)
|
|
1859
|
|
1860 (defface custom-variable-button-face '((t (:underline t :bold t)))
|
|
1861 "Face used for pushable variable tags."
|
|
1862 :group 'custom-faces)
|
|
1863
|
|
1864 (defcustom custom-variable-default-form 'edit
|
|
1865 "Default form of displaying variable values."
|
|
1866 :type '(choice (const edit)
|
|
1867 (const lisp))
|
|
1868 :group 'custom-buffer)
|
|
1869
|
|
1870 (define-widget 'custom-variable 'custom
|
|
1871 "Customize variable."
|
|
1872 :format "%v"
|
|
1873 :help-echo "Set or reset this variable"
|
|
1874 :documentation-property 'variable-documentation
|
|
1875 :custom-category 'option
|
|
1876 :custom-state nil
|
|
1877 :custom-menu 'custom-variable-menu-create
|
|
1878 :custom-form nil ; defaults to value of `custom-variable-default-form'
|
|
1879 :value-create 'custom-variable-value-create
|
|
1880 :action 'custom-variable-action
|
|
1881 :custom-set 'custom-variable-set
|
480
|
1882 :custom-pre-save 'custom-variable-pre-save
|
428
|
1883 :custom-save 'custom-variable-save
|
480
|
1884 :custom-post-save 'custom-variable-post-save
|
428
|
1885 :custom-reset-current 'custom-redraw
|
|
1886 :custom-reset-saved 'custom-variable-reset-saved
|
480
|
1887 :custom-pre-reset-standard 'custom-variable-pre-reset-standard
|
|
1888 :custom-reset-standard 'custom-variable-reset-standard
|
|
1889 :custom-post-reset-standard 'custom-variable-post-reset-standard)
|
428
|
1890
|
|
1891 (defun custom-variable-type (symbol)
|
|
1892 "Return a widget suitable for editing the value of SYMBOL.
|
|
1893 If SYMBOL has a `custom-type' property, use that.
|
|
1894 Otherwise, look up symbol in `custom-guess-type-alist'."
|
|
1895 (let* ((type (or (get symbol 'custom-type)
|
|
1896 (and (not (get symbol 'standard-value))
|
|
1897 (custom-guess-type symbol))
|
|
1898 'sexp))
|
|
1899 (options (get symbol 'custom-options))
|
|
1900 (tmp (if (listp type)
|
|
1901 (copy-sequence type)
|
|
1902 (list type))))
|
|
1903 (when options
|
|
1904 (widget-put tmp :options options))
|
|
1905 tmp))
|
|
1906
|
|
1907 (defun custom-variable-value-create (widget)
|
|
1908 "Here is where you edit the variables value."
|
|
1909 (custom-load-widget widget)
|
|
1910 (unless (widget-get widget :custom-form)
|
|
1911 (widget-put widget :custom-form custom-variable-default-form))
|
|
1912 (let* ((buttons (widget-get widget :buttons))
|
|
1913 (children (widget-get widget :children))
|
|
1914 (form (widget-get widget :custom-form))
|
|
1915 (state (widget-get widget :custom-state))
|
|
1916 (symbol (widget-get widget :value))
|
|
1917 (tag (widget-get widget :tag))
|
|
1918 (type (custom-variable-type symbol))
|
|
1919 (conv (widget-convert type))
|
|
1920 (get (or (get symbol 'custom-get) 'default-value))
|
|
1921 (prefix (widget-get widget :custom-prefix))
|
|
1922 (last (widget-get widget :custom-last))
|
|
1923 (value (if (default-boundp symbol)
|
|
1924 (funcall get symbol)
|
|
1925 (widget-get conv :value))))
|
|
1926 ;; If the widget is new, the child determine whether it is hidden.
|
|
1927 (cond (state)
|
|
1928 ((custom-show type value)
|
|
1929 (setq state 'unknown))
|
|
1930 (t
|
|
1931 (setq state 'hidden)))
|
|
1932 ;; If we don't know the state, see if we need to edit it in lisp form.
|
|
1933 (when (eq state 'unknown)
|
|
1934 (unless (widget-apply conv :match value)
|
|
1935 ;; (widget-apply (widget-convert type) :match value)
|
|
1936 (setq form 'mismatch)))
|
|
1937 ;; Now we can create the child widget.
|
|
1938 (cond ((eq custom-buffer-style 'tree)
|
|
1939 (insert prefix (if last " `--- " " |--- "))
|
|
1940 (push (widget-create-child-and-convert
|
|
1941 widget 'custom-browse-variable-tag)
|
|
1942 buttons)
|
|
1943 (insert " " tag "\n")
|
|
1944 (widget-put widget :buttons buttons))
|
|
1945 ((eq state 'hidden)
|
|
1946 ;; Indicate hidden value.
|
|
1947 (push (widget-create-child-and-convert
|
|
1948 widget 'item
|
|
1949 :format "%{%t%}: "
|
|
1950 :sample-face 'custom-variable-tag-face
|
|
1951 :tag tag
|
|
1952 :parent widget)
|
|
1953 buttons)
|
|
1954 (push (widget-create-child-and-convert
|
|
1955 widget 'visibility
|
|
1956 :help-echo "Show the value of this option"
|
|
1957 :action 'custom-toggle-parent
|
|
1958 nil)
|
|
1959 buttons))
|
|
1960 ((memq form '(lisp mismatch))
|
|
1961 ;; In lisp mode edit the saved value when possible.
|
|
1962 (let* ((value (cond ((get symbol 'saved-value)
|
|
1963 (car (get symbol 'saved-value)))
|
|
1964 ((get symbol 'standard-value)
|
|
1965 (car (get symbol 'standard-value)))
|
|
1966 ((default-boundp symbol)
|
|
1967 (custom-quote (funcall get symbol)))
|
|
1968 (t
|
|
1969 (custom-quote (widget-get conv :value))))))
|
|
1970 (insert (symbol-name symbol) ": ")
|
|
1971 (push (widget-create-child-and-convert
|
|
1972 widget 'visibility
|
|
1973 :help-echo "Hide the value of this option"
|
|
1974 :action 'custom-toggle-parent
|
|
1975 t)
|
|
1976 buttons)
|
|
1977 (insert " ")
|
|
1978 (push (widget-create-child-and-convert
|
|
1979 widget 'sexp
|
|
1980 :button-face 'custom-variable-button-face
|
|
1981 :format "%v"
|
|
1982 :tag (symbol-name symbol)
|
|
1983 :parent widget
|
|
1984 :value value)
|
|
1985 children)))
|
|
1986 (t
|
|
1987 ;; Edit mode.
|
|
1988 (let* ((format (widget-get type :format))
|
|
1989 tag-format value-format)
|
|
1990 (while (not (string-match ":" format))
|
|
1991 (setq format (signal 'error (list "Bad format" format))))
|
|
1992 (setq tag-format (substring format 0 (match-end 0)))
|
|
1993 (setq value-format (substring format (match-end 0)))
|
|
1994 (push (widget-create-child-and-convert
|
|
1995 widget 'item
|
|
1996 :format tag-format
|
|
1997 :action 'custom-tag-action
|
|
1998 :help-echo "Change value of this option"
|
|
1999 :mouse-down-action 'custom-tag-mouse-down-action
|
|
2000 :button-face 'custom-variable-button-face
|
|
2001 :sample-face 'custom-variable-tag-face
|
|
2002 tag)
|
|
2003 buttons)
|
|
2004 (insert " ")
|
|
2005 (push (widget-create-child-and-convert
|
|
2006 widget 'visibility
|
|
2007 :help-echo "Hide the value of this option"
|
|
2008 :action 'custom-toggle-parent
|
|
2009 t)
|
|
2010 buttons)
|
|
2011 (push (widget-create-child-and-convert
|
|
2012 widget type
|
|
2013 :format value-format
|
|
2014 :value value)
|
|
2015 children))))
|
|
2016 (unless (eq custom-buffer-style 'tree)
|
|
2017 (unless (eq (preceding-char) ?\n)
|
|
2018 (widget-insert "\n"))
|
|
2019 ;; Create the magic button.
|
|
2020 (let ((magic (widget-create-child-and-convert
|
|
2021 widget 'custom-magic nil)))
|
|
2022 (widget-put widget :custom-magic magic)
|
|
2023 (push magic buttons))
|
|
2024 ;; Insert documentation.
|
440
|
2025 ;; #### NOTE: this is ugly!!!! I need to do update the :buttons property
|
428
|
2026 ;; before the call to `widget-default-format-handler'. Otherwise, I
|
444
|
2027 ;; lose my current `buttons'. This function shouldn't be called like
|
428
|
2028 ;; this anyway. The doc string widget should be added like the others.
|
|
2029 ;; --dv
|
|
2030 (widget-put widget :buttons buttons)
|
|
2031 (widget-default-format-handler widget ?h)
|
|
2032 ;; The comment field
|
|
2033 (unless (eq state 'hidden)
|
|
2034 (let* ((comment (get symbol 'variable-comment))
|
|
2035 (comment-widget
|
|
2036 (widget-create-child-and-convert
|
|
2037 widget 'custom-comment
|
|
2038 :parent widget
|
|
2039 :value (or comment ""))))
|
|
2040 (widget-put widget :comment-widget comment-widget)
|
|
2041 ;; Don't push it !!! Custom assumes that the first child is the
|
|
2042 ;; value one.
|
|
2043 (setq children (append children (list comment-widget)))))
|
|
2044 ;; Update the rest of the properties properties.
|
|
2045 (widget-put widget :custom-form form)
|
|
2046 (widget-put widget :children children)
|
|
2047 ;; Now update the state.
|
|
2048 (if (eq state 'hidden)
|
|
2049 (widget-put widget :custom-state state)
|
|
2050 (custom-variable-state-set widget))
|
|
2051 ;; See also.
|
|
2052 (unless (eq state 'hidden)
|
|
2053 (when (eq (widget-get widget :custom-level) 1)
|
|
2054 (custom-add-parent-links widget))
|
|
2055 (custom-add-see-also widget)))))
|
|
2056
|
|
2057 (defun custom-tag-action (widget &rest args)
|
|
2058 "Pass :action to first child of WIDGET's parent."
|
|
2059 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
|
|
2060 :action args))
|
|
2061
|
|
2062 (defun custom-tag-mouse-down-action (widget &rest args)
|
|
2063 "Pass :mouse-down-action to first child of WIDGET's parent."
|
|
2064 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
|
|
2065 :mouse-down-action args))
|
|
2066
|
|
2067 (defun custom-variable-state-set (widget)
|
|
2068 "Set the state of WIDGET."
|
|
2069 (let* ((symbol (widget-value widget))
|
|
2070 (get (or (get symbol 'custom-get) 'default-value))
|
|
2071 (value (if (default-boundp symbol)
|
|
2072 (funcall get symbol)
|
|
2073 (widget-get widget :value)))
|
|
2074 (comment (get symbol 'variable-comment))
|
|
2075 tmp
|
|
2076 temp
|
|
2077 (state (cond ((progn (setq tmp (get symbol 'customized-value))
|
|
2078 (setq temp
|
|
2079 (get symbol 'customized-variable-comment))
|
|
2080 (or tmp temp))
|
|
2081 (if (condition-case nil
|
|
2082 (and (equal value (eval (car tmp)))
|
|
2083 (equal comment temp))
|
|
2084 (error nil))
|
|
2085 'set
|
|
2086 'changed))
|
|
2087 ((progn (setq tmp (get symbol 'saved-value))
|
|
2088 (setq temp (get symbol 'saved-variable-comment))
|
|
2089 (or tmp temp))
|
|
2090 (if (condition-case nil
|
|
2091 (and (equal value (eval (car tmp)))
|
|
2092 (equal comment temp))
|
|
2093 (error nil))
|
|
2094 'saved
|
|
2095 'changed))
|
|
2096 ((setq tmp (get symbol 'standard-value))
|
|
2097 (if (condition-case nil
|
|
2098 (and (equal value (eval (car tmp)))
|
|
2099 (equal comment nil))
|
|
2100 (error nil))
|
|
2101 'standard
|
|
2102 'changed))
|
|
2103 (t 'rogue))))
|
|
2104 (widget-put widget :custom-state state)))
|
|
2105
|
|
2106 (defvar custom-variable-menu
|
|
2107 '(("Set for Current Session" custom-variable-set
|
|
2108 (lambda (widget)
|
|
2109 (eq (widget-get widget :custom-state) 'modified)))
|
|
2110 ("Save for Future Sessions" custom-variable-save
|
|
2111 (lambda (widget)
|
|
2112 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
|
|
2113 ("Reset to Current" custom-redraw
|
|
2114 (lambda (widget)
|
|
2115 (and (default-boundp (widget-value widget))
|
|
2116 (memq (widget-get widget :custom-state) '(modified changed)))))
|
|
2117 ("Reset to Saved" custom-variable-reset-saved
|
|
2118 (lambda (widget)
|
|
2119 (and (or (get (widget-value widget) 'saved-value)
|
|
2120 (get (widget-value widget) 'saved-variable-comment))
|
|
2121 (memq (widget-get widget :custom-state)
|
|
2122 '(modified set changed rogue)))))
|
|
2123 ("Reset to Standard Settings" custom-variable-reset-standard
|
|
2124 (lambda (widget)
|
|
2125 (and (get (widget-value widget) 'standard-value)
|
|
2126 (memq (widget-get widget :custom-state)
|
|
2127 '(modified set changed saved rogue)))))
|
|
2128 ("---" ignore ignore)
|
|
2129 ("Add Comment" custom-comment-show custom-comment-invisible-p)
|
|
2130 ("---" ignore ignore)
|
|
2131 ("Don't show as Lisp expression" custom-variable-edit
|
|
2132 (lambda (widget)
|
|
2133 (eq (widget-get widget :custom-form) 'lisp)))
|
|
2134 ("Show as Lisp expression" custom-variable-edit-lisp
|
|
2135 (lambda (widget)
|
|
2136 (eq (widget-get widget :custom-form) 'edit))))
|
|
2137 "Alist of actions for the `custom-variable' widget.
|
|
2138 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
2139 the menu entry, ACTION is the function to call on the widget when the
|
|
2140 menu is selected, and FILTER is a predicate which takes a `custom-variable'
|
|
2141 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
2142 widget. If FILTER is nil, ACTION is always valid.")
|
|
2143
|
|
2144 (defun custom-variable-action (widget &optional event)
|
|
2145 "Show the menu for `custom-variable' WIDGET.
|
|
2146 Optional EVENT is the location for the menu."
|
|
2147 (if (eq (widget-get widget :custom-state) 'hidden)
|
|
2148 (custom-toggle-hide widget)
|
|
2149 (unless (eq (widget-get widget :custom-state) 'modified)
|
|
2150 (custom-variable-state-set widget))
|
|
2151 ;; Redrawing magic also depresses the state glyph.
|
|
2152 ;(custom-redraw-magic widget)
|
|
2153 (let* ((completion-ignore-case t)
|
|
2154 (answer (widget-choose (concat "Operation on "
|
|
2155 (custom-unlispify-tag-name
|
|
2156 (widget-get widget :value)))
|
|
2157 (custom-menu-filter custom-variable-menu
|
|
2158 widget)
|
|
2159 event)))
|
|
2160 (if answer
|
|
2161 (funcall answer widget)))))
|
|
2162
|
|
2163 (defun custom-variable-edit (widget)
|
|
2164 "Edit value of WIDGET."
|
|
2165 (widget-put widget :custom-state 'unknown)
|
|
2166 (widget-put widget :custom-form 'edit)
|
|
2167 (custom-redraw widget))
|
|
2168
|
|
2169 (defun custom-variable-edit-lisp (widget)
|
|
2170 "Edit the lisp representation of the value of WIDGET."
|
|
2171 (widget-put widget :custom-state 'unknown)
|
|
2172 (widget-put widget :custom-form 'lisp)
|
|
2173 (custom-redraw widget))
|
|
2174
|
|
2175 (defun custom-variable-set (widget)
|
|
2176 "Set the current value for the variable being edited by WIDGET."
|
|
2177 (let* ((form (widget-get widget :custom-form))
|
|
2178 (state (widget-get widget :custom-state))
|
|
2179 (child (car (widget-get widget :children)))
|
|
2180 (symbol (widget-value widget))
|
|
2181 (set (or (get symbol 'custom-set) 'set-default))
|
|
2182 (comment-widget (widget-get widget :comment-widget))
|
|
2183 (comment (widget-value comment-widget))
|
|
2184 val)
|
|
2185 (cond ((eq state 'hidden)
|
|
2186 (error "Cannot set hidden variable"))
|
|
2187 ((setq val (widget-apply child :validate))
|
|
2188 (goto-char (widget-get val :from))
|
|
2189 (error "%s" (widget-get val :error)))
|
|
2190 ((memq form '(lisp mismatch))
|
|
2191 (when (equal comment "")
|
|
2192 (setq comment nil)
|
|
2193 ;; Make the comment invisible by hand if it's empty
|
|
2194 (set-extent-property (widget-get comment-widget :comment-extent)
|
|
2195 'invisible t))
|
|
2196 (funcall set symbol (eval (setq val (widget-value child))))
|
|
2197 (put symbol 'customized-value (list val))
|
|
2198 (put symbol 'variable-comment comment)
|
|
2199 (put symbol 'customized-variable-comment comment))
|
|
2200 (t
|
|
2201 (when (equal comment "")
|
|
2202 (setq comment nil)
|
|
2203 ;; Make the comment invisible by hand if it's empty
|
|
2204 (set-extent-property (widget-get comment-widget :comment-extent)
|
|
2205 'invisible t))
|
|
2206 (funcall set symbol (setq val (widget-value child)))
|
|
2207 (put symbol 'customized-value (list (custom-quote val)))
|
|
2208 (put symbol 'variable-comment comment)
|
|
2209 (put symbol 'customized-variable-comment comment)))
|
|
2210 (custom-variable-state-set widget)
|
|
2211 (custom-redraw-magic widget)))
|
|
2212
|
480
|
2213 (defun custom-variable-pre-save (widget)
|
|
2214 "Prepare for saving the value for the variable being edited by WIDGET."
|
428
|
2215 (let* ((form (widget-get widget :custom-form))
|
|
2216 (state (widget-get widget :custom-state))
|
|
2217 (child (car (widget-get widget :children)))
|
|
2218 (symbol (widget-value widget))
|
|
2219 (set (or (get symbol 'custom-set) 'set-default))
|
|
2220 (comment-widget (widget-get widget :comment-widget))
|
|
2221 (comment (widget-value comment-widget))
|
|
2222 val)
|
|
2223 (cond ((eq state 'hidden)
|
|
2224 (error "Cannot set hidden variable"))
|
|
2225 ((setq val (widget-apply child :validate))
|
|
2226 (goto-char (widget-get val :from))
|
|
2227 (error "%s" (widget-get val :error)))
|
|
2228 ((memq form '(lisp mismatch))
|
|
2229 (when (equal comment "")
|
|
2230 (setq comment nil)
|
|
2231 ;; Make the comment invisible by hand if it's empty
|
|
2232 (set-extent-property (widget-get comment-widget :comment-extent)
|
|
2233 'invisible t))
|
|
2234 (put symbol 'saved-value (list (widget-value child)))
|
|
2235 (custom-push-theme 'theme-value symbol 'user
|
|
2236 'set (list (widget-value child)))
|
|
2237 (funcall set symbol (eval (widget-value child)))
|
|
2238 (put symbol 'variable-comment comment)
|
|
2239 (put symbol 'saved-variable-comment comment))
|
|
2240 (t
|
|
2241 (when (equal comment "")
|
|
2242 (setq comment nil)
|
|
2243 ;; Make the comment invisible by hand if it's empty
|
|
2244 (set-extent-property (widget-get comment-widget :comment-extent)
|
|
2245 'invisible t))
|
|
2246 (put symbol
|
|
2247 'saved-value (list (custom-quote (widget-value
|
|
2248 child))))
|
|
2249 (custom-push-theme 'theme-value symbol 'user
|
|
2250 'set (list (custom-quote (widget-value
|
480
|
2251 child))))
|
428
|
2252 (funcall set symbol (widget-value child))
|
|
2253 (put symbol 'variable-comment comment)
|
|
2254 (put symbol 'saved-variable-comment comment)))
|
|
2255 (put symbol 'customized-value nil)
|
|
2256 (put symbol 'customized-variable-comment nil)
|
480
|
2257 ))
|
|
2258
|
|
2259 (defun custom-variable-post-save (widget)
|
|
2260 "Finish saving the variable being edited by WIDGET."
|
|
2261 (custom-variable-state-set widget)
|
|
2262 (custom-redraw-magic widget))
|
|
2263
|
|
2264 (defun custom-variable-save (widget)
|
|
2265 "Set and save the value for the variable being edited by WIDGET."
|
|
2266 (custom-variable-pre-save widget)
|
|
2267 (custom-save-all)
|
|
2268 (custom-variable-post-save widget))
|
428
|
2269
|
|
2270 (defun custom-variable-reset-saved (widget)
|
|
2271 "Restore the saved value for the variable being edited by WIDGET."
|
|
2272 (let* ((symbol (widget-value widget))
|
|
2273 (set (or (get symbol 'custom-set) 'set-default))
|
|
2274 (value (get symbol 'saved-value))
|
|
2275 (comment (get symbol 'saved-variable-comment)))
|
|
2276 (cond ((or value comment)
|
|
2277 (put symbol 'variable-comment comment)
|
|
2278 (condition-case nil
|
|
2279 (funcall set symbol (eval (car value)))
|
|
2280 (error nil)))
|
|
2281 (t
|
|
2282 (signal 'error (list "No saved value for variable" symbol))))
|
|
2283 (put symbol 'customized-value nil)
|
|
2284 (put symbol 'customized-variable-comment nil)
|
|
2285 (widget-put widget :custom-state 'unknown)
|
|
2286 ;; This call will possibly make the comment invisible
|
|
2287 (custom-redraw widget)))
|
|
2288
|
480
|
2289 ;; This function returns non nil if we need to re-save the options --dv.
|
|
2290 (defun custom-variable-pre-reset-standard (widget)
|
|
2291 "Prepare for restoring the variable being edited by WIDGET to its
|
|
2292 standard setting."
|
428
|
2293 (let* ((symbol (widget-value widget))
|
442
|
2294 (set (or (get symbol 'custom-set) 'set-default)))
|
428
|
2295 (if (get symbol 'standard-value)
|
|
2296 (funcall set symbol (eval (car (get symbol 'standard-value))))
|
|
2297 (signal 'error (list "No standard setting known for variable" symbol)))
|
|
2298 (put symbol 'variable-comment nil)
|
|
2299 (put symbol 'customized-value nil)
|
|
2300 (put symbol 'customized-variable-comment nil)
|
|
2301 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
|
|
2302 (put symbol 'saved-value nil)
|
|
2303 (custom-push-theme 'theme-value symbol 'user 'reset 'standard)
|
|
2304 ;; As a special optimizations we do not (explictly)
|
480
|
2305 ;; save resets to standard when no theme sets the value.
|
428
|
2306 (if (null (cdr (get symbol 'theme-value)))
|
|
2307 (put symbol 'theme-value nil))
|
|
2308 (put symbol 'saved-variable-comment nil)
|
480
|
2309 widget)
|
|
2310 ))
|
|
2311
|
|
2312 (defun custom-variable-post-reset-standard (widget)
|
|
2313 "Finish resetting the variable being edited by WIDGET to its standard
|
|
2314 value."
|
|
2315 (widget-put widget :custom-state 'unknown)
|
|
2316 ;; This call will possibly make the comment invisible
|
|
2317 (custom-redraw widget))
|
|
2318
|
|
2319 (defun custom-variable-reset-standard (widget)
|
|
2320 "Restore the standard setting for the variable being edited by WIDGET."
|
|
2321 (when (custom-variable-pre-reset-standard widget)
|
|
2322 (custom-save-all))
|
|
2323 (custom-variable-post-reset-standard widget))
|
|
2324
|
428
|
2325
|
|
2326 ;;; The `custom-face-edit' Widget.
|
|
2327
|
|
2328 (define-widget 'custom-face-edit 'checklist
|
|
2329 "Edit face attributes."
|
|
2330 :format "%t: %v"
|
|
2331 :tag "Attributes"
|
|
2332 :extra-offset 12
|
438
|
2333 :button-args '(:help-echo "Control whether this attribute has any effect")
|
428
|
2334 :args (mapcar (lambda (att)
|
|
2335 (list 'group
|
|
2336 :inline t
|
|
2337 :sibling-args (widget-get (nth 1 att) :sibling-args)
|
|
2338 (list 'const :format "" :value (nth 0 att))
|
|
2339 (nth 1 att)))
|
|
2340 custom-face-attributes))
|
|
2341
|
|
2342 ;;; The `custom-display' Widget.
|
|
2343
|
|
2344 (define-widget 'custom-display 'menu-choice
|
|
2345 "Select a display type."
|
|
2346 :tag "Display"
|
|
2347 :value t
|
|
2348 :help-echo "Specify frames where the face attributes should be used"
|
|
2349 :args '((const :tag "all" t)
|
|
2350 (checklist
|
|
2351 :offset 0
|
|
2352 :extra-offset 9
|
|
2353 :args ((group :sibling-args (:help-echo "\
|
|
2354 Only match the specified window systems")
|
|
2355 (const :format "Type: "
|
|
2356 type)
|
|
2357 (checklist :inline t
|
|
2358 :offset 0
|
|
2359 (const :format "X "
|
|
2360 :sibling-args (:help-echo "\
|
|
2361 The X11 Window System")
|
|
2362 x)
|
555
|
2363 (const :format "GTK "
|
|
2364 :sibling-args (:help-echo "\
|
|
2365 The GTK Window System")
|
|
2366 gtk)
|
428
|
2367 (const :format "PM "
|
|
2368 :sibling-args (:help-echo "\
|
|
2369 OS/2 Presentation Manager")
|
|
2370 pm)
|
|
2371 (const :format "MSWindows "
|
|
2372 :sibling-args (:help-echo "\
|
440
|
2373 Microsoft Windows, displays")
|
428
|
2374 mswindows)
|
440
|
2375 (const :format "MSPrinter "
|
428
|
2376 :sibling-args (:help-echo "\
|
440
|
2377 Microsoft Windows, printers")
|
|
2378 msprinter)
|
428
|
2379 (const :format "TTY%n"
|
|
2380 :sibling-args (:help-echo "\
|
|
2381 Plain text terminals")
|
|
2382 tty)))
|
|
2383 (group :sibling-args (:help-echo "\
|
440
|
2384 Only match display or printer devices")
|
|
2385 (const :format "Output: "
|
|
2386 class)
|
|
2387 (checklist :inline t
|
|
2388 :offset 0
|
|
2389 (const :format "Display "
|
|
2390 :sibling-args (:help-echo "\
|
|
2391 Match display devices")
|
|
2392 display)
|
|
2393 (const :format "Printer%n"
|
|
2394 :sibling-args (:help-echo "\
|
|
2395 Match printer devices")
|
|
2396 printer)))
|
|
2397 (group :sibling-args (:help-echo "\
|
428
|
2398 Only match the frames with the specified color support")
|
440
|
2399 (const :format "Color support: "
|
428
|
2400 class)
|
|
2401 (checklist :inline t
|
|
2402 :offset 0
|
|
2403 (const :format "Color "
|
|
2404 :sibling-args (:help-echo "\
|
|
2405 Match color frames")
|
|
2406 color)
|
|
2407 (const :format "Grayscale "
|
|
2408 :sibling-args (:help-echo "\
|
|
2409 Match grayscale frames")
|
|
2410 grayscale)
|
|
2411 (const :format "Monochrome%n"
|
|
2412 :sibling-args (:help-echo "\
|
|
2413 Match frames with no color support")
|
|
2414 mono)))
|
|
2415 (group :sibling-args (:help-echo "\
|
|
2416 Only match frames with the specified intensity")
|
|
2417 (const :format "\
|
|
2418 Background brightness: "
|
|
2419 background)
|
|
2420 (checklist :inline t
|
|
2421 :offset 0
|
|
2422 (const :format "Light "
|
|
2423 :sibling-args (:help-echo "\
|
|
2424 Match frames with light backgrounds")
|
|
2425 light)
|
|
2426 (const :format "Dark\n"
|
|
2427 :sibling-args (:help-echo "\
|
|
2428 Match frames with dark backgrounds")
|
|
2429 dark)))))))
|
|
2430
|
|
2431 ;;; The `custom-face' Widget.
|
|
2432
|
|
2433 (defface custom-face-tag-face '((t (:underline t)))
|
|
2434 "Face used for face tags."
|
|
2435 :group 'custom-faces)
|
|
2436
|
|
2437 (defcustom custom-face-default-form 'selected
|
|
2438 "Default form of displaying face definition."
|
|
2439 :type '(choice (const all)
|
|
2440 (const selected)
|
|
2441 (const lisp))
|
|
2442 :group 'custom-buffer)
|
|
2443
|
|
2444 (define-widget 'custom-face 'custom
|
|
2445 "Customize face."
|
|
2446 :sample-face 'custom-face-tag-face
|
|
2447 :help-echo "Set or reset this face"
|
|
2448 :documentation-property '(lambda (face)
|
|
2449 (face-doc-string face))
|
|
2450 :value-create 'custom-face-value-create
|
|
2451 :action 'custom-face-action
|
|
2452 :custom-category 'face
|
|
2453 :custom-form nil ; defaults to value of `custom-face-default-form'
|
|
2454 :custom-set 'custom-face-set
|
480
|
2455 :custom-pre-save 'custom-face-pre-save
|
428
|
2456 :custom-save 'custom-face-save
|
480
|
2457 :custom-post-save 'custom-face-post-save
|
428
|
2458 :custom-reset-current 'custom-redraw
|
|
2459 :custom-reset-saved 'custom-face-reset-saved
|
480
|
2460 :custom-pre-reset-standard 'custom-face-pre-reset-standard
|
428
|
2461 :custom-reset-standard 'custom-face-reset-standard
|
480
|
2462 :custom-post-reset-standard 'custom-face-post-reset-standard
|
428
|
2463 :custom-menu 'custom-face-menu-create)
|
|
2464
|
|
2465 (define-widget 'custom-face-all 'editable-list
|
|
2466 "An editable list of display specifications and attributes."
|
|
2467 :entry-format "%i %d %v"
|
|
2468 :insert-button-args '(:help-echo "Insert new display specification here")
|
|
2469 :append-button-args '(:help-echo "Append new display specification here")
|
|
2470 :delete-button-args '(:help-echo "Delete this display specification")
|
|
2471 :args '((group :format "%v" custom-display custom-face-edit)))
|
|
2472
|
|
2473 (defconst custom-face-all (widget-convert 'custom-face-all)
|
|
2474 "Converted version of the `custom-face-all' widget.")
|
|
2475
|
|
2476 (define-widget 'custom-display-unselected 'item
|
|
2477 "A display specification that doesn't match the selected display."
|
|
2478 :match 'custom-display-unselected-match)
|
|
2479
|
|
2480 (defun custom-display-unselected-match (widget value)
|
|
2481 "Non-nil if VALUE is an unselected display specification."
|
|
2482 (not (face-spec-set-match-display value (selected-frame))))
|
|
2483
|
|
2484 (define-widget 'custom-face-selected 'group
|
|
2485 "Edit the attributes of the selected display in a face specification."
|
|
2486 :args '((repeat :format ""
|
|
2487 :inline t
|
|
2488 (group custom-display-unselected sexp))
|
|
2489 (group (sexp :format "") custom-face-edit)
|
|
2490 (repeat :format ""
|
|
2491 :inline t
|
|
2492 sexp)))
|
|
2493
|
|
2494 (defconst custom-face-selected (widget-convert 'custom-face-selected)
|
|
2495 "Converted version of the `custom-face-selected' widget.")
|
|
2496
|
|
2497 (defun custom-face-value-create (widget)
|
|
2498 "Create a list of the display specifications for WIDGET."
|
|
2499 (let ((buttons (widget-get widget :buttons))
|
|
2500 children
|
|
2501 (symbol (widget-get widget :value))
|
|
2502 (tag (widget-get widget :tag))
|
|
2503 (state (widget-get widget :custom-state))
|
|
2504 (begin (point))
|
|
2505 (is-last (widget-get widget :custom-last))
|
|
2506 (prefix (widget-get widget :custom-prefix)))
|
|
2507 (unless tag
|
|
2508 (setq tag (prin1-to-string symbol)))
|
|
2509 (cond ((eq custom-buffer-style 'tree)
|
|
2510 (insert prefix (if is-last " `--- " " |--- "))
|
|
2511 (push (widget-create-child-and-convert
|
|
2512 widget 'custom-browse-face-tag)
|
|
2513 buttons)
|
|
2514 (insert " " tag "\n")
|
|
2515 (widget-put widget :buttons buttons))
|
|
2516 (t
|
|
2517 ;; Create tag.
|
|
2518 (insert tag)
|
|
2519 (if (eq custom-buffer-style 'face)
|
|
2520 (insert " ")
|
|
2521 (widget-specify-sample widget begin (point))
|
|
2522 (insert ": "))
|
|
2523 ;; Sample.
|
|
2524 (and (not (find-face symbol))
|
|
2525 ;; XEmacs cannot display uninitialized faces.
|
|
2526 (make-face symbol))
|
|
2527 (push (widget-create-child-and-convert widget 'item
|
|
2528 :format "(%{%t%})"
|
|
2529 :sample-face symbol
|
|
2530 :tag "sample")
|
|
2531 buttons)
|
|
2532 ;; Visibility.
|
|
2533 (insert " ")
|
|
2534 (push (widget-create-child-and-convert
|
|
2535 widget 'visibility
|
|
2536 :help-echo "Hide or show this face"
|
|
2537 :action 'custom-toggle-parent
|
|
2538 (not (eq state 'hidden)))
|
|
2539 buttons)
|
|
2540 ;; Magic.
|
|
2541 (insert "\n")
|
|
2542 (let ((magic (widget-create-child-and-convert
|
|
2543 widget 'custom-magic nil)))
|
|
2544 (widget-put widget :custom-magic magic)
|
|
2545 (push magic buttons))
|
|
2546 ;; Update buttons.
|
|
2547 (widget-put widget :buttons buttons)
|
|
2548 ;; Insert documentation.
|
|
2549 (widget-default-format-handler widget ?h)
|
|
2550 ;; The comment field
|
|
2551 (unless (eq state 'hidden)
|
|
2552 (let* ((comment (get symbol 'face-comment))
|
|
2553 (comment-widget
|
|
2554 (widget-create-child-and-convert
|
|
2555 widget 'custom-comment
|
|
2556 :parent widget
|
|
2557 :value (or comment ""))))
|
|
2558 (widget-put widget :comment-widget comment-widget)
|
|
2559 (push comment-widget children)))
|
|
2560 ;; See also.
|
|
2561 (unless (eq state 'hidden)
|
|
2562 (when (eq (widget-get widget :custom-level) 1)
|
|
2563 (custom-add-parent-links widget))
|
|
2564 (custom-add-see-also widget))
|
|
2565 ;; Editor.
|
|
2566 (unless (eq (preceding-char) ?\n)
|
|
2567 (insert "\n"))
|
|
2568 (unless (eq state 'hidden)
|
|
2569 (message "Creating face editor...")
|
|
2570 (custom-load-widget widget)
|
|
2571 (unless (widget-get widget :custom-form)
|
|
2572 (widget-put widget :custom-form custom-face-default-form))
|
|
2573 (let* ((symbol (widget-value widget))
|
|
2574 (spec (custom-face-get-spec symbol))
|
|
2575 (form (widget-get widget :custom-form))
|
|
2576 (indent (widget-get widget :indent))
|
|
2577 (edit (widget-create-child-and-convert
|
|
2578 widget
|
|
2579 (cond ((and (eq form 'selected)
|
|
2580 (widget-apply custom-face-selected
|
|
2581 :match spec))
|
|
2582 (when indent (insert-char ?\ indent))
|
|
2583 'custom-face-selected)
|
|
2584 ((and (not (eq form 'lisp))
|
|
2585 (widget-apply custom-face-all
|
|
2586 :match spec))
|
|
2587 'custom-face-all)
|
|
2588 (t
|
|
2589 (when indent (insert-char ?\ indent))
|
|
2590 'sexp))
|
|
2591 :value spec)))
|
|
2592 (custom-face-state-set widget)
|
|
2593 (push edit children)
|
|
2594 (widget-put widget :children children))
|
|
2595 (message "Creating face editor...done"))))))
|
|
2596
|
|
2597 (defvar custom-face-menu
|
|
2598 '(("Set for Current Session" custom-face-set)
|
|
2599 ("Save for Future Sessions" custom-face-save)
|
|
2600 ("Reset to Saved" custom-face-reset-saved
|
|
2601 (lambda (widget)
|
|
2602 (or (get (widget-value widget) 'saved-face)
|
|
2603 (get (widget-value widget) 'saved-face-comment))))
|
|
2604 ("Reset to Standard Setting" custom-face-reset-standard
|
|
2605 (lambda (widget)
|
|
2606 (get (widget-value widget) 'face-defface-spec)))
|
|
2607 ("---" ignore ignore)
|
|
2608 ("Add Comment" custom-comment-show custom-comment-invisible-p)
|
|
2609 ("---" ignore ignore)
|
|
2610 ("Show all display specs" custom-face-edit-all
|
|
2611 (lambda (widget)
|
|
2612 (not (eq (widget-get widget :custom-form) 'all))))
|
|
2613 ("Just current attributes" custom-face-edit-selected
|
|
2614 (lambda (widget)
|
|
2615 (not (eq (widget-get widget :custom-form) 'selected))))
|
|
2616 ("Show as Lisp expression" custom-face-edit-lisp
|
|
2617 (lambda (widget)
|
|
2618 (not (eq (widget-get widget :custom-form) 'lisp)))))
|
|
2619 "Alist of actions for the `custom-face' widget.
|
|
2620 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
2621 the menu entry, ACTION is the function to call on the widget when the
|
|
2622 menu is selected, and FILTER is a predicate which takes a `custom-face'
|
|
2623 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
2624 widget. If FILTER is nil, ACTION is always valid.")
|
|
2625
|
|
2626 (defun custom-face-edit-selected (widget)
|
|
2627 "Edit selected attributes of the value of WIDGET."
|
|
2628 (widget-put widget :custom-state 'unknown)
|
|
2629 (widget-put widget :custom-form 'selected)
|
|
2630 (custom-redraw widget))
|
|
2631
|
|
2632 (defun custom-face-edit-all (widget)
|
|
2633 "Edit all attributes of the value of WIDGET."
|
|
2634 (widget-put widget :custom-state 'unknown)
|
|
2635 (widget-put widget :custom-form 'all)
|
|
2636 (custom-redraw widget))
|
|
2637
|
|
2638 (defun custom-face-edit-lisp (widget)
|
|
2639 "Edit the lisp representation of the value of WIDGET."
|
|
2640 (widget-put widget :custom-state 'unknown)
|
|
2641 (widget-put widget :custom-form 'lisp)
|
|
2642 (custom-redraw widget))
|
|
2643
|
|
2644 (defun custom-face-state-set (widget)
|
|
2645 "Set the state of WIDGET."
|
|
2646 (let* ((symbol (widget-value widget))
|
|
2647 (comment (get symbol 'face-comment))
|
|
2648 tmp temp)
|
|
2649 (widget-put widget :custom-state
|
|
2650 (cond ((progn
|
|
2651 (setq tmp (get symbol 'customized-face))
|
|
2652 (setq temp (get symbol 'customized-face-comment))
|
|
2653 (or tmp temp))
|
|
2654 (if (equal temp comment)
|
|
2655 'set
|
|
2656 'changed))
|
|
2657 ((progn
|
|
2658 (setq tmp (get symbol 'saved-face))
|
|
2659 (setq temp (get symbol 'saved-face-comment))
|
|
2660 (or tmp temp))
|
|
2661 (if (equal temp comment)
|
|
2662 'saved
|
|
2663 'changed))
|
|
2664 ((get symbol 'face-defface-spec)
|
|
2665 (if (equal comment nil)
|
|
2666 'standard
|
|
2667 'changed))
|
|
2668 (t
|
|
2669 'rogue)))))
|
|
2670
|
|
2671 (defun custom-face-action (widget &optional event)
|
|
2672 "Show the menu for `custom-face' WIDGET.
|
|
2673 Optional EVENT is the location for the menu."
|
|
2674 (if (eq (widget-get widget :custom-state) 'hidden)
|
|
2675 (custom-toggle-hide widget)
|
|
2676 (let* ((completion-ignore-case t)
|
|
2677 (symbol (widget-get widget :value))
|
|
2678 (answer (widget-choose (concat "Operation on "
|
|
2679 (custom-unlispify-tag-name symbol))
|
|
2680 (custom-menu-filter custom-face-menu
|
|
2681 widget)
|
|
2682 event)))
|
|
2683 (if answer
|
|
2684 (funcall answer widget)))))
|
|
2685
|
|
2686 (defun custom-face-set (widget)
|
|
2687 "Make the face attributes in WIDGET take effect."
|
|
2688 (let* ((symbol (widget-value widget))
|
|
2689 (child (car (widget-get widget :children)))
|
|
2690 (value (widget-value child))
|
|
2691 (comment-widget (widget-get widget :comment-widget))
|
|
2692 (comment (widget-value comment-widget)))
|
|
2693 (when (equal comment "")
|
|
2694 (setq comment nil)
|
|
2695 ;; Make the comment invisible by hand if it's empty
|
|
2696 (set-extent-property (widget-get comment-widget :comment-extent)
|
|
2697 'invisible t))
|
|
2698 (put symbol 'customized-face value)
|
|
2699 (face-spec-set symbol value nil '(custom))
|
|
2700 (put symbol 'customized-face-comment comment)
|
|
2701 (put symbol 'face-comment comment)
|
|
2702 (custom-face-state-set widget)
|
|
2703 (custom-redraw-magic widget)))
|
|
2704
|
480
|
2705 (defun custom-face-pre-save (widget)
|
|
2706 "Prepare for saving the face being edited by WIDGET."
|
428
|
2707 (let* ((symbol (widget-value widget))
|
|
2708 (child (car (widget-get widget :children)))
|
|
2709 (value (widget-value child))
|
|
2710 (comment-widget (widget-get widget :comment-widget))
|
|
2711 (comment (widget-value comment-widget)))
|
|
2712 (when (equal comment "")
|
|
2713 (setq comment nil)
|
|
2714 ;; Make the comment invisible by hand if it's empty
|
|
2715 (set-extent-property (widget-get comment-widget :comment-extent)
|
|
2716 'invisible t))
|
|
2717 (face-spec-set symbol value nil '(custom))
|
|
2718 (put symbol 'saved-face value)
|
|
2719 (custom-push-theme 'theme-face symbol 'user 'set value)
|
|
2720 (put symbol 'customized-face nil)
|
|
2721 (put symbol 'face-comment comment)
|
|
2722 (put symbol 'customized-face-comment nil)
|
|
2723 (put symbol 'saved-face-comment comment)
|
480
|
2724 ))
|
|
2725
|
|
2726 (defun custom-face-post-save (widget)
|
|
2727 "Finish saving the face being edited by WIDGET."
|
|
2728 (custom-face-state-set widget)
|
|
2729 (custom-redraw-magic widget))
|
|
2730
|
|
2731 (defun custom-face-save (widget)
|
|
2732 "Save the face being edited by WIDGET."
|
|
2733 (custom-face-pre-save widget)
|
|
2734 (custom-save-all)
|
|
2735 (custom-face-post-save widget))
|
428
|
2736
|
|
2737 (defun custom-face-reset-saved (widget)
|
480
|
2738 "Reset the face being edited by WIDGET to its saved value."
|
428
|
2739 (let* ((symbol (widget-value widget))
|
|
2740 (child (car (widget-get widget :children)))
|
|
2741 (value (get symbol 'saved-face))
|
|
2742 (comment (get symbol 'saved-face-comment))
|
|
2743 (comment-widget (widget-get widget :comment-widget)))
|
|
2744 (unless (or value comment)
|
|
2745 (signal 'error (list "No saved value for this face" symbol)))
|
|
2746 (put symbol 'customized-face nil)
|
|
2747 (put symbol 'customized-face-comment nil)
|
|
2748 (face-spec-set symbol value nil '(custom))
|
|
2749 (put symbol 'face-comment comment)
|
|
2750 (widget-value-set child value)
|
|
2751 ;; This call manages the comment visibility
|
|
2752 (widget-value-set comment-widget (or comment ""))
|
|
2753 (custom-face-state-set widget)
|
|
2754 (custom-redraw-magic widget)))
|
|
2755
|
480
|
2756 ;; This function returns non nil if we need to re-save the options --dv.
|
|
2757 (defun custom-face-pre-reset-standard (widget)
|
|
2758 "Prepare for restoring the face edited by WIDGET to its standard
|
|
2759 settings."
|
428
|
2760 (let* ((symbol (widget-value widget))
|
480
|
2761 (value (get symbol 'face-defface-spec)))
|
428
|
2762 (unless value
|
|
2763 (signal 'error (list "No standard setting for this face" symbol)))
|
|
2764 (put symbol 'customized-face nil)
|
|
2765 (put symbol 'customized-face-comment nil)
|
|
2766 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
|
|
2767 (put symbol 'saved-face nil)
|
|
2768 (custom-push-theme 'theme-face symbol 'user 'reset 'standard)
|
|
2769 ;; Do not explictly save resets to standards without themes.
|
|
2770 (if (null (cdr (get symbol 'theme-face)))
|
|
2771 (put symbol 'theme-face nil))
|
|
2772 (put symbol 'saved-face-comment nil)
|
480
|
2773 widget)
|
|
2774 ))
|
|
2775
|
|
2776 (defun custom-face-post-reset-standard (widget)
|
|
2777 "Finish restoring the face edited by WIDGET to its standard settings."
|
|
2778 (let* ((symbol (widget-value widget))
|
|
2779 (child (car (widget-get widget :children)))
|
|
2780 (value (get symbol 'face-defface-spec))
|
|
2781 (comment-widget (widget-get widget :comment-widget)))
|
428
|
2782 (face-spec-set symbol value nil '(custom))
|
|
2783 (put symbol 'face-comment nil)
|
|
2784 (widget-value-set child value)
|
|
2785 ;; This call manages the comment visibility
|
|
2786 (widget-value-set comment-widget "")
|
|
2787 (custom-face-state-set widget)
|
480
|
2788 (custom-redraw-magic widget)
|
|
2789 ))
|
|
2790
|
|
2791 (defun custom-face-reset-standard (widget)
|
|
2792 "Restore the face edited by WIDGET to its standard settings."
|
|
2793 (when (custom-face-pre-reset-standard widget)
|
|
2794 (custom-save-all))
|
|
2795 (custom-face-post-reset-standard widget))
|
|
2796
|
428
|
2797
|
|
2798 ;;; The `face' Widget.
|
|
2799
|
|
2800 (define-widget 'face 'default
|
|
2801 "Select and customize a face."
|
|
2802 :convert-widget 'widget-value-convert-widget
|
|
2803 :button-prefix 'widget-push-button-prefix
|
|
2804 :button-suffix 'widget-push-button-suffix
|
|
2805 :format "%t: %[select face%] %v"
|
|
2806 :tag "Face"
|
|
2807 :value 'default
|
|
2808 :value-create 'widget-face-value-create
|
|
2809 :value-delete 'widget-face-value-delete
|
|
2810 :value-get 'widget-value-value-get
|
|
2811 :validate 'widget-children-validate
|
|
2812 :action 'widget-face-action
|
|
2813 :match (lambda (widget value) (symbolp value)))
|
|
2814
|
|
2815 (defun widget-face-value-create (widget)
|
|
2816 ;; Create a `custom-face' child.
|
|
2817 (let* ((symbol (widget-value widget))
|
|
2818 (custom-buffer-style 'face)
|
|
2819 (child (widget-create-child-and-convert
|
|
2820 widget 'custom-face
|
|
2821 :custom-level nil
|
|
2822 :value symbol)))
|
|
2823 (custom-magic-reset child)
|
|
2824 (setq custom-options (cons child custom-options))
|
|
2825 (widget-put widget :children (list child))))
|
|
2826
|
|
2827 (defun widget-face-value-delete (widget)
|
|
2828 ;; Remove the child from the options.
|
|
2829 (let ((child (car (widget-get widget :children))))
|
|
2830 (setq custom-options (delq child custom-options))
|
|
2831 (widget-children-value-delete widget)))
|
|
2832
|
|
2833 (defvar face-history nil
|
|
2834 "History of entered face names.")
|
|
2835
|
|
2836 (defun widget-face-action (widget &optional event)
|
|
2837 "Prompt for a face."
|
|
2838 (let ((answer (completing-read "Face: "
|
|
2839 (mapcar (lambda (face)
|
|
2840 (list (symbol-name face)))
|
|
2841 (face-list))
|
|
2842 nil nil nil
|
|
2843 'face-history)))
|
|
2844 (unless (zerop (length answer))
|
|
2845 (widget-value-set widget (intern answer))
|
|
2846 (widget-apply widget :notify widget event)
|
|
2847 (widget-setup))))
|
|
2848
|
|
2849 ;;; The `hook' Widget.
|
|
2850
|
|
2851 (define-widget 'hook 'list
|
|
2852 "A emacs lisp hook"
|
|
2853 :value-to-internal (lambda (widget value)
|
|
2854 (if (symbolp value)
|
|
2855 (list value)
|
|
2856 value))
|
|
2857 :match (lambda (widget value)
|
|
2858 (or (symbolp value)
|
|
2859 (widget-group-match widget value)))
|
|
2860 :convert-widget 'custom-hook-convert-widget
|
|
2861 :tag "Hook")
|
|
2862
|
|
2863 (defun custom-hook-convert-widget (widget)
|
438
|
2864 ;; Handle `:options'.
|
428
|
2865 (let* ((options (widget-get widget :options))
|
|
2866 (other `(editable-list :inline t
|
|
2867 :entry-format "%i %d%v"
|
|
2868 (function :format " %v")))
|
|
2869 (args (if options
|
|
2870 (list `(checklist :inline t
|
|
2871 ,@(mapcar (lambda (entry)
|
|
2872 `(function-item ,entry))
|
|
2873 options))
|
|
2874 other)
|
|
2875 (list other))))
|
|
2876 (widget-put widget :args args)
|
|
2877 widget))
|
|
2878
|
|
2879 ;;; The `plist' Widget.
|
|
2880
|
|
2881 (define-widget 'plist 'list
|
|
2882 "A property list."
|
|
2883 :match (lambda (widget value)
|
|
2884 (valid-plist-p value))
|
|
2885 :convert-widget 'custom-plist-convert-widget
|
|
2886 :tag "Property List")
|
|
2887
|
|
2888 ;; #### Should handle options better.
|
|
2889 (defun custom-plist-convert-widget (widget)
|
|
2890 (let* ((options (widget-get widget :options))
|
|
2891 (other `(editable-list :inline t
|
|
2892 (group :inline t
|
|
2893 (symbol :format "%t: %v "
|
|
2894 :size 10
|
|
2895 :tag "Property")
|
|
2896 (sexp :tag "Value"))))
|
|
2897 (args
|
|
2898 (if options
|
|
2899 `((checklist :inline t
|
|
2900 ,@(mapcar 'custom-plist-process-option options))
|
|
2901 ,other)
|
|
2902 (list other))))
|
|
2903 (widget-put widget :args args)
|
|
2904 widget))
|
|
2905
|
|
2906 (defun custom-plist-process-option (entry)
|
|
2907 `(group :inline t
|
|
2908 (const :tag "Property"
|
|
2909 :format "%t: %v "
|
|
2910 :size 10
|
|
2911 ,entry)
|
|
2912 (sexp :tag "Value")))
|
|
2913
|
|
2914 ;;; The `custom-group-link' Widget.
|
|
2915
|
|
2916 (define-widget 'custom-group-link 'link
|
|
2917 "Show parent in other window when activated."
|
|
2918 :help-echo 'custom-group-link-help-echo
|
|
2919 :action 'custom-group-link-action)
|
|
2920
|
|
2921 (defun custom-group-link-help-echo (widget)
|
|
2922 (concat "Create customization buffer for the `"
|
|
2923 (custom-unlispify-tag-name (widget-value widget))
|
|
2924 "' group"))
|
|
2925
|
|
2926 (defun custom-group-link-action (widget &rest ignore)
|
|
2927 (customize-group (widget-value widget)))
|
|
2928
|
|
2929 ;;; The `custom-group' Widget.
|
|
2930
|
|
2931 (defcustom custom-group-tag-faces nil
|
|
2932 ;; In XEmacs, this ought to play games with font size.
|
|
2933 "Face used for group tags.
|
|
2934 The first member is used for level 1 groups, the second for level 2,
|
|
2935 and so forth. The remaining group tags are shown with
|
|
2936 `custom-group-tag-face'."
|
|
2937 :type '(repeat face)
|
|
2938 :group 'custom-faces)
|
|
2939
|
|
2940 (defface custom-group-tag-face-1 '((((class color)
|
|
2941 (background dark))
|
|
2942 (:foreground "pink" :underline t))
|
|
2943 (((class color)
|
|
2944 (background light))
|
|
2945 (:foreground "red" :underline t))
|
|
2946 (t (:underline t)))
|
|
2947 "Face used for group tags.")
|
|
2948
|
|
2949 (defface custom-group-tag-face '((((class color)
|
|
2950 (background dark))
|
|
2951 (:foreground "light blue" :underline t))
|
|
2952 (((class color)
|
|
2953 (background light))
|
|
2954 (:foreground "blue" :underline t))
|
|
2955 (t (:underline t)))
|
|
2956 "Face used for low level group tags."
|
|
2957 :group 'custom-faces)
|
|
2958
|
|
2959 (define-widget 'custom-group 'custom
|
|
2960 "Customize group."
|
|
2961 :format "%v"
|
|
2962 :sample-face-get 'custom-group-sample-face-get
|
|
2963 :documentation-property 'group-documentation
|
|
2964 :help-echo "Set or reset all members of this group"
|
|
2965 :value-create 'custom-group-value-create
|
|
2966 :action 'custom-group-action
|
|
2967 :custom-category 'group
|
|
2968 :custom-set 'custom-group-set
|
480
|
2969 :custom-pre-save 'custom-group-pre-save
|
428
|
2970 :custom-save 'custom-group-save
|
480
|
2971 :custom-post-save 'custom-group-post-save
|
428
|
2972 :custom-reset-current 'custom-group-reset-current
|
|
2973 :custom-reset-saved 'custom-group-reset-saved
|
480
|
2974 :custom-pre-reset-standard 'custom-group-pre-reset-standard
|
428
|
2975 :custom-reset-standard 'custom-group-reset-standard
|
480
|
2976 :custom-post-reset-standard 'custom-group-post-reset-standard
|
428
|
2977 :custom-menu 'custom-group-menu-create)
|
|
2978
|
|
2979 (defun custom-group-sample-face-get (widget)
|
|
2980 ;; Use :sample-face.
|
|
2981 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
|
|
2982 'custom-group-tag-face))
|
|
2983
|
|
2984 (define-widget 'custom-group-visibility 'visibility
|
|
2985 "An indicator and manipulator for hidden group contents."
|
|
2986 :create 'custom-group-visibility-create)
|
|
2987
|
|
2988 (defun custom-group-visibility-create (widget)
|
|
2989 (let ((visible (widget-value widget)))
|
|
2990 (if visible
|
|
2991 (insert "--------")))
|
|
2992 (widget-default-create widget))
|
|
2993
|
|
2994 (defun custom-group-members (symbol groups-only)
|
|
2995 "Return SYMBOL's custom group members.
|
|
2996 If GROUPS-ONLY non-nil, return only those members that are groups."
|
|
2997 (if (not groups-only)
|
|
2998 (get symbol 'custom-group)
|
|
2999 (let (members)
|
|
3000 (dolist (entry (get symbol 'custom-group) (nreverse members))
|
|
3001 (when (eq (nth 1 entry) 'custom-group)
|
|
3002 (push entry members))))))
|
|
3003
|
|
3004 (defun custom-group-value-create (widget)
|
|
3005 "Insert a customize group for WIDGET in the current buffer."
|
|
3006 (let* ((state (widget-get widget :custom-state))
|
|
3007 (level (widget-get widget :custom-level))
|
|
3008 ;; (indent (widget-get widget :indent))
|
|
3009 (prefix (widget-get widget :custom-prefix))
|
|
3010 (buttons (widget-get widget :buttons))
|
|
3011 (tag (widget-get widget :tag))
|
|
3012 (symbol (widget-value widget))
|
|
3013 (members (custom-group-members symbol
|
|
3014 (and (eq custom-buffer-style 'tree)
|
|
3015 custom-browse-only-groups))))
|
|
3016 (cond ((and (eq custom-buffer-style 'tree)
|
|
3017 (eq state 'hidden)
|
|
3018 (or members (custom-unloaded-widget-p widget)))
|
|
3019 (custom-browse-insert-prefix prefix)
|
|
3020 (push (widget-create-child-and-convert
|
|
3021 widget 'custom-browse-visibility
|
|
3022 ;; :tag-glyph "plus"
|
|
3023 :tag "+")
|
|
3024 buttons)
|
|
3025 (insert "-- ")
|
|
3026 ;; (widget-glyph-insert nil "-- " "horizontal")
|
|
3027 (push (widget-create-child-and-convert
|
|
3028 widget 'custom-browse-group-tag)
|
|
3029 buttons)
|
|
3030 (insert " " tag "\n")
|
|
3031 (widget-put widget :buttons buttons))
|
|
3032 ((and (eq custom-buffer-style 'tree)
|
|
3033 (zerop (length members)))
|
|
3034 (custom-browse-insert-prefix prefix)
|
|
3035 (insert "[ ]-- ")
|
|
3036 ;; (widget-glyph-insert nil "[ ]" "empty")
|
|
3037 ;; (widget-glyph-insert nil "-- " "horizontal")
|
|
3038 (push (widget-create-child-and-convert
|
|
3039 widget 'custom-browse-group-tag)
|
|
3040 buttons)
|
|
3041 (insert " " tag "\n")
|
|
3042 (widget-put widget :buttons buttons))
|
|
3043 ((eq custom-buffer-style 'tree)
|
|
3044 (custom-browse-insert-prefix prefix)
|
|
3045 (custom-load-widget widget)
|
|
3046 (if (zerop (length members))
|
|
3047 (progn
|
|
3048 (custom-browse-insert-prefix prefix)
|
|
3049 (insert "[ ]-- ")
|
|
3050 ;; (widget-glyph-insert nil "[ ]" "empty")
|
|
3051 ;; (widget-glyph-insert nil "-- " "horizontal")
|
|
3052 (push (widget-create-child-and-convert
|
|
3053 widget 'custom-browse-group-tag)
|
|
3054 buttons)
|
|
3055 (insert " " tag "\n")
|
|
3056 (widget-put widget :buttons buttons))
|
|
3057 (push (widget-create-child-and-convert
|
|
3058 widget 'custom-browse-visibility
|
|
3059 ;; :tag-glyph "minus"
|
|
3060 :tag "-")
|
|
3061 buttons)
|
|
3062 (insert "-\\ ")
|
|
3063 ;; (widget-glyph-insert nil "-\\ " "top")
|
|
3064 (push (widget-create-child-and-convert
|
|
3065 widget 'custom-browse-group-tag)
|
|
3066 buttons)
|
|
3067 (insert " " tag "\n")
|
|
3068 (widget-put widget :buttons buttons)
|
|
3069 (message "Creating group...")
|
|
3070 (let* ((members (custom-sort-items members
|
|
3071 custom-browse-sort-alphabetically
|
|
3072 custom-browse-order-groups))
|
|
3073 (prefixes (widget-get widget :custom-prefixes))
|
|
3074 (custom-prefix-list (custom-prefix-add symbol prefixes))
|
|
3075 (extra-prefix (if (widget-get widget :custom-last)
|
|
3076 " "
|
|
3077 " | "))
|
|
3078 (prefix (concat prefix extra-prefix))
|
|
3079 children entry)
|
|
3080 (while members
|
|
3081 (setq entry (car members)
|
|
3082 members (cdr members))
|
|
3083 (push (widget-create-child-and-convert
|
|
3084 widget (nth 1 entry)
|
|
3085 :group widget
|
|
3086 :tag (custom-unlispify-tag-name (nth 0 entry))
|
|
3087 :custom-prefixes custom-prefix-list
|
|
3088 :custom-level (1+ level)
|
|
3089 :custom-last (null members)
|
|
3090 :value (nth 0 entry)
|
|
3091 :custom-prefix prefix)
|
|
3092 children))
|
|
3093 (widget-put widget :children (reverse children)))
|
|
3094 (message "Creating group...done")))
|
|
3095 ;; Nested style.
|
|
3096 ((eq state 'hidden)
|
|
3097 ;; Create level indicator.
|
|
3098 (unless (eq custom-buffer-style 'links)
|
|
3099 (insert-char ?\ (* custom-buffer-indent (1- level)))
|
|
3100 (insert "-- "))
|
|
3101 ;; Create link indicator.
|
|
3102 (when (eq custom-buffer-style 'links)
|
|
3103 (insert " ")
|
|
3104 (push (widget-create-child-and-convert
|
|
3105 widget 'custom-group-link
|
|
3106 :tag "Open"
|
|
3107 :tag-glyph '("open-up" "open-down")
|
|
3108 symbol)
|
|
3109 buttons)
|
|
3110 (insert " "))
|
|
3111 ;; Create tag.
|
|
3112 (let ((begin (point)))
|
|
3113 (insert tag)
|
|
3114 (widget-specify-sample widget begin (point)))
|
|
3115 (insert " group")
|
|
3116 ;; Create visibility indicator.
|
|
3117 (unless (eq custom-buffer-style 'links)
|
|
3118 (insert ": ")
|
|
3119 (push (widget-create-child-and-convert
|
|
3120 widget 'custom-group-visibility
|
|
3121 :help-echo "Show members of this group"
|
|
3122 :action 'custom-toggle-parent
|
|
3123 (not (eq state 'hidden)))
|
|
3124 buttons))
|
|
3125 (insert " \n")
|
|
3126 ;; Create magic button.
|
|
3127 (let ((magic (widget-create-child-and-convert
|
|
3128 widget 'custom-magic nil)))
|
|
3129 (widget-put widget :custom-magic magic)
|
|
3130 (push magic buttons))
|
|
3131 ;; Update buttons.
|
|
3132 (widget-put widget :buttons buttons)
|
|
3133 ;; Insert documentation.
|
|
3134 (if (and (eq custom-buffer-style 'links) (> level 1))
|
|
3135 (widget-put widget :documentation-indent 0))
|
|
3136 (widget-default-format-handler widget ?h))
|
|
3137 ;; Nested style.
|
|
3138 (t ;Visible.
|
|
3139 (custom-load-widget widget)
|
|
3140 ;; Update members
|
|
3141 (setq members (custom-group-members
|
|
3142 symbol (and (eq custom-buffer-style 'tree)
|
|
3143 custom-browse-only-groups)))
|
|
3144 ;; Add parent groups references above the group.
|
|
3145 (if t ;;; This should test that the buffer
|
|
3146 ;;; was made to display a group.
|
|
3147 (when (eq level 1)
|
|
3148 (if (custom-add-parent-links widget
|
|
3149 "Go to parent group:")
|
|
3150 (insert "\n"))))
|
|
3151 ;; Create level indicator.
|
|
3152 (insert-char ?\ (* custom-buffer-indent (1- level)))
|
|
3153 (insert "/- ")
|
|
3154 ;; Create tag.
|
|
3155 (let ((start (point)))
|
|
3156 (insert tag)
|
|
3157 (widget-specify-sample widget start (point)))
|
|
3158 (insert " group: ")
|
|
3159 ;; Create visibility indicator.
|
|
3160 (unless (eq custom-buffer-style 'links)
|
|
3161 (insert "--------")
|
|
3162 (push (widget-create-child-and-convert
|
|
3163 widget 'visibility
|
|
3164 :help-echo "Hide members of this group"
|
|
3165 :action 'custom-toggle-parent
|
|
3166 (not (eq state 'hidden)))
|
|
3167 buttons)
|
|
3168 (insert " "))
|
|
3169 ;; Create more dashes.
|
|
3170 ;; Use 76 instead of 75 to compensate for the temporary "<"
|
|
3171 ;; added by `widget-insert'.
|
|
3172 (insert-char ?- (- 76 (current-column)
|
|
3173 (* custom-buffer-indent level)))
|
|
3174 (insert "\\\n")
|
|
3175 ;; Create magic button.
|
|
3176 (let ((magic (widget-create-child-and-convert
|
|
3177 widget 'custom-magic
|
|
3178 :indent 0
|
|
3179 nil)))
|
|
3180 (widget-put widget :custom-magic magic)
|
|
3181 (push magic buttons))
|
|
3182 ;; Update buttons.
|
|
3183 (widget-put widget :buttons buttons)
|
|
3184 ;; Insert documentation.
|
|
3185 (widget-default-format-handler widget ?h)
|
|
3186 ;; Parent groups.
|
|
3187 (if nil ;;; This should test that the buffer
|
|
3188 ;;; was not made to display a group.
|
|
3189 (when (eq level 1)
|
|
3190 (insert-char ?\ custom-buffer-indent)
|
|
3191 (custom-add-parent-links widget)))
|
|
3192 (custom-add-see-also widget
|
|
3193 (make-string (* custom-buffer-indent level)
|
|
3194 ?\ ))
|
|
3195 ;; Members.
|
|
3196 (message "Creating group...")
|
|
3197 (let* ((members (custom-sort-items members
|
|
3198 custom-buffer-sort-alphabetically
|
|
3199 custom-buffer-order-groups))
|
|
3200 (prefixes (widget-get widget :custom-prefixes))
|
|
3201 (custom-prefix-list (custom-prefix-add symbol prefixes))
|
|
3202 (length (length members))
|
|
3203 (count 0)
|
|
3204 (children (mapcar
|
|
3205 (lambda (entry)
|
|
3206 (widget-insert "\n")
|
|
3207 (when (zerop (% count custom-skip-messages))
|
|
3208 (display-message
|
|
3209 'progress
|
|
3210 (format "\
|
|
3211 Creating group members... %2d%%"
|
|
3212 (/ (* 100.0 count) length))))
|
|
3213 (incf count)
|
|
3214 (prog1
|
|
3215 (widget-create-child-and-convert
|
|
3216 widget (nth 1 entry)
|
|
3217 :group widget
|
|
3218 :tag (custom-unlispify-tag-name
|
|
3219 (nth 0 entry))
|
|
3220 :custom-prefixes custom-prefix-list
|
|
3221 :custom-level (1+ level)
|
|
3222 :value (nth 0 entry))
|
|
3223 (unless (eq (preceding-char) ?\n)
|
|
3224 (widget-insert "\n"))))
|
|
3225 members)))
|
|
3226 (message "Creating group magic...")
|
|
3227 (mapc 'custom-magic-reset children)
|
|
3228 (message "Creating group state...")
|
|
3229 (widget-put widget :children children)
|
|
3230 (custom-group-state-update widget)
|
|
3231 (message "Creating group... done"))
|
|
3232 ;; End line
|
|
3233 (insert "\n")
|
|
3234 (insert-char ?\ (* custom-buffer-indent (1- level)))
|
|
3235 (insert "\\- " (widget-get widget :tag) " group end ")
|
|
3236 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
|
|
3237 (insert "/\n")))))
|
|
3238
|
|
3239 (defvar custom-group-menu
|
|
3240 '(("Set for Current Session" custom-group-set
|
|
3241 (lambda (widget)
|
|
3242 (eq (widget-get widget :custom-state) 'modified)))
|
|
3243 ("Save for Future Sessions" custom-group-save
|
|
3244 (lambda (widget)
|
|
3245 (memq (widget-get widget :custom-state) '(modified set))))
|
|
3246 ("Reset to Current" custom-group-reset-current
|
|
3247 (lambda (widget)
|
|
3248 (memq (widget-get widget :custom-state) '(modified))))
|
|
3249 ("Reset to Saved" custom-group-reset-saved
|
|
3250 (lambda (widget)
|
|
3251 (memq (widget-get widget :custom-state) '(modified set))))
|
|
3252 ("Reset to standard setting" custom-group-reset-standard
|
|
3253 (lambda (widget)
|
|
3254 (memq (widget-get widget :custom-state) '(modified set saved)))))
|
|
3255 "Alist of actions for the `custom-group' widget.
|
|
3256 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
3257 the menu entry, ACTION is the function to call on the widget when the
|
|
3258 menu is selected, and FILTER is a predicate which takes a `custom-group'
|
|
3259 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
3260 widget. If FILTER is nil, ACTION is always valid.")
|
|
3261
|
|
3262 (defun custom-group-action (widget &optional event)
|
|
3263 "Show the menu for `custom-group' WIDGET.
|
|
3264 Optional EVENT is the location for the menu."
|
|
3265 (if (eq (widget-get widget :custom-state) 'hidden)
|
|
3266 (custom-toggle-hide widget)
|
|
3267 (let* ((completion-ignore-case t)
|
|
3268 (answer (widget-choose (concat "Operation on "
|
|
3269 (custom-unlispify-tag-name
|
|
3270 (widget-get widget :value)))
|
|
3271 (custom-menu-filter custom-group-menu
|
|
3272 widget)
|
|
3273 event)))
|
|
3274 (if answer
|
|
3275 (funcall answer widget)))))
|
|
3276
|
|
3277 (defun custom-group-set (widget)
|
|
3278 "Set changes in all modified group members."
|
|
3279 (let ((children (widget-get widget :children)))
|
|
3280 (mapc (lambda (child)
|
|
3281 (when (eq (widget-get child :custom-state) 'modified)
|
|
3282 (widget-apply child :custom-set)))
|
|
3283 children)))
|
|
3284
|
480
|
3285 (defun custom-group-pre-save (widget)
|
|
3286 "Prepare for saving all modified group members."
|
|
3287 (let ((children (widget-get widget :children)))
|
|
3288 (mapc (lambda (child)
|
|
3289 (when (memq (widget-get child :custom-state) '(modified set))
|
|
3290 (widget-apply child :custom-pre-save)))
|
|
3291 children)))
|
|
3292
|
|
3293 (defun custom-group-post-save (widget)
|
428
|
3294 "Save all modified group members."
|
|
3295 (let ((children (widget-get widget :children)))
|
|
3296 (mapc (lambda (child)
|
|
3297 (when (memq (widget-get child :custom-state) '(modified set))
|
480
|
3298 (widget-apply child :custom-post-save)))
|
428
|
3299 children)))
|
|
3300
|
480
|
3301 (defun custom-group-save (widget)
|
|
3302 "Save all modified group members."
|
|
3303 (custom-group-pre-save widget)
|
|
3304 (custom-save-all)
|
|
3305 (custom-group-post-save widget))
|
|
3306
|
428
|
3307 (defun custom-group-reset-current (widget)
|
|
3308 "Reset all modified group members."
|
|
3309 (let ((children (widget-get widget :children)))
|
|
3310 (mapc (lambda (child)
|
|
3311 (when (eq (widget-get child :custom-state) 'modified)
|
|
3312 (widget-apply child :custom-reset-current)))
|
|
3313 children)))
|
|
3314
|
|
3315 (defun custom-group-reset-saved (widget)
|
|
3316 "Reset all modified or set group members."
|
|
3317 (let ((children (widget-get widget :children)))
|
|
3318 (mapc (lambda (child)
|
|
3319 (when (memq (widget-get child :custom-state) '(modified set))
|
|
3320 (widget-apply child :custom-reset-saved)))
|
|
3321 children)))
|
|
3322
|
480
|
3323 ;; This function returns non nil when we need to re-save the options --dv.
|
|
3324 (defun custom-group-pre-reset-standard (widget)
|
|
3325 "Prepare for resetting all modified, set, or saved group members."
|
|
3326 (let ((children (widget-get widget :children))
|
|
3327 must-save)
|
|
3328 (mapc (lambda (child)
|
|
3329 (when (memq (widget-get child :custom-state)
|
|
3330 '(modified set saved))
|
|
3331 (and (widget-apply child :custom-pre-reset-standard)
|
|
3332 (setq must-save t))))
|
|
3333 children)
|
|
3334 must-save
|
|
3335 ))
|
|
3336
|
|
3337 (defun custom-group-post-reset-standard (widget)
|
|
3338 "Finish resetting all modified, set, or saved group members."
|
428
|
3339 (let ((children (widget-get widget :children)))
|
|
3340 (mapc (lambda (child)
|
|
3341 (when (memq (widget-get child :custom-state)
|
|
3342 '(modified set saved))
|
480
|
3343 (widget-apply child :custom-post-reset-standard)))
|
428
|
3344 children)))
|
|
3345
|
480
|
3346 (defun custom-group-reset-standard (widget)
|
|
3347 "Reset all modified, set, or saved group members."
|
|
3348 (when (custom-group-pre-reset-standard widget)
|
|
3349 (custom-save-all))
|
|
3350 (custom-group-post-reset-standard widget))
|
|
3351
|
428
|
3352 (defun custom-group-state-update (widget)
|
|
3353 "Update magic."
|
|
3354 (unless (eq (widget-get widget :custom-state) 'hidden)
|
|
3355 (let* ((children (widget-get widget :children))
|
|
3356 (states (mapcar (lambda (child)
|
|
3357 (widget-get child :custom-state))
|
|
3358 children))
|
|
3359 (magics custom-magic-alist)
|
|
3360 (found 'standard))
|
|
3361 (while magics
|
|
3362 (let ((magic (car (car magics))))
|
|
3363 (if (and (not (eq magic 'hidden))
|
|
3364 (memq magic states))
|
|
3365 (setq found magic
|
|
3366 magics nil)
|
|
3367 (setq magics (cdr magics)))))
|
|
3368 (widget-put widget :custom-state found)))
|
|
3369 (custom-magic-reset widget))
|
|
3370
|
|
3371 (defun custom-save-delete (symbol)
|
|
3372 "Delete the call to SYMBOL form in `custom-file'.
|
|
3373 Leave point at the location of the call, or after the last expression."
|
|
3374 (let ((find-file-hooks nil)
|
|
3375 (auto-mode-alist nil))
|
|
3376 (set-buffer (find-file-noselect custom-file)))
|
|
3377 (goto-char (point-min))
|
|
3378 (catch 'found
|
|
3379 (while t
|
|
3380 (let ((sexp (condition-case nil
|
|
3381 (read (current-buffer))
|
|
3382 (end-of-file (throw 'found nil)))))
|
|
3383 (when (and (listp sexp)
|
|
3384 (eq (car sexp) symbol))
|
|
3385 (delete-region (save-excursion
|
|
3386 (backward-sexp)
|
|
3387 (point))
|
|
3388 (point))
|
|
3389 (throw 'found nil))))))
|
|
3390
|
848
|
3391 (defun custom-save-delete-any (&rest symbols)
|
|
3392 "Delete the call to any symbol among SYMBOLS in `custom-file'.
|
|
3393 Leave the point at the end of the file."
|
|
3394 (let ((find-file-hooks nil)
|
|
3395 (auto-mode-alist nil))
|
|
3396 (set-buffer (find-file-noselect custom-file)))
|
|
3397 (goto-char (point-min))
|
|
3398 (condition-case nil
|
|
3399 (while (not (eobp))
|
|
3400 (let ((sexp (read (current-buffer))))
|
|
3401 (when (and (listp sexp)
|
|
3402 (memq (car sexp) symbols))
|
|
3403 (delete-region (save-excursion
|
|
3404 (backward-sexp)
|
|
3405 (point))
|
|
3406 (point))
|
|
3407 (while (and (eolp) (not (eobp)))
|
|
3408 (delete-region (point) (prog2 (forward-line 1) (point))))
|
|
3409 )))
|
|
3410 (end-of-file nil)))
|
|
3411
|
|
3412 (defsubst custom-save-variable-p (symbol)
|
|
3413 "Return non-nil if symbol SYMBOL is a customized variable."
|
|
3414 (and (symbolp symbol)
|
|
3415 (let ((spec (car-safe (get symbol 'theme-value))))
|
|
3416 (or (and spec (eq (car spec) 'user)
|
|
3417 (eq (second spec) 'set))
|
|
3418 (get symbol 'saved-variable-comment)
|
|
3419 ;; support non-themed vars
|
|
3420 (and (null spec) (get symbol 'saved-value))))))
|
|
3421
|
|
3422 (defun custom-save-variable-internal (symbol)
|
|
3423 "Print variable SYMBOL to the standard output.
|
|
3424 SYMBOL must be a customized variable."
|
|
3425 (let ((requests (get symbol 'custom-requests))
|
|
3426 (now (not (or (get symbol 'standard-value)
|
|
3427 (and (not (boundp symbol))
|
|
3428 (not (eq (get symbol 'force-value)
|
|
3429 'rogue))))))
|
|
3430 (comment (get symbol 'saved-variable-comment))
|
|
3431 ;; Print everything, no placeholders `...'
|
|
3432 (print-level nil)
|
|
3433 (print-length nil))
|
|
3434 (unless (custom-save-variable-p symbol)
|
|
3435 (error 'wrong-type-argument "Not a customized variable" symbol))
|
|
3436 (princ "\n '(")
|
|
3437 (prin1 symbol)
|
|
3438 (princ " ")
|
|
3439 ;; This comment stuff is in the way ####
|
|
3440 ;; Is (eq (third spec) (car saved-value)) ????
|
|
3441 ;; (prin1 (third spec))
|
|
3442 ;; XEmacs -- pretty-print value if available
|
|
3443 (if (and custom-save-pretty-print
|
|
3444 (fboundp 'pp))
|
|
3445 ;; To suppress bytecompiler warning
|
|
3446 (with-fboundp 'pp
|
|
3447 (pp (car (get symbol 'saved-value))))
|
|
3448 (prin1 (car (get symbol 'saved-value))))
|
|
3449 (when (or now requests comment)
|
|
3450 (princ (if now " t" " nil")))
|
|
3451 (when (or comment requests)
|
|
3452 (princ " ")
|
|
3453 (prin1 requests))
|
|
3454 (when comment
|
|
3455 (princ " ")
|
|
3456 (prin1 comment))
|
|
3457 (princ ")")))
|
|
3458
|
428
|
3459 (defun custom-save-variables ()
|
|
3460 "Save all customized variables in `custom-file'."
|
|
3461 (save-excursion
|
|
3462 (custom-save-delete 'custom-load-themes)
|
|
3463 (custom-save-delete 'custom-reset-variables)
|
|
3464 (custom-save-delete 'custom-set-variables)
|
848
|
3465 ;; This leaves point at the end of file.
|
|
3466 ;; Adrian Aichner <adrian@xemacs.org> stated it is
|
|
3467 ;; a bad behavior <npak@ispras.ru>
|
|
3468 ;;(custom-save-delete-any 'custom-load-themes
|
|
3469 ;; 'custom-reset-variables
|
|
3470 ;; 'custom-set-variables)
|
428
|
3471 (custom-save-loaded-themes)
|
|
3472 (custom-save-resets 'theme-value 'custom-reset-variables nil)
|
848
|
3473 (let ((standard-output (current-buffer))
|
|
3474 ;; To make nconc work
|
|
3475 (sorted-list (make-list 1 t)))
|
|
3476 ;; First create a sorted list of saved variables.
|
|
3477 (mapatoms
|
|
3478 (lambda (symbol)
|
|
3479 (when (custom-save-variable-p symbol)
|
|
3480 (nconc sorted-list (list symbol)))))
|
|
3481 (setq sorted-list (sort (cdr sorted-list) 'string<))
|
|
3482
|
428
|
3483 (unless (bolp)
|
848
|
3484 (princ "\n"))
|
428
|
3485 (princ "(custom-set-variables")
|
848
|
3486 (mapc 'custom-save-variable-internal
|
|
3487 sorted-list)
|
|
3488 (princ ")")
|
|
3489 (unless (looking-at "\n")
|
|
3490 (princ "\n")))))
|
428
|
3491
|
|
3492 (defvar custom-save-face-ignoring nil)
|
|
3493
|
848
|
3494 (defsubst custom-save-face-p (symbol)
|
|
3495 "Return non-nil if SYMBOL is a customized face."
|
428
|
3496 (let ((theme-spec (car-safe (get symbol 'theme-face)))
|
848
|
3497 (comment (get symbol 'saved-face-comment)))
|
|
3498 (or (and (not (memq symbol custom-save-face-ignoring))
|
|
3499 ;; Don't print default face here.
|
|
3500 (or (and theme-spec
|
|
3501 (eq (car theme-spec) 'user)
|
|
3502 (eq (second theme-spec) 'set))
|
|
3503 ;; cope with non-themed faces
|
|
3504 (and (null theme-spec)
|
|
3505 (get symbol 'saved-face))))
|
|
3506 comment)))
|
|
3507
|
|
3508 (defun custom-save-face-internal (symbol)
|
|
3509 "Print face SYMBOL to the standard output.
|
|
3510 SYMBOL must be a customized face."
|
|
3511 (let ((comment (get symbol 'saved-face-comment))
|
428
|
3512 (now (not (or (get symbol 'face-defface-spec)
|
|
3513 (and (not (find-face symbol))
|
848
|
3514 (not (eq (get symbol 'force-face) 'rogue))))))
|
|
3515 ;; Print everything, no placeholders `...'
|
|
3516 (print-level nil)
|
|
3517 (print-length nil))
|
|
3518 (if (memq symbol custom-save-face-ignoring)
|
|
3519 ;; Do nothing
|
|
3520 nil
|
|
3521 ;; Print face
|
|
3522 (unless (custom-save-face-p symbol)
|
|
3523 (error 'wrong-type-argument "Not a customized face" symbol))
|
428
|
3524 (princ "\n '(")
|
|
3525 (prin1 symbol)
|
|
3526 (princ " ")
|
|
3527 (prin1 (get symbol 'saved-face))
|
|
3528 (if (or comment now)
|
848
|
3529 (princ (if now " t" " nil")))
|
428
|
3530 (when comment
|
848
|
3531 (princ " ")
|
|
3532 (prin1 comment))
|
428
|
3533 (princ ")"))))
|
|
3534
|
|
3535 (defun custom-save-faces ()
|
|
3536 "Save all customized faces in `custom-file'."
|
|
3537 (save-excursion
|
|
3538 (custom-save-delete 'custom-reset-faces)
|
|
3539 (custom-save-delete 'custom-set-faces)
|
848
|
3540 ;; This leaves point at the end of file.
|
|
3541 ;; Adrian Aichner <adrian@xemacs.org> stated it is
|
|
3542 ;; a bad behavior <npak@ispras.ru>
|
|
3543 ;;(custom-save-delete-any 'custom-reset-faces
|
|
3544 ;; 'custom-set-faces)
|
428
|
3545 (custom-save-resets 'theme-face 'custom-reset-faces '(default))
|
848
|
3546 (let ((standard-output (current-buffer))
|
|
3547 ;; To make nconc work
|
|
3548 (sorted-list (make-list 1 t)))
|
|
3549 ;; Create a sorted list of faces
|
|
3550 (mapatoms
|
|
3551 (lambda (symbol)
|
|
3552 (when (custom-save-face-p symbol)
|
|
3553 (nconc sorted-list (list symbol)))))
|
|
3554 (setq sorted-list (sort (cdr sorted-list) 'string<))
|
|
3555
|
428
|
3556 (unless (bolp)
|
|
3557 (princ "\n"))
|
|
3558 (princ "(custom-set-faces")
|
|
3559 ;; The default face must be first, since it affects the others.
|
848
|
3560 (when (custom-save-face-p 'default)
|
|
3561 (custom-save-face-internal 'default))
|
428
|
3562 (let ((custom-save-face-ignoring '(default)))
|
848
|
3563 (mapc 'custom-save-face-internal
|
|
3564 sorted-list))
|
428
|
3565 (princ ")")
|
|
3566 (unless (looking-at "\n")
|
|
3567 (princ "\n")))))
|
|
3568
|
848
|
3569 (defmacro make-custom-save-resets-mapper (property setter)
|
|
3570 "Create a mapper for `custom-save-resets'."
|
|
3571 `(lambda (object)
|
|
3572 (let ((spec (car-safe (get object (quote ,property))))
|
|
3573 (print-level nil)
|
|
3574 (print-length nil))
|
|
3575 (with-boundp '(ignored-special started-writing)
|
|
3576 (when (and (not (memq object ignored-special))
|
|
3577 (eq (car spec) 'user)
|
|
3578 (eq (second spec) 'reset))
|
|
3579 ;; Do not write reset statements unless necessary.
|
|
3580 (unless started-writing
|
|
3581 (setq started-writing t)
|
|
3582 (unless (bolp)
|
|
3583 (princ "\n"))
|
|
3584 (princ "(")
|
|
3585 (princ (quote ,setter))
|
|
3586 (princ "\n '(")
|
|
3587 (prin1 object)
|
|
3588 (princ " ")
|
|
3589 (prin1 (third spec))
|
|
3590 (princ ")")))))))
|
|
3591
|
|
3592 (defconst custom-save-resets-mapper-alist
|
|
3593 (eval-when-compile
|
|
3594 (list (list 'theme-value 'custom-reset-variables
|
|
3595 (byte-compile
|
|
3596 (make-custom-save-resets-mapper
|
|
3597 'theme-value 'custom-reset-variables)))
|
|
3598 (list 'theme-face 'custom-reset-faces
|
|
3599 (byte-compile
|
|
3600 (make-custom-save-resets-mapper
|
|
3601 'theme-face 'custom-reset-faces)))))
|
|
3602 "Never use it.
|
|
3603 Hashes several heavily used functions for `custom-save-resets'")
|
|
3604
|
428
|
3605 (defun custom-save-resets (property setter special)
|
848
|
3606 (declare (special ignored-special))
|
428
|
3607 (let (started-writing ignored-special)
|
444
|
3608 ;; (custom-save-delete setter) Done by caller
|
428
|
3609 (let ((standard-output (current-buffer))
|
848
|
3610 (mapper (let ((triple (assq property custom-save-resets-mapper-alist)))
|
|
3611 (if (and triple (eq (second triple) setter))
|
|
3612 (third triple)
|
|
3613 (make-custom-save-resets-mapper property setter)))))
|
428
|
3614 (mapc mapper special)
|
|
3615 (setq ignored-special special)
|
|
3616 (mapatoms mapper)
|
|
3617 (when started-writing
|
848
|
3618 (princ ")\n")))))
|
444
|
3619
|
428
|
3620
|
|
3621 (defun custom-save-loaded-themes ()
|
|
3622 (let ((themes (reverse (get 'user 'theme-loads-themes)))
|
848
|
3623 (standard-output (current-buffer))
|
|
3624 (print-level nil)
|
|
3625 (print-length nil))
|
428
|
3626 (when themes
|
|
3627 (unless (bolp) (princ "\n"))
|
|
3628 (princ "(custom-load-themes")
|
|
3629 (mapc (lambda (theme)
|
|
3630 (princ "\n '")
|
|
3631 (prin1 theme)) themes)
|
444
|
3632 (princ " )\n"))))
|
428
|
3633
|
|
3634 ;;;###autoload
|
|
3635 (defun customize-save-customized ()
|
|
3636 "Save all user options which have been set in this session."
|
|
3637 (interactive)
|
|
3638 (mapatoms (lambda (symbol)
|
|
3639 (let ((face (get symbol 'customized-face))
|
|
3640 (value (get symbol 'customized-value))
|
|
3641 (face-comment (get symbol 'customized-face-comment))
|
|
3642 (variable-comment
|
|
3643 (get symbol 'customized-variable-comment)))
|
|
3644 (when face
|
|
3645 (put symbol 'saved-face face)
|
|
3646 (custom-push-theme 'theme-face symbol 'user 'set value)
|
|
3647 (put symbol 'customized-face nil))
|
|
3648 (when value
|
|
3649 (put symbol 'saved-value value)
|
|
3650 (custom-push-theme 'theme-value symbol 'user 'set value)
|
|
3651 (put symbol 'customized-value nil))
|
|
3652 (when variable-comment
|
|
3653 (put symbol 'saved-variable-comment variable-comment)
|
|
3654 (put symbol 'customized-variable-comment nil))
|
|
3655 (when face-comment
|
|
3656 (put symbol 'saved-face-comment face-comment)
|
|
3657 (put symbol 'customized-face-comment nil)))))
|
|
3658 ;; We really should update all custom buffers here.
|
|
3659 (custom-save-all))
|
|
3660
|
|
3661 ;;;###autoload
|
|
3662 (defun custom-save-all ()
|
|
3663 "Save all customizations in `custom-file'."
|
|
3664 (let ((inhibit-read-only t))
|
|
3665 (custom-save-variables)
|
|
3666 (custom-save-faces)
|
|
3667 (let ((find-file-hooks nil)
|
|
3668 (auto-mode-alist))
|
|
3669 (with-current-buffer (find-file-noselect custom-file)
|
|
3670 (save-buffer)))))
|
|
3671
|
|
3672
|
|
3673 ;;; The Customize Menu.
|
|
3674
|
|
3675 ;;; Menu support
|
|
3676
|
|
3677 (defun custom-face-menu-create (widget symbol)
|
|
3678 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
|
|
3679 (vector (custom-unlispify-menu-entry symbol)
|
|
3680 `(customize-face ',symbol)
|
|
3681 t))
|
|
3682
|
|
3683 (defun custom-variable-menu-create (widget symbol)
|
|
3684 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
|
|
3685 (let ((type (get symbol 'custom-type)))
|
|
3686 (unless (listp type)
|
|
3687 (setq type (list type)))
|
|
3688 (if (and type (widget-get type :custom-menu))
|
|
3689 (widget-apply type :custom-menu symbol)
|
|
3690 (vector (custom-unlispify-menu-entry symbol)
|
|
3691 `(customize-variable ',symbol)
|
|
3692 t))))
|
|
3693
|
|
3694 ;; Add checkboxes to boolean variable entries.
|
|
3695 (widget-put (get 'boolean 'widget-type)
|
|
3696 :custom-menu (lambda (widget symbol)
|
|
3697 `[,(custom-unlispify-menu-entry symbol)
|
|
3698 (customize-variable ',symbol)
|
|
3699 :style toggle
|
|
3700 :selected ,symbol]))
|
|
3701
|
|
3702 ;; XEmacs can create menus dynamically.
|
|
3703 (defun custom-group-menu-create (widget symbol)
|
|
3704 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
|
|
3705 `( ,(custom-unlispify-menu-entry symbol t)
|
|
3706 :filter (lambda (&rest junk)
|
|
3707 (let ((item (custom-menu-create ',symbol)))
|
|
3708 (if (listp item)
|
|
3709 (cdr item)
|
|
3710 (list item))))))
|
|
3711
|
|
3712 ;;;###autoload
|
|
3713 (defun custom-menu-create (symbol)
|
|
3714 "Create menu for customization group SYMBOL.
|
|
3715 The menu is in a format applicable to `easy-menu-define'."
|
|
3716 (let* ((item (vector (custom-unlispify-menu-entry symbol)
|
|
3717 `(customize-group ',symbol)
|
|
3718 t)))
|
|
3719 ;; Item is the entry for creating a menu buffer for SYMBOL.
|
|
3720 ;; We may nest, if the menu is not too big.
|
|
3721 (custom-load-symbol symbol)
|
|
3722 (if (< (length (get symbol 'custom-group)) widget-menu-max-size)
|
|
3723 ;; The menu is not too big.
|
|
3724 (let ((custom-prefix-list (custom-prefix-add symbol
|
|
3725 custom-prefix-list))
|
|
3726 (members (custom-sort-items (get symbol 'custom-group)
|
|
3727 custom-menu-sort-alphabetically
|
|
3728 custom-menu-order-groups)))
|
|
3729 ;; Create the menu.
|
|
3730 `(,(custom-unlispify-menu-entry symbol t)
|
|
3731 ,item
|
|
3732 "--"
|
|
3733 ,@(mapcar (lambda (entry)
|
|
3734 (widget-apply (if (listp (nth 1 entry))
|
|
3735 (nth 1 entry)
|
|
3736 (list (nth 1 entry)))
|
|
3737 :custom-menu (nth 0 entry)))
|
|
3738 members)))
|
|
3739 ;; The menu was too big.
|
|
3740 item)))
|
|
3741
|
|
3742 ;;;###autoload
|
|
3743 (defun customize-menu-create (symbol &optional name)
|
|
3744 "Return a customize menu for customization group SYMBOL.
|
|
3745 If optional NAME is given, use that as the name of the menu.
|
|
3746 Otherwise the menu will be named `Customize'.
|
|
3747 The format is suitable for use with `easy-menu-define'."
|
|
3748 (unless name
|
|
3749 (setq name "Customize"))
|
|
3750 `(,name
|
|
3751 :filter (lambda (&rest junk)
|
|
3752 (cdr (custom-menu-create ',symbol)))))
|
|
3753
|
|
3754 ;;; The Custom Mode.
|
|
3755
|
|
3756 (defvar custom-mode-map nil
|
|
3757 "Keymap for `custom-mode'.")
|
|
3758
|
|
3759 (unless custom-mode-map
|
|
3760 (setq custom-mode-map (make-sparse-keymap))
|
|
3761 (set-keymap-parents custom-mode-map widget-keymap)
|
|
3762 (suppress-keymap custom-mode-map)
|
|
3763 (define-key custom-mode-map " " 'scroll-up)
|
|
3764 (define-key custom-mode-map [delete] 'scroll-down)
|
|
3765 (define-key custom-mode-map "q" 'Custom-buffer-done)
|
|
3766 (define-key custom-mode-map "u" 'Custom-goto-parent)
|
|
3767 (define-key custom-mode-map "n" 'widget-forward)
|
|
3768 (define-key custom-mode-map "p" 'widget-backward))
|
|
3769
|
|
3770 (easy-menu-define Custom-mode-menu
|
|
3771 custom-mode-map
|
|
3772 "Menu used in customization buffers."
|
|
3773 `("Custom"
|
|
3774 ,(customize-menu-create 'customize)
|
|
3775 ["Set" Custom-set t]
|
|
3776 ["Save" Custom-save t]
|
|
3777 ["Reset to Current" Custom-reset-current t]
|
|
3778 ["Reset to Saved" Custom-reset-saved t]
|
|
3779 ["Reset to Standard Settings" Custom-reset-standard t]
|
|
3780 ["Info" (Info-goto-node "(xemacs)Easy Customization") t]))
|
|
3781
|
|
3782 (defun Custom-goto-parent ()
|
|
3783 "Go to the parent group listed at the top of this buffer.
|
|
3784 If several parents are listed, go to the first of them."
|
|
3785 (interactive)
|
|
3786 (save-excursion
|
|
3787 (goto-char (point-min))
|
|
3788 (if (search-forward "\nGo to parent group: " nil t)
|
|
3789 (let* ((button (get-char-property (point) 'button))
|
|
3790 (parent (downcase (widget-get button :tag))))
|
|
3791 (customize-group parent)))))
|
|
3792
|
|
3793 (defcustom custom-mode-hook nil
|
|
3794 "Hook called when entering custom-mode."
|
|
3795 :type 'hook
|
|
3796 :group 'custom-buffer )
|
|
3797
|
|
3798 (defun custom-state-buffer-message (widget)
|
|
3799 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
|
|
3800 (message
|
|
3801 "To install your edits, invoke [State] and choose the Set operation")))
|
|
3802
|
|
3803 (defun custom-mode ()
|
|
3804 "Major mode for editing customization buffers.
|
|
3805
|
|
3806 The following commands are available:
|
|
3807
|
|
3808 Move to next button or editable field. \\[widget-forward]
|
|
3809 Move to previous button or editable field. \\[widget-backward]
|
|
3810 \\<widget-field-keymap>\
|
|
3811 Complete content of editable text field. \\[widget-complete]
|
|
3812 \\<custom-mode-map>\
|
|
3813 Invoke button under point. \\[widget-button-press]
|
|
3814 Set all modifications. \\[Custom-set]
|
|
3815 Make all modifications default. \\[Custom-save]
|
|
3816 Reset all modified options. \\[Custom-reset-current]
|
|
3817 Reset all modified or set options. \\[Custom-reset-saved]
|
|
3818 Reset all options. \\[Custom-reset-standard]
|
|
3819
|
|
3820 Entry to this mode calls the value of `custom-mode-hook'
|
|
3821 if that value is non-nil."
|
|
3822 (kill-all-local-variables)
|
|
3823 (setq major-mode 'custom-mode
|
|
3824 mode-name "Custom")
|
|
3825 (use-local-map custom-mode-map)
|
|
3826 (easy-menu-add Custom-mode-menu)
|
|
3827 (make-local-variable 'custom-options)
|
|
3828 (make-local-variable 'widget-documentation-face)
|
|
3829 (setq widget-documentation-face 'custom-documentation-face)
|
|
3830 (make-local-variable 'widget-button-face)
|
|
3831 (setq widget-button-face 'custom-button-face)
|
|
3832 (make-local-hook 'widget-edit-functions)
|
|
3833 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
|
|
3834 (run-hooks 'custom-mode-hook))
|
|
3835
|
|
3836
|
442
|
3837 ;;;###autoload
|
|
3838 (defun custom-migrate-custom-file (new-custom-file-name)
|
|
3839 "Migrate custom file from home directory."
|
|
3840 (mapc 'custom-save-delete
|
|
3841 '(custom-load-themes custom-reset-variables
|
|
3842 custom-set-variables
|
|
3843 custom-set-faces
|
|
3844 custom-reset-faces))
|
|
3845 (with-current-buffer (find-file-noselect custom-file)
|
|
3846 (save-buffer))
|
|
3847 (setq custom-file new-custom-file-name)
|
|
3848 (custom-save-all))
|
|
3849
|
428
|
3850 ;;; The End.
|
|
3851
|
|
3852 (provide 'cus-edit)
|
|
3853
|
|
3854 ;; cus-edit.el ends here
|