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