28
|
1 ;;; cus-edit.el --- Tools for customization Emacs.
|
|
2 ;;
|
|
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
|
4 ;;
|
|
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
|
|
6 ;; Keywords: help, faces
|
173
|
7 ;; Version: 1.9951
|
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
|
|
443 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
|
|
444 "Convert symbol into a menu entry."
|
|
445 (cond ((not custom-unlispify-menu-entries)
|
|
446 (symbol-name symbol))
|
|
447 ((get symbol 'custom-tag)
|
|
448 (if no-suffix
|
|
449 (get symbol 'custom-tag)
|
|
450 (concat (get symbol 'custom-tag) "...")))
|
|
451 (t
|
|
452 (save-excursion
|
|
453 (set-buffer (get-buffer-create " *Custom-Work*"))
|
|
454 (erase-buffer)
|
|
455 (princ symbol (current-buffer))
|
|
456 (goto-char (point-min))
|
120
|
457 (when (and (eq (get symbol 'custom-type) 'boolean)
|
|
458 (re-search-forward "-p\\'" nil t))
|
|
459 (replace-match "" t t)
|
|
460 (goto-char (point-min)))
|
28
|
461 (let ((prefixes custom-prefix-list)
|
|
462 prefix)
|
|
463 (while prefixes
|
|
464 (setq prefix (car prefixes))
|
|
465 (if (search-forward prefix (+ (point) (length prefix)) t)
|
|
466 (progn
|
|
467 (setq prefixes nil)
|
|
468 (delete-region (point-min) (point)))
|
|
469 (setq prefixes (cdr prefixes)))))
|
|
470 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
|
|
471 (capitalize-region (point-min) (point-max))
|
|
472 (unless no-suffix
|
|
473 (goto-char (point-max))
|
|
474 (insert "..."))
|
|
475 (buffer-string)))))
|
|
476
|
|
477 (defcustom custom-unlispify-tag-names t
|
|
478 "Display tag names as words instead of symbols if non nil."
|
161
|
479 :group 'custom-buffer
|
28
|
480 :type 'boolean)
|
|
481
|
|
482 (defun custom-unlispify-tag-name (symbol)
|
|
483 "Convert symbol into a menu entry."
|
|
484 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
|
|
485 (custom-unlispify-menu-entry symbol t)))
|
|
486
|
|
487 (defun custom-prefix-add (symbol prefixes)
|
|
488 ;; Addd SYMBOL to list of ignored PREFIXES.
|
|
489 (cons (or (get symbol 'custom-prefix)
|
|
490 (concat (symbol-name symbol) "-"))
|
|
491 prefixes))
|
|
492
|
124
|
493 ;;; Guess.
|
|
494
|
|
495 (defcustom custom-guess-name-alist
|
120
|
496 '(("-p\\'" boolean)
|
|
497 ("-hook\\'" hook)
|
|
498 ("-face\\'" face)
|
|
499 ("-file\\'" file)
|
|
500 ("-function\\'" function)
|
|
501 ("-functions\\'" (repeat function))
|
|
502 ("-list\\'" (repeat sexp))
|
|
503 ("-alist\\'" (repeat (cons sexp sexp))))
|
|
504 "Alist of (MATCH TYPE).
|
|
505
|
|
506 MATCH should be a regexp matching the name of a symbol, and TYPE should
|
|
507 be a widget suitable for editing the value of that symbol. The TYPE
|
|
508 of the first entry where MATCH matches the name of the symbol will be
|
|
509 used.
|
|
510
|
|
511 This is used for guessing the type of variables not declared with
|
|
512 customize."
|
124
|
513 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
|
|
514 :group 'customize)
|
|
515
|
|
516 (defcustom custom-guess-doc-alist
|
|
517 '(("\\`\\*?Non-nil " boolean))
|
|
518 "Alist of (MATCH TYPE).
|
|
519
|
|
520 MATCH should be a regexp matching a documentation string, and TYPE
|
|
521 should be a widget suitable for editing the value of a variable with
|
|
522 that documentation string. The TYPE of the first entry where MATCH
|
|
523 matches the name of the symbol will be used.
|
|
524
|
|
525 This is used for guessing the type of variables not declared with
|
|
526 customize."
|
|
527 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
|
120
|
528 :group 'customize)
|
|
529
|
|
530 (defun custom-guess-type (symbol)
|
|
531 "Guess a widget suitable for editing the value of SYMBOL.
|
124
|
532 This is done by matching SYMBOL with `custom-guess-name-alist' and
|
|
533 if that fails, the doc string with `custom-guess-doc-alist'."
|
120
|
534 (let ((name (symbol-name symbol))
|
124
|
535 (names custom-guess-name-alist)
|
120
|
536 current found)
|
124
|
537 (while names
|
|
538 (setq current (car names)
|
|
539 names (cdr names))
|
120
|
540 (when (string-match (nth 0 current) name)
|
|
541 (setq found (nth 1 current)
|
124
|
542 names nil)))
|
|
543 (unless found
|
|
544 (let ((doc (documentation-property symbol 'variable-documentation))
|
|
545 (docs custom-guess-doc-alist))
|
|
546 (when doc
|
|
547 (while docs
|
|
548 (setq current (car docs)
|
|
549 docs (cdr docs))
|
|
550 (when (string-match (nth 0 current) doc)
|
|
551 (setq found (nth 1 current)
|
|
552 docs nil))))))
|
120
|
553 found))
|
|
554
|
155
|
555 ;;; Sorting.
|
|
556
|
165
|
557 (defcustom custom-browse-sort-alphabetically nil
|
|
558 "If non-nil, sort members of each customization group alphabetically."
|
|
559 :type 'boolean
|
|
560 :group 'custom-browse)
|
|
561
|
|
562 (defcustom custom-browse-order-groups nil
|
|
563 "If non-nil, order group members within each customization group.
|
|
564 If `first', order groups before non-groups.
|
|
565 If `last', order groups after non-groups."
|
|
566 :type '(choice (const first)
|
|
567 (const last)
|
|
568 (const :tag "none" nil))
|
|
569 :group 'custom-browse)
|
|
570
|
167
|
571 (defcustom custom-browse-only-groups nil
|
|
572 "If non-nil, show group members only within each customization group."
|
|
573 :type 'boolean
|
|
574 :group 'custom-browse)
|
|
575
|
163
|
576 (defcustom custom-buffer-sort-alphabetically nil
|
165
|
577 "If non-nil, sort members of each customization group alphabetically."
|
163
|
578 :type 'boolean
|
161
|
579 :group 'custom-buffer)
|
|
580
|
165
|
581 (defcustom custom-buffer-order-groups 'last
|
|
582 "If non-nil, order group members within each customization group.
|
|
583 If `first', order groups before non-groups.
|
|
584 If `last', order groups after non-groups."
|
|
585 :type '(choice (const first)
|
|
586 (const last)
|
|
587 (const :tag "none" nil))
|
161
|
588 :group 'custom-buffer)
|
155
|
589
|
163
|
590 (defcustom custom-menu-sort-alphabetically nil
|
165
|
591 "If non-nil, sort members of each customization group alphabetically."
|
163
|
592 :type 'boolean
|
161
|
593 :group 'custom-menu)
|
155
|
594
|
165
|
595 (defcustom custom-menu-order-groups 'first
|
|
596 "If non-nil, order group members within each customization group.
|
|
597 If `first', order groups before non-groups.
|
|
598 If `last', order groups after non-groups."
|
|
599 :type '(choice (const first)
|
|
600 (const last)
|
|
601 (const :tag "none" nil))
|
|
602 :group 'custom-menu)
|
155
|
603
|
165
|
604 (defun custom-sort-items (items sort-alphabetically order-groups)
|
|
605 "Return a sorted copy of ITEMS.
|
|
606 ITEMS should be a `custom-group' property.
|
|
607 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
|
|
608 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
|
|
609 groups after non-groups, if nil do not order groups at all."
|
|
610 (sort (copy-sequence items)
|
|
611 (lambda (a b)
|
|
612 (let ((typea (nth 1 a)) (typeb (nth 1 b))
|
|
613 (namea (symbol-name (nth 0 a))) (nameb (symbol-name (nth 0 b))))
|
|
614 (cond ((not order-groups)
|
|
615 ;; Since we don't care about A and B order, maybe sort.
|
|
616 (when sort-alphabetically
|
|
617 (string-lessp namea nameb)))
|
|
618 ((eq typea 'custom-group)
|
|
619 ;; If B is also a group, maybe sort. Otherwise, order A and B.
|
|
620 (if (eq typeb 'custom-group)
|
|
621 (when sort-alphabetically
|
|
622 (string-lessp namea nameb))
|
|
623 (eq order-groups 'first)))
|
|
624 ((eq typeb 'custom-group)
|
|
625 ;; Since A cannot be a group, order A and B.
|
|
626 (eq order-groups 'last))
|
|
627 (sort-alphabetically
|
|
628 ;; Since A and B cannot be groups, sort.
|
|
629 (string-lessp namea nameb)))))))
|
155
|
630
|
124
|
631 ;;; Custom Mode Commands.
|
28
|
632
|
|
633 (defvar custom-options nil
|
|
634 "Customization widgets in the current buffer.")
|
|
635
|
165
|
636 (defun Custom-set ()
|
28
|
637 "Set changes in all modified options."
|
|
638 (interactive)
|
|
639 (let ((children custom-options))
|
|
640 (mapcar (lambda (child)
|
|
641 (when (eq (widget-get child :custom-state) 'modified)
|
|
642 (widget-apply child :custom-set)))
|
|
643 children)))
|
|
644
|
165
|
645 (defun Custom-save ()
|
28
|
646 "Set all modified group members and save them."
|
|
647 (interactive)
|
|
648 (let ((children custom-options))
|
|
649 (mapcar (lambda (child)
|
|
650 (when (memq (widget-get child :custom-state) '(modified set))
|
|
651 (widget-apply child :custom-save)))
|
|
652 children))
|
|
653 (custom-save-all))
|
|
654
|
|
655 (defvar custom-reset-menu
|
165
|
656 '(("Current" . Custom-reset-current)
|
|
657 ("Saved" . Custom-reset-saved)
|
|
658 ("Standard Settings" . Custom-reset-standard))
|
28
|
659 "Alist of actions for the `Reset' button.
|
|
660 The key is a string containing the name of the action, the value is a
|
|
661 lisp function taking the widget as an element which will be called
|
|
662 when the action is chosen.")
|
|
663
|
|
664 (defun custom-reset (event)
|
|
665 "Select item from reset menu."
|
|
666 (let* ((completion-ignore-case t)
|
|
667 (answer (widget-choose "Reset to"
|
|
668 custom-reset-menu
|
|
669 event)))
|
|
670 (if answer
|
|
671 (funcall answer))))
|
|
672
|
165
|
673 (defun Custom-reset-current (&rest ignore)
|
28
|
674 "Reset all modified group members to their current value."
|
|
675 (interactive)
|
|
676 (let ((children custom-options))
|
|
677 (mapcar (lambda (child)
|
|
678 (when (eq (widget-get child :custom-state) 'modified)
|
|
679 (widget-apply child :custom-reset-current)))
|
|
680 children)))
|
|
681
|
165
|
682 (defun Custom-reset-saved (&rest ignore)
|
28
|
683 "Reset all modified or set group members to their saved value."
|
|
684 (interactive)
|
|
685 (let ((children custom-options))
|
|
686 (mapcar (lambda (child)
|
|
687 (when (eq (widget-get child :custom-state) 'modified)
|
163
|
688 (widget-apply child :custom-reset-saved)))
|
28
|
689 children)))
|
|
690
|
165
|
691 (defun Custom-reset-standard (&rest ignore)
|
153
|
692 "Reset all modified, set, or saved group members to their standard settings."
|
28
|
693 (interactive)
|
|
694 (let ((children custom-options))
|
|
695 (mapcar (lambda (child)
|
|
696 (when (eq (widget-get child :custom-state) 'modified)
|
163
|
697 (widget-apply child :custom-reset-standard)))
|
28
|
698 children)))
|
|
699
|
|
700 ;;; The Customize Commands
|
|
701
|
149
|
702 (defun custom-prompt-variable (prompt-var prompt-val)
|
|
703 "Prompt for a variable and a value and return them as a list.
|
|
704 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
|
|
705 prompt for the value. The %s escape in PROMPT-VAL is replaced with
|
|
706 the name of the variable.
|
|
707
|
|
708 If the variable has a `variable-interactive' property, that is used as if
|
|
709 it were the arg to `interactive' (which see) to interactively read the value.
|
|
710
|
|
711 If the variable has a `custom-type' property, it must be a widget and the
|
|
712 `:prompt-value' property of that widget will be used for reading the value."
|
|
713 (let* ((var (read-variable prompt-var))
|
|
714 (minibuffer-help-form '(describe-variable var)))
|
|
715 (list var
|
|
716 (let ((prop (get var 'variable-interactive))
|
|
717 (type (get var 'custom-type))
|
|
718 (prompt (format prompt-val var)))
|
|
719 (unless (listp type)
|
|
720 (setq type (list type)))
|
|
721 (cond (prop
|
|
722 ;; Use VAR's `variable-interactive' property
|
|
723 ;; as an interactive spec for prompting.
|
|
724 (call-interactively (list 'lambda '(arg)
|
|
725 (list 'interactive prop)
|
|
726 'arg)))
|
|
727 (type
|
|
728 (widget-prompt-value type
|
|
729 prompt
|
|
730 (if (boundp var)
|
|
731 (symbol-value var))
|
|
732 (not (boundp var))))
|
|
733 (t
|
|
734 (eval-minibuffer prompt)))))))
|
|
735
|
|
736 ;;;###autoload
|
165
|
737 (defun customize-set-value (var val)
|
149
|
738 "Set VARIABLE to VALUE. VALUE is a Lisp object.
|
|
739
|
|
740 If VARIABLE has a `variable-interactive' property, that is used as if
|
|
741 it were the arg to `interactive' (which see) to interactively read the value.
|
|
742
|
|
743 If VARIABLE has a `custom-type' property, it must be a widget and the
|
|
744 `:prompt-value' property of that widget will be used for reading the value."
|
|
745 (interactive (custom-prompt-variable "Set variable: "
|
|
746 "Set %s to value: "))
|
|
747
|
|
748 (set var val))
|
|
749
|
|
750 ;;;###autoload
|
165
|
751 (defun customize-set-variable (var val)
|
149
|
752 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
|
|
753
|
|
754 If VARIABLE has a `custom-set' property, that is used for setting
|
|
755 VARIABLE, otherwise `set-default' is used.
|
|
756
|
|
757 The `customized-value' property of the VARIABLE will be set to a list
|
|
758 with a quoted VALUE as its sole list member.
|
|
759
|
|
760 If VARIABLE has a `variable-interactive' property, that is used as if
|
|
761 it were the arg to `interactive' (which see) to interactively read the value.
|
|
762
|
|
763 If VARIABLE has a `custom-type' property, it must be a widget and the
|
|
764 `:prompt-value' property of that widget will be used for reading the value. "
|
|
765 (interactive (custom-prompt-variable "Set variable: "
|
|
766 "Set customized value for %s to: "))
|
|
767 (funcall (or (get var 'custom-set) 'set-default) var val)
|
|
768 (put var 'customized-value (list (custom-quote val))))
|
|
769
|
28
|
770 ;;;###autoload
|
173
|
771 (defun customize-save-variable (var val)
|
|
772 "Set the default for VARIABLE to VALUE, and save it for future sessions.
|
|
773 If VARIABLE has a `custom-set' property, that is used for setting
|
|
774 VARIABLE, otherwise `set-default' is used.
|
|
775
|
|
776 The `customized-value' property of the VARIABLE will be set to a list
|
|
777 with a quoted VALUE as its sole list member.
|
|
778
|
|
779 If VARIABLE has a `variable-interactive' property, that is used as if
|
|
780 it were the arg to `interactive' (which see) to interactively read the value.
|
|
781
|
|
782 If VARIABLE has a `custom-type' property, it must be a widget and the
|
|
783 `:prompt-value' property of that widget will be used for reading the value. "
|
|
784 (interactive (custom-prompt-variable "Set and ave variable: "
|
|
785 "Set and save value for %s as: "))
|
|
786 (funcall (or (get var 'custom-set) 'set-default) var val)
|
|
787 (put var 'saved-value (list (custom-quote val)))
|
|
788 (custom-save-all))
|
|
789
|
|
790 ;;;###autoload
|
153
|
791 (defun customize ()
|
|
792 "Select a customization buffer which you can use to set user options.
|
|
793 User options are structured into \"groups\".
|
|
794 Initially the top-level group `Emacs' and its immediate subgroups
|
|
795 are shown; the contents of those subgroups are initially hidden."
|
|
796 (interactive)
|
|
797 (customize-group 'emacs))
|
|
798
|
|
799 ;;;###autoload
|
|
800 (defun customize-group (group)
|
|
801 "Customize GROUP, which must be a customization group."
|
163
|
802 (interactive (list (let ((completion-ignore-case t))
|
|
803 (completing-read "Customize group: (default emacs) "
|
|
804 obarray
|
|
805 (lambda (symbol)
|
|
806 (get symbol 'custom-group))
|
|
807 t))))
|
28
|
808
|
153
|
809 (when (stringp group)
|
|
810 (if (string-equal "" group)
|
|
811 (setq group 'emacs)
|
|
812 (setq group (intern group))))
|
163
|
813 (let ((name (format "*Customize Group: %s*"
|
|
814 (custom-unlispify-tag-name group))))
|
|
815 (if (get-buffer name)
|
|
816 (switch-to-buffer name)
|
|
817 (custom-buffer-create (list (list group 'custom-group))
|
173
|
818 name
|
|
819 (concat " for group "
|
|
820 (custom-unlispify-tag-name group))))))
|
149
|
821
|
|
822 ;;;###autoload
|
153
|
823 (defun customize-group-other-window (symbol)
|
149
|
824 "Customize SYMBOL, which must be a customization group."
|
|
825 (interactive (list (completing-read "Customize group: (default emacs) "
|
|
826 obarray
|
|
827 (lambda (symbol)
|
|
828 (get symbol 'custom-group))
|
|
829 t)))
|
|
830
|
|
831 (when (stringp symbol)
|
|
832 (if (string-equal "" symbol)
|
|
833 (setq symbol 'emacs)
|
|
834 (setq symbol (intern symbol))))
|
|
835 (custom-buffer-create-other-window
|
|
836 (list (list symbol 'custom-group))
|
|
837 (format "*Customize Group: %s*" (custom-unlispify-tag-name symbol))))
|
28
|
838
|
|
839 ;;;###autoload
|
155
|
840 (defalias 'customize-variable 'customize-option)
|
|
841
|
|
842 ;;;###autoload
|
|
843 (defun customize-option (symbol)
|
|
844 "Customize SYMBOL, which must be a user option variable."
|
124
|
845 (interactive (custom-variable-prompt))
|
149
|
846 (custom-buffer-create (list (list symbol 'custom-variable))
|
155
|
847 (format "*Customize Option: %s*"
|
149
|
848 (custom-unlispify-tag-name symbol))))
|
28
|
849
|
|
850 ;;;###autoload
|
155
|
851 (defalias 'customize-variable-other-window 'customize-option-other-window)
|
|
852
|
|
853 ;;;###autoload
|
|
854 (defun customize-option-other-window (symbol)
|
|
855 "Customize SYMBOL, which must be a user option variable.
|
124
|
856 Show the buffer in another window, but don't select it."
|
|
857 (interactive (custom-variable-prompt))
|
149
|
858 (custom-buffer-create-other-window
|
|
859 (list (list symbol 'custom-variable))
|
155
|
860 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
|
124
|
861
|
|
862 ;;;###autoload
|
28
|
863 (defun customize-face (&optional symbol)
|
|
864 "Customize SYMBOL, which should be a face name or nil.
|
|
865 If SYMBOL is nil, customize all faces."
|
|
866 (interactive (list (completing-read "Customize face: (default all) "
|
|
867 obarray 'custom-facep)))
|
|
868 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
|
165
|
869 (custom-buffer-create (custom-sort-items
|
|
870 (mapcar (lambda (symbol)
|
|
871 (list symbol 'custom-face))
|
|
872 (face-list))
|
|
873 t nil)
|
|
874 "*Customize Faces*")
|
|
875 (when (stringp symbol)
|
|
876 (setq symbol (intern symbol)))
|
28
|
877 (unless (symbolp symbol)
|
|
878 (error "Should be a symbol %S" symbol))
|
149
|
879 (custom-buffer-create (list (list symbol 'custom-face))
|
|
880 (format "*Customize Face: %s*"
|
|
881 (custom-unlispify-tag-name symbol)))))
|
28
|
882
|
|
883 ;;;###autoload
|
124
|
884 (defun customize-face-other-window (&optional symbol)
|
|
885 "Show customization buffer for FACE in other window."
|
|
886 (interactive (list (completing-read "Customize face: "
|
|
887 obarray 'custom-facep)))
|
|
888 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
|
|
889 ()
|
|
890 (if (stringp symbol)
|
|
891 (setq symbol (intern symbol)))
|
|
892 (unless (symbolp symbol)
|
|
893 (error "Should be a symbol %S" symbol))
|
149
|
894 (custom-buffer-create-other-window
|
|
895 (list (list symbol 'custom-face))
|
|
896 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol)))))
|
124
|
897
|
|
898 ;;;###autoload
|
28
|
899 (defun customize-customized ()
|
149
|
900 "Customize all user options set since the last save in this session."
|
|
901 (interactive)
|
|
902 (let ((found nil))
|
|
903 (mapatoms (lambda (symbol)
|
173
|
904 (and (get symbol 'customized-face)
|
149
|
905 (custom-facep symbol)
|
163
|
906 (push (list symbol 'custom-face) found))
|
149
|
907 (and (get symbol 'customized-value)
|
|
908 (boundp symbol)
|
163
|
909 (push (list symbol 'custom-variable) found))))
|
165
|
910 (if (not found)
|
|
911 (error "No customized user options")
|
|
912 (custom-buffer-create (custom-sort-items found t nil)
|
|
913 "*Customize Customized*"))))
|
149
|
914
|
|
915 ;;;###autoload
|
|
916 (defun customize-saved ()
|
|
917 "Customize all already saved user options."
|
28
|
918 (interactive)
|
|
919 (let ((found nil))
|
|
920 (mapatoms (lambda (symbol)
|
173
|
921 (and (get symbol 'saved-face)
|
28
|
922 (custom-facep symbol)
|
163
|
923 (push (list symbol 'custom-face) found))
|
28
|
924 (and (get symbol 'saved-value)
|
|
925 (boundp symbol)
|
163
|
926 (push (list symbol 'custom-variable) found))))
|
165
|
927 (if (not found )
|
|
928 (error "No saved user options")
|
|
929 (custom-buffer-create (custom-sort-items found t nil)
|
|
930 "*Customize Saved*"))))
|
28
|
931
|
|
932 ;;;###autoload
|
|
933 (defun customize-apropos (regexp &optional all)
|
|
934 "Customize all user options matching REGEXP.
|
163
|
935 If ALL is `options', include only options.
|
|
936 If ALL is `faces', include only faces.
|
|
937 If ALL is `groups', include only groups.
|
|
938 If ALL is t (interactively, with prefix arg), include options which are not
|
|
939 user-settable, as well as faces and groups."
|
28
|
940 (interactive "sCustomize regexp: \nP")
|
|
941 (let ((found nil))
|
|
942 (mapatoms (lambda (symbol)
|
|
943 (when (string-match regexp (symbol-name symbol))
|
163
|
944 (when (and (not (memq all '(faces options)))
|
|
945 (get symbol 'custom-group))
|
|
946 (push (list symbol 'custom-group) found))
|
|
947 (when (and (not (memq all '(options groups)))
|
|
948 (custom-facep symbol))
|
|
949 (push (list symbol 'custom-face) found))
|
|
950 (when (and (not (memq all '(groups faces)))
|
|
951 (boundp symbol)
|
28
|
952 (or (get symbol 'saved-value)
|
153
|
953 (get symbol 'standard-value)
|
163
|
954 (if (memq all '(nil options))
|
|
955 (user-variable-p symbol)
|
|
956 (get symbol 'variable-documentation))))
|
|
957 (push (list symbol 'custom-variable) found)))))
|
|
958 (if (not found)
|
|
959 (error "No matches")
|
165
|
960 (custom-buffer-create (custom-sort-items found t
|
|
961 custom-buffer-order-groups)
|
|
962 "*Customize Apropos*"))))
|
163
|
963
|
|
964 ;;;###autoload
|
|
965 (defun customize-apropos-options (regexp &optional arg)
|
|
966 "Customize all user options matching REGEXP.
|
|
967 With prefix arg, include options which are not user-settable."
|
|
968 (interactive "sCustomize regexp: \nP")
|
|
969 (customize-apropos regexp (or arg 'options)))
|
|
970
|
|
971 ;;;###autoload
|
|
972 (defun customize-apropos-faces (regexp)
|
|
973 "Customize all user faces matching REGEXP."
|
|
974 (interactive "sCustomize regexp: \n")
|
|
975 (customize-apropos regexp 'faces))
|
|
976
|
|
977 ;;;###autoload
|
|
978 (defun customize-apropos-groups (regexp)
|
|
979 "Customize all user groups matching REGEXP."
|
|
980 (interactive "sCustomize regexp: \n")
|
|
981 (customize-apropos regexp 'groups))
|
28
|
982
|
149
|
983 ;;; Buffer.
|
|
984
|
163
|
985 (defcustom custom-buffer-style 'links
|
|
986 "Control the presentation style for customization buffers.
|
|
987 The value should be a symbol, one of:
|
|
988
|
|
989 brackets: groups nest within each other with big horizontal brackets.
|
|
990 links: groups have links to subgroups."
|
|
991 :type '(radio (const brackets)
|
|
992 (const links))
|
|
993 :group 'custom-buffer)
|
|
994
|
|
995 (defcustom custom-buffer-indent 3
|
|
996 "Number of spaces to indent nested groups."
|
|
997 :type 'integer
|
|
998 :group 'custom-buffer)
|
|
999
|
28
|
1000 ;;;###autoload
|
173
|
1001 (defun custom-buffer-create (options &optional name description)
|
28
|
1002 "Create a buffer containing OPTIONS.
|
149
|
1003 Optional NAME is the name of the buffer.
|
28
|
1004 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
|
|
1005 SYMBOL is a customization option, and WIDGET is a widget for editing
|
|
1006 that option."
|
149
|
1007 (unless name (setq name "*Customization*"))
|
|
1008 (kill-buffer (get-buffer-create name))
|
|
1009 (switch-to-buffer (get-buffer-create name))
|
173
|
1010 (custom-buffer-create-internal options description))
|
124
|
1011
|
149
|
1012 ;;;###autoload
|
173
|
1013 (defun custom-buffer-create-other-window (options &optional name description)
|
124
|
1014 "Create a buffer containing OPTIONS.
|
149
|
1015 Optional NAME is the name of the buffer.
|
124
|
1016 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
|
|
1017 SYMBOL is a customization option, and WIDGET is a widget for editing
|
|
1018 that option."
|
149
|
1019 (unless name (setq name "*Customization*"))
|
|
1020 (kill-buffer (get-buffer-create name))
|
124
|
1021 (let ((window (selected-window)))
|
149
|
1022 (switch-to-buffer-other-window (get-buffer-create name))
|
173
|
1023 (custom-buffer-create-internal options description)
|
124
|
1024 (select-window window)))
|
155
|
1025
|
|
1026 (defcustom custom-reset-button-menu nil
|
|
1027 "If non-nil, only show a single reset button in customize buffers.
|
|
1028 This button will have a menu with all three reset operations."
|
|
1029 :type 'boolean
|
161
|
1030 :group 'custom-buffer)
|
124
|
1031
|
173
|
1032 (defun custom-buffer-create-internal (options &optional description)
|
124
|
1033 (message "Creating customization buffer...")
|
28
|
1034 (custom-mode)
|
173
|
1035 (widget-insert "This is a customization buffer")
|
|
1036 (if description
|
|
1037 (widget-insert description))
|
|
1038 (widget-insert ".
|
165
|
1039 Square brackets show active fields; type RET or click mouse-2
|
173
|
1040 on an active field to invoke its action. Editing an option value
|
|
1041 changes the text in the buffer; invoke the State button and
|
|
1042 choose the Set operation to set the option value.
|
|
1043 Invoke ")
|
28
|
1044 (widget-create 'info-link
|
165
|
1045 :tag "Help"
|
30
|
1046 :help-echo "Read the online help."
|
155
|
1047 "(emacs)Easy Customization")
|
28
|
1048 (widget-insert " for more information.\n\n")
|
153
|
1049 (message "Creating customization buttons...")
|
165
|
1050 (widget-insert "Operate on everything in this buffer:\n ")
|
153
|
1051 (widget-create 'push-button
|
173
|
1052 :tag "Set for Current Session"
|
165
|
1053 :help-echo "\
|
|
1054 Make your editing in this buffer take effect for this session."
|
153
|
1055 :action (lambda (widget &optional event)
|
165
|
1056 (Custom-set)))
|
153
|
1057 (widget-insert " ")
|
|
1058 (widget-create 'push-button
|
173
|
1059 :tag "Save for Future Sessions"
|
153
|
1060 :help-echo "\
|
165
|
1061 Make your editing in this buffer take effect for future Emacs sessions."
|
153
|
1062 :action (lambda (widget &optional event)
|
165
|
1063 (Custom-save)))
|
155
|
1064 (if custom-reset-button-menu
|
173
|
1065 (progn
|
|
1066 (widget-insert " ")
|
|
1067 (widget-create 'push-button
|
|
1068 :tag "Reset"
|
|
1069 :help-echo "Show a menu with reset operations."
|
|
1070 :mouse-down-action (lambda (&rest junk) t)
|
|
1071 :action (lambda (widget &optional event)
|
|
1072 (custom-reset event))))
|
|
1073 (widget-insert "\n ")
|
155
|
1074 (widget-create 'push-button
|
|
1075 :tag "Reset"
|
|
1076 :help-echo "\
|
165
|
1077 Reset all edited text in this buffer to reflect current values."
|
|
1078 :action 'Custom-reset-current)
|
155
|
1079 (widget-insert " ")
|
|
1080 (widget-create 'push-button
|
|
1081 :tag "Reset to Saved"
|
|
1082 :help-echo "\
|
165
|
1083 Reset all values in this buffer to their saved settings."
|
|
1084 :action 'Custom-reset-saved)
|
155
|
1085 (widget-insert " ")
|
|
1086 (widget-create 'push-button
|
|
1087 :tag "Reset to Standard"
|
|
1088 :help-echo "\
|
165
|
1089 Reset all values in this buffer to their standard settings."
|
|
1090 :action 'Custom-reset-standard))
|
|
1091 (widget-insert " ")
|
153
|
1092 (widget-create 'push-button
|
165
|
1093 :tag "Bury Buffer"
|
153
|
1094 :help-echo "Bury the buffer."
|
|
1095 :action (lambda (widget &optional event)
|
|
1096 (bury-buffer)))
|
|
1097 (widget-insert "\n\n")
|
|
1098 (message "Creating customization items...")
|
28
|
1099 (setq custom-options
|
120
|
1100 (if (= (length options) 1)
|
|
1101 (mapcar (lambda (entry)
|
|
1102 (widget-create (nth 1 entry)
|
157
|
1103 :documentation-shown t
|
120
|
1104 :custom-state 'unknown
|
|
1105 :tag (custom-unlispify-tag-name
|
|
1106 (nth 0 entry))
|
|
1107 :value (nth 0 entry)))
|
|
1108 options)
|
|
1109 (let ((count 0)
|
|
1110 (length (length options)))
|
|
1111 (mapcar (lambda (entry)
|
|
1112 (prog2
|
|
1113 (message "Creating customization items %2d%%..."
|
|
1114 (/ (* 100.0 count) length))
|
|
1115 (widget-create (nth 1 entry)
|
28
|
1116 :tag (custom-unlispify-tag-name
|
|
1117 (nth 0 entry))
|
|
1118 :value (nth 0 entry))
|
120
|
1119 (setq count (1+ count))
|
|
1120 (unless (eq (preceding-char) ?\n)
|
|
1121 (widget-insert "\n"))
|
|
1122 (widget-insert "\n")))
|
|
1123 options))))
|
|
1124 (unless (eq (preceding-char) ?\n)
|
|
1125 (widget-insert "\n"))
|
173
|
1126 (message "Creating customization items %2d%%...done" 100)
|
163
|
1127 (unless (eq custom-buffer-style 'tree)
|
|
1128 (mapcar 'custom-magic-reset custom-options))
|
120
|
1129 (message "Creating customization setup...")
|
30
|
1130 (widget-setup)
|
120
|
1131 (goto-char (point-min))
|
|
1132 (message "Creating customization buffer...done"))
|
28
|
1133
|
163
|
1134 ;;; The Tree Browser.
|
|
1135
|
|
1136 ;;;###autoload
|
165
|
1137 (defun customize-browse (group)
|
163
|
1138 "Create a tree browser for the customize hierarchy."
|
165
|
1139 (interactive (list (let ((completion-ignore-case t))
|
|
1140 (completing-read "Customize group: (default emacs) "
|
|
1141 obarray
|
|
1142 (lambda (symbol)
|
|
1143 (get symbol 'custom-group))
|
|
1144 t))))
|
|
1145
|
|
1146 (when (stringp group)
|
|
1147 (if (string-equal "" group)
|
|
1148 (setq group 'emacs)
|
|
1149 (setq group (intern group))))
|
163
|
1150 (let ((name "*Customize Browser*"))
|
|
1151 (kill-buffer (get-buffer-create name))
|
|
1152 (switch-to-buffer (get-buffer-create name)))
|
|
1153 (custom-mode)
|
|
1154 (widget-insert "\
|
173
|
1155 Invoke [+] or [?] below to expand items, and [-] to collapse items.\n")
|
|
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)))
|
28
|
1431 (lisp (eq (widget-get parent :custom-form) 'lisp))
|
|
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)))
|
|
1460 (when lisp
|
|
1461 (insert " (lisp)"))
|
|
1462 (put-text-property start (point) 'face 'custom-state-face))
|
28
|
1463 (insert "\n"))
|
165
|
1464 (when (and (eq category 'group)
|
|
1465 (not (and (eq custom-buffer-style 'links)
|
|
1466 (> (widget-get parent :custom-level) 1))))
|
163
|
1467 (insert-char ?\ (* custom-buffer-indent
|
|
1468 (widget-get parent :custom-level))))
|
28
|
1469 (when custom-magic-show-button
|
|
1470 (when custom-magic-show
|
|
1471 (let ((indent (widget-get parent :indent)))
|
|
1472 (when indent
|
|
1473 (insert-char ? indent))))
|
149
|
1474 (push (widget-create-child-and-convert
|
|
1475 widget 'choice-item
|
|
1476 :mouse-down-action 'widget-magic-mouse-down-action
|
|
1477 :button-face face
|
155
|
1478 :button-prefix ""
|
|
1479 :button-suffix ""
|
149
|
1480 :help-echo "Change the state."
|
155
|
1481 :format (if hidden "%t" "%[%t%]")
|
149
|
1482 :tag (if lisp
|
|
1483 (concat "(" magic ")")
|
|
1484 (concat "[" magic "]")))
|
28
|
1485 children)
|
|
1486 (insert " "))
|
|
1487 (widget-put widget :children children)))
|
|
1488
|
|
1489 (defun custom-magic-reset (widget)
|
|
1490 "Redraw the :custom-magic property of WIDGET."
|
|
1491 (let ((magic (widget-get widget :custom-magic)))
|
|
1492 (widget-value-set magic (widget-value magic))))
|
|
1493
|
|
1494 ;;; The `custom' Widget.
|
|
1495
|
165
|
1496 (defface custom-button-face nil
|
|
1497 "Face used for buttons in customization buffers."
|
|
1498 :group 'custom-faces)
|
|
1499
|
|
1500 (defface custom-documentation-face nil
|
|
1501 "Face used for documentation strings in customization buffers."
|
|
1502 :group 'custom-faces)
|
|
1503
|
|
1504 (defface custom-state-face '((((class color)
|
|
1505 (background dark))
|
|
1506 (:foreground "lime green"))
|
|
1507 (((class color)
|
|
1508 (background light))
|
|
1509 (:foreground "dark green"))
|
|
1510 (t nil))
|
|
1511 "Face used for State descriptions in the customize buffer."
|
|
1512 :group 'custom-faces)
|
|
1513
|
28
|
1514 (define-widget 'custom 'default
|
|
1515 "Customize a user option."
|
163
|
1516 :format "%v"
|
28
|
1517 :convert-widget 'custom-convert-widget
|
|
1518 :notify 'custom-notify
|
163
|
1519 :custom-prefix ""
|
28
|
1520 :custom-level 1
|
|
1521 :custom-state 'hidden
|
|
1522 :documentation-property 'widget-subclass-responsibility
|
|
1523 :value-create 'widget-subclass-responsibility
|
|
1524 :value-delete 'widget-children-value-delete
|
149
|
1525 :value-get 'widget-value-value-get
|
|
1526 :validate 'widget-children-validate
|
28
|
1527 :match (lambda (widget value) (symbolp value)))
|
|
1528
|
|
1529 (defun custom-convert-widget (widget)
|
|
1530 ;; Initialize :value and :tag from :args in WIDGET.
|
|
1531 (let ((args (widget-get widget :args)))
|
|
1532 (when args
|
|
1533 (widget-put widget :value (widget-apply widget
|
|
1534 :value-to-internal (car args)))
|
|
1535 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
|
|
1536 (widget-put widget :args nil)))
|
|
1537 widget)
|
|
1538
|
|
1539 (defun custom-notify (widget &rest args)
|
|
1540 "Keep track of changes."
|
155
|
1541 (let ((state (widget-get widget :custom-state)))
|
|
1542 (unless (eq state 'modified)
|
|
1543 (unless (memq state '(nil unknown hidden))
|
|
1544 (widget-put widget :custom-state 'modified))
|
|
1545 (custom-magic-reset widget)
|
|
1546 (apply 'widget-default-notify widget args))))
|
28
|
1547
|
|
1548 (defun custom-redraw (widget)
|
|
1549 "Redraw WIDGET with current settings."
|
149
|
1550 (let ((line (count-lines (point-min) (point)))
|
|
1551 (column (current-column))
|
|
1552 (pos (point))
|
28
|
1553 (from (marker-position (widget-get widget :from)))
|
|
1554 (to (marker-position (widget-get widget :to))))
|
|
1555 (save-excursion
|
|
1556 (widget-value-set widget (widget-value widget))
|
|
1557 (custom-redraw-magic widget))
|
|
1558 (when (and (>= pos from) (<= pos to))
|
149
|
1559 (condition-case nil
|
|
1560 (progn
|
|
1561 (if (> column 0)
|
|
1562 (goto-line line)
|
|
1563 (goto-line (1+ line)))
|
|
1564 (move-to-column column))
|
|
1565 (error nil)))))
|
28
|
1566
|
|
1567 (defun custom-redraw-magic (widget)
|
|
1568 "Redraw WIDGET state with current settings."
|
|
1569 (while widget
|
|
1570 (let ((magic (widget-get widget :custom-magic)))
|
163
|
1571 (cond (magic
|
|
1572 (widget-value-set magic (widget-value magic))
|
|
1573 (when (setq widget (widget-get widget :group))
|
|
1574 (custom-group-state-update widget)))
|
|
1575 (t
|
|
1576 (setq widget nil)))))
|
28
|
1577 (widget-setup))
|
|
1578
|
|
1579 (defun custom-show (widget value)
|
|
1580 "Non-nil if WIDGET should be shown with VALUE by default."
|
|
1581 (let ((show (widget-get widget :custom-show)))
|
|
1582 (cond ((null show)
|
|
1583 nil)
|
|
1584 ((eq t show)
|
|
1585 t)
|
|
1586 (t
|
|
1587 (funcall show widget value)))))
|
|
1588
|
124
|
1589 (defvar custom-load-recursion nil
|
|
1590 "Hack to avoid recursive dependencies.")
|
|
1591
|
28
|
1592 (defun custom-load-symbol (symbol)
|
|
1593 "Load all dependencies for SYMBOL."
|
124
|
1594 (unless custom-load-recursion
|
|
1595 (let ((custom-load-recursion t)
|
|
1596 (loads (get symbol 'custom-loads))
|
|
1597 load)
|
|
1598 (while loads
|
|
1599 (setq load (car loads)
|
|
1600 loads (cdr loads))
|
|
1601 (cond ((symbolp load)
|
|
1602 (condition-case nil
|
|
1603 (require load)
|
|
1604 (error nil)))
|
155
|
1605 ;; Don't reload a file already loaded.
|
124
|
1606 ((assoc load load-history))
|
155
|
1607 ((assoc (locate-library load) load-history))
|
124
|
1608 (t
|
|
1609 (condition-case nil
|
155
|
1610 ;; Without this, we would load cus-edit recursively.
|
|
1611 ;; We are still loading it when we call this,
|
|
1612 ;; and it is not in load-history yet.
|
|
1613 (or (equal load "cus-edit")
|
|
1614 (load-library load))
|
124
|
1615 (error nil))))))))
|
28
|
1616
|
|
1617 (defun custom-load-widget (widget)
|
|
1618 "Load all dependencies for WIDGET."
|
|
1619 (custom-load-symbol (widget-value widget)))
|
|
1620
|
167
|
1621 (defun custom-unloaded-symbol-p (symbol)
|
|
1622 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
|
|
1623 (let ((found nil)
|
|
1624 (loads (get symbol 'custom-loads))
|
|
1625 load)
|
|
1626 (while loads
|
|
1627 (setq load (car loads)
|
|
1628 loads (cdr loads))
|
|
1629 (cond ((symbolp load)
|
|
1630 (unless (featurep load)
|
|
1631 (setq found t)))
|
|
1632 ((assoc load load-history))
|
|
1633 ((assoc (locate-library load) load-history)
|
|
1634 (message nil))
|
|
1635 (t
|
|
1636 (setq found t))))
|
|
1637 found))
|
|
1638
|
|
1639 (defun custom-unloaded-widget-p (widget)
|
|
1640 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
|
|
1641 (custom-unloaded-symbol-p (widget-value widget)))
|
|
1642
|
149
|
1643 (defun custom-toggle-hide (widget)
|
|
1644 "Toggle visibility of WIDGET."
|
167
|
1645 (custom-load-widget widget)
|
149
|
1646 (let ((state (widget-get widget :custom-state)))
|
|
1647 (cond ((memq state '(invalid modified))
|
|
1648 (error "There are unset changes"))
|
|
1649 ((eq state 'hidden)
|
|
1650 (widget-put widget :custom-state 'unknown))
|
|
1651 (t
|
155
|
1652 (widget-put widget :documentation-shown nil)
|
149
|
1653 (widget-put widget :custom-state 'hidden)))
|
163
|
1654 (custom-redraw widget)
|
|
1655 (widget-setup)))
|
149
|
1656
|
155
|
1657 (defun custom-toggle-parent (widget &rest ignore)
|
165
|
1658 "Toggle visibility of parent of WIDGET."
|
155
|
1659 (custom-toggle-hide (widget-get widget :parent)))
|
|
1660
|
163
|
1661 (defun custom-add-see-also (widget &optional prefix)
|
|
1662 "Add `See also ...' to WIDGET if there are any links.
|
|
1663 Insert PREFIX first if non-nil."
|
|
1664 (let* ((symbol (widget-get widget :value))
|
|
1665 (links (get symbol 'custom-links))
|
|
1666 (many (> (length links) 2))
|
|
1667 (buttons (widget-get widget :buttons))
|
|
1668 (indent (widget-get widget :indent)))
|
|
1669 (when links
|
|
1670 (when indent
|
|
1671 (insert-char ?\ indent))
|
|
1672 (when prefix
|
|
1673 (insert prefix))
|
|
1674 (insert "See also ")
|
|
1675 (while links
|
|
1676 (push (widget-create-child-and-convert widget (car links))
|
|
1677 buttons)
|
|
1678 (setq links (cdr links))
|
|
1679 (cond ((null links)
|
|
1680 (insert ".\n"))
|
|
1681 ((null (cdr links))
|
|
1682 (if many
|
|
1683 (insert ", and ")
|
|
1684 (insert " and ")))
|
|
1685 (t
|
|
1686 (insert ", "))))
|
|
1687 (widget-put widget :buttons buttons))))
|
|
1688
|
165
|
1689 (defun custom-add-parent-links (widget &optional initial-string)
|
|
1690 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
|
|
1691 The value if non-nil if any parents were found.
|
|
1692 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
|
163
|
1693 (let ((name (widget-value widget))
|
|
1694 (type (widget-type widget))
|
|
1695 (buttons (widget-get widget :buttons))
|
165
|
1696 (start (point))
|
163
|
1697 found)
|
165
|
1698 (insert (or initial-string "Parent groups:"))
|
163
|
1699 (mapatoms (lambda (symbol)
|
173
|
1700 (let ((entry (assq name (get symbol 'custom-group))))
|
165
|
1701 (when (eq (nth 1 entry) type)
|
|
1702 (insert " ")
|
|
1703 (push (widget-create-child-and-convert
|
|
1704 widget 'custom-group-link
|
|
1705 :tag (custom-unlispify-tag-name symbol)
|
|
1706 symbol)
|
|
1707 buttons)
|
|
1708 (setq found t)))))
|
163
|
1709 (widget-put widget :buttons buttons)
|
165
|
1710 (if found
|
|
1711 (insert "\n")
|
|
1712 (delete-region start (point)))
|
|
1713 found))
|
163
|
1714
|
28
|
1715 ;;; The `custom-variable' Widget.
|
|
1716
|
165
|
1717 (defface custom-variable-tag-face '((((class color)
|
|
1718 (background dark))
|
|
1719 (:foreground "light blue" :underline t))
|
|
1720 (((class color)
|
|
1721 (background light))
|
|
1722 (:foreground "blue" :underline t))
|
|
1723 (t (:underline t)))
|
28
|
1724 "Face used for unpushable variable tags."
|
124
|
1725 :group 'custom-faces)
|
28
|
1726
|
|
1727 (defface custom-variable-button-face '((t (:underline t :bold t)))
|
|
1728 "Face used for pushable variable tags."
|
124
|
1729 :group 'custom-faces)
|
28
|
1730
|
|
1731 (define-widget 'custom-variable 'custom
|
|
1732 "Customize variable."
|
163
|
1733 :format "%v"
|
30
|
1734 :help-echo "Set or reset this variable."
|
28
|
1735 :documentation-property 'variable-documentation
|
155
|
1736 :custom-category 'option
|
28
|
1737 :custom-state nil
|
|
1738 :custom-menu 'custom-variable-menu-create
|
|
1739 :custom-form 'edit
|
|
1740 :value-create 'custom-variable-value-create
|
|
1741 :action 'custom-variable-action
|
|
1742 :custom-set 'custom-variable-set
|
|
1743 :custom-save 'custom-variable-save
|
|
1744 :custom-reset-current 'custom-redraw
|
|
1745 :custom-reset-saved 'custom-variable-reset-saved
|
153
|
1746 :custom-reset-standard 'custom-variable-reset-standard)
|
28
|
1747
|
120
|
1748 (defun custom-variable-type (symbol)
|
|
1749 "Return a widget suitable for editing the value of SYMBOL.
|
|
1750 If SYMBOL has a `custom-type' property, use that.
|
|
1751 Otherwise, look up symbol in `custom-guess-type-alist'."
|
|
1752 (let* ((type (or (get symbol 'custom-type)
|
153
|
1753 (and (not (get symbol 'standard-value))
|
124
|
1754 (custom-guess-type symbol))
|
120
|
1755 'sexp))
|
|
1756 (options (get symbol 'custom-options))
|
|
1757 (tmp (if (listp type)
|
149
|
1758 (copy-sequence type)
|
120
|
1759 (list type))))
|
|
1760 (when options
|
|
1761 (widget-put tmp :options options))
|
|
1762 tmp))
|
|
1763
|
28
|
1764 (defun custom-variable-value-create (widget)
|
|
1765 "Here is where you edit the variables value."
|
|
1766 (custom-load-widget widget)
|
|
1767 (let* ((buttons (widget-get widget :buttons))
|
|
1768 (children (widget-get widget :children))
|
|
1769 (form (widget-get widget :custom-form))
|
|
1770 (state (widget-get widget :custom-state))
|
|
1771 (symbol (widget-get widget :value))
|
|
1772 (tag (widget-get widget :tag))
|
120
|
1773 (type (custom-variable-type symbol))
|
28
|
1774 (conv (widget-convert type))
|
149
|
1775 (get (or (get symbol 'custom-get) 'default-value))
|
163
|
1776 (prefix (widget-get widget :custom-prefix))
|
|
1777 (last (widget-get widget :custom-last))
|
28
|
1778 (value (if (default-boundp symbol)
|
149
|
1779 (funcall get symbol)
|
28
|
1780 (widget-get conv :value))))
|
|
1781 ;; If the widget is new, the child determine whether it is hidden.
|
|
1782 (cond (state)
|
|
1783 ((custom-show type value)
|
|
1784 (setq state 'unknown))
|
|
1785 (t
|
|
1786 (setq state 'hidden)))
|
|
1787 ;; If we don't know the state, see if we need to edit it in lisp form.
|
|
1788 (when (eq state 'unknown)
|
|
1789 (unless (widget-apply conv :match value)
|
|
1790 ;; (widget-apply (widget-convert type) :match value)
|
|
1791 (setq form 'lisp)))
|
|
1792 ;; Now we can create the child widget.
|
163
|
1793 (cond ((eq custom-buffer-style 'tree)
|
|
1794 (insert prefix (if last " `--- " " |--- "))
|
|
1795 (push (widget-create-child-and-convert
|
167
|
1796 widget 'custom-browse-variable-tag)
|
163
|
1797 buttons)
|
|
1798 (insert " " tag "\n")
|
|
1799 (widget-put widget :buttons buttons))
|
|
1800 ((eq state 'hidden)
|
28
|
1801 ;; Indicate hidden value.
|
|
1802 (push (widget-create-child-and-convert
|
|
1803 widget 'item
|
155
|
1804 :format "%{%t%}: "
|
165
|
1805 :sample-face 'custom-variable-tag-face
|
28
|
1806 :tag tag
|
|
1807 :parent widget)
|
155
|
1808 buttons)
|
|
1809 (push (widget-create-child-and-convert
|
|
1810 widget 'visibility
|
163
|
1811 :help-echo "Show the value of this option."
|
155
|
1812 :action 'custom-toggle-parent
|
|
1813 nil)
|
|
1814 buttons))
|
28
|
1815 ((eq form 'lisp)
|
|
1816 ;; In lisp mode edit the saved value when possible.
|
|
1817 (let* ((value (cond ((get symbol 'saved-value)
|
|
1818 (car (get symbol 'saved-value)))
|
153
|
1819 ((get symbol 'standard-value)
|
|
1820 (car (get symbol 'standard-value)))
|
28
|
1821 ((default-boundp symbol)
|
149
|
1822 (custom-quote (funcall get symbol)))
|
28
|
1823 (t
|
|
1824 (custom-quote (widget-get conv :value))))))
|
155
|
1825 (insert (symbol-name symbol) ": ")
|
|
1826 (push (widget-create-child-and-convert
|
163
|
1827 widget 'visibility
|
|
1828 :help-echo "Hide the value of this option."
|
|
1829 :action 'custom-toggle-parent
|
|
1830 t)
|
|
1831 buttons)
|
155
|
1832 (insert " ")
|
28
|
1833 (push (widget-create-child-and-convert
|
|
1834 widget 'sexp
|
|
1835 :button-face 'custom-variable-button-face
|
155
|
1836 :format "%v"
|
28
|
1837 :tag (symbol-name symbol)
|
|
1838 :parent widget
|
|
1839 :value value)
|
|
1840 children)))
|
|
1841 (t
|
|
1842 ;; Edit mode.
|
155
|
1843 (let* ((format (widget-get type :format))
|
|
1844 tag-format value-format)
|
|
1845 (unless (string-match ":" format)
|
|
1846 (error "Bad format."))
|
|
1847 (setq tag-format (substring format 0 (match-end 0)))
|
|
1848 (setq value-format (substring format (match-end 0)))
|
|
1849 (push (widget-create-child-and-convert
|
|
1850 widget 'item
|
|
1851 :format tag-format
|
|
1852 :action 'custom-tag-action
|
163
|
1853 :help-echo "Change value of this option."
|
155
|
1854 :mouse-down-action 'custom-tag-mouse-down-action
|
|
1855 :button-face 'custom-variable-button-face
|
165
|
1856 :sample-face 'custom-variable-tag-face
|
155
|
1857 tag)
|
|
1858 buttons)
|
|
1859 (insert " ")
|
|
1860 (push (widget-create-child-and-convert
|
|
1861 widget 'visibility
|
163
|
1862 :help-echo "Hide the value of this option."
|
155
|
1863 :action 'custom-toggle-parent
|
|
1864 t)
|
|
1865 buttons)
|
|
1866 (push (widget-create-child-and-convert
|
|
1867 widget type
|
|
1868 :format value-format
|
|
1869 :value value)
|
|
1870 children))))
|
163
|
1871 (unless (eq custom-buffer-style 'tree)
|
|
1872 ;; Now update the state.
|
|
1873 (unless (eq (preceding-char) ?\n)
|
|
1874 (widget-insert "\n"))
|
|
1875 (if (eq state 'hidden)
|
|
1876 (widget-put widget :custom-state state)
|
|
1877 (custom-variable-state-set widget))
|
|
1878 ;; Create the magic button.
|
|
1879 (let ((magic (widget-create-child-and-convert
|
|
1880 widget 'custom-magic nil)))
|
|
1881 (widget-put widget :custom-magic magic)
|
|
1882 (push magic buttons))
|
|
1883 ;; Update properties.
|
|
1884 (widget-put widget :custom-form form)
|
|
1885 (widget-put widget :buttons buttons)
|
|
1886 (widget-put widget :children children)
|
|
1887 ;; Insert documentation.
|
|
1888 (widget-default-format-handler widget ?h)
|
|
1889 ;; See also.
|
|
1890 (unless (eq state 'hidden)
|
|
1891 (when (eq (widget-get widget :custom-level) 1)
|
|
1892 (custom-add-parent-links widget))
|
|
1893 (custom-add-see-also widget)))))
|
28
|
1894
|
155
|
1895 (defun custom-tag-action (widget &rest args)
|
|
1896 "Pass :action to first child of WIDGET's parent."
|
|
1897 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
|
|
1898 :action args))
|
|
1899
|
|
1900 (defun custom-tag-mouse-down-action (widget &rest args)
|
|
1901 "Pass :mouse-down-action to first child of WIDGET's parent."
|
|
1902 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
|
|
1903 :mouse-down-action args))
|
|
1904
|
28
|
1905 (defun custom-variable-state-set (widget)
|
|
1906 "Set the state of WIDGET."
|
|
1907 (let* ((symbol (widget-value widget))
|
149
|
1908 (get (or (get symbol 'custom-get) 'default-value))
|
28
|
1909 (value (if (default-boundp symbol)
|
149
|
1910 (funcall get symbol)
|
28
|
1911 (widget-get widget :value)))
|
|
1912 tmp
|
|
1913 (state (cond ((setq tmp (get symbol 'customized-value))
|
|
1914 (if (condition-case nil
|
|
1915 (equal value (eval (car tmp)))
|
|
1916 (error nil))
|
|
1917 'set
|
|
1918 'changed))
|
|
1919 ((setq tmp (get symbol 'saved-value))
|
|
1920 (if (condition-case nil
|
|
1921 (equal value (eval (car tmp)))
|
|
1922 (error nil))
|
|
1923 'saved
|
|
1924 'changed))
|
153
|
1925 ((setq tmp (get symbol 'standard-value))
|
28
|
1926 (if (condition-case nil
|
|
1927 (equal value (eval (car tmp)))
|
|
1928 (error nil))
|
153
|
1929 'standard
|
28
|
1930 'changed))
|
|
1931 (t 'rogue))))
|
|
1932 (widget-put widget :custom-state state)))
|
|
1933
|
|
1934 (defvar custom-variable-menu
|
173
|
1935 '(("Set for Current Session" custom-variable-set
|
149
|
1936 (lambda (widget)
|
|
1937 (eq (widget-get widget :custom-state) 'modified)))
|
173
|
1938 ("Save for Future Sessions" custom-variable-save
|
149
|
1939 (lambda (widget)
|
|
1940 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
|
|
1941 ("Reset to Current" custom-redraw
|
|
1942 (lambda (widget)
|
|
1943 (and (default-boundp (widget-value widget))
|
|
1944 (memq (widget-get widget :custom-state) '(modified changed)))))
|
|
1945 ("Reset to Saved" custom-variable-reset-saved
|
|
1946 (lambda (widget)
|
|
1947 (and (get (widget-value widget) 'saved-value)
|
|
1948 (memq (widget-get widget :custom-state)
|
|
1949 '(modified set changed rogue)))))
|
153
|
1950 ("Reset to Standard Settings" custom-variable-reset-standard
|
149
|
1951 (lambda (widget)
|
153
|
1952 (and (get (widget-value widget) 'standard-value)
|
149
|
1953 (memq (widget-get widget :custom-state)
|
163
|
1954 '(modified set changed saved rogue)))))
|
|
1955 ("---" ignore ignore)
|
|
1956 ("Don't show as Lisp expression" custom-variable-edit
|
|
1957 (lambda (widget)
|
|
1958 (not (eq (widget-get widget :custom-form) 'edit))))
|
|
1959 ("Show as Lisp expression" custom-variable-edit-lisp
|
|
1960 (lambda (widget)
|
|
1961 (not (eq (widget-get widget :custom-form) 'lisp)))))
|
28
|
1962 "Alist of actions for the `custom-variable' widget.
|
149
|
1963 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
1964 the menu entry, ACTION is the function to call on the widget when the
|
|
1965 menu is selected, and FILTER is a predicate which takes a `custom-variable'
|
|
1966 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
1967 widget. If FILTER is nil, ACTION is always valid.")
|
28
|
1968
|
|
1969 (defun custom-variable-action (widget &optional event)
|
|
1970 "Show the menu for `custom-variable' WIDGET.
|
|
1971 Optional EVENT is the location for the menu."
|
|
1972 (if (eq (widget-get widget :custom-state) 'hidden)
|
149
|
1973 (custom-toggle-hide widget)
|
|
1974 (unless (eq (widget-get widget :custom-state) 'modified)
|
|
1975 (custom-variable-state-set widget))
|
|
1976 (custom-redraw-magic widget)
|
28
|
1977 (let* ((completion-ignore-case t)
|
155
|
1978 (answer (widget-choose (concat "Operation on "
|
|
1979 (custom-unlispify-tag-name
|
|
1980 (widget-get widget :value)))
|
149
|
1981 (custom-menu-filter custom-variable-menu
|
|
1982 widget)
|
28
|
1983 event)))
|
|
1984 (if answer
|
|
1985 (funcall answer widget)))))
|
|
1986
|
|
1987 (defun custom-variable-edit (widget)
|
|
1988 "Edit value of WIDGET."
|
|
1989 (widget-put widget :custom-state 'unknown)
|
|
1990 (widget-put widget :custom-form 'edit)
|
|
1991 (custom-redraw widget))
|
|
1992
|
|
1993 (defun custom-variable-edit-lisp (widget)
|
|
1994 "Edit the lisp representation of the value of WIDGET."
|
|
1995 (widget-put widget :custom-state 'unknown)
|
|
1996 (widget-put widget :custom-form 'lisp)
|
|
1997 (custom-redraw widget))
|
|
1998
|
|
1999 (defun custom-variable-set (widget)
|
|
2000 "Set the current value for the variable being edited by WIDGET."
|
149
|
2001 (let* ((form (widget-get widget :custom-form))
|
|
2002 (state (widget-get widget :custom-state))
|
|
2003 (child (car (widget-get widget :children)))
|
|
2004 (symbol (widget-value widget))
|
|
2005 (set (or (get symbol 'custom-set) 'set-default))
|
|
2006 val)
|
28
|
2007 (cond ((eq state 'hidden)
|
|
2008 (error "Cannot set hidden variable."))
|
|
2009 ((setq val (widget-apply child :validate))
|
|
2010 (goto-char (widget-get val :from))
|
|
2011 (error "%s" (widget-get val :error)))
|
|
2012 ((eq form 'lisp)
|
149
|
2013 (funcall set symbol (eval (setq val (widget-value child))))
|
28
|
2014 (put symbol 'customized-value (list val)))
|
|
2015 (t
|
149
|
2016 (funcall set symbol (setq val (widget-value child)))
|
28
|
2017 (put symbol 'customized-value (list (custom-quote val)))))
|
|
2018 (custom-variable-state-set widget)
|
|
2019 (custom-redraw-magic widget)))
|
|
2020
|
|
2021 (defun custom-variable-save (widget)
|
|
2022 "Set the default value for the variable being edited by WIDGET."
|
149
|
2023 (let* ((form (widget-get widget :custom-form))
|
|
2024 (state (widget-get widget :custom-state))
|
|
2025 (child (car (widget-get widget :children)))
|
|
2026 (symbol (widget-value widget))
|
|
2027 (set (or (get symbol 'custom-set) 'set-default))
|
|
2028 val)
|
28
|
2029 (cond ((eq state 'hidden)
|
|
2030 (error "Cannot set hidden variable."))
|
|
2031 ((setq val (widget-apply child :validate))
|
|
2032 (goto-char (widget-get val :from))
|
|
2033 (error "%s" (widget-get val :error)))
|
|
2034 ((eq form 'lisp)
|
|
2035 (put symbol 'saved-value (list (widget-value child)))
|
149
|
2036 (funcall set symbol (eval (widget-value child))))
|
28
|
2037 (t
|
|
2038 (put symbol
|
|
2039 'saved-value (list (custom-quote (widget-value
|
|
2040 child))))
|
149
|
2041 (funcall set symbol (widget-value child))))
|
28
|
2042 (put symbol 'customized-value nil)
|
|
2043 (custom-save-all)
|
|
2044 (custom-variable-state-set widget)
|
|
2045 (custom-redraw-magic widget)))
|
|
2046
|
|
2047 (defun custom-variable-reset-saved (widget)
|
|
2048 "Restore the saved value for the variable being edited by WIDGET."
|
149
|
2049 (let* ((symbol (widget-value widget))
|
|
2050 (set (or (get symbol 'custom-set) 'set-default)))
|
28
|
2051 (if (get symbol 'saved-value)
|
|
2052 (condition-case nil
|
149
|
2053 (funcall set symbol (eval (car (get symbol 'saved-value))))
|
28
|
2054 (error nil))
|
|
2055 (error "No saved value for %s" symbol))
|
|
2056 (put symbol 'customized-value nil)
|
|
2057 (widget-put widget :custom-state 'unknown)
|
|
2058 (custom-redraw widget)))
|
|
2059
|
153
|
2060 (defun custom-variable-reset-standard (widget)
|
|
2061 "Restore the standard setting for the variable being edited by WIDGET."
|
149
|
2062 (let* ((symbol (widget-value widget))
|
|
2063 (set (or (get symbol 'custom-set) 'set-default)))
|
153
|
2064 (if (get symbol 'standard-value)
|
|
2065 (funcall set symbol (eval (car (get symbol 'standard-value))))
|
|
2066 (error "No standard setting known for %S" symbol))
|
28
|
2067 (put symbol 'customized-value nil)
|
|
2068 (when (get symbol 'saved-value)
|
|
2069 (put symbol 'saved-value nil)
|
|
2070 (custom-save-all))
|
|
2071 (widget-put widget :custom-state 'unknown)
|
|
2072 (custom-redraw widget)))
|
|
2073
|
|
2074 ;;; The `custom-face-edit' Widget.
|
|
2075
|
|
2076 (define-widget 'custom-face-edit 'checklist
|
|
2077 "Edit face attributes."
|
|
2078 :format "%t: %v"
|
|
2079 :tag "Attributes"
|
|
2080 :extra-offset 12
|
30
|
2081 :button-args '(:help-echo "Control whether this attribute have any effect.")
|
28
|
2082 :args (mapcar (lambda (att)
|
|
2083 (list 'group
|
|
2084 :inline t
|
30
|
2085 :sibling-args (widget-get (nth 1 att) :sibling-args)
|
28
|
2086 (list 'const :format "" :value (nth 0 att))
|
|
2087 (nth 1 att)))
|
|
2088 custom-face-attributes))
|
|
2089
|
|
2090 ;;; The `custom-display' Widget.
|
|
2091
|
|
2092 (define-widget 'custom-display 'menu-choice
|
|
2093 "Select a display type."
|
|
2094 :tag "Display"
|
|
2095 :value t
|
30
|
2096 :help-echo "Specify frames where the face attributes should be used."
|
28
|
2097 :args '((const :tag "all" t)
|
30
|
2098 (checklist
|
|
2099 :offset 0
|
|
2100 :extra-offset 9
|
|
2101 :args ((group :sibling-args (:help-echo "\
|
|
2102 Only match the specified window systems.")
|
|
2103 (const :format "Type: "
|
|
2104 type)
|
|
2105 (checklist :inline t
|
|
2106 :offset 0
|
|
2107 (const :format "X "
|
|
2108 :sibling-args (:help-echo "\
|
|
2109 The X11 Window System.")
|
|
2110 x)
|
|
2111 (const :format "PM "
|
|
2112 :sibling-args (:help-echo "\
|
|
2113 OS/2 Presentation Manager.")
|
|
2114 pm)
|
|
2115 (const :format "Win32 "
|
|
2116 :sibling-args (:help-echo "\
|
|
2117 Windows NT/95/97.")
|
|
2118 win32)
|
|
2119 (const :format "DOS "
|
|
2120 :sibling-args (:help-echo "\
|
|
2121 Plain MS-DOS.")
|
|
2122 pc)
|
|
2123 (const :format "TTY%n"
|
|
2124 :sibling-args (:help-echo "\
|
|
2125 Plain text terminals.")
|
|
2126 tty)))
|
|
2127 (group :sibling-args (:help-echo "\
|
|
2128 Only match the frames with the specified color support.")
|
|
2129 (const :format "Class: "
|
|
2130 class)
|
|
2131 (checklist :inline t
|
|
2132 :offset 0
|
|
2133 (const :format "Color "
|
|
2134 :sibling-args (:help-echo "\
|
|
2135 Match color frames.")
|
|
2136 color)
|
|
2137 (const :format "Grayscale "
|
|
2138 :sibling-args (:help-echo "\
|
|
2139 Match grayscale frames.")
|
|
2140 grayscale)
|
|
2141 (const :format "Monochrome%n"
|
|
2142 :sibling-args (:help-echo "\
|
|
2143 Match frames with no color support.")
|
|
2144 mono)))
|
|
2145 (group :sibling-args (:help-echo "\
|
|
2146 Only match frames with the specified intensity.")
|
|
2147 (const :format "\
|
|
2148 Background brightness: "
|
|
2149 background)
|
|
2150 (checklist :inline t
|
|
2151 :offset 0
|
|
2152 (const :format "Light "
|
|
2153 :sibling-args (:help-echo "\
|
|
2154 Match frames with light backgrounds.")
|
|
2155 light)
|
|
2156 (const :format "Dark\n"
|
|
2157 :sibling-args (:help-echo "\
|
|
2158 Match frames with dark backgrounds.")
|
|
2159 dark)))))))
|
28
|
2160
|
|
2161 ;;; The `custom-face' Widget.
|
|
2162
|
|
2163 (defface custom-face-tag-face '((t (:underline t)))
|
|
2164 "Face used for face tags."
|
124
|
2165 :group 'custom-faces)
|
28
|
2166
|
|
2167 (define-widget 'custom-face 'custom
|
|
2168 "Customize face."
|
|
2169 :sample-face 'custom-face-tag-face
|
30
|
2170 :help-echo "Set or reset this face."
|
28
|
2171 :documentation-property '(lambda (face)
|
30
|
2172 (face-doc-string face))
|
28
|
2173 :value-create 'custom-face-value-create
|
|
2174 :action 'custom-face-action
|
155
|
2175 :custom-category 'face
|
120
|
2176 :custom-form 'selected
|
28
|
2177 :custom-set 'custom-face-set
|
|
2178 :custom-save 'custom-face-save
|
|
2179 :custom-reset-current 'custom-redraw
|
|
2180 :custom-reset-saved 'custom-face-reset-saved
|
153
|
2181 :custom-reset-standard 'custom-face-reset-standard
|
28
|
2182 :custom-menu 'custom-face-menu-create)
|
|
2183
|
120
|
2184 (define-widget 'custom-face-all 'editable-list
|
|
2185 "An editable list of display specifications and attributes."
|
|
2186 :entry-format "%i %d %v"
|
|
2187 :insert-button-args '(:help-echo "Insert new display specification here.")
|
|
2188 :append-button-args '(:help-echo "Append new display specification here.")
|
|
2189 :delete-button-args '(:help-echo "Delete this display specification.")
|
|
2190 :args '((group :format "%v" custom-display custom-face-edit)))
|
|
2191
|
|
2192 (defconst custom-face-all (widget-convert 'custom-face-all)
|
|
2193 "Converted version of the `custom-face-all' widget.")
|
|
2194
|
|
2195 (define-widget 'custom-display-unselected 'item
|
|
2196 "A display specification that doesn't match the selected display."
|
|
2197 :match 'custom-display-unselected-match)
|
|
2198
|
|
2199 (defun custom-display-unselected-match (widget value)
|
|
2200 "Non-nil if VALUE is an unselected display specification."
|
149
|
2201 (not (face-spec-set-match-display value (selected-frame))))
|
120
|
2202
|
|
2203 (define-widget 'custom-face-selected 'group
|
|
2204 "Edit the attributes of the selected display in a face specification."
|
|
2205 :args '((repeat :format ""
|
|
2206 :inline t
|
|
2207 (group custom-display-unselected sexp))
|
|
2208 (group (sexp :format "") custom-face-edit)
|
|
2209 (repeat :format ""
|
|
2210 :inline t
|
|
2211 sexp)))
|
|
2212
|
|
2213 (defconst custom-face-selected (widget-convert 'custom-face-selected)
|
|
2214 "Converted version of the `custom-face-selected' widget.")
|
|
2215
|
28
|
2216 (defun custom-face-value-create (widget)
|
163
|
2217 "Create a list of the display specifications for WIDGET."
|
|
2218 (let ((buttons (widget-get widget :buttons))
|
|
2219 (symbol (widget-get widget :value))
|
|
2220 (tag (widget-get widget :tag))
|
|
2221 (state (widget-get widget :custom-state))
|
|
2222 (begin (point))
|
|
2223 (is-last (widget-get widget :custom-last))
|
|
2224 (prefix (widget-get widget :custom-prefix)))
|
|
2225 (unless tag
|
|
2226 (setq tag (prin1-to-string symbol)))
|
|
2227 (cond ((eq custom-buffer-style 'tree)
|
|
2228 (insert prefix (if is-last " `--- " " |--- "))
|
|
2229 (push (widget-create-child-and-convert
|
167
|
2230 widget 'custom-browse-face-tag)
|
163
|
2231 buttons)
|
|
2232 (insert " " tag "\n")
|
|
2233 (widget-put widget :buttons buttons))
|
|
2234 (t
|
|
2235 ;; Create tag.
|
|
2236 (insert tag)
|
|
2237 (if (eq custom-buffer-style 'face)
|
|
2238 (insert " ")
|
|
2239 (widget-specify-sample widget begin (point))
|
|
2240 (insert ": "))
|
|
2241 ;; Sample.
|
|
2242 (and (string-match "XEmacs" emacs-version)
|
|
2243 ;; XEmacs cannot display uninitialized faces.
|
|
2244 (not (custom-facep symbol))
|
|
2245 (copy-face 'custom-face-empty symbol))
|
|
2246 (push (widget-create-child-and-convert widget 'item
|
|
2247 :format "(%{%t%})"
|
|
2248 :sample-face symbol
|
|
2249 :tag "sample")
|
|
2250 buttons)
|
|
2251 ;; Visibility.
|
|
2252 (insert " ")
|
|
2253 (push (widget-create-child-and-convert
|
|
2254 widget 'visibility
|
|
2255 :help-echo "Hide or show this face."
|
|
2256 :action 'custom-toggle-parent
|
|
2257 (not (eq state 'hidden)))
|
|
2258 buttons)
|
|
2259 ;; Magic.
|
|
2260 (insert "\n")
|
|
2261 (let ((magic (widget-create-child-and-convert
|
|
2262 widget 'custom-magic nil)))
|
|
2263 (widget-put widget :custom-magic magic)
|
|
2264 (push magic buttons))
|
|
2265 ;; Update buttons.
|
|
2266 (widget-put widget :buttons buttons)
|
|
2267 ;; Insert documentation.
|
|
2268 (widget-default-format-handler widget ?h)
|
|
2269 ;; See also.
|
|
2270 (unless (eq state 'hidden)
|
|
2271 (when (eq (widget-get widget :custom-level) 1)
|
|
2272 (custom-add-parent-links widget))
|
|
2273 (custom-add-see-also widget))
|
|
2274 ;; Editor.
|
|
2275 (unless (eq (preceding-char) ?\n)
|
|
2276 (insert "\n"))
|
|
2277 (unless (eq state 'hidden)
|
|
2278 (message "Creating face editor...")
|
|
2279 (custom-load-widget widget)
|
|
2280 (let* ((symbol (widget-value widget))
|
|
2281 (spec (or (get symbol 'saved-face)
|
|
2282 (get symbol 'face-defface-spec)
|
|
2283 ;; Attempt to construct it.
|
|
2284 (list (list t (custom-face-attributes-get
|
|
2285 symbol (selected-frame))))))
|
|
2286 (form (widget-get widget :custom-form))
|
|
2287 (indent (widget-get widget :indent))
|
|
2288 (edit (widget-create-child-and-convert
|
|
2289 widget
|
|
2290 (cond ((and (eq form 'selected)
|
|
2291 (widget-apply custom-face-selected
|
|
2292 :match spec))
|
|
2293 (when indent (insert-char ?\ indent))
|
|
2294 'custom-face-selected)
|
|
2295 ((and (not (eq form 'lisp))
|
|
2296 (widget-apply custom-face-all
|
|
2297 :match spec))
|
|
2298 'custom-face-all)
|
|
2299 (t
|
|
2300 (when indent (insert-char ?\ indent))
|
|
2301 'sexp))
|
|
2302 :value spec)))
|
|
2303 (custom-face-state-set widget)
|
|
2304 (widget-put widget :children (list edit)))
|
|
2305 (message "Creating face editor...done"))))))
|
28
|
2306
|
|
2307 (defvar custom-face-menu
|
173
|
2308 '(("Set for Current Session" custom-face-set)
|
|
2309 ("Save for Future Sessions" custom-face-save)
|
149
|
2310 ("Reset to Saved" custom-face-reset-saved
|
|
2311 (lambda (widget)
|
|
2312 (get (widget-value widget) 'saved-face)))
|
153
|
2313 ("Reset to Standard Setting" custom-face-reset-standard
|
149
|
2314 (lambda (widget)
|
163
|
2315 (get (widget-value widget) 'face-defface-spec)))
|
|
2316 ("---" ignore ignore)
|
|
2317 ("Show all display specs" custom-face-edit-all
|
|
2318 (lambda (widget)
|
|
2319 (not (eq (widget-get widget :custom-form) 'all))))
|
|
2320 ("Just current attributes" custom-face-edit-selected
|
|
2321 (lambda (widget)
|
|
2322 (not (eq (widget-get widget :custom-form) 'selected))))
|
|
2323 ("Show as Lisp expression" custom-face-edit-lisp
|
|
2324 (lambda (widget)
|
|
2325 (not (eq (widget-get widget :custom-form) 'lisp)))))
|
28
|
2326 "Alist of actions for the `custom-face' widget.
|
149
|
2327 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
2328 the menu entry, ACTION is the function to call on the widget when the
|
|
2329 menu is selected, and FILTER is a predicate which takes a `custom-face'
|
|
2330 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
2331 widget. If FILTER is nil, ACTION is always valid.")
|
28
|
2332
|
120
|
2333 (defun custom-face-edit-selected (widget)
|
|
2334 "Edit selected attributes of the value of WIDGET."
|
|
2335 (widget-put widget :custom-state 'unknown)
|
|
2336 (widget-put widget :custom-form 'selected)
|
|
2337 (custom-redraw widget))
|
|
2338
|
|
2339 (defun custom-face-edit-all (widget)
|
|
2340 "Edit all attributes of the value of WIDGET."
|
|
2341 (widget-put widget :custom-state 'unknown)
|
|
2342 (widget-put widget :custom-form 'all)
|
|
2343 (custom-redraw widget))
|
|
2344
|
|
2345 (defun custom-face-edit-lisp (widget)
|
|
2346 "Edit the lisp representation of the value of WIDGET."
|
|
2347 (widget-put widget :custom-state 'unknown)
|
|
2348 (widget-put widget :custom-form 'lisp)
|
|
2349 (custom-redraw widget))
|
|
2350
|
28
|
2351 (defun custom-face-state-set (widget)
|
|
2352 "Set the state of WIDGET."
|
|
2353 (let ((symbol (widget-value widget)))
|
|
2354 (widget-put widget :custom-state (cond ((get symbol 'customized-face)
|
|
2355 'set)
|
|
2356 ((get symbol 'saved-face)
|
|
2357 'saved)
|
149
|
2358 ((get symbol 'face-defface-spec)
|
153
|
2359 'standard)
|
28
|
2360 (t
|
|
2361 'rogue)))))
|
|
2362
|
|
2363 (defun custom-face-action (widget &optional event)
|
|
2364 "Show the menu for `custom-face' WIDGET.
|
|
2365 Optional EVENT is the location for the menu."
|
|
2366 (if (eq (widget-get widget :custom-state) 'hidden)
|
149
|
2367 (custom-toggle-hide widget)
|
28
|
2368 (let* ((completion-ignore-case t)
|
|
2369 (symbol (widget-get widget :value))
|
155
|
2370 (answer (widget-choose (concat "Operation on "
|
|
2371 (custom-unlispify-tag-name symbol))
|
149
|
2372 (custom-menu-filter custom-face-menu
|
|
2373 widget)
|
|
2374 event)))
|
28
|
2375 (if answer
|
|
2376 (funcall answer widget)))))
|
|
2377
|
|
2378 (defun custom-face-set (widget)
|
|
2379 "Make the face attributes in WIDGET take effect."
|
|
2380 (let* ((symbol (widget-value widget))
|
|
2381 (child (car (widget-get widget :children)))
|
|
2382 (value (widget-value child)))
|
|
2383 (put symbol 'customized-face value)
|
155
|
2384 (face-spec-set symbol value)
|
28
|
2385 (custom-face-state-set widget)
|
|
2386 (custom-redraw-magic widget)))
|
|
2387
|
|
2388 (defun custom-face-save (widget)
|
|
2389 "Make the face attributes in WIDGET default."
|
|
2390 (let* ((symbol (widget-value widget))
|
|
2391 (child (car (widget-get widget :children)))
|
|
2392 (value (widget-value child)))
|
155
|
2393 (face-spec-set symbol value)
|
28
|
2394 (put symbol 'saved-face value)
|
|
2395 (put symbol 'customized-face nil)
|
|
2396 (custom-face-state-set widget)
|
|
2397 (custom-redraw-magic widget)))
|
|
2398
|
|
2399 (defun custom-face-reset-saved (widget)
|
|
2400 "Restore WIDGET to the face's default attributes."
|
|
2401 (let* ((symbol (widget-value widget))
|
|
2402 (child (car (widget-get widget :children)))
|
|
2403 (value (get symbol 'saved-face)))
|
|
2404 (unless value
|
|
2405 (error "No saved value for this face"))
|
|
2406 (put symbol 'customized-face nil)
|
155
|
2407 (face-spec-set symbol value)
|
28
|
2408 (widget-value-set child value)
|
|
2409 (custom-face-state-set widget)
|
|
2410 (custom-redraw-magic widget)))
|
|
2411
|
153
|
2412 (defun custom-face-reset-standard (widget)
|
|
2413 "Restore WIDGET to the face's standard settings."
|
28
|
2414 (let* ((symbol (widget-value widget))
|
|
2415 (child (car (widget-get widget :children)))
|
149
|
2416 (value (get symbol 'face-defface-spec)))
|
28
|
2417 (unless value
|
153
|
2418 (error "No standard setting for this face"))
|
28
|
2419 (put symbol 'customized-face nil)
|
|
2420 (when (get symbol 'saved-face)
|
|
2421 (put symbol 'saved-face nil)
|
|
2422 (custom-save-all))
|
155
|
2423 (face-spec-set symbol value)
|
28
|
2424 (widget-value-set child value)
|
|
2425 (custom-face-state-set widget)
|
|
2426 (custom-redraw-magic widget)))
|
|
2427
|
|
2428 ;;; The `face' Widget.
|
|
2429
|
|
2430 (define-widget 'face 'default
|
|
2431 "Select and customize a face."
|
149
|
2432 :convert-widget 'widget-value-convert-widget
|
163
|
2433 :button-prefix 'widget-push-button-prefix
|
|
2434 :button-suffix 'widget-push-button-suffix
|
|
2435 :format "%t: %[select face%] %v"
|
28
|
2436 :tag "Face"
|
|
2437 :value 'default
|
|
2438 :value-create 'widget-face-value-create
|
|
2439 :value-delete 'widget-face-value-delete
|
149
|
2440 :value-get 'widget-value-value-get
|
|
2441 :validate 'widget-children-validate
|
28
|
2442 :action 'widget-face-action
|
|
2443 :match '(lambda (widget value) (symbolp value)))
|
|
2444
|
|
2445 (defun widget-face-value-create (widget)
|
|
2446 ;; Create a `custom-face' child.
|
|
2447 (let* ((symbol (widget-value widget))
|
163
|
2448 (custom-buffer-style 'face)
|
28
|
2449 (child (widget-create-child-and-convert
|
|
2450 widget 'custom-face
|
|
2451 :custom-level nil
|
|
2452 :value symbol)))
|
|
2453 (custom-magic-reset child)
|
|
2454 (setq custom-options (cons child custom-options))
|
|
2455 (widget-put widget :children (list child))))
|
|
2456
|
|
2457 (defun widget-face-value-delete (widget)
|
|
2458 ;; Remove the child from the options.
|
|
2459 (let ((child (car (widget-get widget :children))))
|
|
2460 (setq custom-options (delq child custom-options))
|
|
2461 (widget-children-value-delete widget)))
|
|
2462
|
|
2463 (defvar face-history nil
|
|
2464 "History of entered face names.")
|
|
2465
|
|
2466 (defun widget-face-action (widget &optional event)
|
|
2467 "Prompt for a face."
|
|
2468 (let ((answer (completing-read "Face: "
|
|
2469 (mapcar (lambda (face)
|
|
2470 (list (symbol-name face)))
|
|
2471 (face-list))
|
|
2472 nil nil nil
|
|
2473 'face-history)))
|
|
2474 (unless (zerop (length answer))
|
|
2475 (widget-value-set widget (intern answer))
|
|
2476 (widget-apply widget :notify widget event)
|
|
2477 (widget-setup))))
|
|
2478
|
|
2479 ;;; The `hook' Widget.
|
|
2480
|
|
2481 (define-widget 'hook 'list
|
|
2482 "A emacs lisp hook"
|
|
2483 :convert-widget 'custom-hook-convert-widget
|
|
2484 :tag "Hook")
|
|
2485
|
|
2486 (defun custom-hook-convert-widget (widget)
|
|
2487 ;; Handle `:custom-options'.
|
|
2488 (let* ((options (widget-get widget :options))
|
|
2489 (other `(editable-list :inline t
|
|
2490 :entry-format "%i %d%v"
|
|
2491 (function :format " %v")))
|
|
2492 (args (if options
|
|
2493 (list `(checklist :inline t
|
|
2494 ,@(mapcar (lambda (entry)
|
|
2495 `(function-item ,entry))
|
|
2496 options))
|
|
2497 other)
|
|
2498 (list other))))
|
|
2499 (widget-put widget :args args)
|
|
2500 widget))
|
|
2501
|
163
|
2502 ;;; The `custom-group-link' Widget.
|
|
2503
|
|
2504 (define-widget 'custom-group-link 'link
|
|
2505 "Show parent in other window when activated."
|
165
|
2506 :help-echo "Create customization buffer for this group."
|
163
|
2507 :action 'custom-group-link-action)
|
|
2508
|
|
2509 (defun custom-group-link-action (widget &rest ignore)
|
|
2510 (customize-group (widget-value widget)))
|
|
2511
|
28
|
2512 ;;; The `custom-group' Widget.
|
|
2513
|
165
|
2514 (defcustom custom-group-tag-faces nil
|
28
|
2515 ;; In XEmacs, this ought to play games with font size.
|
|
2516 "Face used for group tags.
|
|
2517 The first member is used for level 1 groups, the second for level 2,
|
|
2518 and so forth. The remaining group tags are shown with
|
|
2519 `custom-group-tag-face'."
|
|
2520 :type '(repeat face)
|
124
|
2521 :group 'custom-faces)
|
28
|
2522
|
|
2523 (defface custom-group-tag-face-1 '((((class color)
|
118
|
2524 (background dark))
|
|
2525 (:foreground "pink" :underline t))
|
|
2526 (((class color)
|
|
2527 (background light))
|
|
2528 (:foreground "red" :underline t))
|
|
2529 (t (:underline t)))
|
28
|
2530 "Face used for group tags.")
|
|
2531
|
|
2532 (defface custom-group-tag-face '((((class color)
|
|
2533 (background dark))
|
|
2534 (:foreground "light blue" :underline t))
|
|
2535 (((class color)
|
|
2536 (background light))
|
|
2537 (:foreground "blue" :underline t))
|
|
2538 (t (:underline t)))
|
|
2539 "Face used for low level group tags."
|
124
|
2540 :group 'custom-faces)
|
28
|
2541
|
|
2542 (define-widget 'custom-group 'custom
|
|
2543 "Customize group."
|
163
|
2544 :format "%v"
|
28
|
2545 :sample-face-get 'custom-group-sample-face-get
|
|
2546 :documentation-property 'group-documentation
|
30
|
2547 :help-echo "Set or reset all members of this group."
|
28
|
2548 :value-create 'custom-group-value-create
|
|
2549 :action 'custom-group-action
|
155
|
2550 :custom-category 'group
|
28
|
2551 :custom-set 'custom-group-set
|
|
2552 :custom-save 'custom-group-save
|
|
2553 :custom-reset-current 'custom-group-reset-current
|
|
2554 :custom-reset-saved 'custom-group-reset-saved
|
153
|
2555 :custom-reset-standard 'custom-group-reset-standard
|
28
|
2556 :custom-menu 'custom-group-menu-create)
|
|
2557
|
|
2558 (defun custom-group-sample-face-get (widget)
|
|
2559 ;; Use :sample-face.
|
|
2560 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
|
|
2561 'custom-group-tag-face))
|
|
2562
|
165
|
2563 (define-widget 'custom-group-visibility 'visibility
|
|
2564 "An indicator and manipulator for hidden group contents."
|
|
2565 :create 'custom-group-visibility-create)
|
|
2566
|
|
2567 (defun custom-group-visibility-create (widget)
|
|
2568 (let ((visible (widget-value widget)))
|
|
2569 (if visible
|
|
2570 (insert "--------")))
|
|
2571 (widget-default-create widget))
|
|
2572
|
173
|
2573 (defun custom-group-members (symbol groups-only)
|
|
2574 "Return SYMBOL's custom group members.
|
|
2575 If GROUPS-ONLY non-nil, return only those members that are groups."
|
|
2576 (if (not groups-only)
|
|
2577 (get symbol 'custom-group)
|
|
2578 (let (members)
|
|
2579 (dolist (entry (get symbol 'custom-group))
|
|
2580 (when (eq (nth 1 entry) 'custom-group)
|
|
2581 (push entry members)))
|
|
2582 (nreverse members))))
|
|
2583
|
28
|
2584 (defun custom-group-value-create (widget)
|
163
|
2585 "Insert a customize group for WIDGET in the current buffer."
|
173
|
2586 (let* ((state (widget-get widget :custom-state))
|
|
2587 (level (widget-get widget :custom-level))
|
|
2588 (indent (widget-get widget :indent))
|
|
2589 (prefix (widget-get widget :custom-prefix))
|
|
2590 (buttons (widget-get widget :buttons))
|
|
2591 (tag (widget-get widget :tag))
|
|
2592 (symbol (widget-value widget))
|
|
2593 (members (custom-group-members symbol
|
|
2594 (and (eq custom-buffer-style 'tree)
|
|
2595 custom-browse-only-groups))))
|
163
|
2596 (cond ((and (eq custom-buffer-style 'tree)
|
167
|
2597 (eq state 'hidden)
|
173
|
2598 (or members (custom-unloaded-widget-p widget)))
|
167
|
2599 (custom-browse-insert-prefix prefix)
|
163
|
2600 (push (widget-create-child-and-convert
|
167
|
2601 widget 'custom-browse-visibility
|
163
|
2602 ;; :tag-glyph "plus"
|
167
|
2603 :tag (if (custom-unloaded-widget-p widget) "?" "+"))
|
163
|
2604 buttons)
|
|
2605 (insert "-- ")
|
|
2606 ;; (widget-glyph-insert nil "-- " "horizontal")
|
|
2607 (push (widget-create-child-and-convert
|
167
|
2608 widget 'custom-browse-group-tag)
|
163
|
2609 buttons)
|
|
2610 (insert " " tag "\n")
|
|
2611 (widget-put widget :buttons buttons))
|
|
2612 ((and (eq custom-buffer-style 'tree)
|
173
|
2613 (zerop (length members)))
|
167
|
2614 (custom-browse-insert-prefix prefix)
|
163
|
2615 (insert "[ ]-- ")
|
|
2616 ;; (widget-glyph-insert nil "[ ]" "empty")
|
|
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 ((eq custom-buffer-style 'tree)
|
167
|
2624 (custom-browse-insert-prefix prefix)
|
163
|
2625 (custom-load-widget widget)
|
173
|
2626 (if (zerop (length members))
|
163
|
2627 (progn
|
167
|
2628 (custom-browse-insert-prefix prefix)
|
163
|
2629 (insert "[ ]-- ")
|
|
2630 ;; (widget-glyph-insert nil "[ ]" "empty")
|
|
2631 ;; (widget-glyph-insert nil "-- " "horizontal")
|
|
2632 (push (widget-create-child-and-convert
|
167
|
2633 widget 'custom-browse-group-tag)
|
163
|
2634 buttons)
|
|
2635 (insert " " tag "\n")
|
|
2636 (widget-put widget :buttons buttons))
|
|
2637 (push (widget-create-child-and-convert
|
167
|
2638 widget 'custom-browse-visibility
|
163
|
2639 ;; :tag-glyph "minus"
|
|
2640 :tag "-")
|
|
2641 buttons)
|
165
|
2642 (insert "-\\ ")
|
|
2643 ;; (widget-glyph-insert nil "-\\ " "top")
|
163
|
2644 (push (widget-create-child-and-convert
|
167
|
2645 widget 'custom-browse-group-tag)
|
163
|
2646 buttons)
|
|
2647 (insert " " tag "\n")
|
|
2648 (widget-put widget :buttons buttons)
|
|
2649 (message "Creating group...")
|
173
|
2650 (let* ((members (custom-sort-items members
|
165
|
2651 custom-browse-sort-alphabetically
|
|
2652 custom-browse-order-groups))
|
163
|
2653 (prefixes (widget-get widget :custom-prefixes))
|
|
2654 (custom-prefix-list (custom-prefix-add symbol prefixes))
|
|
2655 (extra-prefix (if (widget-get widget :custom-last)
|
|
2656 " "
|
|
2657 " | "))
|
|
2658 (prefix (concat prefix extra-prefix))
|
|
2659 children entry)
|
|
2660 (while members
|
|
2661 (setq entry (car members)
|
|
2662 members (cdr members))
|
173
|
2663 (push (widget-create-child-and-convert
|
|
2664 widget (nth 1 entry)
|
|
2665 :group widget
|
|
2666 :tag (custom-unlispify-tag-name (nth 0 entry))
|
|
2667 :custom-prefixes custom-prefix-list
|
|
2668 :custom-level (1+ level)
|
|
2669 :custom-last (null members)
|
|
2670 :value (nth 0 entry)
|
|
2671 :custom-prefix prefix)
|
|
2672 children))
|
163
|
2673 (widget-put widget :children (reverse children)))
|
|
2674 (message "Creating group...done")))
|
|
2675 ;; Nested style.
|
|
2676 ((eq state 'hidden)
|
|
2677 ;; Create level indicator.
|
165
|
2678 (unless (eq custom-buffer-style 'links)
|
|
2679 (insert-char ?\ (* custom-buffer-indent (1- level)))
|
|
2680 (insert "-- "))
|
163
|
2681 ;; Create tag.
|
|
2682 (let ((begin (point)))
|
|
2683 (insert tag)
|
|
2684 (widget-specify-sample widget begin (point)))
|
|
2685 (insert " group: ")
|
|
2686 ;; Create link/visibility indicator.
|
|
2687 (if (eq custom-buffer-style 'links)
|
|
2688 (push (widget-create-child-and-convert
|
|
2689 widget 'custom-group-link
|
165
|
2690 :tag "Go to Group"
|
163
|
2691 symbol)
|
|
2692 buttons)
|
|
2693 (push (widget-create-child-and-convert
|
165
|
2694 widget 'group-visibility
|
163
|
2695 :help-echo "Show members of this group."
|
|
2696 :action 'custom-toggle-parent
|
|
2697 (not (eq state 'hidden)))
|
|
2698 buttons))
|
|
2699 (insert " \n")
|
|
2700 ;; Create magic button.
|
|
2701 (let ((magic (widget-create-child-and-convert
|
|
2702 widget 'custom-magic nil)))
|
|
2703 (widget-put widget :custom-magic magic)
|
|
2704 (push magic buttons))
|
|
2705 ;; Update buttons.
|
|
2706 (widget-put widget :buttons buttons)
|
|
2707 ;; Insert documentation.
|
165
|
2708 (if (and (eq custom-buffer-style 'links) (> level 1))
|
|
2709 (widget-put widget :documentation-indent 0))
|
163
|
2710 (widget-default-format-handler widget ?h))
|
|
2711 ;; Nested style.
|
|
2712 (t ;Visible.
|
165
|
2713 ;; Add parent groups references above the group.
|
|
2714 (if t ;;; This should test that the buffer
|
|
2715 ;;; was made to display a group.
|
|
2716 (when (eq level 1)
|
|
2717 (if (custom-add-parent-links widget
|
|
2718 "Go to parent group:")
|
|
2719 (insert "\n"))))
|
163
|
2720 ;; Create level indicator.
|
|
2721 (insert-char ?\ (* custom-buffer-indent (1- level)))
|
|
2722 (insert "/- ")
|
|
2723 ;; Create tag.
|
|
2724 (let ((start (point)))
|
|
2725 (insert tag)
|
|
2726 (widget-specify-sample widget start (point)))
|
|
2727 (insert " group: ")
|
|
2728 ;; Create visibility indicator.
|
|
2729 (unless (eq custom-buffer-style 'links)
|
|
2730 (insert "--------")
|
|
2731 (push (widget-create-child-and-convert
|
|
2732 widget 'visibility
|
|
2733 :help-echo "Hide members of this group."
|
|
2734 :action 'custom-toggle-parent
|
|
2735 (not (eq state 'hidden)))
|
|
2736 buttons)
|
|
2737 (insert " "))
|
|
2738 ;; Create more dashes.
|
|
2739 ;; Use 76 instead of 75 to compensate for the temporary "<"
|
|
2740 ;; added by `widget-insert'.
|
|
2741 (insert-char ?- (- 76 (current-column)
|
|
2742 (* custom-buffer-indent level)))
|
|
2743 (insert "\\\n")
|
|
2744 ;; Create magic button.
|
|
2745 (let ((magic (widget-create-child-and-convert
|
|
2746 widget 'custom-magic
|
|
2747 :indent 0
|
|
2748 nil)))
|
|
2749 (widget-put widget :custom-magic magic)
|
|
2750 (push magic buttons))
|
|
2751 ;; Update buttons.
|
|
2752 (widget-put widget :buttons buttons)
|
|
2753 ;; Insert documentation.
|
|
2754 (widget-default-format-handler widget ?h)
|
165
|
2755 ;; Parent groups.
|
|
2756 (if nil ;;; This should test that the buffer
|
|
2757 ;;; was not made to display a group.
|
|
2758 (when (eq level 1)
|
|
2759 (insert-char ?\ custom-buffer-indent)
|
|
2760 (custom-add-parent-links widget)))
|
163
|
2761 (custom-add-see-also widget
|
|
2762 (make-string (* custom-buffer-indent level)
|
|
2763 ?\ ))
|
|
2764 ;; Members.
|
|
2765 (message "Creating group...")
|
|
2766 (custom-load-widget widget)
|
173
|
2767 (let* ((members (custom-sort-items members
|
165
|
2768 custom-buffer-sort-alphabetically
|
|
2769 custom-buffer-order-groups))
|
163
|
2770 (prefixes (widget-get widget :custom-prefixes))
|
|
2771 (custom-prefix-list (custom-prefix-add symbol prefixes))
|
|
2772 (length (length members))
|
|
2773 (count 0)
|
|
2774 (children (mapcar (lambda (entry)
|
|
2775 (widget-insert "\n")
|
|
2776 (message "\
|
|
2777 Creating group members... %2d%%"
|
|
2778 (/ (* 100.0 count) length))
|
|
2779 (setq count (1+ count))
|
|
2780 (prog1
|
|
2781 (widget-create-child-and-convert
|
|
2782 widget (nth 1 entry)
|
|
2783 :group widget
|
|
2784 :tag (custom-unlispify-tag-name
|
|
2785 (nth 0 entry))
|
|
2786 :custom-prefixes custom-prefix-list
|
|
2787 :custom-level (1+ level)
|
|
2788 :value (nth 0 entry))
|
|
2789 (unless (eq (preceding-char) ?\n)
|
|
2790 (widget-insert "\n"))))
|
|
2791 members)))
|
|
2792 (message "Creating group magic...")
|
|
2793 (mapcar 'custom-magic-reset children)
|
|
2794 (message "Creating group state...")
|
|
2795 (widget-put widget :children children)
|
|
2796 (custom-group-state-update widget)
|
|
2797 (message "Creating group... done"))
|
|
2798 ;; End line
|
|
2799 (insert "\n")
|
|
2800 (insert-char ?\ (* custom-buffer-indent (1- level)))
|
|
2801 (insert "\\- " (widget-get widget :tag) " group end ")
|
|
2802 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
|
|
2803 (insert "/\n")))))
|
28
|
2804
|
|
2805 (defvar custom-group-menu
|
173
|
2806 '(("Set for Current Session" custom-group-set
|
149
|
2807 (lambda (widget)
|
|
2808 (eq (widget-get widget :custom-state) 'modified)))
|
173
|
2809 ("Save for Future Sessions" custom-group-save
|
149
|
2810 (lambda (widget)
|
|
2811 (memq (widget-get widget :custom-state) '(modified set))))
|
|
2812 ("Reset to Current" custom-group-reset-current
|
|
2813 (lambda (widget)
|
|
2814 (memq (widget-get widget :custom-state) '(modified))))
|
|
2815 ("Reset to Saved" custom-group-reset-saved
|
|
2816 (lambda (widget)
|
|
2817 (memq (widget-get widget :custom-state) '(modified set))))
|
153
|
2818 ("Reset to standard setting" custom-group-reset-standard
|
149
|
2819 (lambda (widget)
|
|
2820 (memq (widget-get widget :custom-state) '(modified set saved)))))
|
28
|
2821 "Alist of actions for the `custom-group' widget.
|
149
|
2822 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
|
|
2823 the menu entry, ACTION is the function to call on the widget when the
|
|
2824 menu is selected, and FILTER is a predicate which takes a `custom-group'
|
|
2825 widget as an argument, and returns non-nil if ACTION is valid on that
|
|
2826 widget. If FILTER is nil, ACTION is always valid.")
|
28
|
2827
|
|
2828 (defun custom-group-action (widget &optional event)
|
|
2829 "Show the menu for `custom-group' WIDGET.
|
|
2830 Optional EVENT is the location for the menu."
|
|
2831 (if (eq (widget-get widget :custom-state) 'hidden)
|
149
|
2832 (custom-toggle-hide widget)
|
28
|
2833 (let* ((completion-ignore-case t)
|
155
|
2834 (answer (widget-choose (concat "Operation on "
|
|
2835 (custom-unlispify-tag-name
|
|
2836 (widget-get widget :value)))
|
149
|
2837 (custom-menu-filter custom-group-menu
|
|
2838 widget)
|
28
|
2839 event)))
|
|
2840 (if answer
|
|
2841 (funcall answer widget)))))
|
|
2842
|
|
2843 (defun custom-group-set (widget)
|
|
2844 "Set changes in all modified group members."
|
|
2845 (let ((children (widget-get widget :children)))
|
|
2846 (mapcar (lambda (child)
|
|
2847 (when (eq (widget-get child :custom-state) 'modified)
|
|
2848 (widget-apply child :custom-set)))
|
|
2849 children )))
|
|
2850
|
|
2851 (defun custom-group-save (widget)
|
|
2852 "Save all modified group members."
|
|
2853 (let ((children (widget-get widget :children)))
|
|
2854 (mapcar (lambda (child)
|
|
2855 (when (memq (widget-get child :custom-state) '(modified set))
|
|
2856 (widget-apply child :custom-save)))
|
|
2857 children )))
|
|
2858
|
|
2859 (defun custom-group-reset-current (widget)
|
|
2860 "Reset all modified group members."
|
|
2861 (let ((children (widget-get widget :children)))
|
|
2862 (mapcar (lambda (child)
|
|
2863 (when (eq (widget-get child :custom-state) 'modified)
|
|
2864 (widget-apply child :custom-reset-current)))
|
|
2865 children )))
|
|
2866
|
|
2867 (defun custom-group-reset-saved (widget)
|
|
2868 "Reset all modified or set group members."
|
|
2869 (let ((children (widget-get widget :children)))
|
|
2870 (mapcar (lambda (child)
|
|
2871 (when (memq (widget-get child :custom-state) '(modified set))
|
|
2872 (widget-apply child :custom-reset-saved)))
|
|
2873 children )))
|
|
2874
|
153
|
2875 (defun custom-group-reset-standard (widget)
|
28
|
2876 "Reset all modified, set, or saved group members."
|
|
2877 (let ((children (widget-get widget :children)))
|
|
2878 (mapcar (lambda (child)
|
|
2879 (when (memq (widget-get child :custom-state)
|
|
2880 '(modified set saved))
|
153
|
2881 (widget-apply child :custom-reset-standard)))
|
28
|
2882 children )))
|
|
2883
|
|
2884 (defun custom-group-state-update (widget)
|
|
2885 "Update magic."
|
|
2886 (unless (eq (widget-get widget :custom-state) 'hidden)
|
|
2887 (let* ((children (widget-get widget :children))
|
|
2888 (states (mapcar (lambda (child)
|
|
2889 (widget-get child :custom-state))
|
|
2890 children))
|
|
2891 (magics custom-magic-alist)
|
153
|
2892 (found 'standard))
|
28
|
2893 (while magics
|
|
2894 (let ((magic (car (car magics))))
|
|
2895 (if (and (not (eq magic 'hidden))
|
|
2896 (memq magic states))
|
|
2897 (setq found magic
|
|
2898 magics nil)
|
|
2899 (setq magics (cdr magics)))))
|
|
2900 (widget-put widget :custom-state found)))
|
|
2901 (custom-magic-reset widget))
|
|
2902
|
|
2903 ;;; The `custom-save-all' Function.
|
163
|
2904 ;;;###autoload
|
171
|
2905 (defcustom custom-file (if (boundp 'emacs-user-extension-dir)
|
173
|
2906 (concat "~"
|
|
2907 init-file-user
|
|
2908 emacs-user-extension-dir
|
|
2909 "options.el")
|
163
|
2910 "~/.emacs")
|
28
|
2911 "File used for storing customization information.
|
|
2912 If you change this from the default \"~/.emacs\" you need to
|
|
2913 explicitly load that file for the settings to take effect."
|
|
2914 :type 'file
|
|
2915 :group 'customize)
|
|
2916
|
|
2917 (defun custom-save-delete (symbol)
|
|
2918 "Delete the call to SYMBOL form `custom-file'.
|
|
2919 Leave point at the location of the call, or after the last expression."
|
|
2920 (set-buffer (find-file-noselect custom-file))
|
|
2921 (goto-char (point-min))
|
|
2922 (catch 'found
|
|
2923 (while t
|
|
2924 (let ((sexp (condition-case nil
|
|
2925 (read (current-buffer))
|
|
2926 (end-of-file (throw 'found nil)))))
|
|
2927 (when (and (listp sexp)
|
|
2928 (eq (car sexp) symbol))
|
|
2929 (delete-region (save-excursion
|
|
2930 (backward-sexp)
|
|
2931 (point))
|
|
2932 (point))
|
|
2933 (throw 'found nil))))))
|
|
2934
|
|
2935 (defun custom-save-variables ()
|
|
2936 "Save all customized variables in `custom-file'."
|
|
2937 (save-excursion
|
|
2938 (custom-save-delete 'custom-set-variables)
|
|
2939 (let ((standard-output (current-buffer)))
|
|
2940 (unless (bolp)
|
|
2941 (princ "\n"))
|
|
2942 (princ "(custom-set-variables")
|
|
2943 (mapatoms (lambda (symbol)
|
173
|
2944 (let ((value (get symbol 'saved-value))
|
149
|
2945 (requests (get symbol 'custom-requests))
|
153
|
2946 (now (not (or (get symbol 'standard-value)
|
149
|
2947 (and (not (boundp symbol))
|
|
2948 (not (get symbol 'force-value)))))))
|
28
|
2949 (when value
|
|
2950 (princ "\n '(")
|
|
2951 (princ symbol)
|
|
2952 (princ " ")
|
|
2953 (prin1 (car value))
|
149
|
2954 (cond (requests
|
|
2955 (if now
|
|
2956 (princ " t ")
|
|
2957 (princ " nil "))
|
|
2958 (prin1 requests)
|
|
2959 (princ ")"))
|
|
2960 (now
|
|
2961 (princ " t)"))
|
|
2962 (t
|
|
2963 (princ ")")))))))
|
28
|
2964 (princ ")")
|
120
|
2965 (unless (looking-at "\n")
|
28
|
2966 (princ "\n")))))
|
|
2967
|
|
2968 (defun custom-save-faces ()
|
|
2969 "Save all customized faces in `custom-file'."
|
|
2970 (save-excursion
|
|
2971 (custom-save-delete 'custom-set-faces)
|
|
2972 (let ((standard-output (current-buffer)))
|
|
2973 (unless (bolp)
|
|
2974 (princ "\n"))
|
|
2975 (princ "(custom-set-faces")
|
120
|
2976 (let ((value (get 'default 'saved-face)))
|
|
2977 ;; The default face must be first, since it affects the others.
|
|
2978 (when value
|
|
2979 (princ "\n '(default ")
|
|
2980 (prin1 value)
|
149
|
2981 (if (or (get 'default 'face-defface-spec)
|
120
|
2982 (and (not (custom-facep 'default))
|
|
2983 (not (get 'default 'force-face))))
|
|
2984 (princ ")")
|
|
2985 (princ " t)"))))
|
28
|
2986 (mapatoms (lambda (symbol)
|
173
|
2987 (let ((value (get symbol 'saved-face)))
|
120
|
2988 (when (and (not (eq symbol 'default))
|
|
2989 ;; Don't print default face here.
|
|
2990 value)
|
28
|
2991 (princ "\n '(")
|
|
2992 (princ symbol)
|
|
2993 (princ " ")
|
|
2994 (prin1 value)
|
149
|
2995 (if (or (get symbol 'face-defface-spec)
|
28
|
2996 (and (not (custom-facep symbol))
|
|
2997 (not (get symbol 'force-face))))
|
|
2998 (princ ")")
|
|
2999 (princ " t)"))))))
|
|
3000 (princ ")")
|
120
|
3001 (unless (looking-at "\n")
|
28
|
3002 (princ "\n")))))
|
|
3003
|
116
|
3004 ;;;###autoload
|
165
|
3005 (defun customize-save-customized ()
|
149
|
3006 "Save all user options which have been set in this session."
|
|
3007 (interactive)
|
|
3008 (mapatoms (lambda (symbol)
|
173
|
3009 (let ((face (get symbol 'customized-face))
|
|
3010 (value (get symbol 'customized-value)))
|
|
3011 (when face
|
|
3012 (put symbol 'saved-face face)
|
|
3013 (put symbol 'customized-face nil))
|
|
3014 (when value
|
|
3015 (put symbol 'saved-value value)
|
|
3016 (put symbol 'customized-value nil)))))
|
149
|
3017 ;; We really should update all custom buffers here.
|
|
3018 (custom-save-all))
|
|
3019
|
|
3020 ;;;###autoload
|
28
|
3021 (defun custom-save-all ()
|
|
3022 "Save all customizations in `custom-file'."
|
173
|
3023 (let ((inhibit-read-only t))
|
|
3024 (custom-save-variables)
|
|
3025 (custom-save-faces)
|
|
3026 (save-excursion
|
|
3027 (set-buffer (find-file-noselect custom-file))
|
|
3028 (save-buffer))))
|
28
|
3029
|
|
3030 ;;; The Customize Menu.
|
|
3031
|
120
|
3032 ;;; Menu support
|
|
3033
|
|
3034 (unless (string-match "XEmacs" emacs-version)
|
163
|
3035 (defconst custom-help-menu
|
|
3036 '("Customize"
|
167
|
3037 ["Update menu" Custom-menu-update t]
|
|
3038 ["Browse" (customize-browse 'emacs) t]
|
163
|
3039 ["Group..." customize-group t]
|
167
|
3040 ["Option..." customize-option t]
|
163
|
3041 ["Face..." customize-face t]
|
|
3042 ["Saved..." customize-saved t]
|
|
3043 ["Set..." customize-customized t]
|
167
|
3044 "--"
|
163
|
3045 ["Apropos..." customize-apropos t]
|
|
3046 ["Group apropos..." customize-apropos-groups t]
|
167
|
3047 ["Option apropos..." customize-apropos-options t]
|
163
|
3048 ["Face apropos..." customize-apropos-faces t])
|
120
|
3049 ;; This menu should be identical to the one defined in `menu-bar.el'.
|
|
3050 "Customize menu")
|
|
3051
|
|
3052 (defun custom-menu-reset ()
|
|
3053 "Reset customize menu."
|
|
3054 (remove-hook 'custom-define-hook 'custom-menu-reset)
|
|
3055 (define-key global-map [menu-bar help-menu customize-menu]
|
|
3056 (cons (car custom-help-menu)
|
|
3057 (easy-menu-create-keymaps (car custom-help-menu)
|
|
3058 (cdr custom-help-menu)))))
|
|
3059
|
165
|
3060 (defun Custom-menu-update (event)
|
120
|
3061 "Update customize menu."
|
|
3062 (interactive "e")
|
|
3063 (add-hook 'custom-define-hook 'custom-menu-reset)
|
|
3064 (let* ((emacs (widget-apply '(custom-group) :custom-menu 'emacs))
|
|
3065 (menu `(,(car custom-help-menu)
|
|
3066 ,emacs
|
|
3067 ,@(cdr (cdr custom-help-menu)))))
|
|
3068 (let ((map (easy-menu-create-keymaps (car menu) (cdr menu))))
|
|
3069 (define-key global-map [menu-bar help-menu customize-menu]
|
153
|
3070 (cons (car menu) map))))))
|
120
|
3071
|
153
|
3072 (defcustom custom-menu-nesting 2
|
|
3073 "Maximum nesting in custom menus."
|
|
3074 :type 'integer
|
161
|
3075 :group 'custom-menu)
|
28
|
3076
|
|
3077 (defun custom-face-menu-create (widget symbol)
|
|
3078 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
|
|
3079 (vector (custom-unlispify-menu-entry symbol)
|
149
|
3080 `(customize-face ',symbol)
|
28
|
3081 t))
|
|
3082
|
|
3083 (defun custom-variable-menu-create (widget symbol)
|
|
3084 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
|
|
3085 (let ((type (get symbol 'custom-type)))
|
|
3086 (unless (listp type)
|
|
3087 (setq type (list type)))
|
|
3088 (if (and type (widget-get type :custom-menu))
|
|
3089 (widget-apply type :custom-menu symbol)
|
|
3090 (vector (custom-unlispify-menu-entry symbol)
|
149
|
3091 `(customize-variable ',symbol)
|
28
|
3092 t))))
|
|
3093
|
120
|
3094 ;; Add checkboxes to boolean variable entries.
|
28
|
3095 (widget-put (get 'boolean 'widget-type)
|
|
3096 :custom-menu (lambda (widget symbol)
|
|
3097 (vector (custom-unlispify-menu-entry symbol)
|
149
|
3098 `(customize-variable ',symbol)
|
28
|
3099 ':style 'toggle
|
|
3100 ':selected symbol)))
|
|
3101
|
34
|
3102 (if (string-match "XEmacs" emacs-version)
|
|
3103 ;; XEmacs can create menus dynamically.
|
|
3104 (defun custom-group-menu-create (widget symbol)
|
|
3105 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
|
|
3106 `( ,(custom-unlispify-menu-entry symbol t)
|
36
|
3107 :filter (lambda (&rest junk)
|
|
3108 (cdr (custom-menu-create ',symbol)))))
|
34
|
3109 ;; But emacs can't.
|
|
3110 (defun custom-group-menu-create (widget symbol)
|
|
3111 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
|
|
3112 ;; Limit the nesting.
|
|
3113 (let ((custom-menu-nesting (1- custom-menu-nesting)))
|
|
3114 (custom-menu-create symbol))))
|
28
|
3115
|
120
|
3116 ;;;###autoload
|
124
|
3117 (defun custom-menu-create (symbol)
|
28
|
3118 "Create menu for customization group SYMBOL.
|
|
3119 The menu is in a format applicable to `easy-menu-define'."
|
124
|
3120 (let* ((item (vector (custom-unlispify-menu-entry symbol)
|
153
|
3121 `(customize-group ',symbol)
|
124
|
3122 t)))
|
120
|
3123 (if (and (or (not (boundp 'custom-menu-nesting))
|
|
3124 (>= custom-menu-nesting 0))
|
28
|
3125 (< (length (get symbol 'custom-group)) widget-menu-max-size))
|
34
|
3126 (let ((custom-prefix-list (custom-prefix-add symbol
|
155
|
3127 custom-prefix-list))
|
165
|
3128 (members (custom-sort-items (get symbol 'custom-group)
|
|
3129 custom-menu-sort-alphabetically
|
|
3130 custom-menu-order-groups)))
|
28
|
3131 (custom-load-symbol symbol)
|
|
3132 `(,(custom-unlispify-menu-entry symbol t)
|
|
3133 ,item
|
|
3134 "--"
|
|
3135 ,@(mapcar (lambda (entry)
|
|
3136 (widget-apply (if (listp (nth 1 entry))
|
|
3137 (nth 1 entry)
|
|
3138 (list (nth 1 entry)))
|
|
3139 :custom-menu (nth 0 entry)))
|
155
|
3140 members)))
|
28
|
3141 item)))
|
|
3142
|
124
|
3143 ;;;###autoload
|
|
3144 (defun customize-menu-create (symbol &optional name)
|
|
3145 "Return a customize menu for customization group SYMBOL.
|
|
3146 If optional NAME is given, use that as the name of the menu.
|
|
3147 Otherwise the menu will be named `Customize'.
|
|
3148 The format is suitable for use with `easy-menu-define'."
|
|
3149 (unless name
|
|
3150 (setq name "Customize"))
|
|
3151 (if (string-match "XEmacs" emacs-version)
|
|
3152 ;; We can delay it under XEmacs.
|
|
3153 `(,name
|
|
3154 :filter (lambda (&rest junk)
|
|
3155 (cdr (custom-menu-create ',symbol))))
|
|
3156 ;; But we must create it now under Emacs.
|
|
3157 (cons name (cdr (custom-menu-create symbol)))))
|
|
3158
|
|
3159 ;;; The Custom Mode.
|
|
3160
|
|
3161 (defvar custom-mode-map nil
|
|
3162 "Keymap for `custom-mode'.")
|
165
|
3163
|
124
|
3164 (unless custom-mode-map
|
|
3165 (setq custom-mode-map (make-sparse-keymap))
|
|
3166 (set-keymap-parent custom-mode-map widget-keymap)
|
157
|
3167 (suppress-keymap custom-mode-map)
|
165
|
3168 (define-key custom-mode-map " " 'scroll-up)
|
|
3169 (define-key custom-mode-map "\177" 'scroll-down)
|
|
3170 (define-key custom-mode-map "q" 'bury-buffer)
|
173
|
3171 (define-key custom-mode-map "u" 'Custom-goto-parent)
|
|
3172 ;; (define-key custom-mode-map [mouse-1] 'Custom-move-and-invoke)
|
|
3173 )
|
|
3174
|
|
3175 (defun Custom-move-and-invoke (event)
|
|
3176 "Move to where you click, and if it is an active field, invoke it."
|
|
3177 (interactive "e")
|
|
3178 (mouse-set-point event)
|
|
3179 (if (widget-event-point event)
|
|
3180 (let* ((pos (widget-event-point event))
|
|
3181 (button (get-char-property pos 'button)))
|
|
3182 (if button
|
|
3183 (widget-button-click event)))))
|
124
|
3184
|
165
|
3185 (easy-menu-define Custom-mode-menu
|
124
|
3186 custom-mode-map
|
|
3187 "Menu used in customization buffers."
|
|
3188 `("Custom"
|
163
|
3189 ,(customize-menu-create 'customize)
|
165
|
3190 ["Set" Custom-set t]
|
|
3191 ["Save" Custom-save t]
|
|
3192 ["Reset to Current" Custom-reset-current t]
|
|
3193 ["Reset to Saved" Custom-reset-saved t]
|
|
3194 ["Reset to Standard Settings" Custom-reset-standard t]
|
124
|
3195 ["Info" (Info-goto-node "(custom)The Customization Buffer") t]))
|
|
3196
|
165
|
3197 (defun Custom-goto-parent ()
|
|
3198 "Go to the parent group listed at the top of this buffer.
|
|
3199 If several parents are listed, go to the first of them."
|
|
3200 (interactive)
|
|
3201 (save-excursion
|
|
3202 (goto-char (point-min))
|
|
3203 (if (search-forward "\nGo to parent group: " nil t)
|
|
3204 (let* ((button (get-char-property (point) 'button))
|
|
3205 (parent (downcase (widget-get button :tag))))
|
|
3206 (customize-group parent)))))
|
|
3207
|
124
|
3208 (defcustom custom-mode-hook nil
|
|
3209 "Hook called when entering custom-mode."
|
|
3210 :type 'hook
|
161
|
3211 :group 'custom-buffer )
|
124
|
3212
|
165
|
3213 (defun custom-state-buffer-message (widget)
|
|
3214 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
|
|
3215 (message "To install your edits, invoke [State] and choose the Set operation")))
|
|
3216
|
124
|
3217 (defun custom-mode ()
|
|
3218 "Major mode for editing customization buffers.
|
|
3219
|
|
3220 The following commands are available:
|
|
3221
|
|
3222 Move to next button or editable field. \\[widget-forward]
|
|
3223 Move to previous button or editable field. \\[widget-backward]
|
173
|
3224 \\<widget-field-keymap>\
|
|
3225 Complete content of editable text field. \\[widget-complete]
|
|
3226 \\<custom-mode-map>\
|
|
3227 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
|
155
|
3228 Invoke button under point. \\[widget-button-press]
|
165
|
3229 Set all modifications. \\[Custom-set]
|
|
3230 Make all modifications default. \\[Custom-save]
|
|
3231 Reset all modified options. \\[Custom-reset-current]
|
|
3232 Reset all modified or set options. \\[Custom-reset-saved]
|
|
3233 Reset all options. \\[Custom-reset-standard]
|
124
|
3234
|
|
3235 Entry to this mode calls the value of `custom-mode-hook'
|
|
3236 if that value is non-nil."
|
|
3237 (kill-all-local-variables)
|
|
3238 (setq major-mode 'custom-mode
|
|
3239 mode-name "Custom")
|
|
3240 (use-local-map custom-mode-map)
|
165
|
3241 (easy-menu-add Custom-mode-menu)
|
124
|
3242 (make-local-variable 'custom-options)
|
165
|
3243 (make-local-variable 'widget-documentation-face)
|
|
3244 (setq widget-documentation-face 'custom-documentation-face)
|
173
|
3245 (make-local-variable 'widget-button-face)
|
|
3246 (setq widget-button-face 'custom-button-face)
|
165
|
3247 (make-local-hook 'widget-edit-functions)
|
|
3248 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
|
124
|
3249 (run-hooks 'custom-mode-hook))
|
28
|
3250
|
|
3251 ;;; The End.
|
|
3252
|
|
3253 (provide 'cus-edit)
|
|
3254
|
|
3255 ;; cus-edit.el ends here
|