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