28
|
1 ;;; cus-edit.el --- Tools for customization Emacs.
|
|
2 ;;
|
|
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
|
4 ;;
|
|
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
|
|
6 ;; Keywords: help, faces
|
134
|
7 ;; Version: 1.89
|
28
|
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
|
|
9
|
|
10 ;;; Commentary:
|
|
11 ;;
|
134
|
12 ;; This file implements the code to create and edit customize buffers.
|
|
13 ;;
|
28
|
14 ;; See `custom.el'.
|
|
15
|
|
16 ;;; Code:
|
|
17
|
|
18 (require 'cus-face)
|
|
19 (require 'wid-edit)
|
|
20 (require 'easymenu)
|
|
21
|
134
|
22 (condition-case nil
|
|
23 (require 'cus-load)
|
|
24 (error nil))
|
|
25
|
28
|
26 (define-widget-keywords :custom-prefixes :custom-menu :custom-show
|
|
27 :custom-magic :custom-state :custom-level :custom-form
|
|
28 :custom-set :custom-save :custom-reset-current :custom-reset-saved
|
|
29 :custom-reset-factory)
|
|
30
|
120
|
31 (put 'custom-define-hook 'custom-type 'hook)
|
|
32 (put 'custom-define-hook 'factory-value '(nil))
|
|
33 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
|
|
34
|
28
|
35 ;;; Customization Groups.
|
|
36
|
|
37 (defgroup emacs nil
|
|
38 "Customization of the One True Editor."
|
|
39 :link '(custom-manual "(emacs)Top"))
|
|
40
|
|
41 ;; Most of these groups are stolen from `finder.el',
|
|
42 (defgroup editing nil
|
|
43 "Basic text editing facilities."
|
|
44 :group 'emacs)
|
|
45
|
|
46 (defgroup abbrev nil
|
|
47 "Abbreviation handling, typing shortcuts, macros."
|
|
48 :tag "Abbreviations"
|
|
49 :group 'editing)
|
|
50
|
|
51 (defgroup matching nil
|
|
52 "Various sorts of searching and matching."
|
|
53 :group 'editing)
|
|
54
|
|
55 (defgroup emulations nil
|
|
56 "Emulations of other editors."
|
|
57 :group 'editing)
|
|
58
|
|
59 (defgroup mouse nil
|
|
60 "Mouse support."
|
|
61 :group 'editing)
|
|
62
|
|
63 (defgroup outlines nil
|
|
64 "Support for hierarchical outlining."
|
|
65 :group 'editing)
|
|
66
|
|
67 (defgroup external nil
|
|
68 "Interfacing to external utilities."
|
|
69 :group 'emacs)
|
|
70
|
|
71 (defgroup bib nil
|
|
72 "Code related to the `bib' bibliography processor."
|
|
73 :tag "Bibliography"
|
|
74 :group 'external)
|
|
75
|
|
76 (defgroup processes nil
|
|
77 "Process, subshell, compilation, and job control support."
|
|
78 :group 'external
|
|
79 :group 'development)
|
|
80
|
|
81 (defgroup programming nil
|
|
82 "Support for programming in other languages."
|
|
83 :group 'emacs)
|
|
84
|
|
85 (defgroup languages nil
|
|
86 "Specialized modes for editing programming languages."
|
|
87 :group 'programming)
|
|
88
|
|
89 (defgroup lisp nil
|
|
90 "Lisp support, including Emacs Lisp."
|
|
91 :group 'languages
|
|
92 :group 'development)
|
|
93
|
|
94 (defgroup c nil
|
|
95 "Support for the C language and related languages."
|
|
96 :group 'languages)
|
|
97
|
|
98 (defgroup tools nil
|
|
99 "Programming tools."
|
|
100 :group 'programming)
|
|
101
|
|
102 (defgroup oop nil
|
|
103 "Support for object-oriented programming."
|
|
104 :group 'programming)
|
|
105
|
|
106 (defgroup applications nil
|
|
107 "Applications written in Emacs."
|
|
108 :group 'emacs)
|
|
109
|
|
110 (defgroup calendar nil
|
|
111 "Calendar and time management support."
|
|
112 :group 'applications)
|
|
113
|
|
114 (defgroup mail nil
|
|
115 "Modes for electronic-mail handling."
|
|
116 :group 'applications)
|
|
117
|
|
118 (defgroup news nil
|
|
119 "Support for netnews reading and posting."
|
|
120 :group 'applications)
|
|
121
|
|
122 (defgroup games nil
|
|
123 "Games, jokes and amusements."
|
|
124 :group 'applications)
|
|
125
|
|
126 (defgroup development nil
|
|
127 "Support for further development of Emacs."
|
|
128 :group 'emacs)
|
|
129
|
|
130 (defgroup docs nil
|
|
131 "Support for Emacs documentation."
|
|
132 :group 'development)
|
|
133
|
|
134 (defgroup extensions nil
|
|
135 "Emacs Lisp language extensions."
|
|
136 :group 'development)
|
|
137
|
|
138 (defgroup internal nil
|
|
139 "Code for Emacs internals, build process, defaults."
|
|
140 :group 'development)
|
|
141
|
|
142 (defgroup maint nil
|
|
143 "Maintenance aids for the Emacs development group."
|
|
144 :tag "Maintenance"
|
|
145 :group 'development)
|
|
146
|
|
147 (defgroup environment nil
|
|
148 "Fitting Emacs with its environment."
|
|
149 :group 'emacs)
|
|
150
|
|
151 (defgroup comm nil
|
|
152 "Communications, networking, remote access to files."
|
|
153 :tag "Communication"
|
|
154 :group 'environment)
|
|
155
|
|
156 (defgroup hardware nil
|
|
157 "Support for interfacing with exotic hardware."
|
|
158 :group 'environment)
|
|
159
|
|
160 (defgroup terminals nil
|
|
161 "Support for terminal types."
|
|
162 :group 'environment)
|
|
163
|
|
164 (defgroup unix nil
|
|
165 "Front-ends/assistants for, or emulators of, UNIX features."
|
|
166 :group 'environment)
|
|
167
|
|
168 (defgroup vms nil
|
|
169 "Support code for vms."
|
|
170 :group 'environment)
|
|
171
|
|
172 (defgroup i18n nil
|
|
173 "Internationalization and alternate character-set support."
|
|
174 :group 'environment
|
|
175 :group 'editing)
|
|
176
|
|
177 (defgroup frames nil
|
|
178 "Support for Emacs frames and window systems."
|
|
179 :group 'environment)
|
|
180
|
|
181 (defgroup data nil
|
|
182 "Support editing files of data."
|
|
183 :group 'emacs)
|
|
184
|
|
185 (defgroup wp nil
|
|
186 "Word processing."
|
|
187 :group 'emacs)
|
|
188
|
|
189 (defgroup tex nil
|
|
190 "Code related to the TeX formatter."
|
|
191 :group 'wp)
|
|
192
|
|
193 (defgroup faces nil
|
|
194 "Support for multiple fonts."
|
|
195 :group 'emacs)
|
|
196
|
|
197 (defgroup hypermedia nil
|
|
198 "Support for links between text or other media types."
|
|
199 :group 'emacs)
|
|
200
|
|
201 (defgroup help nil
|
|
202 "Support for on-line help systems."
|
|
203 :group 'emacs)
|
|
204
|
|
205 (defgroup local nil
|
|
206 "Code local to your site."
|
|
207 :group 'emacs)
|
|
208
|
|
209 (defgroup customize '((widgets custom-group))
|
|
210 "Customization of the Customization support."
|
|
211 :link '(custom-manual "(custom)Top")
|
|
212 :link '(url-link :tag "Development Page"
|
|
213 "http://www.dina.kvl.dk/~abraham/custom/")
|
|
214 :prefix "custom-"
|
124
|
215 :group 'help)
|
|
216
|
|
217 (defgroup custom-faces nil
|
|
218 "Faces used by customize."
|
|
219 :group 'customize
|
28
|
220 :group 'faces)
|
|
221
|
124
|
222 (defgroup abbrev-mode nil
|
|
223 "Word abbreviations mode."
|
|
224 :group 'abbrev)
|
|
225
|
|
226 (defgroup alloc nil
|
|
227 "Storage allocation and gc for GNU Emacs Lisp interpreter."
|
|
228 :tag "Storage Allocation"
|
|
229 :group 'internal)
|
|
230
|
|
231 (defgroup undo nil
|
|
232 "Undoing changes in buffers."
|
|
233 :group 'editing)
|
|
234
|
|
235 (defgroup modeline nil
|
|
236 "Content of the modeline."
|
|
237 :group 'environment)
|
|
238
|
|
239 (defgroup fill nil
|
|
240 "Indenting and filling text."
|
|
241 :group 'editing)
|
|
242
|
|
243 (defgroup editing-basics nil
|
|
244 "Most basic editing facilities."
|
|
245 :group 'editing)
|
|
246
|
|
247 (defgroup display nil
|
|
248 "How characters are displayed in buffers."
|
|
249 :group 'environment)
|
|
250
|
|
251 (defgroup execute nil
|
|
252 "Executing external commands."
|
|
253 :group 'processes)
|
|
254
|
|
255 (defgroup installation nil
|
|
256 "The Emacs installation."
|
|
257 :group 'environment)
|
|
258
|
|
259 (defgroup dired nil
|
|
260 "Directory editing."
|
|
261 :group 'environment)
|
|
262
|
|
263 (defgroup limits nil
|
|
264 "Internal Emacs limits."
|
|
265 :group 'internal)
|
|
266
|
|
267 (defgroup debug nil
|
|
268 "Debugging Emacs itself."
|
|
269 :group 'development)
|
|
270
|
|
271 (defgroup minibuffer nil
|
|
272 "Controling the behaviour of the minibuffer."
|
|
273 :group 'environment)
|
|
274
|
|
275 (defgroup keyboard nil
|
|
276 "Input from the keyboard."
|
|
277 :group 'environment)
|
|
278
|
|
279 (defgroup mouse nil
|
|
280 "Input from the mouse."
|
|
281 :group 'environment)
|
|
282
|
|
283 (defgroup menu nil
|
|
284 "Input from the menus."
|
|
285 :group 'environment)
|
|
286
|
|
287 (defgroup auto-save nil
|
|
288 "Preventing accidential loss of data."
|
|
289 :group 'data)
|
|
290
|
|
291 (defgroup processes-basics nil
|
|
292 "Basic stuff dealing with processes."
|
|
293 :group 'processes)
|
|
294
|
|
295 (defgroup windows nil
|
|
296 "Windows within a frame."
|
|
297 :group 'processes)
|
|
298
|
28
|
299 ;;; Utilities.
|
|
300
|
|
301 (defun custom-quote (sexp)
|
|
302 "Quote SEXP iff it is not self quoting."
|
|
303 (if (or (memq sexp '(t nil))
|
|
304 (and (symbolp sexp)
|
|
305 (eq (aref (symbol-name sexp) 0) ?:))
|
|
306 (and (listp sexp)
|
|
307 (memq (car sexp) '(lambda)))
|
|
308 (stringp sexp)
|
|
309 (numberp sexp)
|
|
310 (and (fboundp 'characterp)
|
|
311 (characterp sexp)))
|
|
312 sexp
|
|
313 (list 'quote sexp)))
|
|
314
|
|
315 (defun custom-split-regexp-maybe (regexp)
|
|
316 "If REGEXP is a string, split it to a list at `\\|'.
|
|
317 You can get the original back with from the result with:
|
|
318 (mapconcat 'identity result \"\\|\")
|
|
319
|
|
320 IF REGEXP is not a string, return it unchanged."
|
|
321 (if (stringp regexp)
|
|
322 (let ((start 0)
|
|
323 all)
|
|
324 (while (string-match "\\\\|" regexp start)
|
|
325 (setq all (cons (substring regexp start (match-beginning 0)) all)
|
|
326 start (match-end 0)))
|
|
327 (nreverse (cons (substring regexp start) all)))
|
|
328 regexp))
|
|
329
|
124
|
330 (defun custom-variable-prompt ()
|
|
331 ;; Code stolen from `help.el'.
|
|
332 "Prompt for a variable, defaulting to the variable at point.
|
|
333 Return a list suitable for use in `interactive'."
|
|
334 (let ((v (variable-at-point))
|
|
335 (enable-recursive-minibuffers t)
|
|
336 val)
|
|
337 (setq val (completing-read
|
|
338 (if v
|
|
339 (format "Customize variable (default %s): " v)
|
|
340 "Customize variable: ")
|
|
341 obarray 'boundp t))
|
|
342 (list (if (equal val "")
|
|
343 v (intern val)))))
|
|
344
|
134
|
345 (defun custom-menu-filter (menu widget)
|
|
346 "Convert MENU to the form used by `widget-choose'.
|
|
347 MENU should be in the same format as `custom-variable-menu'.
|
|
348 WIDGET is the widget to apply the filter entries of MENU on."
|
|
349 (let ((result nil)
|
|
350 current name action filter)
|
|
351 (while menu
|
|
352 (setq current (car menu)
|
|
353 name (nth 0 current)
|
|
354 action (nth 1 current)
|
|
355 filter (nth 2 current)
|
|
356 menu (cdr menu))
|
|
357 (if (or (null filter) (funcall filter widget))
|
|
358 (push (cons name action) result)
|
|
359 (push name result)))
|
|
360 (nreverse result)))
|
|
361
|
124
|
362 ;;; Unlispify.
|
|
363
|
28
|
364 (defvar custom-prefix-list nil
|
|
365 "List of prefixes that should be ignored by `custom-unlispify'")
|
|
366
|
|
367 (defcustom custom-unlispify-menu-entries t
|
|
368 "Display menu entries as words instead of symbols if non nil."
|
|
369 :group 'customize
|
|
370 :type 'boolean)
|
|
371
|
|
372 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
|
|
373 "Convert symbol into a menu entry."
|
|
374 (cond ((not custom-unlispify-menu-entries)
|
|
375 (symbol-name symbol))
|
|
376 ((get symbol 'custom-tag)
|
|
377 (if no-suffix
|
|
378 (get symbol 'custom-tag)
|
|
379 (concat (get symbol 'custom-tag) "...")))
|
|
380 (t
|
|
381 (save-excursion
|
|
382 (set-buffer (get-buffer-create " *Custom-Work*"))
|
|
383 (erase-buffer)
|
|
384 (princ symbol (current-buffer))
|
|
385 (goto-char (point-min))
|
120
|
386 (when (and (eq (get symbol 'custom-type) 'boolean)
|
|
387 (re-search-forward "-p\\'" nil t))
|
|
388 (replace-match "" t t)
|
|
389 (goto-char (point-min)))
|
28
|
390 (let ((prefixes custom-prefix-list)
|
|
391 prefix)
|
|
392 (while prefixes
|
|
393 (setq prefix (car prefixes))
|
|
394 (if (search-forward prefix (+ (point) (length prefix)) t)
|
|
395 (progn
|
|
396 (setq prefixes nil)
|
|
397 (delete-region (point-min) (point)))
|
|
398 (setq prefixes (cdr prefixes)))))
|
|
399 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
|
|
400 (capitalize-region (point-min) (point-max))
|
|
401 (unless no-suffix
|
|
402 (goto-char (point-max))
|
|
403 (insert "..."))
|
|
404 (buffer-string)))))
|
|
405
|
|
406 (defcustom custom-unlispify-tag-names t
|
|
407 "Display tag names as words instead of symbols if non nil."
|
|
408 :group 'customize
|
|
409 :type 'boolean)
|
|
410
|
|
411 (defun custom-unlispify-tag-name (symbol)
|
|
412 "Convert symbol into a menu entry."
|
|
413 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
|
|
414 (custom-unlispify-menu-entry symbol t)))
|
|
415
|
|
416 (defun custom-prefix-add (symbol prefixes)
|
|
417 ;; Addd SYMBOL to list of ignored PREFIXES.
|
|
418 (cons (or (get symbol 'custom-prefix)
|
|
419 (concat (symbol-name symbol) "-"))
|
|
420 prefixes))
|
|
421
|
124
|
422 ;;; Guess.
|
|
423
|
|
424 (defcustom custom-guess-name-alist
|
120
|
425 '(("-p\\'" boolean)
|
|
426 ("-hook\\'" hook)
|
|
427 ("-face\\'" face)
|
|
428 ("-file\\'" file)
|
|
429 ("-function\\'" function)
|
|
430 ("-functions\\'" (repeat function))
|
|
431 ("-list\\'" (repeat sexp))
|
|
432 ("-alist\\'" (repeat (cons sexp sexp))))
|
|
433 "Alist of (MATCH TYPE).
|
|
434
|
|
435 MATCH should be a regexp matching the name of a symbol, and TYPE should
|
|
436 be a widget suitable for editing the value of that symbol. The TYPE
|
|
437 of the first entry where MATCH matches the name of the symbol will be
|
|
438 used.
|
|
439
|
|
440 This is used for guessing the type of variables not declared with
|
|
441 customize."
|
124
|
442 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
|
|
443 :group 'customize)
|
|
444
|
|
445 (defcustom custom-guess-doc-alist
|
|
446 '(("\\`\\*?Non-nil " boolean))
|
|
447 "Alist of (MATCH TYPE).
|
|
448
|
|
449 MATCH should be a regexp matching a documentation string, and TYPE
|
|
450 should be a widget suitable for editing the value of a variable with
|
|
451 that documentation string. The TYPE of the first entry where MATCH
|
|
452 matches the name of the symbol will be used.
|
|
453
|
|
454 This is used for guessing the type of variables not declared with
|
|
455 customize."
|
|
456 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
|
120
|
457 :group 'customize)
|
|
458
|
|
459 (defun custom-guess-type (symbol)
|
|
460 "Guess a widget suitable for editing the value of SYMBOL.
|
124
|
461 This is done by matching SYMBOL with `custom-guess-name-alist' and
|
|
462 if that fails, the doc string with `custom-guess-doc-alist'."
|
120
|
463 (let ((name (symbol-name symbol))
|
124
|
464 (names custom-guess-name-alist)
|
120
|
465 current found)
|
124
|
466 (while names
|
|
467 (setq current (car names)
|
|
468 names (cdr names))
|
120
|
469 (when (string-match (nth 0 current) name)
|
|
470 (setq found (nth 1 current)
|
124
|
471 names nil)))
|
|
472 (unless found
|
|
473 (let ((doc (documentation-property symbol 'variable-documentation))
|
|
474 (docs custom-guess-doc-alist))
|
|
475 (when doc
|
|
476 (while docs
|
|
477 (setq current (car docs)
|
|
478 docs (cdr docs))
|
|
479 (when (string-match (nth 0 current) doc)
|
|
480 (setq found (nth 1 current)
|
|
481 docs nil))))))
|
120
|
482 found))
|
|
483
|
124
|
484 ;;; Custom Mode Commands.
|
28
|
485
|
|
486 (defvar custom-options nil
|
|
487 "Customization widgets in the current buffer.")
|
|
488
|
|
489 (defun custom-set ()
|
|
490 "Set changes in all modified options."
|
|
491 (interactive)
|
|
492 (let ((children custom-options))
|
|
493 (mapcar (lambda (child)
|
|
494 (when (eq (widget-get child :custom-state) 'modified)
|
|
495 (widget-apply child :custom-set)))
|
|
496 children)))
|
|
497
|
|
498 (defun custom-save ()
|
|
499 "Set all modified group members and save them."
|
|
500 (interactive)
|
|
501 (let ((children custom-options))
|
|
502 (mapcar (lambda (child)
|
|
503 (when (memq (widget-get child :custom-state) '(modified set))
|
|
504 (widget-apply child :custom-save)))
|
|
505 children))
|
|
506 (custom-save-all))
|
|
507
|
|
508 (defvar custom-reset-menu
|
|
509 '(("Current" . custom-reset-current)
|
|
510 ("Saved" . custom-reset-saved)
|
|
511 ("Factory Settings" . custom-reset-factory))
|
|
512 "Alist of actions for the `Reset' button.
|
|
513 The key is a string containing the name of the action, the value is a
|
|
514 lisp function taking the widget as an element which will be called
|
|
515 when the action is chosen.")
|
|
516
|
|
517 (defun custom-reset (event)
|
|
518 "Select item from reset menu."
|
|
519 (let* ((completion-ignore-case t)
|
|
520 (answer (widget-choose "Reset to"
|
|
521 custom-reset-menu
|
|
522 event)))
|
|
523 (if answer
|
|
524 (funcall answer))))
|
|
525
|
|
526 (defun custom-reset-current ()
|
|
527 "Reset all modified group members to their current value."
|
|
528 (interactive)
|
|
529 (let ((children custom-options))
|
|
530 (mapcar (lambda (child)
|
|
531 (when (eq (widget-get child :custom-state) 'modified)
|
|
532 (widget-apply child :custom-reset-current)))
|
|
533 children)))
|
|
534
|
|
535 (defun custom-reset-saved ()
|
|
536 "Reset all modified or set group members to their saved value."
|
|
537 (interactive)
|
|
538 (let ((children custom-options))
|
|
539 (mapcar (lambda (child)
|
|
540 (when (eq (widget-get child :custom-state) 'modified)
|
|
541 (widget-apply child :custom-reset-current)))
|
|
542 children)))
|
|
543
|
|
544 (defun custom-reset-factory ()
|
|
545 "Reset all modified, set, or saved group members to their factory settings."
|
|
546 (interactive)
|
|
547 (let ((children custom-options))
|
|
548 (mapcar (lambda (child)
|
|
549 (when (eq (widget-get child :custom-state) 'modified)
|
|
550 (widget-apply child :custom-reset-current)))
|
|
551 children)))
|
|
552
|
|
553 ;;; The Customize Commands
|
|
554
|
|
555 ;;;###autoload
|
|
556 (defun customize (symbol)
|
|
557 "Customize SYMBOL, which must be a customization group."
|
|
558 (interactive (list (completing-read "Customize group: (default emacs) "
|
|
559 obarray
|
|
560 (lambda (symbol)
|
|
561 (get symbol 'custom-group))
|
|
562 t)))
|
|
563
|
|
564 (when (stringp symbol)
|
|
565 (if (string-equal "" symbol)
|
|
566 (setq symbol 'emacs)
|
|
567 (setq symbol (intern symbol))))
|
|
568 (custom-buffer-create (list (list symbol 'custom-group))))
|
|
569
|
|
570 ;;;###autoload
|
134
|
571 (defun customize-other-window (symbol)
|
|
572 "Customize SYMBOL, which must be a customization group."
|
|
573 (interactive (list (completing-read "Customize group: (default emacs) "
|
|
574 obarray
|
|
575 (lambda (symbol)
|
|
576 (get symbol 'custom-group))
|
|
577 t)))
|
|
578
|
|
579 (when (stringp symbol)
|
|
580 (if (string-equal "" symbol)
|
|
581 (setq symbol 'emacs)
|
|
582 (setq symbol (intern symbol))))
|
|
583 (custom-buffer-create-other-window (list (list symbol 'custom-group))))
|
|
584
|
|
585 ;;;###autoload
|
28
|
586 (defun customize-variable (symbol)
|
|
587 "Customize SYMBOL, which must be a variable."
|
124
|
588 (interactive (custom-variable-prompt))
|
28
|
589 (custom-buffer-create (list (list symbol 'custom-variable))))
|
|
590
|
|
591 ;;;###autoload
|
124
|
592 (defun customize-variable-other-window (symbol)
|
|
593 "Customize SYMBOL, which must be a variable.
|
|
594 Show the buffer in another window, but don't select it."
|
|
595 (interactive (custom-variable-prompt))
|
|
596 (custom-buffer-create-other-window (list (list symbol 'custom-variable))))
|
|
597
|
|
598 ;;;###autoload
|
28
|
599 (defun customize-face (&optional symbol)
|
|
600 "Customize SYMBOL, which should be a face name or nil.
|
|
601 If SYMBOL is nil, customize all faces."
|
|
602 (interactive (list (completing-read "Customize face: (default all) "
|
|
603 obarray 'custom-facep)))
|
|
604 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
|
|
605 (let ((found nil))
|
|
606 (message "Looking for faces...")
|
|
607 (mapcar (lambda (symbol)
|
|
608 (setq found (cons (list symbol 'custom-face) found)))
|
124
|
609 (nreverse (mapcar 'intern
|
|
610 (sort (mapcar 'symbol-name (face-list))
|
|
611 'string<))))
|
|
612
|
28
|
613 (custom-buffer-create found))
|
|
614 (if (stringp symbol)
|
|
615 (setq symbol (intern symbol)))
|
|
616 (unless (symbolp symbol)
|
|
617 (error "Should be a symbol %S" symbol))
|
|
618 (custom-buffer-create (list (list symbol 'custom-face)))))
|
|
619
|
|
620 ;;;###autoload
|
124
|
621 (defun customize-face-other-window (&optional symbol)
|
|
622 "Show customization buffer for FACE in other window."
|
|
623 (interactive (list (completing-read "Customize face: "
|
|
624 obarray 'custom-facep)))
|
|
625 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
|
|
626 ()
|
|
627 (if (stringp symbol)
|
|
628 (setq symbol (intern symbol)))
|
|
629 (unless (symbolp symbol)
|
|
630 (error "Should be a symbol %S" symbol))
|
|
631 (custom-buffer-create-other-window (list (list symbol 'custom-face)))))
|
|
632
|
|
633 ;;;###autoload
|
28
|
634 (defun customize-customized ()
|
|
635 "Customize all already customized user options."
|
|
636 (interactive)
|
|
637 (let ((found nil))
|
|
638 (mapatoms (lambda (symbol)
|
|
639 (and (get symbol 'saved-face)
|
|
640 (custom-facep symbol)
|
|
641 (setq found (cons (list symbol 'custom-face) found)))
|
|
642 (and (get symbol 'saved-value)
|
|
643 (boundp symbol)
|
|
644 (setq found
|
|
645 (cons (list symbol 'custom-variable) found)))))
|
|
646 (if found
|
|
647 (custom-buffer-create found)
|
|
648 (error "No customized user options"))))
|
|
649
|
|
650 ;;;###autoload
|
|
651 (defun customize-apropos (regexp &optional all)
|
|
652 "Customize all user options matching REGEXP.
|
|
653 If ALL (e.g., started with a prefix key), include options which are not
|
|
654 user-settable."
|
|
655 (interactive "sCustomize regexp: \nP")
|
|
656 (let ((found nil))
|
|
657 (mapatoms (lambda (symbol)
|
|
658 (when (string-match regexp (symbol-name symbol))
|
|
659 (when (get symbol 'custom-group)
|
|
660 (setq found (cons (list symbol 'custom-group) found)))
|
|
661 (when (custom-facep symbol)
|
|
662 (setq found (cons (list symbol 'custom-face) found)))
|
|
663 (when (and (boundp symbol)
|
|
664 (or (get symbol 'saved-value)
|
|
665 (get symbol 'factory-value)
|
|
666 (if all
|
|
667 (get symbol 'variable-documentation)
|
|
668 (user-variable-p symbol))))
|
|
669 (setq found
|
|
670 (cons (list symbol 'custom-variable) found))))))
|
|
671 (if found
|
|
672 (custom-buffer-create found)
|
|
673 (error "No matches"))))
|
|
674
|
|
675 ;;;###autoload
|
|
676 (defun custom-buffer-create (options)
|
|
677 "Create a buffer containing OPTIONS.
|
|
678 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
|
|
679 SYMBOL is a customization option, and WIDGET is a widget for editing
|
|
680 that option."
|
|
681 (kill-buffer (get-buffer-create "*Customization*"))
|
|
682 (switch-to-buffer (get-buffer-create "*Customization*"))
|
124
|
683 (custom-buffer-create-internal options))
|
|
684
|
|
685 (defun custom-buffer-create-other-window (options)
|
|
686 "Create a buffer containing OPTIONS.
|
|
687 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
|
|
688 SYMBOL is a customization option, and WIDGET is a widget for editing
|
|
689 that option."
|
|
690 (kill-buffer (get-buffer-create "*Customization*"))
|
|
691 (let ((window (selected-window)))
|
|
692 (switch-to-buffer-other-window (get-buffer-create "*Customization*"))
|
|
693 (custom-buffer-create-internal options)
|
|
694 (select-window window)))
|
|
695
|
|
696
|
|
697 (defun custom-buffer-create-internal (options)
|
|
698 (message "Creating customization buffer...")
|
28
|
699 (custom-mode)
|
|
700 (widget-insert "This is a customization buffer.
|
|
701 Push RET or click mouse-2 on the word ")
|
116
|
702 ;; (put-text-property 1 2 'start-open nil)
|
28
|
703 (widget-create 'info-link
|
|
704 :tag "help"
|
30
|
705 :help-echo "Read the online help."
|
28
|
706 "(custom)The Customization Buffer")
|
|
707 (widget-insert " for more information.\n\n")
|
|
708 (setq custom-options
|
120
|
709 (if (= (length options) 1)
|
|
710 (mapcar (lambda (entry)
|
|
711 (widget-create (nth 1 entry)
|
|
712 :custom-state 'unknown
|
|
713 :tag (custom-unlispify-tag-name
|
|
714 (nth 0 entry))
|
|
715 :value (nth 0 entry)))
|
|
716 options)
|
|
717 (let ((count 0)
|
|
718 (length (length options)))
|
|
719 (mapcar (lambda (entry)
|
|
720 (prog2
|
|
721 (message "Creating customization items %2d%%..."
|
|
722 (/ (* 100.0 count) length))
|
|
723 (widget-create (nth 1 entry)
|
28
|
724 :tag (custom-unlispify-tag-name
|
|
725 (nth 0 entry))
|
|
726 :value (nth 0 entry))
|
120
|
727 (setq count (1+ count))
|
|
728 (unless (eq (preceding-char) ?\n)
|
|
729 (widget-insert "\n"))
|
|
730 (widget-insert "\n")))
|
|
731 options))))
|
|
732 (unless (eq (preceding-char) ?\n)
|
|
733 (widget-insert "\n"))
|
|
734 (widget-insert "\n")
|
|
735 (message "Creating customization magic...")
|
28
|
736 (mapcar 'custom-magic-reset custom-options)
|
120
|
737 (message "Creating customization buttons...")
|
28
|
738 (widget-create 'push-button
|
|
739 :tag "Set"
|
30
|
740 :help-echo "Set all modifications for this session."
|
28
|
741 :action (lambda (widget &optional event)
|
|
742 (custom-set)))
|
|
743 (widget-insert " ")
|
|
744 (widget-create 'push-button
|
|
745 :tag "Save"
|
30
|
746 :help-echo "\
|
|
747 Make the modifications default for future sessions."
|
28
|
748 :action (lambda (widget &optional event)
|
|
749 (custom-save)))
|
|
750 (widget-insert " ")
|
|
751 (widget-create 'push-button
|
|
752 :tag "Reset"
|
30
|
753 :help-echo "Undo all modifications."
|
28
|
754 :action (lambda (widget &optional event)
|
|
755 (custom-reset event)))
|
|
756 (widget-insert " ")
|
|
757 (widget-create 'push-button
|
|
758 :tag "Done"
|
30
|
759 :help-echo "Bury the buffer."
|
28
|
760 :action (lambda (widget &optional event)
|
|
761 (bury-buffer)
|
|
762 ;; Steal button release event.
|
|
763 (if (and (fboundp 'button-press-event-p)
|
|
764 (fboundp 'next-command-event))
|
|
765 ;; XEmacs
|
|
766 (and event
|
|
767 (button-press-event-p event)
|
|
768 (next-command-event))
|
|
769 ;; Emacs
|
|
770 (when (memq 'down (event-modifiers event))
|
|
771 (read-event)))))
|
|
772 (widget-insert "\n")
|
120
|
773 (message "Creating customization setup...")
|
30
|
774 (widget-setup)
|
120
|
775 (goto-char (point-min))
|
124
|
776 (forward-char) ;Kludge: bob is writable in XEmacs.
|
120
|
777 (message "Creating customization buffer...done"))
|
28
|
778
|
|
779 ;;; Modification of Basic Widgets.
|
|
780 ;;
|
|
781 ;; We add extra properties to the basic widgets needed here. This is
|
|
782 ;; fine, as long as we are careful to stay within out own namespace.
|
|
783 ;;
|
|
784 ;; We want simple widgets to be displayed by default, but complex
|
|
785 ;; widgets to be hidden.
|
|
786
|
|
787 (widget-put (get 'item 'widget-type) :custom-show t)
|
|
788 (widget-put (get 'editable-field 'widget-type)
|
|
789 :custom-show (lambda (widget value)
|
|
790 (let ((pp (pp-to-string value)))
|
|
791 (cond ((string-match "\n" pp)
|
|
792 nil)
|
|
793 ((> (length pp) 40)
|
|
794 nil)
|
|
795 (t t)))))
|
|
796 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
|
|
797
|
|
798 ;;; The `custom-manual' Widget.
|
|
799
|
|
800 (define-widget 'custom-manual 'info-link
|
|
801 "Link to the manual entry for this customization option."
|
30
|
802 :help-echo "Read the manual entry for this option."
|
28
|
803 :tag "Manual")
|
|
804
|
|
805 ;;; The `custom-magic' Widget.
|
|
806
|
|
807 (defface custom-invalid-face '((((class color))
|
|
808 (:foreground "yellow" :background "red"))
|
|
809 (t
|
|
810 (:bold t :italic t :underline t)))
|
|
811 "Face used when the customize item is invalid.")
|
|
812
|
|
813 (defface custom-rogue-face '((((class color))
|
|
814 (:foreground "pink" :background "black"))
|
|
815 (t
|
|
816 (:underline t)))
|
|
817 "Face used when the customize item is not defined for customization.")
|
|
818
|
|
819 (defface custom-modified-face '((((class color))
|
|
820 (:foreground "white" :background "blue"))
|
|
821 (t
|
|
822 (:italic t :bold)))
|
|
823 "Face used when the customize item has been modified.")
|
|
824
|
|
825 (defface custom-set-face '((((class color))
|
|
826 (:foreground "blue" :background "white"))
|
|
827 (t
|
|
828 (:italic t)))
|
|
829 "Face used when the customize item has been set.")
|
|
830
|
|
831 (defface custom-changed-face '((((class color))
|
|
832 (:foreground "white" :background "blue"))
|
|
833 (t
|
|
834 (:italic t)))
|
|
835 "Face used when the customize item has been changed.")
|
|
836
|
|
837 (defface custom-saved-face '((t (:underline t)))
|
|
838 "Face used when the customize item has been saved.")
|
|
839
|
|
840 (defcustom custom-magic-alist '((nil "#" underline "\
|
|
841 uninitialized, you should not see this.")
|
|
842 (unknown "?" italic "\
|
|
843 unknown, you should not see this.")
|
|
844 (hidden "-" default "\
|
|
845 hidden, press the state button to show.")
|
|
846 (invalid "x" custom-invalid-face "\
|
|
847 the value displayed for this item is invalid and cannot be set.")
|
|
848 (modified "*" custom-modified-face "\
|
|
849 you have edited the item, and can now set it.")
|
|
850 (set "+" custom-set-face "\
|
|
851 you have set this item, but not saved it.")
|
|
852 (changed ":" custom-changed-face "\
|
|
853 this item has been changed outside customize.")
|
|
854 (saved "!" custom-saved-face "\
|
|
855 this item has been saved.")
|
|
856 (rogue "@" custom-rogue-face "\
|
|
857 this item is not prepared for customization.")
|
|
858 (factory " " nil "\
|
|
859 this item is unchanged from its factory setting."))
|
|
860 "Alist of customize option states.
|
|
861 Each entry is of the form (STATE MAGIC FACE DESCRIPTION), where
|
|
862
|
|
863 STATE is one of the following symbols:
|
|
864
|
|
865 `nil'
|
|
866 For internal use, should never occur.
|
|
867 `unknown'
|
|
868 For internal use, should never occur.
|
|
869 `hidden'
|
|
870 This item is not being displayed.
|
|
871 `invalid'
|
|
872 This item is modified, but has an invalid form.
|
|
873 `modified'
|
|
874 This item is modified, and has a valid form.
|
|
875 `set'
|
|
876 This item has been set but not saved.
|
|
877 `changed'
|
|
878 The current value of this item has been changed temporarily.
|
|
879 `saved'
|
|
880 This item is marked for saving.
|
|
881 `rogue'
|
|
882 This item has no customization information.
|
|
883 `factory'
|
|
884 This item is unchanged from the factory default.
|
|
885
|
|
886 MAGIC is a string used to present that state.
|
|
887
|
|
888 FACE is a face used to present the state.
|
|
889
|
|
890 DESCRIPTION is a string describing the state.
|
|
891
|
|
892 The list should be sorted most significant first."
|
|
893 :type '(list (checklist :inline t
|
|
894 (group (const nil)
|
|
895 (string :tag "Magic")
|
|
896 face
|
|
897 (string :tag "Description"))
|
|
898 (group (const unknown)
|
|
899 (string :tag "Magic")
|
|
900 face
|
|
901 (string :tag "Description"))
|
|
902 (group (const hidden)
|
|
903 (string :tag "Magic")
|
|
904 face
|
|
905 (string :tag "Description"))
|
|
906 (group (const invalid)
|
|
907 (string :tag "Magic")
|
|
908 face
|
|
909 (string :tag "Description"))
|
|
910 (group (const modified)
|
|
911 (string :tag "Magic")
|
|
912 face
|
|
913 (string :tag "Description"))
|
|
914 (group (const set)
|
|
915 (string :tag "Magic")
|
|
916 face
|
|
917 (string :tag "Description"))
|
|
918 (group (const changed)
|
|
919 (string :tag "Magic")
|
|
920 face
|
|
921 (string :tag "Description"))
|
|
922 (group (const saved)
|
|
923 (string :tag "Magic")
|
|
924 face
|
|
925 (string :tag "Description"))
|
|
926 (group (const rogue)
|
|
927 (string :tag "Magic")
|
|
928 face
|
|
929 (string :tag "Description"))
|
|
930 (group (const factory)
|
|
931 (string :tag "Magic")
|
|
932 face
|
|
933 (string :tag "Description")))
|
|
934 (editable-list :inline t
|
|
935 (group symbol
|
|
936 (string :tag "Magic")
|
|
937 face
|
|
938 (string :tag "Description"))))
|
124
|
939 :group 'customize
|
|
940 :group 'custom-faces)
|
28
|
941
|
|
942 (defcustom custom-magic-show 'long
|
|
943 "Show long description of the state of each customization option."
|
|
944 :type '(choice (const :tag "no" nil)
|
|
945 (const short)
|
|
946 (const long))
|
|
947 :group 'customize)
|
|
948
|
|
949 (defcustom custom-magic-show-button t
|
|
950 "Show a magic button indicating the state of each customization option."
|
|
951 :type 'boolean
|
|
952 :group 'customize)
|
|
953
|
|
954 (define-widget 'custom-magic 'default
|
|
955 "Show and manipulate state for a customization option."
|
|
956 :format "%v"
|
|
957 :action 'widget-choice-item-action
|
134
|
958 :notify 'ignore
|
28
|
959 :value-get 'ignore
|
|
960 :value-create 'custom-magic-value-create
|
|
961 :value-delete 'widget-children-value-delete)
|
|
962
|
|
963 (defun custom-magic-value-create (widget)
|
|
964 ;; Create compact status report for WIDGET.
|
|
965 (let* ((parent (widget-get widget :parent))
|
|
966 (state (widget-get parent :custom-state))
|
|
967 (entry (assq state custom-magic-alist))
|
|
968 (magic (nth 1 entry))
|
|
969 (face (nth 2 entry))
|
|
970 (text (nth 3 entry))
|
|
971 (lisp (eq (widget-get parent :custom-form) 'lisp))
|
|
972 children)
|
|
973 (when custom-magic-show
|
|
974 (push (widget-create-child-and-convert widget 'choice-item
|
|
975 :help-echo "\
|
30
|
976 Change the state of this item."
|
28
|
977 :format "%[%t%]"
|
|
978 :tag "State")
|
|
979 children)
|
|
980 (insert ": ")
|
|
981 (if (eq custom-magic-show 'long)
|
|
982 (insert text)
|
|
983 (insert (symbol-name state)))
|
|
984 (when lisp
|
|
985 (insert " (lisp)"))
|
|
986 (insert "\n"))
|
|
987 (when custom-magic-show-button
|
|
988 (when custom-magic-show
|
|
989 (let ((indent (widget-get parent :indent)))
|
|
990 (when indent
|
|
991 (insert-char ? indent))))
|
|
992 (push (widget-create-child-and-convert widget 'choice-item
|
|
993 :button-face face
|
30
|
994 :help-echo "Change the state."
|
28
|
995 :format "%[%t%]"
|
|
996 :tag (if lisp
|
|
997 (concat "(" magic ")")
|
|
998 (concat "[" magic "]")))
|
|
999 children)
|
|
1000 (insert " "))
|
|
1001 (widget-put widget :children children)))
|
|
1002
|
|
1003 (defun custom-magic-reset (widget)
|
|
1004 "Redraw the :custom-magic property of WIDGET."
|
|
1005 (let ((magic (widget-get widget :custom-magic)))
|
|
1006 (widget-value-set magic (widget-value magic))))
|
|
1007
|
|
1008 ;;; The `custom-level' Widget.
|
|
1009
|
|
1010 (define-widget 'custom-level 'item
|
|
1011 "The custom level buttons."
|
|
1012 :format "%[%t%]"
|
30
|
1013 :help-echo "Expand or collapse this item."
|
28
|
1014 :action 'custom-level-action)
|
|
1015
|
|
1016 (defun custom-level-action (widget &optional event)
|
|
1017 "Toggle visibility for parent to WIDGET."
|
134
|
1018 (custom-toggle-hide (widget-get widget :parent)))
|
28
|
1019
|
|
1020 ;;; The `custom' Widget.
|
|
1021
|
|
1022 (define-widget 'custom 'default
|
|
1023 "Customize a user option."
|
|
1024 :convert-widget 'custom-convert-widget
|
|
1025 :format "%l%[%t%]: %v%m%h%a"
|
|
1026 :format-handler 'custom-format-handler
|
|
1027 :notify 'custom-notify
|
|
1028 :custom-level 1
|
|
1029 :custom-state 'hidden
|
|
1030 :documentation-property 'widget-subclass-responsibility
|
|
1031 :value-create 'widget-subclass-responsibility
|
|
1032 :value-delete 'widget-children-value-delete
|
|
1033 :value-get 'widget-item-value-get
|
|
1034 :validate 'widget-editable-list-validate
|
|
1035 :match (lambda (widget value) (symbolp value)))
|
|
1036
|
|
1037 (defun custom-convert-widget (widget)
|
|
1038 ;; Initialize :value and :tag from :args in WIDGET.
|
|
1039 (let ((args (widget-get widget :args)))
|
|
1040 (when args
|
|
1041 (widget-put widget :value (widget-apply widget
|
|
1042 :value-to-internal (car args)))
|
|
1043 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
|
|
1044 (widget-put widget :args nil)))
|
|
1045 widget)
|
|
1046
|
|
1047 (defun custom-format-handler (widget escape)
|
|
1048 ;; We recognize extra escape sequences.
|
|
1049 (let* ((buttons (widget-get widget :buttons))
|
|
1050 (state (widget-get widget :custom-state))
|
|
1051 (level (widget-get widget :custom-level)))
|
|
1052 (cond ((eq escape ?l)
|
|
1053 (when level
|
|
1054 (push (widget-create-child-and-convert
|
|
1055 widget 'custom-level (make-string level ?*))
|
|
1056 buttons)
|
|
1057 (widget-insert " ")
|
|
1058 (widget-put widget :buttons buttons)))
|
|
1059 ((eq escape ?L)
|
|
1060 (when (eq state 'hidden)
|
|
1061 (widget-insert " ...")))
|
|
1062 ((eq escape ?m)
|
|
1063 (and (eq (preceding-char) ?\n)
|
|
1064 (widget-get widget :indent)
|
|
1065 (insert-char ? (widget-get widget :indent)))
|
|
1066 (let ((magic (widget-create-child-and-convert
|
|
1067 widget 'custom-magic nil)))
|
|
1068 (widget-put widget :custom-magic magic)
|
|
1069 (push magic buttons)
|
|
1070 (widget-put widget :buttons buttons)))
|
|
1071 ((eq escape ?a)
|
|
1072 (let* ((symbol (widget-get widget :value))
|
|
1073 (links (get symbol 'custom-links))
|
|
1074 (many (> (length links) 2)))
|
|
1075 (when links
|
|
1076 (and (eq (preceding-char) ?\n)
|
|
1077 (widget-get widget :indent)
|
|
1078 (insert-char ? (widget-get widget :indent)))
|
|
1079 (insert "See also ")
|
|
1080 (while links
|
|
1081 (push (widget-create-child-and-convert widget (car links))
|
|
1082 buttons)
|
|
1083 (setq links (cdr links))
|
|
1084 (cond ((null links)
|
|
1085 (insert ".\n"))
|
|
1086 ((null (cdr links))
|
|
1087 (if many
|
|
1088 (insert ", and ")
|
|
1089 (insert " and ")))
|
|
1090 (t
|
|
1091 (insert ", "))))
|
|
1092 (widget-put widget :buttons buttons))))
|
|
1093 (t
|
|
1094 (widget-default-format-handler widget escape)))))
|
|
1095
|
|
1096 (defun custom-notify (widget &rest args)
|
|
1097 "Keep track of changes."
|
30
|
1098 (unless (memq (widget-get widget :custom-state) '(nil unknown hidden))
|
|
1099 (widget-put widget :custom-state 'modified))
|
28
|
1100 (let ((buffer-undo-list t))
|
|
1101 (custom-magic-reset widget))
|
|
1102 (apply 'widget-default-notify widget args))
|
|
1103
|
|
1104 (defun custom-redraw (widget)
|
|
1105 "Redraw WIDGET with current settings."
|
134
|
1106 (let ((line (count-lines (point-min) (point)))
|
|
1107 (column (current-column))
|
|
1108 (pos (point))
|
28
|
1109 (from (marker-position (widget-get widget :from)))
|
|
1110 (to (marker-position (widget-get widget :to))))
|
|
1111 (save-excursion
|
|
1112 (widget-value-set widget (widget-value widget))
|
|
1113 (custom-redraw-magic widget))
|
|
1114 (when (and (>= pos from) (<= pos to))
|
134
|
1115 (condition-case nil
|
|
1116 (progn
|
|
1117 (goto-line line)
|
|
1118 (move-to-column column))
|
|
1119 (error nil)))))
|
28
|
1120
|
|
1121 (defun custom-redraw-magic (widget)
|
|
1122 "Redraw WIDGET state with current settings."
|
|
1123 (while widget
|
|
1124 (let ((magic (widget-get widget :custom-magic)))
|
|
1125 (unless magic
|
|
1126 (debug))
|
|
1127 (widget-value-set magic (widget-value magic))
|
|
1128 (when (setq widget (widget-get widget :group))
|
|
1129 (custom-group-state-update widget))))
|
|
1130 (widget-setup))
|
|
1131
|
|
1132 (defun custom-show (widget value)
|
|
1133 "Non-nil if WIDGET should be shown with VALUE by default."
|
|
1134 (let ((show (widget-get widget :custom-show)))
|
|
1135 (cond ((null show)
|
|
1136 nil)
|
|
1137 ((eq t show)
|
|
1138 t)
|
|
1139 (t
|
|
1140 (funcall show widget value)))))
|
|
1141
|
124
|
1142 (defvar custom-load-recursion nil
|
|
1143 "Hack to avoid recursive dependencies.")
|
|
1144
|
28
|
1145 (defun custom-load-symbol (symbol)
|
|
1146 "Load all dependencies for SYMBOL."
|
124
|
1147 (unless custom-load-recursion
|
|
1148 (let ((custom-load-recursion t)
|
|
1149 (loads (get symbol 'custom-loads))
|
|
1150 load)
|
|
1151 (while loads
|
|
1152 (setq load (car loads)
|
|
1153 loads (cdr loads))
|
|
1154 (cond ((symbolp load)
|
|
1155 (condition-case nil
|
|
1156 (require load)
|
|
1157 (error nil)))
|
|
1158 ((assoc load load-history))
|
|
1159 (t
|
|
1160 (condition-case nil
|
|
1161 (load-library load)
|
|
1162 (error nil))))))))
|
28
|
1163
|
|
1164 (defun custom-load-widget (widget)
|
|
1165 "Load all dependencies for WIDGET."
|
|
1166 (custom-load-symbol (widget-value widget)))
|
|
1167
|
134
|
1168 (defun custom-toggle-hide (widget)
|
|
1169 "Toggle visibility of WIDGET."
|
|
1170 (let ((state (widget-get widget :custom-state)))
|
|
1171 (cond ((memq state '(invalid modified))
|
|
1172 (error "There are unset changes"))
|
|
1173 ((eq state 'hidden)
|
|
1174 (widget-put widget :custom-state 'unknown))
|
|
1175 (t
|
|
1176 (widget-put widget :custom-state 'hidden)))
|
|
1177 (custom-redraw widget)))
|
|
1178
|
28
|
1179 ;;; The `custom-variable' Widget.
|
|
1180
|
|
1181 (defface custom-variable-sample-face '((t (:underline t)))
|
|
1182 "Face used for unpushable variable tags."
|
124
|
1183 :group 'custom-faces)
|
28
|
1184
|
|
1185 (defface custom-variable-button-face '((t (:underline t :bold t)))
|
|
1186 "Face used for pushable variable tags."
|
124
|
1187 :group 'custom-faces)
|
28
|
1188
|
|
1189 (define-widget 'custom-variable 'custom
|
|
1190 "Customize variable."
|
|
1191 :format "%l%v%m%h%a"
|
30
|
1192 :help-echo "Set or reset this variable."
|
28
|
1193 :documentation-property 'variable-documentation
|
|
1194 :custom-state nil
|
|
1195 :custom-menu 'custom-variable-menu-create
|
|
1196 :custom-form 'edit
|
|
1197 :value-create 'custom-variable-value-create
|
|
1198 :action 'custom-variable-action
|
|
1199 :custom-set 'custom-variable-set
|
|
1200 :custom-save 'custom-variable-save
|
|
1201 :custom-reset-current 'custom-redraw
|
|
1202 :custom-reset-saved 'custom-variable-reset-saved
|
|
1203 :custom-reset-factory 'custom-variable-reset-factory)
|
|
1204
|
120
|
1205 (defun custom-variable-type (symbol)
|
|
1206 "Return a widget suitable for editing the value of SYMBOL.
|
|
1207 If SYMBOL has a `custom-type' property, use that.
|
|
1208 Otherwise, look up symbol in `custom-guess-type-alist'."
|
|
1209 (let* ((type (or (get symbol 'custom-type)
|
124
|
1210 (and (not (get symbol 'factory-value))
|
|
1211 (custom-guess-type symbol))
|
120
|
1212 'sexp))
|
|
1213 (options (get symbol 'custom-options))
|
|
1214 (tmp (if (listp type)
|
|
1215 (copy-list type)
|
|
1216 (list type))))
|
|
1217 (when options
|
|
1218 (widget-put tmp :options options))
|
|
1219 tmp))
|
|
1220
|
28
|
1221 (defun custom-variable-value-create (widget)
|
|
1222 "Here is where you edit the variables value."
|
|
1223 (custom-load-widget widget)
|
|
1224 (let* ((buttons (widget-get widget :buttons))
|
|
1225 (children (widget-get widget :children))
|
|
1226 (form (widget-get widget :custom-form))
|
|
1227 (state (widget-get widget :custom-state))
|
|
1228 (symbol (widget-get widget :value))
|
|
1229 (tag (widget-get widget :tag))
|
120
|
1230 (type (custom-variable-type symbol))
|
28
|
1231 (conv (widget-convert type))
|
134
|
1232 (get (or (get symbol 'custom-get) 'default-value))
|
|
1233 (set (or (get symbol 'custom-set) 'set-default))
|
28
|
1234 (value (if (default-boundp symbol)
|
134
|
1235 (funcall get symbol)
|
28
|
1236 (widget-get conv :value))))
|
|
1237 ;; If the widget is new, the child determine whether it is hidden.
|
|
1238 (cond (state)
|
|
1239 ((custom-show type value)
|
|
1240 (setq state 'unknown))
|
|
1241 (t
|
|
1242 (setq state 'hidden)))
|
|
1243 ;; If we don't know the state, see if we need to edit it in lisp form.
|
|
1244 (when (eq state 'unknown)
|
|
1245 (unless (widget-apply conv :match value)
|
|
1246 ;; (widget-apply (widget-convert type) :match value)
|
|
1247 (setq form 'lisp)))
|
|
1248 ;; Now we can create the child widget.
|
|
1249 (cond ((eq state 'hidden)
|
|
1250 ;; Indicate hidden value.
|
|
1251 (push (widget-create-child-and-convert
|
|
1252 widget 'item
|
|
1253 :format "%{%t%}: ..."
|
|
1254 :sample-face 'custom-variable-sample-face
|
|
1255 :tag tag
|
|
1256 :parent widget)
|
|
1257 children))
|
|
1258 ((eq form 'lisp)
|
|
1259 ;; In lisp mode edit the saved value when possible.
|
|
1260 (let* ((value (cond ((get symbol 'saved-value)
|
|
1261 (car (get symbol 'saved-value)))
|
|
1262 ((get symbol 'factory-value)
|
|
1263 (car (get symbol 'factory-value)))
|
|
1264 ((default-boundp symbol)
|
134
|
1265 (custom-quote (funcall get symbol)))
|
28
|
1266 (t
|
|
1267 (custom-quote (widget-get conv :value))))))
|
|
1268 (push (widget-create-child-and-convert
|
|
1269 widget 'sexp
|
|
1270 :button-face 'custom-variable-button-face
|
|
1271 :tag (symbol-name symbol)
|
|
1272 :parent widget
|
|
1273 :value value)
|
|
1274 children)))
|
|
1275 (t
|
|
1276 ;; Edit mode.
|
|
1277 (push (widget-create-child-and-convert
|
|
1278 widget type
|
|
1279 :tag tag
|
|
1280 :button-face 'custom-variable-button-face
|
|
1281 :sample-face 'custom-variable-sample-face
|
|
1282 :value value)
|
|
1283 children)))
|
|
1284 ;; Now update the state.
|
|
1285 (unless (eq (preceding-char) ?\n)
|
|
1286 (widget-insert "\n"))
|
|
1287 (if (eq state 'hidden)
|
|
1288 (widget-put widget :custom-state state)
|
|
1289 (custom-variable-state-set widget))
|
|
1290 (widget-put widget :custom-form form)
|
|
1291 (widget-put widget :buttons buttons)
|
|
1292 (widget-put widget :children children)))
|
|
1293
|
|
1294 (defun custom-variable-state-set (widget)
|
|
1295 "Set the state of WIDGET."
|
|
1296 (let* ((symbol (widget-value widget))
|
134
|
1297 (get (or (get symbol 'custom-get) 'default-value))
|
28
|
1298 (value (if (default-boundp symbol)
|
134
|
1299 (funcall get symbol)
|
28
|
1300 (widget-get widget :value)))
|
|
1301 tmp
|
|
1302 (state (cond ((setq tmp (get symbol 'customized-value))
|
|
1303 (if (condition-case nil
|
|
1304 (equal value (eval (car tmp)))
|
|
1305 (error nil))
|
|
1306 'set
|
|
1307 'changed))
|
|
1308 ((setq tmp (get symbol 'saved-value))
|
|
1309 (if (condition-case nil
|
|
1310 (equal value (eval (car tmp)))
|
|
1311 (error nil))
|
|
1312 'saved
|
|
1313 'changed))
|
|
1314 ((setq tmp (get symbol 'factory-value))
|
|
1315 (if (condition-case nil
|
|
1316 (equal value (eval (car tmp)))
|
|
1317 (error nil))
|
|
1318 'factory
|
|
1319 'changed))
|
|
1320 (t 'rogue))))
|
|
1321 (widget-put widget :custom-state state)))
|
|
1322
|
|
1323 (defvar custom-variable-menu
|
134
|
1324 '(("Hide" custom-toggle-hide
|
|
1325 (lambda (widget)
|
|
1326 (not (memq (widget-get widget :custom-state) '(modified invalid)))))
|
|
1327 ("Edit" custom-variable-edit
|
|
1328 (lambda (widget)
|
|
1329 (not (eq (widget-get widget :custom-form) 'edit))))
|
|
1330 ("Edit Lisp" custom-variable-edit-lisp
|
|
1331 (lambda (widget)
|
|
1332 (not (eq (widget-get widget :custom-form) 'lisp))))
|
|
1333 ("Set" custom-variable-set
|
|
1334 (lambda (widget)
|
|
1335 (eq (widget-get widget :custom-state) 'modified)))
|
|
1336 ("Save" custom-variable-save
|
|
1337 (lambda (widget)
|
|
1338 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
|
|
1339 ("Reset to Current" custom-redraw
|
|
1340 (lambda (widget)
|
|
1341 (and (default-boundp (widget-value widget))
|
|
1342 (memq (widget-get widget :custom-state) '(modified)))))
|
|
1343 ("Reset to Saved" custom-variable-reset-saved
|
|
1344 (lambda (widget)
|
|
1345 (and (get (widget-value widget) 'saved-value)
|
|
1346 (memq (widget-get widget :custom-state)
|
|
1347 '(modified set changed rogue)))))
|
|
1348 ("Reset to Factory Settings" custom-variable-reset-factory
|
|
1349 (lambda (widget)
|
|
1350 (and (get (widget-value widget) 'factory-value)
|
|
1351 (memq (widget-get widget :custom-state)
|
|
1352 '(modified set changed saved rogue))))))
|
28
|
1353 "Alist of actions for the `custom-variable' widget.
|
134
|
1354 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
1355 the menu entry, ACTION is the function to call on the widget when the
|
|
1356 menu is selected, and FILTER is a predicate which takes a `custom-variable'
|
|
1357 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
1358 widget. If FILTER is nil, ACTION is always valid.")
|
28
|
1359
|
|
1360 (defun custom-variable-action (widget &optional event)
|
|
1361 "Show the menu for `custom-variable' WIDGET.
|
|
1362 Optional EVENT is the location for the menu."
|
|
1363 (if (eq (widget-get widget :custom-state) 'hidden)
|
|
1364 (progn
|
|
1365 (widget-put widget :custom-state 'unknown)
|
|
1366 (custom-redraw widget))
|
|
1367 (let* ((completion-ignore-case t)
|
|
1368 (answer (widget-choose (custom-unlispify-tag-name
|
|
1369 (widget-get widget :value))
|
134
|
1370 (custom-menu-filter custom-variable-menu
|
|
1371 widget)
|
28
|
1372 event)))
|
|
1373 (if answer
|
|
1374 (funcall answer widget)))))
|
|
1375
|
|
1376 (defun custom-variable-edit (widget)
|
|
1377 "Edit value of WIDGET."
|
|
1378 (widget-put widget :custom-state 'unknown)
|
|
1379 (widget-put widget :custom-form 'edit)
|
|
1380 (custom-redraw widget))
|
|
1381
|
|
1382 (defun custom-variable-edit-lisp (widget)
|
|
1383 "Edit the lisp representation of the value of WIDGET."
|
|
1384 (widget-put widget :custom-state 'unknown)
|
|
1385 (widget-put widget :custom-form 'lisp)
|
|
1386 (custom-redraw widget))
|
|
1387
|
|
1388 (defun custom-variable-set (widget)
|
|
1389 "Set the current value for the variable being edited by WIDGET."
|
134
|
1390 (let* ((form (widget-get widget :custom-form))
|
|
1391 (state (widget-get widget :custom-state))
|
|
1392 (child (car (widget-get widget :children)))
|
|
1393 (symbol (widget-value widget))
|
|
1394 (set (or (get symbol 'custom-set) 'set-default))
|
|
1395 val)
|
28
|
1396 (cond ((eq state 'hidden)
|
|
1397 (error "Cannot set hidden variable."))
|
|
1398 ((setq val (widget-apply child :validate))
|
|
1399 (goto-char (widget-get val :from))
|
|
1400 (error "%s" (widget-get val :error)))
|
|
1401 ((eq form 'lisp)
|
134
|
1402 (funcall set symbol (eval (setq val (widget-value child))))
|
28
|
1403 (put symbol 'customized-value (list val)))
|
|
1404 (t
|
134
|
1405 (funcall set symbol (setq val (widget-value child)))
|
28
|
1406 (put symbol 'customized-value (list (custom-quote val)))))
|
|
1407 (custom-variable-state-set widget)
|
|
1408 (custom-redraw-magic widget)))
|
|
1409
|
|
1410 (defun custom-variable-save (widget)
|
|
1411 "Set the default value for the variable being edited by WIDGET."
|
134
|
1412 (let* ((form (widget-get widget :custom-form))
|
|
1413 (state (widget-get widget :custom-state))
|
|
1414 (child (car (widget-get widget :children)))
|
|
1415 (symbol (widget-value widget))
|
|
1416 (set (or (get symbol 'custom-set) 'set-default))
|
|
1417 val)
|
28
|
1418 (cond ((eq state 'hidden)
|
|
1419 (error "Cannot set hidden variable."))
|
|
1420 ((setq val (widget-apply child :validate))
|
|
1421 (goto-char (widget-get val :from))
|
|
1422 (error "%s" (widget-get val :error)))
|
|
1423 ((eq form 'lisp)
|
|
1424 (put symbol 'saved-value (list (widget-value child)))
|
134
|
1425 (funcall set symbol (eval (widget-value child))))
|
28
|
1426 (t
|
|
1427 (put symbol
|
|
1428 'saved-value (list (custom-quote (widget-value
|
|
1429 child))))
|
134
|
1430 (funcall set symbol (widget-value child))))
|
28
|
1431 (put symbol 'customized-value nil)
|
|
1432 (custom-save-all)
|
|
1433 (custom-variable-state-set widget)
|
|
1434 (custom-redraw-magic widget)))
|
|
1435
|
|
1436 (defun custom-variable-reset-saved (widget)
|
|
1437 "Restore the saved value for the variable being edited by WIDGET."
|
134
|
1438 (let* ((symbol (widget-value widget))
|
|
1439 (set (or (get symbol 'custom-set) 'set-default)))
|
28
|
1440 (if (get symbol 'saved-value)
|
|
1441 (condition-case nil
|
134
|
1442 (funcall set symbol (eval (car (get symbol 'saved-value))))
|
28
|
1443 (error nil))
|
|
1444 (error "No saved value for %s" symbol))
|
|
1445 (put symbol 'customized-value nil)
|
|
1446 (widget-put widget :custom-state 'unknown)
|
|
1447 (custom-redraw widget)))
|
|
1448
|
|
1449 (defun custom-variable-reset-factory (widget)
|
|
1450 "Restore the factory setting for the variable being edited by WIDGET."
|
134
|
1451 (let* ((symbol (widget-value widget))
|
|
1452 (set (or (get symbol 'custom-set) 'set-default)))
|
28
|
1453 (if (get symbol 'factory-value)
|
134
|
1454 (funcall set symbol (eval (car (get symbol 'factory-value))))
|
28
|
1455 (error "No factory default for %S" symbol))
|
|
1456 (put symbol 'customized-value nil)
|
|
1457 (when (get symbol 'saved-value)
|
|
1458 (put symbol 'saved-value nil)
|
|
1459 (custom-save-all))
|
|
1460 (widget-put widget :custom-state 'unknown)
|
|
1461 (custom-redraw widget)))
|
|
1462
|
|
1463 ;;; The `custom-face-edit' Widget.
|
|
1464
|
|
1465 (define-widget 'custom-face-edit 'checklist
|
|
1466 "Edit face attributes."
|
|
1467 :format "%t: %v"
|
|
1468 :tag "Attributes"
|
|
1469 :extra-offset 12
|
30
|
1470 :button-args '(:help-echo "Control whether this attribute have any effect.")
|
28
|
1471 :args (mapcar (lambda (att)
|
|
1472 (list 'group
|
|
1473 :inline t
|
30
|
1474 :sibling-args (widget-get (nth 1 att) :sibling-args)
|
28
|
1475 (list 'const :format "" :value (nth 0 att))
|
|
1476 (nth 1 att)))
|
|
1477 custom-face-attributes))
|
|
1478
|
|
1479 ;;; The `custom-display' Widget.
|
|
1480
|
|
1481 (define-widget 'custom-display 'menu-choice
|
|
1482 "Select a display type."
|
|
1483 :tag "Display"
|
|
1484 :value t
|
30
|
1485 :help-echo "Specify frames where the face attributes should be used."
|
28
|
1486 :args '((const :tag "all" t)
|
30
|
1487 (checklist
|
|
1488 :offset 0
|
|
1489 :extra-offset 9
|
|
1490 :args ((group :sibling-args (:help-echo "\
|
|
1491 Only match the specified window systems.")
|
|
1492 (const :format "Type: "
|
|
1493 type)
|
|
1494 (checklist :inline t
|
|
1495 :offset 0
|
|
1496 (const :format "X "
|
|
1497 :sibling-args (:help-echo "\
|
|
1498 The X11 Window System.")
|
|
1499 x)
|
|
1500 (const :format "PM "
|
|
1501 :sibling-args (:help-echo "\
|
|
1502 OS/2 Presentation Manager.")
|
|
1503 pm)
|
|
1504 (const :format "Win32 "
|
|
1505 :sibling-args (:help-echo "\
|
|
1506 Windows NT/95/97.")
|
|
1507 win32)
|
|
1508 (const :format "DOS "
|
|
1509 :sibling-args (:help-echo "\
|
|
1510 Plain MS-DOS.")
|
|
1511 pc)
|
|
1512 (const :format "TTY%n"
|
|
1513 :sibling-args (:help-echo "\
|
|
1514 Plain text terminals.")
|
|
1515 tty)))
|
|
1516 (group :sibling-args (:help-echo "\
|
|
1517 Only match the frames with the specified color support.")
|
|
1518 (const :format "Class: "
|
|
1519 class)
|
|
1520 (checklist :inline t
|
|
1521 :offset 0
|
|
1522 (const :format "Color "
|
|
1523 :sibling-args (:help-echo "\
|
|
1524 Match color frames.")
|
|
1525 color)
|
|
1526 (const :format "Grayscale "
|
|
1527 :sibling-args (:help-echo "\
|
|
1528 Match grayscale frames.")
|
|
1529 grayscale)
|
|
1530 (const :format "Monochrome%n"
|
|
1531 :sibling-args (:help-echo "\
|
|
1532 Match frames with no color support.")
|
|
1533 mono)))
|
|
1534 (group :sibling-args (:help-echo "\
|
|
1535 Only match frames with the specified intensity.")
|
|
1536 (const :format "\
|
|
1537 Background brightness: "
|
|
1538 background)
|
|
1539 (checklist :inline t
|
|
1540 :offset 0
|
|
1541 (const :format "Light "
|
|
1542 :sibling-args (:help-echo "\
|
|
1543 Match frames with light backgrounds.")
|
|
1544 light)
|
|
1545 (const :format "Dark\n"
|
|
1546 :sibling-args (:help-echo "\
|
|
1547 Match frames with dark backgrounds.")
|
|
1548 dark)))))))
|
28
|
1549
|
|
1550 ;;; The `custom-face' Widget.
|
|
1551
|
|
1552 (defface custom-face-tag-face '((t (:underline t)))
|
|
1553 "Face used for face tags."
|
124
|
1554 :group 'custom-faces)
|
28
|
1555
|
|
1556 (define-widget 'custom-face 'custom
|
|
1557 "Customize face."
|
|
1558 :format "%l%{%t%}: %s%m%h%a%v"
|
|
1559 :format-handler 'custom-face-format-handler
|
|
1560 :sample-face 'custom-face-tag-face
|
30
|
1561 :help-echo "Set or reset this face."
|
28
|
1562 :documentation-property '(lambda (face)
|
30
|
1563 (face-doc-string face))
|
28
|
1564 :value-create 'custom-face-value-create
|
|
1565 :action 'custom-face-action
|
120
|
1566 :custom-form 'selected
|
28
|
1567 :custom-set 'custom-face-set
|
|
1568 :custom-save 'custom-face-save
|
|
1569 :custom-reset-current 'custom-redraw
|
|
1570 :custom-reset-saved 'custom-face-reset-saved
|
|
1571 :custom-reset-factory 'custom-face-reset-factory
|
|
1572 :custom-menu 'custom-face-menu-create)
|
|
1573
|
|
1574 (defun custom-face-format-handler (widget escape)
|
|
1575 ;; We recognize extra escape sequences.
|
|
1576 (let (child
|
|
1577 (symbol (widget-get widget :value)))
|
|
1578 (cond ((eq escape ?s)
|
|
1579 (and (string-match "XEmacs" emacs-version)
|
|
1580 ;; XEmacs cannot display initialized faces.
|
|
1581 (not (custom-facep symbol))
|
|
1582 (copy-face 'custom-face-empty symbol))
|
|
1583 (setq child (widget-create-child-and-convert
|
|
1584 widget 'item
|
|
1585 :format "(%{%t%})\n"
|
|
1586 :sample-face symbol
|
|
1587 :tag "sample")))
|
|
1588 (t
|
|
1589 (custom-format-handler widget escape)))
|
|
1590 (when child
|
|
1591 (widget-put widget
|
|
1592 :buttons (cons child (widget-get widget :buttons))))))
|
|
1593
|
120
|
1594 (define-widget 'custom-face-all 'editable-list
|
|
1595 "An editable list of display specifications and attributes."
|
|
1596 :entry-format "%i %d %v"
|
|
1597 :insert-button-args '(:help-echo "Insert new display specification here.")
|
|
1598 :append-button-args '(:help-echo "Append new display specification here.")
|
|
1599 :delete-button-args '(:help-echo "Delete this display specification.")
|
|
1600 :args '((group :format "%v" custom-display custom-face-edit)))
|
|
1601
|
|
1602 (defconst custom-face-all (widget-convert 'custom-face-all)
|
|
1603 "Converted version of the `custom-face-all' widget.")
|
|
1604
|
|
1605 (define-widget 'custom-display-unselected 'item
|
|
1606 "A display specification that doesn't match the selected display."
|
|
1607 :match 'custom-display-unselected-match)
|
|
1608
|
|
1609 (defun custom-display-unselected-match (widget value)
|
|
1610 "Non-nil if VALUE is an unselected display specification."
|
134
|
1611 (not (custom-display-match-frame value (selected-frame))))
|
120
|
1612
|
|
1613 (define-widget 'custom-face-selected 'group
|
|
1614 "Edit the attributes of the selected display in a face specification."
|
|
1615 :args '((repeat :format ""
|
|
1616 :inline t
|
|
1617 (group custom-display-unselected sexp))
|
|
1618 (group (sexp :format "") custom-face-edit)
|
|
1619 (repeat :format ""
|
|
1620 :inline t
|
|
1621 sexp)))
|
|
1622
|
|
1623 (defconst custom-face-selected (widget-convert 'custom-face-selected)
|
|
1624 "Converted version of the `custom-face-selected' widget.")
|
|
1625
|
28
|
1626 (defun custom-face-value-create (widget)
|
|
1627 ;; Create a list of the display specifications.
|
|
1628 (unless (eq (preceding-char) ?\n)
|
|
1629 (insert "\n"))
|
|
1630 (when (not (eq (widget-get widget :custom-state) 'hidden))
|
120
|
1631 (message "Creating face editor...")
|
28
|
1632 (custom-load-widget widget)
|
|
1633 (let* ((symbol (widget-value widget))
|
120
|
1634 (spec (or (get symbol 'saved-face)
|
|
1635 (get symbol 'factory-face)
|
|
1636 ;; Attempt to construct it.
|
|
1637 (list (list t (custom-face-attributes-get
|
|
1638 symbol (selected-frame))))))
|
|
1639 (form (widget-get widget :custom-form))
|
|
1640 (indent (widget-get widget :indent))
|
28
|
1641 (edit (widget-create-child-and-convert
|
120
|
1642 widget
|
|
1643 (cond ((and (eq form 'selected)
|
|
1644 (widget-apply custom-face-selected :match spec))
|
|
1645 (when indent (insert-char ?\ indent))
|
|
1646 'custom-face-selected)
|
|
1647 ((and (not (eq form 'lisp))
|
|
1648 (widget-apply custom-face-all :match spec))
|
|
1649 'custom-face-all)
|
|
1650 (t
|
|
1651 (when indent (insert-char ?\ indent))
|
|
1652 'sexp))
|
|
1653 :value spec)))
|
28
|
1654 (custom-face-state-set widget)
|
120
|
1655 (widget-put widget :children (list edit)))
|
|
1656 (message "Creating face editor...done")))
|
28
|
1657
|
|
1658 (defvar custom-face-menu
|
134
|
1659 '(("Hide" custom-toggle-hide
|
|
1660 (lambda (widget)
|
|
1661 (not (memq (widget-get widget :custom-state) '(modified invalid)))))
|
|
1662 ("Edit Selected" custom-face-edit-selected
|
|
1663 (lambda (widget)
|
|
1664 (not (eq (widget-get widget :custom-form) 'selected))))
|
|
1665 ("Edit All" custom-face-edit-all
|
|
1666 (lambda (widget)
|
|
1667 (not (eq (widget-get widget :custom-form) 'all))))
|
|
1668 ("Edit Lisp" custom-face-edit-lisp
|
|
1669 (lambda (widget)
|
|
1670 (not (eq (widget-get widget :custom-form) 'lisp))))
|
|
1671 ("Set" custom-face-set)
|
|
1672 ("Save" custom-face-save)
|
|
1673 ("Reset to Saved" custom-face-reset-saved
|
|
1674 (lambda (widget)
|
|
1675 (get (widget-value widget) 'saved-face)))
|
|
1676 ("Reset to Factory Setting" custom-face-reset-factory
|
|
1677 (lambda (widget)
|
|
1678 (get (widget-value widget) 'factory-face))))
|
28
|
1679 "Alist of actions for the `custom-face' widget.
|
134
|
1680 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
1681 the menu entry, ACTION is the function to call on the widget when the
|
|
1682 menu is selected, and FILTER is a predicate which takes a `custom-face'
|
|
1683 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
1684 widget. If FILTER is nil, ACTION is always valid.")
|
28
|
1685
|
120
|
1686 (defun custom-face-edit-selected (widget)
|
|
1687 "Edit selected attributes of the value of WIDGET."
|
|
1688 (widget-put widget :custom-state 'unknown)
|
|
1689 (widget-put widget :custom-form 'selected)
|
|
1690 (custom-redraw widget))
|
|
1691
|
|
1692 (defun custom-face-edit-all (widget)
|
|
1693 "Edit all attributes of the value of WIDGET."
|
|
1694 (widget-put widget :custom-state 'unknown)
|
|
1695 (widget-put widget :custom-form 'all)
|
|
1696 (custom-redraw widget))
|
|
1697
|
|
1698 (defun custom-face-edit-lisp (widget)
|
|
1699 "Edit the lisp representation of the value of WIDGET."
|
|
1700 (widget-put widget :custom-state 'unknown)
|
|
1701 (widget-put widget :custom-form 'lisp)
|
|
1702 (custom-redraw widget))
|
|
1703
|
28
|
1704 (defun custom-face-state-set (widget)
|
|
1705 "Set the state of WIDGET."
|
|
1706 (let ((symbol (widget-value widget)))
|
|
1707 (widget-put widget :custom-state (cond ((get symbol 'customized-face)
|
|
1708 'set)
|
|
1709 ((get symbol 'saved-face)
|
|
1710 'saved)
|
|
1711 ((get symbol 'factory-face)
|
|
1712 'factory)
|
|
1713 (t
|
|
1714 'rogue)))))
|
|
1715
|
|
1716 (defun custom-face-action (widget &optional event)
|
|
1717 "Show the menu for `custom-face' WIDGET.
|
|
1718 Optional EVENT is the location for the menu."
|
|
1719 (if (eq (widget-get widget :custom-state) 'hidden)
|
|
1720 (progn
|
|
1721 (widget-put widget :custom-state 'unknown)
|
|
1722 (custom-redraw widget))
|
|
1723 (let* ((completion-ignore-case t)
|
|
1724 (symbol (widget-get widget :value))
|
|
1725 (answer (widget-choose (custom-unlispify-tag-name symbol)
|
134
|
1726 (custom-menu-filter custom-face-menu
|
|
1727 widget)
|
|
1728 event)))
|
28
|
1729 (if answer
|
|
1730 (funcall answer widget)))))
|
|
1731
|
|
1732 (defun custom-face-set (widget)
|
|
1733 "Make the face attributes in WIDGET take effect."
|
|
1734 (let* ((symbol (widget-value widget))
|
|
1735 (child (car (widget-get widget :children)))
|
|
1736 (value (widget-value child)))
|
|
1737 (put symbol 'customized-face value)
|
|
1738 (when (fboundp 'copy-face)
|
|
1739 (copy-face 'custom-face-empty symbol))
|
|
1740 (custom-face-display-set symbol value)
|
|
1741 (custom-face-state-set widget)
|
|
1742 (custom-redraw-magic widget)))
|
|
1743
|
|
1744 (defun custom-face-save (widget)
|
|
1745 "Make the face attributes in WIDGET default."
|
|
1746 (let* ((symbol (widget-value widget))
|
|
1747 (child (car (widget-get widget :children)))
|
|
1748 (value (widget-value child)))
|
|
1749 (when (fboundp 'copy-face)
|
|
1750 (copy-face 'custom-face-empty symbol))
|
|
1751 (custom-face-display-set symbol value)
|
|
1752 (put symbol 'saved-face value)
|
|
1753 (put symbol 'customized-face nil)
|
|
1754 (custom-face-state-set widget)
|
|
1755 (custom-redraw-magic widget)))
|
|
1756
|
|
1757 (defun custom-face-reset-saved (widget)
|
|
1758 "Restore WIDGET to the face's default attributes."
|
|
1759 (let* ((symbol (widget-value widget))
|
|
1760 (child (car (widget-get widget :children)))
|
|
1761 (value (get symbol 'saved-face)))
|
|
1762 (unless value
|
|
1763 (error "No saved value for this face"))
|
|
1764 (put symbol 'customized-face nil)
|
|
1765 (when (fboundp 'copy-face)
|
|
1766 (copy-face 'custom-face-empty symbol))
|
|
1767 (custom-face-display-set symbol value)
|
|
1768 (widget-value-set child value)
|
|
1769 (custom-face-state-set widget)
|
|
1770 (custom-redraw-magic widget)))
|
|
1771
|
|
1772 (defun custom-face-reset-factory (widget)
|
|
1773 "Restore WIDGET to the face's factory settings."
|
|
1774 (let* ((symbol (widget-value widget))
|
|
1775 (child (car (widget-get widget :children)))
|
|
1776 (value (get symbol 'factory-face)))
|
|
1777 (unless value
|
|
1778 (error "No factory default for this face"))
|
|
1779 (put symbol 'customized-face nil)
|
|
1780 (when (get symbol 'saved-face)
|
|
1781 (put symbol 'saved-face nil)
|
|
1782 (custom-save-all))
|
|
1783 (when (fboundp 'copy-face)
|
|
1784 (copy-face 'custom-face-empty symbol))
|
|
1785 (custom-face-display-set symbol value)
|
|
1786 (widget-value-set child value)
|
|
1787 (custom-face-state-set widget)
|
|
1788 (custom-redraw-magic widget)))
|
|
1789
|
|
1790 ;;; The `face' Widget.
|
|
1791
|
|
1792 (define-widget 'face 'default
|
|
1793 "Select and customize a face."
|
|
1794 :convert-widget 'widget-item-convert-widget
|
|
1795 :format "%[%t%]: %v"
|
|
1796 :tag "Face"
|
|
1797 :value 'default
|
|
1798 :value-create 'widget-face-value-create
|
|
1799 :value-delete 'widget-face-value-delete
|
|
1800 :value-get 'widget-item-value-get
|
|
1801 :validate 'widget-editable-list-validate
|
|
1802 :action 'widget-face-action
|
|
1803 :match '(lambda (widget value) (symbolp value)))
|
|
1804
|
|
1805 (defun widget-face-value-create (widget)
|
|
1806 ;; Create a `custom-face' child.
|
|
1807 (let* ((symbol (widget-value widget))
|
|
1808 (child (widget-create-child-and-convert
|
|
1809 widget 'custom-face
|
|
1810 :format "%t %s%m%h%v"
|
|
1811 :custom-level nil
|
|
1812 :value symbol)))
|
|
1813 (custom-magic-reset child)
|
|
1814 (setq custom-options (cons child custom-options))
|
|
1815 (widget-put widget :children (list child))))
|
|
1816
|
|
1817 (defun widget-face-value-delete (widget)
|
|
1818 ;; Remove the child from the options.
|
|
1819 (let ((child (car (widget-get widget :children))))
|
|
1820 (setq custom-options (delq child custom-options))
|
|
1821 (widget-children-value-delete widget)))
|
|
1822
|
|
1823 (defvar face-history nil
|
|
1824 "History of entered face names.")
|
|
1825
|
|
1826 (defun widget-face-action (widget &optional event)
|
|
1827 "Prompt for a face."
|
|
1828 (let ((answer (completing-read "Face: "
|
|
1829 (mapcar (lambda (face)
|
|
1830 (list (symbol-name face)))
|
|
1831 (face-list))
|
|
1832 nil nil nil
|
|
1833 'face-history)))
|
|
1834 (unless (zerop (length answer))
|
|
1835 (widget-value-set widget (intern answer))
|
|
1836 (widget-apply widget :notify widget event)
|
|
1837 (widget-setup))))
|
|
1838
|
|
1839 ;;; The `hook' Widget.
|
|
1840
|
|
1841 (define-widget 'hook 'list
|
|
1842 "A emacs lisp hook"
|
|
1843 :convert-widget 'custom-hook-convert-widget
|
|
1844 :tag "Hook")
|
|
1845
|
|
1846 (defun custom-hook-convert-widget (widget)
|
|
1847 ;; Handle `:custom-options'.
|
|
1848 (let* ((options (widget-get widget :options))
|
|
1849 (other `(editable-list :inline t
|
|
1850 :entry-format "%i %d%v"
|
|
1851 (function :format " %v")))
|
|
1852 (args (if options
|
|
1853 (list `(checklist :inline t
|
|
1854 ,@(mapcar (lambda (entry)
|
|
1855 `(function-item ,entry))
|
|
1856 options))
|
|
1857 other)
|
|
1858 (list other))))
|
|
1859 (widget-put widget :args args)
|
|
1860 widget))
|
|
1861
|
|
1862 ;;; The `custom-group' Widget.
|
|
1863
|
|
1864 (defcustom custom-group-tag-faces '(custom-group-tag-face-1)
|
|
1865 ;; In XEmacs, this ought to play games with font size.
|
|
1866 "Face used for group tags.
|
|
1867 The first member is used for level 1 groups, the second for level 2,
|
|
1868 and so forth. The remaining group tags are shown with
|
|
1869 `custom-group-tag-face'."
|
|
1870 :type '(repeat face)
|
124
|
1871 :group 'custom-faces)
|
28
|
1872
|
|
1873 (defface custom-group-tag-face-1 '((((class color)
|
118
|
1874 (background dark))
|
|
1875 (:foreground "pink" :underline t))
|
|
1876 (((class color)
|
|
1877 (background light))
|
|
1878 (:foreground "red" :underline t))
|
|
1879 (t (:underline t)))
|
28
|
1880 "Face used for group tags.")
|
|
1881
|
|
1882 (defface custom-group-tag-face '((((class color)
|
|
1883 (background dark))
|
|
1884 (:foreground "light blue" :underline t))
|
|
1885 (((class color)
|
|
1886 (background light))
|
|
1887 (:foreground "blue" :underline t))
|
|
1888 (t (:underline t)))
|
|
1889 "Face used for low level group tags."
|
124
|
1890 :group 'custom-faces)
|
28
|
1891
|
|
1892 (define-widget 'custom-group 'custom
|
|
1893 "Customize group."
|
|
1894 :format "%l%{%t%}:%L\n%m%h%a%v"
|
|
1895 :sample-face-get 'custom-group-sample-face-get
|
|
1896 :documentation-property 'group-documentation
|
30
|
1897 :help-echo "Set or reset all members of this group."
|
28
|
1898 :value-create 'custom-group-value-create
|
|
1899 :action 'custom-group-action
|
|
1900 :custom-set 'custom-group-set
|
|
1901 :custom-save 'custom-group-save
|
|
1902 :custom-reset-current 'custom-group-reset-current
|
|
1903 :custom-reset-saved 'custom-group-reset-saved
|
|
1904 :custom-reset-factory 'custom-group-reset-factory
|
|
1905 :custom-menu 'custom-group-menu-create)
|
|
1906
|
|
1907 (defun custom-group-sample-face-get (widget)
|
|
1908 ;; Use :sample-face.
|
|
1909 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
|
|
1910 'custom-group-tag-face))
|
|
1911
|
|
1912 (defun custom-group-value-create (widget)
|
|
1913 (let ((state (widget-get widget :custom-state)))
|
|
1914 (unless (eq state 'hidden)
|
120
|
1915 (message "Creating group...")
|
28
|
1916 (custom-load-widget widget)
|
|
1917 (let* ((level (widget-get widget :custom-level))
|
|
1918 (symbol (widget-value widget))
|
|
1919 (members (get symbol 'custom-group))
|
|
1920 (prefixes (widget-get widget :custom-prefixes))
|
|
1921 (custom-prefix-list (custom-prefix-add symbol prefixes))
|
120
|
1922 (length (length members))
|
|
1923 (count 0)
|
28
|
1924 (children (mapcar (lambda (entry)
|
|
1925 (widget-insert "\n")
|
120
|
1926 (message "Creating group members... %2d%%"
|
|
1927 (/ (* 100.0 count) length))
|
|
1928 (setq count (1+ count))
|
28
|
1929 (prog1
|
|
1930 (widget-create-child-and-convert
|
|
1931 widget (nth 1 entry)
|
|
1932 :group widget
|
|
1933 :tag (custom-unlispify-tag-name
|
|
1934 (nth 0 entry))
|
|
1935 :custom-prefixes custom-prefix-list
|
|
1936 :custom-level (1+ level)
|
|
1937 :value (nth 0 entry))
|
|
1938 (unless (eq (preceding-char) ?\n)
|
|
1939 (widget-insert "\n"))))
|
|
1940 members)))
|
120
|
1941 (message "Creating group magic...")
|
28
|
1942 (mapcar 'custom-magic-reset children)
|
120
|
1943 (message "Creating group state...")
|
28
|
1944 (widget-put widget :children children)
|
120
|
1945 (custom-group-state-update widget)
|
|
1946 (message "Creating group... done")))))
|
28
|
1947
|
|
1948 (defvar custom-group-menu
|
134
|
1949 '(("Hide" custom-toggle-hide
|
|
1950 (lambda (widget)
|
|
1951 (not (memq (widget-get widget :custom-state) '(modified invalid)))))
|
|
1952 ("Set" custom-group-set
|
|
1953 (lambda (widget)
|
|
1954 (eq (widget-get widget :custom-state) 'modified)))
|
|
1955 ("Save" custom-group-save
|
|
1956 (lambda (widget)
|
|
1957 (memq (widget-get widget :custom-state) '(modified set))))
|
|
1958 ("Reset to Current" custom-group-reset-current
|
|
1959 (lambda (widget)
|
|
1960 (and (default-boundp (widget-value widget))
|
|
1961 (memq (widget-get widget :custom-state) '(modified)))))
|
|
1962 ("Reset to Saved" custom-group-reset-saved
|
|
1963 (lambda (widget)
|
|
1964 (and (get (widget-value widget) 'saved-value)
|
|
1965 (memq (widget-get widget :custom-state) '(modified set)))))
|
|
1966 ("Reset to Factory" custom-group-reset-factory
|
|
1967 (lambda (widget)
|
|
1968 (and (get (widget-value widget) 'factory-value)
|
|
1969 (memq (widget-get widget :custom-state) '(modified set saved))))))
|
28
|
1970 "Alist of actions for the `custom-group' widget.
|
134
|
1971 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
1972 the menu entry, ACTION is the function to call on the widget when the
|
|
1973 menu is selected, and FILTER is a predicate which takes a `custom-group'
|
|
1974 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
1975 widget. If FILTER is nil, ACTION is always valid.")
|
28
|
1976
|
|
1977 (defun custom-group-action (widget &optional event)
|
|
1978 "Show the menu for `custom-group' WIDGET.
|
|
1979 Optional EVENT is the location for the menu."
|
|
1980 (if (eq (widget-get widget :custom-state) 'hidden)
|
|
1981 (progn
|
|
1982 (widget-put widget :custom-state 'unknown)
|
|
1983 (custom-redraw widget))
|
|
1984 (let* ((completion-ignore-case t)
|
|
1985 (answer (widget-choose (custom-unlispify-tag-name
|
|
1986 (widget-get widget :value))
|
134
|
1987 (custom-menu-filter custom-group-menu
|
|
1988 widget)
|
28
|
1989 event)))
|
|
1990 (if answer
|
|
1991 (funcall answer widget)))))
|
|
1992
|
|
1993 (defun custom-group-set (widget)
|
|
1994 "Set changes in all modified group members."
|
|
1995 (let ((children (widget-get widget :children)))
|
|
1996 (mapcar (lambda (child)
|
|
1997 (when (eq (widget-get child :custom-state) 'modified)
|
|
1998 (widget-apply child :custom-set)))
|
|
1999 children )))
|
|
2000
|
|
2001 (defun custom-group-save (widget)
|
|
2002 "Save all modified group members."
|
|
2003 (let ((children (widget-get widget :children)))
|
|
2004 (mapcar (lambda (child)
|
|
2005 (when (memq (widget-get child :custom-state) '(modified set))
|
|
2006 (widget-apply child :custom-save)))
|
|
2007 children )))
|
|
2008
|
|
2009 (defun custom-group-reset-current (widget)
|
|
2010 "Reset all modified group members."
|
|
2011 (let ((children (widget-get widget :children)))
|
|
2012 (mapcar (lambda (child)
|
|
2013 (when (eq (widget-get child :custom-state) 'modified)
|
|
2014 (widget-apply child :custom-reset-current)))
|
|
2015 children )))
|
|
2016
|
|
2017 (defun custom-group-reset-saved (widget)
|
|
2018 "Reset all modified or set group members."
|
|
2019 (let ((children (widget-get widget :children)))
|
|
2020 (mapcar (lambda (child)
|
|
2021 (when (memq (widget-get child :custom-state) '(modified set))
|
|
2022 (widget-apply child :custom-reset-saved)))
|
|
2023 children )))
|
|
2024
|
|
2025 (defun custom-group-reset-factory (widget)
|
|
2026 "Reset all modified, set, or saved group members."
|
|
2027 (let ((children (widget-get widget :children)))
|
|
2028 (mapcar (lambda (child)
|
|
2029 (when (memq (widget-get child :custom-state)
|
|
2030 '(modified set saved))
|
|
2031 (widget-apply child :custom-reset-factory)))
|
|
2032 children )))
|
|
2033
|
|
2034 (defun custom-group-state-update (widget)
|
|
2035 "Update magic."
|
|
2036 (unless (eq (widget-get widget :custom-state) 'hidden)
|
|
2037 (let* ((children (widget-get widget :children))
|
|
2038 (states (mapcar (lambda (child)
|
|
2039 (widget-get child :custom-state))
|
|
2040 children))
|
|
2041 (magics custom-magic-alist)
|
|
2042 (found 'factory))
|
|
2043 (while magics
|
|
2044 (let ((magic (car (car magics))))
|
|
2045 (if (and (not (eq magic 'hidden))
|
|
2046 (memq magic states))
|
|
2047 (setq found magic
|
|
2048 magics nil)
|
|
2049 (setq magics (cdr magics)))))
|
|
2050 (widget-put widget :custom-state found)))
|
|
2051 (custom-magic-reset widget))
|
|
2052
|
|
2053 ;;; The `custom-save-all' Function.
|
|
2054
|
|
2055 (defcustom custom-file "~/.emacs"
|
|
2056 "File used for storing customization information.
|
|
2057 If you change this from the default \"~/.emacs\" you need to
|
|
2058 explicitly load that file for the settings to take effect."
|
|
2059 :type 'file
|
|
2060 :group 'customize)
|
|
2061
|
|
2062 (defun custom-save-delete (symbol)
|
|
2063 "Delete the call to SYMBOL form `custom-file'.
|
|
2064 Leave point at the location of the call, or after the last expression."
|
|
2065 (set-buffer (find-file-noselect custom-file))
|
|
2066 (goto-char (point-min))
|
|
2067 (catch 'found
|
|
2068 (while t
|
|
2069 (let ((sexp (condition-case nil
|
|
2070 (read (current-buffer))
|
|
2071 (end-of-file (throw 'found nil)))))
|
|
2072 (when (and (listp sexp)
|
|
2073 (eq (car sexp) symbol))
|
|
2074 (delete-region (save-excursion
|
|
2075 (backward-sexp)
|
|
2076 (point))
|
|
2077 (point))
|
|
2078 (throw 'found nil))))))
|
|
2079
|
|
2080 (defun custom-save-variables ()
|
|
2081 "Save all customized variables in `custom-file'."
|
|
2082 (save-excursion
|
|
2083 (custom-save-delete 'custom-set-variables)
|
|
2084 (let ((standard-output (current-buffer)))
|
|
2085 (unless (bolp)
|
|
2086 (princ "\n"))
|
|
2087 (princ "(custom-set-variables")
|
|
2088 (mapatoms (lambda (symbol)
|
134
|
2089 (let ((value (get symbol 'saved-value))
|
|
2090 (requests (get symbol 'custom-requests))
|
|
2091 (now (not (or (get symbol 'factory-value)
|
|
2092 (and (not (boundp symbol))
|
|
2093 (not (get symbol 'force-value)))))))
|
28
|
2094 (when value
|
|
2095 (princ "\n '(")
|
|
2096 (princ symbol)
|
|
2097 (princ " ")
|
|
2098 (prin1 (car value))
|
134
|
2099 (cond (requests
|
|
2100 (if now
|
|
2101 (princ " t ")
|
|
2102 (princ " nil "))
|
|
2103 (prin1 requests)
|
|
2104 (princ ")"))
|
|
2105 (now
|
|
2106 (princ " t)"))
|
|
2107 (t
|
|
2108 (princ ")")))))))
|
28
|
2109 (princ ")")
|
120
|
2110 (unless (looking-at "\n")
|
28
|
2111 (princ "\n")))))
|
|
2112
|
|
2113 (defun custom-save-faces ()
|
|
2114 "Save all customized faces in `custom-file'."
|
|
2115 (save-excursion
|
|
2116 (custom-save-delete 'custom-set-faces)
|
|
2117 (let ((standard-output (current-buffer)))
|
|
2118 (unless (bolp)
|
|
2119 (princ "\n"))
|
|
2120 (princ "(custom-set-faces")
|
120
|
2121 (let ((value (get 'default 'saved-face)))
|
|
2122 ;; The default face must be first, since it affects the others.
|
|
2123 (when value
|
|
2124 (princ "\n '(default ")
|
|
2125 (prin1 value)
|
|
2126 (if (or (get 'default 'factory-face)
|
|
2127 (and (not (custom-facep 'default))
|
|
2128 (not (get 'default 'force-face))))
|
|
2129 (princ ")")
|
|
2130 (princ " t)"))))
|
28
|
2131 (mapatoms (lambda (symbol)
|
|
2132 (let ((value (get symbol 'saved-face)))
|
120
|
2133 (when (and (not (eq symbol 'default))
|
|
2134 ;; Don't print default face here.
|
|
2135 value)
|
28
|
2136 (princ "\n '(")
|
|
2137 (princ symbol)
|
|
2138 (princ " ")
|
|
2139 (prin1 value)
|
|
2140 (if (or (get symbol 'factory-face)
|
|
2141 (and (not (custom-facep symbol))
|
|
2142 (not (get symbol 'force-face))))
|
|
2143 (princ ")")
|
|
2144 (princ " t)"))))))
|
|
2145 (princ ")")
|
120
|
2146 (unless (looking-at "\n")
|
28
|
2147 (princ "\n")))))
|
|
2148
|
116
|
2149 ;;;###autoload
|
28
|
2150 (defun custom-save-all ()
|
|
2151 "Save all customizations in `custom-file'."
|
|
2152 (custom-save-variables)
|
|
2153 (custom-save-faces)
|
|
2154 (save-excursion
|
|
2155 (set-buffer (find-file-noselect custom-file))
|
|
2156 (save-buffer)))
|
|
2157
|
|
2158 ;;; The Customize Menu.
|
|
2159
|
120
|
2160 ;;; Menu support
|
|
2161
|
|
2162 (unless (string-match "XEmacs" emacs-version)
|
|
2163 (defconst custom-help-menu '("Customize"
|
|
2164 ["Update menu..." custom-menu-update t]
|
|
2165 ["Group..." customize t]
|
|
2166 ["Variable..." customize-variable t]
|
|
2167 ["Face..." customize-face t]
|
|
2168 ["Saved..." customize-customized t]
|
|
2169 ["Apropos..." customize-apropos t])
|
|
2170 ;; This menu should be identical to the one defined in `menu-bar.el'.
|
|
2171 "Customize menu")
|
|
2172
|
|
2173 (defun custom-menu-reset ()
|
|
2174 "Reset customize menu."
|
|
2175 (remove-hook 'custom-define-hook 'custom-menu-reset)
|
|
2176 (define-key global-map [menu-bar help-menu customize-menu]
|
|
2177 (cons (car custom-help-menu)
|
|
2178 (easy-menu-create-keymaps (car custom-help-menu)
|
|
2179 (cdr custom-help-menu)))))
|
|
2180
|
|
2181 (defun custom-menu-update (event)
|
|
2182 "Update customize menu."
|
|
2183 (interactive "e")
|
|
2184 (add-hook 'custom-define-hook 'custom-menu-reset)
|
|
2185 (let* ((emacs (widget-apply '(custom-group) :custom-menu 'emacs))
|
|
2186 (menu `(,(car custom-help-menu)
|
|
2187 ,emacs
|
|
2188 ,@(cdr (cdr custom-help-menu)))))
|
|
2189 (let ((map (easy-menu-create-keymaps (car menu) (cdr menu))))
|
|
2190 (define-key global-map [menu-bar help-menu customize-menu]
|
|
2191 (cons (car menu) map)))))
|
|
2192
|
|
2193 (defcustom custom-menu-nesting 2
|
|
2194 "Maximum nesting in custom menus."
|
|
2195 :type 'integer
|
|
2196 :group 'customize))
|
28
|
2197
|
|
2198 (defun custom-face-menu-create (widget symbol)
|
|
2199 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
|
|
2200 (vector (custom-unlispify-menu-entry symbol)
|
|
2201 `(custom-buffer-create '((,symbol custom-face)))
|
|
2202 t))
|
|
2203
|
|
2204 (defun custom-variable-menu-create (widget symbol)
|
|
2205 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
|
|
2206 (let ((type (get symbol 'custom-type)))
|
|
2207 (unless (listp type)
|
|
2208 (setq type (list type)))
|
|
2209 (if (and type (widget-get type :custom-menu))
|
|
2210 (widget-apply type :custom-menu symbol)
|
|
2211 (vector (custom-unlispify-menu-entry symbol)
|
|
2212 `(custom-buffer-create '((,symbol custom-variable)))
|
|
2213 t))))
|
|
2214
|
120
|
2215 ;; Add checkboxes to boolean variable entries.
|
28
|
2216 (widget-put (get 'boolean 'widget-type)
|
|
2217 :custom-menu (lambda (widget symbol)
|
|
2218 (vector (custom-unlispify-menu-entry symbol)
|
|
2219 `(custom-buffer-create
|
|
2220 '((,symbol custom-variable)))
|
|
2221 ':style 'toggle
|
|
2222 ':selected symbol)))
|
|
2223
|
34
|
2224 (if (string-match "XEmacs" emacs-version)
|
|
2225 ;; XEmacs can create menus dynamically.
|
|
2226 (defun custom-group-menu-create (widget symbol)
|
|
2227 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
|
|
2228 `( ,(custom-unlispify-menu-entry symbol t)
|
36
|
2229 :filter (lambda (&rest junk)
|
|
2230 (cdr (custom-menu-create ',symbol)))))
|
34
|
2231 ;; But emacs can't.
|
|
2232 (defun custom-group-menu-create (widget symbol)
|
|
2233 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
|
|
2234 ;; Limit the nesting.
|
|
2235 (let ((custom-menu-nesting (1- custom-menu-nesting)))
|
|
2236 (custom-menu-create symbol))))
|
28
|
2237
|
120
|
2238 ;;;###autoload
|
124
|
2239 (defun custom-menu-create (symbol)
|
28
|
2240 "Create menu for customization group SYMBOL.
|
|
2241 The menu is in a format applicable to `easy-menu-define'."
|
124
|
2242 (let* ((item (vector (custom-unlispify-menu-entry symbol)
|
|
2243 `(custom-buffer-create '((,symbol custom-group)))
|
|
2244 t)))
|
120
|
2245 (if (and (or (not (boundp 'custom-menu-nesting))
|
|
2246 (>= custom-menu-nesting 0))
|
28
|
2247 (< (length (get symbol 'custom-group)) widget-menu-max-size))
|
34
|
2248 (let ((custom-prefix-list (custom-prefix-add symbol
|
28
|
2249 custom-prefix-list)))
|
|
2250 (custom-load-symbol symbol)
|
|
2251 `(,(custom-unlispify-menu-entry symbol t)
|
|
2252 ,item
|
|
2253 "--"
|
|
2254 ,@(mapcar (lambda (entry)
|
|
2255 (widget-apply (if (listp (nth 1 entry))
|
|
2256 (nth 1 entry)
|
|
2257 (list (nth 1 entry)))
|
|
2258 :custom-menu (nth 0 entry)))
|
|
2259 (get symbol 'custom-group))))
|
|
2260 item)))
|
|
2261
|
124
|
2262 ;;;###autoload
|
|
2263 (defun customize-menu-create (symbol &optional name)
|
|
2264 "Return a customize menu for customization group SYMBOL.
|
|
2265 If optional NAME is given, use that as the name of the menu.
|
|
2266 Otherwise the menu will be named `Customize'.
|
|
2267 The format is suitable for use with `easy-menu-define'."
|
|
2268 (unless name
|
|
2269 (setq name "Customize"))
|
|
2270 (if (string-match "XEmacs" emacs-version)
|
|
2271 ;; We can delay it under XEmacs.
|
|
2272 `(,name
|
|
2273 :filter (lambda (&rest junk)
|
|
2274 (cdr (custom-menu-create ',symbol))))
|
|
2275 ;; But we must create it now under Emacs.
|
|
2276 (cons name (cdr (custom-menu-create symbol)))))
|
|
2277
|
|
2278 ;;; The Custom Mode.
|
|
2279
|
|
2280 (defvar custom-mode-map nil
|
|
2281 "Keymap for `custom-mode'.")
|
|
2282
|
|
2283 (unless custom-mode-map
|
|
2284 (setq custom-mode-map (make-sparse-keymap))
|
|
2285 (set-keymap-parent custom-mode-map widget-keymap)
|
|
2286 (define-key custom-mode-map "q" 'bury-buffer))
|
|
2287
|
|
2288 (easy-menu-define custom-mode-customize-menu
|
|
2289 custom-mode-map
|
134
|
2290 "Menu used to customize customization buffers."
|
124
|
2291 (customize-menu-create 'customize))
|
28
|
2292
|
124
|
2293 (easy-menu-define custom-mode-menu
|
|
2294 custom-mode-map
|
|
2295 "Menu used in customization buffers."
|
|
2296 `("Custom"
|
|
2297 ["Set" custom-set t]
|
|
2298 ["Save" custom-save t]
|
|
2299 ["Reset to Current" custom-reset-current t]
|
|
2300 ["Reset to Saved" custom-reset-saved t]
|
|
2301 ["Reset to Factory Settings" custom-reset-factory t]
|
|
2302 ["Info" (Info-goto-node "(custom)The Customization Buffer") t]))
|
|
2303
|
|
2304 (defcustom custom-mode-hook nil
|
|
2305 "Hook called when entering custom-mode."
|
|
2306 :type 'hook
|
|
2307 :group 'customize)
|
|
2308
|
|
2309 (defun custom-mode ()
|
|
2310 "Major mode for editing customization buffers.
|
|
2311
|
|
2312 The following commands are available:
|
|
2313
|
|
2314 Move to next button or editable field. \\[widget-forward]
|
|
2315 Move to previous button or editable field. \\[widget-backward]
|
|
2316 Activate button under the mouse pointer. \\[widget-button-click]
|
|
2317 Activate button under point. \\[widget-button-press]
|
|
2318 Set all modifications. \\[custom-set]
|
|
2319 Make all modifications default. \\[custom-save]
|
|
2320 Reset all modified options. \\[custom-reset-current]
|
|
2321 Reset all modified or set options. \\[custom-reset-saved]
|
|
2322 Reset all options. \\[custom-reset-factory]
|
|
2323
|
|
2324 Entry to this mode calls the value of `custom-mode-hook'
|
|
2325 if that value is non-nil."
|
|
2326 (kill-all-local-variables)
|
|
2327 (setq major-mode 'custom-mode
|
|
2328 mode-name "Custom")
|
|
2329 (use-local-map custom-mode-map)
|
|
2330 (easy-menu-add custom-mode-customize-menu)
|
|
2331 (easy-menu-add custom-mode-menu)
|
|
2332 (make-local-variable 'custom-options)
|
|
2333 (run-hooks 'custom-mode-hook))
|
28
|
2334
|
|
2335 ;;; The End.
|
|
2336
|
|
2337 (provide 'cus-edit)
|
|
2338
|
|
2339 ;; cus-edit.el ends here
|