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