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