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