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