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
|
225
|
1079 (defun custom-buffer-create-buttons ()
|
209
|
1080 (message "Creating customization buttons...")
|
225
|
1081 (widget-insert "\nOperate on everything in this buffer:\n ")
|
209
|
1082 (widget-create 'push-button
|
|
1083 :tag "Set"
|
|
1084 :tag-glyph '("set-up" "set-down")
|
|
1085 :help-echo "\
|
|
1086 Make your editing in this buffer take effect for this session"
|
|
1087 :action (lambda (widget &optional event)
|
|
1088 (Custom-set)))
|
|
1089 (widget-insert " ")
|
|
1090 (widget-create 'push-button
|
|
1091 :tag "Save"
|
|
1092 :tag-glyph '("save-up" "save-down")
|
|
1093 :help-echo "\
|
|
1094 Make your editing in this buffer take effect for future Emacs sessions"
|
|
1095 :action (lambda (widget &optional event)
|
|
1096 (Custom-save)))
|
|
1097 (if custom-reset-button-menu
|
|
1098 (progn
|
|
1099 (widget-insert " ")
|
|
1100 (widget-create 'push-button
|
|
1101 :tag "Reset"
|
|
1102 :tag-glyph '("reset-up" "reset-down")
|
|
1103 :help-echo "Show a menu with reset operations"
|
|
1104 :mouse-down-action (lambda (&rest junk) t)
|
|
1105 :action (lambda (widget &optional event)
|
|
1106 (custom-reset event))))
|
|
1107 (widget-insert " ")
|
|
1108 (widget-create 'push-button
|
|
1109 :tag "Reset"
|
|
1110 :help-echo "\
|
|
1111 Reset all edited text in this buffer to reflect current values"
|
|
1112 :action 'Custom-reset-current)
|
|
1113 (widget-insert " ")
|
|
1114 (widget-create 'push-button
|
|
1115 :tag "Reset to Saved"
|
|
1116 :help-echo "\
|
|
1117 Reset all values in this buffer to their saved settings"
|
|
1118 :action 'Custom-reset-saved)
|
|
1119 (widget-insert " ")
|
|
1120 (widget-create 'push-button
|
|
1121 :tag "Reset to Standard"
|
|
1122 :help-echo "\
|
|
1123 Reset all values in this buffer to their standard settings"
|
|
1124 :action 'Custom-reset-standard))
|
|
1125 (widget-insert " ")
|
|
1126 (widget-create 'push-button
|
|
1127 :tag "Done"
|
|
1128 :tag-glyph '("done-up" "done-down")
|
219
|
1129 :help-echo "Remove the buffer"
|
209
|
1130 :action (lambda (widget &optional event)
|
219
|
1131 (Custom-buffer-done)))
|
225
|
1132 (widget-insert "\n"))
|
|
1133
|
|
1134 (defcustom custom-novice t
|
|
1135 "If non-nil, show help message at top of customize buffers."
|
|
1136 :type 'boolean
|
|
1137 :group 'custom-buffer)
|
|
1138
|
|
1139 (defcustom custom-display-global-buttons 'top
|
|
1140 "If `nil' don't display the global buttons. If `top' display at the
|
|
1141 beginning of custom buffers. If `bottom', display at the end."
|
|
1142 :type '(choice (const top)
|
|
1143 (const bottom)
|
|
1144 (const :tag "don't" nil))
|
|
1145 :group 'custom-buffer)
|
|
1146
|
|
1147 (defun custom-buffer-create-internal (options &optional description)
|
|
1148 (message "Creating customization buffer...")
|
|
1149 (custom-mode)
|
|
1150 (widget-insert "This is a customization buffer")
|
|
1151 (if description
|
|
1152 (widget-insert description))
|
|
1153 (when custom-novice
|
|
1154 (widget-insert ".\n\
|
|
1155 Type RET or click button2 on an active field to invoke its action.
|
|
1156 Invoke ")
|
|
1157 (widget-create 'info-link
|
|
1158 :tag "Help"
|
|
1159 :help-echo "Read the online help"
|
|
1160 "(XEmacs)Easy Customization")
|
|
1161 (widget-insert " for more information."))
|
|
1162 (widget-insert "\n")
|
|
1163 (if (equal custom-display-global-buttons 'top)
|
|
1164 (custom-buffer-create-buttons))
|
|
1165 (widget-insert "\n")
|
209
|
1166 (message "Creating customization items...")
|
|
1167 (setq custom-options
|
|
1168 (if (= (length options) 1)
|
|
1169 (mapcar (lambda (entry)
|
|
1170 (widget-create (nth 1 entry)
|
|
1171 :documentation-shown t
|
|
1172 :custom-state 'unknown
|
|
1173 :tag (custom-unlispify-tag-name
|
|
1174 (nth 0 entry))
|
|
1175 :value (nth 0 entry)))
|
|
1176 options)
|
|
1177 (let ((count 0)
|
|
1178 (length (length options)))
|
|
1179 (mapcar (lambda (entry)
|
|
1180 (prog2
|
|
1181 (display-message
|
|
1182 'progress
|
|
1183 (format "Creating customization items %2d%%..."
|
|
1184 (/ (* 100.0 count) length)))
|
|
1185 (widget-create (nth 1 entry)
|
|
1186 :tag (custom-unlispify-tag-name
|
|
1187 (nth 0 entry))
|
|
1188 :value (nth 0 entry))
|
|
1189 (incf count)
|
|
1190 (unless (eq (preceding-char) ?\n)
|
|
1191 (widget-insert "\n"))
|
|
1192 (widget-insert "\n")))
|
|
1193 options))))
|
|
1194 (unless (eq (preceding-char) ?\n)
|
|
1195 (widget-insert "\n"))
|
225
|
1196 (if (equal custom-display-global-buttons 'bottom)
|
|
1197 (custom-buffer-create-buttons))
|
209
|
1198 (display-message 'progress
|
|
1199 (format
|
|
1200 "Creating customization items %2d%%...done" 100))
|
|
1201 (unless (eq custom-buffer-style 'tree)
|
|
1202 (mapc 'custom-magic-reset custom-options))
|
|
1203 (message "Creating customization setup...")
|
|
1204 (widget-setup)
|
|
1205 (goto-char (point-min))
|
|
1206 (message "Creating customization buffer...done"))
|
|
1207
|
|
1208
|
|
1209 ;;; The Tree Browser.
|
|
1210
|
|
1211 ;;;###autoload
|
|
1212 (defun customize-browse (&optional group)
|
|
1213 "Create a tree browser for the customize hierarchy."
|
|
1214 (interactive)
|
|
1215 (unless group
|
|
1216 (setq group 'emacs))
|
|
1217 (let ((name "*Customize Browser*"))
|
|
1218 (kill-buffer (get-buffer-create name))
|
|
1219 (switch-to-buffer (get-buffer-create name)))
|
|
1220 (custom-mode)
|
|
1221 (widget-insert "\
|
|
1222 Square brackets show active fields; type RET or click button2
|
|
1223 on an active field to invoke its action.
|
|
1224 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
|
|
1225 (if custom-browse-only-groups
|
|
1226 (widget-insert "\
|
|
1227 Invoke the [Group] button below to edit that item in another window.\n\n")
|
|
1228 (widget-insert "Invoke the ")
|
|
1229 (widget-create 'item
|
|
1230 :format "%t"
|
|
1231 :tag "[Group]"
|
|
1232 :tag-glyph "folder")
|
|
1233 (widget-insert ", ")
|
|
1234 (widget-create 'item
|
|
1235 :format "%t"
|
|
1236 :tag "[Face]"
|
|
1237 :tag-glyph "face")
|
|
1238 (widget-insert ", and ")
|
|
1239 (widget-create 'item
|
|
1240 :format "%t"
|
|
1241 :tag "[Option]"
|
|
1242 :tag-glyph "option")
|
|
1243 (widget-insert " buttons below to edit that
|
|
1244 item in another window.\n\n"))
|
|
1245 (let ((custom-buffer-style 'tree))
|
|
1246 (widget-create 'custom-group
|
|
1247 :custom-last t
|
|
1248 :custom-state 'unknown
|
|
1249 :tag (custom-unlispify-tag-name group)
|
|
1250 :value group))
|
215
|
1251 (widget-add-change)
|
209
|
1252 (goto-char (point-min)))
|
|
1253
|
|
1254 (define-widget 'custom-browse-visibility 'item
|
|
1255 "Control visibility of of items in the customize tree browser."
|
|
1256 :format "%[[%t]%]"
|
|
1257 :action 'custom-browse-visibility-action)
|
|
1258
|
|
1259 (defun custom-browse-visibility-action (widget &rest ignore)
|
|
1260 (let ((custom-buffer-style 'tree))
|
|
1261 (custom-toggle-parent widget)))
|
|
1262
|
|
1263 (define-widget 'custom-browse-group-tag 'push-button
|
|
1264 "Show parent in other window when activated."
|
|
1265 :tag "Group"
|
|
1266 :tag-glyph "folder"
|
|
1267 :action 'custom-browse-group-tag-action)
|
|
1268
|
|
1269 (defun custom-browse-group-tag-action (widget &rest ignore)
|
|
1270 (let ((parent (widget-get widget :parent)))
|
|
1271 (customize-group-other-window (widget-value parent))))
|
|
1272
|
|
1273 (define-widget 'custom-browse-variable-tag 'push-button
|
|
1274 "Show parent in other window when activated."
|
|
1275 :tag "Option"
|
|
1276 :tag-glyph "option"
|
|
1277 :action 'custom-browse-variable-tag-action)
|
|
1278
|
|
1279 (defun custom-browse-variable-tag-action (widget &rest ignore)
|
|
1280 (let ((parent (widget-get widget :parent)))
|
|
1281 (customize-variable-other-window (widget-value parent))))
|
|
1282
|
|
1283 (define-widget 'custom-browse-face-tag 'push-button
|
|
1284 "Show parent in other window when activated."
|
|
1285 :tag "Face"
|
|
1286 :tag-glyph "face"
|
|
1287 :action 'custom-browse-face-tag-action)
|
|
1288
|
|
1289 (defun custom-browse-face-tag-action (widget &rest ignore)
|
|
1290 (let ((parent (widget-get widget :parent)))
|
|
1291 (customize-face-other-window (widget-value parent))))
|
|
1292
|
|
1293 (defconst custom-browse-alist '((" " "space")
|
|
1294 (" | " "vertical")
|
|
1295 ("-\\ " "top")
|
|
1296 (" |-" "middle")
|
|
1297 (" `-" "bottom")))
|
|
1298
|
|
1299 (defun custom-browse-insert-prefix (prefix)
|
|
1300 "Insert PREFIX. On XEmacs convert it to line graphics."
|
|
1301 ;; ### Unfinished.
|
|
1302 (if nil ; (string-match "XEmacs" emacs-version)
|
|
1303 (progn
|
|
1304 (insert "*")
|
|
1305 (while (not (string-equal prefix ""))
|
|
1306 (let ((entry (substring prefix 0 3)))
|
|
1307 (setq prefix (substring prefix 3))
|
|
1308 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
|
|
1309 (name (nth 1 (assoc entry custom-browse-alist))))
|
|
1310 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
|
|
1311 (overlay-put overlay 'start-open t)
|
|
1312 (overlay-put overlay 'end-open t)))))
|
|
1313 (insert prefix)))
|
|
1314
|
|
1315
|
|
1316 ;;; Modification of Basic Widgets.
|
|
1317 ;;
|
|
1318 ;; We add extra properties to the basic widgets needed here. This is
|
|
1319 ;; fine, as long as we are careful to stay within out own namespace.
|
|
1320 ;;
|
|
1321 ;; We want simple widgets to be displayed by default, but complex
|
|
1322 ;; widgets to be hidden.
|
|
1323
|
|
1324 (widget-put (get 'item 'widget-type) :custom-show t)
|
|
1325 (widget-put (get 'editable-field 'widget-type)
|
|
1326 :custom-show (lambda (widget value)
|
219
|
1327 ;; This used to call pp-to-string
|
|
1328 (let ((pp (widget-prettyprint-to-string value)))
|
209
|
1329 (cond ((string-match "\n" pp)
|
|
1330 nil)
|
|
1331 ((> (length pp) 40)
|
|
1332 nil)
|
|
1333 (t t)))))
|
|
1334 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
|
|
1335
|
|
1336 ;;; The `custom-manual' Widget.
|
|
1337
|
|
1338 (define-widget 'custom-manual 'info-link
|
|
1339 "Link to the manual entry for this customization option."
|
|
1340 :tag "Manual")
|
|
1341
|
|
1342 ;;; The `custom-magic' Widget.
|
|
1343
|
|
1344 (defgroup custom-magic-faces nil
|
|
1345 "Faces used by the magic button."
|
|
1346 :group 'custom-faces
|
|
1347 :group 'custom-buffer)
|
|
1348
|
|
1349 (defface custom-invalid-face '((((class color))
|
|
1350 (:foreground "yellow" :background "red"))
|
|
1351 (t
|
|
1352 (:bold t :italic t :underline t)))
|
|
1353 "Face used when the customize item is invalid."
|
|
1354 :group 'custom-magic-faces)
|
|
1355
|
|
1356 (defface custom-rogue-face '((((class color))
|
|
1357 (:foreground "pink" :background "black"))
|
|
1358 (t
|
|
1359 (:underline t)))
|
|
1360 "Face used when the customize item is not defined for customization."
|
|
1361 :group 'custom-magic-faces)
|
|
1362
|
|
1363 (defface custom-modified-face '((((class color))
|
|
1364 (:foreground "white" :background "blue"))
|
|
1365 (t
|
|
1366 (:italic t :bold)))
|
|
1367 "Face used when the customize item has been modified."
|
|
1368 :group 'custom-magic-faces)
|
|
1369
|
|
1370 (defface custom-set-face '((((class color))
|
|
1371 (:foreground "blue" :background "white"))
|
|
1372 (t
|
|
1373 (:italic t)))
|
|
1374 "Face used when the customize item has been set."
|
|
1375 :group 'custom-magic-faces)
|
|
1376
|
|
1377 (defface custom-changed-face '((((class color))
|
|
1378 (:foreground "white" :background "blue"))
|
|
1379 (t
|
|
1380 (:italic t)))
|
|
1381 "Face used when the customize item has been changed."
|
|
1382 :group 'custom-magic-faces)
|
|
1383
|
|
1384 (defface custom-saved-face '((t (:underline t)))
|
|
1385 "Face used when the customize item has been saved."
|
|
1386 :group 'custom-magic-faces)
|
|
1387
|
|
1388 (defconst custom-magic-alist '((nil "#" underline "\
|
|
1389 uninitialized, you should not see this.")
|
|
1390 (unknown "?" italic "\
|
|
1391 unknown, you should not see this.")
|
|
1392 (hidden "-" default "\
|
|
1393 hidden, invoke \"Show\" button in the previous line to show." "\
|
|
1394 group now hidden, invoke the above \"Show\" button to show contents.")
|
|
1395 (invalid "x" custom-invalid-face "\
|
|
1396 the value displayed for this %c is invalid and cannot be set.")
|
|
1397 (modified "*" custom-modified-face "\
|
|
1398 you have edited the value as text, but you have not set the %c." "\
|
|
1399 you have edited something in this group, but not set it.")
|
|
1400 (set "+" custom-set-face "\
|
|
1401 you have set this %c, but not saved it for future sessions." "\
|
|
1402 something in this group has been set, but not saved.")
|
|
1403 (changed ":" custom-changed-face "\
|
|
1404 this %c has been changed outside the customize buffer." "\
|
|
1405 something in this group has been changed outside customize.")
|
|
1406 (saved "!" custom-saved-face "\
|
|
1407 this %c has been set and saved." "\
|
|
1408 something in this group has been set and saved.")
|
|
1409 (rogue "@" custom-rogue-face "\
|
|
1410 this %c has not been changed with customize." "\
|
|
1411 something in this group is not prepared for customization.")
|
|
1412 (standard " " nil "\
|
|
1413 this %c is unchanged from its standard setting." "\
|
|
1414 visible group members are all at standard settings."))
|
|
1415 "Alist of customize option states.
|
|
1416 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
|
|
1417
|
|
1418 STATE is one of the following symbols:
|
|
1419
|
|
1420 `nil'
|
|
1421 For internal use, should never occur.
|
|
1422 `unknown'
|
|
1423 For internal use, should never occur.
|
|
1424 `hidden'
|
|
1425 This item is not being displayed.
|
|
1426 `invalid'
|
|
1427 This item is modified, but has an invalid form.
|
|
1428 `modified'
|
|
1429 This item is modified, and has a valid form.
|
|
1430 `set'
|
|
1431 This item has been set but not saved.
|
|
1432 `changed'
|
|
1433 The current value of this item has been changed temporarily.
|
|
1434 `saved'
|
|
1435 This item is marked for saving.
|
|
1436 `rogue'
|
|
1437 This item has no customization information.
|
|
1438 `standard'
|
|
1439 This item is unchanged from the standard setting.
|
|
1440
|
|
1441 MAGIC is a string used to present that state.
|
|
1442
|
|
1443 FACE is a face used to present the state.
|
|
1444
|
|
1445 ITEM-DESC is a string describing the state for options.
|
|
1446
|
|
1447 GROUP-DESC is a string describing the state for groups. If this is
|
|
1448 left out, ITEM-DESC will be used.
|
|
1449
|
|
1450 The string %c in either description will be replaced with the
|
|
1451 category of the item. These are `group'. `option', and `face'.
|
|
1452
|
|
1453 The list should be sorted most significant first.")
|
|
1454
|
|
1455 (defcustom custom-magic-show 'long
|
|
1456 "If non-nil, show textual description of the state.
|
|
1457 If `long', show a full-line description, not just one word."
|
|
1458 :type '(choice (const :tag "no" nil)
|
|
1459 (const short)
|
|
1460 (const long))
|
|
1461 :group 'custom-buffer)
|
|
1462
|
|
1463 (defcustom custom-magic-show-hidden '(option face)
|
|
1464 "Control whether the State button is shown for hidden items.
|
|
1465 The value should be a list with the custom categories where the State
|
|
1466 button should be visible. Possible categories are `group', `option',
|
|
1467 and `face'."
|
|
1468 :type '(set (const group) (const option) (const face))
|
|
1469 :group 'custom-buffer)
|
|
1470
|
|
1471 (defcustom custom-magic-show-button nil
|
|
1472 "Show a \"magic\" button indicating the state of each customization option."
|
|
1473 :type 'boolean
|
|
1474 :group 'custom-buffer)
|
|
1475
|
|
1476 (define-widget 'custom-magic 'default
|
|
1477 "Show and manipulate state for a customization option."
|
|
1478 :format "%v"
|
|
1479 :action 'widget-parent-action
|
|
1480 :notify 'ignore
|
|
1481 :value-get 'ignore
|
|
1482 :value-create 'custom-magic-value-create
|
|
1483 :value-delete 'widget-children-value-delete)
|
|
1484
|
|
1485 (defun widget-magic-mouse-down-action (widget &optional event)
|
|
1486 ;; Non-nil unless hidden.
|
|
1487 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
|
|
1488 :custom-state)
|
|
1489 'hidden)))
|
|
1490
|
|
1491 (defun custom-magic-value-create (widget)
|
|
1492 ;; Create compact status report for WIDGET.
|
|
1493 (let* ((parent (widget-get widget :parent))
|
|
1494 (state (widget-get parent :custom-state))
|
|
1495 (hidden (eq state 'hidden))
|
|
1496 (entry (assq state custom-magic-alist))
|
|
1497 (magic (nth 1 entry))
|
|
1498 (face (nth 2 entry))
|
|
1499 (category (widget-get parent :custom-category))
|
|
1500 (text (or (and (eq category 'group)
|
|
1501 (nth 4 entry))
|
|
1502 (nth 3 entry)))
|
|
1503 (form (widget-get parent :custom-form))
|
|
1504 children)
|
|
1505 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
|
|
1506 (setq text (concat (match-string 1 text)
|
|
1507 (symbol-name category)
|
|
1508 (match-string 2 text))))
|
|
1509 (when (and custom-magic-show
|
|
1510 (or (not hidden)
|
|
1511 (memq category custom-magic-show-hidden)))
|
|
1512 (insert " ")
|
|
1513 (when (and (eq category 'group)
|
|
1514 (not (and (eq custom-buffer-style 'links)
|
|
1515 (> (widget-get parent :custom-level) 1))))
|
|
1516 (insert-char ?\ (* custom-buffer-indent
|
|
1517 (widget-get parent :custom-level))))
|
|
1518 (push (widget-create-child-and-convert
|
|
1519 widget 'choice-item
|
|
1520 :help-echo "Change the state of this item"
|
|
1521 :format (if hidden "%t" "%[%t%]")
|
|
1522 :button-prefix 'widget-push-button-prefix
|
|
1523 :button-suffix 'widget-push-button-suffix
|
|
1524 :mouse-down-action 'widget-magic-mouse-down-action
|
|
1525 :tag "State"
|
|
1526 ;;:tag-glyph (or hidden '("state-up" "state-down"))
|
|
1527 )
|
|
1528 children)
|
|
1529 (insert ": ")
|
|
1530 (let ((start (point)))
|
|
1531 (if (eq custom-magic-show 'long)
|
|
1532 (insert text)
|
|
1533 (insert (symbol-name state)))
|
|
1534 (cond ((eq form 'lisp)
|
|
1535 (insert " (lisp)"))
|
|
1536 ((eq form 'mismatch)
|
|
1537 (insert " (mismatch)")))
|
|
1538 (put-text-property start (point) 'face 'custom-state-face))
|
|
1539 (insert "\n"))
|
|
1540 (when (and (eq category 'group)
|
|
1541 (not (and (eq custom-buffer-style 'links)
|
|
1542 (> (widget-get parent :custom-level) 1))))
|
|
1543 (insert-char ?\ (* custom-buffer-indent
|
|
1544 (widget-get parent :custom-level))))
|
|
1545 (when custom-magic-show-button
|
|
1546 (when custom-magic-show
|
|
1547 (let ((indent (widget-get parent :indent)))
|
|
1548 (when indent
|
|
1549 (insert-char ?\ indent))))
|
|
1550 (push (widget-create-child-and-convert
|
|
1551 widget 'choice-item
|
|
1552 :mouse-down-action 'widget-magic-mouse-down-action
|
|
1553 :button-face face
|
|
1554 :button-prefix ""
|
|
1555 :button-suffix ""
|
|
1556 :help-echo "Change the state"
|
|
1557 :format (if hidden "%t" "%[%t%]")
|
|
1558 :tag (if (memq form '(lisp mismatch))
|
|
1559 (concat "(" magic ")")
|
|
1560 (concat "[" magic "]")))
|
|
1561 children)
|
|
1562 (insert " "))
|
|
1563 (widget-put widget :children children)))
|
|
1564
|
|
1565 (defun custom-magic-reset (widget)
|
|
1566 "Redraw the :custom-magic property of WIDGET."
|
|
1567 (let ((magic (widget-get widget :custom-magic)))
|
|
1568 (widget-value-set magic (widget-value magic))))
|
|
1569
|
|
1570 ;;; The `custom' Widget.
|
|
1571
|
|
1572 (defface custom-button-face '((t (:bold t)))
|
|
1573 "Face used for buttons in customization buffers."
|
|
1574 :group 'custom-faces)
|
|
1575
|
|
1576 (defface custom-documentation-face nil
|
|
1577 "Face used for documentation strings in customization buffers."
|
|
1578 :group 'custom-faces)
|
|
1579
|
|
1580 (defface custom-state-face '((((class color)
|
|
1581 (background dark))
|
|
1582 (:foreground "lime green"))
|
|
1583 (((class color)
|
|
1584 (background light))
|
|
1585 (:foreground "dark green"))
|
|
1586 (t nil))
|
|
1587 "Face used for State descriptions in the customize buffer."
|
|
1588 :group 'custom-faces)
|
|
1589
|
|
1590 (define-widget 'custom 'default
|
|
1591 "Customize a user option."
|
|
1592 :format "%v"
|
|
1593 :convert-widget 'custom-convert-widget
|
|
1594 :notify 'custom-notify
|
|
1595 :custom-prefix ""
|
|
1596 :custom-level 1
|
|
1597 :custom-state 'hidden
|
|
1598 :documentation-property 'widget-subclass-responsibility
|
|
1599 :value-create 'widget-subclass-responsibility
|
|
1600 :value-delete 'widget-children-value-delete
|
|
1601 :value-get 'widget-value-value-get
|
|
1602 :validate 'widget-children-validate
|
|
1603 :match (lambda (widget value) (symbolp value)))
|
|
1604
|
|
1605 (defun custom-convert-widget (widget)
|
|
1606 ;; Initialize :value and :tag from :args in WIDGET.
|
|
1607 (let ((args (widget-get widget :args)))
|
|
1608 (when args
|
|
1609 (widget-put widget :value (widget-apply widget
|
|
1610 :value-to-internal (car args)))
|
|
1611 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
|
|
1612 (widget-put widget :args nil)))
|
|
1613 widget)
|
|
1614
|
|
1615 (defun custom-notify (widget &rest args)
|
|
1616 "Keep track of changes."
|
|
1617 (let ((state (widget-get widget :custom-state)))
|
|
1618 (unless (eq state 'modified)
|
|
1619 (unless (memq state '(nil unknown hidden))
|
|
1620 (widget-put widget :custom-state 'modified))
|
|
1621 (custom-magic-reset widget)
|
|
1622 (apply 'widget-default-notify widget args))))
|
|
1623
|
|
1624 (defun custom-redraw (widget)
|
|
1625 "Redraw WIDGET with current settings."
|
|
1626 (let ((line (count-lines (point-min) (point)))
|
|
1627 (column (current-column))
|
|
1628 (pos (point))
|
|
1629 (from (marker-position (widget-get widget :from)))
|
|
1630 (to (marker-position (widget-get widget :to))))
|
|
1631 (save-excursion
|
|
1632 (widget-value-set widget (widget-value widget))
|
|
1633 (custom-redraw-magic widget))
|
|
1634 (when (and (>= pos from) (<= pos to))
|
|
1635 (condition-case nil
|
|
1636 (progn
|
|
1637 (if (> column 0)
|
|
1638 (goto-line line)
|
|
1639 (goto-line (1+ line)))
|
|
1640 (move-to-column column))
|
|
1641 (error nil)))))
|
|
1642
|
|
1643 (defun custom-redraw-magic (widget)
|
|
1644 "Redraw WIDGET state with current settings."
|
|
1645 (while widget
|
|
1646 (let ((magic (widget-get widget :custom-magic)))
|
|
1647 (cond (magic
|
|
1648 (widget-value-set magic (widget-value magic))
|
|
1649 (when (setq widget (widget-get widget :group))
|
|
1650 (custom-group-state-update widget)))
|
|
1651 (t
|
|
1652 (setq widget nil)))))
|
|
1653 (widget-setup))
|
|
1654
|
|
1655 (defun custom-show (widget value)
|
|
1656 "Non-nil if WIDGET should be shown with VALUE by default."
|
|
1657 (let ((show (widget-get widget :custom-show)))
|
|
1658 (cond ((null show)
|
|
1659 nil)
|
|
1660 ((eq t show)
|
|
1661 t)
|
|
1662 (t
|
|
1663 (funcall show widget value)))))
|
|
1664
|
|
1665 (defvar custom-load-recursion nil
|
|
1666 "Hack to avoid recursive dependencies.")
|
|
1667
|
|
1668 (defun custom-load-symbol (symbol)
|
|
1669 "Load all dependencies for SYMBOL."
|
|
1670 (unless custom-load-recursion
|
|
1671 (let ((custom-load-recursion t)
|
|
1672 (loads (get symbol 'custom-loads))
|
|
1673 load)
|
|
1674 (while loads
|
|
1675 (setq load (car loads)
|
|
1676 loads (cdr loads))
|
|
1677 (cond ((symbolp load)
|
|
1678 (condition-case nil
|
|
1679 (require load)
|
|
1680 (error nil)))
|
|
1681 ;; Don't reload a file already loaded.
|
|
1682 ((and (boundp 'preloaded-file-list)
|
|
1683 (member load preloaded-file-list)))
|
|
1684 ((assoc load load-history))
|
|
1685 ((assoc (locate-library load) load-history))
|
|
1686 (t
|
|
1687 (condition-case nil
|
|
1688 ;; Without this, we would load cus-edit recursively.
|
|
1689 ;; We are still loading it when we call this,
|
|
1690 ;; and it is not in load-history yet.
|
|
1691 (or (equal load "cus-edit")
|
|
1692 (load-library load))
|
|
1693 (error nil))))))))
|
|
1694
|
|
1695 (defun custom-load-widget (widget)
|
|
1696 "Load all dependencies for WIDGET."
|
|
1697 (custom-load-symbol (widget-value widget)))
|
|
1698
|
|
1699 (defun custom-unloaded-symbol-p (symbol)
|
|
1700 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
|
|
1701 (let ((found nil)
|
|
1702 (loads (get symbol 'custom-loads))
|
|
1703 load)
|
|
1704 (while loads
|
|
1705 (setq load (car loads)
|
|
1706 loads (cdr loads))
|
|
1707 (cond ((symbolp load)
|
|
1708 (unless (featurep load)
|
|
1709 (setq found t)))
|
|
1710 ((assoc load load-history))
|
|
1711 ((assoc (locate-library load) load-history)
|
|
1712 ;; #### WTF???
|
|
1713 (message nil))
|
|
1714 (t
|
|
1715 (setq found t))))
|
|
1716 found))
|
|
1717
|
|
1718 (defun custom-unloaded-widget-p (widget)
|
|
1719 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
|
|
1720 (custom-unloaded-symbol-p (widget-value widget)))
|
|
1721
|
|
1722 (defun custom-toggle-hide (widget)
|
|
1723 "Toggle visibility of WIDGET."
|
|
1724 (custom-load-widget widget)
|
|
1725 (let ((state (widget-get widget :custom-state)))
|
|
1726 (cond ((memq state '(invalid modified))
|
|
1727 (error "There are unset changes"))
|
|
1728 ((eq state 'hidden)
|
|
1729 (widget-put widget :custom-state 'unknown))
|
|
1730 (t
|
|
1731 (widget-put widget :documentation-shown nil)
|
|
1732 (widget-put widget :custom-state 'hidden)))
|
|
1733 (custom-redraw widget)
|
|
1734 (widget-setup)))
|
|
1735
|
|
1736 (defun custom-toggle-parent (widget &rest ignore)
|
|
1737 "Toggle visibility of parent of WIDGET."
|
|
1738 (custom-toggle-hide (widget-get widget :parent)))
|
|
1739
|
|
1740 (defun custom-add-see-also (widget &optional prefix)
|
|
1741 "Add `See also ...' to WIDGET if there are any links.
|
|
1742 Insert PREFIX first if non-nil."
|
|
1743 (let* ((symbol (widget-get widget :value))
|
|
1744 (links (get symbol 'custom-links))
|
|
1745 (many (> (length links) 2))
|
|
1746 (buttons (widget-get widget :buttons))
|
|
1747 (indent (widget-get widget :indent)))
|
|
1748 (when links
|
|
1749 (when indent
|
|
1750 (insert-char ?\ indent))
|
|
1751 (when prefix
|
|
1752 (insert prefix))
|
|
1753 (insert "See also ")
|
|
1754 (while links
|
|
1755 (push (widget-create-child-and-convert widget (car links))
|
|
1756 buttons)
|
|
1757 (setq links (cdr links))
|
|
1758 (cond ((null links)
|
|
1759 (insert ".\n"))
|
|
1760 ((null (cdr links))
|
|
1761 (if many
|
|
1762 (insert ", and ")
|
|
1763 (insert " and ")))
|
|
1764 (t
|
|
1765 (insert ", "))))
|
|
1766 (widget-put widget :buttons buttons))))
|
|
1767
|
|
1768 (defun custom-add-parent-links (widget &optional initial-string)
|
|
1769 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
|
|
1770 The value if non-nil if any parents were found.
|
|
1771 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
|
|
1772 (let ((name (widget-value widget))
|
|
1773 (type (widget-type widget))
|
|
1774 (buttons (widget-get widget :buttons))
|
|
1775 (start (point))
|
|
1776 found)
|
|
1777 (insert (or initial-string "Parent groups:"))
|
|
1778 (maphash (lambda (group ignore)
|
|
1779 (let ((entry (assq name (get group 'custom-group))))
|
|
1780 (when (eq (nth 1 entry) type)
|
|
1781 (insert " ")
|
|
1782 (push (widget-create-child-and-convert
|
|
1783 widget 'custom-group-link
|
|
1784 :tag (custom-unlispify-tag-name group)
|
|
1785 group)
|
|
1786 buttons)
|
|
1787 (setq found t))))
|
|
1788 custom-group-hash-table)
|
|
1789 (widget-put widget :buttons buttons)
|
|
1790 (if found
|
|
1791 (insert "\n")
|
|
1792 (delete-region start (point)))
|
|
1793 found))
|
|
1794
|
|
1795 ;;; The `custom-variable' Widget.
|
|
1796
|
|
1797 (defface custom-variable-tag-face '((((class color)
|
|
1798 (background dark))
|
|
1799 (:foreground "light blue" :underline t))
|
|
1800 (((class color)
|
|
1801 (background light))
|
|
1802 (:foreground "blue" :underline t))
|
|
1803 (t (:underline t)))
|
|
1804 "Face used for unpushable variable tags."
|
|
1805 :group 'custom-faces)
|
|
1806
|
|
1807 (defface custom-variable-button-face '((t (:underline t :bold t)))
|
|
1808 "Face used for pushable variable tags."
|
|
1809 :group 'custom-faces)
|
|
1810
|
219
|
1811 (defcustom custom-variable-default-form 'edit
|
|
1812 "Default form of displaying variable values."
|
|
1813 :type '(choice (const edit)
|
|
1814 (const lisp))
|
|
1815 :group 'custom-buffer)
|
|
1816
|
209
|
1817 (define-widget 'custom-variable 'custom
|
|
1818 "Customize variable."
|
|
1819 :format "%v"
|
|
1820 :help-echo "Set or reset this variable"
|
|
1821 :documentation-property 'variable-documentation
|
|
1822 :custom-category 'option
|
|
1823 :custom-state nil
|
|
1824 :custom-menu 'custom-variable-menu-create
|
219
|
1825 :custom-form nil ; defaults to value of `custom-variable-default-form'
|
209
|
1826 :value-create 'custom-variable-value-create
|
|
1827 :action 'custom-variable-action
|
|
1828 :custom-set 'custom-variable-set
|
|
1829 :custom-save 'custom-variable-save
|
|
1830 :custom-reset-current 'custom-redraw
|
|
1831 :custom-reset-saved 'custom-variable-reset-saved
|
|
1832 :custom-reset-standard 'custom-variable-reset-standard)
|
|
1833
|
|
1834 (defun custom-variable-type (symbol)
|
|
1835 "Return a widget suitable for editing the value of SYMBOL.
|
|
1836 If SYMBOL has a `custom-type' property, use that.
|
|
1837 Otherwise, look up symbol in `custom-guess-type-alist'."
|
|
1838 (let* ((type (or (get symbol 'custom-type)
|
|
1839 (and (not (get symbol 'standard-value))
|
|
1840 (custom-guess-type symbol))
|
|
1841 'sexp))
|
|
1842 (options (get symbol 'custom-options))
|
|
1843 (tmp (if (listp type)
|
|
1844 (copy-sequence type)
|
|
1845 (list type))))
|
|
1846 (when options
|
|
1847 (widget-put tmp :options options))
|
|
1848 tmp))
|
|
1849
|
|
1850 (defun custom-variable-value-create (widget)
|
|
1851 "Here is where you edit the variables value."
|
|
1852 (custom-load-widget widget)
|
219
|
1853 (unless (widget-get widget :custom-form)
|
|
1854 (widget-put widget :custom-form custom-variable-default-form))
|
209
|
1855 (let* ((buttons (widget-get widget :buttons))
|
|
1856 (children (widget-get widget :children))
|
|
1857 (form (widget-get widget :custom-form))
|
|
1858 (state (widget-get widget :custom-state))
|
|
1859 (symbol (widget-get widget :value))
|
|
1860 (tag (widget-get widget :tag))
|
|
1861 (type (custom-variable-type symbol))
|
|
1862 (conv (widget-convert type))
|
|
1863 (get (or (get symbol 'custom-get) 'default-value))
|
|
1864 (prefix (widget-get widget :custom-prefix))
|
|
1865 (last (widget-get widget :custom-last))
|
|
1866 (value (if (default-boundp symbol)
|
|
1867 (funcall get symbol)
|
|
1868 (widget-get conv :value))))
|
|
1869 ;; If the widget is new, the child determine whether it is hidden.
|
|
1870 (cond (state)
|
|
1871 ((custom-show type value)
|
|
1872 (setq state 'unknown))
|
|
1873 (t
|
|
1874 (setq state 'hidden)))
|
|
1875 ;; If we don't know the state, see if we need to edit it in lisp form.
|
|
1876 (when (eq state 'unknown)
|
|
1877 (unless (widget-apply conv :match value)
|
|
1878 ;; (widget-apply (widget-convert type) :match value)
|
|
1879 (setq form 'mismatch)))
|
|
1880 ;; Now we can create the child widget.
|
|
1881 (cond ((eq custom-buffer-style 'tree)
|
|
1882 (insert prefix (if last " `--- " " |--- "))
|
|
1883 (push (widget-create-child-and-convert
|
|
1884 widget 'custom-browse-variable-tag)
|
|
1885 buttons)
|
|
1886 (insert " " tag "\n")
|
|
1887 (widget-put widget :buttons buttons))
|
|
1888 ((eq state 'hidden)
|
|
1889 ;; Indicate hidden value.
|
|
1890 (push (widget-create-child-and-convert
|
|
1891 widget 'item
|
|
1892 :format "%{%t%}: "
|
|
1893 :sample-face 'custom-variable-tag-face
|
|
1894 :tag tag
|
|
1895 :parent widget)
|
|
1896 buttons)
|
|
1897 (push (widget-create-child-and-convert
|
|
1898 widget 'visibility
|
|
1899 :help-echo "Show the value of this option"
|
|
1900 :action 'custom-toggle-parent
|
|
1901 nil)
|
|
1902 buttons))
|
|
1903 ((memq form '(lisp mismatch))
|
|
1904 ;; In lisp mode edit the saved value when possible.
|
|
1905 (let* ((value (cond ((get symbol 'saved-value)
|
|
1906 (car (get symbol 'saved-value)))
|
|
1907 ((get symbol 'standard-value)
|
|
1908 (car (get symbol 'standard-value)))
|
|
1909 ((default-boundp symbol)
|
|
1910 (custom-quote (funcall get symbol)))
|
|
1911 (t
|
|
1912 (custom-quote (widget-get conv :value))))))
|
|
1913 (insert (symbol-name symbol) ": ")
|
|
1914 (push (widget-create-child-and-convert
|
|
1915 widget 'visibility
|
|
1916 :help-echo "Hide the value of this option"
|
|
1917 :action 'custom-toggle-parent
|
|
1918 t)
|
|
1919 buttons)
|
|
1920 (insert " ")
|
|
1921 (push (widget-create-child-and-convert
|
|
1922 widget 'sexp
|
|
1923 :button-face 'custom-variable-button-face
|
|
1924 :format "%v"
|
|
1925 :tag (symbol-name symbol)
|
|
1926 :parent widget
|
|
1927 :value value)
|
|
1928 children)))
|
|
1929 (t
|
|
1930 ;; Edit mode.
|
|
1931 (let* ((format (widget-get type :format))
|
|
1932 tag-format value-format)
|
|
1933 (unless (string-match ":" format)
|
|
1934 (error "Bad format."))
|
|
1935 (setq tag-format (substring format 0 (match-end 0)))
|
|
1936 (setq value-format (substring format (match-end 0)))
|
|
1937 (push (widget-create-child-and-convert
|
|
1938 widget 'item
|
|
1939 :format tag-format
|
|
1940 :action 'custom-tag-action
|
|
1941 :help-echo "Change value of this option"
|
|
1942 :mouse-down-action 'custom-tag-mouse-down-action
|
|
1943 :button-face 'custom-variable-button-face
|
|
1944 :sample-face 'custom-variable-tag-face
|
|
1945 tag)
|
|
1946 buttons)
|
|
1947 (insert " ")
|
|
1948 (push (widget-create-child-and-convert
|
|
1949 widget 'visibility
|
|
1950 :help-echo "Hide the value of this option"
|
|
1951 :action 'custom-toggle-parent
|
|
1952 t)
|
|
1953 buttons)
|
|
1954 (push (widget-create-child-and-convert
|
|
1955 widget type
|
|
1956 :format value-format
|
|
1957 :value value)
|
|
1958 children))))
|
|
1959 (unless (eq custom-buffer-style 'tree)
|
|
1960 ;; Now update the state.
|
|
1961 (unless (eq (preceding-char) ?\n)
|
|
1962 (widget-insert "\n"))
|
|
1963 (if (eq state 'hidden)
|
|
1964 (widget-put widget :custom-state state)
|
|
1965 (custom-variable-state-set widget))
|
|
1966 ;; Create the magic button.
|
|
1967 (let ((magic (widget-create-child-and-convert
|
|
1968 widget 'custom-magic nil)))
|
|
1969 (widget-put widget :custom-magic magic)
|
|
1970 (push magic buttons))
|
|
1971 ;; Update properties.
|
|
1972 (widget-put widget :custom-form form)
|
|
1973 (widget-put widget :buttons buttons)
|
|
1974 (widget-put widget :children children)
|
|
1975 ;; Insert documentation.
|
|
1976 (widget-default-format-handler widget ?h)
|
|
1977 ;; See also.
|
|
1978 (unless (eq state 'hidden)
|
|
1979 (when (eq (widget-get widget :custom-level) 1)
|
|
1980 (custom-add-parent-links widget))
|
|
1981 (custom-add-see-also widget)))))
|
|
1982
|
|
1983 (defun custom-tag-action (widget &rest args)
|
|
1984 "Pass :action to first child of WIDGET's parent."
|
|
1985 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
|
|
1986 :action args))
|
|
1987
|
|
1988 (defun custom-tag-mouse-down-action (widget &rest args)
|
|
1989 "Pass :mouse-down-action to first child of WIDGET's parent."
|
|
1990 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
|
|
1991 :mouse-down-action args))
|
|
1992
|
|
1993 (defun custom-variable-state-set (widget)
|
|
1994 "Set the state of WIDGET."
|
|
1995 (let* ((symbol (widget-value widget))
|
|
1996 (get (or (get symbol 'custom-get) 'default-value))
|
|
1997 (value (if (default-boundp symbol)
|
|
1998 (funcall get symbol)
|
|
1999 (widget-get widget :value)))
|
|
2000 tmp
|
|
2001 (state (cond ((setq tmp (get symbol 'customized-value))
|
|
2002 (if (condition-case nil
|
|
2003 (equal value (eval (car tmp)))
|
|
2004 (error nil))
|
|
2005 'set
|
|
2006 'changed))
|
|
2007 ((setq tmp (get symbol 'saved-value))
|
|
2008 (if (condition-case nil
|
|
2009 (equal value (eval (car tmp)))
|
|
2010 (error nil))
|
|
2011 'saved
|
|
2012 'changed))
|
|
2013 ((setq tmp (get symbol 'standard-value))
|
|
2014 (if (condition-case nil
|
|
2015 (equal value (eval (car tmp)))
|
|
2016 (error nil))
|
|
2017 'standard
|
|
2018 'changed))
|
|
2019 (t 'rogue))))
|
|
2020 (widget-put widget :custom-state state)))
|
|
2021
|
|
2022 (defvar custom-variable-menu
|
|
2023 '(("Set for Current Session" custom-variable-set
|
|
2024 (lambda (widget)
|
|
2025 (eq (widget-get widget :custom-state) 'modified)))
|
|
2026 ("Save for Future Sessions" custom-variable-save
|
|
2027 (lambda (widget)
|
|
2028 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
|
|
2029 ("Reset to Current" custom-redraw
|
|
2030 (lambda (widget)
|
|
2031 (and (default-boundp (widget-value widget))
|
|
2032 (memq (widget-get widget :custom-state) '(modified changed)))))
|
|
2033 ("Reset to Saved" custom-variable-reset-saved
|
|
2034 (lambda (widget)
|
|
2035 (and (get (widget-value widget) 'saved-value)
|
|
2036 (memq (widget-get widget :custom-state)
|
|
2037 '(modified set changed rogue)))))
|
|
2038 ("Reset to Standard Settings" custom-variable-reset-standard
|
|
2039 (lambda (widget)
|
|
2040 (and (get (widget-value widget) 'standard-value)
|
|
2041 (memq (widget-get widget :custom-state)
|
|
2042 '(modified set changed saved rogue)))))
|
|
2043 ("---" ignore ignore)
|
|
2044 ("Don't show as Lisp expression" custom-variable-edit
|
|
2045 (lambda (widget)
|
|
2046 (eq (widget-get widget :custom-form) 'lisp)))
|
|
2047 ("Show as Lisp expression" custom-variable-edit-lisp
|
|
2048 (lambda (widget)
|
|
2049 (eq (widget-get widget :custom-form) 'edit))))
|
|
2050 "Alist of actions for the `custom-variable' widget.
|
|
2051 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
2052 the menu entry, ACTION is the function to call on the widget when the
|
|
2053 menu is selected, and FILTER is a predicate which takes a `custom-variable'
|
|
2054 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
2055 widget. If FILTER is nil, ACTION is always valid.")
|
|
2056
|
|
2057 (defun custom-variable-action (widget &optional event)
|
|
2058 "Show the menu for `custom-variable' WIDGET.
|
|
2059 Optional EVENT is the location for the menu."
|
|
2060 (if (eq (widget-get widget :custom-state) 'hidden)
|
|
2061 (custom-toggle-hide widget)
|
|
2062 (unless (eq (widget-get widget :custom-state) 'modified)
|
|
2063 (custom-variable-state-set widget))
|
|
2064 ;; Redrawing magic also depresses the state glyph.
|
|
2065 ;(custom-redraw-magic widget)
|
|
2066 (let* ((completion-ignore-case t)
|
|
2067 (answer (widget-choose (concat "Operation on "
|
|
2068 (custom-unlispify-tag-name
|
|
2069 (widget-get widget :value)))
|
|
2070 (custom-menu-filter custom-variable-menu
|
|
2071 widget)
|
|
2072 event)))
|
|
2073 (if answer
|
|
2074 (funcall answer widget)))))
|
|
2075
|
|
2076 (defun custom-variable-edit (widget)
|
|
2077 "Edit value of WIDGET."
|
|
2078 (widget-put widget :custom-state 'unknown)
|
|
2079 (widget-put widget :custom-form 'edit)
|
|
2080 (custom-redraw widget))
|
|
2081
|
|
2082 (defun custom-variable-edit-lisp (widget)
|
|
2083 "Edit the lisp representation of the value of WIDGET."
|
|
2084 (widget-put widget :custom-state 'unknown)
|
|
2085 (widget-put widget :custom-form 'lisp)
|
|
2086 (custom-redraw widget))
|
|
2087
|
|
2088 (defun custom-variable-set (widget)
|
|
2089 "Set the current 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 (funcall set symbol (eval (setq val (widget-value child))))
|
|
2103 (put symbol 'customized-value (list val)))
|
|
2104 (t
|
|
2105 (funcall set symbol (setq val (widget-value child)))
|
|
2106 (put symbol 'customized-value (list (custom-quote val)))))
|
|
2107 (custom-variable-state-set widget)
|
|
2108 (custom-redraw-magic widget)))
|
|
2109
|
|
2110 (defun custom-variable-save (widget)
|
|
2111 "Set and save the value for the variable being edited by WIDGET."
|
|
2112 (let* ((form (widget-get widget :custom-form))
|
|
2113 (state (widget-get widget :custom-state))
|
|
2114 (child (car (widget-get widget :children)))
|
|
2115 (symbol (widget-value widget))
|
|
2116 (set (or (get symbol 'custom-set) 'set-default))
|
|
2117 val)
|
|
2118 (cond ((eq state 'hidden)
|
|
2119 (error "Cannot set hidden variable."))
|
|
2120 ((setq val (widget-apply child :validate))
|
|
2121 (goto-char (widget-get val :from))
|
|
2122 (error "%s" (widget-get val :error)))
|
|
2123 ((memq form '(lisp mismatch))
|
|
2124 (put symbol 'saved-value (list (widget-value child)))
|
|
2125 (funcall set symbol (eval (widget-value child))))
|
|
2126 (t
|
|
2127 (put symbol
|
|
2128 'saved-value (list (custom-quote (widget-value
|
|
2129 child))))
|
|
2130 (funcall set symbol (widget-value child))))
|
|
2131 (put symbol 'customized-value nil)
|
|
2132 (custom-save-all)
|
|
2133 (custom-variable-state-set widget)
|
|
2134 (custom-redraw-magic widget)))
|
|
2135
|
|
2136 (defun custom-variable-reset-saved (widget)
|
|
2137 "Restore the saved value for the variable being edited by WIDGET."
|
|
2138 (let* ((symbol (widget-value widget))
|
|
2139 (set (or (get symbol 'custom-set) 'set-default)))
|
|
2140 (if (get symbol 'saved-value)
|
|
2141 (condition-case nil
|
|
2142 (funcall set symbol (eval (car (get symbol 'saved-value))))
|
|
2143 (error nil))
|
|
2144 (error "No saved value for %s" symbol))
|
|
2145 (put symbol 'customized-value nil)
|
|
2146 (widget-put widget :custom-state 'unknown)
|
|
2147 (custom-redraw widget)))
|
|
2148
|
|
2149 (defun custom-variable-reset-standard (widget)
|
|
2150 "Restore the standard setting for the variable being edited by WIDGET."
|
|
2151 (let* ((symbol (widget-value widget))
|
|
2152 (set (or (get symbol 'custom-set) 'set-default)))
|
|
2153 (if (get symbol 'standard-value)
|
|
2154 (funcall set symbol (eval (car (get symbol 'standard-value))))
|
|
2155 (error "No standard setting known for %S" symbol))
|
|
2156 (put symbol 'customized-value nil)
|
|
2157 (when (get symbol 'saved-value)
|
|
2158 (put symbol 'saved-value nil)
|
|
2159 (custom-save-all))
|
|
2160 (widget-put widget :custom-state 'unknown)
|
|
2161 (custom-redraw widget)))
|
|
2162
|
|
2163 ;;; The `custom-face-edit' Widget.
|
|
2164
|
|
2165 (define-widget 'custom-face-edit 'checklist
|
|
2166 "Edit face attributes."
|
|
2167 :format "%t: %v"
|
|
2168 :tag "Attributes"
|
|
2169 :extra-offset 12
|
|
2170 :button-args '(:help-echo "Control whether this attribute have any effect")
|
|
2171 :args (mapcar (lambda (att)
|
|
2172 (list 'group
|
|
2173 :inline t
|
|
2174 :sibling-args (widget-get (nth 1 att) :sibling-args)
|
|
2175 (list 'const :format "" :value (nth 0 att))
|
|
2176 (nth 1 att)))
|
|
2177 custom-face-attributes))
|
|
2178
|
|
2179 ;;; The `custom-display' Widget.
|
|
2180
|
|
2181 (define-widget 'custom-display 'menu-choice
|
|
2182 "Select a display type."
|
|
2183 :tag "Display"
|
|
2184 :value t
|
|
2185 :help-echo "Specify frames where the face attributes should be used"
|
|
2186 :args '((const :tag "all" t)
|
|
2187 (checklist
|
|
2188 :offset 0
|
|
2189 :extra-offset 9
|
|
2190 :args ((group :sibling-args (:help-echo "\
|
|
2191 Only match the specified window systems")
|
|
2192 (const :format "Type: "
|
|
2193 type)
|
|
2194 (checklist :inline t
|
|
2195 :offset 0
|
|
2196 (const :format "X "
|
|
2197 :sibling-args (:help-echo "\
|
|
2198 The X11 Window System")
|
|
2199 x)
|
|
2200 (const :format "PM "
|
|
2201 :sibling-args (:help-echo "\
|
|
2202 OS/2 Presentation Manager")
|
|
2203 pm)
|
213
|
2204 (const :format "MSWindows "
|
209
|
2205 :sibling-args (:help-echo "\
|
|
2206 Windows NT/95/97")
|
213
|
2207 mswindows)
|
209
|
2208 (const :format "DOS "
|
|
2209 :sibling-args (:help-echo "\
|
|
2210 Plain MS-DOS")
|
|
2211 pc)
|
|
2212 (const :format "TTY%n"
|
|
2213 :sibling-args (:help-echo "\
|
|
2214 Plain text terminals")
|
|
2215 tty)))
|
|
2216 (group :sibling-args (:help-echo "\
|
|
2217 Only match the frames with the specified color support")
|
|
2218 (const :format "Class: "
|
|
2219 class)
|
|
2220 (checklist :inline t
|
|
2221 :offset 0
|
|
2222 (const :format "Color "
|
|
2223 :sibling-args (:help-echo "\
|
|
2224 Match color frames")
|
|
2225 color)
|
|
2226 (const :format "Grayscale "
|
|
2227 :sibling-args (:help-echo "\
|
|
2228 Match grayscale frames")
|
|
2229 grayscale)
|
|
2230 (const :format "Monochrome%n"
|
|
2231 :sibling-args (:help-echo "\
|
|
2232 Match frames with no color support")
|
|
2233 mono)))
|
|
2234 (group :sibling-args (:help-echo "\
|
|
2235 Only match frames with the specified intensity")
|
|
2236 (const :format "\
|
|
2237 Background brightness: "
|
|
2238 background)
|
|
2239 (checklist :inline t
|
|
2240 :offset 0
|
|
2241 (const :format "Light "
|
|
2242 :sibling-args (:help-echo "\
|
|
2243 Match frames with light backgrounds")
|
|
2244 light)
|
|
2245 (const :format "Dark\n"
|
|
2246 :sibling-args (:help-echo "\
|
|
2247 Match frames with dark backgrounds")
|
|
2248 dark)))))))
|
|
2249
|
|
2250 ;;; The `custom-face' Widget.
|
|
2251
|
|
2252 (defface custom-face-tag-face '((t (:underline t)))
|
|
2253 "Face used for face tags."
|
|
2254 :group 'custom-faces)
|
|
2255
|
219
|
2256 (defcustom custom-face-default-form 'selected
|
|
2257 "Default form of displaying face definition."
|
|
2258 :type '(choice (const all)
|
|
2259 (const selected)
|
|
2260 (const lisp))
|
|
2261 :group 'custom-buffer)
|
|
2262
|
209
|
2263 (define-widget 'custom-face 'custom
|
|
2264 "Customize face."
|
|
2265 :sample-face 'custom-face-tag-face
|
|
2266 :help-echo "Set or reset this face"
|
|
2267 :documentation-property '(lambda (face)
|
|
2268 (face-doc-string face))
|
|
2269 :value-create 'custom-face-value-create
|
|
2270 :action 'custom-face-action
|
|
2271 :custom-category 'face
|
219
|
2272 :custom-form nil ; defaults to value of `custom-face-default-form'
|
209
|
2273 :custom-set 'custom-face-set
|
|
2274 :custom-save 'custom-face-save
|
|
2275 :custom-reset-current 'custom-redraw
|
|
2276 :custom-reset-saved 'custom-face-reset-saved
|
|
2277 :custom-reset-standard 'custom-face-reset-standard
|
|
2278 :custom-menu 'custom-face-menu-create)
|
|
2279
|
|
2280 (define-widget 'custom-face-all 'editable-list
|
|
2281 "An editable list of display specifications and attributes."
|
|
2282 :entry-format "%i %d %v"
|
|
2283 :insert-button-args '(:help-echo "Insert new display specification here")
|
|
2284 :append-button-args '(:help-echo "Append new display specification here")
|
|
2285 :delete-button-args '(:help-echo "Delete this display specification")
|
|
2286 :args '((group :format "%v" custom-display custom-face-edit)))
|
|
2287
|
|
2288 (defconst custom-face-all (widget-convert 'custom-face-all)
|
|
2289 "Converted version of the `custom-face-all' widget.")
|
|
2290
|
|
2291 (define-widget 'custom-display-unselected 'item
|
|
2292 "A display specification that doesn't match the selected display."
|
|
2293 :match 'custom-display-unselected-match)
|
|
2294
|
|
2295 (defun custom-display-unselected-match (widget value)
|
|
2296 "Non-nil if VALUE is an unselected display specification."
|
|
2297 (not (face-spec-set-match-display value (selected-frame))))
|
|
2298
|
|
2299 (define-widget 'custom-face-selected 'group
|
|
2300 "Edit the attributes of the selected display in a face specification."
|
|
2301 :args '((repeat :format ""
|
|
2302 :inline t
|
|
2303 (group custom-display-unselected sexp))
|
|
2304 (group (sexp :format "") custom-face-edit)
|
|
2305 (repeat :format ""
|
|
2306 :inline t
|
|
2307 sexp)))
|
|
2308
|
|
2309 (defconst custom-face-selected (widget-convert 'custom-face-selected)
|
|
2310 "Converted version of the `custom-face-selected' widget.")
|
|
2311
|
|
2312 (defun custom-face-value-create (widget)
|
|
2313 "Create a list of the display specifications for WIDGET."
|
|
2314 (let ((buttons (widget-get widget :buttons))
|
|
2315 (symbol (widget-get widget :value))
|
|
2316 (tag (widget-get widget :tag))
|
|
2317 (state (widget-get widget :custom-state))
|
|
2318 (begin (point))
|
|
2319 (is-last (widget-get widget :custom-last))
|
|
2320 (prefix (widget-get widget :custom-prefix)))
|
|
2321 (unless tag
|
|
2322 (setq tag (prin1-to-string symbol)))
|
|
2323 (cond ((eq custom-buffer-style 'tree)
|
|
2324 (insert prefix (if is-last " `--- " " |--- "))
|
|
2325 (push (widget-create-child-and-convert
|
|
2326 widget 'custom-browse-face-tag)
|
|
2327 buttons)
|
|
2328 (insert " " tag "\n")
|
|
2329 (widget-put widget :buttons buttons))
|
|
2330 (t
|
|
2331 ;; Create tag.
|
|
2332 (insert tag)
|
|
2333 (if (eq custom-buffer-style 'face)
|
|
2334 (insert " ")
|
|
2335 (widget-specify-sample widget begin (point))
|
|
2336 (insert ": "))
|
|
2337 ;; Sample.
|
|
2338 (and (not (find-face symbol))
|
|
2339 ;; XEmacs cannot display uninitialized faces.
|
|
2340 (make-face symbol))
|
|
2341 (push (widget-create-child-and-convert widget 'item
|
|
2342 :format "(%{%t%})"
|
|
2343 :sample-face symbol
|
|
2344 :tag "sample")
|
|
2345 buttons)
|
|
2346 ;; Visibility.
|
|
2347 (insert " ")
|
|
2348 (push (widget-create-child-and-convert
|
|
2349 widget 'visibility
|
|
2350 :help-echo "Hide or show this face"
|
|
2351 :action 'custom-toggle-parent
|
|
2352 (not (eq state 'hidden)))
|
|
2353 buttons)
|
|
2354 ;; Magic.
|
|
2355 (insert "\n")
|
|
2356 (let ((magic (widget-create-child-and-convert
|
|
2357 widget 'custom-magic nil)))
|
|
2358 (widget-put widget :custom-magic magic)
|
|
2359 (push magic buttons))
|
|
2360 ;; Update buttons.
|
|
2361 (widget-put widget :buttons buttons)
|
|
2362 ;; Insert documentation.
|
|
2363 (widget-default-format-handler widget ?h)
|
|
2364 ;; See also.
|
|
2365 (unless (eq state 'hidden)
|
|
2366 (when (eq (widget-get widget :custom-level) 1)
|
|
2367 (custom-add-parent-links widget))
|
|
2368 (custom-add-see-also widget))
|
|
2369 ;; Editor.
|
|
2370 (unless (eq (preceding-char) ?\n)
|
|
2371 (insert "\n"))
|
|
2372 (unless (eq state 'hidden)
|
|
2373 (message "Creating face editor...")
|
|
2374 (custom-load-widget widget)
|
219
|
2375 (unless (widget-get widget :custom-form)
|
|
2376 (widget-put widget :custom-form custom-face-default-form))
|
209
|
2377 (let* ((symbol (widget-value widget))
|
|
2378 (spec (or (get symbol 'saved-face)
|
|
2379 (get symbol 'face-defface-spec)
|
|
2380 ;; Attempt to construct it.
|
|
2381 (list (list t (face-custom-attributes-get
|
|
2382 symbol (selected-frame))))))
|
|
2383 (form (widget-get widget :custom-form))
|
|
2384 (indent (widget-get widget :indent))
|
|
2385 (edit (widget-create-child-and-convert
|
|
2386 widget
|
|
2387 (cond ((and (eq form 'selected)
|
|
2388 (widget-apply custom-face-selected
|
|
2389 :match spec))
|
|
2390 (when indent (insert-char ?\ indent))
|
|
2391 'custom-face-selected)
|
|
2392 ((and (not (eq form 'lisp))
|
|
2393 (widget-apply custom-face-all
|
|
2394 :match spec))
|
|
2395 'custom-face-all)
|
|
2396 (t
|
|
2397 (when indent (insert-char ?\ indent))
|
|
2398 'sexp))
|
|
2399 :value spec)))
|
|
2400 (custom-face-state-set widget)
|
|
2401 (widget-put widget :children (list edit)))
|
|
2402 (message "Creating face editor...done"))))))
|
|
2403
|
|
2404 (defvar custom-face-menu
|
|
2405 '(("Set for Current Session" custom-face-set)
|
|
2406 ("Save for Future Sessions" custom-face-save)
|
|
2407 ("Reset to Saved" custom-face-reset-saved
|
|
2408 (lambda (widget)
|
|
2409 (get (widget-value widget) 'saved-face)))
|
|
2410 ("Reset to Standard Setting" custom-face-reset-standard
|
|
2411 (lambda (widget)
|
|
2412 (get (widget-value widget) 'face-defface-spec)))
|
|
2413 ("---" ignore ignore)
|
|
2414 ("Show all display specs" custom-face-edit-all
|
|
2415 (lambda (widget)
|
|
2416 (not (eq (widget-get widget :custom-form) 'all))))
|
|
2417 ("Just current attributes" custom-face-edit-selected
|
|
2418 (lambda (widget)
|
|
2419 (not (eq (widget-get widget :custom-form) 'selected))))
|
|
2420 ("Show as Lisp expression" custom-face-edit-lisp
|
|
2421 (lambda (widget)
|
|
2422 (not (eq (widget-get widget :custom-form) 'lisp)))))
|
|
2423 "Alist of actions for the `custom-face' widget.
|
|
2424 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
2425 the menu entry, ACTION is the function to call on the widget when the
|
|
2426 menu is selected, and FILTER is a predicate which takes a `custom-face'
|
|
2427 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
2428 widget. If FILTER is nil, ACTION is always valid.")
|
|
2429
|
|
2430 (defun custom-face-edit-selected (widget)
|
|
2431 "Edit selected attributes of the value of WIDGET."
|
|
2432 (widget-put widget :custom-state 'unknown)
|
|
2433 (widget-put widget :custom-form 'selected)
|
|
2434 (custom-redraw widget))
|
|
2435
|
|
2436 (defun custom-face-edit-all (widget)
|
|
2437 "Edit all attributes of the value of WIDGET."
|
|
2438 (widget-put widget :custom-state 'unknown)
|
|
2439 (widget-put widget :custom-form 'all)
|
|
2440 (custom-redraw widget))
|
|
2441
|
|
2442 (defun custom-face-edit-lisp (widget)
|
|
2443 "Edit the lisp representation of the value of WIDGET."
|
|
2444 (widget-put widget :custom-state 'unknown)
|
|
2445 (widget-put widget :custom-form 'lisp)
|
|
2446 (custom-redraw widget))
|
|
2447
|
|
2448 (defun custom-face-state-set (widget)
|
|
2449 "Set the state of WIDGET."
|
|
2450 (let ((symbol (widget-value widget)))
|
|
2451 (widget-put widget :custom-state (cond ((get symbol 'customized-face)
|
|
2452 'set)
|
|
2453 ((get symbol 'saved-face)
|
|
2454 'saved)
|
|
2455 ((get symbol 'face-defface-spec)
|
|
2456 'standard)
|
|
2457 (t
|
|
2458 'rogue)))))
|
|
2459
|
|
2460 (defun custom-face-action (widget &optional event)
|
|
2461 "Show the menu for `custom-face' WIDGET.
|
|
2462 Optional EVENT is the location for the menu."
|
|
2463 (if (eq (widget-get widget :custom-state) 'hidden)
|
|
2464 (custom-toggle-hide widget)
|
|
2465 (let* ((completion-ignore-case t)
|
|
2466 (symbol (widget-get widget :value))
|
|
2467 (answer (widget-choose (concat "Operation on "
|
|
2468 (custom-unlispify-tag-name symbol))
|
|
2469 (custom-menu-filter custom-face-menu
|
|
2470 widget)
|
|
2471 event)))
|
|
2472 (if answer
|
|
2473 (funcall answer widget)))))
|
|
2474
|
|
2475 (defun custom-face-set (widget)
|
|
2476 "Make the face attributes in WIDGET take effect."
|
|
2477 (let* ((symbol (widget-value widget))
|
|
2478 (child (car (widget-get widget :children)))
|
|
2479 (value (widget-value child)))
|
|
2480 (put symbol 'customized-face value)
|
|
2481 (face-spec-set symbol value)
|
|
2482 (custom-face-state-set widget)
|
|
2483 (custom-redraw-magic widget)))
|
|
2484
|
|
2485 (defun custom-face-save (widget)
|
|
2486 "Make the face attributes in WIDGET default."
|
|
2487 (let* ((symbol (widget-value widget))
|
|
2488 (child (car (widget-get widget :children)))
|
|
2489 (value (widget-value child)))
|
|
2490 (face-spec-set symbol value)
|
|
2491 (put symbol 'saved-face value)
|
|
2492 (put symbol 'customized-face nil)
|
213
|
2493 (custom-save-all)
|
209
|
2494 (custom-face-state-set widget)
|
|
2495 (custom-redraw-magic widget)))
|
|
2496
|
|
2497 (defun custom-face-reset-saved (widget)
|
|
2498 "Restore WIDGET to the face's default attributes."
|
|
2499 (let* ((symbol (widget-value widget))
|
|
2500 (child (car (widget-get widget :children)))
|
|
2501 (value (get symbol 'saved-face)))
|
|
2502 (unless value
|
|
2503 (error "No saved value for this face"))
|
|
2504 (put symbol 'customized-face nil)
|
|
2505 (face-spec-set symbol value)
|
|
2506 (widget-value-set child value)
|
|
2507 (custom-face-state-set widget)
|
|
2508 (custom-redraw-magic widget)))
|
|
2509
|
|
2510 (defun custom-face-reset-standard (widget)
|
|
2511 "Restore WIDGET to the face's standard settings."
|
|
2512 (let* ((symbol (widget-value widget))
|
|
2513 (child (car (widget-get widget :children)))
|
|
2514 (value (get symbol 'face-defface-spec)))
|
|
2515 (unless value
|
|
2516 (error "No standard setting for this face"))
|
|
2517 (put symbol 'customized-face nil)
|
|
2518 (when (get symbol 'saved-face)
|
|
2519 (put symbol 'saved-face nil)
|
|
2520 (custom-save-all))
|
|
2521 (face-spec-set symbol value)
|
|
2522 (widget-value-set child value)
|
|
2523 (custom-face-state-set widget)
|
|
2524 (custom-redraw-magic widget)))
|
|
2525
|
|
2526 ;;; The `face' Widget.
|
|
2527
|
|
2528 (define-widget 'face 'default
|
|
2529 "Select and customize a face."
|
|
2530 :convert-widget 'widget-value-convert-widget
|
|
2531 :button-prefix 'widget-push-button-prefix
|
|
2532 :button-suffix 'widget-push-button-suffix
|
|
2533 :format "%t: %[select face%] %v"
|
|
2534 :tag "Face"
|
|
2535 :value 'default
|
|
2536 :value-create 'widget-face-value-create
|
|
2537 :value-delete 'widget-face-value-delete
|
|
2538 :value-get 'widget-value-value-get
|
|
2539 :validate 'widget-children-validate
|
|
2540 :action 'widget-face-action
|
|
2541 :match (lambda (widget value) (symbolp value)))
|
|
2542
|
|
2543 (defun widget-face-value-create (widget)
|
|
2544 ;; Create a `custom-face' child.
|
|
2545 (let* ((symbol (widget-value widget))
|
|
2546 (custom-buffer-style 'face)
|
|
2547 (child (widget-create-child-and-convert
|
|
2548 widget 'custom-face
|
|
2549 :custom-level nil
|
|
2550 :value symbol)))
|
|
2551 (custom-magic-reset child)
|
|
2552 (setq custom-options (cons child custom-options))
|
|
2553 (widget-put widget :children (list child))))
|
|
2554
|
|
2555 (defun widget-face-value-delete (widget)
|
|
2556 ;; Remove the child from the options.
|
|
2557 (let ((child (car (widget-get widget :children))))
|
|
2558 (setq custom-options (delq child custom-options))
|
|
2559 (widget-children-value-delete widget)))
|
|
2560
|
|
2561 (defvar face-history nil
|
|
2562 "History of entered face names.")
|
|
2563
|
|
2564 (defun widget-face-action (widget &optional event)
|
|
2565 "Prompt for a face."
|
|
2566 (let ((answer (completing-read "Face: "
|
|
2567 (mapcar (lambda (face)
|
|
2568 (list (symbol-name face)))
|
|
2569 (face-list))
|
|
2570 nil nil nil
|
|
2571 'face-history)))
|
|
2572 (unless (zerop (length answer))
|
|
2573 (widget-value-set widget (intern answer))
|
|
2574 (widget-apply widget :notify widget event)
|
|
2575 (widget-setup))))
|
|
2576
|
|
2577 ;;; The `hook' Widget.
|
|
2578
|
|
2579 (define-widget 'hook 'list
|
|
2580 "A emacs lisp hook"
|
|
2581 :value-to-internal (lambda (widget value)
|
|
2582 (if (symbolp value)
|
|
2583 (list value)
|
|
2584 value))
|
|
2585 :match (lambda (widget value)
|
|
2586 (or (symbolp value)
|
|
2587 (widget-group-match widget value)))
|
|
2588 :convert-widget 'custom-hook-convert-widget
|
|
2589 :tag "Hook")
|
|
2590
|
|
2591 (defun custom-hook-convert-widget (widget)
|
|
2592 ;; Handle `:custom-options'.
|
|
2593 (let* ((options (widget-get widget :options))
|
|
2594 (other `(editable-list :inline t
|
|
2595 :entry-format "%i %d%v"
|
|
2596 (function :format " %v")))
|
|
2597 (args (if options
|
|
2598 (list `(checklist :inline t
|
|
2599 ,@(mapcar (lambda (entry)
|
|
2600 `(function-item ,entry))
|
|
2601 options))
|
|
2602 other)
|
|
2603 (list other))))
|
|
2604 (widget-put widget :args args)
|
|
2605 widget))
|
|
2606
|
219
|
2607 ;;; The `plist' Widget.
|
|
2608
|
|
2609 (define-widget 'plist 'list
|
|
2610 "A property list."
|
|
2611 :match (lambda (widget value)
|
|
2612 (valid-plist-p value))
|
|
2613 :convert-widget 'custom-plist-convert-widget
|
|
2614 :tag "Property List")
|
|
2615
|
|
2616 ;; #### Should handle options better.
|
|
2617 (defun custom-plist-convert-widget (widget)
|
|
2618 (let* ((options (widget-get widget :options))
|
|
2619 (other `(editable-list :inline t
|
|
2620 (group :inline t
|
|
2621 (symbol :format "%t: %v "
|
|
2622 :size 10
|
|
2623 :tag "Property")
|
|
2624 (sexp :tag "Value"))))
|
|
2625 (args
|
|
2626 (if options
|
|
2627 `((checklist :inline t
|
|
2628 ,@(mapcar 'custom-plist-process-option options))
|
|
2629 ,other)
|
|
2630 (list other))))
|
|
2631 (widget-put widget :args args)
|
|
2632 widget))
|
|
2633
|
|
2634 (defun custom-plist-process-option (entry)
|
|
2635 `(group :inline t
|
|
2636 (const :tag "Property"
|
|
2637 :format "%t: %v "
|
|
2638 :size 10
|
|
2639 ,entry)
|
|
2640 (sexp :tag "Value")))
|
|
2641
|
209
|
2642 ;;; The `custom-group-link' Widget.
|
|
2643
|
|
2644 (define-widget 'custom-group-link 'link
|
|
2645 "Show parent in other window when activated."
|
|
2646 :help-echo 'custom-group-link-help-echo
|
|
2647 :action 'custom-group-link-action)
|
|
2648
|
|
2649 (defun custom-group-link-help-echo (widget)
|
|
2650 (concat "Create customization buffer for the `"
|
|
2651 (custom-unlispify-tag-name (widget-value widget))
|
|
2652 "' group"))
|
|
2653
|
|
2654 (defun custom-group-link-action (widget &rest ignore)
|
|
2655 (customize-group (widget-value widget)))
|
|
2656
|
|
2657 ;;; The `custom-group' Widget.
|
|
2658
|
|
2659 (defcustom custom-group-tag-faces nil
|
|
2660 ;; In XEmacs, this ought to play games with font size.
|
|
2661 "Face used for group tags.
|
|
2662 The first member is used for level 1 groups, the second for level 2,
|
|
2663 and so forth. The remaining group tags are shown with
|
|
2664 `custom-group-tag-face'."
|
|
2665 :type '(repeat face)
|
|
2666 :group 'custom-faces)
|
|
2667
|
|
2668 (defface custom-group-tag-face-1 '((((class color)
|
|
2669 (background dark))
|
|
2670 (:foreground "pink" :underline t))
|
|
2671 (((class color)
|
|
2672 (background light))
|
|
2673 (:foreground "red" :underline t))
|
|
2674 (t (:underline t)))
|
|
2675 "Face used for group tags.")
|
|
2676
|
|
2677 (defface custom-group-tag-face '((((class color)
|
|
2678 (background dark))
|
|
2679 (:foreground "light blue" :underline t))
|
|
2680 (((class color)
|
|
2681 (background light))
|
|
2682 (:foreground "blue" :underline t))
|
|
2683 (t (:underline t)))
|
|
2684 "Face used for low level group tags."
|
|
2685 :group 'custom-faces)
|
|
2686
|
|
2687 (define-widget 'custom-group 'custom
|
|
2688 "Customize group."
|
|
2689 :format "%v"
|
|
2690 :sample-face-get 'custom-group-sample-face-get
|
|
2691 :documentation-property 'group-documentation
|
|
2692 :help-echo "Set or reset all members of this group"
|
|
2693 :value-create 'custom-group-value-create
|
|
2694 :action 'custom-group-action
|
|
2695 :custom-category 'group
|
|
2696 :custom-set 'custom-group-set
|
|
2697 :custom-save 'custom-group-save
|
|
2698 :custom-reset-current 'custom-group-reset-current
|
|
2699 :custom-reset-saved 'custom-group-reset-saved
|
|
2700 :custom-reset-standard 'custom-group-reset-standard
|
|
2701 :custom-menu 'custom-group-menu-create)
|
|
2702
|
|
2703 (defun custom-group-sample-face-get (widget)
|
|
2704 ;; Use :sample-face.
|
|
2705 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
|
|
2706 'custom-group-tag-face))
|
|
2707
|
|
2708 (define-widget 'custom-group-visibility 'visibility
|
|
2709 "An indicator and manipulator for hidden group contents."
|
|
2710 :create 'custom-group-visibility-create)
|
|
2711
|
|
2712 (defun custom-group-visibility-create (widget)
|
|
2713 (let ((visible (widget-value widget)))
|
|
2714 (if visible
|
|
2715 (insert "--------")))
|
|
2716 (widget-default-create widget))
|
|
2717
|
|
2718 (defun custom-group-members (symbol groups-only)
|
|
2719 "Return SYMBOL's custom group members.
|
|
2720 If GROUPS-ONLY non-nil, return only those members that are groups."
|
|
2721 (if (not groups-only)
|
|
2722 (get symbol 'custom-group)
|
|
2723 (let (members)
|
|
2724 (dolist (entry (get symbol 'custom-group) (nreverse members))
|
|
2725 (when (eq (nth 1 entry) 'custom-group)
|
|
2726 (push entry members))))))
|
|
2727
|
|
2728 (defun custom-group-value-create (widget)
|
|
2729 "Insert a customize group for WIDGET in the current buffer."
|
|
2730 (let* ((state (widget-get widget :custom-state))
|
|
2731 (level (widget-get widget :custom-level))
|
|
2732 ;; (indent (widget-get widget :indent))
|
|
2733 (prefix (widget-get widget :custom-prefix))
|
|
2734 (buttons (widget-get widget :buttons))
|
|
2735 (tag (widget-get widget :tag))
|
|
2736 (symbol (widget-value widget))
|
|
2737 (members (custom-group-members symbol
|
|
2738 (and (eq custom-buffer-style 'tree)
|
|
2739 custom-browse-only-groups))))
|
|
2740 (cond ((and (eq custom-buffer-style 'tree)
|
|
2741 (eq state 'hidden)
|
|
2742 (or members (custom-unloaded-widget-p widget)))
|
|
2743 (custom-browse-insert-prefix prefix)
|
|
2744 (push (widget-create-child-and-convert
|
|
2745 widget 'custom-browse-visibility
|
|
2746 ;; :tag-glyph "plus"
|
|
2747 :tag "+")
|
|
2748 buttons)
|
|
2749 (insert "-- ")
|
|
2750 ;; (widget-glyph-insert nil "-- " "horizontal")
|
|
2751 (push (widget-create-child-and-convert
|
|
2752 widget 'custom-browse-group-tag)
|
|
2753 buttons)
|
|
2754 (insert " " tag "\n")
|
|
2755 (widget-put widget :buttons buttons))
|
|
2756 ((and (eq custom-buffer-style 'tree)
|
|
2757 (zerop (length members)))
|
|
2758 (custom-browse-insert-prefix prefix)
|
|
2759 (insert "[ ]-- ")
|
|
2760 ;; (widget-glyph-insert nil "[ ]" "empty")
|
|
2761 ;; (widget-glyph-insert nil "-- " "horizontal")
|
|
2762 (push (widget-create-child-and-convert
|
|
2763 widget 'custom-browse-group-tag)
|
|
2764 buttons)
|
|
2765 (insert " " tag "\n")
|
|
2766 (widget-put widget :buttons buttons))
|
|
2767 ((eq custom-buffer-style 'tree)
|
|
2768 (custom-browse-insert-prefix prefix)
|
|
2769 (custom-load-widget widget)
|
|
2770 (if (zerop (length members))
|
|
2771 (progn
|
|
2772 (custom-browse-insert-prefix prefix)
|
|
2773 (insert "[ ]-- ")
|
|
2774 ;; (widget-glyph-insert nil "[ ]" "empty")
|
|
2775 ;; (widget-glyph-insert nil "-- " "horizontal")
|
|
2776 (push (widget-create-child-and-convert
|
|
2777 widget 'custom-browse-group-tag)
|
|
2778 buttons)
|
|
2779 (insert " " tag "\n")
|
|
2780 (widget-put widget :buttons buttons))
|
|
2781 (push (widget-create-child-and-convert
|
|
2782 widget 'custom-browse-visibility
|
|
2783 ;; :tag-glyph "minus"
|
|
2784 :tag "-")
|
|
2785 buttons)
|
|
2786 (insert "-\\ ")
|
|
2787 ;; (widget-glyph-insert nil "-\\ " "top")
|
|
2788 (push (widget-create-child-and-convert
|
|
2789 widget 'custom-browse-group-tag)
|
|
2790 buttons)
|
|
2791 (insert " " tag "\n")
|
|
2792 (widget-put widget :buttons buttons)
|
|
2793 (message "Creating group...")
|
|
2794 (let* ((members (custom-sort-items members
|
|
2795 custom-browse-sort-alphabetically
|
|
2796 custom-browse-order-groups))
|
|
2797 (prefixes (widget-get widget :custom-prefixes))
|
|
2798 (custom-prefix-list (custom-prefix-add symbol prefixes))
|
|
2799 (extra-prefix (if (widget-get widget :custom-last)
|
|
2800 " "
|
|
2801 " | "))
|
|
2802 (prefix (concat prefix extra-prefix))
|
|
2803 children entry)
|
|
2804 (while members
|
|
2805 (setq entry (car members)
|
|
2806 members (cdr members))
|
|
2807 (push (widget-create-child-and-convert
|
|
2808 widget (nth 1 entry)
|
|
2809 :group widget
|
|
2810 :tag (custom-unlispify-tag-name (nth 0 entry))
|
|
2811 :custom-prefixes custom-prefix-list
|
|
2812 :custom-level (1+ level)
|
|
2813 :custom-last (null members)
|
|
2814 :value (nth 0 entry)
|
|
2815 :custom-prefix prefix)
|
|
2816 children))
|
|
2817 (widget-put widget :children (reverse children)))
|
|
2818 (message "Creating group...done")))
|
|
2819 ;; Nested style.
|
|
2820 ((eq state 'hidden)
|
|
2821 ;; Create level indicator.
|
|
2822 (unless (eq custom-buffer-style 'links)
|
|
2823 (insert-char ?\ (* custom-buffer-indent (1- level)))
|
|
2824 (insert "-- "))
|
|
2825 ;; Create link indicator.
|
|
2826 (when (eq custom-buffer-style 'links)
|
|
2827 (insert " ")
|
|
2828 (push (widget-create-child-and-convert
|
|
2829 widget 'custom-group-link
|
|
2830 :tag "Open"
|
|
2831 :tag-glyph '("open-up" "open-down")
|
|
2832 symbol)
|
|
2833 buttons)
|
|
2834 (insert " "))
|
|
2835 ;; Create tag.
|
|
2836 (let ((begin (point)))
|
|
2837 (insert tag)
|
|
2838 (widget-specify-sample widget begin (point)))
|
|
2839 (insert " group")
|
|
2840 ;; Create visibility indicator.
|
|
2841 (unless (eq custom-buffer-style 'links)
|
|
2842 (insert ": ")
|
|
2843 (push (widget-create-child-and-convert
|
|
2844 widget 'custom-group-visibility
|
|
2845 :help-echo "Show members of this group"
|
|
2846 :action 'custom-toggle-parent
|
|
2847 (not (eq state 'hidden)))
|
|
2848 buttons))
|
|
2849 (insert " \n")
|
|
2850 ;; Create magic button.
|
|
2851 (let ((magic (widget-create-child-and-convert
|
|
2852 widget 'custom-magic nil)))
|
|
2853 (widget-put widget :custom-magic magic)
|
|
2854 (push magic buttons))
|
|
2855 ;; Update buttons.
|
|
2856 (widget-put widget :buttons buttons)
|
|
2857 ;; Insert documentation.
|
|
2858 (if (and (eq custom-buffer-style 'links) (> level 1))
|
|
2859 (widget-put widget :documentation-indent 0))
|
|
2860 (widget-default-format-handler widget ?h))
|
|
2861 ;; Nested style.
|
|
2862 (t ;Visible.
|
|
2863 (custom-load-widget widget)
|
|
2864 ;; Update members
|
|
2865 (setq members (custom-group-members
|
|
2866 symbol (and (eq custom-buffer-style 'tree)
|
|
2867 custom-browse-only-groups)))
|
|
2868 ;; Add parent groups references above the group.
|
|
2869 (if t ;;; This should test that the buffer
|
|
2870 ;;; was made to display a group.
|
|
2871 (when (eq level 1)
|
|
2872 (if (custom-add-parent-links widget
|
|
2873 "Go to parent group:")
|
|
2874 (insert "\n"))))
|
|
2875 ;; Create level indicator.
|
|
2876 (insert-char ?\ (* custom-buffer-indent (1- level)))
|
|
2877 (insert "/- ")
|
|
2878 ;; Create tag.
|
|
2879 (let ((start (point)))
|
|
2880 (insert tag)
|
|
2881 (widget-specify-sample widget start (point)))
|
|
2882 (insert " group: ")
|
|
2883 ;; Create visibility indicator.
|
|
2884 (unless (eq custom-buffer-style 'links)
|
|
2885 (insert "--------")
|
|
2886 (push (widget-create-child-and-convert
|
|
2887 widget 'visibility
|
|
2888 :help-echo "Hide members of this group"
|
|
2889 :action 'custom-toggle-parent
|
|
2890 (not (eq state 'hidden)))
|
|
2891 buttons)
|
|
2892 (insert " "))
|
|
2893 ;; Create more dashes.
|
|
2894 ;; Use 76 instead of 75 to compensate for the temporary "<"
|
|
2895 ;; added by `widget-insert'.
|
|
2896 (insert-char ?- (- 76 (current-column)
|
|
2897 (* custom-buffer-indent level)))
|
|
2898 (insert "\\\n")
|
|
2899 ;; Create magic button.
|
|
2900 (let ((magic (widget-create-child-and-convert
|
|
2901 widget 'custom-magic
|
|
2902 :indent 0
|
|
2903 nil)))
|
|
2904 (widget-put widget :custom-magic magic)
|
|
2905 (push magic buttons))
|
|
2906 ;; Update buttons.
|
|
2907 (widget-put widget :buttons buttons)
|
|
2908 ;; Insert documentation.
|
|
2909 (widget-default-format-handler widget ?h)
|
|
2910 ;; Parent groups.
|
|
2911 (if nil ;;; This should test that the buffer
|
|
2912 ;;; was not made to display a group.
|
|
2913 (when (eq level 1)
|
|
2914 (insert-char ?\ custom-buffer-indent)
|
|
2915 (custom-add-parent-links widget)))
|
|
2916 (custom-add-see-also widget
|
|
2917 (make-string (* custom-buffer-indent level)
|
|
2918 ?\ ))
|
|
2919 ;; Members.
|
|
2920 (message "Creating group...")
|
|
2921 (let* ((members (custom-sort-items members
|
|
2922 custom-buffer-sort-alphabetically
|
|
2923 custom-buffer-order-groups))
|
|
2924 (prefixes (widget-get widget :custom-prefixes))
|
|
2925 (custom-prefix-list (custom-prefix-add symbol prefixes))
|
|
2926 (length (length members))
|
|
2927 (count 0)
|
|
2928 (children (mapcar
|
|
2929 (lambda (entry)
|
|
2930 (widget-insert "\n")
|
|
2931 (when (zerop (% count custom-skip-messages))
|
|
2932 (display-message
|
|
2933 'progress
|
|
2934 (format "\
|
|
2935 Creating group members... %2d%%"
|
|
2936 (/ (* 100.0 count) length))))
|
|
2937 (incf count)
|
|
2938 (prog1
|
|
2939 (widget-create-child-and-convert
|
|
2940 widget (nth 1 entry)
|
|
2941 :group widget
|
|
2942 :tag (custom-unlispify-tag-name
|
|
2943 (nth 0 entry))
|
|
2944 :custom-prefixes custom-prefix-list
|
|
2945 :custom-level (1+ level)
|
|
2946 :value (nth 0 entry))
|
|
2947 (unless (eq (preceding-char) ?\n)
|
|
2948 (widget-insert "\n"))))
|
|
2949 members)))
|
|
2950 (message "Creating group magic...")
|
|
2951 (mapc 'custom-magic-reset children)
|
|
2952 (message "Creating group state...")
|
|
2953 (widget-put widget :children children)
|
|
2954 (custom-group-state-update widget)
|
|
2955 (message "Creating group... done"))
|
|
2956 ;; End line
|
|
2957 (insert "\n")
|
|
2958 (insert-char ?\ (* custom-buffer-indent (1- level)))
|
|
2959 (insert "\\- " (widget-get widget :tag) " group end ")
|
|
2960 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
|
|
2961 (insert "/\n")))))
|
|
2962
|
|
2963 (defvar custom-group-menu
|
|
2964 '(("Set for Current Session" custom-group-set
|
|
2965 (lambda (widget)
|
|
2966 (eq (widget-get widget :custom-state) 'modified)))
|
|
2967 ("Save for Future Sessions" custom-group-save
|
|
2968 (lambda (widget)
|
|
2969 (memq (widget-get widget :custom-state) '(modified set))))
|
|
2970 ("Reset to Current" custom-group-reset-current
|
|
2971 (lambda (widget)
|
|
2972 (memq (widget-get widget :custom-state) '(modified))))
|
|
2973 ("Reset to Saved" custom-group-reset-saved
|
|
2974 (lambda (widget)
|
|
2975 (memq (widget-get widget :custom-state) '(modified set))))
|
|
2976 ("Reset to standard setting" custom-group-reset-standard
|
|
2977 (lambda (widget)
|
|
2978 (memq (widget-get widget :custom-state) '(modified set saved)))))
|
|
2979 "Alist of actions for the `custom-group' widget.
|
|
2980 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
2981 the menu entry, ACTION is the function to call on the widget when the
|
|
2982 menu is selected, and FILTER is a predicate which takes a `custom-group'
|
|
2983 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
2984 widget. If FILTER is nil, ACTION is always valid.")
|
|
2985
|
|
2986 (defun custom-group-action (widget &optional event)
|
|
2987 "Show the menu for `custom-group' WIDGET.
|
|
2988 Optional EVENT is the location for the menu."
|
|
2989 (if (eq (widget-get widget :custom-state) 'hidden)
|
|
2990 (custom-toggle-hide widget)
|
|
2991 (let* ((completion-ignore-case t)
|
|
2992 (answer (widget-choose (concat "Operation on "
|
|
2993 (custom-unlispify-tag-name
|
|
2994 (widget-get widget :value)))
|
|
2995 (custom-menu-filter custom-group-menu
|
|
2996 widget)
|
|
2997 event)))
|
|
2998 (if answer
|
|
2999 (funcall answer widget)))))
|
|
3000
|
|
3001 (defun custom-group-set (widget)
|
|
3002 "Set changes in all modified group members."
|
|
3003 (let ((children (widget-get widget :children)))
|
|
3004 (mapc (lambda (child)
|
|
3005 (when (eq (widget-get child :custom-state) 'modified)
|
|
3006 (widget-apply child :custom-set)))
|
|
3007 children)))
|
|
3008
|
|
3009 (defun custom-group-save (widget)
|
|
3010 "Save all modified group members."
|
|
3011 (let ((children (widget-get widget :children)))
|
|
3012 (mapc (lambda (child)
|
|
3013 (when (memq (widget-get child :custom-state) '(modified set))
|
|
3014 (widget-apply child :custom-save)))
|
|
3015 children)))
|
|
3016
|
|
3017 (defun custom-group-reset-current (widget)
|
|
3018 "Reset all modified group members."
|
|
3019 (let ((children (widget-get widget :children)))
|
|
3020 (mapc (lambda (child)
|
|
3021 (when (eq (widget-get child :custom-state) 'modified)
|
|
3022 (widget-apply child :custom-reset-current)))
|
|
3023 children)))
|
|
3024
|
|
3025 (defun custom-group-reset-saved (widget)
|
|
3026 "Reset all modified or set group members."
|
|
3027 (let ((children (widget-get widget :children)))
|
|
3028 (mapc (lambda (child)
|
|
3029 (when (memq (widget-get child :custom-state) '(modified set))
|
|
3030 (widget-apply child :custom-reset-saved)))
|
|
3031 children)))
|
|
3032
|
|
3033 (defun custom-group-reset-standard (widget)
|
|
3034 "Reset all modified, set, or saved group members."
|
|
3035 (let ((children (widget-get widget :children)))
|
|
3036 (mapc (lambda (child)
|
|
3037 (when (memq (widget-get child :custom-state)
|
|
3038 '(modified set saved))
|
|
3039 (widget-apply child :custom-reset-standard)))
|
|
3040 children)))
|
|
3041
|
|
3042 (defun custom-group-state-update (widget)
|
|
3043 "Update magic."
|
|
3044 (unless (eq (widget-get widget :custom-state) 'hidden)
|
|
3045 (let* ((children (widget-get widget :children))
|
|
3046 (states (mapcar (lambda (child)
|
|
3047 (widget-get child :custom-state))
|
|
3048 children))
|
|
3049 (magics custom-magic-alist)
|
|
3050 (found 'standard))
|
|
3051 (while magics
|
|
3052 (let ((magic (car (car magics))))
|
|
3053 (if (and (not (eq magic 'hidden))
|
|
3054 (memq magic states))
|
|
3055 (setq found magic
|
|
3056 magics nil)
|
|
3057 (setq magics (cdr magics)))))
|
|
3058 (widget-put widget :custom-state found)))
|
|
3059 (custom-magic-reset widget))
|
|
3060
|
|
3061 ;;; The `custom-save-all' Function.
|
|
3062 ;;;###autoload
|
213
|
3063 (defcustom custom-file (if (boundp 'user-init-directory)
|
209
|
3064 (concat "~"
|
|
3065 init-file-user
|
213
|
3066 user-init-directory
|
209
|
3067 "options.el")
|
|
3068 "~/.emacs")
|
|
3069 "File used for storing customization information.
|
|
3070 If you change this from the default \"~/.emacs\" you need to
|
|
3071 explicitly load that file for the settings to take effect."
|
|
3072 :type 'file
|
|
3073 :group 'customize)
|
|
3074
|
|
3075 (defun custom-save-delete (symbol)
|
|
3076 "Delete the call to SYMBOL form `custom-file'.
|
|
3077 Leave point at the location of the call, or after the last expression."
|
|
3078 (let ((find-file-hooks nil)
|
|
3079 (auto-mode-alist nil))
|
|
3080 (set-buffer (find-file-noselect custom-file)))
|
|
3081 (goto-char (point-min))
|
|
3082 (catch 'found
|
|
3083 (while t
|
|
3084 (let ((sexp (condition-case nil
|
|
3085 (read (current-buffer))
|
|
3086 (end-of-file (throw 'found nil)))))
|
|
3087 (when (and (listp sexp)
|
|
3088 (eq (car sexp) symbol))
|
|
3089 (delete-region (save-excursion
|
|
3090 (backward-sexp)
|
|
3091 (point))
|
|
3092 (point))
|
|
3093 (throw 'found nil))))))
|
|
3094
|
|
3095 (defun custom-save-variables ()
|
|
3096 "Save all customized variables in `custom-file'."
|
|
3097 (save-excursion
|
|
3098 (custom-save-delete 'custom-set-variables)
|
|
3099 (let ((standard-output (current-buffer)))
|
|
3100 (unless (bolp)
|
|
3101 (princ "\n"))
|
|
3102 (princ "(custom-set-variables")
|
|
3103 (mapatoms (lambda (symbol)
|
|
3104 (let ((value (get symbol 'saved-value))
|
|
3105 (requests (get symbol 'custom-requests))
|
|
3106 (now (not (or (get symbol 'standard-value)
|
|
3107 (and (not (boundp symbol))
|
|
3108 (not (get symbol 'force-value)))))))
|
|
3109 (when value
|
|
3110 (princ "\n '(")
|
|
3111 (princ symbol)
|
|
3112 (princ " ")
|
|
3113 (prin1 (car value))
|
|
3114 (cond (requests
|
|
3115 (if now
|
|
3116 (princ " t ")
|
|
3117 (princ " nil "))
|
|
3118 (prin1 requests)
|
|
3119 (princ ")"))
|
|
3120 (now
|
|
3121 (princ " t)"))
|
|
3122 (t
|
|
3123 (princ ")")))))))
|
|
3124 (princ ")")
|
|
3125 (unless (looking-at "\n")
|
|
3126 (princ "\n")))))
|
|
3127
|
|
3128 (defun custom-save-faces ()
|
|
3129 "Save all customized faces in `custom-file'."
|
|
3130 (save-excursion
|
|
3131 (custom-save-delete 'custom-set-faces)
|
|
3132 (let ((standard-output (current-buffer)))
|
|
3133 (unless (bolp)
|
|
3134 (princ "\n"))
|
|
3135 (princ "(custom-set-faces")
|
|
3136 (let ((value (get 'default 'saved-face)))
|
|
3137 ;; The default face must be first, since it affects the others.
|
|
3138 (when value
|
|
3139 (princ "\n '(default ")
|
|
3140 (prin1 value)
|
|
3141 (if (or (get 'default 'face-defface-spec)
|
|
3142 (and (not (find-face 'default))
|
|
3143 (not (get 'default 'force-face))))
|
|
3144 (princ ")")
|
|
3145 (princ " t)"))))
|
|
3146 (mapatoms (lambda (symbol)
|
|
3147 (let ((value (get symbol 'saved-face)))
|
|
3148 (when (and (not (eq symbol 'default))
|
|
3149 ;; Don't print default face here.
|
|
3150 value)
|
|
3151 (princ "\n '(")
|
|
3152 (princ symbol)
|
|
3153 (princ " ")
|
|
3154 (prin1 value)
|
|
3155 (if (or (get symbol 'face-defface-spec)
|
|
3156 (and (not (find-face symbol))
|
|
3157 (not (get symbol 'force-face))))
|
|
3158 (princ ")")
|
|
3159 (princ " t)"))))))
|
|
3160 (princ ")")
|
|
3161 (unless (looking-at "\n")
|
|
3162 (princ "\n")))))
|
|
3163
|
|
3164 ;;;###autoload
|
|
3165 (defun customize-save-customized ()
|
|
3166 "Save all user options which have been set in this session."
|
|
3167 (interactive)
|
|
3168 (mapatoms (lambda (symbol)
|
|
3169 (let ((face (get symbol 'customized-face))
|
|
3170 (value (get symbol 'customized-value)))
|
|
3171 (when face
|
|
3172 (put symbol 'saved-face face)
|
|
3173 (put symbol 'customized-face nil))
|
|
3174 (when value
|
|
3175 (put symbol 'saved-value value)
|
|
3176 (put symbol 'customized-value nil)))))
|
|
3177 ;; We really should update all custom buffers here.
|
|
3178 (custom-save-all))
|
|
3179
|
|
3180 ;;;###autoload
|
|
3181 (defun custom-save-all ()
|
|
3182 "Save all customizations in `custom-file'."
|
|
3183 (let ((inhibit-read-only t))
|
|
3184 (custom-save-variables)
|
|
3185 (custom-save-faces)
|
|
3186 (let ((find-file-hooks nil)
|
|
3187 (auto-mode-alist))
|
|
3188 (with-current-buffer (find-file-noselect custom-file)
|
|
3189 (save-buffer)))))
|
|
3190
|
|
3191
|
|
3192 ;;; The Customize Menu.
|
|
3193
|
|
3194 ;;; Menu support
|
|
3195
|
|
3196 (defun custom-face-menu-create (widget symbol)
|
|
3197 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
|
|
3198 (vector (custom-unlispify-menu-entry symbol)
|
|
3199 `(customize-face ',symbol)
|
|
3200 t))
|
|
3201
|
|
3202 (defun custom-variable-menu-create (widget symbol)
|
|
3203 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
|
|
3204 (let ((type (get symbol 'custom-type)))
|
|
3205 (unless (listp type)
|
|
3206 (setq type (list type)))
|
|
3207 (if (and type (widget-get type :custom-menu))
|
|
3208 (widget-apply type :custom-menu symbol)
|
|
3209 (vector (custom-unlispify-menu-entry symbol)
|
|
3210 `(customize-variable ',symbol)
|
|
3211 t))))
|
|
3212
|
|
3213 ;; Add checkboxes to boolean variable entries.
|
|
3214 (widget-put (get 'boolean 'widget-type)
|
|
3215 :custom-menu (lambda (widget symbol)
|
|
3216 `[,(custom-unlispify-menu-entry symbol)
|
|
3217 (customize-variable ',symbol)
|
|
3218 :style toggle
|
|
3219 :selected ,symbol]))
|
|
3220
|
|
3221 ;; XEmacs can create menus dynamically.
|
|
3222 (defun custom-group-menu-create (widget symbol)
|
|
3223 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
|
|
3224 `( ,(custom-unlispify-menu-entry symbol t)
|
|
3225 :filter (lambda (&rest junk)
|
|
3226 (let ((item (custom-menu-create ',symbol)))
|
|
3227 (if (listp item)
|
|
3228 (cdr item)
|
|
3229 (list item))))))
|
|
3230
|
|
3231 ;;;###autoload
|
|
3232 (defun custom-menu-create (symbol)
|
|
3233 "Create menu for customization group SYMBOL.
|
|
3234 The menu is in a format applicable to `easy-menu-define'."
|
|
3235 (let* ((item (vector (custom-unlispify-menu-entry symbol)
|
|
3236 `(customize-group ',symbol)
|
|
3237 t)))
|
|
3238 ;; Item is the entry for creating a menu buffer for SYMBOL.
|
|
3239 ;; We may nest, if the menu is not too big.
|
|
3240 (custom-load-symbol symbol)
|
|
3241 (if (< (length (get symbol 'custom-group)) widget-menu-max-size)
|
|
3242 ;; The menu is not too big.
|
|
3243 (let ((custom-prefix-list (custom-prefix-add symbol
|
|
3244 custom-prefix-list))
|
|
3245 (members (custom-sort-items (get symbol 'custom-group)
|
|
3246 custom-menu-sort-alphabetically
|
|
3247 custom-menu-order-groups)))
|
|
3248 ;; Create the menu.
|
|
3249 `(,(custom-unlispify-menu-entry symbol t)
|
|
3250 ,item
|
|
3251 "--"
|
|
3252 ,@(mapcar (lambda (entry)
|
|
3253 (widget-apply (if (listp (nth 1 entry))
|
|
3254 (nth 1 entry)
|
|
3255 (list (nth 1 entry)))
|
|
3256 :custom-menu (nth 0 entry)))
|
|
3257 members)))
|
|
3258 ;; The menu was too big.
|
|
3259 item)))
|
|
3260
|
|
3261 ;;;###autoload
|
|
3262 (defun customize-menu-create (symbol &optional name)
|
|
3263 "Return a customize menu for customization group SYMBOL.
|
|
3264 If optional NAME is given, use that as the name of the menu.
|
|
3265 Otherwise the menu will be named `Customize'.
|
|
3266 The format is suitable for use with `easy-menu-define'."
|
|
3267 (unless name
|
|
3268 (setq name "Customize"))
|
|
3269 `(,name
|
|
3270 :filter (lambda (&rest junk)
|
|
3271 (cdr (custom-menu-create ',symbol)))))
|
|
3272
|
|
3273 ;;; The Custom Mode.
|
|
3274
|
|
3275 (defvar custom-mode-map nil
|
|
3276 "Keymap for `custom-mode'.")
|
|
3277
|
|
3278 (unless custom-mode-map
|
|
3279 (setq custom-mode-map (make-sparse-keymap))
|
|
3280 (set-keymap-parents custom-mode-map widget-keymap)
|
|
3281 (suppress-keymap custom-mode-map)
|
|
3282 (define-key custom-mode-map " " 'scroll-up)
|
219
|
3283 (define-key custom-mode-map [delete] 'scroll-down)
|
|
3284 (define-key custom-mode-map "q" 'Custom-buffer-done)
|
209
|
3285 (define-key custom-mode-map "u" 'Custom-goto-parent)
|
|
3286 (define-key custom-mode-map "n" 'widget-forward)
|
219
|
3287 (define-key custom-mode-map "p" 'widget-backward))
|
209
|
3288
|
|
3289 (easy-menu-define Custom-mode-menu
|
|
3290 custom-mode-map
|
|
3291 "Menu used in customization buffers."
|
|
3292 `("Custom"
|
|
3293 ,(customize-menu-create 'customize)
|
|
3294 ["Set" Custom-set t]
|
|
3295 ["Save" Custom-save t]
|
|
3296 ["Reset to Current" Custom-reset-current t]
|
|
3297 ["Reset to Saved" Custom-reset-saved t]
|
|
3298 ["Reset to Standard Settings" Custom-reset-standard t]
|
|
3299 ["Info" (Info-goto-node "(xemacs)Easy Customization") t]))
|
|
3300
|
|
3301 (defun Custom-goto-parent ()
|
|
3302 "Go to the parent group listed at the top of this buffer.
|
|
3303 If several parents are listed, go to the first of them."
|
|
3304 (interactive)
|
|
3305 (save-excursion
|
|
3306 (goto-char (point-min))
|
|
3307 (if (search-forward "\nGo to parent group: " nil t)
|
|
3308 (let* ((button (get-char-property (point) 'button))
|
|
3309 (parent (downcase (widget-get button :tag))))
|
|
3310 (customize-group parent)))))
|
|
3311
|
|
3312 (defcustom custom-mode-hook nil
|
|
3313 "Hook called when entering custom-mode."
|
|
3314 :type 'hook
|
|
3315 :group 'custom-buffer )
|
|
3316
|
|
3317 (defun custom-state-buffer-message (widget)
|
|
3318 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
|
|
3319 (message
|
|
3320 "To install your edits, invoke [State] and choose the Set operation")))
|
|
3321
|
|
3322 (defun custom-mode ()
|
|
3323 "Major mode for editing customization buffers.
|
|
3324
|
|
3325 The following commands are available:
|
|
3326
|
|
3327 Move to next button or editable field. \\[widget-forward]
|
|
3328 Move to previous button or editable field. \\[widget-backward]
|
|
3329 \\<widget-field-keymap>\
|
|
3330 Complete content of editable text field. \\[widget-complete]
|
|
3331 \\<custom-mode-map>\
|
|
3332 Invoke button under point. \\[widget-button-press]
|
|
3333 Set all modifications. \\[Custom-set]
|
|
3334 Make all modifications default. \\[Custom-save]
|
|
3335 Reset all modified options. \\[Custom-reset-current]
|
|
3336 Reset all modified or set options. \\[Custom-reset-saved]
|
|
3337 Reset all options. \\[Custom-reset-standard]
|
|
3338
|
|
3339 Entry to this mode calls the value of `custom-mode-hook'
|
|
3340 if that value is non-nil."
|
|
3341 (kill-all-local-variables)
|
|
3342 (setq major-mode 'custom-mode
|
|
3343 mode-name "Custom")
|
|
3344 (use-local-map custom-mode-map)
|
|
3345 (easy-menu-add Custom-mode-menu)
|
|
3346 (make-local-variable 'custom-options)
|
|
3347 (make-local-variable 'widget-documentation-face)
|
|
3348 (setq widget-documentation-face 'custom-documentation-face)
|
|
3349 (make-local-variable 'widget-button-face)
|
|
3350 (setq widget-button-face 'custom-button-face)
|
|
3351 (make-local-hook 'widget-edit-functions)
|
|
3352 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
|
|
3353 (run-hooks 'custom-mode-hook))
|
|
3354
|
|
3355
|
|
3356 ;;; The End.
|
|
3357
|
|
3358 (provide 'cus-edit)
|
|
3359
|
|
3360 ;; cus-edit.el ends here
|