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