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