]> code.delx.au - gnu-emacs/blob - lisp/cus-edit.el
(viet-encode-viscii-char): New function.
[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 (custom-buffer-create (list (list symbol 'custom-variable))
872 (format "*Customize Option: %s*"
873 (custom-unlispify-tag-name symbol))))
874
875 ;;;###autoload
876 (defun customize-changed-options (since-version)
877 "Customize all user option variables whose default values changed recently.
878 This means, in other words, variables and groups defined with a `:version'
879 option."
880 (interactive "sCustomize options changed, since version (default all versions): ")
881 (if (equal since-version "")
882 (setq since-version nil))
883 (let ((found nil)
884 (versions nil))
885 (mapatoms (lambda (symbol)
886 (and (or (boundp symbol)
887 ;; For variables not yet loaded.
888 (get symbol 'standard-value)
889 ;; For groups the previous test fails, this one
890 ;; could be used to determine if symbol is a
891 ;; group. Is there a better way for this?
892 (get symbol 'group-documentation))
893 (let ((version (get symbol 'custom-version)))
894 (and version
895 (or (null since-version)
896 (customize-version-lessp since-version version))
897 (if (member version versions)
898 t
899 ;;; Collect all versions that we use.
900 (push version versions))))
901 (setq found
902 ;; We have to set the right thing here,
903 ;; depending if we have a group or a
904 ;; variable.
905 (if (get symbol 'group-documentation)
906 (cons (list symbol 'custom-group) found)
907 (cons (list symbol 'custom-variable) found))))))
908 (if (not found)
909 (error "No user options have changed defaults in recent Emacs versions")
910 (let ((flist nil))
911 (while versions
912 (push (copy-sequence
913 (cdr (assoc (car versions) custom-versions-load-alist)))
914 flist)
915 (setq versions (cdr versions)))
916 (put 'custom-versions-load-alist 'custom-loads
917 ;; Get all the files that correspond to element from the
918 ;; VERSIONS list. This could use some simplification.
919 (apply 'nconc flist)))
920 ;; Because we set all the files needed to be loaded as a
921 ;; `custom-loads' property to `custom-versions-load-alist' this
922 ;; call will actually load them.
923 (custom-load-symbol 'custom-versions-load-alist)
924 ;; Clean up
925 (put 'custom-versions-load-alist 'custom-loads nil)
926 (custom-buffer-create (custom-sort-items found t 'first)
927 "*Customize Changed Options*"))))
928
929 (defun customize-version-lessp (version1 version2)
930 (let (major1 major2 minor1 minor2)
931 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1)
932 (setq major1 (read (match-string 1 version1)))
933 (setq minor1 (read (match-string 2 version1)))
934 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2)
935 (setq major2 (read (match-string 1 version2)))
936 (setq minor2 (read (match-string 2 version2)))
937 (or (< major1 major2)
938 (and (= major1 major2)
939 (< minor1 minor2)))))
940
941 ;;;###autoload
942 (defalias 'customize-variable-other-window 'customize-option-other-window)
943
944 ;;;###autoload
945 (defun customize-option-other-window (symbol)
946 "Customize SYMBOL, which must be a user option variable.
947 Show the buffer in another window, but don't select it."
948 (interactive (custom-variable-prompt))
949 (custom-buffer-create-other-window
950 (list (list symbol 'custom-variable))
951 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
952
953 ;;;###autoload
954 (defun customize-face (&optional symbol)
955 "Customize SYMBOL, which should be a face name or nil.
956 If SYMBOL is nil, customize all faces."
957 (interactive (list (completing-read "Customize face: (default all) "
958 obarray 'custom-facep)))
959 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
960 (custom-buffer-create (custom-sort-items
961 (mapcar (lambda (symbol)
962 (list symbol 'custom-face))
963 (face-list))
964 t nil)
965 "*Customize Faces*")
966 (when (stringp symbol)
967 (setq symbol (intern symbol)))
968 (unless (symbolp symbol)
969 (error "Should be a symbol %S" symbol))
970 (custom-buffer-create (list (list symbol 'custom-face))
971 (format "*Customize Face: %s*"
972 (custom-unlispify-tag-name symbol)))))
973
974 ;;;###autoload
975 (defun customize-face-other-window (&optional symbol)
976 "Show customization buffer for FACE in other window."
977 (interactive (list (completing-read "Customize face: "
978 obarray 'custom-facep)))
979 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
980 ()
981 (if (stringp symbol)
982 (setq symbol (intern symbol)))
983 (unless (symbolp symbol)
984 (error "Should be a symbol %S" symbol))
985 (custom-buffer-create-other-window
986 (list (list symbol 'custom-face))
987 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol)))))
988
989 ;;;###autoload
990 (defun customize-customized ()
991 "Customize all user options set since the last save in this session."
992 (interactive)
993 (let ((found nil))
994 (mapatoms (lambda (symbol)
995 (and (get symbol 'customized-face)
996 (custom-facep symbol)
997 (push (list symbol 'custom-face) found))
998 (and (get symbol 'customized-value)
999 (boundp symbol)
1000 (push (list symbol 'custom-variable) found))))
1001 (if (not found)
1002 (error "No customized user options")
1003 (custom-buffer-create (custom-sort-items found t nil)
1004 "*Customize Customized*"))))
1005
1006 ;;;###autoload
1007 (defun customize-saved ()
1008 "Customize all already saved user options."
1009 (interactive)
1010 (let ((found nil))
1011 (mapatoms (lambda (symbol)
1012 (and (get symbol 'saved-face)
1013 (custom-facep symbol)
1014 (push (list symbol 'custom-face) found))
1015 (and (get symbol 'saved-value)
1016 (boundp symbol)
1017 (push (list symbol 'custom-variable) found))))
1018 (if (not found )
1019 (error "No saved user options")
1020 (custom-buffer-create (custom-sort-items found t nil)
1021 "*Customize Saved*"))))
1022
1023 ;;;###autoload
1024 (defun customize-apropos (regexp &optional all)
1025 "Customize all user options matching REGEXP.
1026 If ALL is `options', include only options.
1027 If ALL is `faces', include only faces.
1028 If ALL is `groups', include only groups.
1029 If ALL is t (interactively, with prefix arg), include options which are not
1030 user-settable, as well as faces and groups."
1031 (interactive "sCustomize regexp: \nP")
1032 (let ((found nil))
1033 (mapatoms (lambda (symbol)
1034 (when (string-match regexp (symbol-name symbol))
1035 (when (and (not (memq all '(faces options)))
1036 (get symbol 'custom-group))
1037 (push (list symbol 'custom-group) found))
1038 (when (and (not (memq all '(options groups)))
1039 (custom-facep symbol))
1040 (push (list symbol 'custom-face) found))
1041 (when (and (not (memq all '(groups faces)))
1042 (boundp symbol)
1043 (or (get symbol 'saved-value)
1044 (get symbol 'standard-value)
1045 (if (memq all '(nil options))
1046 (user-variable-p symbol)
1047 (get symbol 'variable-documentation))))
1048 (push (list symbol 'custom-variable) found)))))
1049 (if (not found)
1050 (error "No matches")
1051 (custom-buffer-create (custom-sort-items found t
1052 custom-buffer-order-groups)
1053 "*Customize Apropos*"))))
1054
1055 ;;;###autoload
1056 (defun customize-apropos-options (regexp &optional arg)
1057 "Customize all user options matching REGEXP.
1058 With prefix arg, include options which are not user-settable."
1059 (interactive "sCustomize regexp: \nP")
1060 (customize-apropos regexp (or arg 'options)))
1061
1062 ;;;###autoload
1063 (defun customize-apropos-faces (regexp)
1064 "Customize all user faces matching REGEXP."
1065 (interactive "sCustomize regexp: \n")
1066 (customize-apropos regexp 'faces))
1067
1068 ;;;###autoload
1069 (defun customize-apropos-groups (regexp)
1070 "Customize all user groups matching REGEXP."
1071 (interactive "sCustomize regexp: \n")
1072 (customize-apropos regexp 'groups))
1073
1074 ;;; Buffer.
1075
1076 (defcustom custom-buffer-style 'links
1077 "Control the presentation style for customization buffers.
1078 The value should be a symbol, one of:
1079
1080 brackets: groups nest within each other with big horizontal brackets.
1081 links: groups have links to subgroups."
1082 :type '(radio (const brackets)
1083 (const links))
1084 :group 'custom-buffer)
1085
1086 (defcustom custom-buffer-indent 3
1087 "Number of spaces to indent nested groups."
1088 :type 'integer
1089 :group 'custom-buffer)
1090
1091 ;;;###autoload
1092 (defun custom-buffer-create (options &optional name description)
1093 "Create a buffer containing OPTIONS.
1094 Optional NAME is the name of the buffer.
1095 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1096 SYMBOL is a customization option, and WIDGET is a widget for editing
1097 that option."
1098 (unless name (setq name "*Customization*"))
1099 (kill-buffer (get-buffer-create name))
1100 (pop-to-buffer (get-buffer-create name))
1101 (custom-buffer-create-internal options description))
1102
1103 ;;;###autoload
1104 (defun custom-buffer-create-other-window (options &optional name description)
1105 "Create a buffer containing OPTIONS.
1106 Optional NAME is the name of the buffer.
1107 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1108 SYMBOL is a customization option, and WIDGET is a widget for editing
1109 that option."
1110 (unless name (setq name "*Customization*"))
1111 (kill-buffer (get-buffer-create name))
1112 (let ((window (selected-window))
1113 (pop-up-windows t)
1114 (special-display-buffer-names nil)
1115 (special-display-regexps nil)
1116 (same-window-buffer-names nil)
1117 (same-window-regexps nil))
1118 (pop-to-buffer (get-buffer-create name))
1119 (custom-buffer-create-internal options description)
1120 (select-window window)))
1121
1122 (defcustom custom-reset-button-menu nil
1123 "If non-nil, only show a single reset button in customize buffers.
1124 This button will have a menu with all three reset operations."
1125 :type 'boolean
1126 :group 'custom-buffer)
1127
1128 (defun custom-buffer-create-internal (options &optional description)
1129 (message "Creating customization buffer...")
1130 (custom-mode)
1131 (widget-insert "This is a customization buffer")
1132 (if description
1133 (widget-insert description))
1134 (widget-insert ".
1135 Square brackets show active fields; type RET or click mouse-1
1136 on an active field to invoke its action. Editing an option value
1137 changes the text in the buffer; invoke the State button and
1138 choose the Set operation to set the option value.
1139 Invoke ")
1140 (widget-create 'info-link
1141 :tag "Help"
1142 :help-echo "Read the online help."
1143 "(emacs)Easy Customization")
1144 (widget-insert " for more information.\n\n")
1145 (message "Creating customization buttons...")
1146 (widget-insert "Operate on everything in this buffer:\n ")
1147 (widget-create 'push-button
1148 :tag "Set for Current Session"
1149 :help-echo "\
1150 Make your editing in this buffer take effect for this session."
1151 :action (lambda (widget &optional event)
1152 (Custom-set)))
1153 (widget-insert " ")
1154 (widget-create 'push-button
1155 :tag "Save for Future Sessions"
1156 :help-echo "\
1157 Make your editing in this buffer take effect for future Emacs sessions."
1158 :action (lambda (widget &optional event)
1159 (Custom-save)))
1160 (if custom-reset-button-menu
1161 (progn
1162 (widget-insert " ")
1163 (widget-create 'push-button
1164 :tag "Reset"
1165 :help-echo "Show a menu with reset operations."
1166 :mouse-down-action (lambda (&rest junk) t)
1167 :action (lambda (widget &optional event)
1168 (custom-reset event))))
1169 (widget-insert "\n ")
1170 (widget-create 'push-button
1171 :tag "Reset"
1172 :help-echo "\
1173 Reset all edited text in this buffer to reflect current values."
1174 :action 'Custom-reset-current)
1175 (widget-insert " ")
1176 (widget-create 'push-button
1177 :tag "Reset to Saved"
1178 :help-echo "\
1179 Reset all values in this buffer to their saved settings."
1180 :action 'Custom-reset-saved)
1181 (widget-insert " ")
1182 (widget-create 'push-button
1183 :tag "Reset to Standard"
1184 :help-echo "\
1185 Reset all values in this buffer to their standard settings."
1186 :action 'Custom-reset-standard))
1187 (widget-insert " ")
1188 (widget-create 'push-button
1189 :tag "Bury Buffer"
1190 :help-echo "Bury the buffer."
1191 :action (lambda (widget &optional event)
1192 (bury-buffer)))
1193 (widget-insert "\n\n")
1194 (message "Creating customization items...")
1195 (setq custom-options
1196 (if (= (length options) 1)
1197 (mapcar (lambda (entry)
1198 (widget-create (nth 1 entry)
1199 :documentation-shown t
1200 :custom-state 'unknown
1201 :tag (custom-unlispify-tag-name
1202 (nth 0 entry))
1203 :value (nth 0 entry)))
1204 options)
1205 (let ((count 0)
1206 (length (length options)))
1207 (mapcar (lambda (entry)
1208 (prog2
1209 (message "Creating customization items ...%2d%%"
1210 (/ (* 100.0 count) length))
1211 (widget-create (nth 1 entry)
1212 :tag (custom-unlispify-tag-name
1213 (nth 0 entry))
1214 :value (nth 0 entry))
1215 (setq count (1+ count))
1216 (unless (eq (preceding-char) ?\n)
1217 (widget-insert "\n"))
1218 (widget-insert "\n")))
1219 options))))
1220 (unless (eq (preceding-char) ?\n)
1221 (widget-insert "\n"))
1222 (message "Creating customization items ...%2d%%done" 100)
1223 (unless (eq custom-buffer-style 'tree)
1224 (mapcar 'custom-magic-reset custom-options))
1225 (message "Creating customization setup...")
1226 (widget-setup)
1227 (goto-char (point-min))
1228 (message "Creating customization buffer...done"))
1229
1230 ;;; The Tree Browser.
1231
1232 ;;;###autoload
1233 (defun customize-browse (&optional group)
1234 "Create a tree browser for the customize hierarchy."
1235 (interactive)
1236 (unless group
1237 (setq group 'emacs))
1238 (let ((name "*Customize Browser*"))
1239 (kill-buffer (get-buffer-create name))
1240 (pop-to-buffer (get-buffer-create name)))
1241 (custom-mode)
1242 (widget-insert "\
1243 Square brackets show active fields; type RET or click mouse-1
1244 on an active field to invoke its action.
1245 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1246 (if custom-browse-only-groups
1247 (widget-insert "\
1248 Invoke the [Group] button below to edit that item in another window.\n\n")
1249 (widget-insert "Invoke the ")
1250 (widget-create 'item
1251 :format "%t"
1252 :tag "[Group]"
1253 :tag-glyph "folder")
1254 (widget-insert ", ")
1255 (widget-create 'item
1256 :format "%t"
1257 :tag "[Face]"
1258 :tag-glyph "face")
1259 (widget-insert ", and ")
1260 (widget-create 'item
1261 :format "%t"
1262 :tag "[Option]"
1263 :tag-glyph "option")
1264 (widget-insert " buttons below to edit that
1265 item in another window.\n\n"))
1266 (let ((custom-buffer-style 'tree))
1267 (widget-create 'custom-group
1268 :custom-last t
1269 :custom-state 'unknown
1270 :tag (custom-unlispify-tag-name group)
1271 :value group))
1272 (goto-char (point-min)))
1273
1274 (define-widget 'custom-browse-visibility 'item
1275 "Control visibility of items in the customize tree browser."
1276 :format "%[[%t]%]"
1277 :action 'custom-browse-visibility-action)
1278
1279 (defun custom-browse-visibility-action (widget &rest ignore)
1280 (let ((custom-buffer-style 'tree))
1281 (custom-toggle-parent widget)))
1282
1283 (define-widget 'custom-browse-group-tag 'push-button
1284 "Show parent in other window when activated."
1285 :tag "Group"
1286 :tag-glyph "folder"
1287 :action 'custom-browse-group-tag-action)
1288
1289 (defun custom-browse-group-tag-action (widget &rest ignore)
1290 (let ((parent (widget-get widget :parent)))
1291 (customize-group-other-window (widget-value parent))))
1292
1293 (define-widget 'custom-browse-variable-tag 'push-button
1294 "Show parent in other window when activated."
1295 :tag "Option"
1296 :tag-glyph "option"
1297 :action 'custom-browse-variable-tag-action)
1298
1299 (defun custom-browse-variable-tag-action (widget &rest ignore)
1300 (let ((parent (widget-get widget :parent)))
1301 (customize-variable-other-window (widget-value parent))))
1302
1303 (define-widget 'custom-browse-face-tag 'push-button
1304 "Show parent in other window when activated."
1305 :tag "Face"
1306 :tag-glyph "face"
1307 :action 'custom-browse-face-tag-action)
1308
1309 (defun custom-browse-face-tag-action (widget &rest ignore)
1310 (let ((parent (widget-get widget :parent)))
1311 (customize-face-other-window (widget-value parent))))
1312
1313 (defconst custom-browse-alist '((" " "space")
1314 (" | " "vertical")
1315 ("-\\ " "top")
1316 (" |-" "middle")
1317 (" `-" "bottom")))
1318
1319 (defun custom-browse-insert-prefix (prefix)
1320 "Insert PREFIX. On XEmacs convert it to line graphics."
1321 (if nil ; (string-match "XEmacs" emacs-version)
1322 (progn
1323 (insert "*")
1324 (while (not (string-equal prefix ""))
1325 (let ((entry (substring prefix 0 3)))
1326 (setq prefix (substring prefix 3))
1327 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1328 (name (nth 1 (assoc entry custom-browse-alist))))
1329 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1330 (overlay-put overlay 'start-open t)
1331 (overlay-put overlay 'end-open t)))))
1332 (insert prefix)))
1333
1334 ;;; Modification of Basic Widgets.
1335 ;;
1336 ;; We add extra properties to the basic widgets needed here. This is
1337 ;; fine, as long as we are careful to stay within out own namespace.
1338 ;;
1339 ;; We want simple widgets to be displayed by default, but complex
1340 ;; widgets to be hidden.
1341
1342 (widget-put (get 'item 'widget-type) :custom-show t)
1343 (widget-put (get 'editable-field 'widget-type)
1344 :custom-show (lambda (widget value)
1345 (let ((pp (pp-to-string value)))
1346 (cond ((string-match "\n" pp)
1347 nil)
1348 ((> (length pp) 40)
1349 nil)
1350 (t t)))))
1351 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1352
1353 ;;; The `custom-manual' Widget.
1354
1355 (define-widget 'custom-manual 'info-link
1356 "Link to the manual entry for this customization option."
1357 :help-echo "Read the manual entry for this option."
1358 :tag "Manual")
1359
1360 ;;; The `custom-magic' Widget.
1361
1362 (defgroup custom-magic-faces nil
1363 "Faces used by the magic button."
1364 :group 'custom-faces
1365 :group 'custom-buffer)
1366
1367 (defface custom-invalid-face '((((class color))
1368 (:foreground "yellow" :background "red"))
1369 (t
1370 (:bold t :italic t :underline t)))
1371 "Face used when the customize item is invalid."
1372 :group 'custom-magic-faces)
1373
1374 (defface custom-rogue-face '((((class color))
1375 (:foreground "pink" :background "black"))
1376 (t
1377 (:underline t)))
1378 "Face used when the customize item is not defined for customization."
1379 :group 'custom-magic-faces)
1380
1381 (defface custom-modified-face '((((class color))
1382 (:foreground "white" :background "blue"))
1383 (t
1384 (:italic t :bold)))
1385 "Face used when the customize item has been modified."
1386 :group 'custom-magic-faces)
1387
1388 (defface custom-set-face '((((class color))
1389 (:foreground "blue" :background "white"))
1390 (t
1391 (:italic t)))
1392 "Face used when the customize item has been set."
1393 :group 'custom-magic-faces)
1394
1395 (defface custom-changed-face '((((class color))
1396 (:foreground "white" :background "blue"))
1397 (t
1398 (:italic t)))
1399 "Face used when the customize item has been changed."
1400 :group 'custom-magic-faces)
1401
1402 (defface custom-saved-face '((t (:underline t)))
1403 "Face used when the customize item has been saved."
1404 :group 'custom-magic-faces)
1405
1406 (defconst custom-magic-alist '((nil "#" underline "\
1407 uninitialized, you should not see this.")
1408 (unknown "?" italic "\
1409 unknown, you should not see this.")
1410 (hidden "-" default "\
1411 hidden, invoke \"Show\" in the previous line to show." "\
1412 group now hidden, invoke \"Show\", above, to show contents.")
1413 (invalid "x" custom-invalid-face "\
1414 the value displayed for this %c is invalid and cannot be set.")
1415 (modified "*" custom-modified-face "\
1416 you have edited the value as text, but you have not set the %c." "\
1417 you have edited something in this group, but not set it.")
1418 (set "+" custom-set-face "\
1419 you have set this %c, but not saved it for future sessions." "\
1420 something in this group has been set, but not saved.")
1421 (changed ":" custom-changed-face "\
1422 this %c has been changed outside the customize buffer." "\
1423 something in this group has been changed outside customize.")
1424 (saved "!" custom-saved-face "\
1425 this %c has been set and saved." "\
1426 something in this group has been set and saved.")
1427 (rogue "@" custom-rogue-face "\
1428 this %c has not been changed with customize." "\
1429 something in this group is not prepared for customization.")
1430 (standard " " nil "\
1431 this %c is unchanged from its standard setting." "\
1432 visible group members are all at standard settings."))
1433 "Alist of customize option states.
1434 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1435
1436 STATE is one of the following symbols:
1437
1438 `nil'
1439 For internal use, should never occur.
1440 `unknown'
1441 For internal use, should never occur.
1442 `hidden'
1443 This item is not being displayed.
1444 `invalid'
1445 This item is modified, but has an invalid form.
1446 `modified'
1447 This item is modified, and has a valid form.
1448 `set'
1449 This item has been set but not saved.
1450 `changed'
1451 The current value of this item has been changed temporarily.
1452 `saved'
1453 This item is marked for saving.
1454 `rogue'
1455 This item has no customization information.
1456 `standard'
1457 This item is unchanged from the standard setting.
1458
1459 MAGIC is a string used to present that state.
1460
1461 FACE is a face used to present the state.
1462
1463 ITEM-DESC is a string describing the state for options.
1464
1465 GROUP-DESC is a string describing the state for groups. If this is
1466 left out, ITEM-DESC will be used.
1467
1468 The string %c in either description will be replaced with the
1469 category of the item. These are `group'. `option', and `face'.
1470
1471 The list should be sorted most significant first.")
1472
1473 (defcustom custom-magic-show 'long
1474 "If non-nil, show textual description of the state.
1475 If `long', show a full-line description, not just one word."
1476 :type '(choice (const :tag "no" nil)
1477 (const long)
1478 (other :tag "short" short))
1479 :group 'custom-buffer)
1480
1481 (defcustom custom-magic-show-hidden '(option face)
1482 "Control whether the State button is shown for hidden items.
1483 The value should be a list with the custom categories where the State
1484 button should be visible. Possible categories are `group', `option',
1485 and `face'."
1486 :type '(set (const group) (const option) (const face))
1487 :group 'custom-buffer)
1488
1489 (defcustom custom-magic-show-button nil
1490 "Show a \"magic\" button indicating the state of each customization option."
1491 :type 'boolean
1492 :group 'custom-buffer)
1493
1494 (define-widget 'custom-magic 'default
1495 "Show and manipulate state for a customization option."
1496 :format "%v"
1497 :action 'widget-parent-action
1498 :notify 'ignore
1499 :value-get 'ignore
1500 :value-create 'custom-magic-value-create
1501 :value-delete 'widget-children-value-delete)
1502
1503 (defun widget-magic-mouse-down-action (widget &optional event)
1504 ;; Non-nil unless hidden.
1505 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1506 :custom-state)
1507 'hidden)))
1508
1509 (defun custom-magic-value-create (widget)
1510 ;; Create compact status report for WIDGET.
1511 (let* ((parent (widget-get widget :parent))
1512 (state (widget-get parent :custom-state))
1513 (hidden (eq state 'hidden))
1514 (entry (assq state custom-magic-alist))
1515 (magic (nth 1 entry))
1516 (face (nth 2 entry))
1517 (category (widget-get parent :custom-category))
1518 (text (or (and (eq category 'group)
1519 (nth 4 entry))
1520 (nth 3 entry)))
1521 (form (widget-get parent :custom-form))
1522 children)
1523 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1524 (setq text (concat (match-string 1 text)
1525 (symbol-name category)
1526 (match-string 2 text))))
1527 (when (and custom-magic-show
1528 (or (not hidden)
1529 (memq category custom-magic-show-hidden)))
1530 (insert " ")
1531 (when (and (eq category 'group)
1532 (not (and (eq custom-buffer-style 'links)
1533 (> (widget-get parent :custom-level) 1))))
1534 (insert-char ?\ (* custom-buffer-indent
1535 (widget-get parent :custom-level))))
1536 (push (widget-create-child-and-convert
1537 widget 'choice-item
1538 :help-echo "Change the state of this item."
1539 :format (if hidden "%t" "%[%t%]")
1540 :button-prefix 'widget-push-button-prefix
1541 :button-suffix 'widget-push-button-suffix
1542 :mouse-down-action 'widget-magic-mouse-down-action
1543 :tag "State")
1544 children)
1545 (insert ": ")
1546 (let ((start (point)))
1547 (if (eq custom-magic-show 'long)
1548 (insert text)
1549 (insert (symbol-name state)))
1550 (cond ((eq form 'lisp)
1551 (insert " (lisp)"))
1552 ((eq form 'mismatch)
1553 (insert " (mismatch)")))
1554 (put-text-property start (point) 'face 'custom-state-face))
1555 (insert "\n"))
1556 (when (and (eq category 'group)
1557 (not (and (eq custom-buffer-style 'links)
1558 (> (widget-get parent :custom-level) 1))))
1559 (insert-char ?\ (* custom-buffer-indent
1560 (widget-get parent :custom-level))))
1561 (when custom-magic-show-button
1562 (when custom-magic-show
1563 (let ((indent (widget-get parent :indent)))
1564 (when indent
1565 (insert-char ? indent))))
1566 (push (widget-create-child-and-convert
1567 widget 'choice-item
1568 :mouse-down-action 'widget-magic-mouse-down-action
1569 :button-face face
1570 :button-prefix ""
1571 :button-suffix ""
1572 :help-echo "Change the state."
1573 :format (if hidden "%t" "%[%t%]")
1574 :tag (if (memq form '(lisp mismatch))
1575 (concat "(" magic ")")
1576 (concat "[" magic "]")))
1577 children)
1578 (insert " "))
1579 (widget-put widget :children children)))
1580
1581 (defun custom-magic-reset (widget)
1582 "Redraw the :custom-magic property of WIDGET."
1583 (let ((magic (widget-get widget :custom-magic)))
1584 (widget-value-set magic (widget-value magic))))
1585
1586 ;;; The `custom' Widget.
1587
1588 (defface custom-button-face nil
1589 "Face used for buttons in customization buffers."
1590 :group 'custom-faces)
1591
1592 (defface custom-documentation-face nil
1593 "Face used for documentation strings in customization buffers."
1594 :group 'custom-faces)
1595
1596 (defface custom-state-face '((((class color)
1597 (background dark))
1598 (:foreground "lime green"))
1599 (((class color)
1600 (background light))
1601 (:foreground "dark green"))
1602 (t nil))
1603 "Face used for State descriptions in the customize buffer."
1604 :group 'custom-faces)
1605
1606 (define-widget 'custom 'default
1607 "Customize a user option."
1608 :format "%v"
1609 :convert-widget 'custom-convert-widget
1610 :notify 'custom-notify
1611 :custom-prefix ""
1612 :custom-level 1
1613 :custom-state 'hidden
1614 :documentation-property 'widget-subclass-responsibility
1615 :value-create 'widget-subclass-responsibility
1616 :value-delete 'widget-children-value-delete
1617 :value-get 'widget-value-value-get
1618 :validate 'widget-children-validate
1619 :match (lambda (widget value) (symbolp value)))
1620
1621 (defun custom-convert-widget (widget)
1622 ;; Initialize :value and :tag from :args in WIDGET.
1623 (let ((args (widget-get widget :args)))
1624 (when args
1625 (widget-put widget :value (widget-apply widget
1626 :value-to-internal (car args)))
1627 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1628 (widget-put widget :args nil)))
1629 widget)
1630
1631 (defun custom-notify (widget &rest args)
1632 "Keep track of changes."
1633 (let ((state (widget-get widget :custom-state)))
1634 (unless (eq state 'modified)
1635 (unless (memq state '(nil unknown hidden))
1636 (widget-put widget :custom-state 'modified))
1637 (custom-magic-reset widget)
1638 (apply 'widget-default-notify widget args))))
1639
1640 (defun custom-redraw (widget)
1641 "Redraw WIDGET with current settings."
1642 (let ((line (count-lines (point-min) (point)))
1643 (column (current-column))
1644 (pos (point))
1645 (from (marker-position (widget-get widget :from)))
1646 (to (marker-position (widget-get widget :to))))
1647 (save-excursion
1648 (widget-value-set widget (widget-value widget))
1649 (custom-redraw-magic widget))
1650 (when (and (>= pos from) (<= pos to))
1651 (condition-case nil
1652 (progn
1653 (if (> column 0)
1654 (goto-line line)
1655 (goto-line (1+ line)))
1656 (move-to-column column))
1657 (error nil)))))
1658
1659 (defun custom-redraw-magic (widget)
1660 "Redraw WIDGET state with current settings."
1661 (while widget
1662 (let ((magic (widget-get widget :custom-magic)))
1663 (cond (magic
1664 (widget-value-set magic (widget-value magic))
1665 (when (setq widget (widget-get widget :group))
1666 (custom-group-state-update widget)))
1667 (t
1668 (setq widget nil)))))
1669 (widget-setup))
1670
1671 (defun custom-show (widget value)
1672 "Non-nil if WIDGET should be shown with VALUE by default."
1673 (let ((show (widget-get widget :custom-show)))
1674 (cond ((null show)
1675 nil)
1676 ((eq t show)
1677 t)
1678 (t
1679 (funcall show widget value)))))
1680
1681 (defvar custom-load-recursion nil
1682 "Hack to avoid recursive dependencies.")
1683
1684 (defun custom-load-symbol (symbol)
1685 "Load all dependencies for SYMBOL."
1686 (unless custom-load-recursion
1687 (let ((custom-load-recursion t)
1688 (loads (get symbol 'custom-loads))
1689 load)
1690 (while loads
1691 (setq load (car loads)
1692 loads (cdr loads))
1693 (cond ((symbolp load)
1694 (condition-case nil
1695 (require load)
1696 (error nil)))
1697 ;; Don't reload a file already loaded.
1698 ((and (boundp 'preloaded-file-list)
1699 (member load preloaded-file-list)))
1700 ((assoc load load-history))
1701 ((assoc (locate-library load) load-history))
1702 (t
1703 (condition-case nil
1704 ;; Without this, we would load cus-edit recursively.
1705 ;; We are still loading it when we call this,
1706 ;; and it is not in load-history yet.
1707 (or (equal load "cus-edit")
1708 (load-library load))
1709 (error nil))))))))
1710
1711 (defun custom-load-widget (widget)
1712 "Load all dependencies for WIDGET."
1713 (custom-load-symbol (widget-value widget)))
1714
1715 (defun custom-unloaded-symbol-p (symbol)
1716 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1717 (let ((found nil)
1718 (loads (get symbol 'custom-loads))
1719 load)
1720 (while loads
1721 (setq load (car loads)
1722 loads (cdr loads))
1723 (cond ((symbolp load)
1724 (unless (featurep load)
1725 (setq found t)))
1726 ((assoc load load-history))
1727 ((assoc (locate-library load) load-history)
1728 (message nil))
1729 (t
1730 (setq found t))))
1731 found))
1732
1733 (defun custom-unloaded-widget-p (widget)
1734 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1735 (custom-unloaded-symbol-p (widget-value widget)))
1736
1737 (defun custom-toggle-hide (widget)
1738 "Toggle visibility of WIDGET."
1739 (custom-load-widget widget)
1740 (let ((state (widget-get widget :custom-state)))
1741 (cond ((memq state '(invalid modified))
1742 (error "There are unset changes"))
1743 ((eq state 'hidden)
1744 (widget-put widget :custom-state 'unknown))
1745 (t
1746 (widget-put widget :documentation-shown nil)
1747 (widget-put widget :custom-state 'hidden)))
1748 (custom-redraw widget)
1749 (widget-setup)))
1750
1751 (defun custom-toggle-parent (widget &rest ignore)
1752 "Toggle visibility of parent of WIDGET."
1753 (custom-toggle-hide (widget-get widget :parent)))
1754
1755 (defun custom-add-see-also (widget &optional prefix)
1756 "Add `See also ...' to WIDGET if there are any links.
1757 Insert PREFIX first if non-nil."
1758 (let* ((symbol (widget-get widget :value))
1759 (links (get symbol 'custom-links))
1760 (many (> (length links) 2))
1761 (buttons (widget-get widget :buttons))
1762 (indent (widget-get widget :indent)))
1763 (when links
1764 (when indent
1765 (insert-char ?\ indent))
1766 (when prefix
1767 (insert prefix))
1768 (insert "See also ")
1769 (while links
1770 (push (widget-create-child-and-convert widget (car links))
1771 buttons)
1772 (setq links (cdr links))
1773 (cond ((null links)
1774 (insert ".\n"))
1775 ((null (cdr links))
1776 (if many
1777 (insert ", and ")
1778 (insert " and ")))
1779 (t
1780 (insert ", "))))
1781 (widget-put widget :buttons buttons))))
1782
1783 (defun custom-add-parent-links (widget &optional initial-string)
1784 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1785 The value if non-nil if any parents were found.
1786 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1787 (let ((name (widget-value widget))
1788 (type (widget-type widget))
1789 (buttons (widget-get widget :buttons))
1790 (start (point))
1791 found)
1792 (insert (or initial-string "Parent groups:"))
1793 (mapatoms (lambda (symbol)
1794 (let ((entry (assq name (get symbol 'custom-group))))
1795 (when (eq (nth 1 entry) type)
1796 (insert " ")
1797 (push (widget-create-child-and-convert
1798 widget 'custom-group-link
1799 :tag (custom-unlispify-tag-name symbol)
1800 symbol)
1801 buttons)
1802 (setq found t)))))
1803 (widget-put widget :buttons buttons)
1804 (if found
1805 (insert "\n")
1806 (delete-region start (point)))
1807 found))
1808
1809 ;;; The `custom-variable' Widget.
1810
1811 (defface custom-variable-tag-face '((((class color)
1812 (background dark))
1813 (:foreground "light blue" :underline t))
1814 (((class color)
1815 (background light))
1816 (:foreground "blue" :underline t))
1817 (t (:underline t)))
1818 "Face used for unpushable variable tags."
1819 :group 'custom-faces)
1820
1821 (defface custom-variable-button-face '((t (:underline t :bold t)))
1822 "Face used for pushable variable tags."
1823 :group 'custom-faces)
1824
1825 (defcustom custom-variable-default-form 'edit
1826 "Default form of displaying variable values."
1827 :type '(choice (const edit)
1828 (const lisp))
1829 :group 'custom-buffer
1830 :version "20.3")
1831
1832 (define-widget 'custom-variable 'custom
1833 "Customize variable."
1834 :format "%v"
1835 :help-echo "Set or reset this variable."
1836 :documentation-property 'variable-documentation
1837 :custom-category 'option
1838 :custom-state nil
1839 :custom-menu 'custom-variable-menu-create
1840 :custom-form nil ; defaults to value of `custom-variable-default-form'
1841 :value-create 'custom-variable-value-create
1842 :action 'custom-variable-action
1843 :custom-set 'custom-variable-set
1844 :custom-save 'custom-variable-save
1845 :custom-reset-current 'custom-redraw
1846 :custom-reset-saved 'custom-variable-reset-saved
1847 :custom-reset-standard 'custom-variable-reset-standard)
1848
1849 (defun custom-variable-type (symbol)
1850 "Return a widget suitable for editing the value of SYMBOL.
1851 If SYMBOL has a `custom-type' property, use that.
1852 Otherwise, look up symbol in `custom-guess-type-alist'."
1853 (let* ((type (or (get symbol 'custom-type)
1854 (and (not (get symbol 'standard-value))
1855 (custom-guess-type symbol))
1856 'sexp))
1857 (options (get symbol 'custom-options))
1858 (tmp (if (listp type)
1859 (copy-sequence type)
1860 (list type))))
1861 (when options
1862 (widget-put tmp :options options))
1863 tmp))
1864
1865 (defun custom-variable-value-create (widget)
1866 "Here is where you edit the variables value."
1867 (custom-load-widget widget)
1868 (unless (widget-get widget :custom-form)
1869 (widget-put widget :custom-form custom-variable-default-form))
1870 (let* ((buttons (widget-get widget :buttons))
1871 (children (widget-get widget :children))
1872 (form (widget-get widget :custom-form))
1873 (state (widget-get widget :custom-state))
1874 (symbol (widget-get widget :value))
1875 (tag (widget-get widget :tag))
1876 (type (custom-variable-type symbol))
1877 (conv (widget-convert type))
1878 (get (or (get symbol 'custom-get) 'default-value))
1879 (prefix (widget-get widget :custom-prefix))
1880 (last (widget-get widget :custom-last))
1881 (value (if (default-boundp symbol)
1882 (funcall get symbol)
1883 (widget-get conv :value))))
1884 ;; If the widget is new, the child determine whether it is hidden.
1885 (cond (state)
1886 ((custom-show type value)
1887 (setq state 'unknown))
1888 (t
1889 (setq state 'hidden)))
1890 ;; If we don't know the state, see if we need to edit it in lisp form.
1891 (when (eq state 'unknown)
1892 (unless (widget-apply conv :match value)
1893 ;; (widget-apply (widget-convert type) :match value)
1894 (setq form 'mismatch)))
1895 ;; Now we can create the child widget.
1896 (cond ((eq custom-buffer-style 'tree)
1897 (insert prefix (if last " `--- " " |--- "))
1898 (push (widget-create-child-and-convert
1899 widget 'custom-browse-variable-tag)
1900 buttons)
1901 (insert " " tag "\n")
1902 (widget-put widget :buttons buttons))
1903 ((eq state 'hidden)
1904 ;; Indicate hidden value.
1905 (push (widget-create-child-and-convert
1906 widget 'item
1907 :format "%{%t%}: "
1908 :sample-face 'custom-variable-tag-face
1909 :tag tag
1910 :parent widget)
1911 buttons)
1912 (push (widget-create-child-and-convert
1913 widget 'visibility
1914 :help-echo "Show the value of this option."
1915 :action 'custom-toggle-parent
1916 nil)
1917 buttons))
1918 ((memq form '(lisp mismatch))
1919 ;; In lisp mode edit the saved value when possible.
1920 (let* ((value (cond ((get symbol 'saved-value)
1921 (car (get symbol 'saved-value)))
1922 ((get symbol 'standard-value)
1923 (car (get symbol 'standard-value)))
1924 ((default-boundp symbol)
1925 (custom-quote (funcall get symbol)))
1926 (t
1927 (custom-quote (widget-get conv :value))))))
1928 (insert (symbol-name symbol) ": ")
1929 (push (widget-create-child-and-convert
1930 widget 'visibility
1931 :help-echo "Hide the value of this option."
1932 :action 'custom-toggle-parent
1933 t)
1934 buttons)
1935 (insert " ")
1936 (push (widget-create-child-and-convert
1937 widget 'sexp
1938 :button-face 'custom-variable-button-face
1939 :format "%v"
1940 :tag (symbol-name symbol)
1941 :parent widget
1942 :value value)
1943 children)))
1944 (t
1945 ;; Edit mode.
1946 (let* ((format (widget-get type :format))
1947 tag-format value-format)
1948 (unless (string-match ":" format)
1949 (error "Bad format"))
1950 (setq tag-format (substring format 0 (match-end 0)))
1951 (setq value-format (substring format (match-end 0)))
1952 (push (widget-create-child-and-convert
1953 widget 'item
1954 :format tag-format
1955 :action 'custom-tag-action
1956 :help-echo "Change value of this option."
1957 :mouse-down-action 'custom-tag-mouse-down-action
1958 :button-face 'custom-variable-button-face
1959 :sample-face 'custom-variable-tag-face
1960 tag)
1961 buttons)
1962 (insert " ")
1963 (push (widget-create-child-and-convert
1964 widget 'visibility
1965 :help-echo "Hide the value of this option."
1966 :action 'custom-toggle-parent
1967 t)
1968 buttons)
1969 (push (widget-create-child-and-convert
1970 widget type
1971 :format value-format
1972 :value value)
1973 children))))
1974 (unless (eq custom-buffer-style 'tree)
1975 ;; Now update the state.
1976 (unless (eq (preceding-char) ?\n)
1977 (widget-insert "\n"))
1978 (if (eq state 'hidden)
1979 (widget-put widget :custom-state state)
1980 (custom-variable-state-set widget))
1981 ;; Create the magic button.
1982 (let ((magic (widget-create-child-and-convert
1983 widget 'custom-magic nil)))
1984 (widget-put widget :custom-magic magic)
1985 (push magic buttons))
1986 ;; Update properties.
1987 (widget-put widget :custom-form form)
1988 (widget-put widget :buttons buttons)
1989 (widget-put widget :children children)
1990 ;; Insert documentation.
1991 (widget-default-format-handler widget ?h)
1992 ;; See also.
1993 (unless (eq state 'hidden)
1994 (when (eq (widget-get widget :custom-level) 1)
1995 (custom-add-parent-links widget))
1996 (custom-add-see-also widget)))))
1997
1998 (defun custom-tag-action (widget &rest args)
1999 "Pass :action to first child of WIDGET's parent."
2000 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2001 :action args))
2002
2003 (defun custom-tag-mouse-down-action (widget &rest args)
2004 "Pass :mouse-down-action to first child of WIDGET's parent."
2005 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2006 :mouse-down-action args))
2007
2008 (defun custom-variable-state-set (widget)
2009 "Set the state of WIDGET."
2010 (let* ((symbol (widget-value widget))
2011 (get (or (get symbol 'custom-get) 'default-value))
2012 (value (if (default-boundp symbol)
2013 (funcall get symbol)
2014 (widget-get widget :value)))
2015 tmp
2016 (state (cond ((setq tmp (get symbol 'customized-value))
2017 (if (condition-case nil
2018 (equal value (eval (car tmp)))
2019 (error nil))
2020 'set
2021 'changed))
2022 ((setq tmp (get symbol 'saved-value))
2023 (if (condition-case nil
2024 (equal value (eval (car tmp)))
2025 (error nil))
2026 'saved
2027 'changed))
2028 ((setq tmp (get symbol 'standard-value))
2029 (if (condition-case nil
2030 (equal value (eval (car tmp)))
2031 (error nil))
2032 'standard
2033 'changed))
2034 (t 'rogue))))
2035 (widget-put widget :custom-state state)))
2036
2037 (defvar custom-variable-menu
2038 '(("Set for Current Session" custom-variable-set
2039 (lambda (widget)
2040 (eq (widget-get widget :custom-state) 'modified)))
2041 ("Save for Future Sessions" custom-variable-save
2042 (lambda (widget)
2043 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2044 ("Reset to Current" custom-redraw
2045 (lambda (widget)
2046 (and (default-boundp (widget-value widget))
2047 (memq (widget-get widget :custom-state) '(modified changed)))))
2048 ("Reset to Saved" custom-variable-reset-saved
2049 (lambda (widget)
2050 (and (get (widget-value widget) 'saved-value)
2051 (memq (widget-get widget :custom-state)
2052 '(modified set changed rogue)))))
2053 ("Reset to Standard Settings" custom-variable-reset-standard
2054 (lambda (widget)
2055 (and (get (widget-value widget) 'standard-value)
2056 (memq (widget-get widget :custom-state)
2057 '(modified set changed saved rogue)))))
2058 ("---" ignore ignore)
2059 ("Don't show as Lisp expression" custom-variable-edit
2060 (lambda (widget)
2061 (eq (widget-get widget :custom-form) 'lisp)))
2062 ("Show initial Lisp expression" custom-variable-edit-lisp
2063 (lambda (widget)
2064 (eq (widget-get widget :custom-form) 'edit))))
2065 "Alist of actions for the `custom-variable' widget.
2066 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2067 the menu entry, ACTION is the function to call on the widget when the
2068 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2069 widget as an argument, and returns non-nil if ACTION is valid on that
2070 widget. If FILTER is nil, ACTION is always valid.")
2071
2072 (defun custom-variable-action (widget &optional event)
2073 "Show the menu for `custom-variable' WIDGET.
2074 Optional EVENT is the location for the menu."
2075 (if (eq (widget-get widget :custom-state) 'hidden)
2076 (custom-toggle-hide widget)
2077 (unless (eq (widget-get widget :custom-state) 'modified)
2078 (custom-variable-state-set widget))
2079 (custom-redraw-magic widget)
2080 (let* ((completion-ignore-case t)
2081 (answer (widget-choose (concat "Operation on "
2082 (custom-unlispify-tag-name
2083 (widget-get widget :value)))
2084 (custom-menu-filter custom-variable-menu
2085 widget)
2086 event)))
2087 (if answer
2088 (funcall answer widget)))))
2089
2090 (defun custom-variable-edit (widget)
2091 "Edit value of WIDGET."
2092 (widget-put widget :custom-state 'unknown)
2093 (widget-put widget :custom-form 'edit)
2094 (custom-redraw widget))
2095
2096 (defun custom-variable-edit-lisp (widget)
2097 "Edit the lisp representation of the value of WIDGET."
2098 (widget-put widget :custom-state 'unknown)
2099 (widget-put widget :custom-form 'lisp)
2100 (custom-redraw widget))
2101
2102 (defun custom-variable-set (widget)
2103 "Set the current value for the variable being edited by WIDGET."
2104 (let* ((form (widget-get widget :custom-form))
2105 (state (widget-get widget :custom-state))
2106 (child (car (widget-get widget :children)))
2107 (symbol (widget-value widget))
2108 (set (or (get symbol 'custom-set) 'set-default))
2109 val)
2110 (cond ((eq state 'hidden)
2111 (error "Cannot set hidden variable"))
2112 ((setq val (widget-apply child :validate))
2113 (goto-char (widget-get val :from))
2114 (error "%s" (widget-get val :error)))
2115 ((memq form '(lisp mismatch))
2116 (funcall set symbol (eval (setq val (widget-value child))))
2117 (put symbol 'customized-value (list val)))
2118 (t
2119 (funcall set symbol (setq val (widget-value child)))
2120 (put symbol 'customized-value (list (custom-quote val)))))
2121 (custom-variable-state-set widget)
2122 (custom-redraw-magic widget)))
2123
2124 (defun custom-variable-save (widget)
2125 "Set and save the value for the variable being edited by WIDGET."
2126 (let* ((form (widget-get widget :custom-form))
2127 (state (widget-get widget :custom-state))
2128 (child (car (widget-get widget :children)))
2129 (symbol (widget-value widget))
2130 (set (or (get symbol 'custom-set) 'set-default))
2131 val)
2132 (cond ((eq state 'hidden)
2133 (error "Cannot set hidden variable"))
2134 ((setq val (widget-apply child :validate))
2135 (goto-char (widget-get val :from))
2136 (error "%s" (widget-get val :error)))
2137 ((memq form '(lisp mismatch))
2138 (put symbol 'saved-value (list (widget-value child)))
2139 (funcall set symbol (eval (widget-value child))))
2140 (t
2141 (put symbol
2142 'saved-value (list (custom-quote (widget-value
2143 child))))
2144 (funcall set symbol (widget-value child))))
2145 (put symbol 'customized-value nil)
2146 (custom-save-all)
2147 (custom-variable-state-set widget)
2148 (custom-redraw-magic widget)))
2149
2150 (defun custom-variable-reset-saved (widget)
2151 "Restore the saved value for the variable being edited by WIDGET."
2152 (let* ((symbol (widget-value widget))
2153 (set (or (get symbol 'custom-set) 'set-default)))
2154 (if (get symbol 'saved-value)
2155 (condition-case nil
2156 (funcall set symbol (eval (car (get symbol 'saved-value))))
2157 (error nil))
2158 (error "No saved value for %s" symbol))
2159 (put symbol 'customized-value nil)
2160 (widget-put widget :custom-state 'unknown)
2161 (custom-redraw widget)))
2162
2163 (defun custom-variable-reset-standard (widget)
2164 "Restore the standard setting for the variable being edited by WIDGET."
2165 (let* ((symbol (widget-value widget))
2166 (set (or (get symbol 'custom-set) 'set-default)))
2167 (if (get symbol 'standard-value)
2168 (funcall set symbol (eval (car (get symbol 'standard-value))))
2169 (error "No standard setting known for %S" symbol))
2170 (put symbol 'customized-value nil)
2171 (when (get symbol 'saved-value)
2172 (put symbol 'saved-value nil)
2173 (custom-save-all))
2174 (widget-put widget :custom-state 'unknown)
2175 (custom-redraw widget)))
2176
2177 ;;; The `custom-face-edit' Widget.
2178
2179 (define-widget 'custom-face-edit 'checklist
2180 "Edit face attributes."
2181 :format "%t: %v"
2182 :tag "Attributes"
2183 :extra-offset 12
2184 :button-args '(:help-echo "Control whether this attribute have any effect.")
2185 :args (mapcar (lambda (att)
2186 (list 'group
2187 :inline t
2188 :sibling-args (widget-get (nth 1 att) :sibling-args)
2189 (list 'const :format "" :value (nth 0 att))
2190 (nth 1 att)))
2191 custom-face-attributes))
2192
2193 ;;; The `custom-display' Widget.
2194
2195 (define-widget 'custom-display 'menu-choice
2196 "Select a display type."
2197 :tag "Display"
2198 :value t
2199 :help-echo "Specify frames where the face attributes should be used."
2200 :args '((const :tag "all" t)
2201 (checklist
2202 :offset 0
2203 :extra-offset 9
2204 :args ((group :sibling-args (:help-echo "\
2205 Only match the specified window systems.")
2206 (const :format "Type: "
2207 type)
2208 (checklist :inline t
2209 :offset 0
2210 (const :format "X "
2211 :sibling-args (:help-echo "\
2212 The X11 Window System.")
2213 x)
2214 (const :format "PM "
2215 :sibling-args (:help-echo "\
2216 OS/2 Presentation Manager.")
2217 pm)
2218 (const :format "W32 "
2219 :sibling-args (:help-echo "\
2220 Windows NT/9X.")
2221 w32)
2222 (const :format "DOS "
2223 :sibling-args (:help-echo "\
2224 Plain MS-DOS.")
2225 pc)
2226 (const :format "TTY%n"
2227 :sibling-args (:help-echo "\
2228 Plain text terminals.")
2229 tty)))
2230 (group :sibling-args (:help-echo "\
2231 Only match the frames with the specified color support.")
2232 (const :format "Class: "
2233 class)
2234 (checklist :inline t
2235 :offset 0
2236 (const :format "Color "
2237 :sibling-args (:help-echo "\
2238 Match color frames.")
2239 color)
2240 (const :format "Grayscale "
2241 :sibling-args (:help-echo "\
2242 Match grayscale frames.")
2243 grayscale)
2244 (const :format "Monochrome%n"
2245 :sibling-args (:help-echo "\
2246 Match frames with no color support.")
2247 mono)))
2248 (group :sibling-args (:help-echo "\
2249 Only match frames with the specified intensity.")
2250 (const :format "\
2251 Background brightness: "
2252 background)
2253 (checklist :inline t
2254 :offset 0
2255 (const :format "Light "
2256 :sibling-args (:help-echo "\
2257 Match frames with light backgrounds.")
2258 light)
2259 (const :format "Dark\n"
2260 :sibling-args (:help-echo "\
2261 Match frames with dark backgrounds.")
2262 dark)))))))
2263
2264 ;;; The `custom-face' Widget.
2265
2266 (defface custom-face-tag-face '((t (:underline t)))
2267 "Face used for face tags."
2268 :group 'custom-faces)
2269
2270 (defcustom custom-face-default-form 'selected
2271 "Default form of displaying face definition."
2272 :type '(choice (const all)
2273 (const selected)
2274 (const lisp))
2275 :group 'custom-buffer
2276 :version "20.3")
2277
2278 (define-widget 'custom-face 'custom
2279 "Customize face."
2280 :sample-face 'custom-face-tag-face
2281 :help-echo "Set or reset this face."
2282 :documentation-property '(lambda (face)
2283 (face-doc-string face))
2284 :value-create 'custom-face-value-create
2285 :action 'custom-face-action
2286 :custom-category 'face
2287 :custom-form nil ; defaults to value of `custom-face-default-form'
2288 :custom-set 'custom-face-set
2289 :custom-save 'custom-face-save
2290 :custom-reset-current 'custom-redraw
2291 :custom-reset-saved 'custom-face-reset-saved
2292 :custom-reset-standard 'custom-face-reset-standard
2293 :custom-menu 'custom-face-menu-create)
2294
2295 (define-widget 'custom-face-all 'editable-list
2296 "An editable list of display specifications and attributes."
2297 :entry-format "%i %d %v"
2298 :insert-button-args '(:help-echo "Insert new display specification here.")
2299 :append-button-args '(:help-echo "Append new display specification here.")
2300 :delete-button-args '(:help-echo "Delete this display specification.")
2301 :args '((group :format "%v" custom-display custom-face-edit)))
2302
2303 (defconst custom-face-all (widget-convert 'custom-face-all)
2304 "Converted version of the `custom-face-all' widget.")
2305
2306 (define-widget 'custom-display-unselected 'item
2307 "A display specification that doesn't match the selected display."
2308 :match 'custom-display-unselected-match)
2309
2310 (defun custom-display-unselected-match (widget value)
2311 "Non-nil if VALUE is an unselected display specification."
2312 (not (face-spec-set-match-display value (selected-frame))))
2313
2314 (define-widget 'custom-face-selected 'group
2315 "Edit the attributes of the selected display in a face specification."
2316 :args '((repeat :format ""
2317 :inline t
2318 (group custom-display-unselected sexp))
2319 (group (sexp :format "") custom-face-edit)
2320 (repeat :format ""
2321 :inline t
2322 sexp)))
2323
2324 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2325 "Converted version of the `custom-face-selected' widget.")
2326
2327 (defun custom-face-value-create (widget)
2328 "Create a list of the display specifications for WIDGET."
2329 (let ((buttons (widget-get widget :buttons))
2330 (symbol (widget-get widget :value))
2331 (tag (widget-get widget :tag))
2332 (state (widget-get widget :custom-state))
2333 (begin (point))
2334 (is-last (widget-get widget :custom-last))
2335 (prefix (widget-get widget :custom-prefix)))
2336 (unless tag
2337 (setq tag (prin1-to-string symbol)))
2338 (cond ((eq custom-buffer-style 'tree)
2339 (insert prefix (if is-last " `--- " " |--- "))
2340 (push (widget-create-child-and-convert
2341 widget 'custom-browse-face-tag)
2342 buttons)
2343 (insert " " tag "\n")
2344 (widget-put widget :buttons buttons))
2345 (t
2346 ;; Create tag.
2347 (insert tag)
2348 (if (eq custom-buffer-style 'face)
2349 (insert " ")
2350 (widget-specify-sample widget begin (point))
2351 (insert ": "))
2352 ;; Sample.
2353 (and (string-match "XEmacs" emacs-version)
2354 ;; XEmacs cannot display uninitialized faces.
2355 (not (custom-facep symbol))
2356 (copy-face 'custom-face-empty symbol))
2357 (push (widget-create-child-and-convert widget 'item
2358 :format "(%{%t%})"
2359 :sample-face symbol
2360 :tag "sample")
2361 buttons)
2362 ;; Visibility.
2363 (insert " ")
2364 (push (widget-create-child-and-convert
2365 widget 'visibility
2366 :help-echo "Hide or show this face."
2367 :action 'custom-toggle-parent
2368 (not (eq state 'hidden)))
2369 buttons)
2370 ;; Magic.
2371 (insert "\n")
2372 (let ((magic (widget-create-child-and-convert
2373 widget 'custom-magic nil)))
2374 (widget-put widget :custom-magic magic)
2375 (push magic buttons))
2376 ;; Update buttons.
2377 (widget-put widget :buttons buttons)
2378 ;; Insert documentation.
2379 (widget-default-format-handler widget ?h)
2380 ;; See also.
2381 (unless (eq state 'hidden)
2382 (when (eq (widget-get widget :custom-level) 1)
2383 (custom-add-parent-links widget))
2384 (custom-add-see-also widget))
2385 ;; Editor.
2386 (unless (eq (preceding-char) ?\n)
2387 (insert "\n"))
2388 (unless (eq state 'hidden)
2389 (message "Creating face editor...")
2390 (custom-load-widget widget)
2391 (unless (widget-get widget :custom-form)
2392 (widget-put widget :custom-form custom-face-default-form))
2393 (let* ((symbol (widget-value widget))
2394 (spec (or (get symbol 'saved-face)
2395 (get symbol 'face-defface-spec)
2396 ;; Attempt to construct it.
2397 (list (list t (custom-face-attributes-get
2398 symbol (selected-frame))))))
2399 (form (widget-get widget :custom-form))
2400 (indent (widget-get widget :indent))
2401 edit)
2402 ;; If the user has changed this face in some other way,
2403 ;; edit it as the user has specified it.
2404 (if (not (face-spec-match-p symbol spec (selected-frame)))
2405 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
2406 (setq edit (widget-create-child-and-convert
2407 widget
2408 (cond ((and (eq form 'selected)
2409 (widget-apply custom-face-selected
2410 :match spec))
2411 (when indent (insert-char ?\ indent))
2412 'custom-face-selected)
2413 ((and (not (eq form 'lisp))
2414 (widget-apply custom-face-all
2415 :match spec))
2416 'custom-face-all)
2417 (t
2418 (when indent (insert-char ?\ indent))
2419 'sexp))
2420 :value spec))
2421 (custom-face-state-set widget)
2422 (widget-put widget :children (list edit)))
2423 (message "Creating face editor...done"))))))
2424
2425 (defvar custom-face-menu
2426 '(("Set for Current Session" custom-face-set)
2427 ("Save for Future Sessions" custom-face-save-command)
2428 ("Reset to Saved" custom-face-reset-saved
2429 (lambda (widget)
2430 (get (widget-value widget) 'saved-face)))
2431 ("Reset to Standard Setting" custom-face-reset-standard
2432 (lambda (widget)
2433 (get (widget-value widget) 'face-defface-spec)))
2434 ("---" ignore ignore)
2435 ("Show all display specs" custom-face-edit-all
2436 (lambda (widget)
2437 (not (eq (widget-get widget :custom-form) 'all))))
2438 ("Just current attributes" custom-face-edit-selected
2439 (lambda (widget)
2440 (not (eq (widget-get widget :custom-form) 'selected))))
2441 ("Show as Lisp expression" custom-face-edit-lisp
2442 (lambda (widget)
2443 (not (eq (widget-get widget :custom-form) 'lisp)))))
2444 "Alist of actions for the `custom-face' widget.
2445 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2446 the menu entry, ACTION is the function to call on the widget when the
2447 menu is selected, and FILTER is a predicate which takes a `custom-face'
2448 widget as an argument, and returns non-nil if ACTION is valid on that
2449 widget. If FILTER is nil, ACTION is always valid.")
2450
2451 (defun custom-face-edit-selected (widget)
2452 "Edit selected attributes of the value of WIDGET."
2453 (widget-put widget :custom-state 'unknown)
2454 (widget-put widget :custom-form 'selected)
2455 (custom-redraw widget))
2456
2457 (defun custom-face-edit-all (widget)
2458 "Edit all attributes of the value of WIDGET."
2459 (widget-put widget :custom-state 'unknown)
2460 (widget-put widget :custom-form 'all)
2461 (custom-redraw widget))
2462
2463 (defun custom-face-edit-lisp (widget)
2464 "Edit the lisp representation of the value of WIDGET."
2465 (widget-put widget :custom-state 'unknown)
2466 (widget-put widget :custom-form 'lisp)
2467 (custom-redraw widget))
2468
2469 (defun custom-face-state-set (widget)
2470 "Set the state of WIDGET."
2471 (let ((symbol (widget-value widget)))
2472 (widget-put widget :custom-state (cond ((get symbol 'customized-face)
2473 'set)
2474 ((get symbol 'saved-face)
2475 'saved)
2476 ((get symbol 'face-defface-spec)
2477 'standard)
2478 (t
2479 'rogue)))))
2480
2481 (defun custom-face-action (widget &optional event)
2482 "Show the menu for `custom-face' WIDGET.
2483 Optional EVENT is the location for the menu."
2484 (if (eq (widget-get widget :custom-state) 'hidden)
2485 (custom-toggle-hide widget)
2486 (let* ((completion-ignore-case t)
2487 (symbol (widget-get widget :value))
2488 (answer (widget-choose (concat "Operation on "
2489 (custom-unlispify-tag-name symbol))
2490 (custom-menu-filter custom-face-menu
2491 widget)
2492 event)))
2493 (if answer
2494 (funcall answer widget)))))
2495
2496 (defun custom-face-set (widget)
2497 "Make the face attributes in WIDGET take effect."
2498 (let* ((symbol (widget-value widget))
2499 (child (car (widget-get widget :children)))
2500 (value (widget-value child)))
2501 (put symbol 'customized-face value)
2502 (face-spec-set symbol value)
2503 (custom-face-state-set widget)
2504 (custom-redraw-magic widget)))
2505
2506 (defun custom-face-save-command (widget)
2507 "Save in `.emacs' the face attributes in WIDGET."
2508 (custom-face-save widget)
2509 (custom-save-all))
2510
2511 (defun custom-face-save (widget)
2512 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2513 (let* ((symbol (widget-value widget))
2514 (child (car (widget-get widget :children)))
2515 (value (widget-value child)))
2516 (face-spec-set symbol value)
2517 (put symbol 'saved-face value)
2518 (put symbol 'customized-face nil)
2519 (custom-save-all)
2520 (custom-face-state-set widget)
2521 (custom-redraw-magic widget)))
2522
2523 (defun custom-face-reset-saved (widget)
2524 "Restore WIDGET to the face's default attributes."
2525 (let* ((symbol (widget-value widget))
2526 (child (car (widget-get widget :children)))
2527 (value (get symbol 'saved-face)))
2528 (unless value
2529 (error "No saved value for this face"))
2530 (put symbol 'customized-face nil)
2531 (face-spec-set symbol value)
2532 (widget-value-set child value)
2533 (custom-face-state-set widget)
2534 (custom-redraw-magic widget)))
2535
2536 (defun custom-face-reset-standard (widget)
2537 "Restore WIDGET to the face's standard settings."
2538 (let* ((symbol (widget-value widget))
2539 (child (car (widget-get widget :children)))
2540 (value (get symbol 'face-defface-spec)))
2541 (unless value
2542 (error "No standard setting for this face"))
2543 (put symbol 'customized-face nil)
2544 (when (get symbol 'saved-face)
2545 (put symbol 'saved-face nil)
2546 (custom-save-all))
2547 (face-spec-set symbol value)
2548 (widget-value-set child value)
2549 (custom-face-state-set widget)
2550 (custom-redraw-magic widget)))
2551
2552 ;;; The `face' Widget.
2553
2554 (define-widget 'face 'default
2555 "Select and customize a face."
2556 :convert-widget 'widget-value-convert-widget
2557 :button-prefix 'widget-push-button-prefix
2558 :button-suffix 'widget-push-button-suffix
2559 :format "%t: %[select face%] %v"
2560 :tag "Face"
2561 :value 'default
2562 :value-create 'widget-face-value-create
2563 :value-delete 'widget-face-value-delete
2564 :value-get 'widget-value-value-get
2565 :validate 'widget-children-validate
2566 :action 'widget-face-action
2567 :match '(lambda (widget value) (symbolp value)))
2568
2569 (defun widget-face-value-create (widget)
2570 ;; Create a `custom-face' child.
2571 (let* ((symbol (widget-value widget))
2572 (custom-buffer-style 'face)
2573 (child (widget-create-child-and-convert
2574 widget 'custom-face
2575 :custom-level nil
2576 :value symbol)))
2577 (custom-magic-reset child)
2578 (setq custom-options (cons child custom-options))
2579 (widget-put widget :children (list child))))
2580
2581 (defun widget-face-value-delete (widget)
2582 ;; Remove the child from the options.
2583 (let ((child (car (widget-get widget :children))))
2584 (setq custom-options (delq child custom-options))
2585 (widget-children-value-delete widget)))
2586
2587 (defvar face-history nil
2588 "History of entered face names.")
2589
2590 (defun widget-face-action (widget &optional event)
2591 "Prompt for a face."
2592 (let ((answer (completing-read "Face: "
2593 (mapcar (lambda (face)
2594 (list (symbol-name face)))
2595 (face-list))
2596 nil nil nil
2597 'face-history)))
2598 (unless (zerop (length answer))
2599 (widget-value-set widget (intern answer))
2600 (widget-apply widget :notify widget event)
2601 (widget-setup))))
2602
2603 ;;; The `hook' Widget.
2604
2605 (define-widget 'hook 'list
2606 "A emacs lisp hook"
2607 :value-to-internal (lambda (widget value)
2608 (if (and value (symbolp value))
2609 (list value)
2610 value))
2611 :match (lambda (widget value)
2612 (or (symbolp value)
2613 (widget-group-match widget value)))
2614 :convert-widget 'custom-hook-convert-widget
2615 :tag "Hook")
2616
2617 (defun custom-hook-convert-widget (widget)
2618 ;; Handle `:custom-options'.
2619 (let* ((options (widget-get widget :options))
2620 (other `(editable-list :inline t
2621 :entry-format "%i %d%v"
2622 (function :format " %v")))
2623 (args (if options
2624 (list `(checklist :inline t
2625 ,@(mapcar (lambda (entry)
2626 `(function-item ,entry))
2627 options))
2628 other)
2629 (list other))))
2630 (widget-put widget :args args)
2631 widget))
2632
2633 ;;; The `custom-group-link' Widget.
2634
2635 (define-widget 'custom-group-link 'link
2636 "Show parent in other window when activated."
2637 :help-echo "Create customization buffer for this group."
2638 :action 'custom-group-link-action)
2639
2640 (defun custom-group-link-action (widget &rest ignore)
2641 (customize-group (widget-value widget)))
2642
2643 ;;; The `custom-group' Widget.
2644
2645 (defcustom custom-group-tag-faces nil
2646 ;; In XEmacs, this ought to play games with font size.
2647 "Face used for group tags.
2648 The first member is used for level 1 groups, the second for level 2,
2649 and so forth. The remaining group tags are shown with
2650 `custom-group-tag-face'."
2651 :type '(repeat face)
2652 :group 'custom-faces)
2653
2654 (defface custom-group-tag-face-1 '((((class color)
2655 (background dark))
2656 (:foreground "pink" :underline t))
2657 (((class color)
2658 (background light))
2659 (:foreground "red" :underline t))
2660 (t (:underline t)))
2661 "Face used for group tags.")
2662
2663 (defface custom-group-tag-face '((((class color)
2664 (background dark))
2665 (:foreground "light blue" :underline t))
2666 (((class color)
2667 (background light))
2668 (:foreground "blue" :underline t))
2669 (t (:underline t)))
2670 "Face used for low level group tags."
2671 :group 'custom-faces)
2672
2673 (define-widget 'custom-group 'custom
2674 "Customize group."
2675 :format "%v"
2676 :sample-face-get 'custom-group-sample-face-get
2677 :documentation-property 'group-documentation
2678 :help-echo "Set or reset all members of this group."
2679 :value-create 'custom-group-value-create
2680 :action 'custom-group-action
2681 :custom-category 'group
2682 :custom-set 'custom-group-set
2683 :custom-save 'custom-group-save
2684 :custom-reset-current 'custom-group-reset-current
2685 :custom-reset-saved 'custom-group-reset-saved
2686 :custom-reset-standard 'custom-group-reset-standard
2687 :custom-menu 'custom-group-menu-create)
2688
2689 (defun custom-group-sample-face-get (widget)
2690 ;; Use :sample-face.
2691 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
2692 'custom-group-tag-face))
2693
2694 (define-widget 'custom-group-visibility 'visibility
2695 "An indicator and manipulator for hidden group contents."
2696 :create 'custom-group-visibility-create)
2697
2698 (defun custom-group-visibility-create (widget)
2699 (let ((visible (widget-value widget)))
2700 (if visible
2701 (insert "--------")))
2702 (widget-default-create widget))
2703
2704 (defun custom-group-members (symbol groups-only)
2705 "Return SYMBOL's custom group members.
2706 If GROUPS-ONLY non-nil, return only those members that are groups."
2707 (if (not groups-only)
2708 (get symbol 'custom-group)
2709 (let (members)
2710 (dolist (entry (get symbol 'custom-group))
2711 (when (eq (nth 1 entry) 'custom-group)
2712 (push entry members)))
2713 (nreverse members))))
2714
2715 (defun custom-group-value-create (widget)
2716 "Insert a customize group for WIDGET in the current buffer."
2717 (let* ((state (widget-get widget :custom-state))
2718 (level (widget-get widget :custom-level))
2719 ;; (indent (widget-get widget :indent))
2720 (prefix (widget-get widget :custom-prefix))
2721 (buttons (widget-get widget :buttons))
2722 (tag (widget-get widget :tag))
2723 (symbol (widget-value widget))
2724 (members (custom-group-members symbol
2725 (and (eq custom-buffer-style 'tree)
2726 custom-browse-only-groups))))
2727 (cond ((and (eq custom-buffer-style 'tree)
2728 (eq state 'hidden)
2729 (or members (custom-unloaded-widget-p widget)))
2730 (custom-browse-insert-prefix prefix)
2731 (push (widget-create-child-and-convert
2732 widget 'custom-browse-visibility
2733 ;; :tag-glyph "plus"
2734 :tag "+")
2735 buttons)
2736 (insert "-- ")
2737 ;; (widget-glyph-insert nil "-- " "horizontal")
2738 (push (widget-create-child-and-convert
2739 widget 'custom-browse-group-tag)
2740 buttons)
2741 (insert " " tag "\n")
2742 (widget-put widget :buttons buttons))
2743 ((and (eq custom-buffer-style 'tree)
2744 (zerop (length members)))
2745 (custom-browse-insert-prefix prefix)
2746 (insert "[ ]-- ")
2747 ;; (widget-glyph-insert nil "[ ]" "empty")
2748 ;; (widget-glyph-insert nil "-- " "horizontal")
2749 (push (widget-create-child-and-convert
2750 widget 'custom-browse-group-tag)
2751 buttons)
2752 (insert " " tag "\n")
2753 (widget-put widget :buttons buttons))
2754 ((eq custom-buffer-style 'tree)
2755 (custom-browse-insert-prefix prefix)
2756 (custom-load-widget widget)
2757 (if (zerop (length members))
2758 (progn
2759 (custom-browse-insert-prefix prefix)
2760 (insert "[ ]-- ")
2761 ;; (widget-glyph-insert nil "[ ]" "empty")
2762 ;; (widget-glyph-insert nil "-- " "horizontal")
2763 (push (widget-create-child-and-convert
2764 widget 'custom-browse-group-tag)
2765 buttons)
2766 (insert " " tag "\n")
2767 (widget-put widget :buttons buttons))
2768 (push (widget-create-child-and-convert
2769 widget 'custom-browse-visibility
2770 ;; :tag-glyph "minus"
2771 :tag "-")
2772 buttons)
2773 (insert "-\\ ")
2774 ;; (widget-glyph-insert nil "-\\ " "top")
2775 (push (widget-create-child-and-convert
2776 widget 'custom-browse-group-tag)
2777 buttons)
2778 (insert " " tag "\n")
2779 (widget-put widget :buttons buttons)
2780 (message "Creating group...")
2781 (let* ((members (custom-sort-items members
2782 custom-browse-sort-alphabetically
2783 custom-browse-order-groups))
2784 (prefixes (widget-get widget :custom-prefixes))
2785 (custom-prefix-list (custom-prefix-add symbol prefixes))
2786 (extra-prefix (if (widget-get widget :custom-last)
2787 " "
2788 " | "))
2789 (prefix (concat prefix extra-prefix))
2790 children entry)
2791 (while members
2792 (setq entry (car members)
2793 members (cdr members))
2794 (push (widget-create-child-and-convert
2795 widget (nth 1 entry)
2796 :group widget
2797 :tag (custom-unlispify-tag-name (nth 0 entry))
2798 :custom-prefixes custom-prefix-list
2799 :custom-level (1+ level)
2800 :custom-last (null members)
2801 :value (nth 0 entry)
2802 :custom-prefix prefix)
2803 children))
2804 (widget-put widget :children (reverse children)))
2805 (message "Creating group...done")))
2806 ;; Nested style.
2807 ((eq state 'hidden)
2808 ;; Create level indicator.
2809 (unless (eq custom-buffer-style 'links)
2810 (insert-char ?\ (* custom-buffer-indent (1- level)))
2811 (insert "-- "))
2812 ;; Create tag.
2813 (let ((begin (point)))
2814 (insert tag)
2815 (widget-specify-sample widget begin (point)))
2816 (insert " group: ")
2817 ;; Create link/visibility indicator.
2818 (if (eq custom-buffer-style 'links)
2819 (push (widget-create-child-and-convert
2820 widget 'custom-group-link
2821 :tag "Go to Group"
2822 symbol)
2823 buttons)
2824 (push (widget-create-child-and-convert
2825 widget 'custom-group-visibility
2826 :help-echo "Show members of this group."
2827 :action 'custom-toggle-parent
2828 (not (eq state 'hidden)))
2829 buttons))
2830 (insert " \n")
2831 ;; Create magic button.
2832 (let ((magic (widget-create-child-and-convert
2833 widget 'custom-magic nil)))
2834 (widget-put widget :custom-magic magic)
2835 (push magic buttons))
2836 ;; Update buttons.
2837 (widget-put widget :buttons buttons)
2838 ;; Insert documentation.
2839 (if (and (eq custom-buffer-style 'links) (> level 1))
2840 (widget-put widget :documentation-indent 0))
2841 (widget-default-format-handler widget ?h))
2842 ;; Nested style.
2843 (t ;Visible.
2844 ;; Add parent groups references above the group.
2845 (if t ;;; This should test that the buffer
2846 ;;; was made to display a group.
2847 (when (eq level 1)
2848 (if (custom-add-parent-links widget
2849 "Go to parent group:")
2850 (insert "\n"))))
2851 ;; Create level indicator.
2852 (insert-char ?\ (* custom-buffer-indent (1- level)))
2853 (insert "/- ")
2854 ;; Create tag.
2855 (let ((start (point)))
2856 (insert tag)
2857 (widget-specify-sample widget start (point)))
2858 (insert " group: ")
2859 ;; Create visibility indicator.
2860 (unless (eq custom-buffer-style 'links)
2861 (insert "--------")
2862 (push (widget-create-child-and-convert
2863 widget 'visibility
2864 :help-echo "Hide members of this group."
2865 :action 'custom-toggle-parent
2866 (not (eq state 'hidden)))
2867 buttons)
2868 (insert " "))
2869 ;; Create more dashes.
2870 ;; Use 76 instead of 75 to compensate for the temporary "<"
2871 ;; added by `widget-insert'.
2872 (insert-char ?- (- 76 (current-column)
2873 (* custom-buffer-indent level)))
2874 (insert "\\\n")
2875 ;; Create magic button.
2876 (let ((magic (widget-create-child-and-convert
2877 widget 'custom-magic
2878 :indent 0
2879 nil)))
2880 (widget-put widget :custom-magic magic)
2881 (push magic buttons))
2882 ;; Update buttons.
2883 (widget-put widget :buttons buttons)
2884 ;; Insert documentation.
2885 (widget-default-format-handler widget ?h)
2886 ;; Parent groups.
2887 (if nil ;;; This should test that the buffer
2888 ;;; was not made to display a group.
2889 (when (eq level 1)
2890 (insert-char ?\ custom-buffer-indent)
2891 (custom-add-parent-links widget)))
2892 (custom-add-see-also widget
2893 (make-string (* custom-buffer-indent level)
2894 ?\ ))
2895 ;; Members.
2896 (message "Creating group...")
2897 (custom-load-widget widget)
2898 (let* ((members (custom-sort-items members
2899 custom-buffer-sort-alphabetically
2900 custom-buffer-order-groups))
2901 (prefixes (widget-get widget :custom-prefixes))
2902 (custom-prefix-list (custom-prefix-add symbol prefixes))
2903 (length (length members))
2904 (count 0)
2905 (children (mapcar (lambda (entry)
2906 (widget-insert "\n")
2907 (message "\
2908 Creating group members... %2d%%"
2909 (/ (* 100.0 count) length))
2910 (setq count (1+ count))
2911 (prog1
2912 (widget-create-child-and-convert
2913 widget (nth 1 entry)
2914 :group widget
2915 :tag (custom-unlispify-tag-name
2916 (nth 0 entry))
2917 :custom-prefixes custom-prefix-list
2918 :custom-level (1+ level)
2919 :value (nth 0 entry))
2920 (unless (eq (preceding-char) ?\n)
2921 (widget-insert "\n"))))
2922 members)))
2923 (message "Creating group magic...")
2924 (mapcar 'custom-magic-reset children)
2925 (message "Creating group state...")
2926 (widget-put widget :children children)
2927 (custom-group-state-update widget)
2928 (message "Creating group... done"))
2929 ;; End line
2930 (insert "\n")
2931 (insert-char ?\ (* custom-buffer-indent (1- level)))
2932 (insert "\\- " (widget-get widget :tag) " group end ")
2933 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
2934 (insert "/\n")))))
2935
2936 (defvar custom-group-menu
2937 '(("Set for Current Session" custom-group-set
2938 (lambda (widget)
2939 (eq (widget-get widget :custom-state) 'modified)))
2940 ("Save for Future Sessions" custom-group-save
2941 (lambda (widget)
2942 (memq (widget-get widget :custom-state) '(modified set))))
2943 ("Reset to Current" custom-group-reset-current
2944 (lambda (widget)
2945 (memq (widget-get widget :custom-state) '(modified))))
2946 ("Reset to Saved" custom-group-reset-saved
2947 (lambda (widget)
2948 (memq (widget-get widget :custom-state) '(modified set))))
2949 ("Reset to standard setting" custom-group-reset-standard
2950 (lambda (widget)
2951 (memq (widget-get widget :custom-state) '(modified set saved)))))
2952 "Alist of actions for the `custom-group' widget.
2953 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2954 the menu entry, ACTION is the function to call on the widget when the
2955 menu is selected, and FILTER is a predicate which takes a `custom-group'
2956 widget as an argument, and returns non-nil if ACTION is valid on that
2957 widget. If FILTER is nil, ACTION is always valid.")
2958
2959 (defun custom-group-action (widget &optional event)
2960 "Show the menu for `custom-group' WIDGET.
2961 Optional EVENT is the location for the menu."
2962 (if (eq (widget-get widget :custom-state) 'hidden)
2963 (custom-toggle-hide widget)
2964 (let* ((completion-ignore-case t)
2965 (answer (widget-choose (concat "Operation on "
2966 (custom-unlispify-tag-name
2967 (widget-get widget :value)))
2968 (custom-menu-filter custom-group-menu
2969 widget)
2970 event)))
2971 (if answer
2972 (funcall answer widget)))))
2973
2974 (defun custom-group-set (widget)
2975 "Set changes in all modified group members."
2976 (let ((children (widget-get widget :children)))
2977 (mapcar (lambda (child)
2978 (when (eq (widget-get child :custom-state) 'modified)
2979 (widget-apply child :custom-set)))
2980 children )))
2981
2982 (defun custom-group-save (widget)
2983 "Save all modified group members."
2984 (let ((children (widget-get widget :children)))
2985 (mapcar (lambda (child)
2986 (when (memq (widget-get child :custom-state) '(modified set))
2987 (widget-apply child :custom-save)))
2988 children )))
2989
2990 (defun custom-group-reset-current (widget)
2991 "Reset all modified group members."
2992 (let ((children (widget-get widget :children)))
2993 (mapcar (lambda (child)
2994 (when (eq (widget-get child :custom-state) 'modified)
2995 (widget-apply child :custom-reset-current)))
2996 children )))
2997
2998 (defun custom-group-reset-saved (widget)
2999 "Reset all modified or set group members."
3000 (let ((children (widget-get widget :children)))
3001 (mapcar (lambda (child)
3002 (when (memq (widget-get child :custom-state) '(modified set))
3003 (widget-apply child :custom-reset-saved)))
3004 children )))
3005
3006 (defun custom-group-reset-standard (widget)
3007 "Reset all modified, set, or saved group members."
3008 (let ((children (widget-get widget :children)))
3009 (mapcar (lambda (child)
3010 (when (memq (widget-get child :custom-state)
3011 '(modified set saved))
3012 (widget-apply child :custom-reset-standard)))
3013 children )))
3014
3015 (defun custom-group-state-update (widget)
3016 "Update magic."
3017 (unless (eq (widget-get widget :custom-state) 'hidden)
3018 (let* ((children (widget-get widget :children))
3019 (states (mapcar (lambda (child)
3020 (widget-get child :custom-state))
3021 children))
3022 (magics custom-magic-alist)
3023 (found 'standard))
3024 (while magics
3025 (let ((magic (car (car magics))))
3026 (if (and (not (eq magic 'hidden))
3027 (memq magic states))
3028 (setq found magic
3029 magics nil)
3030 (setq magics (cdr magics)))))
3031 (widget-put widget :custom-state found)))
3032 (custom-magic-reset widget))
3033
3034 ;;; The `custom-save-all' Function.
3035 ;;;###autoload
3036 (defcustom custom-file nil
3037 "File used for storing customization information.
3038 The default is nil, which means to use your init file
3039 as specified by `user-init-file'. If you specify some other file,
3040 you need to explicitly load that file for the settings to take effect."
3041 :type '(choice (const :tag "Your Emacs init file" nil) file)
3042 :group 'customize)
3043
3044 (defun custom-file ()
3045 "Return the file name for saving customizations."
3046 (setq custom-file
3047 (or custom-file
3048 user-init-file
3049 (read-file-name "File for customizations: "
3050 "~/" nil nil ".emacs"))))
3051
3052 (defun custom-save-delete (symbol)
3053 "Delete the call to SYMBOL from `custom-file'.
3054 Leave point at the location of the call, or after the last expression."
3055 (let ((default-major-mode))
3056 (set-buffer (find-file-noselect (custom-file))))
3057 (goto-char (point-min))
3058 (catch 'found
3059 (while t
3060 (let ((sexp (condition-case nil
3061 (read (current-buffer))
3062 (end-of-file (throw 'found nil)))))
3063 (when (and (listp sexp)
3064 (eq (car sexp) symbol))
3065 (delete-region (save-excursion
3066 (backward-sexp)
3067 (point))
3068 (point))
3069 (throw 'found nil))))))
3070
3071 (defun custom-save-variables ()
3072 "Save all customized variables in `custom-file'."
3073 (save-excursion
3074 (custom-save-delete 'custom-set-variables)
3075 (let ((standard-output (current-buffer)))
3076 (unless (bolp)
3077 (princ "\n"))
3078 (princ "(custom-set-variables")
3079 (mapatoms (lambda (symbol)
3080 (let ((value (get symbol 'saved-value))
3081 (requests (get symbol 'custom-requests))
3082 (now (not (or (get symbol 'standard-value)
3083 (and (not (boundp symbol))
3084 (not (get symbol 'force-value)))))))
3085 (when value
3086 (princ "\n '(")
3087 (princ symbol)
3088 (princ " ")
3089 (prin1 (car value))
3090 (cond (requests
3091 (if now
3092 (princ " t ")
3093 (princ " nil "))
3094 (prin1 requests)
3095 (princ ")"))
3096 (now
3097 (princ " t)"))
3098 (t
3099 (princ ")")))))))
3100 (princ ")")
3101 (unless (looking-at "\n")
3102 (princ "\n")))))
3103
3104 (defun custom-save-faces ()
3105 "Save all customized faces in `custom-file'."
3106 (save-excursion
3107 (custom-save-delete 'custom-set-faces)
3108 (let ((standard-output (current-buffer)))
3109 (unless (bolp)
3110 (princ "\n"))
3111 (princ "(custom-set-faces")
3112 (let ((value (get 'default 'saved-face)))
3113 ;; The default face must be first, since it affects the others.
3114 (when value
3115 (princ "\n '(default ")
3116 (prin1 value)
3117 (if (or (get 'default 'face-defface-spec)
3118 (and (not (custom-facep 'default))
3119 (not (get 'default 'force-face))))
3120 (princ ")")
3121 (princ " t)"))))
3122 (mapatoms (lambda (symbol)
3123 (let ((value (get symbol 'saved-face)))
3124 (when (and (not (eq symbol 'default))
3125 ;; Don't print default face here.
3126 value)
3127 (princ "\n '(")
3128 (princ symbol)
3129 (princ " ")
3130 (prin1 value)
3131 (if (or (get symbol 'face-defface-spec)
3132 (and (not (custom-facep symbol))
3133 (not (get symbol 'force-face))))
3134 (princ ")")
3135 (princ " t)"))))))
3136 (princ ")")
3137 (unless (looking-at "\n")
3138 (princ "\n")))))
3139
3140 ;;;###autoload
3141 (defun customize-save-customized ()
3142 "Save all user options which have been set in this session."
3143 (interactive)
3144 (mapatoms (lambda (symbol)
3145 (let ((face (get symbol 'customized-face))
3146 (value (get symbol 'customized-value)))
3147 (when face
3148 (put symbol 'saved-face face)
3149 (put symbol 'customized-face nil))
3150 (when value
3151 (put symbol 'saved-value value)
3152 (put symbol 'customized-value nil)))))
3153 ;; We really should update all custom buffers here.
3154 (custom-save-all))
3155
3156 ;;;###autoload
3157 (defun custom-save-all ()
3158 "Save all customizations in `custom-file'."
3159 (let ((inhibit-read-only t))
3160 (custom-save-variables)
3161 (custom-save-faces)
3162 (save-excursion
3163 (let ((default-major-mode nil))
3164 (set-buffer (find-file-noselect (custom-file))))
3165 (save-buffer))))
3166
3167 ;;; The Customize Menu.
3168
3169 ;;; Menu support
3170
3171 (defcustom custom-menu-nesting 2
3172 "Maximum nesting in custom menus."
3173 :type 'integer
3174 :group 'custom-menu)
3175
3176 (defun custom-face-menu-create (widget symbol)
3177 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3178 (vector (custom-unlispify-menu-entry symbol)
3179 `(customize-face ',symbol)
3180 t))
3181
3182 (defun custom-variable-menu-create (widget symbol)
3183 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3184 (let ((type (get symbol 'custom-type)))
3185 (unless (listp type)
3186 (setq type (list type)))
3187 (if (and type (widget-get type :custom-menu))
3188 (widget-apply type :custom-menu symbol)
3189 (vector (custom-unlispify-menu-entry symbol)
3190 `(customize-variable ',symbol)
3191 t))))
3192
3193 ;; Add checkboxes to boolean variable entries.
3194 (widget-put (get 'boolean 'widget-type)
3195 :custom-menu (lambda (widget symbol)
3196 (vector (custom-unlispify-menu-entry symbol)
3197 `(customize-variable ',symbol)
3198 ':style 'toggle
3199 ':selected symbol)))
3200
3201 (if (string-match "XEmacs" emacs-version)
3202 ;; XEmacs can create menus dynamically.
3203 (defun custom-group-menu-create (widget symbol)
3204 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3205 `( ,(custom-unlispify-menu-entry symbol t)
3206 :filter (lambda (&rest junk)
3207 (cdr (custom-menu-create ',symbol)))))
3208 ;; But emacs can't.
3209 (defun custom-group-menu-create (widget symbol)
3210 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3211 ;; Limit the nesting.
3212 (let ((custom-menu-nesting (1- custom-menu-nesting)))
3213 (custom-menu-create symbol))))
3214
3215 ;;;###autoload
3216 (defun custom-menu-create (symbol)
3217 "Create menu for customization group SYMBOL.
3218 The menu is in a format applicable to `easy-menu-define'."
3219 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3220 `(customize-group ',symbol)
3221 t)))
3222 (if (and (or (not (boundp 'custom-menu-nesting))
3223 (>= custom-menu-nesting 0))
3224 (< (length (get symbol 'custom-group)) widget-menu-max-size))
3225 (let ((custom-prefix-list (custom-prefix-add symbol
3226 custom-prefix-list))
3227 (members (custom-sort-items (get symbol 'custom-group)
3228 custom-menu-sort-alphabetically
3229 custom-menu-order-groups)))
3230 (custom-load-symbol symbol)
3231 `(,(custom-unlispify-menu-entry symbol t)
3232 ,item
3233 "--"
3234 ,@(mapcar (lambda (entry)
3235 (widget-apply (if (listp (nth 1 entry))
3236 (nth 1 entry)
3237 (list (nth 1 entry)))
3238 :custom-menu (nth 0 entry)))
3239 members)))
3240 item)))
3241
3242 ;;;###autoload
3243 (defun customize-menu-create (symbol &optional name)
3244 "Return a customize menu for customization group SYMBOL.
3245 If optional NAME is given, use that as the name of the menu.
3246 Otherwise the menu will be named `Customize'.
3247 The format is suitable for use with `easy-menu-define'."
3248 (unless name
3249 (setq name "Customize"))
3250 (if (string-match "XEmacs" emacs-version)
3251 ;; We can delay it under XEmacs.
3252 `(,name
3253 :filter (lambda (&rest junk)
3254 (cdr (custom-menu-create ',symbol))))
3255 ;; But we must create it now under Emacs.
3256 (cons name (cdr (custom-menu-create symbol)))))
3257
3258 ;;; The Custom Mode.
3259
3260 (defvar custom-mode-map nil
3261 "Keymap for `custom-mode'.")
3262
3263 (unless custom-mode-map
3264 (setq custom-mode-map (make-sparse-keymap))
3265 (set-keymap-parent custom-mode-map widget-keymap)
3266 (suppress-keymap custom-mode-map)
3267 (define-key custom-mode-map " " 'scroll-up)
3268 (define-key custom-mode-map "\177" 'scroll-down)
3269 (define-key custom-mode-map "q" 'bury-buffer)
3270 (define-key custom-mode-map "u" 'Custom-goto-parent)
3271 (define-key custom-mode-map "n" 'widget-forward)
3272 (define-key custom-mode-map "p" 'widget-backward)
3273 (define-key custom-mode-map [mouse-1] 'Custom-move-and-invoke))
3274
3275 (defun Custom-move-and-invoke (event)
3276 "Move to where you click, and if it is an active field, invoke it."
3277 (interactive "e")
3278 (mouse-set-point event)
3279 (if (widget-event-point event)
3280 (let* ((pos (widget-event-point event))
3281 (button (get-char-property pos 'button)))
3282 (if button
3283 (widget-button-click event)))))
3284
3285 (easy-menu-define Custom-mode-menu
3286 custom-mode-map
3287 "Menu used in customization buffers."
3288 `("Custom"
3289 ,(customize-menu-create 'customize)
3290 ["Set" Custom-set t]
3291 ["Save" Custom-save t]
3292 ["Reset to Current" Custom-reset-current t]
3293 ["Reset to Saved" Custom-reset-saved t]
3294 ["Reset to Standard Settings" Custom-reset-standard t]
3295 ["Info" (Info-goto-node "(custom)The Customization Buffer") t]))
3296
3297 (defun Custom-goto-parent ()
3298 "Go to the parent group listed at the top of this buffer.
3299 If several parents are listed, go to the first of them."
3300 (interactive)
3301 (save-excursion
3302 (goto-char (point-min))
3303 (if (search-forward "\nGo to parent group: " nil t)
3304 (let* ((button (get-char-property (point) 'button))
3305 (parent (downcase (widget-get button :tag))))
3306 (customize-group parent)))))
3307
3308 (defcustom custom-mode-hook nil
3309 "Hook called when entering custom-mode."
3310 :type 'hook
3311 :group 'custom-buffer )
3312
3313 (defun custom-state-buffer-message (widget)
3314 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
3315 (message "To install your edits, invoke [State] and choose the Set operation")))
3316
3317 (defun custom-mode ()
3318 "Major mode for editing customization buffers.
3319
3320 The following commands are available:
3321
3322 Move to next button or editable field. \\[widget-forward]
3323 Move to previous button or editable field. \\[widget-backward]
3324 \\<widget-field-keymap>\
3325 Complete content of editable text field. \\[widget-complete]
3326 \\<custom-mode-map>\
3327 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3328 Invoke button under point. \\[widget-button-press]
3329 Set all modifications. \\[Custom-set]
3330 Make all modifications default. \\[Custom-save]
3331 Reset all modified options. \\[Custom-reset-current]
3332 Reset all modified or set options. \\[Custom-reset-saved]
3333 Reset all options. \\[Custom-reset-standard]
3334
3335 Entry to this mode calls the value of `custom-mode-hook'
3336 if that value is non-nil."
3337 (kill-all-local-variables)
3338 (setq major-mode 'custom-mode
3339 mode-name "Custom")
3340 (use-local-map custom-mode-map)
3341 (easy-menu-add Custom-mode-menu)
3342 (make-local-variable 'custom-options)
3343 (make-local-variable 'widget-documentation-face)
3344 (setq widget-documentation-face 'custom-documentation-face)
3345 (make-local-variable 'widget-button-face)
3346 (setq widget-button-face 'custom-button-face)
3347 (make-local-hook 'widget-edit-functions)
3348 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
3349 (run-hooks 'custom-mode-hook))
3350
3351 ;;; The End.
3352
3353 (provide 'cus-edit)
3354
3355 ;; cus-edit.el ends here