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
|
|
943 (defun customize-apropos (regexp &optional all)
|
|
944 "Customize all user options matching REGEXP.
|
|
945 If ALL is `options', include only options.
|
|
946 If ALL is `faces', include only faces.
|
|
947 If ALL is `groups', include only groups.
|
|
948 If ALL is t (interactively, with prefix arg), include options which are not
|
|
949 user-settable, as well as faces and groups."
|
|
950 (interactive "sCustomize regexp: \nP")
|
|
951 (let ((found nil))
|
|
952 (mapatoms (lambda (symbol)
|
|
953 (when (string-match regexp (symbol-name symbol))
|
|
954 (when (and (not (memq all '(faces options)))
|
|
955 (get symbol 'custom-group))
|
|
956 (push (list symbol 'custom-group) found))
|
|
957 (when (and (not (memq all '(options groups)))
|
|
958 (find-face symbol))
|
|
959 (push (list symbol 'custom-face) found))
|
|
960 (when (and (not (memq all '(groups faces)))
|
|
961 (boundp symbol)
|
|
962 (or (get symbol 'saved-value)
|
|
963 (get symbol 'standard-value)
|
|
964 (if (memq all '(nil options))
|
|
965 (user-variable-p symbol)
|
|
966 (get symbol 'variable-documentation))))
|
|
967 (push (list symbol 'custom-variable) found)))))
|
|
968 (if (not found)
|
|
969 (error "No matches")
|
|
970 (custom-buffer-create (custom-sort-items found t
|
|
971 custom-buffer-order-groups)
|
|
972 "*Customize Apropos*"))))
|
|
973
|
|
974 ;;;###autoload
|
|
975 (defun customize-apropos-options (regexp &optional arg)
|
|
976 "Customize all user options matching REGEXP.
|
|
977 With prefix arg, include options which are not user-settable."
|
|
978 (interactive "sCustomize regexp: \nP")
|
|
979 (customize-apropos regexp (or arg 'options)))
|
|
980
|
|
981 ;;;###autoload
|
|
982 (defun customize-apropos-faces (regexp)
|
|
983 "Customize all user faces matching REGEXP."
|
|
984 (interactive "sCustomize regexp: \n")
|
|
985 (customize-apropos regexp 'faces))
|
|
986
|
|
987 ;;;###autoload
|
|
988 (defun customize-apropos-groups (regexp)
|
|
989 "Customize all user groups matching REGEXP."
|
|
990 (interactive "sCustomize regexp: \n")
|
|
991 (customize-apropos regexp 'groups))
|
|
992
|
|
993
|
|
994 ;;; Buffer.
|
|
995
|
|
996 (defcustom custom-buffer-style 'links
|
|
997 "*Control the presentation style for customization buffers.
|
|
998 The value should be a symbol, one of:
|
|
999
|
|
1000 brackets: groups nest within each other with big horizontal brackets.
|
|
1001 links: groups have links to subgroups."
|
|
1002 :type '(radio (const :tag "brackets: Groups nest within each others" brackets)
|
|
1003 (const :tag "links: Group have links to subgroups" links))
|
|
1004 :group 'custom-buffer)
|
|
1005
|
|
1006 (defcustom custom-buffer-done-function 'kill-buffer
|
|
1007 "*Function to be used to remove the buffer when the user is done with it.
|
|
1008 Choices include `kill-buffer' (the default) and `bury-buffer'.
|
|
1009 The function will be called with one argument, the buffer to remove."
|
|
1010 :type '(radio (function-item kill-buffer)
|
|
1011 (function-item bury-buffer)
|
|
1012 (function :tag "Other" nil))
|
|
1013 :group 'custom-buffer)
|
|
1014
|
|
1015 (defcustom custom-buffer-indent 3
|
|
1016 "Number of spaces to indent nested groups."
|
|
1017 :type 'integer
|
|
1018 :group 'custom-buffer)
|
|
1019
|
|
1020 ;;;###autoload
|
|
1021 (defun custom-buffer-create (options &optional name description)
|
|
1022 "Create a buffer containing OPTIONS.
|
|
1023 Optional NAME is the name of the buffer.
|
|
1024 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
|
|
1025 SYMBOL is a customization option, and WIDGET is a widget for editing
|
|
1026 that option."
|
|
1027 (unless name (setq name "*Customization*"))
|
|
1028 (kill-buffer (get-buffer-create name))
|
|
1029 (switch-to-buffer (get-buffer-create name))
|
|
1030 (custom-buffer-create-internal options description))
|
|
1031
|
|
1032 ;;;###autoload
|
|
1033 (defun custom-buffer-create-other-window (options &optional name description)
|
|
1034 "Create a buffer containing OPTIONS.
|
|
1035 Optional NAME is the name of the buffer.
|
|
1036 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
|
|
1037 SYMBOL is a customization option, and WIDGET is a widget for editing
|
|
1038 that option."
|
|
1039 (unless name (setq name "*Customization*"))
|
|
1040 (kill-buffer (get-buffer-create name))
|
|
1041 (let ((window (selected-window)))
|
|
1042 (switch-to-buffer-other-window (get-buffer-create name))
|
|
1043 (custom-buffer-create-internal options description)
|
|
1044 (select-window window)))
|
|
1045
|
|
1046 (defcustom custom-reset-button-menu t
|
|
1047 "If non-nil, only show a single reset button in customize buffers.
|
|
1048 This button will have a menu with all three reset operations."
|
|
1049 :type 'boolean
|
|
1050 :group 'custom-buffer)
|
|
1051
|
|
1052 (defconst custom-skip-messages 5)
|
|
1053
|
|
1054 (defun Custom-buffer-done ()
|
|
1055 "Remove current buffer.
|
|
1056 This works by calling the function specified by
|
|
1057 `custom-buffer-done-function'."
|
|
1058 (interactive)
|
|
1059 (funcall custom-buffer-done-function (current-buffer)))
|
|
1060
|
|
1061 (defun custom-buffer-create-buttons ()
|
|
1062 (message "Creating customization buttons...")
|
|
1063 (widget-insert "\nOperate on everything in this buffer:\n ")
|
|
1064 (widget-create 'push-button
|
|
1065 :tag "Set"
|
|
1066 :help-echo "\
|
|
1067 Make your editing in this buffer take effect for this session"
|
|
1068 :action (lambda (widget &optional event)
|
|
1069 (Custom-set)))
|
|
1070 (widget-insert " ")
|
|
1071 (widget-create 'push-button
|
|
1072 :tag "Save"
|
|
1073 :help-echo "\
|
|
1074 Make your editing in this buffer take effect for future Emacs sessions"
|
|
1075 :action (lambda (widget &optional event)
|
|
1076 (Custom-save)))
|
|
1077 (if custom-reset-button-menu
|
|
1078 (progn
|
|
1079 (widget-insert " ")
|
|
1080 (widget-create 'push-button
|
|
1081 :tag "Reset"
|
|
1082 :tag-glyph '("reset-up" "reset-down")
|
|
1083 :help-echo "Show a menu with reset operations"
|
|
1084 :mouse-down-action (lambda (&rest junk) t)
|
|
1085 :action (lambda (widget &optional event)
|
|
1086 (custom-reset event))))
|
|
1087 (widget-insert " ")
|
|
1088 (widget-create 'push-button
|
|
1089 :tag "Reset"
|
|
1090 :help-echo "\
|
|
1091 Reset all edited text in this buffer to reflect current values"
|
|
1092 :action 'Custom-reset-current)
|
|
1093 (widget-insert " ")
|
|
1094 (widget-create 'push-button
|
|
1095 :tag "Reset to Saved"
|
|
1096 :help-echo "\
|
|
1097 Reset all values in this buffer to their saved settings"
|
|
1098 :action 'Custom-reset-saved)
|
|
1099 (widget-insert " ")
|
|
1100 (widget-create 'push-button
|
|
1101 :tag "Reset to Standard"
|
|
1102 :help-echo "\
|
|
1103 Reset all values in this buffer to their standard settings"
|
|
1104 :action 'Custom-reset-standard))
|
|
1105 (widget-insert " ")
|
|
1106 (widget-create 'push-button
|
|
1107 :tag "Done"
|
|
1108 :help-echo "Remove the buffer"
|
|
1109 :action (lambda (widget &optional event)
|
|
1110 (Custom-buffer-done)))
|
|
1111 (widget-insert "\n"))
|
|
1112
|
|
1113 (defcustom custom-novice t
|
|
1114 "If non-nil, show help message at top of customize buffers."
|
|
1115 :type 'boolean
|
|
1116 :group 'custom-buffer)
|
|
1117
|
|
1118 (defcustom custom-display-global-buttons 'top
|
|
1119 "If `nil' don't display the global buttons. If `top' display at the
|
|
1120 beginning of custom buffers. If `bottom', display at the end."
|
|
1121 :type '(choice (const top)
|
|
1122 (const bottom)
|
|
1123 (const :tag "don't" nil))
|
|
1124 :group 'custom-buffer)
|
|
1125
|
|
1126 (defun custom-buffer-create-internal (options &optional description)
|
|
1127 (message "Creating customization buffer...")
|
|
1128 (custom-mode)
|
|
1129 (widget-insert "This is a customization buffer")
|
|
1130 (if description
|
|
1131 (widget-insert description))
|
|
1132 (when custom-novice
|
|
1133 (widget-insert ".\n\
|
|
1134 Type RET or click button2 on an active field to invoke its action.
|
|
1135 Invoke ")
|
|
1136 (widget-create 'info-link
|
|
1137 :tag "Help"
|
|
1138 :help-echo "Read the online help"
|
|
1139 "(XEmacs)Easy Customization")
|
|
1140 (widget-insert " for more information."))
|
|
1141 (widget-insert "\n")
|
|
1142 (if (equal custom-display-global-buttons 'top)
|
|
1143 (custom-buffer-create-buttons))
|
|
1144 (widget-insert "\n")
|
|
1145 (message "Creating customization items...")
|
|
1146 (setq custom-options
|
|
1147 (if (= (length options) 1)
|
|
1148 (mapcar (lambda (entry)
|
|
1149 (widget-create (nth 1 entry)
|
|
1150 :documentation-shown t
|
|
1151 :custom-state 'unknown
|
|
1152 :tag (custom-unlispify-tag-name
|
|
1153 (nth 0 entry))
|
|
1154 :value (nth 0 entry)))
|
|
1155 options)
|
|
1156 (let ((count 0)
|
|
1157 (length (length options)))
|
|
1158 (mapcar (lambda (entry)
|
|
1159 (prog2
|
|
1160 (display-message
|
|
1161 'progress
|
|
1162 (format "Creating customization items %2d%%..."
|
|
1163 (/ (* 100.0 count) length)))
|
|
1164 (widget-create (nth 1 entry)
|
|
1165 :tag (custom-unlispify-tag-name
|
|
1166 (nth 0 entry))
|
|
1167 :value (nth 0 entry))
|
|
1168 (incf count)
|
|
1169 (unless (eq (preceding-char) ?\n)
|
|
1170 (widget-insert "\n"))
|
|
1171 (widget-insert "\n")))
|
|
1172 options))))
|
|
1173 (unless (eq (preceding-char) ?\n)
|
|
1174 (widget-insert "\n"))
|
|
1175 (if (equal custom-display-global-buttons 'bottom)
|
|
1176 (custom-buffer-create-buttons))
|
|
1177 (display-message 'progress
|
|
1178 (format
|
|
1179 "Creating customization items %2d%%...done" 100))
|
|
1180 (unless (eq custom-buffer-style 'tree)
|
|
1181 (mapc 'custom-magic-reset custom-options))
|
|
1182 (message "Creating customization setup...")
|
|
1183 (widget-setup)
|
|
1184 (goto-char (point-min))
|
|
1185 (message "Creating customization buffer...done"))
|
|
1186
|
|
1187
|
|
1188 ;;; The Tree Browser.
|
|
1189
|
|
1190 ;;;###autoload
|
|
1191 (defun customize-browse (&optional group)
|
|
1192 "Create a tree browser for the customize hierarchy."
|
|
1193 (interactive)
|
|
1194 (unless group
|
|
1195 (setq group 'emacs))
|
|
1196 (let ((name "*Customize Browser*"))
|
|
1197 (kill-buffer (get-buffer-create name))
|
|
1198 (switch-to-buffer (get-buffer-create name)))
|
|
1199 (custom-mode)
|
|
1200 (widget-insert "\
|
|
1201 Square brackets show active fields; type RET or click button2
|
|
1202 on an active field to invoke its action.
|
|
1203 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
|
|
1204 (if custom-browse-only-groups
|
|
1205 (widget-insert "\
|
|
1206 Invoke the [Group] button below to edit that item in another window.\n\n")
|
|
1207 (widget-insert "Invoke the ")
|
|
1208 (widget-create 'item
|
|
1209 :format "%t"
|
|
1210 :tag "[Group]"
|
|
1211 :tag-glyph "folder")
|
|
1212 (widget-insert ", ")
|
|
1213 (widget-create 'item
|
|
1214 :format "%t"
|
|
1215 :tag "[Face]"
|
|
1216 :tag-glyph "face")
|
|
1217 (widget-insert ", and ")
|
|
1218 (widget-create 'item
|
|
1219 :format "%t"
|
|
1220 :tag "[Option]"
|
|
1221 :tag-glyph "option")
|
|
1222 (widget-insert " buttons below to edit that
|
|
1223 item in another window.\n\n"))
|
|
1224 (let ((custom-buffer-style 'tree))
|
|
1225 (widget-create 'custom-group
|
|
1226 :custom-last t
|
|
1227 :custom-state 'unknown
|
|
1228 :tag (custom-unlispify-tag-name group)
|
|
1229 :value group))
|
|
1230 (widget-add-change)
|
|
1231 (goto-char (point-min)))
|
|
1232
|
|
1233 (define-widget 'custom-browse-visibility 'item
|
|
1234 "Control visibility of of items in the customize tree browser."
|
|
1235 :format "%[[%t]%]"
|
|
1236 :action 'custom-browse-visibility-action)
|
|
1237
|
|
1238 (defun custom-browse-visibility-action (widget &rest ignore)
|
|
1239 (let ((custom-buffer-style 'tree))
|
|
1240 (custom-toggle-parent widget)))
|
|
1241
|
|
1242 (define-widget 'custom-browse-group-tag 'push-button
|
|
1243 "Show parent in other window when activated."
|
|
1244 :tag "Group"
|
|
1245 :tag-glyph "folder"
|
|
1246 :action 'custom-browse-group-tag-action)
|
|
1247
|
|
1248 (defun custom-browse-group-tag-action (widget &rest ignore)
|
|
1249 (let ((parent (widget-get widget :parent)))
|
|
1250 (customize-group-other-window (widget-value parent))))
|
|
1251
|
|
1252 (define-widget 'custom-browse-variable-tag 'push-button
|
|
1253 "Show parent in other window when activated."
|
|
1254 :tag "Option"
|
|
1255 :tag-glyph "option"
|
|
1256 :action 'custom-browse-variable-tag-action)
|
|
1257
|
|
1258 (defun custom-browse-variable-tag-action (widget &rest ignore)
|
|
1259 (let ((parent (widget-get widget :parent)))
|
|
1260 (customize-variable-other-window (widget-value parent))))
|
|
1261
|
|
1262 (define-widget 'custom-browse-face-tag 'push-button
|
|
1263 "Show parent in other window when activated."
|
|
1264 :tag "Face"
|
|
1265 :tag-glyph "face"
|
|
1266 :action 'custom-browse-face-tag-action)
|
|
1267
|
|
1268 (defun custom-browse-face-tag-action (widget &rest ignore)
|
|
1269 (let ((parent (widget-get widget :parent)))
|
|
1270 (customize-face-other-window (widget-value parent))))
|
|
1271
|
|
1272 (defconst custom-browse-alist '((" " "space")
|
|
1273 (" | " "vertical")
|
|
1274 ("-\\ " "top")
|
|
1275 (" |-" "middle")
|
|
1276 (" `-" "bottom")))
|
|
1277
|
|
1278 (defun custom-browse-insert-prefix (prefix)
|
|
1279 "Insert PREFIX. On XEmacs convert it to line graphics."
|
440
|
1280 ;; #### Unfinished.
|
428
|
1281 (if nil ; (string-match "XEmacs" emacs-version)
|
|
1282 (progn
|
|
1283 (insert "*")
|
|
1284 (while (not (string-equal prefix ""))
|
|
1285 (let ((entry (substring prefix 0 3)))
|
|
1286 (setq prefix (substring prefix 3))
|
|
1287 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
|
|
1288 (name (nth 1 (assoc entry custom-browse-alist))))
|
|
1289 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
|
|
1290 (overlay-put overlay 'start-open t)
|
|
1291 (overlay-put overlay 'end-open t)))))
|
|
1292 (insert prefix)))
|
|
1293
|
|
1294
|
|
1295 ;;; Modification of Basic Widgets.
|
|
1296 ;;
|
|
1297 ;; We add extra properties to the basic widgets needed here. This is
|
|
1298 ;; fine, as long as we are careful to stay within out own namespace.
|
|
1299 ;;
|
|
1300 ;; We want simple widgets to be displayed by default, but complex
|
|
1301 ;; widgets to be hidden.
|
|
1302
|
|
1303 (widget-put (get 'item 'widget-type) :custom-show t)
|
|
1304 (widget-put (get 'editable-field 'widget-type)
|
|
1305 :custom-show (lambda (widget value)
|
|
1306 ;; This used to call pp-to-string
|
|
1307 (let ((pp (widget-prettyprint-to-string value)))
|
|
1308 (cond ((string-match "\n" pp)
|
|
1309 nil)
|
|
1310 ((> (length pp) 40)
|
|
1311 nil)
|
|
1312 (t t)))))
|
|
1313 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
|
|
1314
|
|
1315 ;;; The `custom-manual' Widget.
|
|
1316
|
|
1317 (define-widget 'custom-manual 'info-link
|
|
1318 "Link to the manual entry for this customization option."
|
|
1319 :tag "Manual")
|
|
1320
|
|
1321 ;;; The `custom-magic' Widget.
|
|
1322
|
|
1323 (defgroup custom-magic-faces nil
|
|
1324 "Faces used by the magic button."
|
|
1325 :group 'custom-faces
|
|
1326 :group 'custom-buffer)
|
|
1327
|
|
1328 (defface custom-invalid-face '((((class color))
|
|
1329 (:foreground "yellow" :background "red"))
|
|
1330 (t
|
|
1331 (:bold t :italic t :underline t)))
|
|
1332 "Face used when the customize item is invalid."
|
|
1333 :group 'custom-magic-faces)
|
|
1334
|
|
1335 (defface custom-rogue-face '((((class color))
|
|
1336 (:foreground "pink" :background "black"))
|
|
1337 (t
|
|
1338 (:underline t)))
|
|
1339 "Face used when the customize item is not defined for customization."
|
|
1340 :group 'custom-magic-faces)
|
|
1341
|
|
1342 (defface custom-modified-face '((((class color))
|
|
1343 (:foreground "white" :background "blue"))
|
|
1344 (t
|
|
1345 (:italic t :bold)))
|
|
1346 "Face used when the customize item has been modified."
|
|
1347 :group 'custom-magic-faces)
|
|
1348
|
|
1349 (defface custom-set-face '((((class color))
|
|
1350 (:foreground "blue" :background "white"))
|
|
1351 (t
|
|
1352 (:italic t)))
|
|
1353 "Face used when the customize item has been set."
|
|
1354 :group 'custom-magic-faces)
|
|
1355
|
|
1356 (defface custom-changed-face '((((class color))
|
|
1357 (:foreground "white" :background "blue"))
|
|
1358 (t
|
|
1359 (:italic t)))
|
|
1360 "Face used when the customize item has been changed."
|
|
1361 :group 'custom-magic-faces)
|
|
1362
|
|
1363 (defface custom-saved-face '((t (:underline t)))
|
|
1364 "Face used when the customize item has been saved."
|
|
1365 :group 'custom-magic-faces)
|
|
1366
|
|
1367 (defconst custom-magic-alist '((nil "#" underline "\
|
|
1368 uninitialized, you should not see this.")
|
|
1369 (unknown "?" italic "\
|
|
1370 unknown, you should not see this.")
|
|
1371 (hidden "-" default "\
|
|
1372 hidden, invoke \"Show\" button in the previous line to show." "\
|
|
1373 group now hidden, invoke the above \"Show\" button to show contents.")
|
|
1374 (invalid "x" custom-invalid-face "\
|
|
1375 the value displayed for this %c is invalid and cannot be set.")
|
|
1376 (modified "*" custom-modified-face "\
|
|
1377 you have edited the value as text, but you have not set the %c." "\
|
|
1378 you have edited something in this group, but not set it.")
|
|
1379 (set "+" custom-set-face "\
|
|
1380 you have set this %c, but not saved it for future sessions." "\
|
|
1381 something in this group has been set, but not saved.")
|
|
1382 (changed ":" custom-changed-face "\
|
|
1383 this %c has been changed outside the customize buffer." "\
|
|
1384 something in this group has been changed outside customize.")
|
|
1385 (saved "!" custom-saved-face "\
|
|
1386 this %c has been set and saved." "\
|
|
1387 something in this group has been set and saved.")
|
|
1388 (rogue "@" custom-rogue-face "\
|
|
1389 this %c has not been changed with customize." "\
|
|
1390 something in this group is not prepared for customization.")
|
|
1391 (standard " " nil "\
|
|
1392 this %c is unchanged from its standard setting." "\
|
|
1393 visible group members are all at standard settings."))
|
|
1394 "Alist of customize option states.
|
|
1395 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
|
|
1396
|
|
1397 STATE is one of the following symbols:
|
|
1398
|
|
1399 `nil'
|
|
1400 For internal use, should never occur.
|
|
1401 `unknown'
|
|
1402 For internal use, should never occur.
|
|
1403 `hidden'
|
|
1404 This item is not being displayed.
|
|
1405 `invalid'
|
|
1406 This item is modified, but has an invalid form.
|
|
1407 `modified'
|
|
1408 This item is modified, and has a valid form.
|
|
1409 `set'
|
|
1410 This item has been set but not saved.
|
|
1411 `changed'
|
|
1412 The current value of this item has been changed temporarily.
|
|
1413 `saved'
|
|
1414 This item is marked for saving.
|
|
1415 `rogue'
|
|
1416 This item has no customization information.
|
|
1417 `standard'
|
|
1418 This item is unchanged from the standard setting.
|
|
1419
|
|
1420 MAGIC is a string used to present that state.
|
|
1421
|
|
1422 FACE is a face used to present the state.
|
|
1423
|
|
1424 ITEM-DESC is a string describing the state for options.
|
|
1425
|
|
1426 GROUP-DESC is a string describing the state for groups. If this is
|
|
1427 left out, ITEM-DESC will be used.
|
|
1428
|
|
1429 The string %c in either description will be replaced with the
|
|
1430 category of the item. These are `group'. `option', and `face'.
|
|
1431
|
|
1432 The list should be sorted most significant first.")
|
|
1433
|
|
1434 (defcustom custom-magic-show 'long
|
|
1435 "If non-nil, show textual description of the state.
|
|
1436 If `long', show a full-line description, not just one word."
|
|
1437 :type '(choice (const :tag "no" nil)
|
|
1438 (const short)
|
|
1439 (const long))
|
|
1440 :group 'custom-buffer)
|
|
1441
|
|
1442 (defcustom custom-magic-show-hidden '(option face)
|
|
1443 "Control whether the State button is shown for hidden items.
|
|
1444 The value should be a list with the custom categories where the State
|
|
1445 button should be visible. Possible categories are `group', `option',
|
|
1446 and `face'."
|
|
1447 :type '(set (const group) (const option) (const face))
|
|
1448 :group 'custom-buffer)
|
|
1449
|
|
1450 (defcustom custom-magic-show-button nil
|
|
1451 "Show a \"magic\" button indicating the state of each customization option."
|
|
1452 :type 'boolean
|
|
1453 :group 'custom-buffer)
|
|
1454
|
|
1455 (define-widget 'custom-magic 'default
|
|
1456 "Show and manipulate state for a customization option."
|
|
1457 :format "%v"
|
|
1458 :action 'widget-parent-action
|
|
1459 :notify 'ignore
|
|
1460 :value-get 'ignore
|
|
1461 :value-create 'custom-magic-value-create
|
|
1462 :value-delete 'widget-children-value-delete)
|
|
1463
|
|
1464 (defun widget-magic-mouse-down-action (widget &optional event)
|
|
1465 ;; Non-nil unless hidden.
|
|
1466 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
|
|
1467 :custom-state)
|
|
1468 'hidden)))
|
|
1469
|
|
1470 (defun custom-magic-value-create (widget)
|
|
1471 ;; Create compact status report for WIDGET.
|
|
1472 (let* ((parent (widget-get widget :parent))
|
|
1473 (state (widget-get parent :custom-state))
|
|
1474 (hidden (eq state 'hidden))
|
|
1475 (entry (assq state custom-magic-alist))
|
|
1476 (magic (nth 1 entry))
|
|
1477 (face (nth 2 entry))
|
|
1478 (category (widget-get parent :custom-category))
|
|
1479 (text (or (and (eq category 'group)
|
|
1480 (nth 4 entry))
|
|
1481 (nth 3 entry)))
|
|
1482 (form (widget-get parent :custom-form))
|
|
1483 children)
|
|
1484 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
|
|
1485 (setq text (concat (match-string 1 text)
|
|
1486 (symbol-name category)
|
|
1487 (match-string 2 text))))
|
|
1488 (when (and custom-magic-show
|
|
1489 (or (not hidden)
|
|
1490 (memq category custom-magic-show-hidden)))
|
|
1491 (insert " ")
|
|
1492 (when (and (eq category 'group)
|
|
1493 (not (and (eq custom-buffer-style 'links)
|
|
1494 (> (widget-get parent :custom-level) 1))))
|
|
1495 (insert-char ?\ (* custom-buffer-indent
|
|
1496 (widget-get parent :custom-level))))
|
|
1497 (push (widget-create-child-and-convert
|
|
1498 widget 'choice-item
|
|
1499 :help-echo "Change the state of this item"
|
|
1500 :format (if hidden "%t" "%[%t%]")
|
|
1501 :button-prefix 'widget-push-button-prefix
|
|
1502 :button-suffix 'widget-push-button-suffix
|
|
1503 :mouse-down-action 'widget-magic-mouse-down-action
|
|
1504 :tag "State"
|
|
1505 ;;:tag-glyph (or hidden '("state-up" "state-down"))
|
|
1506 )
|
|
1507 children)
|
|
1508 (insert ": ")
|
|
1509 (let ((start (point)))
|
|
1510 (if (eq custom-magic-show 'long)
|
|
1511 (insert text)
|
|
1512 (insert (symbol-name state)))
|
|
1513 (cond ((eq form 'lisp)
|
|
1514 (insert " (lisp)"))
|
|
1515 ((eq form 'mismatch)
|
|
1516 (insert " (mismatch)")))
|
|
1517 (put-text-property start (point) 'face 'custom-state-face))
|
|
1518 (insert "\n"))
|
|
1519 (when (and (eq category 'group)
|
|
1520 (not (and (eq custom-buffer-style 'links)
|
|
1521 (> (widget-get parent :custom-level) 1))))
|
|
1522 (insert-char ?\ (* custom-buffer-indent
|
|
1523 (widget-get parent :custom-level))))
|
|
1524 (when custom-magic-show-button
|
|
1525 (when custom-magic-show
|
|
1526 (let ((indent (widget-get parent :indent)))
|
|
1527 (when indent
|
|
1528 (insert-char ?\ indent))))
|
|
1529 (push (widget-create-child-and-convert
|
|
1530 widget 'choice-item
|
|
1531 :mouse-down-action 'widget-magic-mouse-down-action
|
|
1532 :button-face face
|
|
1533 :button-prefix ""
|
|
1534 :button-suffix ""
|
|
1535 :help-echo "Change the state"
|
|
1536 :format (if hidden "%t" "%[%t%]")
|
|
1537 :tag (if (memq form '(lisp mismatch))
|
|
1538 (concat "(" magic ")")
|
|
1539 (concat "[" magic "]")))
|
|
1540 children)
|
|
1541 (insert " "))
|
|
1542 (widget-put widget :children children)))
|
|
1543
|
|
1544 (defun custom-magic-reset (widget)
|
|
1545 "Redraw the :custom-magic property of WIDGET."
|
|
1546 (let ((magic (widget-get widget :custom-magic)))
|
|
1547 (widget-value-set magic (widget-value magic))))
|
|
1548
|
|
1549 ;;; The `custom' Widget.
|
|
1550
|
|
1551 (defface custom-button-face '((t (:bold t)))
|
|
1552 "Face used for buttons in customization buffers."
|
|
1553 :group 'custom-faces)
|
|
1554
|
|
1555 (defface custom-documentation-face nil
|
|
1556 "Face used for documentation strings in customization buffers."
|
|
1557 :group 'custom-faces)
|
|
1558
|
|
1559 (defface custom-state-face '((((class color)
|
|
1560 (background dark))
|
|
1561 (:foreground "lime green"))
|
|
1562 (((class color)
|
|
1563 (background light))
|
|
1564 (:foreground "dark green"))
|
|
1565 (t nil))
|
|
1566 "Face used for State descriptions in the customize buffer."
|
|
1567 :group 'custom-faces)
|
|
1568
|
|
1569 (define-widget 'custom 'default
|
|
1570 "Customize a user option."
|
|
1571 :format "%v"
|
|
1572 :convert-widget 'custom-convert-widget
|
|
1573 :notify 'custom-notify
|
|
1574 :custom-prefix ""
|
|
1575 :custom-level 1
|
|
1576 :custom-state 'hidden
|
|
1577 :documentation-property 'widget-subclass-responsibility
|
|
1578 :value-create 'widget-subclass-responsibility
|
|
1579 :value-delete 'widget-children-value-delete
|
|
1580 :value-get 'widget-value-value-get
|
|
1581 :validate 'widget-children-validate
|
|
1582 :match (lambda (widget value) (symbolp value)))
|
|
1583
|
|
1584 (defun custom-convert-widget (widget)
|
|
1585 ;; Initialize :value and :tag from :args in WIDGET.
|
|
1586 (let ((args (widget-get widget :args)))
|
|
1587 (when args
|
|
1588 (widget-put widget :value (widget-apply widget
|
|
1589 :value-to-internal (car args)))
|
|
1590 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
|
|
1591 (widget-put widget :args nil)))
|
|
1592 widget)
|
|
1593
|
|
1594 (defun custom-notify (widget &rest args)
|
|
1595 "Keep track of changes."
|
|
1596 (let ((state (widget-get widget :custom-state)))
|
|
1597 (unless (eq state 'modified)
|
|
1598 (unless (memq state '(nil unknown hidden))
|
|
1599 (widget-put widget :custom-state 'modified))
|
|
1600 (custom-magic-reset widget)
|
|
1601 (apply 'widget-default-notify widget args))))
|
|
1602
|
|
1603 (defun custom-redraw (widget)
|
|
1604 "Redraw WIDGET with current settings."
|
|
1605 (let ((line (count-lines (point-min) (point)))
|
|
1606 (column (current-column))
|
|
1607 (pos (point))
|
|
1608 (from (marker-position (widget-get widget :from)))
|
|
1609 (to (marker-position (widget-get widget :to))))
|
|
1610 (save-excursion
|
|
1611 (widget-value-set widget (widget-value widget))
|
|
1612 (custom-redraw-magic widget))
|
|
1613 (when (and (>= pos from) (<= pos to))
|
|
1614 (condition-case nil
|
|
1615 (progn
|
|
1616 (if (> column 0)
|
|
1617 (goto-line line)
|
|
1618 (goto-line (1+ line)))
|
|
1619 (move-to-column column))
|
|
1620 (error nil)))))
|
|
1621
|
|
1622 (defun custom-redraw-magic (widget)
|
|
1623 "Redraw WIDGET state with current settings."
|
|
1624 (while widget
|
|
1625 (let ((magic (widget-get widget :custom-magic)))
|
|
1626 (cond (magic
|
|
1627 (widget-value-set magic (widget-value magic))
|
|
1628 (when (setq widget (widget-get widget :group))
|
|
1629 (custom-group-state-update widget)))
|
|
1630 (t
|
|
1631 (setq widget nil)))))
|
|
1632 (widget-setup))
|
|
1633
|
|
1634 (defun custom-show (widget value)
|
|
1635 "Non-nil if WIDGET should be shown with VALUE by default."
|
|
1636 (let ((show (widget-get widget :custom-show)))
|
|
1637 (cond ((null show)
|
|
1638 nil)
|
|
1639 ((eq t show)
|
|
1640 t)
|
|
1641 (t
|
|
1642 (funcall show widget value)))))
|
|
1643
|
|
1644 (defvar custom-load-recursion nil
|
|
1645 "Hack to avoid recursive dependencies.")
|
|
1646
|
|
1647 (defun custom-load-symbol (symbol)
|
|
1648 "Load all dependencies for SYMBOL."
|
|
1649 (unless custom-load-recursion
|
|
1650 (let ((custom-load-recursion t)
|
|
1651 (loads (get symbol 'custom-loads))
|
|
1652 load)
|
|
1653 (while loads
|
|
1654 (setq load (car loads)
|
|
1655 loads (cdr loads))
|
|
1656 (cond ((symbolp load)
|
|
1657 (condition-case nil
|
|
1658 (require load)
|
|
1659 (error nil)))
|
|
1660 ;; Don't reload a file already loaded.
|
|
1661 ((and (boundp 'preloaded-file-list)
|
|
1662 (member load preloaded-file-list)))
|
|
1663 ((assoc load load-history))
|
|
1664 ((assoc (locate-library load) load-history))
|
|
1665 (t
|
|
1666 (condition-case nil
|
|
1667 ;; Without this, we would load cus-edit recursively.
|
|
1668 ;; We are still loading it when we call this,
|
|
1669 ;; and it is not in load-history yet.
|
|
1670 (or (equal load "cus-edit")
|
|
1671 (load-library load))
|
|
1672 (error nil))))))))
|
|
1673
|
|
1674 (defun custom-load-widget (widget)
|
|
1675 "Load all dependencies for WIDGET."
|
|
1676 (custom-load-symbol (widget-value widget)))
|
|
1677
|
|
1678 (defun custom-unloaded-symbol-p (symbol)
|
|
1679 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
|
|
1680 (let ((found nil)
|
|
1681 (loads (get symbol 'custom-loads))
|
|
1682 load)
|
|
1683 (while loads
|
|
1684 (setq load (car loads)
|
|
1685 loads (cdr loads))
|
|
1686 (cond ((symbolp load)
|
|
1687 (unless (featurep load)
|
|
1688 (setq found t)))
|
|
1689 ((assoc load load-history))
|
|
1690 ((assoc (locate-library load) load-history)
|
|
1691 ;; #### WTF???
|
|
1692 (message nil))
|
|
1693 (t
|
|
1694 (setq found t))))
|
|
1695 found))
|
|
1696
|
|
1697 (defun custom-unloaded-widget-p (widget)
|
|
1698 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
|
|
1699 (custom-unloaded-symbol-p (widget-value widget)))
|
|
1700
|
|
1701 (defun custom-toggle-hide (widget)
|
|
1702 "Toggle visibility of WIDGET."
|
|
1703 (custom-load-widget widget)
|
|
1704 (let ((state (widget-get widget :custom-state)))
|
|
1705 (cond ((memq state '(invalid modified))
|
|
1706 (error "There are unset changes"))
|
|
1707 ((eq state 'hidden)
|
|
1708 (widget-put widget :custom-state 'unknown))
|
|
1709 (t
|
|
1710 (widget-put widget :documentation-shown nil)
|
|
1711 (widget-put widget :custom-state 'hidden)))
|
|
1712 (custom-redraw widget)
|
|
1713 (widget-setup)))
|
|
1714
|
|
1715 (defun custom-toggle-parent (widget &rest ignore)
|
|
1716 "Toggle visibility of parent of WIDGET."
|
|
1717 (custom-toggle-hide (widget-get widget :parent)))
|
|
1718
|
|
1719 (defun custom-add-see-also (widget &optional prefix)
|
|
1720 "Add `See also ...' to WIDGET if there are any links.
|
|
1721 Insert PREFIX first if non-nil."
|
|
1722 (let* ((symbol (widget-get widget :value))
|
|
1723 (links (get symbol 'custom-links))
|
|
1724 (many (> (length links) 2))
|
|
1725 (buttons (widget-get widget :buttons))
|
|
1726 (indent (widget-get widget :indent)))
|
|
1727 (when links
|
|
1728 (when indent
|
|
1729 (insert-char ?\ indent))
|
|
1730 (when prefix
|
|
1731 (insert prefix))
|
|
1732 (insert "See also ")
|
|
1733 (while links
|
|
1734 (push (widget-create-child-and-convert widget (car links))
|
|
1735 buttons)
|
|
1736 (setq links (cdr links))
|
|
1737 (cond ((null links)
|
|
1738 (insert ".\n"))
|
|
1739 ((null (cdr links))
|
|
1740 (if many
|
|
1741 (insert ", and ")
|
|
1742 (insert " and ")))
|
|
1743 (t
|
|
1744 (insert ", "))))
|
|
1745 (widget-put widget :buttons buttons))))
|
|
1746
|
|
1747 (defun custom-add-parent-links (widget &optional initial-string)
|
|
1748 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
|
|
1749 The value if non-nil if any parents were found.
|
|
1750 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
|
|
1751 (let ((name (widget-value widget))
|
|
1752 (type (widget-type widget))
|
|
1753 (buttons (widget-get widget :buttons))
|
|
1754 (start (point))
|
|
1755 found)
|
|
1756 (insert (or initial-string "Parent groups:"))
|
|
1757 (maphash (lambda (group ignore)
|
|
1758 (let ((entry (assq name (get group 'custom-group))))
|
|
1759 (when (eq (nth 1 entry) type)
|
|
1760 (insert " ")
|
|
1761 (push (widget-create-child-and-convert
|
|
1762 widget 'custom-group-link
|
|
1763 :tag (custom-unlispify-tag-name group)
|
|
1764 group)
|
|
1765 buttons)
|
|
1766 (setq found t))))
|
|
1767 custom-group-hash-table)
|
|
1768 (widget-put widget :buttons buttons)
|
|
1769 (if found
|
|
1770 (insert "\n")
|
|
1771 (delete-region start (point)))
|
|
1772 found))
|
|
1773
|
|
1774 ;;; The `custom-comment' Widget.
|
|
1775
|
|
1776 ;; like the editable field
|
|
1777 (defface custom-comment-face '((((class grayscale color)
|
|
1778 (background light))
|
|
1779 (:background "gray85"))
|
|
1780 (((class grayscale color)
|
|
1781 (background dark))
|
|
1782 (:background "dim gray"))
|
|
1783 (t
|
|
1784 (:italic t)))
|
|
1785 "Face used for comments on variables or faces"
|
|
1786 :group 'custom-faces)
|
|
1787
|
|
1788 ;; like font-lock-comment-face
|
|
1789 (defface custom-comment-tag-face
|
|
1790 '((((class color) (background dark)) (:foreground "gray80"))
|
|
1791 (((class color) (background light)) (:foreground "blue4"))
|
|
1792 (((class grayscale) (background light))
|
|
1793 (:foreground "DimGray" :bold t :italic t))
|
|
1794 (((class grayscale) (background dark))
|
|
1795 (:foreground "LightGray" :bold t :italic t))
|
|
1796 (t (:bold t)))
|
|
1797 "Face used for variables or faces comment tags"
|
|
1798 :group 'custom-faces)
|
|
1799
|
|
1800 (define-widget 'custom-comment 'string
|
|
1801 "User comment"
|
|
1802 :tag "Comment"
|
|
1803 :help-echo "Edit a comment here"
|
|
1804 :sample-face 'custom-comment-tag-face
|
|
1805 :value-face 'custom-comment-face
|
|
1806 :value-set 'custom-comment-value-set
|
|
1807 :create 'custom-comment-create
|
|
1808 :delete 'custom-comment-delete)
|
|
1809
|
|
1810 (defun custom-comment-create (widget)
|
|
1811 (let (ext)
|
|
1812 (widget-default-create widget)
|
|
1813 (widget-put widget :comment-extent
|
|
1814 (setq ext (make-extent (widget-get widget :from)
|
|
1815 (widget-get widget :to))))
|
|
1816 (set-extent-property ext 'start-open t)
|
|
1817 (when (equal (widget-get widget :value) "")
|
|
1818 (set-extent-property ext 'invisible t))
|
|
1819 ))
|
|
1820
|
|
1821 (defun custom-comment-delete (widget)
|
|
1822 (widget-default-delete widget)
|
|
1823 (delete-extent (widget-get widget :comment-extent)))
|
|
1824
|
|
1825 (defun custom-comment-value-set (widget value)
|
|
1826 (widget-default-value-set widget value)
|
|
1827 (if (equal value "")
|
|
1828 (set-extent-property (widget-get widget :comment-extent)
|
|
1829 'invisible t)
|
|
1830 (set-extent-property (widget-get widget :comment-extent)
|
|
1831 'invisible nil)))
|
|
1832
|
|
1833 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
|
|
1834 ;; the global custom one
|
|
1835 (defun custom-comment-show (widget)
|
|
1836 (set-extent-property
|
|
1837 (widget-get (widget-get widget :comment-widget) :comment-extent)
|
|
1838 'invisible nil))
|
|
1839
|
|
1840 (defun custom-comment-invisible-p (widget)
|
|
1841 (extent-property
|
|
1842 (widget-get (widget-get widget :comment-widget) :comment-extent)
|
|
1843 'invisible))
|
|
1844
|
|
1845 ;;; The `custom-variable' Widget.
|
|
1846
|
|
1847 (defface custom-variable-tag-face '((((class color)
|
|
1848 (background dark))
|
|
1849 (:foreground "light blue" :underline t))
|
|
1850 (((class color)
|
|
1851 (background light))
|
|
1852 (:foreground "blue" :underline t))
|
|
1853 (t (:underline t)))
|
|
1854 "Face used for unpushable variable tags."
|
|
1855 :group 'custom-faces)
|
|
1856
|
|
1857 (defface custom-variable-button-face '((t (:underline t :bold t)))
|
|
1858 "Face used for pushable variable tags."
|
|
1859 :group 'custom-faces)
|
|
1860
|
|
1861 (defcustom custom-variable-default-form 'edit
|
|
1862 "Default form of displaying variable values."
|
|
1863 :type '(choice (const edit)
|
|
1864 (const lisp))
|
|
1865 :group 'custom-buffer)
|
|
1866
|
|
1867 (define-widget 'custom-variable 'custom
|
|
1868 "Customize variable."
|
|
1869 :format "%v"
|
|
1870 :help-echo "Set or reset this variable"
|
|
1871 :documentation-property 'variable-documentation
|
|
1872 :custom-category 'option
|
|
1873 :custom-state nil
|
|
1874 :custom-menu 'custom-variable-menu-create
|
|
1875 :custom-form nil ; defaults to value of `custom-variable-default-form'
|
|
1876 :value-create 'custom-variable-value-create
|
|
1877 :action 'custom-variable-action
|
|
1878 :custom-set 'custom-variable-set
|
480
|
1879 :custom-pre-save 'custom-variable-pre-save
|
428
|
1880 :custom-save 'custom-variable-save
|
480
|
1881 :custom-post-save 'custom-variable-post-save
|
428
|
1882 :custom-reset-current 'custom-redraw
|
|
1883 :custom-reset-saved 'custom-variable-reset-saved
|
480
|
1884 :custom-pre-reset-standard 'custom-variable-pre-reset-standard
|
|
1885 :custom-reset-standard 'custom-variable-reset-standard
|
|
1886 :custom-post-reset-standard 'custom-variable-post-reset-standard)
|
428
|
1887
|
|
1888 (defun custom-variable-type (symbol)
|
|
1889 "Return a widget suitable for editing the value of SYMBOL.
|
|
1890 If SYMBOL has a `custom-type' property, use that.
|
|
1891 Otherwise, look up symbol in `custom-guess-type-alist'."
|
|
1892 (let* ((type (or (get symbol 'custom-type)
|
|
1893 (and (not (get symbol 'standard-value))
|
|
1894 (custom-guess-type symbol))
|
|
1895 'sexp))
|
|
1896 (options (get symbol 'custom-options))
|
|
1897 (tmp (if (listp type)
|
|
1898 (copy-sequence type)
|
|
1899 (list type))))
|
|
1900 (when options
|
|
1901 (widget-put tmp :options options))
|
|
1902 tmp))
|
|
1903
|
|
1904 (defun custom-variable-value-create (widget)
|
|
1905 "Here is where you edit the variables value."
|
|
1906 (custom-load-widget widget)
|
|
1907 (unless (widget-get widget :custom-form)
|
|
1908 (widget-put widget :custom-form custom-variable-default-form))
|
|
1909 (let* ((buttons (widget-get widget :buttons))
|
|
1910 (children (widget-get widget :children))
|
|
1911 (form (widget-get widget :custom-form))
|
|
1912 (state (widget-get widget :custom-state))
|
|
1913 (symbol (widget-get widget :value))
|
|
1914 (tag (widget-get widget :tag))
|
|
1915 (type (custom-variable-type symbol))
|
|
1916 (conv (widget-convert type))
|
|
1917 (get (or (get symbol 'custom-get) 'default-value))
|
|
1918 (prefix (widget-get widget :custom-prefix))
|
|
1919 (last (widget-get widget :custom-last))
|
|
1920 (value (if (default-boundp symbol)
|
|
1921 (funcall get symbol)
|
|
1922 (widget-get conv :value))))
|
|
1923 ;; If the widget is new, the child determine whether it is hidden.
|
|
1924 (cond (state)
|
|
1925 ((custom-show type value)
|
|
1926 (setq state 'unknown))
|
|
1927 (t
|
|
1928 (setq state 'hidden)))
|
|
1929 ;; If we don't know the state, see if we need to edit it in lisp form.
|
|
1930 (when (eq state 'unknown)
|
|
1931 (unless (widget-apply conv :match value)
|
|
1932 ;; (widget-apply (widget-convert type) :match value)
|
|
1933 (setq form 'mismatch)))
|
|
1934 ;; Now we can create the child widget.
|
|
1935 (cond ((eq custom-buffer-style 'tree)
|
|
1936 (insert prefix (if last " `--- " " |--- "))
|
|
1937 (push (widget-create-child-and-convert
|
|
1938 widget 'custom-browse-variable-tag)
|
|
1939 buttons)
|
|
1940 (insert " " tag "\n")
|
|
1941 (widget-put widget :buttons buttons))
|
|
1942 ((eq state 'hidden)
|
|
1943 ;; Indicate hidden value.
|
|
1944 (push (widget-create-child-and-convert
|
|
1945 widget 'item
|
|
1946 :format "%{%t%}: "
|
|
1947 :sample-face 'custom-variable-tag-face
|
|
1948 :tag tag
|
|
1949 :parent widget)
|
|
1950 buttons)
|
|
1951 (push (widget-create-child-and-convert
|
|
1952 widget 'visibility
|
|
1953 :help-echo "Show the value of this option"
|
|
1954 :action 'custom-toggle-parent
|
|
1955 nil)
|
|
1956 buttons))
|
|
1957 ((memq form '(lisp mismatch))
|
|
1958 ;; In lisp mode edit the saved value when possible.
|
|
1959 (let* ((value (cond ((get symbol 'saved-value)
|
|
1960 (car (get symbol 'saved-value)))
|
|
1961 ((get symbol 'standard-value)
|
|
1962 (car (get symbol 'standard-value)))
|
|
1963 ((default-boundp symbol)
|
|
1964 (custom-quote (funcall get symbol)))
|
|
1965 (t
|
|
1966 (custom-quote (widget-get conv :value))))))
|
|
1967 (insert (symbol-name symbol) ": ")
|
|
1968 (push (widget-create-child-and-convert
|
|
1969 widget 'visibility
|
|
1970 :help-echo "Hide the value of this option"
|
|
1971 :action 'custom-toggle-parent
|
|
1972 t)
|
|
1973 buttons)
|
|
1974 (insert " ")
|
|
1975 (push (widget-create-child-and-convert
|
|
1976 widget 'sexp
|
|
1977 :button-face 'custom-variable-button-face
|
|
1978 :format "%v"
|
|
1979 :tag (symbol-name symbol)
|
|
1980 :parent widget
|
|
1981 :value value)
|
|
1982 children)))
|
|
1983 (t
|
|
1984 ;; Edit mode.
|
|
1985 (let* ((format (widget-get type :format))
|
|
1986 tag-format value-format)
|
|
1987 (while (not (string-match ":" format))
|
|
1988 (setq format (signal 'error (list "Bad format" format))))
|
|
1989 (setq tag-format (substring format 0 (match-end 0)))
|
|
1990 (setq value-format (substring format (match-end 0)))
|
|
1991 (push (widget-create-child-and-convert
|
|
1992 widget 'item
|
|
1993 :format tag-format
|
|
1994 :action 'custom-tag-action
|
|
1995 :help-echo "Change value of this option"
|
|
1996 :mouse-down-action 'custom-tag-mouse-down-action
|
|
1997 :button-face 'custom-variable-button-face
|
|
1998 :sample-face 'custom-variable-tag-face
|
|
1999 tag)
|
|
2000 buttons)
|
|
2001 (insert " ")
|
|
2002 (push (widget-create-child-and-convert
|
|
2003 widget 'visibility
|
|
2004 :help-echo "Hide the value of this option"
|
|
2005 :action 'custom-toggle-parent
|
|
2006 t)
|
|
2007 buttons)
|
|
2008 (push (widget-create-child-and-convert
|
|
2009 widget type
|
|
2010 :format value-format
|
|
2011 :value value)
|
|
2012 children))))
|
|
2013 (unless (eq custom-buffer-style 'tree)
|
|
2014 (unless (eq (preceding-char) ?\n)
|
|
2015 (widget-insert "\n"))
|
|
2016 ;; Create the magic button.
|
|
2017 (let ((magic (widget-create-child-and-convert
|
|
2018 widget 'custom-magic nil)))
|
|
2019 (widget-put widget :custom-magic magic)
|
|
2020 (push magic buttons))
|
|
2021 ;; Insert documentation.
|
440
|
2022 ;; #### NOTE: this is ugly!!!! I need to do update the :buttons property
|
428
|
2023 ;; before the call to `widget-default-format-handler'. Otherwise, I
|
444
|
2024 ;; lose my current `buttons'. This function shouldn't be called like
|
428
|
2025 ;; this anyway. The doc string widget should be added like the others.
|
|
2026 ;; --dv
|
|
2027 (widget-put widget :buttons buttons)
|
|
2028 (widget-default-format-handler widget ?h)
|
|
2029 ;; The comment field
|
|
2030 (unless (eq state 'hidden)
|
|
2031 (let* ((comment (get symbol 'variable-comment))
|
|
2032 (comment-widget
|
|
2033 (widget-create-child-and-convert
|
|
2034 widget 'custom-comment
|
|
2035 :parent widget
|
|
2036 :value (or comment ""))))
|
|
2037 (widget-put widget :comment-widget comment-widget)
|
|
2038 ;; Don't push it !!! Custom assumes that the first child is the
|
|
2039 ;; value one.
|
|
2040 (setq children (append children (list comment-widget)))))
|
|
2041 ;; Update the rest of the properties properties.
|
|
2042 (widget-put widget :custom-form form)
|
|
2043 (widget-put widget :children children)
|
|
2044 ;; Now update the state.
|
|
2045 (if (eq state 'hidden)
|
|
2046 (widget-put widget :custom-state state)
|
|
2047 (custom-variable-state-set widget))
|
|
2048 ;; See also.
|
|
2049 (unless (eq state 'hidden)
|
|
2050 (when (eq (widget-get widget :custom-level) 1)
|
|
2051 (custom-add-parent-links widget))
|
|
2052 (custom-add-see-also widget)))))
|
|
2053
|
|
2054 (defun custom-tag-action (widget &rest args)
|
|
2055 "Pass :action to first child of WIDGET's parent."
|
|
2056 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
|
|
2057 :action args))
|
|
2058
|
|
2059 (defun custom-tag-mouse-down-action (widget &rest args)
|
|
2060 "Pass :mouse-down-action to first child of WIDGET's parent."
|
|
2061 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
|
|
2062 :mouse-down-action args))
|
|
2063
|
|
2064 (defun custom-variable-state-set (widget)
|
|
2065 "Set the state of WIDGET."
|
|
2066 (let* ((symbol (widget-value widget))
|
|
2067 (get (or (get symbol 'custom-get) 'default-value))
|
|
2068 (value (if (default-boundp symbol)
|
|
2069 (funcall get symbol)
|
|
2070 (widget-get widget :value)))
|
|
2071 (comment (get symbol 'variable-comment))
|
|
2072 tmp
|
|
2073 temp
|
|
2074 (state (cond ((progn (setq tmp (get symbol 'customized-value))
|
|
2075 (setq temp
|
|
2076 (get symbol 'customized-variable-comment))
|
|
2077 (or tmp temp))
|
|
2078 (if (condition-case nil
|
|
2079 (and (equal value (eval (car tmp)))
|
|
2080 (equal comment temp))
|
|
2081 (error nil))
|
|
2082 'set
|
|
2083 'changed))
|
|
2084 ((progn (setq tmp (get symbol 'saved-value))
|
|
2085 (setq temp (get symbol 'saved-variable-comment))
|
|
2086 (or tmp temp))
|
|
2087 (if (condition-case nil
|
|
2088 (and (equal value (eval (car tmp)))
|
|
2089 (equal comment temp))
|
|
2090 (error nil))
|
|
2091 'saved
|
|
2092 'changed))
|
|
2093 ((setq tmp (get symbol 'standard-value))
|
|
2094 (if (condition-case nil
|
|
2095 (and (equal value (eval (car tmp)))
|
|
2096 (equal comment nil))
|
|
2097 (error nil))
|
|
2098 'standard
|
|
2099 'changed))
|
|
2100 (t 'rogue))))
|
|
2101 (widget-put widget :custom-state state)))
|
|
2102
|
|
2103 (defvar custom-variable-menu
|
|
2104 '(("Set for Current Session" custom-variable-set
|
|
2105 (lambda (widget)
|
|
2106 (eq (widget-get widget :custom-state) 'modified)))
|
|
2107 ("Save for Future Sessions" custom-variable-save
|
|
2108 (lambda (widget)
|
|
2109 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
|
|
2110 ("Reset to Current" custom-redraw
|
|
2111 (lambda (widget)
|
|
2112 (and (default-boundp (widget-value widget))
|
|
2113 (memq (widget-get widget :custom-state) '(modified changed)))))
|
|
2114 ("Reset to Saved" custom-variable-reset-saved
|
|
2115 (lambda (widget)
|
|
2116 (and (or (get (widget-value widget) 'saved-value)
|
|
2117 (get (widget-value widget) 'saved-variable-comment))
|
|
2118 (memq (widget-get widget :custom-state)
|
|
2119 '(modified set changed rogue)))))
|
|
2120 ("Reset to Standard Settings" custom-variable-reset-standard
|
|
2121 (lambda (widget)
|
|
2122 (and (get (widget-value widget) 'standard-value)
|
|
2123 (memq (widget-get widget :custom-state)
|
|
2124 '(modified set changed saved rogue)))))
|
|
2125 ("---" ignore ignore)
|
|
2126 ("Add Comment" custom-comment-show custom-comment-invisible-p)
|
|
2127 ("---" ignore ignore)
|
|
2128 ("Don't show as Lisp expression" custom-variable-edit
|
|
2129 (lambda (widget)
|
|
2130 (eq (widget-get widget :custom-form) 'lisp)))
|
|
2131 ("Show as Lisp expression" custom-variable-edit-lisp
|
|
2132 (lambda (widget)
|
|
2133 (eq (widget-get widget :custom-form) 'edit))))
|
|
2134 "Alist of actions for the `custom-variable' widget.
|
|
2135 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
2136 the menu entry, ACTION is the function to call on the widget when the
|
|
2137 menu is selected, and FILTER is a predicate which takes a `custom-variable'
|
|
2138 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
2139 widget. If FILTER is nil, ACTION is always valid.")
|
|
2140
|
|
2141 (defun custom-variable-action (widget &optional event)
|
|
2142 "Show the menu for `custom-variable' WIDGET.
|
|
2143 Optional EVENT is the location for the menu."
|
|
2144 (if (eq (widget-get widget :custom-state) 'hidden)
|
|
2145 (custom-toggle-hide widget)
|
|
2146 (unless (eq (widget-get widget :custom-state) 'modified)
|
|
2147 (custom-variable-state-set widget))
|
|
2148 ;; Redrawing magic also depresses the state glyph.
|
|
2149 ;(custom-redraw-magic widget)
|
|
2150 (let* ((completion-ignore-case t)
|
|
2151 (answer (widget-choose (concat "Operation on "
|
|
2152 (custom-unlispify-tag-name
|
|
2153 (widget-get widget :value)))
|
|
2154 (custom-menu-filter custom-variable-menu
|
|
2155 widget)
|
|
2156 event)))
|
|
2157 (if answer
|
|
2158 (funcall answer widget)))))
|
|
2159
|
|
2160 (defun custom-variable-edit (widget)
|
|
2161 "Edit value of WIDGET."
|
|
2162 (widget-put widget :custom-state 'unknown)
|
|
2163 (widget-put widget :custom-form 'edit)
|
|
2164 (custom-redraw widget))
|
|
2165
|
|
2166 (defun custom-variable-edit-lisp (widget)
|
|
2167 "Edit the lisp representation of the value of WIDGET."
|
|
2168 (widget-put widget :custom-state 'unknown)
|
|
2169 (widget-put widget :custom-form 'lisp)
|
|
2170 (custom-redraw widget))
|
|
2171
|
|
2172 (defun custom-variable-set (widget)
|
|
2173 "Set the current value for the variable being edited by WIDGET."
|
|
2174 (let* ((form (widget-get widget :custom-form))
|
|
2175 (state (widget-get widget :custom-state))
|
|
2176 (child (car (widget-get widget :children)))
|
|
2177 (symbol (widget-value widget))
|
|
2178 (set (or (get symbol 'custom-set) 'set-default))
|
|
2179 (comment-widget (widget-get widget :comment-widget))
|
|
2180 (comment (widget-value comment-widget))
|
|
2181 val)
|
|
2182 (cond ((eq state 'hidden)
|
|
2183 (error "Cannot set hidden variable"))
|
|
2184 ((setq val (widget-apply child :validate))
|
|
2185 (goto-char (widget-get val :from))
|
|
2186 (error "%s" (widget-get val :error)))
|
|
2187 ((memq form '(lisp mismatch))
|
|
2188 (when (equal comment "")
|
|
2189 (setq comment nil)
|
|
2190 ;; Make the comment invisible by hand if it's empty
|
|
2191 (set-extent-property (widget-get comment-widget :comment-extent)
|
|
2192 'invisible t))
|
|
2193 (funcall set symbol (eval (setq val (widget-value child))))
|
|
2194 (put symbol 'customized-value (list val))
|
|
2195 (put symbol 'variable-comment comment)
|
|
2196 (put symbol 'customized-variable-comment comment))
|
|
2197 (t
|
|
2198 (when (equal comment "")
|
|
2199 (setq comment nil)
|
|
2200 ;; Make the comment invisible by hand if it's empty
|
|
2201 (set-extent-property (widget-get comment-widget :comment-extent)
|
|
2202 'invisible t))
|
|
2203 (funcall set symbol (setq val (widget-value child)))
|
|
2204 (put symbol 'customized-value (list (custom-quote val)))
|
|
2205 (put symbol 'variable-comment comment)
|
|
2206 (put symbol 'customized-variable-comment comment)))
|
|
2207 (custom-variable-state-set widget)
|
|
2208 (custom-redraw-magic widget)))
|
|
2209
|
480
|
2210 (defun custom-variable-pre-save (widget)
|
|
2211 "Prepare for saving the value for the variable being edited by WIDGET."
|
428
|
2212 (let* ((form (widget-get widget :custom-form))
|
|
2213 (state (widget-get widget :custom-state))
|
|
2214 (child (car (widget-get widget :children)))
|
|
2215 (symbol (widget-value widget))
|
|
2216 (set (or (get symbol 'custom-set) 'set-default))
|
|
2217 (comment-widget (widget-get widget :comment-widget))
|
|
2218 (comment (widget-value comment-widget))
|
|
2219 val)
|
|
2220 (cond ((eq state 'hidden)
|
|
2221 (error "Cannot set hidden variable"))
|
|
2222 ((setq val (widget-apply child :validate))
|
|
2223 (goto-char (widget-get val :from))
|
|
2224 (error "%s" (widget-get val :error)))
|
|
2225 ((memq form '(lisp mismatch))
|
|
2226 (when (equal comment "")
|
|
2227 (setq comment nil)
|
|
2228 ;; Make the comment invisible by hand if it's empty
|
|
2229 (set-extent-property (widget-get comment-widget :comment-extent)
|
|
2230 'invisible t))
|
|
2231 (put symbol 'saved-value (list (widget-value child)))
|
|
2232 (custom-push-theme 'theme-value symbol 'user
|
|
2233 'set (list (widget-value child)))
|
|
2234 (funcall set symbol (eval (widget-value child)))
|
|
2235 (put symbol 'variable-comment comment)
|
|
2236 (put symbol 'saved-variable-comment comment))
|
|
2237 (t
|
|
2238 (when (equal comment "")
|
|
2239 (setq comment nil)
|
|
2240 ;; Make the comment invisible by hand if it's empty
|
|
2241 (set-extent-property (widget-get comment-widget :comment-extent)
|
|
2242 'invisible t))
|
|
2243 (put symbol
|
|
2244 'saved-value (list (custom-quote (widget-value
|
|
2245 child))))
|
|
2246 (custom-push-theme 'theme-value symbol 'user
|
|
2247 'set (list (custom-quote (widget-value
|
480
|
2248 child))))
|
428
|
2249 (funcall set symbol (widget-value child))
|
|
2250 (put symbol 'variable-comment comment)
|
|
2251 (put symbol 'saved-variable-comment comment)))
|
|
2252 (put symbol 'customized-value nil)
|
|
2253 (put symbol 'customized-variable-comment nil)
|
480
|
2254 ))
|
|
2255
|
|
2256 (defun custom-variable-post-save (widget)
|
|
2257 "Finish saving the variable being edited by WIDGET."
|
|
2258 (custom-variable-state-set widget)
|
|
2259 (custom-redraw-magic widget))
|
|
2260
|
|
2261 (defun custom-variable-save (widget)
|
|
2262 "Set and save the value for the variable being edited by WIDGET."
|
|
2263 (custom-variable-pre-save widget)
|
|
2264 (custom-save-all)
|
|
2265 (custom-variable-post-save widget))
|
428
|
2266
|
|
2267 (defun custom-variable-reset-saved (widget)
|
|
2268 "Restore the saved value for the variable being edited by WIDGET."
|
|
2269 (let* ((symbol (widget-value widget))
|
|
2270 (set (or (get symbol 'custom-set) 'set-default))
|
|
2271 (value (get symbol 'saved-value))
|
|
2272 (comment (get symbol 'saved-variable-comment)))
|
|
2273 (cond ((or value comment)
|
|
2274 (put symbol 'variable-comment comment)
|
|
2275 (condition-case nil
|
|
2276 (funcall set symbol (eval (car value)))
|
|
2277 (error nil)))
|
|
2278 (t
|
|
2279 (signal 'error (list "No saved value for variable" symbol))))
|
|
2280 (put symbol 'customized-value nil)
|
|
2281 (put symbol 'customized-variable-comment nil)
|
|
2282 (widget-put widget :custom-state 'unknown)
|
|
2283 ;; This call will possibly make the comment invisible
|
|
2284 (custom-redraw widget)))
|
|
2285
|
480
|
2286 ;; This function returns non nil if we need to re-save the options --dv.
|
|
2287 (defun custom-variable-pre-reset-standard (widget)
|
|
2288 "Prepare for restoring the variable being edited by WIDGET to its
|
|
2289 standard setting."
|
428
|
2290 (let* ((symbol (widget-value widget))
|
442
|
2291 (set (or (get symbol 'custom-set) 'set-default)))
|
428
|
2292 (if (get symbol 'standard-value)
|
|
2293 (funcall set symbol (eval (car (get symbol 'standard-value))))
|
|
2294 (signal 'error (list "No standard setting known for variable" symbol)))
|
|
2295 (put symbol 'variable-comment nil)
|
|
2296 (put symbol 'customized-value nil)
|
|
2297 (put symbol 'customized-variable-comment nil)
|
|
2298 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
|
|
2299 (put symbol 'saved-value nil)
|
|
2300 (custom-push-theme 'theme-value symbol 'user 'reset 'standard)
|
|
2301 ;; As a special optimizations we do not (explictly)
|
480
|
2302 ;; save resets to standard when no theme sets the value.
|
428
|
2303 (if (null (cdr (get symbol 'theme-value)))
|
|
2304 (put symbol 'theme-value nil))
|
|
2305 (put symbol 'saved-variable-comment nil)
|
480
|
2306 widget)
|
|
2307 ))
|
|
2308
|
|
2309 (defun custom-variable-post-reset-standard (widget)
|
|
2310 "Finish resetting the variable being edited by WIDGET to its standard
|
|
2311 value."
|
|
2312 (widget-put widget :custom-state 'unknown)
|
|
2313 ;; This call will possibly make the comment invisible
|
|
2314 (custom-redraw widget))
|
|
2315
|
|
2316 (defun custom-variable-reset-standard (widget)
|
|
2317 "Restore the standard setting for the variable being edited by WIDGET."
|
|
2318 (when (custom-variable-pre-reset-standard widget)
|
|
2319 (custom-save-all))
|
|
2320 (custom-variable-post-reset-standard widget))
|
|
2321
|
428
|
2322
|
|
2323 ;;; The `custom-face-edit' Widget.
|
|
2324
|
|
2325 (define-widget 'custom-face-edit 'checklist
|
|
2326 "Edit face attributes."
|
|
2327 :format "%t: %v"
|
|
2328 :tag "Attributes"
|
|
2329 :extra-offset 12
|
438
|
2330 :button-args '(:help-echo "Control whether this attribute has any effect")
|
428
|
2331 :args (mapcar (lambda (att)
|
|
2332 (list 'group
|
|
2333 :inline t
|
|
2334 :sibling-args (widget-get (nth 1 att) :sibling-args)
|
|
2335 (list 'const :format "" :value (nth 0 att))
|
|
2336 (nth 1 att)))
|
|
2337 custom-face-attributes))
|
|
2338
|
|
2339 ;;; The `custom-display' Widget.
|
|
2340
|
|
2341 (define-widget 'custom-display 'menu-choice
|
|
2342 "Select a display type."
|
|
2343 :tag "Display"
|
|
2344 :value t
|
|
2345 :help-echo "Specify frames where the face attributes should be used"
|
|
2346 :args '((const :tag "all" t)
|
|
2347 (checklist
|
|
2348 :offset 0
|
|
2349 :extra-offset 9
|
|
2350 :args ((group :sibling-args (:help-echo "\
|
|
2351 Only match the specified window systems")
|
|
2352 (const :format "Type: "
|
|
2353 type)
|
|
2354 (checklist :inline t
|
|
2355 :offset 0
|
|
2356 (const :format "X "
|
|
2357 :sibling-args (:help-echo "\
|
|
2358 The X11 Window System")
|
|
2359 x)
|
555
|
2360 (const :format "GTK "
|
|
2361 :sibling-args (:help-echo "\
|
|
2362 The GTK Window System")
|
|
2363 gtk)
|
428
|
2364 (const :format "PM "
|
|
2365 :sibling-args (:help-echo "\
|
|
2366 OS/2 Presentation Manager")
|
|
2367 pm)
|
|
2368 (const :format "MSWindows "
|
|
2369 :sibling-args (:help-echo "\
|
440
|
2370 Microsoft Windows, displays")
|
428
|
2371 mswindows)
|
440
|
2372 (const :format "MSPrinter "
|
428
|
2373 :sibling-args (:help-echo "\
|
440
|
2374 Microsoft Windows, printers")
|
|
2375 msprinter)
|
428
|
2376 (const :format "TTY%n"
|
|
2377 :sibling-args (:help-echo "\
|
|
2378 Plain text terminals")
|
|
2379 tty)))
|
|
2380 (group :sibling-args (:help-echo "\
|
440
|
2381 Only match display or printer devices")
|
|
2382 (const :format "Output: "
|
|
2383 class)
|
|
2384 (checklist :inline t
|
|
2385 :offset 0
|
|
2386 (const :format "Display "
|
|
2387 :sibling-args (:help-echo "\
|
|
2388 Match display devices")
|
|
2389 display)
|
|
2390 (const :format "Printer%n"
|
|
2391 :sibling-args (:help-echo "\
|
|
2392 Match printer devices")
|
|
2393 printer)))
|
|
2394 (group :sibling-args (:help-echo "\
|
428
|
2395 Only match the frames with the specified color support")
|
440
|
2396 (const :format "Color support: "
|
428
|
2397 class)
|
|
2398 (checklist :inline t
|
|
2399 :offset 0
|
|
2400 (const :format "Color "
|
|
2401 :sibling-args (:help-echo "\
|
|
2402 Match color frames")
|
|
2403 color)
|
|
2404 (const :format "Grayscale "
|
|
2405 :sibling-args (:help-echo "\
|
|
2406 Match grayscale frames")
|
|
2407 grayscale)
|
|
2408 (const :format "Monochrome%n"
|
|
2409 :sibling-args (:help-echo "\
|
|
2410 Match frames with no color support")
|
|
2411 mono)))
|
|
2412 (group :sibling-args (:help-echo "\
|
|
2413 Only match frames with the specified intensity")
|
|
2414 (const :format "\
|
|
2415 Background brightness: "
|
|
2416 background)
|
|
2417 (checklist :inline t
|
|
2418 :offset 0
|
|
2419 (const :format "Light "
|
|
2420 :sibling-args (:help-echo "\
|
|
2421 Match frames with light backgrounds")
|
|
2422 light)
|
|
2423 (const :format "Dark\n"
|
|
2424 :sibling-args (:help-echo "\
|
|
2425 Match frames with dark backgrounds")
|
|
2426 dark)))))))
|
|
2427
|
|
2428 ;;; The `custom-face' Widget.
|
|
2429
|
|
2430 (defface custom-face-tag-face '((t (:underline t)))
|
|
2431 "Face used for face tags."
|
|
2432 :group 'custom-faces)
|
|
2433
|
|
2434 (defcustom custom-face-default-form 'selected
|
|
2435 "Default form of displaying face definition."
|
|
2436 :type '(choice (const all)
|
|
2437 (const selected)
|
|
2438 (const lisp))
|
|
2439 :group 'custom-buffer)
|
|
2440
|
|
2441 (define-widget 'custom-face 'custom
|
|
2442 "Customize face."
|
|
2443 :sample-face 'custom-face-tag-face
|
|
2444 :help-echo "Set or reset this face"
|
|
2445 :documentation-property '(lambda (face)
|
|
2446 (face-doc-string face))
|
|
2447 :value-create 'custom-face-value-create
|
|
2448 :action 'custom-face-action
|
|
2449 :custom-category 'face
|
|
2450 :custom-form nil ; defaults to value of `custom-face-default-form'
|
|
2451 :custom-set 'custom-face-set
|
480
|
2452 :custom-pre-save 'custom-face-pre-save
|
428
|
2453 :custom-save 'custom-face-save
|
480
|
2454 :custom-post-save 'custom-face-post-save
|
428
|
2455 :custom-reset-current 'custom-redraw
|
|
2456 :custom-reset-saved 'custom-face-reset-saved
|
480
|
2457 :custom-pre-reset-standard 'custom-face-pre-reset-standard
|
428
|
2458 :custom-reset-standard 'custom-face-reset-standard
|
480
|
2459 :custom-post-reset-standard 'custom-face-post-reset-standard
|
428
|
2460 :custom-menu 'custom-face-menu-create)
|
|
2461
|
|
2462 (define-widget 'custom-face-all 'editable-list
|
|
2463 "An editable list of display specifications and attributes."
|
|
2464 :entry-format "%i %d %v"
|
|
2465 :insert-button-args '(:help-echo "Insert new display specification here")
|
|
2466 :append-button-args '(:help-echo "Append new display specification here")
|
|
2467 :delete-button-args '(:help-echo "Delete this display specification")
|
|
2468 :args '((group :format "%v" custom-display custom-face-edit)))
|
|
2469
|
|
2470 (defconst custom-face-all (widget-convert 'custom-face-all)
|
|
2471 "Converted version of the `custom-face-all' widget.")
|
|
2472
|
|
2473 (define-widget 'custom-display-unselected 'item
|
|
2474 "A display specification that doesn't match the selected display."
|
|
2475 :match 'custom-display-unselected-match)
|
|
2476
|
|
2477 (defun custom-display-unselected-match (widget value)
|
|
2478 "Non-nil if VALUE is an unselected display specification."
|
|
2479 (not (face-spec-set-match-display value (selected-frame))))
|
|
2480
|
|
2481 (define-widget 'custom-face-selected 'group
|
|
2482 "Edit the attributes of the selected display in a face specification."
|
|
2483 :args '((repeat :format ""
|
|
2484 :inline t
|
|
2485 (group custom-display-unselected sexp))
|
|
2486 (group (sexp :format "") custom-face-edit)
|
|
2487 (repeat :format ""
|
|
2488 :inline t
|
|
2489 sexp)))
|
|
2490
|
|
2491 (defconst custom-face-selected (widget-convert 'custom-face-selected)
|
|
2492 "Converted version of the `custom-face-selected' widget.")
|
|
2493
|
|
2494 (defun custom-face-value-create (widget)
|
|
2495 "Create a list of the display specifications for WIDGET."
|
|
2496 (let ((buttons (widget-get widget :buttons))
|
|
2497 children
|
|
2498 (symbol (widget-get widget :value))
|
|
2499 (tag (widget-get widget :tag))
|
|
2500 (state (widget-get widget :custom-state))
|
|
2501 (begin (point))
|
|
2502 (is-last (widget-get widget :custom-last))
|
|
2503 (prefix (widget-get widget :custom-prefix)))
|
|
2504 (unless tag
|
|
2505 (setq tag (prin1-to-string symbol)))
|
|
2506 (cond ((eq custom-buffer-style 'tree)
|
|
2507 (insert prefix (if is-last " `--- " " |--- "))
|
|
2508 (push (widget-create-child-and-convert
|
|
2509 widget 'custom-browse-face-tag)
|
|
2510 buttons)
|
|
2511 (insert " " tag "\n")
|
|
2512 (widget-put widget :buttons buttons))
|
|
2513 (t
|
|
2514 ;; Create tag.
|
|
2515 (insert tag)
|
|
2516 (if (eq custom-buffer-style 'face)
|
|
2517 (insert " ")
|
|
2518 (widget-specify-sample widget begin (point))
|
|
2519 (insert ": "))
|
|
2520 ;; Sample.
|
|
2521 (and (not (find-face symbol))
|
|
2522 ;; XEmacs cannot display uninitialized faces.
|
|
2523 (make-face symbol))
|
|
2524 (push (widget-create-child-and-convert widget 'item
|
|
2525 :format "(%{%t%})"
|
|
2526 :sample-face symbol
|
|
2527 :tag "sample")
|
|
2528 buttons)
|
|
2529 ;; Visibility.
|
|
2530 (insert " ")
|
|
2531 (push (widget-create-child-and-convert
|
|
2532 widget 'visibility
|
|
2533 :help-echo "Hide or show this face"
|
|
2534 :action 'custom-toggle-parent
|
|
2535 (not (eq state 'hidden)))
|
|
2536 buttons)
|
|
2537 ;; Magic.
|
|
2538 (insert "\n")
|
|
2539 (let ((magic (widget-create-child-and-convert
|
|
2540 widget 'custom-magic nil)))
|
|
2541 (widget-put widget :custom-magic magic)
|
|
2542 (push magic buttons))
|
|
2543 ;; Update buttons.
|
|
2544 (widget-put widget :buttons buttons)
|
|
2545 ;; Insert documentation.
|
|
2546 (widget-default-format-handler widget ?h)
|
|
2547 ;; The comment field
|
|
2548 (unless (eq state 'hidden)
|
|
2549 (let* ((comment (get symbol 'face-comment))
|
|
2550 (comment-widget
|
|
2551 (widget-create-child-and-convert
|
|
2552 widget 'custom-comment
|
|
2553 :parent widget
|
|
2554 :value (or comment ""))))
|
|
2555 (widget-put widget :comment-widget comment-widget)
|
|
2556 (push comment-widget children)))
|
|
2557 ;; See also.
|
|
2558 (unless (eq state 'hidden)
|
|
2559 (when (eq (widget-get widget :custom-level) 1)
|
|
2560 (custom-add-parent-links widget))
|
|
2561 (custom-add-see-also widget))
|
|
2562 ;; Editor.
|
|
2563 (unless (eq (preceding-char) ?\n)
|
|
2564 (insert "\n"))
|
|
2565 (unless (eq state 'hidden)
|
|
2566 (message "Creating face editor...")
|
|
2567 (custom-load-widget widget)
|
|
2568 (unless (widget-get widget :custom-form)
|
|
2569 (widget-put widget :custom-form custom-face-default-form))
|
|
2570 (let* ((symbol (widget-value widget))
|
|
2571 (spec (custom-face-get-spec symbol))
|
|
2572 (form (widget-get widget :custom-form))
|
|
2573 (indent (widget-get widget :indent))
|
|
2574 (edit (widget-create-child-and-convert
|
|
2575 widget
|
|
2576 (cond ((and (eq form 'selected)
|
|
2577 (widget-apply custom-face-selected
|
|
2578 :match spec))
|
|
2579 (when indent (insert-char ?\ indent))
|
|
2580 'custom-face-selected)
|
|
2581 ((and (not (eq form 'lisp))
|
|
2582 (widget-apply custom-face-all
|
|
2583 :match spec))
|
|
2584 'custom-face-all)
|
|
2585 (t
|
|
2586 (when indent (insert-char ?\ indent))
|
|
2587 'sexp))
|
|
2588 :value spec)))
|
|
2589 (custom-face-state-set widget)
|
|
2590 (push edit children)
|
|
2591 (widget-put widget :children children))
|
|
2592 (message "Creating face editor...done"))))))
|
|
2593
|
|
2594 (defvar custom-face-menu
|
|
2595 '(("Set for Current Session" custom-face-set)
|
|
2596 ("Save for Future Sessions" custom-face-save)
|
|
2597 ("Reset to Saved" custom-face-reset-saved
|
|
2598 (lambda (widget)
|
|
2599 (or (get (widget-value widget) 'saved-face)
|
|
2600 (get (widget-value widget) 'saved-face-comment))))
|
|
2601 ("Reset to Standard Setting" custom-face-reset-standard
|
|
2602 (lambda (widget)
|
|
2603 (get (widget-value widget) 'face-defface-spec)))
|
|
2604 ("---" ignore ignore)
|
|
2605 ("Add Comment" custom-comment-show custom-comment-invisible-p)
|
|
2606 ("---" ignore ignore)
|
|
2607 ("Show all display specs" custom-face-edit-all
|
|
2608 (lambda (widget)
|
|
2609 (not (eq (widget-get widget :custom-form) 'all))))
|
|
2610 ("Just current attributes" custom-face-edit-selected
|
|
2611 (lambda (widget)
|
|
2612 (not (eq (widget-get widget :custom-form) 'selected))))
|
|
2613 ("Show as Lisp expression" custom-face-edit-lisp
|
|
2614 (lambda (widget)
|
|
2615 (not (eq (widget-get widget :custom-form) 'lisp)))))
|
|
2616 "Alist of actions for the `custom-face' widget.
|
|
2617 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
2618 the menu entry, ACTION is the function to call on the widget when the
|
|
2619 menu is selected, and FILTER is a predicate which takes a `custom-face'
|
|
2620 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
2621 widget. If FILTER is nil, ACTION is always valid.")
|
|
2622
|
|
2623 (defun custom-face-edit-selected (widget)
|
|
2624 "Edit selected attributes of the value of WIDGET."
|
|
2625 (widget-put widget :custom-state 'unknown)
|
|
2626 (widget-put widget :custom-form 'selected)
|
|
2627 (custom-redraw widget))
|
|
2628
|
|
2629 (defun custom-face-edit-all (widget)
|
|
2630 "Edit all attributes of the value of WIDGET."
|
|
2631 (widget-put widget :custom-state 'unknown)
|
|
2632 (widget-put widget :custom-form 'all)
|
|
2633 (custom-redraw widget))
|
|
2634
|
|
2635 (defun custom-face-edit-lisp (widget)
|
|
2636 "Edit the lisp representation of the value of WIDGET."
|
|
2637 (widget-put widget :custom-state 'unknown)
|
|
2638 (widget-put widget :custom-form 'lisp)
|
|
2639 (custom-redraw widget))
|
|
2640
|
|
2641 (defun custom-face-state-set (widget)
|
|
2642 "Set the state of WIDGET."
|
|
2643 (let* ((symbol (widget-value widget))
|
|
2644 (comment (get symbol 'face-comment))
|
|
2645 tmp temp)
|
|
2646 (widget-put widget :custom-state
|
|
2647 (cond ((progn
|
|
2648 (setq tmp (get symbol 'customized-face))
|
|
2649 (setq temp (get symbol 'customized-face-comment))
|
|
2650 (or tmp temp))
|
|
2651 (if (equal temp comment)
|
|
2652 'set
|
|
2653 'changed))
|
|
2654 ((progn
|
|
2655 (setq tmp (get symbol 'saved-face))
|
|
2656 (setq temp (get symbol 'saved-face-comment))
|
|
2657 (or tmp temp))
|
|
2658 (if (equal temp comment)
|
|
2659 'saved
|
|
2660 'changed))
|
|
2661 ((get symbol 'face-defface-spec)
|
|
2662 (if (equal comment nil)
|
|
2663 'standard
|
|
2664 'changed))
|
|
2665 (t
|
|
2666 'rogue)))))
|
|
2667
|
|
2668 (defun custom-face-action (widget &optional event)
|
|
2669 "Show the menu for `custom-face' WIDGET.
|
|
2670 Optional EVENT is the location for the menu."
|
|
2671 (if (eq (widget-get widget :custom-state) 'hidden)
|
|
2672 (custom-toggle-hide widget)
|
|
2673 (let* ((completion-ignore-case t)
|
|
2674 (symbol (widget-get widget :value))
|
|
2675 (answer (widget-choose (concat "Operation on "
|
|
2676 (custom-unlispify-tag-name symbol))
|
|
2677 (custom-menu-filter custom-face-menu
|
|
2678 widget)
|
|
2679 event)))
|
|
2680 (if answer
|
|
2681 (funcall answer widget)))))
|
|
2682
|
|
2683 (defun custom-face-set (widget)
|
|
2684 "Make the face attributes in WIDGET take effect."
|
|
2685 (let* ((symbol (widget-value widget))
|
|
2686 (child (car (widget-get widget :children)))
|
|
2687 (value (widget-value child))
|
|
2688 (comment-widget (widget-get widget :comment-widget))
|
|
2689 (comment (widget-value comment-widget)))
|
|
2690 (when (equal comment "")
|
|
2691 (setq comment nil)
|
|
2692 ;; Make the comment invisible by hand if it's empty
|
|
2693 (set-extent-property (widget-get comment-widget :comment-extent)
|
|
2694 'invisible t))
|
|
2695 (put symbol 'customized-face value)
|
|
2696 (face-spec-set symbol value nil '(custom))
|
|
2697 (put symbol 'customized-face-comment comment)
|
|
2698 (put symbol 'face-comment comment)
|
|
2699 (custom-face-state-set widget)
|
|
2700 (custom-redraw-magic widget)))
|
|
2701
|
480
|
2702 (defun custom-face-pre-save (widget)
|
|
2703 "Prepare for saving the face being edited by WIDGET."
|
428
|
2704 (let* ((symbol (widget-value widget))
|
|
2705 (child (car (widget-get widget :children)))
|
|
2706 (value (widget-value child))
|
|
2707 (comment-widget (widget-get widget :comment-widget))
|
|
2708 (comment (widget-value comment-widget)))
|
|
2709 (when (equal comment "")
|
|
2710 (setq comment nil)
|
|
2711 ;; Make the comment invisible by hand if it's empty
|
|
2712 (set-extent-property (widget-get comment-widget :comment-extent)
|
|
2713 'invisible t))
|
|
2714 (face-spec-set symbol value nil '(custom))
|
|
2715 (put symbol 'saved-face value)
|
|
2716 (custom-push-theme 'theme-face symbol 'user 'set value)
|
|
2717 (put symbol 'customized-face nil)
|
|
2718 (put symbol 'face-comment comment)
|
|
2719 (put symbol 'customized-face-comment nil)
|
|
2720 (put symbol 'saved-face-comment comment)
|
480
|
2721 ))
|
|
2722
|
|
2723 (defun custom-face-post-save (widget)
|
|
2724 "Finish saving the face being edited by WIDGET."
|
|
2725 (custom-face-state-set widget)
|
|
2726 (custom-redraw-magic widget))
|
|
2727
|
|
2728 (defun custom-face-save (widget)
|
|
2729 "Save the face being edited by WIDGET."
|
|
2730 (custom-face-pre-save widget)
|
|
2731 (custom-save-all)
|
|
2732 (custom-face-post-save widget))
|
428
|
2733
|
|
2734 (defun custom-face-reset-saved (widget)
|
480
|
2735 "Reset the face being edited by WIDGET to its saved value."
|
428
|
2736 (let* ((symbol (widget-value widget))
|
|
2737 (child (car (widget-get widget :children)))
|
|
2738 (value (get symbol 'saved-face))
|
|
2739 (comment (get symbol 'saved-face-comment))
|
|
2740 (comment-widget (widget-get widget :comment-widget)))
|
|
2741 (unless (or value comment)
|
|
2742 (signal 'error (list "No saved value for this face" symbol)))
|
|
2743 (put symbol 'customized-face nil)
|
|
2744 (put symbol 'customized-face-comment nil)
|
|
2745 (face-spec-set symbol value nil '(custom))
|
|
2746 (put symbol 'face-comment comment)
|
|
2747 (widget-value-set child value)
|
|
2748 ;; This call manages the comment visibility
|
|
2749 (widget-value-set comment-widget (or comment ""))
|
|
2750 (custom-face-state-set widget)
|
|
2751 (custom-redraw-magic widget)))
|
|
2752
|
480
|
2753 ;; This function returns non nil if we need to re-save the options --dv.
|
|
2754 (defun custom-face-pre-reset-standard (widget)
|
|
2755 "Prepare for restoring the face edited by WIDGET to its standard
|
|
2756 settings."
|
428
|
2757 (let* ((symbol (widget-value widget))
|
480
|
2758 (value (get symbol 'face-defface-spec)))
|
428
|
2759 (unless value
|
|
2760 (signal 'error (list "No standard setting for this face" symbol)))
|
|
2761 (put symbol 'customized-face nil)
|
|
2762 (put symbol 'customized-face-comment nil)
|
|
2763 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
|
|
2764 (put symbol 'saved-face nil)
|
|
2765 (custom-push-theme 'theme-face symbol 'user 'reset 'standard)
|
|
2766 ;; Do not explictly save resets to standards without themes.
|
|
2767 (if (null (cdr (get symbol 'theme-face)))
|
|
2768 (put symbol 'theme-face nil))
|
|
2769 (put symbol 'saved-face-comment nil)
|
480
|
2770 widget)
|
|
2771 ))
|
|
2772
|
|
2773 (defun custom-face-post-reset-standard (widget)
|
|
2774 "Finish restoring the face edited by WIDGET to its standard settings."
|
|
2775 (let* ((symbol (widget-value widget))
|
|
2776 (child (car (widget-get widget :children)))
|
|
2777 (value (get symbol 'face-defface-spec))
|
|
2778 (comment-widget (widget-get widget :comment-widget)))
|
428
|
2779 (face-spec-set symbol value nil '(custom))
|
|
2780 (put symbol 'face-comment nil)
|
|
2781 (widget-value-set child value)
|
|
2782 ;; This call manages the comment visibility
|
|
2783 (widget-value-set comment-widget "")
|
|
2784 (custom-face-state-set widget)
|
480
|
2785 (custom-redraw-magic widget)
|
|
2786 ))
|
|
2787
|
|
2788 (defun custom-face-reset-standard (widget)
|
|
2789 "Restore the face edited by WIDGET to its standard settings."
|
|
2790 (when (custom-face-pre-reset-standard widget)
|
|
2791 (custom-save-all))
|
|
2792 (custom-face-post-reset-standard widget))
|
|
2793
|
428
|
2794
|
|
2795 ;;; The `face' Widget.
|
|
2796
|
|
2797 (define-widget 'face 'default
|
|
2798 "Select and customize a face."
|
|
2799 :convert-widget 'widget-value-convert-widget
|
|
2800 :button-prefix 'widget-push-button-prefix
|
|
2801 :button-suffix 'widget-push-button-suffix
|
|
2802 :format "%t: %[select face%] %v"
|
|
2803 :tag "Face"
|
|
2804 :value 'default
|
|
2805 :value-create 'widget-face-value-create
|
|
2806 :value-delete 'widget-face-value-delete
|
|
2807 :value-get 'widget-value-value-get
|
|
2808 :validate 'widget-children-validate
|
|
2809 :action 'widget-face-action
|
|
2810 :match (lambda (widget value) (symbolp value)))
|
|
2811
|
|
2812 (defun widget-face-value-create (widget)
|
|
2813 ;; Create a `custom-face' child.
|
|
2814 (let* ((symbol (widget-value widget))
|
|
2815 (custom-buffer-style 'face)
|
|
2816 (child (widget-create-child-and-convert
|
|
2817 widget 'custom-face
|
|
2818 :custom-level nil
|
|
2819 :value symbol)))
|
|
2820 (custom-magic-reset child)
|
|
2821 (setq custom-options (cons child custom-options))
|
|
2822 (widget-put widget :children (list child))))
|
|
2823
|
|
2824 (defun widget-face-value-delete (widget)
|
|
2825 ;; Remove the child from the options.
|
|
2826 (let ((child (car (widget-get widget :children))))
|
|
2827 (setq custom-options (delq child custom-options))
|
|
2828 (widget-children-value-delete widget)))
|
|
2829
|
|
2830 (defvar face-history nil
|
|
2831 "History of entered face names.")
|
|
2832
|
|
2833 (defun widget-face-action (widget &optional event)
|
|
2834 "Prompt for a face."
|
|
2835 (let ((answer (completing-read "Face: "
|
|
2836 (mapcar (lambda (face)
|
|
2837 (list (symbol-name face)))
|
|
2838 (face-list))
|
|
2839 nil nil nil
|
|
2840 'face-history)))
|
|
2841 (unless (zerop (length answer))
|
|
2842 (widget-value-set widget (intern answer))
|
|
2843 (widget-apply widget :notify widget event)
|
|
2844 (widget-setup))))
|
|
2845
|
|
2846 ;;; The `hook' Widget.
|
|
2847
|
|
2848 (define-widget 'hook 'list
|
|
2849 "A emacs lisp hook"
|
|
2850 :value-to-internal (lambda (widget value)
|
|
2851 (if (symbolp value)
|
|
2852 (list value)
|
|
2853 value))
|
|
2854 :match (lambda (widget value)
|
|
2855 (or (symbolp value)
|
|
2856 (widget-group-match widget value)))
|
|
2857 :convert-widget 'custom-hook-convert-widget
|
|
2858 :tag "Hook")
|
|
2859
|
|
2860 (defun custom-hook-convert-widget (widget)
|
438
|
2861 ;; Handle `:options'.
|
428
|
2862 (let* ((options (widget-get widget :options))
|
|
2863 (other `(editable-list :inline t
|
|
2864 :entry-format "%i %d%v"
|
|
2865 (function :format " %v")))
|
|
2866 (args (if options
|
|
2867 (list `(checklist :inline t
|
|
2868 ,@(mapcar (lambda (entry)
|
|
2869 `(function-item ,entry))
|
|
2870 options))
|
|
2871 other)
|
|
2872 (list other))))
|
|
2873 (widget-put widget :args args)
|
|
2874 widget))
|
|
2875
|
|
2876 ;;; The `plist' Widget.
|
|
2877
|
|
2878 (define-widget 'plist 'list
|
|
2879 "A property list."
|
|
2880 :match (lambda (widget value)
|
|
2881 (valid-plist-p value))
|
|
2882 :convert-widget 'custom-plist-convert-widget
|
|
2883 :tag "Property List")
|
|
2884
|
|
2885 ;; #### Should handle options better.
|
|
2886 (defun custom-plist-convert-widget (widget)
|
|
2887 (let* ((options (widget-get widget :options))
|
|
2888 (other `(editable-list :inline t
|
|
2889 (group :inline t
|
|
2890 (symbol :format "%t: %v "
|
|
2891 :size 10
|
|
2892 :tag "Property")
|
|
2893 (sexp :tag "Value"))))
|
|
2894 (args
|
|
2895 (if options
|
|
2896 `((checklist :inline t
|
|
2897 ,@(mapcar 'custom-plist-process-option options))
|
|
2898 ,other)
|
|
2899 (list other))))
|
|
2900 (widget-put widget :args args)
|
|
2901 widget))
|
|
2902
|
|
2903 (defun custom-plist-process-option (entry)
|
|
2904 `(group :inline t
|
|
2905 (const :tag "Property"
|
|
2906 :format "%t: %v "
|
|
2907 :size 10
|
|
2908 ,entry)
|
|
2909 (sexp :tag "Value")))
|
|
2910
|
|
2911 ;;; The `custom-group-link' Widget.
|
|
2912
|
|
2913 (define-widget 'custom-group-link 'link
|
|
2914 "Show parent in other window when activated."
|
|
2915 :help-echo 'custom-group-link-help-echo
|
|
2916 :action 'custom-group-link-action)
|
|
2917
|
|
2918 (defun custom-group-link-help-echo (widget)
|
|
2919 (concat "Create customization buffer for the `"
|
|
2920 (custom-unlispify-tag-name (widget-value widget))
|
|
2921 "' group"))
|
|
2922
|
|
2923 (defun custom-group-link-action (widget &rest ignore)
|
|
2924 (customize-group (widget-value widget)))
|
|
2925
|
|
2926 ;;; The `custom-group' Widget.
|
|
2927
|
|
2928 (defcustom custom-group-tag-faces nil
|
|
2929 ;; In XEmacs, this ought to play games with font size.
|
|
2930 "Face used for group tags.
|
|
2931 The first member is used for level 1 groups, the second for level 2,
|
|
2932 and so forth. The remaining group tags are shown with
|
|
2933 `custom-group-tag-face'."
|
|
2934 :type '(repeat face)
|
|
2935 :group 'custom-faces)
|
|
2936
|
|
2937 (defface custom-group-tag-face-1 '((((class color)
|
|
2938 (background dark))
|
|
2939 (:foreground "pink" :underline t))
|
|
2940 (((class color)
|
|
2941 (background light))
|
|
2942 (:foreground "red" :underline t))
|
|
2943 (t (:underline t)))
|
|
2944 "Face used for group tags.")
|
|
2945
|
|
2946 (defface custom-group-tag-face '((((class color)
|
|
2947 (background dark))
|
|
2948 (:foreground "light blue" :underline t))
|
|
2949 (((class color)
|
|
2950 (background light))
|
|
2951 (:foreground "blue" :underline t))
|
|
2952 (t (:underline t)))
|
|
2953 "Face used for low level group tags."
|
|
2954 :group 'custom-faces)
|
|
2955
|
|
2956 (define-widget 'custom-group 'custom
|
|
2957 "Customize group."
|
|
2958 :format "%v"
|
|
2959 :sample-face-get 'custom-group-sample-face-get
|
|
2960 :documentation-property 'group-documentation
|
|
2961 :help-echo "Set or reset all members of this group"
|
|
2962 :value-create 'custom-group-value-create
|
|
2963 :action 'custom-group-action
|
|
2964 :custom-category 'group
|
|
2965 :custom-set 'custom-group-set
|
480
|
2966 :custom-pre-save 'custom-group-pre-save
|
428
|
2967 :custom-save 'custom-group-save
|
480
|
2968 :custom-post-save 'custom-group-post-save
|
428
|
2969 :custom-reset-current 'custom-group-reset-current
|
|
2970 :custom-reset-saved 'custom-group-reset-saved
|
480
|
2971 :custom-pre-reset-standard 'custom-group-pre-reset-standard
|
428
|
2972 :custom-reset-standard 'custom-group-reset-standard
|
480
|
2973 :custom-post-reset-standard 'custom-group-post-reset-standard
|
428
|
2974 :custom-menu 'custom-group-menu-create)
|
|
2975
|
|
2976 (defun custom-group-sample-face-get (widget)
|
|
2977 ;; Use :sample-face.
|
|
2978 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
|
|
2979 'custom-group-tag-face))
|
|
2980
|
|
2981 (define-widget 'custom-group-visibility 'visibility
|
|
2982 "An indicator and manipulator for hidden group contents."
|
|
2983 :create 'custom-group-visibility-create)
|
|
2984
|
|
2985 (defun custom-group-visibility-create (widget)
|
|
2986 (let ((visible (widget-value widget)))
|
|
2987 (if visible
|
|
2988 (insert "--------")))
|
|
2989 (widget-default-create widget))
|
|
2990
|
|
2991 (defun custom-group-members (symbol groups-only)
|
|
2992 "Return SYMBOL's custom group members.
|
|
2993 If GROUPS-ONLY non-nil, return only those members that are groups."
|
|
2994 (if (not groups-only)
|
|
2995 (get symbol 'custom-group)
|
|
2996 (let (members)
|
|
2997 (dolist (entry (get symbol 'custom-group) (nreverse members))
|
|
2998 (when (eq (nth 1 entry) 'custom-group)
|
|
2999 (push entry members))))))
|
|
3000
|
|
3001 (defun custom-group-value-create (widget)
|
|
3002 "Insert a customize group for WIDGET in the current buffer."
|
|
3003 (let* ((state (widget-get widget :custom-state))
|
|
3004 (level (widget-get widget :custom-level))
|
|
3005 ;; (indent (widget-get widget :indent))
|
|
3006 (prefix (widget-get widget :custom-prefix))
|
|
3007 (buttons (widget-get widget :buttons))
|
|
3008 (tag (widget-get widget :tag))
|
|
3009 (symbol (widget-value widget))
|
|
3010 (members (custom-group-members symbol
|
|
3011 (and (eq custom-buffer-style 'tree)
|
|
3012 custom-browse-only-groups))))
|
|
3013 (cond ((and (eq custom-buffer-style 'tree)
|
|
3014 (eq state 'hidden)
|
|
3015 (or members (custom-unloaded-widget-p widget)))
|
|
3016 (custom-browse-insert-prefix prefix)
|
|
3017 (push (widget-create-child-and-convert
|
|
3018 widget 'custom-browse-visibility
|
|
3019 ;; :tag-glyph "plus"
|
|
3020 :tag "+")
|
|
3021 buttons)
|
|
3022 (insert "-- ")
|
|
3023 ;; (widget-glyph-insert nil "-- " "horizontal")
|
|
3024 (push (widget-create-child-and-convert
|
|
3025 widget 'custom-browse-group-tag)
|
|
3026 buttons)
|
|
3027 (insert " " tag "\n")
|
|
3028 (widget-put widget :buttons buttons))
|
|
3029 ((and (eq custom-buffer-style 'tree)
|
|
3030 (zerop (length members)))
|
|
3031 (custom-browse-insert-prefix prefix)
|
|
3032 (insert "[ ]-- ")
|
|
3033 ;; (widget-glyph-insert nil "[ ]" "empty")
|
|
3034 ;; (widget-glyph-insert nil "-- " "horizontal")
|
|
3035 (push (widget-create-child-and-convert
|
|
3036 widget 'custom-browse-group-tag)
|
|
3037 buttons)
|
|
3038 (insert " " tag "\n")
|
|
3039 (widget-put widget :buttons buttons))
|
|
3040 ((eq custom-buffer-style 'tree)
|
|
3041 (custom-browse-insert-prefix prefix)
|
|
3042 (custom-load-widget widget)
|
|
3043 (if (zerop (length members))
|
|
3044 (progn
|
|
3045 (custom-browse-insert-prefix prefix)
|
|
3046 (insert "[ ]-- ")
|
|
3047 ;; (widget-glyph-insert nil "[ ]" "empty")
|
|
3048 ;; (widget-glyph-insert nil "-- " "horizontal")
|
|
3049 (push (widget-create-child-and-convert
|
|
3050 widget 'custom-browse-group-tag)
|
|
3051 buttons)
|
|
3052 (insert " " tag "\n")
|
|
3053 (widget-put widget :buttons buttons))
|
|
3054 (push (widget-create-child-and-convert
|
|
3055 widget 'custom-browse-visibility
|
|
3056 ;; :tag-glyph "minus"
|
|
3057 :tag "-")
|
|
3058 buttons)
|
|
3059 (insert "-\\ ")
|
|
3060 ;; (widget-glyph-insert nil "-\\ " "top")
|
|
3061 (push (widget-create-child-and-convert
|
|
3062 widget 'custom-browse-group-tag)
|
|
3063 buttons)
|
|
3064 (insert " " tag "\n")
|
|
3065 (widget-put widget :buttons buttons)
|
|
3066 (message "Creating group...")
|
|
3067 (let* ((members (custom-sort-items members
|
|
3068 custom-browse-sort-alphabetically
|
|
3069 custom-browse-order-groups))
|
|
3070 (prefixes (widget-get widget :custom-prefixes))
|
|
3071 (custom-prefix-list (custom-prefix-add symbol prefixes))
|
|
3072 (extra-prefix (if (widget-get widget :custom-last)
|
|
3073 " "
|
|
3074 " | "))
|
|
3075 (prefix (concat prefix extra-prefix))
|
|
3076 children entry)
|
|
3077 (while members
|
|
3078 (setq entry (car members)
|
|
3079 members (cdr members))
|
|
3080 (push (widget-create-child-and-convert
|
|
3081 widget (nth 1 entry)
|
|
3082 :group widget
|
|
3083 :tag (custom-unlispify-tag-name (nth 0 entry))
|
|
3084 :custom-prefixes custom-prefix-list
|
|
3085 :custom-level (1+ level)
|
|
3086 :custom-last (null members)
|
|
3087 :value (nth 0 entry)
|
|
3088 :custom-prefix prefix)
|
|
3089 children))
|
|
3090 (widget-put widget :children (reverse children)))
|
|
3091 (message "Creating group...done")))
|
|
3092 ;; Nested style.
|
|
3093 ((eq state 'hidden)
|
|
3094 ;; Create level indicator.
|
|
3095 (unless (eq custom-buffer-style 'links)
|
|
3096 (insert-char ?\ (* custom-buffer-indent (1- level)))
|
|
3097 (insert "-- "))
|
|
3098 ;; Create link indicator.
|
|
3099 (when (eq custom-buffer-style 'links)
|
|
3100 (insert " ")
|
|
3101 (push (widget-create-child-and-convert
|
|
3102 widget 'custom-group-link
|
|
3103 :tag "Open"
|
|
3104 :tag-glyph '("open-up" "open-down")
|
|
3105 symbol)
|
|
3106 buttons)
|
|
3107 (insert " "))
|
|
3108 ;; Create tag.
|
|
3109 (let ((begin (point)))
|
|
3110 (insert tag)
|
|
3111 (widget-specify-sample widget begin (point)))
|
|
3112 (insert " group")
|
|
3113 ;; Create visibility indicator.
|
|
3114 (unless (eq custom-buffer-style 'links)
|
|
3115 (insert ": ")
|
|
3116 (push (widget-create-child-and-convert
|
|
3117 widget 'custom-group-visibility
|
|
3118 :help-echo "Show members of this group"
|
|
3119 :action 'custom-toggle-parent
|
|
3120 (not (eq state 'hidden)))
|
|
3121 buttons))
|
|
3122 (insert " \n")
|
|
3123 ;; Create magic button.
|
|
3124 (let ((magic (widget-create-child-and-convert
|
|
3125 widget 'custom-magic nil)))
|
|
3126 (widget-put widget :custom-magic magic)
|
|
3127 (push magic buttons))
|
|
3128 ;; Update buttons.
|
|
3129 (widget-put widget :buttons buttons)
|
|
3130 ;; Insert documentation.
|
|
3131 (if (and (eq custom-buffer-style 'links) (> level 1))
|
|
3132 (widget-put widget :documentation-indent 0))
|
|
3133 (widget-default-format-handler widget ?h))
|
|
3134 ;; Nested style.
|
|
3135 (t ;Visible.
|
|
3136 (custom-load-widget widget)
|
|
3137 ;; Update members
|
|
3138 (setq members (custom-group-members
|
|
3139 symbol (and (eq custom-buffer-style 'tree)
|
|
3140 custom-browse-only-groups)))
|
|
3141 ;; Add parent groups references above the group.
|
|
3142 (if t ;;; This should test that the buffer
|
|
3143 ;;; was made to display a group.
|
|
3144 (when (eq level 1)
|
|
3145 (if (custom-add-parent-links widget
|
|
3146 "Go to parent group:")
|
|
3147 (insert "\n"))))
|
|
3148 ;; Create level indicator.
|
|
3149 (insert-char ?\ (* custom-buffer-indent (1- level)))
|
|
3150 (insert "/- ")
|
|
3151 ;; Create tag.
|
|
3152 (let ((start (point)))
|
|
3153 (insert tag)
|
|
3154 (widget-specify-sample widget start (point)))
|
|
3155 (insert " group: ")
|
|
3156 ;; Create visibility indicator.
|
|
3157 (unless (eq custom-buffer-style 'links)
|
|
3158 (insert "--------")
|
|
3159 (push (widget-create-child-and-convert
|
|
3160 widget 'visibility
|
|
3161 :help-echo "Hide members of this group"
|
|
3162 :action 'custom-toggle-parent
|
|
3163 (not (eq state 'hidden)))
|
|
3164 buttons)
|
|
3165 (insert " "))
|
|
3166 ;; Create more dashes.
|
|
3167 ;; Use 76 instead of 75 to compensate for the temporary "<"
|
|
3168 ;; added by `widget-insert'.
|
|
3169 (insert-char ?- (- 76 (current-column)
|
|
3170 (* custom-buffer-indent level)))
|
|
3171 (insert "\\\n")
|
|
3172 ;; Create magic button.
|
|
3173 (let ((magic (widget-create-child-and-convert
|
|
3174 widget 'custom-magic
|
|
3175 :indent 0
|
|
3176 nil)))
|
|
3177 (widget-put widget :custom-magic magic)
|
|
3178 (push magic buttons))
|
|
3179 ;; Update buttons.
|
|
3180 (widget-put widget :buttons buttons)
|
|
3181 ;; Insert documentation.
|
|
3182 (widget-default-format-handler widget ?h)
|
|
3183 ;; Parent groups.
|
|
3184 (if nil ;;; This should test that the buffer
|
|
3185 ;;; was not made to display a group.
|
|
3186 (when (eq level 1)
|
|
3187 (insert-char ?\ custom-buffer-indent)
|
|
3188 (custom-add-parent-links widget)))
|
|
3189 (custom-add-see-also widget
|
|
3190 (make-string (* custom-buffer-indent level)
|
|
3191 ?\ ))
|
|
3192 ;; Members.
|
|
3193 (message "Creating group...")
|
|
3194 (let* ((members (custom-sort-items members
|
|
3195 custom-buffer-sort-alphabetically
|
|
3196 custom-buffer-order-groups))
|
|
3197 (prefixes (widget-get widget :custom-prefixes))
|
|
3198 (custom-prefix-list (custom-prefix-add symbol prefixes))
|
|
3199 (length (length members))
|
|
3200 (count 0)
|
|
3201 (children (mapcar
|
|
3202 (lambda (entry)
|
|
3203 (widget-insert "\n")
|
|
3204 (when (zerop (% count custom-skip-messages))
|
|
3205 (display-message
|
|
3206 'progress
|
|
3207 (format "\
|
|
3208 Creating group members... %2d%%"
|
|
3209 (/ (* 100.0 count) length))))
|
|
3210 (incf count)
|
|
3211 (prog1
|
|
3212 (widget-create-child-and-convert
|
|
3213 widget (nth 1 entry)
|
|
3214 :group widget
|
|
3215 :tag (custom-unlispify-tag-name
|
|
3216 (nth 0 entry))
|
|
3217 :custom-prefixes custom-prefix-list
|
|
3218 :custom-level (1+ level)
|
|
3219 :value (nth 0 entry))
|
|
3220 (unless (eq (preceding-char) ?\n)
|
|
3221 (widget-insert "\n"))))
|
|
3222 members)))
|
|
3223 (message "Creating group magic...")
|
|
3224 (mapc 'custom-magic-reset children)
|
|
3225 (message "Creating group state...")
|
|
3226 (widget-put widget :children children)
|
|
3227 (custom-group-state-update widget)
|
|
3228 (message "Creating group... done"))
|
|
3229 ;; End line
|
|
3230 (insert "\n")
|
|
3231 (insert-char ?\ (* custom-buffer-indent (1- level)))
|
|
3232 (insert "\\- " (widget-get widget :tag) " group end ")
|
|
3233 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
|
|
3234 (insert "/\n")))))
|
|
3235
|
|
3236 (defvar custom-group-menu
|
|
3237 '(("Set for Current Session" custom-group-set
|
|
3238 (lambda (widget)
|
|
3239 (eq (widget-get widget :custom-state) 'modified)))
|
|
3240 ("Save for Future Sessions" custom-group-save
|
|
3241 (lambda (widget)
|
|
3242 (memq (widget-get widget :custom-state) '(modified set))))
|
|
3243 ("Reset to Current" custom-group-reset-current
|
|
3244 (lambda (widget)
|
|
3245 (memq (widget-get widget :custom-state) '(modified))))
|
|
3246 ("Reset to Saved" custom-group-reset-saved
|
|
3247 (lambda (widget)
|
|
3248 (memq (widget-get widget :custom-state) '(modified set))))
|
|
3249 ("Reset to standard setting" custom-group-reset-standard
|
|
3250 (lambda (widget)
|
|
3251 (memq (widget-get widget :custom-state) '(modified set saved)))))
|
|
3252 "Alist of actions for the `custom-group' widget.
|
|
3253 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
3254 the menu entry, ACTION is the function to call on the widget when the
|
|
3255 menu is selected, and FILTER is a predicate which takes a `custom-group'
|
|
3256 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
3257 widget. If FILTER is nil, ACTION is always valid.")
|
|
3258
|
|
3259 (defun custom-group-action (widget &optional event)
|
|
3260 "Show the menu for `custom-group' WIDGET.
|
|
3261 Optional EVENT is the location for the menu."
|
|
3262 (if (eq (widget-get widget :custom-state) 'hidden)
|
|
3263 (custom-toggle-hide widget)
|
|
3264 (let* ((completion-ignore-case t)
|
|
3265 (answer (widget-choose (concat "Operation on "
|
|
3266 (custom-unlispify-tag-name
|
|
3267 (widget-get widget :value)))
|
|
3268 (custom-menu-filter custom-group-menu
|
|
3269 widget)
|
|
3270 event)))
|
|
3271 (if answer
|
|
3272 (funcall answer widget)))))
|
|
3273
|
|
3274 (defun custom-group-set (widget)
|
|
3275 "Set changes in all modified group members."
|
|
3276 (let ((children (widget-get widget :children)))
|
|
3277 (mapc (lambda (child)
|
|
3278 (when (eq (widget-get child :custom-state) 'modified)
|
|
3279 (widget-apply child :custom-set)))
|
|
3280 children)))
|
|
3281
|
480
|
3282 (defun custom-group-pre-save (widget)
|
|
3283 "Prepare for saving all modified group members."
|
|
3284 (let ((children (widget-get widget :children)))
|
|
3285 (mapc (lambda (child)
|
|
3286 (when (memq (widget-get child :custom-state) '(modified set))
|
|
3287 (widget-apply child :custom-pre-save)))
|
|
3288 children)))
|
|
3289
|
|
3290 (defun custom-group-post-save (widget)
|
428
|
3291 "Save all modified group members."
|
|
3292 (let ((children (widget-get widget :children)))
|
|
3293 (mapc (lambda (child)
|
|
3294 (when (memq (widget-get child :custom-state) '(modified set))
|
480
|
3295 (widget-apply child :custom-post-save)))
|
428
|
3296 children)))
|
|
3297
|
480
|
3298 (defun custom-group-save (widget)
|
|
3299 "Save all modified group members."
|
|
3300 (custom-group-pre-save widget)
|
|
3301 (custom-save-all)
|
|
3302 (custom-group-post-save widget))
|
|
3303
|
428
|
3304 (defun custom-group-reset-current (widget)
|
|
3305 "Reset all modified group members."
|
|
3306 (let ((children (widget-get widget :children)))
|
|
3307 (mapc (lambda (child)
|
|
3308 (when (eq (widget-get child :custom-state) 'modified)
|
|
3309 (widget-apply child :custom-reset-current)))
|
|
3310 children)))
|
|
3311
|
|
3312 (defun custom-group-reset-saved (widget)
|
|
3313 "Reset all modified or set group members."
|
|
3314 (let ((children (widget-get widget :children)))
|
|
3315 (mapc (lambda (child)
|
|
3316 (when (memq (widget-get child :custom-state) '(modified set))
|
|
3317 (widget-apply child :custom-reset-saved)))
|
|
3318 children)))
|
|
3319
|
480
|
3320 ;; This function returns non nil when we need to re-save the options --dv.
|
|
3321 (defun custom-group-pre-reset-standard (widget)
|
|
3322 "Prepare for resetting all modified, set, or saved group members."
|
|
3323 (let ((children (widget-get widget :children))
|
|
3324 must-save)
|
|
3325 (mapc (lambda (child)
|
|
3326 (when (memq (widget-get child :custom-state)
|
|
3327 '(modified set saved))
|
|
3328 (and (widget-apply child :custom-pre-reset-standard)
|
|
3329 (setq must-save t))))
|
|
3330 children)
|
|
3331 must-save
|
|
3332 ))
|
|
3333
|
|
3334 (defun custom-group-post-reset-standard (widget)
|
|
3335 "Finish resetting all modified, set, or saved group members."
|
428
|
3336 (let ((children (widget-get widget :children)))
|
|
3337 (mapc (lambda (child)
|
|
3338 (when (memq (widget-get child :custom-state)
|
|
3339 '(modified set saved))
|
480
|
3340 (widget-apply child :custom-post-reset-standard)))
|
428
|
3341 children)))
|
|
3342
|
480
|
3343 (defun custom-group-reset-standard (widget)
|
|
3344 "Reset all modified, set, or saved group members."
|
|
3345 (when (custom-group-pre-reset-standard widget)
|
|
3346 (custom-save-all))
|
|
3347 (custom-group-post-reset-standard widget))
|
|
3348
|
428
|
3349 (defun custom-group-state-update (widget)
|
|
3350 "Update magic."
|
|
3351 (unless (eq (widget-get widget :custom-state) 'hidden)
|
|
3352 (let* ((children (widget-get widget :children))
|
|
3353 (states (mapcar (lambda (child)
|
|
3354 (widget-get child :custom-state))
|
|
3355 children))
|
|
3356 (magics custom-magic-alist)
|
|
3357 (found 'standard))
|
|
3358 (while magics
|
|
3359 (let ((magic (car (car magics))))
|
|
3360 (if (and (not (eq magic 'hidden))
|
|
3361 (memq magic states))
|
|
3362 (setq found magic
|
|
3363 magics nil)
|
|
3364 (setq magics (cdr magics)))))
|
|
3365 (widget-put widget :custom-state found)))
|
|
3366 (custom-magic-reset widget))
|
|
3367
|
|
3368 (defun custom-save-delete (symbol)
|
|
3369 "Delete the call to SYMBOL form in `custom-file'.
|
|
3370 Leave point at the location of the call, or after the last expression."
|
|
3371 (let ((find-file-hooks nil)
|
|
3372 (auto-mode-alist nil))
|
|
3373 (set-buffer (find-file-noselect custom-file)))
|
|
3374 (goto-char (point-min))
|
|
3375 (catch 'found
|
|
3376 (while t
|
|
3377 (let ((sexp (condition-case nil
|
|
3378 (read (current-buffer))
|
|
3379 (end-of-file (throw 'found nil)))))
|
|
3380 (when (and (listp sexp)
|
|
3381 (eq (car sexp) symbol))
|
|
3382 (delete-region (save-excursion
|
|
3383 (backward-sexp)
|
|
3384 (point))
|
|
3385 (point))
|
|
3386 (throw 'found nil))))))
|
|
3387
|
848
|
3388 (defun custom-save-delete-any (&rest symbols)
|
|
3389 "Delete the call to any symbol among SYMBOLS in `custom-file'.
|
|
3390 Leave the point at the end of the file."
|
|
3391 (let ((find-file-hooks nil)
|
|
3392 (auto-mode-alist nil))
|
|
3393 (set-buffer (find-file-noselect custom-file)))
|
|
3394 (goto-char (point-min))
|
|
3395 (condition-case nil
|
|
3396 (while (not (eobp))
|
|
3397 (let ((sexp (read (current-buffer))))
|
|
3398 (when (and (listp sexp)
|
|
3399 (memq (car sexp) symbols))
|
|
3400 (delete-region (save-excursion
|
|
3401 (backward-sexp)
|
|
3402 (point))
|
|
3403 (point))
|
|
3404 (while (and (eolp) (not (eobp)))
|
|
3405 (delete-region (point) (prog2 (forward-line 1) (point))))
|
|
3406 )))
|
|
3407 (end-of-file nil)))
|
|
3408
|
|
3409 (defsubst custom-save-variable-p (symbol)
|
|
3410 "Return non-nil if symbol SYMBOL is a customized variable."
|
|
3411 (and (symbolp symbol)
|
|
3412 (let ((spec (car-safe (get symbol 'theme-value))))
|
|
3413 (or (and spec (eq (car spec) 'user)
|
|
3414 (eq (second spec) 'set))
|
|
3415 (get symbol 'saved-variable-comment)
|
|
3416 ;; support non-themed vars
|
|
3417 (and (null spec) (get symbol 'saved-value))))))
|
|
3418
|
|
3419 (defun custom-save-variable-internal (symbol)
|
|
3420 "Print variable SYMBOL to the standard output.
|
|
3421 SYMBOL must be a customized variable."
|
|
3422 (let ((requests (get symbol 'custom-requests))
|
|
3423 (now (not (or (get symbol 'standard-value)
|
|
3424 (and (not (boundp symbol))
|
|
3425 (not (eq (get symbol 'force-value)
|
|
3426 'rogue))))))
|
|
3427 (comment (get symbol 'saved-variable-comment))
|
|
3428 ;; Print everything, no placeholders `...'
|
|
3429 (print-level nil)
|
|
3430 (print-length nil))
|
|
3431 (unless (custom-save-variable-p symbol)
|
|
3432 (error 'wrong-type-argument "Not a customized variable" symbol))
|
|
3433 (princ "\n '(")
|
|
3434 (prin1 symbol)
|
|
3435 (princ " ")
|
|
3436 ;; This comment stuff is in the way ####
|
|
3437 ;; Is (eq (third spec) (car saved-value)) ????
|
|
3438 ;; (prin1 (third spec))
|
|
3439 ;; XEmacs -- pretty-print value if available
|
|
3440 (if (and custom-save-pretty-print
|
|
3441 (fboundp 'pp))
|
|
3442 ;; To suppress bytecompiler warning
|
|
3443 (with-fboundp 'pp
|
|
3444 (pp (car (get symbol 'saved-value))))
|
|
3445 (prin1 (car (get symbol 'saved-value))))
|
|
3446 (when (or now requests comment)
|
|
3447 (princ (if now " t" " nil")))
|
|
3448 (when (or comment requests)
|
|
3449 (princ " ")
|
|
3450 (prin1 requests))
|
|
3451 (when comment
|
|
3452 (princ " ")
|
|
3453 (prin1 comment))
|
|
3454 (princ ")")))
|
|
3455
|
428
|
3456 (defun custom-save-variables ()
|
|
3457 "Save all customized variables in `custom-file'."
|
|
3458 (save-excursion
|
|
3459 (custom-save-delete 'custom-load-themes)
|
|
3460 (custom-save-delete 'custom-reset-variables)
|
|
3461 (custom-save-delete 'custom-set-variables)
|
848
|
3462 ;; This leaves point at the end of file.
|
|
3463 ;; Adrian Aichner <adrian@xemacs.org> stated it is
|
|
3464 ;; a bad behavior <npak@ispras.ru>
|
|
3465 ;;(custom-save-delete-any 'custom-load-themes
|
|
3466 ;; 'custom-reset-variables
|
|
3467 ;; 'custom-set-variables)
|
428
|
3468 (custom-save-loaded-themes)
|
|
3469 (custom-save-resets 'theme-value 'custom-reset-variables nil)
|
848
|
3470 (let ((standard-output (current-buffer))
|
|
3471 ;; To make nconc work
|
|
3472 (sorted-list (make-list 1 t)))
|
|
3473 ;; First create a sorted list of saved variables.
|
|
3474 (mapatoms
|
|
3475 (lambda (symbol)
|
|
3476 (when (custom-save-variable-p symbol)
|
|
3477 (nconc sorted-list (list symbol)))))
|
|
3478 (setq sorted-list (sort (cdr sorted-list) 'string<))
|
|
3479
|
428
|
3480 (unless (bolp)
|
848
|
3481 (princ "\n"))
|
428
|
3482 (princ "(custom-set-variables")
|
848
|
3483 (mapc 'custom-save-variable-internal
|
|
3484 sorted-list)
|
|
3485 (princ ")")
|
|
3486 (unless (looking-at "\n")
|
|
3487 (princ "\n")))))
|
428
|
3488
|
|
3489 (defvar custom-save-face-ignoring nil)
|
|
3490
|
848
|
3491 (defsubst custom-save-face-p (symbol)
|
|
3492 "Return non-nil if SYMBOL is a customized face."
|
428
|
3493 (let ((theme-spec (car-safe (get symbol 'theme-face)))
|
848
|
3494 (comment (get symbol 'saved-face-comment)))
|
|
3495 (or (and (not (memq symbol custom-save-face-ignoring))
|
|
3496 ;; Don't print default face here.
|
|
3497 (or (and theme-spec
|
|
3498 (eq (car theme-spec) 'user)
|
|
3499 (eq (second theme-spec) 'set))
|
|
3500 ;; cope with non-themed faces
|
|
3501 (and (null theme-spec)
|
|
3502 (get symbol 'saved-face))))
|
|
3503 comment)))
|
|
3504
|
|
3505 (defun custom-save-face-internal (symbol)
|
|
3506 "Print face SYMBOL to the standard output.
|
|
3507 SYMBOL must be a customized face."
|
|
3508 (let ((comment (get symbol 'saved-face-comment))
|
428
|
3509 (now (not (or (get symbol 'face-defface-spec)
|
|
3510 (and (not (find-face symbol))
|
848
|
3511 (not (eq (get symbol 'force-face) 'rogue))))))
|
|
3512 ;; Print everything, no placeholders `...'
|
|
3513 (print-level nil)
|
|
3514 (print-length nil))
|
|
3515 (if (memq symbol custom-save-face-ignoring)
|
|
3516 ;; Do nothing
|
|
3517 nil
|
|
3518 ;; Print face
|
|
3519 (unless (custom-save-face-p symbol)
|
|
3520 (error 'wrong-type-argument "Not a customized face" symbol))
|
428
|
3521 (princ "\n '(")
|
|
3522 (prin1 symbol)
|
|
3523 (princ " ")
|
|
3524 (prin1 (get symbol 'saved-face))
|
|
3525 (if (or comment now)
|
848
|
3526 (princ (if now " t" " nil")))
|
428
|
3527 (when comment
|
848
|
3528 (princ " ")
|
|
3529 (prin1 comment))
|
428
|
3530 (princ ")"))))
|
|
3531
|
|
3532 (defun custom-save-faces ()
|
|
3533 "Save all customized faces in `custom-file'."
|
|
3534 (save-excursion
|
|
3535 (custom-save-delete 'custom-reset-faces)
|
|
3536 (custom-save-delete 'custom-set-faces)
|
848
|
3537 ;; This leaves point at the end of file.
|
|
3538 ;; Adrian Aichner <adrian@xemacs.org> stated it is
|
|
3539 ;; a bad behavior <npak@ispras.ru>
|
|
3540 ;;(custom-save-delete-any 'custom-reset-faces
|
|
3541 ;; 'custom-set-faces)
|
428
|
3542 (custom-save-resets 'theme-face 'custom-reset-faces '(default))
|
848
|
3543 (let ((standard-output (current-buffer))
|
|
3544 ;; To make nconc work
|
|
3545 (sorted-list (make-list 1 t)))
|
|
3546 ;; Create a sorted list of faces
|
|
3547 (mapatoms
|
|
3548 (lambda (symbol)
|
|
3549 (when (custom-save-face-p symbol)
|
|
3550 (nconc sorted-list (list symbol)))))
|
|
3551 (setq sorted-list (sort (cdr sorted-list) 'string<))
|
|
3552
|
428
|
3553 (unless (bolp)
|
|
3554 (princ "\n"))
|
|
3555 (princ "(custom-set-faces")
|
|
3556 ;; The default face must be first, since it affects the others.
|
848
|
3557 (when (custom-save-face-p 'default)
|
|
3558 (custom-save-face-internal 'default))
|
428
|
3559 (let ((custom-save-face-ignoring '(default)))
|
848
|
3560 (mapc 'custom-save-face-internal
|
|
3561 sorted-list))
|
428
|
3562 (princ ")")
|
|
3563 (unless (looking-at "\n")
|
|
3564 (princ "\n")))))
|
|
3565
|
848
|
3566 (defmacro make-custom-save-resets-mapper (property setter)
|
|
3567 "Create a mapper for `custom-save-resets'."
|
|
3568 `(lambda (object)
|
|
3569 (let ((spec (car-safe (get object (quote ,property))))
|
|
3570 (print-level nil)
|
|
3571 (print-length nil))
|
|
3572 (with-boundp '(ignored-special started-writing)
|
|
3573 (when (and (not (memq object ignored-special))
|
|
3574 (eq (car spec) 'user)
|
|
3575 (eq (second spec) 'reset))
|
|
3576 ;; Do not write reset statements unless necessary.
|
|
3577 (unless started-writing
|
|
3578 (setq started-writing t)
|
|
3579 (unless (bolp)
|
|
3580 (princ "\n"))
|
|
3581 (princ "(")
|
|
3582 (princ (quote ,setter))
|
|
3583 (princ "\n '(")
|
|
3584 (prin1 object)
|
|
3585 (princ " ")
|
|
3586 (prin1 (third spec))
|
|
3587 (princ ")")))))))
|
|
3588
|
|
3589 (defconst custom-save-resets-mapper-alist
|
|
3590 (eval-when-compile
|
|
3591 (list (list 'theme-value 'custom-reset-variables
|
|
3592 (byte-compile
|
|
3593 (make-custom-save-resets-mapper
|
|
3594 'theme-value 'custom-reset-variables)))
|
|
3595 (list 'theme-face 'custom-reset-faces
|
|
3596 (byte-compile
|
|
3597 (make-custom-save-resets-mapper
|
|
3598 'theme-face 'custom-reset-faces)))))
|
|
3599 "Never use it.
|
|
3600 Hashes several heavily used functions for `custom-save-resets'")
|
|
3601
|
428
|
3602 (defun custom-save-resets (property setter special)
|
848
|
3603 (declare (special ignored-special))
|
428
|
3604 (let (started-writing ignored-special)
|
444
|
3605 ;; (custom-save-delete setter) Done by caller
|
428
|
3606 (let ((standard-output (current-buffer))
|
848
|
3607 (mapper (let ((triple (assq property custom-save-resets-mapper-alist)))
|
|
3608 (if (and triple (eq (second triple) setter))
|
|
3609 (third triple)
|
|
3610 (make-custom-save-resets-mapper property setter)))))
|
428
|
3611 (mapc mapper special)
|
|
3612 (setq ignored-special special)
|
|
3613 (mapatoms mapper)
|
|
3614 (when started-writing
|
848
|
3615 (princ ")\n")))))
|
444
|
3616
|
428
|
3617
|
|
3618 (defun custom-save-loaded-themes ()
|
|
3619 (let ((themes (reverse (get 'user 'theme-loads-themes)))
|
848
|
3620 (standard-output (current-buffer))
|
|
3621 (print-level nil)
|
|
3622 (print-length nil))
|
428
|
3623 (when themes
|
|
3624 (unless (bolp) (princ "\n"))
|
|
3625 (princ "(custom-load-themes")
|
|
3626 (mapc (lambda (theme)
|
|
3627 (princ "\n '")
|
|
3628 (prin1 theme)) themes)
|
444
|
3629 (princ " )\n"))))
|
428
|
3630
|
|
3631 ;;;###autoload
|
|
3632 (defun customize-save-customized ()
|
|
3633 "Save all user options which have been set in this session."
|
|
3634 (interactive)
|
|
3635 (mapatoms (lambda (symbol)
|
|
3636 (let ((face (get symbol 'customized-face))
|
|
3637 (value (get symbol 'customized-value))
|
|
3638 (face-comment (get symbol 'customized-face-comment))
|
|
3639 (variable-comment
|
|
3640 (get symbol 'customized-variable-comment)))
|
|
3641 (when face
|
|
3642 (put symbol 'saved-face face)
|
|
3643 (custom-push-theme 'theme-face symbol 'user 'set value)
|
|
3644 (put symbol 'customized-face nil))
|
|
3645 (when value
|
|
3646 (put symbol 'saved-value value)
|
|
3647 (custom-push-theme 'theme-value symbol 'user 'set value)
|
|
3648 (put symbol 'customized-value nil))
|
|
3649 (when variable-comment
|
|
3650 (put symbol 'saved-variable-comment variable-comment)
|
|
3651 (put symbol 'customized-variable-comment nil))
|
|
3652 (when face-comment
|
|
3653 (put symbol 'saved-face-comment face-comment)
|
|
3654 (put symbol 'customized-face-comment nil)))))
|
|
3655 ;; We really should update all custom buffers here.
|
|
3656 (custom-save-all))
|
|
3657
|
|
3658 ;;;###autoload
|
|
3659 (defun custom-save-all ()
|
|
3660 "Save all customizations in `custom-file'."
|
|
3661 (let ((inhibit-read-only t))
|
|
3662 (custom-save-variables)
|
|
3663 (custom-save-faces)
|
|
3664 (let ((find-file-hooks nil)
|
|
3665 (auto-mode-alist))
|
|
3666 (with-current-buffer (find-file-noselect custom-file)
|
|
3667 (save-buffer)))))
|
|
3668
|
|
3669
|
|
3670 ;;; The Customize Menu.
|
|
3671
|
|
3672 ;;; Menu support
|
|
3673
|
|
3674 (defun custom-face-menu-create (widget symbol)
|
|
3675 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
|
|
3676 (vector (custom-unlispify-menu-entry symbol)
|
|
3677 `(customize-face ',symbol)
|
|
3678 t))
|
|
3679
|
|
3680 (defun custom-variable-menu-create (widget symbol)
|
|
3681 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
|
|
3682 (let ((type (get symbol 'custom-type)))
|
|
3683 (unless (listp type)
|
|
3684 (setq type (list type)))
|
|
3685 (if (and type (widget-get type :custom-menu))
|
|
3686 (widget-apply type :custom-menu symbol)
|
|
3687 (vector (custom-unlispify-menu-entry symbol)
|
|
3688 `(customize-variable ',symbol)
|
|
3689 t))))
|
|
3690
|
|
3691 ;; Add checkboxes to boolean variable entries.
|
|
3692 (widget-put (get 'boolean 'widget-type)
|
|
3693 :custom-menu (lambda (widget symbol)
|
|
3694 `[,(custom-unlispify-menu-entry symbol)
|
|
3695 (customize-variable ',symbol)
|
|
3696 :style toggle
|
|
3697 :selected ,symbol]))
|
|
3698
|
|
3699 ;; XEmacs can create menus dynamically.
|
|
3700 (defun custom-group-menu-create (widget symbol)
|
|
3701 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
|
|
3702 `( ,(custom-unlispify-menu-entry symbol t)
|
|
3703 :filter (lambda (&rest junk)
|
|
3704 (let ((item (custom-menu-create ',symbol)))
|
|
3705 (if (listp item)
|
|
3706 (cdr item)
|
|
3707 (list item))))))
|
|
3708
|
|
3709 ;;;###autoload
|
|
3710 (defun custom-menu-create (symbol)
|
|
3711 "Create menu for customization group SYMBOL.
|
|
3712 The menu is in a format applicable to `easy-menu-define'."
|
|
3713 (let* ((item (vector (custom-unlispify-menu-entry symbol)
|
|
3714 `(customize-group ',symbol)
|
|
3715 t)))
|
|
3716 ;; Item is the entry for creating a menu buffer for SYMBOL.
|
|
3717 ;; We may nest, if the menu is not too big.
|
|
3718 (custom-load-symbol symbol)
|
|
3719 (if (< (length (get symbol 'custom-group)) widget-menu-max-size)
|
|
3720 ;; The menu is not too big.
|
|
3721 (let ((custom-prefix-list (custom-prefix-add symbol
|
|
3722 custom-prefix-list))
|
|
3723 (members (custom-sort-items (get symbol 'custom-group)
|
|
3724 custom-menu-sort-alphabetically
|
|
3725 custom-menu-order-groups)))
|
|
3726 ;; Create the menu.
|
|
3727 `(,(custom-unlispify-menu-entry symbol t)
|
|
3728 ,item
|
|
3729 "--"
|
|
3730 ,@(mapcar (lambda (entry)
|
|
3731 (widget-apply (if (listp (nth 1 entry))
|
|
3732 (nth 1 entry)
|
|
3733 (list (nth 1 entry)))
|
|
3734 :custom-menu (nth 0 entry)))
|
|
3735 members)))
|
|
3736 ;; The menu was too big.
|
|
3737 item)))
|
|
3738
|
|
3739 ;;;###autoload
|
|
3740 (defun customize-menu-create (symbol &optional name)
|
|
3741 "Return a customize menu for customization group SYMBOL.
|
|
3742 If optional NAME is given, use that as the name of the menu.
|
|
3743 Otherwise the menu will be named `Customize'.
|
|
3744 The format is suitable for use with `easy-menu-define'."
|
|
3745 (unless name
|
|
3746 (setq name "Customize"))
|
|
3747 `(,name
|
|
3748 :filter (lambda (&rest junk)
|
|
3749 (cdr (custom-menu-create ',symbol)))))
|
|
3750
|
|
3751 ;;; The Custom Mode.
|
|
3752
|
|
3753 (defvar custom-mode-map nil
|
|
3754 "Keymap for `custom-mode'.")
|
|
3755
|
|
3756 (unless custom-mode-map
|
|
3757 (setq custom-mode-map (make-sparse-keymap))
|
|
3758 (set-keymap-parents custom-mode-map widget-keymap)
|
|
3759 (suppress-keymap custom-mode-map)
|
|
3760 (define-key custom-mode-map " " 'scroll-up)
|
|
3761 (define-key custom-mode-map [delete] 'scroll-down)
|
|
3762 (define-key custom-mode-map "q" 'Custom-buffer-done)
|
|
3763 (define-key custom-mode-map "u" 'Custom-goto-parent)
|
|
3764 (define-key custom-mode-map "n" 'widget-forward)
|
|
3765 (define-key custom-mode-map "p" 'widget-backward))
|
|
3766
|
|
3767 (easy-menu-define Custom-mode-menu
|
|
3768 custom-mode-map
|
|
3769 "Menu used in customization buffers."
|
|
3770 `("Custom"
|
|
3771 ,(customize-menu-create 'customize)
|
|
3772 ["Set" Custom-set t]
|
|
3773 ["Save" Custom-save t]
|
|
3774 ["Reset to Current" Custom-reset-current t]
|
|
3775 ["Reset to Saved" Custom-reset-saved t]
|
|
3776 ["Reset to Standard Settings" Custom-reset-standard t]
|
|
3777 ["Info" (Info-goto-node "(xemacs)Easy Customization") t]))
|
|
3778
|
|
3779 (defun Custom-goto-parent ()
|
|
3780 "Go to the parent group listed at the top of this buffer.
|
|
3781 If several parents are listed, go to the first of them."
|
|
3782 (interactive)
|
|
3783 (save-excursion
|
|
3784 (goto-char (point-min))
|
|
3785 (if (search-forward "\nGo to parent group: " nil t)
|
|
3786 (let* ((button (get-char-property (point) 'button))
|
|
3787 (parent (downcase (widget-get button :tag))))
|
|
3788 (customize-group parent)))))
|
|
3789
|
|
3790 (defcustom custom-mode-hook nil
|
|
3791 "Hook called when entering custom-mode."
|
|
3792 :type 'hook
|
|
3793 :group 'custom-buffer )
|
|
3794
|
|
3795 (defun custom-state-buffer-message (widget)
|
|
3796 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
|
|
3797 (message
|
|
3798 "To install your edits, invoke [State] and choose the Set operation")))
|
|
3799
|
|
3800 (defun custom-mode ()
|
|
3801 "Major mode for editing customization buffers.
|
|
3802
|
|
3803 The following commands are available:
|
|
3804
|
|
3805 Move to next button or editable field. \\[widget-forward]
|
|
3806 Move to previous button or editable field. \\[widget-backward]
|
|
3807 \\<widget-field-keymap>\
|
|
3808 Complete content of editable text field. \\[widget-complete]
|
|
3809 \\<custom-mode-map>\
|
|
3810 Invoke button under point. \\[widget-button-press]
|
|
3811 Set all modifications. \\[Custom-set]
|
|
3812 Make all modifications default. \\[Custom-save]
|
|
3813 Reset all modified options. \\[Custom-reset-current]
|
|
3814 Reset all modified or set options. \\[Custom-reset-saved]
|
|
3815 Reset all options. \\[Custom-reset-standard]
|
|
3816
|
|
3817 Entry to this mode calls the value of `custom-mode-hook'
|
|
3818 if that value is non-nil."
|
|
3819 (kill-all-local-variables)
|
|
3820 (setq major-mode 'custom-mode
|
|
3821 mode-name "Custom")
|
|
3822 (use-local-map custom-mode-map)
|
|
3823 (easy-menu-add Custom-mode-menu)
|
|
3824 (make-local-variable 'custom-options)
|
|
3825 (make-local-variable 'widget-documentation-face)
|
|
3826 (setq widget-documentation-face 'custom-documentation-face)
|
|
3827 (make-local-variable 'widget-button-face)
|
|
3828 (setq widget-button-face 'custom-button-face)
|
|
3829 (make-local-hook 'widget-edit-functions)
|
|
3830 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
|
|
3831 (run-hooks 'custom-mode-hook))
|
|
3832
|
|
3833
|
442
|
3834 ;;;###autoload
|
|
3835 (defun custom-migrate-custom-file (new-custom-file-name)
|
|
3836 "Migrate custom file from home directory."
|
|
3837 (mapc 'custom-save-delete
|
|
3838 '(custom-load-themes custom-reset-variables
|
|
3839 custom-set-variables
|
|
3840 custom-set-faces
|
|
3841 custom-reset-faces))
|
|
3842 (with-current-buffer (find-file-noselect custom-file)
|
|
3843 (save-buffer))
|
|
3844 (setq custom-file new-custom-file-name)
|
|
3845 (custom-save-all))
|
|
3846
|
428
|
3847 ;;; The End.
|
|
3848
|
|
3849 (provide 'cus-edit)
|
|
3850
|
|
3851 ;; cus-edit.el ends here
|