Change release version from 21.4 to 22.1 throughout.
[bpt/emacs.git] / lisp / cus-edit.el
1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
2 ;;
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 ;; Free Software Foundation, Inc.
5 ;;
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7 ;; Maintainer: FSF
8 ;; Keywords: help, faces
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 (eval-when-compile
42 (defvar custom-versions-load-alist)) ; from cus-load
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 (put 'custom-define-hook 'custom-type 'hook)
53 (put 'custom-define-hook 'standard-value '(nil))
54 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
55
56 ;;; Customization Groups.
57
58 (defgroup emacs nil
59 "Customization of the One True Editor."
60 :link '(custom-manual "(emacs)Top"))
61
62 ;; Most of these groups are stolen from `finder.el',
63 (defgroup editing nil
64 "Basic text editing facilities."
65 :group 'emacs)
66
67 (defgroup abbrev nil
68 "Abbreviation handling, typing shortcuts, macros."
69 :tag "Abbreviations"
70 :group 'editing)
71
72 (defgroup matching nil
73 "Various sorts of searching and matching."
74 :group 'editing)
75
76 (defgroup emulations nil
77 "Emulations of other editors."
78 :link '(custom-manual "(emacs)Emulation")
79 :group 'editing)
80
81 (defgroup mouse nil
82 "Mouse support."
83 :group 'editing)
84
85 (defgroup outlines nil
86 "Support for hierarchical outlining."
87 :group 'editing)
88
89 (defgroup external nil
90 "Interfacing to external utilities."
91 :group 'emacs)
92
93 (defgroup processes nil
94 "Process, subshell, compilation, and job control support."
95 :group 'external
96 :group 'development)
97
98 (defgroup convenience nil
99 "Convenience features for faster editing."
100 :group 'emacs)
101
102 (defgroup programming nil
103 "Support for programming in other languages."
104 :group 'emacs)
105
106 (defgroup languages nil
107 "Specialized modes for editing programming languages."
108 :group 'programming)
109
110 (defgroup lisp nil
111 "Lisp support, including Emacs Lisp."
112 :group 'languages
113 :group 'development)
114
115 (defgroup c nil
116 "Support for the C language and related languages."
117 :link '(custom-manual "(ccmode)")
118 :group 'languages)
119
120 (defgroup tools nil
121 "Programming tools."
122 :group 'programming)
123
124 (defgroup oop nil
125 "Support for object-oriented programming."
126 :group 'programming)
127
128 (defgroup applications nil
129 "Applications written in Emacs."
130 :group 'emacs)
131
132 (defgroup calendar nil
133 "Calendar and time management support."
134 :group 'applications)
135
136 (defgroup mail nil
137 "Modes for electronic-mail handling."
138 :group 'applications)
139
140 (defgroup news nil
141 "Support for netnews reading and posting."
142 :link '(custom-manual "(gnus)")
143 :group 'applications)
144
145 (defgroup games nil
146 "Games, jokes and amusements."
147 :group 'applications)
148
149 (defgroup development nil
150 "Support for further development of Emacs."
151 :group 'emacs)
152
153 (defgroup docs nil
154 "Support for Emacs documentation."
155 :group 'development)
156
157 (defgroup extensions nil
158 "Emacs Lisp language extensions."
159 :group 'development)
160
161 (defgroup internal nil
162 "Code for Emacs internals, build process, defaults."
163 :group 'development)
164
165 (defgroup maint nil
166 "Maintenance aids for the Emacs development group."
167 :tag "Maintenance"
168 :group 'development)
169
170 (defgroup environment nil
171 "Fitting Emacs with its environment."
172 :group 'emacs)
173
174 (defgroup comm nil
175 "Communications, networking, remote access to files."
176 :tag "Communication"
177 :group 'environment)
178
179 (defgroup hardware nil
180 "Support for interfacing with exotic hardware."
181 :group 'environment)
182
183 (defgroup terminals nil
184 "Support for terminal types."
185 :group 'environment)
186
187 (defgroup unix nil
188 "Front-ends/assistants for, or emulators of, UNIX features."
189 :group 'environment)
190
191 (defgroup vms nil
192 "Support code for vms."
193 :group 'environment)
194
195 (defgroup i18n nil
196 "Internationalization and alternate character-set support."
197 :link '(custom-manual "(emacs)International")
198 :group 'environment
199 :group 'editing)
200
201 (defgroup x nil
202 "The X Window system."
203 :group 'environment)
204
205 (defgroup frames nil
206 "Support for Emacs frames and window systems."
207 :group 'environment)
208
209 (defgroup data nil
210 "Support editing files of data."
211 :group 'emacs)
212
213 (defgroup files nil
214 "Support editing files."
215 :group 'emacs)
216
217 (defgroup wp nil
218 "Word processing."
219 :group 'emacs)
220
221 (defgroup tex nil
222 "Code related to the TeX formatter."
223 :group 'wp)
224
225 (defgroup faces nil
226 "Support for multiple fonts."
227 :group 'emacs)
228
229 (defgroup hypermedia nil
230 "Support for links between text or other media types."
231 :group 'emacs)
232
233 (defgroup help nil
234 "Support for on-line help systems."
235 :group 'emacs)
236
237 (defgroup multimedia nil
238 "Non-textual support, specifically images and sound."
239 :group 'emacs)
240
241 (defgroup local nil
242 "Code local to your site."
243 :group 'emacs)
244
245 (defgroup customize '((widgets custom-group))
246 "Customization of the Customization support."
247 :prefix "custom-"
248 :group 'help)
249
250 (defgroup custom-faces nil
251 "Faces used by customize."
252 :group 'customize
253 :group 'faces)
254
255 (defgroup custom-browse nil
256 "Control customize browser."
257 :prefix "custom-"
258 :group 'customize)
259
260 (defgroup custom-buffer nil
261 "Control customize buffers."
262 :prefix "custom-"
263 :group 'customize)
264
265 (defgroup custom-menu nil
266 "Control customize menus."
267 :prefix "custom-"
268 :group 'customize)
269
270 (defgroup abbrev-mode nil
271 "Word abbreviations mode."
272 :link '(custom-manual "(emacs)Abbrevs")
273 :group 'abbrev)
274
275 (defgroup alloc nil
276 "Storage allocation and gc for GNU Emacs Lisp interpreter."
277 :tag "Storage Allocation"
278 :group 'internal)
279
280 (defgroup undo nil
281 "Undoing changes in buffers."
282 :link '(custom-manual "(emacs)Undo")
283 :group 'editing)
284
285 (defgroup modeline nil
286 "Content of the modeline."
287 :group 'environment)
288
289 (defgroup editing-basics nil
290 "Most basic editing facilities."
291 :group 'editing)
292
293 (defgroup display nil
294 "How characters are displayed in buffers."
295 :group 'environment)
296
297 (defgroup execute nil
298 "Executing external commands."
299 :group 'processes)
300
301 (defgroup installation nil
302 "The Emacs installation."
303 :group 'environment)
304
305 (defgroup dired nil
306 "Directory editing."
307 :group 'environment)
308
309 (defgroup limits nil
310 "Internal Emacs limits."
311 :group 'internal)
312
313 (defgroup debug nil
314 "Debugging Emacs itself."
315 :group 'development)
316
317 (defgroup minibuffer nil
318 "Controling the behaviour of the minibuffer."
319 :link '(custom-manual "(emacs)Minibuffer")
320 :group 'environment)
321
322 (defgroup keyboard nil
323 "Input from the keyboard."
324 :group 'environment)
325
326 (defgroup mouse nil
327 "Input from the mouse."
328 :group 'environment)
329
330 (defgroup menu nil
331 "Input from the menus."
332 :group 'environment)
333
334 (defgroup auto-save nil
335 "Preventing accidential loss of data."
336 :group 'files)
337
338 (defgroup processes-basics nil
339 "Basic stuff dealing with processes."
340 :group 'processes)
341
342 (defgroup mule nil
343 "MULE Emacs internationalization."
344 :group 'i18n)
345
346 (defgroup windows nil
347 "Windows within a frame."
348 :link '(custom-manual "(emacs)Windows")
349 :group 'environment)
350
351 ;;; Utilities.
352
353 (defun custom-quote (sexp)
354 "Quote SEXP iff it is not self quoting."
355 (if (or (memq sexp '(t nil))
356 (keywordp sexp)
357 (and (listp sexp)
358 (memq (car sexp) '(lambda)))
359 (stringp sexp)
360 (numberp sexp)
361 (vectorp sexp)
362 ;;; (and (fboundp 'characterp)
363 ;;; (characterp sexp))
364 )
365 sexp
366 (list 'quote sexp)))
367
368 (defun custom-split-regexp-maybe (regexp)
369 "If REGEXP is a string, split it to a list at `\\|'.
370 You can get the original back with from the result with:
371 (mapconcat 'identity result \"\\|\")
372
373 IF REGEXP is not a string, return it unchanged."
374 (if (stringp regexp)
375 (let ((start 0)
376 all)
377 (while (string-match "\\\\|" regexp start)
378 (setq all (cons (substring regexp start (match-beginning 0)) all)
379 start (match-end 0)))
380 (nreverse (cons (substring regexp start) all)))
381 regexp))
382
383 (defun custom-variable-prompt ()
384 "Prompt for a custom variable, defaulting to the variable at point.
385 Return a list suitable for use in `interactive'."
386 (let ((v (variable-at-point))
387 (enable-recursive-minibuffers t)
388 val)
389 (setq val (completing-read
390 (if (and (symbolp v) (custom-variable-p v))
391 (format "Customize option: (default %s) " v)
392 "Customize option: ")
393 obarray 'custom-variable-p t))
394 (list (if (equal val "")
395 (if (symbolp v) v nil)
396 (intern val)))))
397
398 (defun custom-menu-filter (menu widget)
399 "Convert MENU to the form used by `widget-choose'.
400 MENU should be in the same format as `custom-variable-menu'.
401 WIDGET is the widget to apply the filter entries of MENU on."
402 (let ((result nil)
403 current name action filter)
404 (while menu
405 (setq current (car menu)
406 name (nth 0 current)
407 action (nth 1 current)
408 filter (nth 2 current)
409 menu (cdr menu))
410 (if (or (null filter) (funcall filter widget))
411 (push (cons name action) result)
412 (push name result)))
413 (nreverse result)))
414
415 ;;; Unlispify.
416
417 (defvar custom-prefix-list nil
418 "List of prefixes that should be ignored by `custom-unlispify'.")
419
420 (defcustom custom-unlispify-menu-entries t
421 "Display menu entries as words instead of symbols if non nil."
422 :group 'custom-menu
423 :type 'boolean)
424
425 (defcustom custom-unlispify-remove-prefixes nil
426 "Non-nil means remove group prefixes from option names in buffer."
427 :group 'custom-menu
428 :group 'custom-buffer
429 :type 'boolean)
430
431 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
432 "Convert SYMBOL into a menu entry."
433 (cond ((not custom-unlispify-menu-entries)
434 (symbol-name symbol))
435 ((get symbol 'custom-tag)
436 (if no-suffix
437 (get symbol 'custom-tag)
438 (concat (get symbol 'custom-tag) "...")))
439 (t
440 (with-current-buffer (get-buffer-create " *Custom-Work*")
441 (erase-buffer)
442 (princ symbol (current-buffer))
443 (goto-char (point-min))
444 ;; FIXME: Boolean variables are not predicates, so they shouldn't
445 ;; end with `-p'. -stef
446 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
447 ;; (re-search-forward "-p\\'" nil t))
448 ;; (replace-match "" t t)
449 ;; (goto-char (point-min)))
450 (if custom-unlispify-remove-prefixes
451 (let ((prefixes custom-prefix-list)
452 prefix)
453 (while prefixes
454 (setq prefix (car prefixes))
455 (if (search-forward prefix (+ (point) (length prefix)) t)
456 (progn
457 (setq prefixes nil)
458 (delete-region (point-min) (point)))
459 (setq prefixes (cdr prefixes))))))
460 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
461 (capitalize-region (point-min) (point-max))
462 (unless no-suffix
463 (goto-char (point-max))
464 (insert "..."))
465 (buffer-string)))))
466
467 (defcustom custom-unlispify-tag-names t
468 "Display tag names as words instead of symbols if non nil."
469 :group 'custom-buffer
470 :type 'boolean)
471
472 (defun custom-unlispify-tag-name (symbol)
473 "Convert SYMBOL into a menu entry."
474 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
475 (custom-unlispify-menu-entry symbol t)))
476
477 (defun custom-prefix-add (symbol prefixes)
478 "Add SYMBOL to list of ignored PREFIXES."
479 (cons (or (get symbol 'custom-prefix)
480 (concat (symbol-name symbol) "-"))
481 prefixes))
482
483 ;;; Guess.
484
485 (defcustom custom-guess-name-alist
486 '(("-p\\'" boolean)
487 ("-hook\\'" hook)
488 ("-face\\'" face)
489 ("-file\\'" file)
490 ("-function\\'" function)
491 ("-functions\\'" (repeat function))
492 ("-list\\'" (repeat sexp))
493 ("-alist\\'" (repeat (cons sexp sexp))))
494 "Alist of (MATCH TYPE).
495
496 MATCH should be a regexp matching the name of a symbol, and TYPE should
497 be a widget suitable for editing the value of that symbol. The TYPE
498 of the first entry where MATCH matches the name of the symbol will be
499 used.
500
501 This is used for guessing the type of variables not declared with
502 customize."
503 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
504 :group 'customize)
505
506 (defcustom custom-guess-doc-alist
507 '(("\\`\\*?Non-nil " boolean))
508 "Alist of (MATCH TYPE).
509
510 MATCH should be a regexp matching a documentation string, and TYPE
511 should be a widget suitable for editing the value of a variable with
512 that documentation string. The TYPE of the first entry where MATCH
513 matches the name of the symbol will be used.
514
515 This is used for guessing the type of variables not declared with
516 customize."
517 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
518 :group 'customize)
519
520 (defun custom-guess-type (symbol)
521 "Guess a widget suitable for editing the value of SYMBOL.
522 This is done by matching SYMBOL with `custom-guess-name-alist' and
523 if that fails, the doc string with `custom-guess-doc-alist'."
524 (let ((name (symbol-name symbol))
525 (names custom-guess-name-alist)
526 current found)
527 (while names
528 (setq current (car names)
529 names (cdr names))
530 (when (string-match (nth 0 current) name)
531 (setq found (nth 1 current)
532 names nil)))
533 (unless found
534 (let ((doc (documentation-property symbol 'variable-documentation))
535 (docs custom-guess-doc-alist))
536 (when doc
537 (while docs
538 (setq current (car docs)
539 docs (cdr docs))
540 (when (string-match (nth 0 current) doc)
541 (setq found (nth 1 current)
542 docs nil))))))
543 found))
544
545 ;;; Sorting.
546
547 (defcustom custom-browse-sort-alphabetically nil
548 "If non-nil, sort members of each customization group alphabetically."
549 :type 'boolean
550 :group 'custom-browse)
551
552 (defcustom custom-browse-order-groups nil
553 "If non-nil, order group members within each customization group.
554 If `first', order groups before non-groups.
555 If `last', order groups after non-groups."
556 :type '(choice (const first)
557 (const last)
558 (const :tag "none" nil))
559 :group 'custom-browse)
560
561 (defcustom custom-browse-only-groups nil
562 "If non-nil, show group members only within each customization group."
563 :type 'boolean
564 :group 'custom-browse)
565
566 (defcustom custom-buffer-sort-alphabetically nil
567 "If non-nil, sort members of each customization group alphabetically."
568 :type 'boolean
569 :group 'custom-buffer)
570
571 (defcustom custom-buffer-order-groups 'last
572 "If non-nil, order group members within each customization group.
573 If `first', order groups before non-groups.
574 If `last', order groups after non-groups."
575 :type '(choice (const first)
576 (const last)
577 (const :tag "none" nil))
578 :group 'custom-buffer)
579
580 (defcustom custom-menu-sort-alphabetically nil
581 "If non-nil, sort members of each customization group alphabetically."
582 :type 'boolean
583 :group 'custom-menu)
584
585 (defcustom custom-menu-order-groups 'first
586 "If non-nil, order group members within each customization group.
587 If `first', order groups before non-groups.
588 If `last', order groups after non-groups."
589 :type '(choice (const first)
590 (const last)
591 (const :tag "none" nil))
592 :group 'custom-menu)
593
594 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
595
596 (defun custom-sort-items (items sort-alphabetically order-groups)
597 "Return a sorted copy of ITEMS.
598 ITEMS should be a `custom-group' property.
599 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
600 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
601 groups after non-groups, if nil do not order groups at all."
602 (sort (copy-sequence items)
603 (lambda (a b)
604 (let ((typea (nth 1 a)) (typeb (nth 1 b))
605 (namea (nth 0 a)) (nameb (nth 0 b)))
606 (cond ((not order-groups)
607 ;; Since we don't care about A and B order, maybe sort.
608 (when sort-alphabetically
609 (string-lessp namea nameb)))
610 ((eq typea 'custom-group)
611 ;; If B is also a group, maybe sort. Otherwise, order A and B.
612 (if (eq typeb 'custom-group)
613 (when sort-alphabetically
614 (string-lessp namea nameb))
615 (eq order-groups 'first)))
616 ((eq typeb 'custom-group)
617 ;; Since A cannot be a group, order A and B.
618 (eq order-groups 'last))
619 (sort-alphabetically
620 ;; Since A and B cannot be groups, sort.
621 (string-lessp namea nameb)))))))
622
623 ;;; Custom Mode Commands.
624
625 (defvar custom-options nil
626 "Customization widgets in the current buffer.")
627
628 (defun Custom-set ()
629 "Set changes in all modified options."
630 (interactive)
631 (let ((children custom-options))
632 (mapc (lambda (child)
633 (when (eq (widget-get child :custom-state) 'modified)
634 (widget-apply child :custom-set)))
635 children)))
636
637 (defun Custom-save ()
638 "Set all modified group members and save them."
639 (interactive)
640 (let ((children custom-options))
641 (mapc (lambda (child)
642 (when (memq (widget-get child :custom-state)
643 '(modified set changed rogue))
644 (widget-apply child :custom-save)))
645 children))
646 (custom-save-all))
647
648 (defvar custom-reset-menu
649 '(("Current" . Custom-reset-current)
650 ("Saved" . Custom-reset-saved)
651 ("Erase Customization (use standard settings)" . Custom-reset-standard))
652 "Alist of actions for the `Reset' button.
653 The key is a string containing the name of the action, the value is a
654 Lisp function taking the widget as an element which will be called
655 when the action is chosen.")
656
657 (defun custom-reset (event)
658 "Select item from reset menu."
659 (let* ((completion-ignore-case t)
660 (answer (widget-choose "Reset to"
661 custom-reset-menu
662 event)))
663 (if answer
664 (funcall answer))))
665
666 (defun Custom-reset-current (&rest ignore)
667 "Reset all modified group members to their current value."
668 (interactive)
669 (let ((children custom-options))
670 (mapc (lambda (widget)
671 (if (memq (widget-get widget :custom-state)
672 '(modified changed))
673 (widget-apply widget :custom-reset-current)))
674 children)))
675
676 (defun Custom-reset-saved (&rest ignore)
677 "Reset all modified or set group members to their saved value."
678 (interactive)
679 (let ((children custom-options))
680 (mapc (lambda (widget)
681 (if (memq (widget-get widget :custom-state)
682 '(modified set changed rogue))
683 (widget-apply widget :custom-reset-saved)))
684 children)))
685
686 (defun Custom-reset-standard (&rest ignore)
687 "Erase all customization (either current or saved) for the group members.
688 The immediate result is to restore them to their standard settings.
689 This operation eliminates any saved settings for the group members,
690 making them as if they had never been customized at all."
691 (interactive)
692 (let ((children custom-options))
693 (mapc (lambda (widget)
694 (and (widget-apply widget :custom-standard-value)
695 (if (memq (widget-get widget :custom-state)
696 '(modified set changed saved rogue))
697 (widget-apply widget :custom-reset-standard))))
698 children)))
699
700 ;;; The Customize Commands
701
702 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
703 "Prompt for a variable and a value and return them as a list.
704 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
705 prompt for the value. The %s escape in PROMPT-VAL is replaced with
706 the name of the variable.
707
708 If the variable has a `variable-interactive' property, that is used as if
709 it were the arg to `interactive' (which see) to interactively read the value.
710
711 If the variable has a `custom-type' property, it must be a widget and the
712 `:prompt-value' property of that widget will be used for reading the value.
713
714 If optional COMMENT argument is non nil, also prompt for a comment and return
715 it as the third element in the list."
716 (let* ((var (read-variable prompt-var))
717 (minibuffer-help-form '(describe-variable var))
718 (val
719 (let ((prop (get var 'variable-interactive))
720 (type (get var 'custom-type))
721 (prompt (format prompt-val var)))
722 (unless (listp type)
723 (setq type (list type)))
724 (cond (prop
725 ;; Use VAR's `variable-interactive' property
726 ;; as an interactive spec for prompting.
727 (call-interactively (list 'lambda '(arg)
728 (list 'interactive prop)
729 'arg)))
730 (type
731 (widget-prompt-value type
732 prompt
733 (if (boundp var)
734 (symbol-value var))
735 (not (boundp var))))
736 (t
737 (eval-minibuffer prompt))))))
738 (if comment
739 (list var val
740 (read-string "Comment: " (get var 'variable-comment)))
741 (list var val))))
742
743 ;;;###autoload
744 (defun customize-set-value (variable value &optional comment)
745 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
746
747 If VARIABLE has a `variable-interactive' property, that is used as if
748 it were the arg to `interactive' (which see) to interactively read the value.
749
750 If VARIABLE has a `custom-type' property, it must be a widget and the
751 `:prompt-value' property of that widget will be used for reading the value.
752
753 If given a prefix (or a COMMENT argument), also prompt for a comment."
754 (interactive (custom-prompt-variable "Set variable: "
755 "Set %s to value: "
756 current-prefix-arg))
757
758 (cond ((string= comment "")
759 (put variable 'variable-comment nil))
760 (comment
761 (put variable 'variable-comment comment)))
762 (set variable value))
763
764 ;;;###autoload
765 (defun customize-set-variable (variable value &optional comment)
766 "Set the default for VARIABLE to VALUE, and return VALUE.
767 VALUE is a Lisp object.
768
769 If VARIABLE has a `custom-set' property, that is used for setting
770 VARIABLE, otherwise `set-default' is used.
771
772 The `customized-value' property of the VARIABLE will be set to a list
773 with a quoted VALUE as its sole list member.
774
775 If VARIABLE has a `variable-interactive' property, that is used as if
776 it were the arg to `interactive' (which see) to interactively read the value.
777
778 If VARIABLE has a `custom-type' property, it must be a widget and the
779 `:prompt-value' property of that widget will be used for reading the value.
780
781 If given a prefix (or a COMMENT argument), also prompt for a comment."
782 (interactive (custom-prompt-variable "Set variable: "
783 "Set customized value for %s to: "
784 current-prefix-arg))
785 (custom-load-symbol variable)
786 (funcall (or (get variable 'custom-set) 'set-default) variable value)
787 (put variable 'customized-value (list (custom-quote value)))
788 (cond ((string= comment "")
789 (put variable 'variable-comment nil)
790 (put variable 'customized-variable-comment nil))
791 (comment
792 (put variable 'variable-comment comment)
793 (put variable 'customized-variable-comment comment)))
794 value)
795
796 ;;;###autoload
797 (defun customize-save-variable (variable value &optional comment)
798 "Set the default for VARIABLE to VALUE, and save it for future sessions.
799 Return VALUE.
800
801 If VARIABLE has a `custom-set' property, that is used for setting
802 VARIABLE, otherwise `set-default' is used.
803
804 The `customized-value' property of the VARIABLE will be set to a list
805 with a quoted VALUE as its sole list member.
806
807 If VARIABLE has a `variable-interactive' property, that is used as if
808 it were the arg to `interactive' (which see) to interactively read the value.
809
810 If VARIABLE has a `custom-type' property, it must be a widget and the
811 `:prompt-value' property of that widget will be used for reading the value.
812
813 If given a prefix (or a COMMENT argument), also prompt for a comment."
814 (interactive (custom-prompt-variable "Set and save variable: "
815 "Set and save value for %s as: "
816 current-prefix-arg))
817 (funcall (or (get variable 'custom-set) 'set-default) variable value)
818 (put variable 'saved-value (list (custom-quote value)))
819 (custom-push-theme 'theme-value variable 'user 'set (list (custom-quote value)))
820 (cond ((string= comment "")
821 (put variable 'variable-comment nil)
822 (put variable 'saved-variable-comment nil))
823 (comment
824 (put variable 'variable-comment comment)
825 (put variable 'saved-variable-comment comment)))
826 (custom-save-all)
827 value)
828
829 ;;;###autoload
830 (defun customize ()
831 "Select a customization buffer which you can use to set user options.
832 User options are structured into \"groups\".
833 Initially the top-level group `Emacs' and its immediate subgroups
834 are shown; the contents of those subgroups are initially hidden."
835 (interactive)
836 (customize-group 'emacs))
837
838 ;;;###autoload
839 (defun customize-mode (mode)
840 "Customize options related to the current major mode.
841 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
842 then prompt for the MODE to customize."
843 (interactive
844 (list
845 (let ((completion-regexp-list '("-mode\\'"))
846 (group (custom-group-of-mode major-mode)))
847 (if (and group (not current-prefix-arg))
848 major-mode
849 (intern
850 (completing-read (if group
851 (format "Major mode (default %s): " major-mode)
852 "Major mode: ")
853 obarray
854 'custom-group-of-mode
855 t nil nil (if group (symbol-name major-mode))))))))
856 (customize-group (custom-group-of-mode mode)))
857
858
859 ;;;###autoload
860 (defun customize-group (group)
861 "Customize GROUP, which must be a customization group."
862 (interactive (list (let ((completion-ignore-case t))
863 (completing-read "Customize group: (default emacs) "
864 obarray
865 (lambda (symbol)
866 (or (get symbol 'custom-loads)
867 (get symbol 'custom-group)))
868 t))))
869 (when (stringp group)
870 (if (string-equal "" group)
871 (setq group 'emacs)
872 (setq group (intern group))))
873 (let ((name (format "*Customize Group: %s*"
874 (custom-unlispify-tag-name group))))
875 (if (get-buffer name)
876 (pop-to-buffer name)
877 (custom-buffer-create (list (list group 'custom-group))
878 name
879 (concat " for group "
880 (custom-unlispify-tag-name group))))))
881
882 ;;;###autoload
883 (defun customize-group-other-window (group)
884 "Customize GROUP, which must be a customization group."
885 (interactive (list (let ((completion-ignore-case t))
886 (completing-read "Customize group: (default emacs) "
887 obarray
888 (lambda (symbol)
889 (or (get symbol 'custom-loads)
890 (get symbol 'custom-group)))
891 t))))
892 (when (stringp group)
893 (if (string-equal "" group)
894 (setq group 'emacs)
895 (setq group (intern group))))
896 (let ((name (format "*Customize Group: %s*"
897 (custom-unlispify-tag-name group))))
898 (if (get-buffer name)
899 (let (
900 ;; Copied from `custom-buffer-create-other-window'.
901 (pop-up-windows t)
902 (same-window-buffer-names nil)
903 (same-window-regexps nil))
904 (pop-to-buffer name))
905 (custom-buffer-create-other-window
906 (list (list group 'custom-group))
907 name
908 (concat " for group "
909 (custom-unlispify-tag-name group))))))
910
911 ;;;###autoload
912 (defalias 'customize-variable 'customize-option)
913
914 ;;;###autoload
915 (defun customize-option (symbol)
916 "Customize SYMBOL, which must be a user option variable."
917 (interactive (custom-variable-prompt))
918 (custom-buffer-create (list (list symbol 'custom-variable))
919 (format "*Customize Option: %s*"
920 (custom-unlispify-tag-name symbol))))
921
922 ;;;###autoload
923 (defalias 'customize-variable-other-window 'customize-option-other-window)
924
925 ;;;###autoload
926 (defun customize-option-other-window (symbol)
927 "Customize SYMBOL, which must be a user option variable.
928 Show the buffer in another window, but don't select it."
929 (interactive (custom-variable-prompt))
930 (custom-buffer-create-other-window
931 (list (list symbol 'custom-variable))
932 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
933
934 (defvar customize-changed-options-previous-release "20.2"
935 "Version for `customize-changed-options' to refer back to by default.")
936
937 ;;;###autoload
938 (defun customize-changed-options (since-version)
939 "Customize all user option variables changed in Emacs itself.
940 This includes new user option variables and faces, and new
941 customization groups, as well as older options and faces whose default
942 values have changed since the previous major Emacs release.
943
944 With argument SINCE-VERSION (a string), customize all user option
945 variables that were added (or their meanings were changed) since that
946 version."
947
948 (interactive "sCustomize options changed, since version (default all versions): ")
949 (if (equal since-version "")
950 (setq since-version nil)
951 (unless (condition-case nil
952 (numberp (read since-version))
953 (error nil))
954 (signal 'wrong-type-argument (list 'numberp since-version))))
955 (unless since-version
956 (setq since-version customize-changed-options-previous-release))
957
958 ;; Load the information for versions since since-version. We use
959 ;; custom-load-symbol for this.
960 (put 'custom-versions-load-alist 'custom-loads nil)
961 (dolist (elt custom-versions-load-alist)
962 (if (customize-version-lessp since-version (car elt))
963 (dolist (load (cdr elt))
964 (custom-add-load 'custom-versions-load-alist load))))
965 (custom-load-symbol 'custom-versions-load-alist)
966 (put 'custom-versions-load-alist 'custom-loads nil)
967
968 (let (found)
969 (mapatoms
970 (lambda (symbol)
971 (let ((version (get symbol 'custom-version)))
972 (if version
973 (when (customize-version-lessp since-version version)
974 (if (or (get symbol 'custom-group)
975 (get symbol 'group-documentation))
976 (push (list symbol 'custom-group) found))
977 (if (custom-variable-p symbol)
978 (push (list symbol 'custom-variable) found))
979 (if (custom-facep symbol)
980 (push (list symbol 'custom-face) found)))))))
981 (if found
982 (custom-buffer-create (custom-sort-items found t 'first)
983 "*Customize Changed Options*")
984 (error "No user option defaults have been changed since Emacs %s"
985 since-version))))
986
987 (defun customize-version-lessp (version1 version2)
988 ;; Why are the versions strings, and given that they are, why aren't
989 ;; they converted to numbers and compared as such here? -- fx
990
991 ;; In case someone made a mistake and left out the quotes
992 ;; in the :version value.
993 (if (numberp version2)
994 (setq version2 (prin1-to-string version2)))
995 (let (major1 major2 minor1 minor2)
996 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
997 (setq major1 (read (or (match-string 1 version1)
998 "0")))
999 (setq minor1 (read (or (match-string 3 version1)
1000 "0")))
1001 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1002 (setq major2 (read (or (match-string 1 version2)
1003 "0")))
1004 (setq minor2 (read (or (match-string 3 version2)
1005 "0")))
1006 (or (< major1 major2)
1007 (and (= major1 major2)
1008 (< minor1 minor2)))))
1009
1010 ;;;###autoload
1011 (defun customize-face (&optional face)
1012 "Customize FACE, which should be a face name or nil.
1013 If FACE is nil, customize all faces.
1014
1015 Interactively, when point is on text which has a face specified,
1016 suggest to customize that face, if it's customizable."
1017 (interactive
1018 (list (read-face-name "Customize face" "all faces" t)))
1019 (if (member face '(nil ""))
1020 (setq face (face-list)))
1021 (if (and (listp face) (null (cdr face)))
1022 (setq face (car face)))
1023 (if (listp face)
1024 (custom-buffer-create (custom-sort-items
1025 (mapcar (lambda (s)
1026 (list s 'custom-face))
1027 face)
1028 t nil)
1029 "*Customize Faces*")
1030 (unless (facep face)
1031 (error "Invalid face %S" face))
1032 (custom-buffer-create (list (list face 'custom-face))
1033 (format "*Customize Face: %s*"
1034 (custom-unlispify-tag-name face)))))
1035
1036 ;;;###autoload
1037 (defun customize-face-other-window (&optional face)
1038 "Show customization buffer for face FACE in other window.
1039
1040 Interactively, when point is on text which has a face specified,
1041 suggest to customize that face, if it's customizable."
1042 (interactive
1043 (list (read-face-name "Customize face" "all faces" t)))
1044 (if (member face '(nil ""))
1045 (setq face (face-list)))
1046 (if (and (listp face) (null (cdr face)))
1047 (setq face (car face)))
1048 (if (listp face)
1049 (custom-buffer-create-other-window
1050 (custom-sort-items
1051 (mapcar (lambda (s)
1052 (list s 'custom-face))
1053 face)
1054 t nil)
1055 "*Customize Faces*")
1056 (unless (facep face)
1057 (error "Invalid face %S" face))
1058 (custom-buffer-create-other-window
1059 (list (list face 'custom-face))
1060 (format "*Customize Face: %s*"
1061 (custom-unlispify-tag-name face)))))
1062
1063 ;;;###autoload
1064 (defun customize-customized ()
1065 "Customize all user options set since the last save in this session."
1066 (interactive)
1067 (let ((found nil))
1068 (mapatoms (lambda (symbol)
1069 (and (or (get symbol 'customized-face)
1070 (get symbol 'customized-face-comment))
1071 (custom-facep symbol)
1072 (push (list symbol 'custom-face) found))
1073 (and (or (get symbol 'customized-value)
1074 (get symbol 'customized-variable-comment))
1075 (boundp symbol)
1076 (push (list symbol 'custom-variable) found))))
1077 (if (not found)
1078 (error "No customized user options")
1079 (custom-buffer-create (custom-sort-items found t nil)
1080 "*Customize Customized*"))))
1081
1082 ;;;###autoload
1083 (defun customize-rogue ()
1084 "Customize all user variable modified outside customize."
1085 (interactive)
1086 (let ((found nil))
1087 (mapatoms (lambda (symbol)
1088 (let ((cval (or (get symbol 'customized-value)
1089 (get symbol 'saved-value)
1090 (get symbol 'standard-value))))
1091 (when (and cval ;Declared with defcustom.
1092 (default-boundp symbol) ;Has a value.
1093 (not (equal (eval (car cval))
1094 ;; Which does not match customize.
1095 (default-value symbol))))
1096 (push (list symbol 'custom-variable) found)))))
1097 (if (not found)
1098 (error "No rogue user options")
1099 (custom-buffer-create (custom-sort-items found t nil)
1100 "*Customize Rogue*"))))
1101 ;;;###autoload
1102 (defun customize-saved ()
1103 "Customize all already saved user options."
1104 (interactive)
1105 (let ((found nil))
1106 (mapatoms (lambda (symbol)
1107 (and (or (get symbol 'saved-face)
1108 (get symbol 'saved-face-comment))
1109 (custom-facep symbol)
1110 (push (list symbol 'custom-face) found))
1111 (and (or (get symbol 'saved-value)
1112 (get symbol 'saved-variable-comment))
1113 (boundp symbol)
1114 (push (list symbol 'custom-variable) found))))
1115 (if (not found )
1116 (error "No saved user options")
1117 (custom-buffer-create (custom-sort-items found t nil)
1118 "*Customize Saved*"))))
1119
1120 ;;;###autoload
1121 (defun customize-apropos (regexp &optional all)
1122 "Customize all user options matching REGEXP.
1123 If ALL is `options', include only options.
1124 If ALL is `faces', include only faces.
1125 If ALL is `groups', include only groups.
1126 If ALL is t (interactively, with prefix arg), include options which are not
1127 user-settable, as well as faces and groups."
1128 (interactive "sCustomize regexp: \nP")
1129 (let ((found nil))
1130 (mapatoms (lambda (symbol)
1131 (when (string-match regexp (symbol-name symbol))
1132 (when (and (not (memq all '(faces options)))
1133 (get symbol 'custom-group))
1134 (push (list symbol 'custom-group) found))
1135 (when (and (not (memq all '(options groups)))
1136 (custom-facep symbol))
1137 (push (list symbol 'custom-face) found))
1138 (when (and (not (memq all '(groups faces)))
1139 (boundp symbol)
1140 (or (get symbol 'saved-value)
1141 (custom-variable-p symbol)
1142 (if (memq all '(nil options))
1143 (user-variable-p symbol)
1144 (get symbol 'variable-documentation))))
1145 (push (list symbol 'custom-variable) found)))))
1146 (if (not found)
1147 (error "No matches")
1148 (custom-buffer-create (custom-sort-items found t
1149 custom-buffer-order-groups)
1150 "*Customize Apropos*"))))
1151
1152 ;;;###autoload
1153 (defun customize-apropos-options (regexp &optional arg)
1154 "Customize all user options matching REGEXP.
1155 With prefix arg, include options which are not user-settable."
1156 (interactive "sCustomize regexp: \nP")
1157 (customize-apropos regexp (or arg 'options)))
1158
1159 ;;;###autoload
1160 (defun customize-apropos-faces (regexp)
1161 "Customize all user faces matching REGEXP."
1162 (interactive "sCustomize regexp: \n")
1163 (customize-apropos regexp 'faces))
1164
1165 ;;;###autoload
1166 (defun customize-apropos-groups (regexp)
1167 "Customize all user groups matching REGEXP."
1168 (interactive "sCustomize regexp: \n")
1169 (customize-apropos regexp 'groups))
1170
1171 ;;; Buffer.
1172
1173 (defcustom custom-buffer-style 'links
1174 "Control the presentation style for customization buffers.
1175 The value should be a symbol, one of:
1176
1177 brackets: groups nest within each other with big horizontal brackets.
1178 links: groups have links to subgroups."
1179 :type '(radio (const brackets)
1180 (const links))
1181 :group 'custom-buffer)
1182
1183 (defcustom custom-buffer-done-kill nil
1184 "*Non-nil means exiting a Custom buffer should kill it."
1185 :type 'boolean
1186 :version "22.1"
1187 :group 'custom-buffer)
1188
1189 (defcustom custom-buffer-indent 3
1190 "Number of spaces to indent nested groups."
1191 :type 'integer
1192 :group 'custom-buffer)
1193
1194 (defun custom-get-fresh-buffer (name)
1195 "Get a fresh new buffer with name NAME.
1196 If the buffer already exist, clean it up to be like new.
1197 Beware: it's not quite like new. Good enough for custom, but maybe
1198 not for everybody."
1199 ;; To be more complete, we should also kill all permanent-local variables,
1200 ;; but it's not needed for custom.
1201 (let ((buf (get-buffer name)))
1202 (when (and buf (buffer-local-value 'buffer-file-name buf))
1203 ;; This will check if the file is not saved.
1204 (kill-buffer buf)
1205 (setq buf nil))
1206 (if (null buf)
1207 (get-buffer-create name)
1208 (with-current-buffer buf
1209 (kill-all-local-variables)
1210 (run-hooks 'kill-buffer-hook)
1211 ;; Delete overlays before erasing the buffer so the overlay hooks
1212 ;; don't get run spuriously when we erase the buffer.
1213 (let ((ols (overlay-lists)))
1214 (dolist (ol (nconc (car ols) (cdr ols)))
1215 (delete-overlay ol)))
1216 (erase-buffer)
1217 buf))))
1218
1219 ;;;###autoload
1220 (defun custom-buffer-create (options &optional name description)
1221 "Create a buffer containing OPTIONS.
1222 Optional NAME is the name of the buffer.
1223 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1224 SYMBOL is a customization option, and WIDGET is a widget for editing
1225 that option."
1226 (pop-to-buffer (custom-get-fresh-buffer (or name "*Customization*")))
1227 (custom-buffer-create-internal options description))
1228
1229 ;;;###autoload
1230 (defun custom-buffer-create-other-window (options &optional name description)
1231 "Create a buffer containing OPTIONS, and display it in another window.
1232 The result includes selecting that window.
1233 Optional NAME is the name of the buffer.
1234 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1235 SYMBOL is a customization option, and WIDGET is a widget for editing
1236 that option."
1237 (unless name (setq name "*Customization*"))
1238 (let ((pop-up-windows t)
1239 (same-window-buffer-names nil)
1240 (same-window-regexps nil))
1241 (pop-to-buffer (custom-get-fresh-buffer name))
1242 (custom-buffer-create-internal options description)))
1243
1244 (defcustom custom-reset-button-menu nil
1245 "If non-nil, only show a single reset button in customize buffers.
1246 This button will have a menu with all three reset operations."
1247 :type 'boolean
1248 :group 'custom-buffer)
1249
1250 (defcustom custom-buffer-verbose-help t
1251 "If non-nil, include explanatory text in the customization buffer."
1252 :type 'boolean
1253 :group 'custom-buffer)
1254
1255 (defun Custom-buffer-done (&rest ignore)
1256 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1257 (interactive)
1258 (quit-window custom-buffer-done-kill))
1259
1260 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1261 '(("unspecified" . unspecified))))
1262 "If non-nil, indicate active buttons in a `raised-button' style.
1263 Otherwise use brackets."
1264 :type 'boolean
1265 :version "21.1"
1266 :group 'custom-buffer)
1267
1268 (defun custom-buffer-create-internal (options &optional description)
1269 (message "Creating customization buffer...")
1270 (custom-mode)
1271 (if custom-buffer-verbose-help
1272 (progn
1273 (widget-insert "This is a customization buffer")
1274 (if description
1275 (widget-insert description))
1276 (widget-insert (format ".
1277 %s show active fields; type RET or click mouse-1
1278 on an active field to invoke its action. Editing an option value
1279 changes the text in the buffer; invoke the State button and
1280 choose the Set operation to set the option value.
1281 Invoke " (if custom-raised-buttons
1282 "`Raised' buttons"
1283 "Square brackets")))
1284 (widget-create 'info-link
1285 :tag "Help"
1286 :help-echo "Read the online help."
1287 "(emacs)Easy Customization")
1288 (widget-insert " for more information.\n\n")
1289 (message "Creating customization buttons...")
1290 (widget-insert "Operate on everything in this buffer:\n "))
1291 (widget-insert " "))
1292 (widget-create 'push-button
1293 :tag "Set for Current Session"
1294 :help-echo "\
1295 Make your editing in this buffer take effect for this session."
1296 :action (lambda (widget &optional event)
1297 (Custom-set)))
1298 (widget-insert " ")
1299 (widget-create 'push-button
1300 :tag "Save for Future Sessions"
1301 :help-echo "\
1302 Make your editing in this buffer take effect for future Emacs sessions."
1303 :action (lambda (widget &optional event)
1304 (Custom-save)))
1305 (if custom-reset-button-menu
1306 (progn
1307 (widget-insert " ")
1308 (widget-create 'push-button
1309 :tag "Reset"
1310 :help-echo "Show a menu with reset operations."
1311 :mouse-down-action (lambda (&rest junk) t)
1312 :action (lambda (widget &optional event)
1313 (custom-reset event))))
1314 (widget-insert "\n ")
1315 (widget-create 'push-button
1316 :tag "Reset"
1317 :help-echo "\
1318 Reset all edited text in this buffer to reflect current values."
1319 :action 'Custom-reset-current)
1320 (widget-insert " ")
1321 (widget-create 'push-button
1322 :tag "Reset to Saved"
1323 :help-echo "\
1324 Reset all values in this buffer to their saved settings."
1325 :action 'Custom-reset-saved)
1326 (widget-insert " ")
1327 (widget-create 'push-button
1328 :tag "Erase Customization"
1329 :help-echo "\
1330 Un-customize all values in this buffer. They get their standard settings."
1331 :action 'Custom-reset-standard))
1332 (if (not custom-buffer-verbose-help)
1333 (progn
1334 (widget-insert " ")
1335 (widget-create 'info-link
1336 :tag "Help"
1337 :help-echo "Read the online help."
1338 "(emacs)Easy Customization")))
1339 (widget-insert " ")
1340 (widget-create 'push-button
1341 :tag "Finish"
1342 :help-echo
1343 (lambda (&rest ignore)
1344 (if custom-buffer-done-kill
1345 "Kill this buffer"
1346 "Bury this buffer"))
1347 :action #'Custom-buffer-done)
1348 (widget-insert "\n\n")
1349 (message "Creating customization items...")
1350 (buffer-disable-undo)
1351 (setq custom-options
1352 (if (= (length options) 1)
1353 (mapcar (lambda (entry)
1354 (widget-create (nth 1 entry)
1355 :documentation-shown t
1356 :custom-state 'unknown
1357 :tag (custom-unlispify-tag-name
1358 (nth 0 entry))
1359 :value (nth 0 entry)))
1360 options)
1361 (let ((count 0)
1362 (length (length options)))
1363 (mapcar (lambda (entry)
1364 (prog2
1365 (message "Creating customization items ...%2d%%"
1366 (/ (* 100.0 count) length))
1367 (widget-create (nth 1 entry)
1368 :tag (custom-unlispify-tag-name
1369 (nth 0 entry))
1370 :value (nth 0 entry))
1371 (setq count (1+ count))
1372 (unless (eq (preceding-char) ?\n)
1373 (widget-insert "\n"))
1374 (widget-insert "\n")))
1375 options))))
1376 (unless (eq (preceding-char) ?\n)
1377 (widget-insert "\n"))
1378 (message "Creating customization items ...done")
1379 (unless (eq custom-buffer-style 'tree)
1380 (mapc 'custom-magic-reset custom-options))
1381 (message "Creating customization setup...")
1382 (widget-setup)
1383 (buffer-enable-undo)
1384 (goto-char (point-min))
1385 (message "Creating customization buffer...done"))
1386
1387 ;;; The Tree Browser.
1388
1389 ;;;###autoload
1390 (defun customize-browse (&optional group)
1391 "Create a tree browser for the customize hierarchy."
1392 (interactive)
1393 (unless group
1394 (setq group 'emacs))
1395 (let ((name "*Customize Browser*"))
1396 (pop-to-buffer (custom-get-fresh-buffer name)))
1397 (custom-mode)
1398 (widget-insert "\
1399 Square brackets show active fields; type RET or click mouse-1
1400 on an active field to invoke its action.
1401 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1402 (if custom-browse-only-groups
1403 (widget-insert "\
1404 Invoke the [Group] button below to edit that item in another window.\n\n")
1405 (widget-insert "Invoke the ")
1406 (widget-create 'item
1407 :format "%t"
1408 :tag "[Group]"
1409 :tag-glyph "folder")
1410 (widget-insert ", ")
1411 (widget-create 'item
1412 :format "%t"
1413 :tag "[Face]"
1414 :tag-glyph "face")
1415 (widget-insert ", and ")
1416 (widget-create 'item
1417 :format "%t"
1418 :tag "[Option]"
1419 :tag-glyph "option")
1420 (widget-insert " buttons below to edit that
1421 item in another window.\n\n"))
1422 (let ((custom-buffer-style 'tree))
1423 (widget-create 'custom-group
1424 :custom-last t
1425 :custom-state 'unknown
1426 :tag (custom-unlispify-tag-name group)
1427 :value group))
1428 (widget-setup)
1429 (goto-char (point-min)))
1430
1431 (define-widget 'custom-browse-visibility 'item
1432 "Control visibility of items in the customize tree browser."
1433 :format "%[[%t]%]"
1434 :action 'custom-browse-visibility-action)
1435
1436 (defun custom-browse-visibility-action (widget &rest ignore)
1437 (let ((custom-buffer-style 'tree))
1438 (custom-toggle-parent widget)))
1439
1440 (define-widget 'custom-browse-group-tag 'push-button
1441 "Show parent in other window when activated."
1442 :tag "Group"
1443 :tag-glyph "folder"
1444 :action 'custom-browse-group-tag-action)
1445
1446 (defun custom-browse-group-tag-action (widget &rest ignore)
1447 (let ((parent (widget-get widget :parent)))
1448 (customize-group-other-window (widget-value parent))))
1449
1450 (define-widget 'custom-browse-variable-tag 'push-button
1451 "Show parent in other window when activated."
1452 :tag "Option"
1453 :tag-glyph "option"
1454 :action 'custom-browse-variable-tag-action)
1455
1456 (defun custom-browse-variable-tag-action (widget &rest ignore)
1457 (let ((parent (widget-get widget :parent)))
1458 (customize-variable-other-window (widget-value parent))))
1459
1460 (define-widget 'custom-browse-face-tag 'push-button
1461 "Show parent in other window when activated."
1462 :tag "Face"
1463 :tag-glyph "face"
1464 :action 'custom-browse-face-tag-action)
1465
1466 (defun custom-browse-face-tag-action (widget &rest ignore)
1467 (let ((parent (widget-get widget :parent)))
1468 (customize-face-other-window (widget-value parent))))
1469
1470 (defconst custom-browse-alist '((" " "space")
1471 (" | " "vertical")
1472 ("-\\ " "top")
1473 (" |-" "middle")
1474 (" `-" "bottom")))
1475
1476 (defun custom-browse-insert-prefix (prefix)
1477 "Insert PREFIX. On XEmacs convert it to line graphics."
1478 ;; Fixme: do graphics.
1479 (if nil ; (string-match "XEmacs" emacs-version)
1480 (progn
1481 (insert "*")
1482 (while (not (string-equal prefix ""))
1483 (let ((entry (substring prefix 0 3)))
1484 (setq prefix (substring prefix 3))
1485 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1486 (name (nth 1 (assoc entry custom-browse-alist))))
1487 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1488 (overlay-put overlay 'start-open t)
1489 (overlay-put overlay 'end-open t)))))
1490 (insert prefix)))
1491
1492 ;;; Modification of Basic Widgets.
1493 ;;
1494 ;; We add extra properties to the basic widgets needed here. This is
1495 ;; fine, as long as we are careful to stay within out own namespace.
1496 ;;
1497 ;; We want simple widgets to be displayed by default, but complex
1498 ;; widgets to be hidden.
1499
1500 (widget-put (get 'item 'widget-type) :custom-show t)
1501 (widget-put (get 'editable-field 'widget-type)
1502 :custom-show (lambda (widget value)
1503 (let ((pp (pp-to-string value)))
1504 (cond ((string-match "\n" pp)
1505 nil)
1506 ((> (length pp) 40)
1507 nil)
1508 (t t)))))
1509 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1510
1511 ;;; The `custom-manual' Widget.
1512
1513 (define-widget 'custom-manual 'info-link
1514 "Link to the manual entry for this customization option."
1515 :help-echo "Read the manual entry for this option."
1516 :tag "Manual")
1517
1518 ;;; The `custom-magic' Widget.
1519
1520 (defgroup custom-magic-faces nil
1521 "Faces used by the magic button."
1522 :group 'custom-faces
1523 :group 'custom-buffer)
1524
1525 (defface custom-invalid-face '((((class color))
1526 (:foreground "yellow" :background "red"))
1527 (t
1528 (:weight bold :slant italic :underline t)))
1529 "Face used when the customize item is invalid."
1530 :group 'custom-magic-faces)
1531
1532 (defface custom-rogue-face '((((class color))
1533 (:foreground "pink" :background "black"))
1534 (t
1535 (:underline t)))
1536 "Face used when the customize item is not defined for customization."
1537 :group 'custom-magic-faces)
1538
1539 (defface custom-modified-face '((((class color))
1540 (:foreground "white" :background "blue"))
1541 (t
1542 (:slant italic :bold)))
1543 "Face used when the customize item has been modified."
1544 :group 'custom-magic-faces)
1545
1546 (defface custom-set-face '((((class color))
1547 (:foreground "blue" :background "white"))
1548 (t
1549 (:slant italic)))
1550 "Face used when the customize item has been set."
1551 :group 'custom-magic-faces)
1552
1553 (defface custom-changed-face '((((class color))
1554 (:foreground "white" :background "blue"))
1555 (t
1556 (:slant italic)))
1557 "Face used when the customize item has been changed."
1558 :group 'custom-magic-faces)
1559
1560 (defface custom-saved-face '((t (:underline t)))
1561 "Face used when the customize item has been saved."
1562 :group 'custom-magic-faces)
1563
1564 (defconst custom-magic-alist
1565 '((nil "#" underline "\
1566 uninitialized, you should not see this.")
1567 (unknown "?" italic "\
1568 unknown, you should not see this.")
1569 (hidden "-" default "\
1570 hidden, invoke \"Show\" in the previous line to show." "\
1571 group now hidden, invoke \"Show\", above, to show contents.")
1572 (invalid "x" custom-invalid-face "\
1573 the value displayed for this %c is invalid and cannot be set.")
1574 (modified "*" custom-modified-face "\
1575 you have edited the value as text, but you have not set the %c." "\
1576 you have edited something in this group, but not set it.")
1577 (set "+" custom-set-face "\
1578 you have set this %c, but not saved it for future sessions." "\
1579 something in this group has been set, but not saved.")
1580 (changed ":" custom-changed-face "\
1581 this %c has been changed outside the customize buffer." "\
1582 something in this group has been changed outside customize.")
1583 (saved "!" custom-saved-face "\
1584 this %c has been set and saved." "\
1585 something in this group has been set and saved.")
1586 (rogue "@" custom-rogue-face "\
1587 this %c has not been changed with customize." "\
1588 something in this group is not prepared for customization.")
1589 (standard " " nil "\
1590 this %c is unchanged from its standard setting." "\
1591 visible group members are all at standard settings."))
1592 "Alist of customize option states.
1593 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1594
1595 STATE is one of the following symbols:
1596
1597 `nil'
1598 For internal use, should never occur.
1599 `unknown'
1600 For internal use, should never occur.
1601 `hidden'
1602 This item is not being displayed.
1603 `invalid'
1604 This item is modified, but has an invalid form.
1605 `modified'
1606 This item is modified, and has a valid form.
1607 `set'
1608 This item has been set but not saved.
1609 `changed'
1610 The current value of this item has been changed temporarily.
1611 `saved'
1612 This item is marked for saving.
1613 `rogue'
1614 This item has no customization information.
1615 `standard'
1616 This item is unchanged from the standard setting.
1617
1618 MAGIC is a string used to present that state.
1619
1620 FACE is a face used to present the state.
1621
1622 ITEM-DESC is a string describing the state for options.
1623
1624 GROUP-DESC is a string describing the state for groups. If this is
1625 left out, ITEM-DESC will be used.
1626
1627 The string %c in either description will be replaced with the
1628 category of the item. These are `group'. `option', and `face'.
1629
1630 The list should be sorted most significant first.")
1631
1632 (defcustom custom-magic-show 'long
1633 "If non-nil, show textual description of the state.
1634 If `long', show a full-line description, not just one word."
1635 :type '(choice (const :tag "no" nil)
1636 (const long)
1637 (other :tag "short" short))
1638 :group 'custom-buffer)
1639
1640 (defcustom custom-magic-show-hidden '(option face)
1641 "Control whether the State button is shown for hidden items.
1642 The value should be a list with the custom categories where the State
1643 button should be visible. Possible categories are `group', `option',
1644 and `face'."
1645 :type '(set (const group) (const option) (const face))
1646 :group 'custom-buffer)
1647
1648 (defcustom custom-magic-show-button nil
1649 "Show a \"magic\" button indicating the state of each customization option."
1650 :type 'boolean
1651 :group 'custom-buffer)
1652
1653 (define-widget 'custom-magic 'default
1654 "Show and manipulate state for a customization option."
1655 :format "%v"
1656 :action 'widget-parent-action
1657 :notify 'ignore
1658 :value-get 'ignore
1659 :value-create 'custom-magic-value-create
1660 :value-delete 'widget-children-value-delete)
1661
1662 (defun widget-magic-mouse-down-action (widget &optional event)
1663 ;; Non-nil unless hidden.
1664 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1665 :custom-state)
1666 'hidden)))
1667
1668 (defun custom-magic-value-create (widget)
1669 "Create compact status report for WIDGET."
1670 (let* ((parent (widget-get widget :parent))
1671 (state (widget-get parent :custom-state))
1672 (hidden (eq state 'hidden))
1673 (entry (assq state custom-magic-alist))
1674 (magic (nth 1 entry))
1675 (face (nth 2 entry))
1676 (category (widget-get parent :custom-category))
1677 (text (or (and (eq category 'group)
1678 (nth 4 entry))
1679 (nth 3 entry)))
1680 (form (widget-get parent :custom-form))
1681 children)
1682 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1683 (setq text (concat (match-string 1 text)
1684 (symbol-name category)
1685 (match-string 2 text))))
1686 (when (and custom-magic-show
1687 (or (not hidden)
1688 (memq category custom-magic-show-hidden)))
1689 (insert " ")
1690 (when (and (eq category 'group)
1691 (not (and (eq custom-buffer-style 'links)
1692 (> (widget-get parent :custom-level) 1))))
1693 (insert-char ?\ (* custom-buffer-indent
1694 (widget-get parent :custom-level))))
1695 (push (widget-create-child-and-convert
1696 widget 'choice-item
1697 :help-echo "Change the state of this item."
1698 :format (if hidden "%t" "%[%t%]")
1699 :button-prefix 'widget-push-button-prefix
1700 :button-suffix 'widget-push-button-suffix
1701 :mouse-down-action 'widget-magic-mouse-down-action
1702 :tag "State")
1703 children)
1704 (insert ": ")
1705 (let ((start (point)))
1706 (if (eq custom-magic-show 'long)
1707 (insert text)
1708 (insert (symbol-name state)))
1709 (cond ((eq form 'lisp)
1710 (insert " (lisp)"))
1711 ((eq form 'mismatch)
1712 (insert " (mismatch)")))
1713 (put-text-property start (point) 'face 'custom-state-face))
1714 (insert "\n"))
1715 (when (and (eq category 'group)
1716 (not (and (eq custom-buffer-style 'links)
1717 (> (widget-get parent :custom-level) 1))))
1718 (insert-char ?\ (* custom-buffer-indent
1719 (widget-get parent :custom-level))))
1720 (when custom-magic-show-button
1721 (when custom-magic-show
1722 (let ((indent (widget-get parent :indent)))
1723 (when indent
1724 (insert-char ? indent))))
1725 (push (widget-create-child-and-convert
1726 widget 'choice-item
1727 :mouse-down-action 'widget-magic-mouse-down-action
1728 :button-face face
1729 :button-prefix ""
1730 :button-suffix ""
1731 :help-echo "Change the state."
1732 :format (if hidden "%t" "%[%t%]")
1733 :tag (if (memq form '(lisp mismatch))
1734 (concat "(" magic ")")
1735 (concat "[" magic "]")))
1736 children)
1737 (insert " "))
1738 (widget-put widget :children children)))
1739
1740 (defun custom-magic-reset (widget)
1741 "Redraw the :custom-magic property of WIDGET."
1742 (let ((magic (widget-get widget :custom-magic)))
1743 (widget-value-set magic (widget-value magic))))
1744
1745 ;;; The `custom' Widget.
1746
1747 (defface custom-button-face
1748 '((((type x w32 mac) (class color)) ; Like default modeline
1749 (:box (:line-width 2 :style released-button)
1750 :background "lightgrey" :foreground "black"))
1751 (t
1752 nil))
1753 "Face used for buttons in customization buffers."
1754 :version "21.1"
1755 :group 'custom-faces)
1756
1757 (defface custom-button-pressed-face
1758 '((((type x w32 mac) (class color))
1759 (:box (:line-width 2 :style pressed-button)
1760 :background "lightgrey" :foreground "black"))
1761 (t
1762 (:inverse-video t)))
1763 "Face used for buttons in customization buffers."
1764 :version "21.1"
1765 :group 'custom-faces)
1766
1767 (defface custom-documentation-face nil
1768 "Face used for documentation strings in customization buffers."
1769 :group 'custom-faces)
1770
1771 (defface custom-state-face '((((class color)
1772 (background dark))
1773 (:foreground "lime green"))
1774 (((class color)
1775 (background light))
1776 (:foreground "dark green"))
1777 (t nil))
1778 "Face used for State descriptions in the customize buffer."
1779 :group 'custom-faces)
1780
1781 (define-widget 'custom 'default
1782 "Customize a user option."
1783 :format "%v"
1784 :convert-widget 'custom-convert-widget
1785 :notify 'custom-notify
1786 :custom-prefix ""
1787 :custom-level 1
1788 :custom-state 'hidden
1789 :documentation-property 'widget-subclass-responsibility
1790 :value-create 'widget-subclass-responsibility
1791 :value-delete 'widget-children-value-delete
1792 :value-get 'widget-value-value-get
1793 :validate 'widget-children-validate
1794 :match (lambda (widget value) (symbolp value)))
1795
1796 (defun custom-convert-widget (widget)
1797 "Initialize :value and :tag from :args in WIDGET."
1798 (let ((args (widget-get widget :args)))
1799 (when args
1800 (widget-put widget :value (widget-apply widget
1801 :value-to-internal (car args)))
1802 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1803 (widget-put widget :args nil)))
1804 widget)
1805
1806 (defun custom-notify (widget &rest args)
1807 "Keep track of changes."
1808 (let ((state (widget-get widget :custom-state)))
1809 (unless (eq state 'modified)
1810 (unless (memq state '(nil unknown hidden))
1811 (widget-put widget :custom-state 'modified))
1812 (custom-magic-reset widget)
1813 (apply 'widget-default-notify widget args))))
1814
1815 (defun custom-redraw (widget)
1816 "Redraw WIDGET with current settings."
1817 (let ((line (count-lines (point-min) (point)))
1818 (column (current-column))
1819 (pos (point))
1820 (from (marker-position (widget-get widget :from)))
1821 (to (marker-position (widget-get widget :to))))
1822 (save-excursion
1823 (widget-value-set widget (widget-value widget))
1824 (custom-redraw-magic widget))
1825 (when (and (>= pos from) (<= pos to))
1826 (condition-case nil
1827 (progn
1828 (if (> column 0)
1829 (goto-line line)
1830 (goto-line (1+ line)))
1831 (move-to-column column))
1832 (error nil)))))
1833
1834 (defun custom-redraw-magic (widget)
1835 "Redraw WIDGET state with current settings."
1836 (while widget
1837 (let ((magic (widget-get widget :custom-magic)))
1838 (cond (magic
1839 (widget-value-set magic (widget-value magic))
1840 (when (setq widget (widget-get widget :group))
1841 (custom-group-state-update widget)))
1842 (t
1843 (setq widget nil)))))
1844 (widget-setup))
1845
1846 (defun custom-show (widget value)
1847 "Non-nil if WIDGET should be shown with VALUE by default."
1848 (let ((show (widget-get widget :custom-show)))
1849 (cond ((null show)
1850 nil)
1851 ((eq t show)
1852 t)
1853 (t
1854 (funcall show widget value)))))
1855
1856 (defun custom-load-widget (widget)
1857 "Load all dependencies for WIDGET."
1858 (custom-load-symbol (widget-value widget)))
1859
1860 (defun custom-unloaded-symbol-p (symbol)
1861 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
1862 (let ((found nil)
1863 (loads (get symbol 'custom-loads))
1864 load)
1865 (while loads
1866 (setq load (car loads)
1867 loads (cdr loads))
1868 (cond ((symbolp load)
1869 (unless (featurep load)
1870 (setq found t)))
1871 ((assoc load load-history))
1872 ((assoc (locate-library load) load-history)
1873 (message nil))
1874 (t
1875 (setq found t))))
1876 found))
1877
1878 (defun custom-unloaded-widget-p (widget)
1879 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
1880 (custom-unloaded-symbol-p (widget-value widget)))
1881
1882 (defun custom-toggle-hide (widget)
1883 "Toggle visibility of WIDGET."
1884 (custom-load-widget widget)
1885 (let ((state (widget-get widget :custom-state)))
1886 (cond ((memq state '(invalid modified))
1887 (error "There are unset changes"))
1888 ((eq state 'hidden)
1889 (widget-put widget :custom-state 'unknown))
1890 (t
1891 (widget-put widget :documentation-shown nil)
1892 (widget-put widget :custom-state 'hidden)))
1893 (custom-redraw widget)
1894 (widget-setup)))
1895
1896 (defun custom-toggle-parent (widget &rest ignore)
1897 "Toggle visibility of parent of WIDGET."
1898 (custom-toggle-hide (widget-get widget :parent)))
1899
1900 (defun custom-add-see-also (widget &optional prefix)
1901 "Add `See also ...' to WIDGET if there are any links.
1902 Insert PREFIX first if non-nil."
1903 (let* ((symbol (widget-get widget :value))
1904 (links (get symbol 'custom-links))
1905 (many (> (length links) 2))
1906 (buttons (widget-get widget :buttons))
1907 (indent (widget-get widget :indent)))
1908 (when links
1909 (when indent
1910 (insert-char ?\ indent))
1911 (when prefix
1912 (insert prefix))
1913 (insert "See also ")
1914 (while links
1915 (push (widget-create-child-and-convert widget (car links))
1916 buttons)
1917 (setq links (cdr links))
1918 (cond ((null links)
1919 (insert ".\n"))
1920 ((null (cdr links))
1921 (if many
1922 (insert ", and ")
1923 (insert " and ")))
1924 (t
1925 (insert ", "))))
1926 (widget-put widget :buttons buttons))))
1927
1928 (defun custom-add-parent-links (widget &optional initial-string)
1929 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1930 The value if non-nil if any parents were found.
1931 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1932 (let ((name (widget-value widget))
1933 (type (widget-type widget))
1934 (buttons (widget-get widget :buttons))
1935 (start (point))
1936 (parents nil))
1937 (insert (or initial-string "Parent groups:"))
1938 (mapatoms (lambda (symbol)
1939 (let ((entry (assq name (get symbol 'custom-group))))
1940 (when (eq (nth 1 entry) type)
1941 (insert " ")
1942 (push (widget-create-child-and-convert
1943 widget 'custom-group-link
1944 :tag (custom-unlispify-tag-name symbol)
1945 symbol)
1946 buttons)
1947 (setq parents (cons symbol parents))))))
1948 (and (null (get name 'custom-links)) ;No links of its own.
1949 (= (length parents) 1) ;A single parent.
1950 (let* ((links (get (car parents) 'custom-links))
1951 (many (> (length links) 2)))
1952 (when links
1953 (insert "\nParent documentation: ")
1954 (while links
1955 (push (widget-create-child-and-convert widget (car links))
1956 buttons)
1957 (setq links (cdr links))
1958 (cond ((null links)
1959 (insert ".\n"))
1960 ((null (cdr links))
1961 (if many
1962 (insert ", and ")
1963 (insert " and ")))
1964 (t
1965 (insert ", ")))))))
1966 (if parents
1967 (insert "\n")
1968 (delete-region start (point)))
1969 (widget-put widget :buttons buttons)
1970 parents))
1971
1972 ;;; The `custom-comment' Widget.
1973
1974 ;; like the editable field
1975 (defface custom-comment-face '((((class grayscale color)
1976 (background light))
1977 (:background "gray85"))
1978 (((class grayscale color)
1979 (background dark))
1980 (:background "dim gray"))
1981 (t
1982 (:slant italic)))
1983 "Face used for comments on variables or faces"
1984 :version "21.1"
1985 :group 'custom-faces)
1986
1987 ;; like font-lock-comment-face
1988 (defface custom-comment-tag-face
1989 '((((class color) (background dark)) (:foreground "gray80"))
1990 (((class color) (background light)) (:foreground "blue4"))
1991 (((class grayscale) (background light))
1992 (:foreground "DimGray" :weight bold :slant italic))
1993 (((class grayscale) (background dark))
1994 (:foreground "LightGray" :weight bold :slant italic))
1995 (t (:weight bold)))
1996 "Face used for variables or faces comment tags"
1997 :group 'custom-faces)
1998
1999 (define-widget 'custom-comment 'string
2000 "User comment."
2001 :tag "Comment"
2002 :help-echo "Edit a comment here."
2003 :sample-face 'custom-comment-tag-face
2004 :value-face 'custom-comment-face
2005 :shown nil
2006 :create 'custom-comment-create)
2007
2008 (defun custom-comment-create (widget)
2009 (let* ((null-comment (equal "" (widget-value widget))))
2010 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2011 (not null-comment))
2012 (widget-default-create widget)
2013 ;; `widget-default-delete' expects markers in these slots --
2014 ;; maybe it shouldn't.
2015 (widget-put widget :from (point-marker))
2016 (widget-put widget :to (point-marker)))))
2017
2018 (defun custom-comment-hide (widget)
2019 (widget-put (widget-get widget :parent) :comment-shown nil))
2020
2021 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2022 ;; the global custom one
2023 (defun custom-comment-show (widget)
2024 (widget-put widget :comment-shown t)
2025 (custom-redraw widget)
2026 (widget-setup))
2027
2028 (defun custom-comment-invisible-p (widget)
2029 (let ((val (widget-value (widget-get widget :comment-widget))))
2030 (and (equal "" val)
2031 (not (widget-get widget :comment-shown)))))
2032
2033 ;;; The `custom-variable' Widget.
2034
2035 ;; When this was underlined blue, users confused it with a
2036 ;; Mosaic-style hyperlink...
2037 (defface custom-variable-tag-face
2038 `((((class color)
2039 (background dark))
2040 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
2041 (((class color)
2042 (background light))
2043 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
2044 (t (:weight bold)))
2045 "Face used for unpushable variable tags."
2046 :group 'custom-faces)
2047
2048 (defface custom-variable-button-face '((t (:underline t :weight bold)))
2049 "Face used for pushable variable tags."
2050 :group 'custom-faces)
2051
2052 (defcustom custom-variable-default-form 'edit
2053 "Default form of displaying variable values."
2054 :type '(choice (const edit)
2055 (const lisp))
2056 :group 'custom-buffer
2057 :version "20.3")
2058
2059 (defun custom-variable-documentation (variable)
2060 "Return documentation of VARIABLE for use in Custom buffer.
2061 Normally just return the docstring. But if VARIABLE automatically
2062 becomes buffer local when set, append a message to that effect."
2063 (if (and (local-variable-if-set-p variable)
2064 (or (not (local-variable-p variable))
2065 (with-temp-buffer
2066 (local-variable-if-set-p variable))))
2067 (concat (documentation-property variable 'variable-documentation)
2068 "\n
2069 This variable automatically becomes buffer-local when set outside Custom.
2070 However, setting it through Custom sets the default value.")
2071 (documentation-property variable 'variable-documentation)))
2072
2073 (define-widget 'custom-variable 'custom
2074 "Customize variable."
2075 :format "%v"
2076 :help-echo "Set or reset this variable."
2077 :documentation-property #'custom-variable-documentation
2078 :custom-category 'option
2079 :custom-state nil
2080 :custom-menu 'custom-variable-menu-create
2081 :custom-form nil ; defaults to value of `custom-variable-default-form'
2082 :value-create 'custom-variable-value-create
2083 :action 'custom-variable-action
2084 :custom-set 'custom-variable-set
2085 :custom-save 'custom-variable-save
2086 :custom-reset-current 'custom-redraw
2087 :custom-reset-saved 'custom-variable-reset-saved
2088 :custom-reset-standard 'custom-variable-reset-standard
2089 :custom-standard-value 'custom-variable-standard-value)
2090
2091 (defun custom-variable-type (symbol)
2092 "Return a widget suitable for editing the value of SYMBOL.
2093 If SYMBOL has a `custom-type' property, use that.
2094 Otherwise, look up symbol in `custom-guess-type-alist'."
2095 (let* ((type (or (get symbol 'custom-type)
2096 (and (not (get symbol 'standard-value))
2097 (custom-guess-type symbol))
2098 'sexp))
2099 (options (get symbol 'custom-options))
2100 (tmp (if (listp type)
2101 (copy-sequence type)
2102 (list type))))
2103 (when options
2104 (widget-put tmp :options options))
2105 tmp))
2106
2107 (defun custom-variable-value-create (widget)
2108 "Here is where you edit the variable's value."
2109 (custom-load-widget widget)
2110 (unless (widget-get widget :custom-form)
2111 (widget-put widget :custom-form custom-variable-default-form))
2112 (let* ((buttons (widget-get widget :buttons))
2113 (children (widget-get widget :children))
2114 (form (widget-get widget :custom-form))
2115 (state (widget-get widget :custom-state))
2116 (symbol (widget-get widget :value))
2117 (tag (widget-get widget :tag))
2118 (type (custom-variable-type symbol))
2119 (conv (widget-convert type))
2120 (get (or (get symbol 'custom-get) 'default-value))
2121 (prefix (widget-get widget :custom-prefix))
2122 (last (widget-get widget :custom-last))
2123 (value (if (default-boundp symbol)
2124 (funcall get symbol)
2125 (widget-get conv :value))))
2126 ;; If the widget is new, the child determines whether it is hidden.
2127 (cond (state)
2128 ((custom-show type value)
2129 (setq state 'unknown))
2130 (t
2131 (setq state 'hidden)))
2132 ;; If we don't know the state, see if we need to edit it in lisp form.
2133 (when (eq state 'unknown)
2134 (unless (widget-apply conv :match value)
2135 ;; (widget-apply (widget-convert type) :match value)
2136 (setq form 'mismatch)))
2137 ;; Now we can create the child widget.
2138 (cond ((eq custom-buffer-style 'tree)
2139 (insert prefix (if last " `--- " " |--- "))
2140 (push (widget-create-child-and-convert
2141 widget 'custom-browse-variable-tag)
2142 buttons)
2143 (insert " " tag "\n")
2144 (widget-put widget :buttons buttons))
2145 ((eq state 'hidden)
2146 ;; Indicate hidden value.
2147 (push (widget-create-child-and-convert
2148 widget 'item
2149 :format "%{%t%}: "
2150 :sample-face 'custom-variable-tag-face
2151 :tag tag
2152 :parent widget)
2153 buttons)
2154 (push (widget-create-child-and-convert
2155 widget 'visibility
2156 :help-echo "Show the value of this option."
2157 :off "Show Value"
2158 :action 'custom-toggle-parent
2159 nil)
2160 buttons))
2161 ((memq form '(lisp mismatch))
2162 ;; In lisp mode edit the saved value when possible.
2163 (let* ((value (cond ((get symbol 'saved-value)
2164 (car (get symbol 'saved-value)))
2165 ((get symbol 'standard-value)
2166 (car (get symbol 'standard-value)))
2167 ((default-boundp symbol)
2168 (custom-quote (funcall get symbol)))
2169 (t
2170 (custom-quote (widget-get conv :value))))))
2171 (insert (symbol-name symbol) ": ")
2172 (push (widget-create-child-and-convert
2173 widget 'visibility
2174 :help-echo "Hide the value of this option."
2175 :on "Hide Value"
2176 :off "Show Value"
2177 :action 'custom-toggle-parent
2178 t)
2179 buttons)
2180 (insert " ")
2181 (push (widget-create-child-and-convert
2182 widget 'sexp
2183 :button-face 'custom-variable-button-face
2184 :format "%v"
2185 :tag (symbol-name symbol)
2186 :parent widget
2187 :value value)
2188 children)))
2189 (t
2190 ;; Edit mode.
2191 (let* ((format (widget-get type :format))
2192 tag-format value-format)
2193 (unless (string-match ":" format)
2194 (error "Bad format"))
2195 (setq tag-format (substring format 0 (match-end 0)))
2196 (setq value-format (substring format (match-end 0)))
2197 (push (widget-create-child-and-convert
2198 widget 'item
2199 :format tag-format
2200 :action 'custom-tag-action
2201 :help-echo "Change value of this option."
2202 :mouse-down-action 'custom-tag-mouse-down-action
2203 :button-face 'custom-variable-button-face
2204 :sample-face 'custom-variable-tag-face
2205 tag)
2206 buttons)
2207 (insert " ")
2208 (push (widget-create-child-and-convert
2209 widget 'visibility
2210 :help-echo "Hide the value of this option."
2211 :on "Hide Value"
2212 :off "Show Value"
2213 :action 'custom-toggle-parent
2214 t)
2215 buttons)
2216 (push (widget-create-child-and-convert
2217 widget type
2218 :format value-format
2219 :value value)
2220 children))))
2221 (unless (eq custom-buffer-style 'tree)
2222 (unless (eq (preceding-char) ?\n)
2223 (widget-insert "\n"))
2224 ;; Create the magic button.
2225 (let ((magic (widget-create-child-and-convert
2226 widget 'custom-magic nil)))
2227 (widget-put widget :custom-magic magic)
2228 (push magic buttons))
2229 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2230 ;; before the call to `widget-default-format-handler'. Otherwise, I
2231 ;; loose my current `buttons'. This function shouldn't be called like
2232 ;; this anyway. The doc string widget should be added like the others.
2233 ;; --dv
2234 (widget-put widget :buttons buttons)
2235 (insert "\n")
2236 ;; Insert documentation.
2237 (widget-default-format-handler widget ?h)
2238
2239 ;; The comment field
2240 (unless (eq state 'hidden)
2241 (let* ((comment (get symbol 'variable-comment))
2242 (comment-widget
2243 (widget-create-child-and-convert
2244 widget 'custom-comment
2245 :parent widget
2246 :value (or comment ""))))
2247 (widget-put widget :comment-widget comment-widget)
2248 ;; Don't push it !!! Custom assumes that the first child is the
2249 ;; value one.
2250 (setq children (append children (list comment-widget)))))
2251 ;; Update the rest of the properties properties.
2252 (widget-put widget :custom-form form)
2253 (widget-put widget :children children)
2254 ;; Now update the state.
2255 (if (eq state 'hidden)
2256 (widget-put widget :custom-state state)
2257 (custom-variable-state-set widget))
2258 ;; See also.
2259 (unless (eq state 'hidden)
2260 (when (eq (widget-get widget :custom-level) 1)
2261 (custom-add-parent-links widget))
2262 (custom-add-see-also widget)))))
2263
2264 (defun custom-tag-action (widget &rest args)
2265 "Pass :action to first child of WIDGET's parent."
2266 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2267 :action args))
2268
2269 (defun custom-tag-mouse-down-action (widget &rest args)
2270 "Pass :mouse-down-action to first child of WIDGET's parent."
2271 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2272 :mouse-down-action args))
2273
2274 (defun custom-variable-state-set (widget)
2275 "Set the state of WIDGET."
2276 (let* ((symbol (widget-value widget))
2277 (get (or (get symbol 'custom-get) 'default-value))
2278 (value (if (default-boundp symbol)
2279 (funcall get symbol)
2280 (widget-get widget :value)))
2281 (comment (get symbol 'variable-comment))
2282 tmp
2283 temp
2284 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2285 (setq temp
2286 (get symbol 'customized-variable-comment))
2287 (or tmp temp))
2288 (if (condition-case nil
2289 (and (equal value (eval (car tmp)))
2290 (equal comment temp))
2291 (error nil))
2292 'set
2293 'changed))
2294 ((progn (setq tmp (get symbol 'saved-value))
2295 (setq temp (get symbol 'saved-variable-comment))
2296 (or tmp temp))
2297 (if (condition-case nil
2298 (and (equal value (eval (car tmp)))
2299 (equal comment temp))
2300 (error nil))
2301 'saved
2302 'changed))
2303 ((setq tmp (get symbol 'standard-value))
2304 (if (condition-case nil
2305 (and (equal value (eval (car tmp)))
2306 (equal comment nil))
2307 (error nil))
2308 'standard
2309 'changed))
2310 (t 'rogue))))
2311 (widget-put widget :custom-state state)))
2312
2313 (defun custom-variable-standard-value (widget)
2314 (get (widget-value widget) 'standard-value))
2315
2316 (defvar custom-variable-menu
2317 '(("Set for Current Session" custom-variable-set
2318 (lambda (widget)
2319 (eq (widget-get widget :custom-state) 'modified)))
2320 ("Save for Future Sessions" custom-variable-save
2321 (lambda (widget)
2322 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2323 ("Reset to Current" custom-redraw
2324 (lambda (widget)
2325 (and (default-boundp (widget-value widget))
2326 (memq (widget-get widget :custom-state) '(modified changed)))))
2327 ("Reset to Saved" custom-variable-reset-saved
2328 (lambda (widget)
2329 (and (or (get (widget-value widget) 'saved-value)
2330 (get (widget-value widget) 'saved-variable-comment))
2331 (memq (widget-get widget :custom-state)
2332 '(modified set changed rogue)))))
2333 ("Erase Customization" custom-variable-reset-standard
2334 (lambda (widget)
2335 (and (get (widget-value widget) 'standard-value)
2336 (memq (widget-get widget :custom-state)
2337 '(modified set changed saved rogue)))))
2338 ("Use Backup Value" custom-variable-reset-backup
2339 (lambda (widget)
2340 (get (widget-value widget) 'backup-value)))
2341 ("---" ignore ignore)
2342 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2343 ("---" ignore ignore)
2344 ("Don't show as Lisp expression" custom-variable-edit
2345 (lambda (widget)
2346 (eq (widget-get widget :custom-form) 'lisp)))
2347 ("Show initial Lisp expression" custom-variable-edit-lisp
2348 (lambda (widget)
2349 (eq (widget-get widget :custom-form) 'edit))))
2350 "Alist of actions for the `custom-variable' widget.
2351 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2352 the menu entry, ACTION is the function to call on the widget when the
2353 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2354 widget as an argument, and returns non-nil if ACTION is valid on that
2355 widget. If FILTER is nil, ACTION is always valid.")
2356
2357 (defun custom-variable-action (widget &optional event)
2358 "Show the menu for `custom-variable' WIDGET.
2359 Optional EVENT is the location for the menu."
2360 (if (eq (widget-get widget :custom-state) 'hidden)
2361 (custom-toggle-hide widget)
2362 (unless (eq (widget-get widget :custom-state) 'modified)
2363 (custom-variable-state-set widget))
2364 (custom-redraw-magic widget)
2365 (let* ((completion-ignore-case t)
2366 (answer (widget-choose (concat "Operation on "
2367 (custom-unlispify-tag-name
2368 (widget-get widget :value)))
2369 (custom-menu-filter custom-variable-menu
2370 widget)
2371 event)))
2372 (if answer
2373 (funcall answer widget)))))
2374
2375 (defun custom-variable-edit (widget)
2376 "Edit value of WIDGET."
2377 (widget-put widget :custom-state 'unknown)
2378 (widget-put widget :custom-form 'edit)
2379 (custom-redraw widget))
2380
2381 (defun custom-variable-edit-lisp (widget)
2382 "Edit the Lisp representation of the value of WIDGET."
2383 (widget-put widget :custom-state 'unknown)
2384 (widget-put widget :custom-form 'lisp)
2385 (custom-redraw widget))
2386
2387 (defun custom-variable-set (widget)
2388 "Set the current value for the variable being edited by WIDGET."
2389 (let* ((form (widget-get widget :custom-form))
2390 (state (widget-get widget :custom-state))
2391 (child (car (widget-get widget :children)))
2392 (symbol (widget-value widget))
2393 (set (or (get symbol 'custom-set) 'set-default))
2394 (comment-widget (widget-get widget :comment-widget))
2395 (comment (widget-value comment-widget))
2396 val)
2397 (cond ((eq state 'hidden)
2398 (error "Cannot set hidden variable"))
2399 ((setq val (widget-apply child :validate))
2400 (goto-char (widget-get val :from))
2401 (error "%s" (widget-get val :error)))
2402 ((memq form '(lisp mismatch))
2403 (when (equal comment "")
2404 (setq comment nil)
2405 ;; Make the comment invisible by hand if it's empty
2406 (custom-comment-hide comment-widget))
2407 (custom-variable-backup-value widget)
2408 (funcall set symbol (eval (setq val (widget-value child))))
2409 (put symbol 'customized-value (list val))
2410 (put symbol 'variable-comment comment)
2411 (put symbol 'customized-variable-comment comment))
2412 (t
2413 (when (equal comment "")
2414 (setq comment nil)
2415 ;; Make the comment invisible by hand if it's empty
2416 (custom-comment-hide comment-widget))
2417 (custom-variable-backup-value widget)
2418 (funcall set symbol (setq val (widget-value child)))
2419 (put symbol 'customized-value (list (custom-quote val)))
2420 (put symbol 'variable-comment comment)
2421 (put symbol 'customized-variable-comment comment)))
2422 (custom-variable-state-set widget)
2423 (custom-redraw-magic widget)))
2424
2425 (defun custom-variable-save (widget)
2426 "Set and save the value for the variable being edited by WIDGET."
2427 (let* ((form (widget-get widget :custom-form))
2428 (state (widget-get widget :custom-state))
2429 (child (car (widget-get widget :children)))
2430 (symbol (widget-value widget))
2431 (set (or (get symbol 'custom-set) 'set-default))
2432 (comment-widget (widget-get widget :comment-widget))
2433 (comment (widget-value comment-widget))
2434 val)
2435 (cond ((eq state 'hidden)
2436 (error "Cannot set hidden variable"))
2437 ((setq val (widget-apply child :validate))
2438 (goto-char (widget-get val :from))
2439 (error "Saving %s: %s" symbol (widget-get val :error)))
2440 ((memq form '(lisp mismatch))
2441 (when (equal comment "")
2442 (setq comment nil)
2443 ;; Make the comment invisible by hand if it's empty
2444 (custom-comment-hide comment-widget))
2445 (put symbol 'saved-value (list (widget-value child)))
2446 (custom-push-theme 'theme-value symbol 'user
2447 'set (list (widget-value child)))
2448 (funcall set symbol (eval (widget-value child)))
2449 (put symbol 'variable-comment comment)
2450 (put symbol 'saved-variable-comment comment))
2451 (t
2452 (when (equal comment "")
2453 (setq comment nil)
2454 ;; Make the comment invisible by hand if it's empty
2455 (custom-comment-hide comment-widget))
2456 (put symbol 'saved-value
2457 (list (custom-quote (widget-value child))))
2458 (custom-push-theme 'theme-value symbol 'user
2459 'set (list (custom-quote (widget-value
2460 child))))
2461 (funcall set symbol (widget-value child))
2462 (put symbol 'variable-comment comment)
2463 (put symbol 'saved-variable-comment comment)))
2464 (put symbol 'customized-value nil)
2465 (put symbol 'customized-variable-comment nil)
2466 (custom-save-all)
2467 (custom-variable-state-set widget)
2468 (custom-redraw-magic widget)))
2469
2470 (defun custom-variable-reset-saved (widget)
2471 "Restore the saved value for the variable being edited by WIDGET.
2472 The value that was current before this operation
2473 becomes the backup value, so you can get it again."
2474 (let* ((symbol (widget-value widget))
2475 (set (or (get symbol 'custom-set) 'set-default))
2476 (value (get symbol 'saved-value))
2477 (comment (get symbol 'saved-variable-comment)))
2478 (cond ((or value comment)
2479 (put symbol 'variable-comment comment)
2480 (custom-variable-backup-value widget)
2481 (condition-case nil
2482 (funcall set symbol (eval (car value)))
2483 (error nil)))
2484 (t
2485 (error "No saved value for %s" symbol)))
2486 (put symbol 'customized-value nil)
2487 (put symbol 'customized-variable-comment nil)
2488 (widget-put widget :custom-state 'unknown)
2489 ;; This call will possibly make the comment invisible
2490 (custom-redraw widget)))
2491
2492 (defun custom-variable-reset-standard (widget)
2493 "Restore the standard setting for the variable being edited by WIDGET.
2494 This operation eliminates any saved setting for the variable,
2495 restoring it to the state of a variable that has never been customized.
2496 The value that was current before this operation
2497 becomes the backup value, so you can get it again."
2498 (let* ((symbol (widget-value widget))
2499 (set (or (get symbol 'custom-set) 'set-default)))
2500 (if (get symbol 'standard-value)
2501 (progn
2502 (custom-variable-backup-value widget)
2503 (funcall set symbol (eval (car (get symbol 'standard-value)))))
2504 (error "No standard setting known for %S" symbol))
2505 (put symbol 'variable-comment nil)
2506 (put symbol 'customized-value nil)
2507 (put symbol 'customized-variable-comment nil)
2508 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2509 (put symbol 'saved-value nil)
2510 (custom-push-theme 'theme-value symbol 'user 'reset 'standard)
2511 ;; As a special optimizations we do not (explictly)
2512 ;; save resets to standard when no theme set the value.
2513 (if (null (cdr (get symbol 'theme-value)))
2514 (put symbol 'theme-value nil))
2515 (put symbol 'saved-variable-comment nil)
2516 (custom-save-all))
2517 (widget-put widget :custom-state 'unknown)
2518 ;; This call will possibly make the comment invisible
2519 (custom-redraw widget)))
2520
2521 (defun custom-variable-backup-value (widget)
2522 "Back up the current value for WIDGET's variable.
2523 The backup value is kept in the car of the `backup-value' property."
2524 (let* ((symbol (widget-value widget))
2525 (get (or (get symbol 'custom-get) 'default-value))
2526 (type (custom-variable-type symbol))
2527 (conv (widget-convert type))
2528 (value (if (default-boundp symbol)
2529 (funcall get symbol)
2530 (widget-get conv :value))))
2531 (put symbol 'backup-value (list value))))
2532
2533 (defun custom-variable-reset-backup (widget)
2534 "Restore the backup value for the variable being edited by WIDGET.
2535 The value that was current before this operation
2536 becomes the backup value, so you can use this operation repeatedly
2537 to switch between two values."
2538 (let* ((symbol (widget-value widget))
2539 (set (or (get symbol 'custom-set) 'set-default))
2540 (value (get symbol 'backup-value))
2541 (comment-widget (widget-get widget :comment-widget))
2542 (comment (widget-value comment-widget)))
2543 (if value
2544 (progn
2545 (custom-variable-backup-value widget)
2546 (condition-case nil
2547 (funcall set symbol (car value))
2548 (error nil)))
2549 (error "No backup value for %s" symbol))
2550 (put symbol 'customized-value (list (car value)))
2551 (put symbol 'variable-comment comment)
2552 (put symbol 'customized-variable-comment comment)
2553 (custom-variable-state-set widget)
2554 ;; This call will possibly make the comment invisible
2555 (custom-redraw widget)))
2556
2557 ;;; The `custom-face-edit' Widget.
2558
2559 (define-widget 'custom-face-edit 'checklist
2560 "Edit face attributes."
2561 :format "%t: %v"
2562 :tag "Attributes"
2563 :extra-offset 13
2564 :button-args '(:help-echo "Control whether this attribute has any effect.")
2565 :value-to-internal 'custom-face-edit-fix-value
2566 :match (lambda (widget value)
2567 (widget-checklist-match widget
2568 (custom-face-edit-fix-value widget value)))
2569 :convert-widget 'custom-face-edit-convert-widget
2570 :args (mapcar (lambda (att)
2571 (list 'group
2572 :inline t
2573 :sibling-args (widget-get (nth 1 att) :sibling-args)
2574 (list 'const :format "" :value (nth 0 att))
2575 (nth 1 att)))
2576 custom-face-attributes))
2577
2578 (defun custom-face-edit-fix-value (widget value)
2579 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2580 Also change :reverse-video to :inverse-video."
2581 (if (listp value)
2582 (let (result)
2583 (while value
2584 (let ((key (car value))
2585 (val (car (cdr value))))
2586 (cond ((eq key :italic)
2587 (push :slant result)
2588 (push (if val 'italic 'normal) result))
2589 ((eq key :bold)
2590 (push :weight result)
2591 (push (if val 'bold 'normal) result))
2592 ((eq key :reverse-video)
2593 (push :inverse-video result)
2594 (push val result))
2595 (t
2596 (push key result)
2597 (push val result))))
2598 (setq value (cdr (cdr value))))
2599 (setq result (nreverse result))
2600 result)
2601 value))
2602
2603 (defun custom-face-edit-convert-widget (widget)
2604 "Convert :args as widget types in WIDGET."
2605 (widget-put
2606 widget
2607 :args (mapcar (lambda (arg)
2608 (widget-convert arg
2609 :deactivate 'custom-face-edit-deactivate
2610 :activate 'custom-face-edit-activate
2611 :delete 'custom-face-edit-delete))
2612 (widget-get widget :args)))
2613 widget)
2614
2615 (defun custom-face-edit-deactivate (widget)
2616 "Make face widget WIDGET inactive for user modifications."
2617 (unless (widget-get widget :inactive)
2618 (let ((tag (custom-face-edit-attribute-tag widget))
2619 (from (copy-marker (widget-get widget :from)))
2620 (value (widget-value widget))
2621 (inhibit-read-only t)
2622 (inhibit-modification-hooks t))
2623 (save-excursion
2624 (goto-char from)
2625 (widget-default-delete widget)
2626 (insert tag ": *\n")
2627 (widget-put widget :inactive
2628 (cons value (cons from (- (point) from))))))))
2629
2630 (defun custom-face-edit-activate (widget)
2631 "Make face widget WIDGET inactive for user modifications."
2632 (let ((inactive (widget-get widget :inactive))
2633 (inhibit-read-only t)
2634 (inhibit-modification-hooks t))
2635 (when (consp inactive)
2636 (save-excursion
2637 (goto-char (car (cdr inactive)))
2638 (delete-region (point) (+ (point) (cdr (cdr inactive))))
2639 (widget-put widget :inactive nil)
2640 (widget-apply widget :create)
2641 (widget-value-set widget (car inactive))
2642 (widget-setup)))))
2643
2644 (defun custom-face-edit-delete (widget)
2645 "Remove WIDGET from the buffer."
2646 (let ((inactive (widget-get widget :inactive))
2647 (inhibit-read-only t)
2648 (inhibit-modification-hooks t))
2649 (if (not inactive)
2650 ;; Widget is alive, we don't have to do anything special
2651 (widget-default-delete widget)
2652 ;; WIDGET is already deleted because we did so to inactivate it;
2653 ;; now just get rid of the label we put in its place.
2654 (delete-region (car (cdr inactive))
2655 (+ (car (cdr inactive)) (cdr (cdr inactive))))
2656 (widget-put widget :inactive nil))))
2657
2658
2659 (defun custom-face-edit-attribute-tag (widget)
2660 "Returns the first :tag property in WIDGET or one of its children."
2661 (let ((tag (widget-get widget :tag)))
2662 (or (and (not (equal tag "")) tag)
2663 (let ((children (widget-get widget :children)))
2664 (while (and (null tag) children)
2665 (setq tag (custom-face-edit-attribute-tag (pop children))))
2666 tag))))
2667
2668 ;;; The `custom-display' Widget.
2669
2670 (define-widget 'custom-display 'menu-choice
2671 "Select a display type."
2672 :tag "Display"
2673 :value t
2674 :help-echo "Specify frames where the face attributes should be used."
2675 :args '((const :tag "all" t)
2676 (const :tag "defaults" default)
2677 (checklist
2678 :offset 0
2679 :extra-offset 9
2680 :args ((group :sibling-args (:help-echo "\
2681 Only match the specified window systems.")
2682 (const :format "Type: "
2683 type)
2684 (checklist :inline t
2685 :offset 0
2686 (const :format "X "
2687 :sibling-args (:help-echo "\
2688 The X11 Window System.")
2689 x)
2690 (const :format "PM "
2691 :sibling-args (:help-echo "\
2692 OS/2 Presentation Manager.")
2693 pm)
2694 (const :format "W32 "
2695 :sibling-args (:help-echo "\
2696 Windows NT/9X.")
2697 w32)
2698 (const :format "MAC "
2699 :sibling-args (:help-echo "\
2700 Macintosh OS.")
2701 mac)
2702 (const :format "DOS "
2703 :sibling-args (:help-echo "\
2704 Plain MS-DOS.")
2705 pc)
2706 (const :format "TTY%n"
2707 :sibling-args (:help-echo "\
2708 Plain text terminals.")
2709 tty)))
2710 (group :sibling-args (:help-echo "\
2711 Only match the frames with the specified color support.")
2712 (const :format "Class: "
2713 class)
2714 (checklist :inline t
2715 :offset 0
2716 (const :format "Color "
2717 :sibling-args (:help-echo "\
2718 Match color frames.")
2719 color)
2720 (const :format "Grayscale "
2721 :sibling-args (:help-echo "\
2722 Match grayscale frames.")
2723 grayscale)
2724 (const :format "Monochrome%n"
2725 :sibling-args (:help-echo "\
2726 Match frames with no color support.")
2727 mono)))
2728 (group :sibling-args (:help-echo "\
2729 The minimum number of colors the frame should support.")
2730 (const :format "" min-colors)
2731 (integer :tag "Minimum number of colors" ))
2732 (group :sibling-args (:help-echo "\
2733 Only match frames with the specified intensity.")
2734 (const :format "\
2735 Background brightness: "
2736 background)
2737 (checklist :inline t
2738 :offset 0
2739 (const :format "Light "
2740 :sibling-args (:help-echo "\
2741 Match frames with light backgrounds.")
2742 light)
2743 (const :format "Dark\n"
2744 :sibling-args (:help-echo "\
2745 Match frames with dark backgrounds.")
2746 dark)))
2747 (group :sibling-args (:help-echo "\
2748 Only match frames that support the specified face attributes.")
2749 (const :format "Supports attributes:" supports)
2750 (custom-face-edit :inline t :format "%n%v"))))))
2751
2752 ;;; The `custom-face' Widget.
2753
2754 (defface custom-face-tag-face
2755 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
2756 "Face used for face tags."
2757 :group 'custom-faces)
2758
2759 (defcustom custom-face-default-form 'selected
2760 "Default form of displaying face definition."
2761 :type '(choice (const all)
2762 (const selected)
2763 (const lisp))
2764 :group 'custom-buffer
2765 :version "20.3")
2766
2767 (define-widget 'custom-face 'custom
2768 "Customize face."
2769 :sample-face 'custom-face-tag-face
2770 :help-echo "Set or reset this face."
2771 :documentation-property #'face-doc-string
2772 :value-create 'custom-face-value-create
2773 :action 'custom-face-action
2774 :custom-category 'face
2775 :custom-form nil ; defaults to value of `custom-face-default-form'
2776 :custom-set 'custom-face-set
2777 :custom-save 'custom-face-save
2778 :custom-reset-current 'custom-redraw
2779 :custom-reset-saved 'custom-face-reset-saved
2780 :custom-reset-standard 'custom-face-reset-standard
2781 :custom-standard-value 'custom-face-standard-value
2782 :custom-menu 'custom-face-menu-create)
2783
2784 (define-widget 'custom-face-all 'editable-list
2785 "An editable list of display specifications and attributes."
2786 :entry-format "%i %d %v"
2787 :insert-button-args '(:help-echo "Insert new display specification here.")
2788 :append-button-args '(:help-echo "Append new display specification here.")
2789 :delete-button-args '(:help-echo "Delete this display specification.")
2790 :args '((group :format "%v" custom-display custom-face-edit)))
2791
2792 (defconst custom-face-all (widget-convert 'custom-face-all)
2793 "Converted version of the `custom-face-all' widget.")
2794
2795 (define-widget 'custom-display-unselected 'item
2796 "A display specification that doesn't match the selected display."
2797 :match 'custom-display-unselected-match)
2798
2799 (defun custom-display-unselected-match (widget value)
2800 "Non-nil if VALUE is an unselected display specification."
2801 (not (face-spec-set-match-display value (selected-frame))))
2802
2803 (define-widget 'custom-face-selected 'group
2804 "Edit the attributes of the selected display in a face specification."
2805 :args '((choice :inline t
2806 (group :tag "With Defaults" :inline t
2807 (group (const :tag "" default)
2808 (custom-face-edit :tag " Default\n Attributes"))
2809 (repeat :format ""
2810 :inline t
2811 (group custom-display-unselected sexp))
2812 (group (sexp :format "")
2813 (custom-face-edit :tag " Overriding\n Attributes"))
2814 (repeat :format ""
2815 :inline t
2816 sexp))
2817 (group :tag "No Defaults" :inline t
2818 (repeat :format ""
2819 :inline t
2820 (group custom-display-unselected sexp))
2821 (group (sexp :format "")
2822 (custom-face-edit :tag "\n Attributes"))
2823 (repeat :format ""
2824 :inline t
2825 sexp)))))
2826
2827
2828
2829 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2830 "Converted version of the `custom-face-selected' widget.")
2831
2832 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
2833 "Return a canonicalized version of SPEC using.
2834 FILTER-INDEX is the index in the entry for each attribute in
2835 `custom-face-attributes' at which the appropriate filter function can be
2836 found, and DEFAULT-FILTER is the filter to apply for attributes that
2837 don't specify one."
2838 (mapcar (lambda (entry)
2839 ;; Filter a single face-spec entry
2840 (let ((tests (car entry))
2841 (unfiltered-attrs
2842 ;; Handle both old- and new-style attribute syntax
2843 (if (listp (car (cdr entry)))
2844 (car (cdr entry))
2845 (cdr entry)))
2846 (filtered-attrs nil))
2847 ;; Filter each face attribute
2848 (while unfiltered-attrs
2849 (let* ((attr (pop unfiltered-attrs))
2850 (pre-filtered-value (pop unfiltered-attrs))
2851 (filter
2852 (or (nth filter-index (assq attr custom-face-attributes))
2853 default-filter))
2854 (filtered-value
2855 (if filter
2856 (funcall filter pre-filtered-value)
2857 pre-filtered-value)))
2858 (push filtered-value filtered-attrs)
2859 (push attr filtered-attrs)))
2860 ;;
2861 (list tests filtered-attrs)))
2862 spec))
2863
2864 (defun custom-pre-filter-face-spec (spec)
2865 "Return SPEC changed as necessary for editing by the face customization widget.
2866 SPEC must be a full face spec."
2867 (custom-filter-face-spec spec 2))
2868
2869 (defun custom-post-filter-face-spec (spec)
2870 "Return the customized SPEC in a form suitable for setting the face."
2871 (custom-filter-face-spec spec 3))
2872
2873 (defun custom-face-value-create (widget)
2874 "Create a list of the display specifications for WIDGET."
2875 (let ((buttons (widget-get widget :buttons))
2876 children
2877 (symbol (widget-get widget :value))
2878 (tag (widget-get widget :tag))
2879 (state (widget-get widget :custom-state))
2880 (begin (point))
2881 (is-last (widget-get widget :custom-last))
2882 (prefix (widget-get widget :custom-prefix)))
2883 (unless tag
2884 (setq tag (prin1-to-string symbol)))
2885 (cond ((eq custom-buffer-style 'tree)
2886 (insert prefix (if is-last " `--- " " |--- "))
2887 (push (widget-create-child-and-convert
2888 widget 'custom-browse-face-tag)
2889 buttons)
2890 (insert " " tag "\n")
2891 (widget-put widget :buttons buttons))
2892 (t
2893 ;; Create tag.
2894 (insert tag)
2895 (widget-specify-sample widget begin (point))
2896 (if (eq custom-buffer-style 'face)
2897 (insert " ")
2898 (if (string-match "face\\'" tag)
2899 (insert ":")
2900 (insert " face: ")))
2901 ;; Sample.
2902 (push (widget-create-child-and-convert widget 'item
2903 :format "(%{%t%})"
2904 :sample-face symbol
2905 :tag "sample")
2906 buttons)
2907 ;; Visibility.
2908 (insert " ")
2909 (push (widget-create-child-and-convert
2910 widget 'visibility
2911 :help-echo "Hide or show this face."
2912 :on "Hide Face"
2913 :off "Show Face"
2914 :action 'custom-toggle-parent
2915 (not (eq state 'hidden)))
2916 buttons)
2917 ;; Magic.
2918 (insert "\n")
2919 (let ((magic (widget-create-child-and-convert
2920 widget 'custom-magic nil)))
2921 (widget-put widget :custom-magic magic)
2922 (push magic buttons))
2923 ;; Update buttons.
2924 (widget-put widget :buttons buttons)
2925 ;; Insert documentation.
2926 (widget-default-format-handler widget ?h)
2927 ;; The comment field
2928 (unless (eq state 'hidden)
2929 (let* ((comment (get symbol 'face-comment))
2930 (comment-widget
2931 (widget-create-child-and-convert
2932 widget 'custom-comment
2933 :parent widget
2934 :value (or comment ""))))
2935 (widget-put widget :comment-widget comment-widget)
2936 (push comment-widget children)))
2937 ;; See also.
2938 (unless (eq state 'hidden)
2939 (when (eq (widget-get widget :custom-level) 1)
2940 (custom-add-parent-links widget))
2941 (custom-add-see-also widget))
2942 ;; Editor.
2943 (unless (eq (preceding-char) ?\n)
2944 (insert "\n"))
2945 (unless (eq state 'hidden)
2946 (message "Creating face editor...")
2947 (custom-load-widget widget)
2948 (unless (widget-get widget :custom-form)
2949 (widget-put widget :custom-form custom-face-default-form))
2950 (let* ((symbol (widget-value widget))
2951 (spec (or (get symbol 'customized-face)
2952 (get symbol 'saved-face)
2953 (get symbol 'face-defface-spec)
2954 ;; Attempt to construct it.
2955 (list (list t (custom-face-attributes-get
2956 symbol (selected-frame))))))
2957 (form (widget-get widget :custom-form))
2958 (indent (widget-get widget :indent))
2959 edit)
2960 ;; If the user has changed this face in some other way,
2961 ;; edit it as the user has specified it.
2962 (if (not (face-spec-match-p symbol spec (selected-frame)))
2963 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
2964 (setq spec (custom-pre-filter-face-spec spec))
2965 (setq edit (widget-create-child-and-convert
2966 widget
2967 (cond ((and (eq form 'selected)
2968 (widget-apply custom-face-selected
2969 :match spec))
2970 (when indent (insert-char ?\ indent))
2971 'custom-face-selected)
2972 ((and (not (eq form 'lisp))
2973 (widget-apply custom-face-all
2974 :match spec))
2975 'custom-face-all)
2976 (t
2977 (when indent (insert-char ?\ indent))
2978 'sexp))
2979 :value spec))
2980 (custom-face-state-set widget)
2981 (push edit children)
2982 (widget-put widget :children children))
2983 (message "Creating face editor...done"))))))
2984
2985 (defvar custom-face-menu
2986 '(("Set for Current Session" custom-face-set)
2987 ("Save for Future Sessions" custom-face-save-command)
2988 ("Reset to Saved" custom-face-reset-saved
2989 (lambda (widget)
2990 (or (get (widget-value widget) 'saved-face)
2991 (get (widget-value widget) 'saved-face-comment))))
2992 ("Erase Customization" custom-face-reset-standard
2993 (lambda (widget)
2994 (get (widget-value widget) 'face-defface-spec)))
2995 ("---" ignore ignore)
2996 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2997 ("---" ignore ignore)
2998 ("Show all display specs" custom-face-edit-all
2999 (lambda (widget)
3000 (not (eq (widget-get widget :custom-form) 'all))))
3001 ("Just current attributes" custom-face-edit-selected
3002 (lambda (widget)
3003 (not (eq (widget-get widget :custom-form) 'selected))))
3004 ("Show as Lisp expression" custom-face-edit-lisp
3005 (lambda (widget)
3006 (not (eq (widget-get widget :custom-form) 'lisp)))))
3007 "Alist of actions for the `custom-face' widget.
3008 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3009 the menu entry, ACTION is the function to call on the widget when the
3010 menu is selected, and FILTER is a predicate which takes a `custom-face'
3011 widget as an argument, and returns non-nil if ACTION is valid on that
3012 widget. If FILTER is nil, ACTION is always valid.")
3013
3014 (defun custom-face-edit-selected (widget)
3015 "Edit selected attributes of the value of WIDGET."
3016 (widget-put widget :custom-state 'unknown)
3017 (widget-put widget :custom-form 'selected)
3018 (custom-redraw widget))
3019
3020 (defun custom-face-edit-all (widget)
3021 "Edit all attributes of the value of WIDGET."
3022 (widget-put widget :custom-state 'unknown)
3023 (widget-put widget :custom-form 'all)
3024 (custom-redraw widget))
3025
3026 (defun custom-face-edit-lisp (widget)
3027 "Edit the Lisp representation of the value of WIDGET."
3028 (widget-put widget :custom-state 'unknown)
3029 (widget-put widget :custom-form 'lisp)
3030 (custom-redraw widget))
3031
3032 (defun custom-face-state-set (widget)
3033 "Set the state of WIDGET."
3034 (let* ((symbol (widget-value widget))
3035 (comment (get symbol 'face-comment))
3036 tmp temp
3037 (state
3038 (cond ((progn
3039 (setq tmp (get symbol 'customized-face))
3040 (setq temp (get symbol 'customized-face-comment))
3041 (or tmp temp))
3042 (if (equal temp comment)
3043 'set
3044 'changed))
3045 ((progn
3046 (setq tmp (get symbol 'saved-face))
3047 (setq temp (get symbol 'saved-face-comment))
3048 (or tmp temp))
3049 (if (equal temp comment)
3050 'saved
3051 'changed))
3052 ((get symbol 'face-defface-spec)
3053 (if (equal comment nil)
3054 'standard
3055 'changed))
3056 (t
3057 'rogue))))
3058 ;; If the user called set-face-attribute to change the default
3059 ;; for new frames, this face is "set outside of Customize".
3060 (if (and (not (eq state 'rogue))
3061 (get symbol 'face-modified))
3062 (setq state 'changed))
3063 (widget-put widget :custom-state state)))
3064
3065 (defun custom-face-action (widget &optional event)
3066 "Show the menu for `custom-face' WIDGET.
3067 Optional EVENT is the location for the menu."
3068 (if (eq (widget-get widget :custom-state) 'hidden)
3069 (custom-toggle-hide widget)
3070 (let* ((completion-ignore-case t)
3071 (symbol (widget-get widget :value))
3072 (answer (widget-choose (concat "Operation on "
3073 (custom-unlispify-tag-name symbol))
3074 (custom-menu-filter custom-face-menu
3075 widget)
3076 event)))
3077 (if answer
3078 (funcall answer widget)))))
3079
3080 (defun custom-face-set (widget)
3081 "Make the face attributes in WIDGET take effect."
3082 (let* ((symbol (widget-value widget))
3083 (child (car (widget-get widget :children)))
3084 (value (custom-post-filter-face-spec (widget-value child)))
3085 (comment-widget (widget-get widget :comment-widget))
3086 (comment (widget-value comment-widget)))
3087 (when (equal comment "")
3088 (setq comment nil)
3089 ;; Make the comment invisible by hand if it's empty
3090 (custom-comment-hide comment-widget))
3091 (put symbol 'customized-face value)
3092 (if (face-spec-choose value)
3093 (face-spec-set symbol value)
3094 ;; face-set-spec ignores empty attribute lists, so just give it
3095 ;; something harmless instead.
3096 (face-spec-set symbol '((t :foreground unspecified))))
3097 (put symbol 'customized-face-comment comment)
3098 (put symbol 'face-comment comment)
3099 (custom-face-state-set widget)
3100 (custom-redraw-magic widget)))
3101
3102 (defun custom-face-save-command (widget)
3103 "Save in `.emacs' the face attributes in WIDGET."
3104 (custom-face-save widget)
3105 (custom-save-all))
3106
3107 (defun custom-face-save (widget)
3108 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3109 (let* ((symbol (widget-value widget))
3110 (child (car (widget-get widget :children)))
3111 (value (custom-post-filter-face-spec (widget-value child)))
3112 (comment-widget (widget-get widget :comment-widget))
3113 (comment (widget-value comment-widget)))
3114 (when (equal comment "")
3115 (setq comment nil)
3116 ;; Make the comment invisible by hand if it's empty
3117 (custom-comment-hide comment-widget))
3118 (if (face-spec-choose value)
3119 (face-spec-set symbol value)
3120 ;; face-set-spec ignores empty attribute lists, so just give it
3121 ;; something harmless instead.
3122 (face-spec-set symbol '((t :foreground unspecified))))
3123 (unless (eq (widget-get widget :custom-state) 'standard)
3124 (put symbol 'saved-face value))
3125 (custom-push-theme 'theme-face symbol 'user 'set value)
3126 (put symbol 'customized-face nil)
3127 (put symbol 'face-comment comment)
3128 (put symbol 'customized-face-comment nil)
3129 (put symbol 'saved-face-comment comment)
3130 (custom-save-all)
3131 (custom-face-state-set widget)
3132 (custom-redraw-magic widget)))
3133
3134 (defun custom-face-reset-saved (widget)
3135 "Restore WIDGET to the face's default attributes."
3136 (let* ((symbol (widget-value widget))
3137 (child (car (widget-get widget :children)))
3138 (value (get symbol 'saved-face))
3139 (comment (get symbol 'saved-face-comment))
3140 (comment-widget (widget-get widget :comment-widget)))
3141 (unless (or value comment)
3142 (error "No saved value for this face"))
3143 (put symbol 'customized-face nil)
3144 (put symbol 'customized-face-comment nil)
3145 (face-spec-set symbol value)
3146 (put symbol 'face-comment comment)
3147 (widget-value-set child value)
3148 ;; This call manages the comment visibility
3149 (widget-value-set comment-widget (or comment ""))
3150 (custom-face-state-set widget)
3151 (custom-redraw-magic widget)))
3152
3153 (defun custom-face-standard-value (widget)
3154 (get (widget-value widget) 'face-defface-spec))
3155
3156 (defun custom-face-reset-standard (widget)
3157 "Restore WIDGET to the face's standard settings.
3158 This operation eliminates any saved setting for the face,
3159 restoring it to the state of a face that has never been customized."
3160 (let* ((symbol (widget-value widget))
3161 (child (car (widget-get widget :children)))
3162 (value (get symbol 'face-defface-spec))
3163 (comment-widget (widget-get widget :comment-widget)))
3164 (unless value
3165 (error "No standard setting for this face"))
3166 (put symbol 'customized-face nil)
3167 (put symbol 'customized-face-comment nil)
3168 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3169 (put symbol 'saved-face nil)
3170 (custom-push-theme 'theme-face symbol 'user 'reset 'standard)
3171 ;; Do not explictly save resets to standards without themes.
3172 (if (null (cdr (get symbol 'theme-face)))
3173 (put symbol 'theme-face nil))
3174 (put symbol 'saved-face-comment nil)
3175 (custom-save-all))
3176 (face-spec-set symbol value)
3177 (put symbol 'face-comment nil)
3178 (widget-value-set child value)
3179 ;; This call manages the comment visibility
3180 (widget-value-set comment-widget "")
3181 (custom-face-state-set widget)
3182 (custom-redraw-magic widget)))
3183
3184 ;;; The `face' Widget.
3185
3186 (define-widget 'face 'default
3187 "Select and customize a face."
3188 :convert-widget 'widget-value-convert-widget
3189 :button-prefix 'widget-push-button-prefix
3190 :button-suffix 'widget-push-button-suffix
3191 :format "%{%t%}: %[select face%] %v"
3192 :tag "Face"
3193 :value 'default
3194 :value-create 'widget-face-value-create
3195 :value-delete 'widget-face-value-delete
3196 :value-get 'widget-value-value-get
3197 :validate 'widget-children-validate
3198 :action 'widget-face-action
3199 :match (lambda (widget value) (symbolp value)))
3200
3201 (defun widget-face-value-create (widget)
3202 "Create a `custom-face' child."
3203 (let* ((symbol (widget-value widget))
3204 (custom-buffer-style 'face)
3205 (child (widget-create-child-and-convert
3206 widget 'custom-face
3207 :custom-level nil
3208 :value symbol)))
3209 (custom-magic-reset child)
3210 (setq custom-options (cons child custom-options))
3211 (widget-put widget :children (list child))))
3212
3213 (defun widget-face-value-delete (widget)
3214 "Remove the child from the options."
3215 (let ((child (car (widget-get widget :children))))
3216 (setq custom-options (delq child custom-options))
3217 (widget-children-value-delete widget)))
3218
3219 (defvar face-history nil
3220 "History of entered face names.")
3221
3222 (defun widget-face-action (widget &optional event)
3223 "Prompt for a face."
3224 (let ((answer (completing-read "Face: "
3225 (mapcar (lambda (face)
3226 (list (symbol-name face)))
3227 (face-list))
3228 nil nil nil
3229 'face-history)))
3230 (unless (zerop (length answer))
3231 (widget-value-set widget (intern answer))
3232 (widget-apply widget :notify widget event)
3233 (widget-setup))))
3234
3235 ;;; The `hook' Widget.
3236
3237 (define-widget 'hook 'list
3238 "A emacs lisp hook"
3239 :value-to-internal (lambda (widget value)
3240 (if (and value (symbolp value))
3241 (list value)
3242 value))
3243 :match (lambda (widget value)
3244 (or (symbolp value)
3245 (widget-group-match widget value)))
3246 ;; Avoid adding undefined functions to the hook, especially for
3247 ;; things like `find-file-hook' or even more basic ones, to avoid
3248 ;; chaos.
3249 :set (lambda (symbol value)
3250 (dolist (elt value)
3251 (if (fboundp elt)
3252 (add-hook symbol elt))))
3253 :convert-widget 'custom-hook-convert-widget
3254 :tag "Hook")
3255
3256 (defun custom-hook-convert-widget (widget)
3257 ;; Handle `:options'.
3258 (let* ((options (widget-get widget :options))
3259 (other `(editable-list :inline t
3260 :entry-format "%i %d%v"
3261 (function :format " %v")))
3262 (args (if options
3263 (list `(checklist :inline t
3264 ,@(mapcar (lambda (entry)
3265 `(function-item ,entry))
3266 options))
3267 other)
3268 (list other))))
3269 (widget-put widget :args args)
3270 widget))
3271
3272 ;;; The `custom-group-link' Widget.
3273
3274 (define-widget 'custom-group-link 'link
3275 "Show parent in other window when activated."
3276 :help-echo "Create customization buffer for this group."
3277 :action 'custom-group-link-action)
3278
3279 (defun custom-group-link-action (widget &rest ignore)
3280 (customize-group (widget-value widget)))
3281
3282 ;;; The `custom-group' Widget.
3283
3284 (defcustom custom-group-tag-faces nil
3285 ;; In XEmacs, this ought to play games with font size.
3286 ;; Fixme: make it do so in Emacs.
3287 "Face used for group tags.
3288 The first member is used for level 1 groups, the second for level 2,
3289 and so forth. The remaining group tags are shown with
3290 `custom-group-tag-face'."
3291 :type '(repeat face)
3292 :group 'custom-faces)
3293
3294 (defface custom-group-tag-face-1
3295 `((((class color)
3296 (background dark))
3297 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3298 (((class color)
3299 (background light))
3300 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3301 (t (:weight bold)))
3302 "Face used for group tags."
3303 :group 'custom-faces)
3304
3305 (defface custom-group-tag-face
3306 `((((class color)
3307 (background dark))
3308 (:foreground "light blue" :weight bold :height 1.2))
3309 (((class color)
3310 (background light))
3311 (:foreground "blue" :weight bold :height 1.2))
3312 (t (:weight bold)))
3313 "Face used for low level group tags."
3314 :group 'custom-faces)
3315
3316 (define-widget 'custom-group 'custom
3317 "Customize group."
3318 :format "%v"
3319 :sample-face-get 'custom-group-sample-face-get
3320 :documentation-property 'group-documentation
3321 :help-echo "Set or reset all members of this group."
3322 :value-create 'custom-group-value-create
3323 :action 'custom-group-action
3324 :custom-category 'group
3325 :custom-set 'custom-group-set
3326 :custom-save 'custom-group-save
3327 :custom-reset-current 'custom-group-reset-current
3328 :custom-reset-saved 'custom-group-reset-saved
3329 :custom-reset-standard 'custom-group-reset-standard
3330 :custom-menu 'custom-group-menu-create)
3331
3332 (defun custom-group-sample-face-get (widget)
3333 ;; Use :sample-face.
3334 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3335 'custom-group-tag-face))
3336
3337 (define-widget 'custom-group-visibility 'visibility
3338 "An indicator and manipulator for hidden group contents."
3339 :create 'custom-group-visibility-create)
3340
3341 (defun custom-group-visibility-create (widget)
3342 (let ((visible (widget-value widget)))
3343 (if visible
3344 (insert "--------")))
3345 (widget-default-create widget))
3346
3347 (defun custom-group-members (symbol groups-only)
3348 "Return SYMBOL's custom group members.
3349 If GROUPS-ONLY non-nil, return only those members that are groups."
3350 (if (not groups-only)
3351 (get symbol 'custom-group)
3352 (let (members)
3353 (dolist (entry (get symbol 'custom-group))
3354 (when (eq (nth 1 entry) 'custom-group)
3355 (push entry members)))
3356 (nreverse members))))
3357
3358 (defun custom-group-value-create (widget)
3359 "Insert a customize group for WIDGET in the current buffer."
3360 (unless (eq (widget-get widget :custom-state) 'hidden)
3361 (custom-load-widget widget))
3362 (let* ((state (widget-get widget :custom-state))
3363 (level (widget-get widget :custom-level))
3364 ;; (indent (widget-get widget :indent))
3365 (prefix (widget-get widget :custom-prefix))
3366 (buttons (widget-get widget :buttons))
3367 (tag (widget-get widget :tag))
3368 (symbol (widget-value widget))
3369 (members (custom-group-members symbol
3370 (and (eq custom-buffer-style 'tree)
3371 custom-browse-only-groups))))
3372 (cond ((and (eq custom-buffer-style 'tree)
3373 (eq state 'hidden)
3374 (or members (custom-unloaded-widget-p widget)))
3375 (custom-browse-insert-prefix prefix)
3376 (push (widget-create-child-and-convert
3377 widget 'custom-browse-visibility
3378 ;; :tag-glyph "plus"
3379 :tag "+")
3380 buttons)
3381 (insert "-- ")
3382 ;; (widget-glyph-insert nil "-- " "horizontal")
3383 (push (widget-create-child-and-convert
3384 widget 'custom-browse-group-tag)
3385 buttons)
3386 (insert " " tag "\n")
3387 (widget-put widget :buttons buttons))
3388 ((and (eq custom-buffer-style 'tree)
3389 (zerop (length members)))
3390 (custom-browse-insert-prefix prefix)
3391 (insert "[ ]-- ")
3392 ;; (widget-glyph-insert nil "[ ]" "empty")
3393 ;; (widget-glyph-insert nil "-- " "horizontal")
3394 (push (widget-create-child-and-convert
3395 widget 'custom-browse-group-tag)
3396 buttons)
3397 (insert " " tag "\n")
3398 (widget-put widget :buttons buttons))
3399 ((eq custom-buffer-style 'tree)
3400 (custom-browse-insert-prefix prefix)
3401 (if (zerop (length members))
3402 (progn
3403 (custom-browse-insert-prefix prefix)
3404 (insert "[ ]-- ")
3405 ;; (widget-glyph-insert nil "[ ]" "empty")
3406 ;; (widget-glyph-insert nil "-- " "horizontal")
3407 (push (widget-create-child-and-convert
3408 widget 'custom-browse-group-tag)
3409 buttons)
3410 (insert " " tag "\n")
3411 (widget-put widget :buttons buttons))
3412 (push (widget-create-child-and-convert
3413 widget 'custom-browse-visibility
3414 ;; :tag-glyph "minus"
3415 :tag "-")
3416 buttons)
3417 (insert "-\\ ")
3418 ;; (widget-glyph-insert nil "-\\ " "top")
3419 (push (widget-create-child-and-convert
3420 widget 'custom-browse-group-tag)
3421 buttons)
3422 (insert " " tag "\n")
3423 (widget-put widget :buttons buttons)
3424 (message "Creating group...")
3425 (let* ((members (custom-sort-items members
3426 custom-browse-sort-alphabetically
3427 custom-browse-order-groups))
3428 (prefixes (widget-get widget :custom-prefixes))
3429 (custom-prefix-list (custom-prefix-add symbol prefixes))
3430 (extra-prefix (if (widget-get widget :custom-last)
3431 " "
3432 " | "))
3433 (prefix (concat prefix extra-prefix))
3434 children entry)
3435 (while members
3436 (setq entry (car members)
3437 members (cdr members))
3438 (push (widget-create-child-and-convert
3439 widget (nth 1 entry)
3440 :group widget
3441 :tag (custom-unlispify-tag-name (nth 0 entry))
3442 :custom-prefixes custom-prefix-list
3443 :custom-level (1+ level)
3444 :custom-last (null members)
3445 :value (nth 0 entry)
3446 :custom-prefix prefix)
3447 children))
3448 (widget-put widget :children (reverse children)))
3449 (message "Creating group...done")))
3450 ;; Nested style.
3451 ((eq state 'hidden)
3452 ;; Create level indicator.
3453 (unless (eq custom-buffer-style 'links)
3454 (insert-char ?\ (* custom-buffer-indent (1- level)))
3455 (insert "-- "))
3456 ;; Create tag.
3457 (let ((begin (point)))
3458 (insert tag)
3459 (widget-specify-sample widget begin (point)))
3460 (insert " group: ")
3461 ;; Create link/visibility indicator.
3462 (if (eq custom-buffer-style 'links)
3463 (push (widget-create-child-and-convert
3464 widget 'custom-group-link
3465 :tag "Go to Group"
3466 symbol)
3467 buttons)
3468 (push (widget-create-child-and-convert
3469 widget 'custom-group-visibility
3470 :help-echo "Show members of this group."
3471 :action 'custom-toggle-parent
3472 (not (eq state 'hidden)))
3473 buttons))
3474 (insert " \n")
3475 ;; Create magic button.
3476 (let ((magic (widget-create-child-and-convert
3477 widget 'custom-magic nil)))
3478 (widget-put widget :custom-magic magic)
3479 (push magic buttons))
3480 ;; Update buttons.
3481 (widget-put widget :buttons buttons)
3482 ;; Insert documentation.
3483 (if (and (eq custom-buffer-style 'links) (> level 1))
3484 (widget-put widget :documentation-indent 0))
3485 (widget-default-format-handler widget ?h))
3486 ;; Nested style.
3487 (t ;Visible.
3488 ;; Add parent groups references above the group.
3489 (if t ;;; This should test that the buffer
3490 ;;; was made to display a group.
3491 (when (eq level 1)
3492 (if (custom-add-parent-links widget
3493 "Go to parent group:")
3494 (insert "\n"))))
3495 ;; Create level indicator.
3496 (insert-char ?\ (* custom-buffer-indent (1- level)))
3497 (insert "/- ")
3498 ;; Create tag.
3499 (let ((start (point)))
3500 (insert tag)
3501 (widget-specify-sample widget start (point)))
3502 (insert " group: ")
3503 ;; Create visibility indicator.
3504 (unless (eq custom-buffer-style 'links)
3505 (insert "--------")
3506 (push (widget-create-child-and-convert
3507 widget 'visibility
3508 :help-echo "Hide members of this group."
3509 :action 'custom-toggle-parent
3510 (not (eq state 'hidden)))
3511 buttons)
3512 (insert " "))
3513 ;; Create more dashes.
3514 ;; Use 76 instead of 75 to compensate for the temporary "<"
3515 ;; added by `widget-insert'.
3516 (insert-char ?- (- 76 (current-column)
3517 (* custom-buffer-indent level)))
3518 (insert "\\\n")
3519 ;; Create magic button.
3520 (let ((magic (widget-create-child-and-convert
3521 widget 'custom-magic
3522 :indent 0
3523 nil)))
3524 (widget-put widget :custom-magic magic)
3525 (push magic buttons))
3526 ;; Update buttons.
3527 (widget-put widget :buttons buttons)
3528 ;; Insert documentation.
3529 (widget-default-format-handler widget ?h)
3530 ;; Parent groups.
3531 (if nil ;;; This should test that the buffer
3532 ;;; was not made to display a group.
3533 (when (eq level 1)
3534 (insert-char ?\ custom-buffer-indent)
3535 (custom-add-parent-links widget)))
3536 (custom-add-see-also widget
3537 (make-string (* custom-buffer-indent level)
3538 ?\ ))
3539 ;; Members.
3540 (message "Creating group...")
3541 (let* ((members (custom-sort-items members
3542 custom-buffer-sort-alphabetically
3543 custom-buffer-order-groups))
3544 (prefixes (widget-get widget :custom-prefixes))
3545 (custom-prefix-list (custom-prefix-add symbol prefixes))
3546 (length (length members))
3547 (count 0)
3548 (children (mapcar (lambda (entry)
3549 (widget-insert "\n")
3550 (message "\
3551 Creating group members... %2d%%"
3552 (/ (* 100.0 count) length))
3553 (setq count (1+ count))
3554 (prog1
3555 (widget-create-child-and-convert
3556 widget (nth 1 entry)
3557 :group widget
3558 :tag (custom-unlispify-tag-name
3559 (nth 0 entry))
3560 :custom-prefixes custom-prefix-list
3561 :custom-level (1+ level)
3562 :value (nth 0 entry))
3563 (unless (eq (preceding-char) ?\n)
3564 (widget-insert "\n"))))
3565 members)))
3566 (message "Creating group magic...")
3567 (mapc 'custom-magic-reset children)
3568 (message "Creating group state...")
3569 (widget-put widget :children children)
3570 (custom-group-state-update widget)
3571 (message "Creating group... done"))
3572 ;; End line
3573 (insert "\n")
3574 (insert-char ?\ (* custom-buffer-indent (1- level)))
3575 (insert "\\- " (widget-get widget :tag) " group end ")
3576 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3577 (insert "/\n")))))
3578
3579 (defvar custom-group-menu
3580 '(("Set for Current Session" custom-group-set
3581 (lambda (widget)
3582 (eq (widget-get widget :custom-state) 'modified)))
3583 ("Save for Future Sessions" custom-group-save
3584 (lambda (widget)
3585 (memq (widget-get widget :custom-state) '(modified set))))
3586 ("Reset to Current" custom-group-reset-current
3587 (lambda (widget)
3588 (memq (widget-get widget :custom-state) '(modified))))
3589 ("Reset to Saved" custom-group-reset-saved
3590 (lambda (widget)
3591 (memq (widget-get widget :custom-state) '(modified set))))
3592 ("Reset to standard setting" custom-group-reset-standard
3593 (lambda (widget)
3594 (memq (widget-get widget :custom-state) '(modified set saved)))))
3595 "Alist of actions for the `custom-group' widget.
3596 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3597 the menu entry, ACTION is the function to call on the widget when the
3598 menu is selected, and FILTER is a predicate which takes a `custom-group'
3599 widget as an argument, and returns non-nil if ACTION is valid on that
3600 widget. If FILTER is nil, ACTION is always valid.")
3601
3602 (defun custom-group-action (widget &optional event)
3603 "Show the menu for `custom-group' WIDGET.
3604 Optional EVENT is the location for the menu."
3605 (if (eq (widget-get widget :custom-state) 'hidden)
3606 (custom-toggle-hide widget)
3607 (let* ((completion-ignore-case t)
3608 (answer (widget-choose (concat "Operation on "
3609 (custom-unlispify-tag-name
3610 (widget-get widget :value)))
3611 (custom-menu-filter custom-group-menu
3612 widget)
3613 event)))
3614 (if answer
3615 (funcall answer widget)))))
3616
3617 (defun custom-group-set (widget)
3618 "Set changes in all modified group members."
3619 (let ((children (widget-get widget :children)))
3620 (mapc (lambda (child)
3621 (when (eq (widget-get child :custom-state) 'modified)
3622 (widget-apply child :custom-set)))
3623 children )))
3624
3625 (defun custom-group-save (widget)
3626 "Save all modified group members."
3627 (let ((children (widget-get widget :children)))
3628 (mapc (lambda (child)
3629 (when (memq (widget-get child :custom-state) '(modified set))
3630 (widget-apply child :custom-save)))
3631 children )))
3632
3633 (defun custom-group-reset-current (widget)
3634 "Reset all modified group members."
3635 (let ((children (widget-get widget :children)))
3636 (mapc (lambda (child)
3637 (when (eq (widget-get child :custom-state) 'modified)
3638 (widget-apply child :custom-reset-current)))
3639 children )))
3640
3641 (defun custom-group-reset-saved (widget)
3642 "Reset all modified or set group members."
3643 (let ((children (widget-get widget :children)))
3644 (mapc (lambda (child)
3645 (when (memq (widget-get child :custom-state) '(modified set))
3646 (widget-apply child :custom-reset-saved)))
3647 children )))
3648
3649 (defun custom-group-reset-standard (widget)
3650 "Reset all modified, set, or saved group members."
3651 (let ((children (widget-get widget :children)))
3652 (mapc (lambda (child)
3653 (when (memq (widget-get child :custom-state)
3654 '(modified set saved))
3655 (widget-apply child :custom-reset-standard)))
3656 children )))
3657
3658 (defun custom-group-state-update (widget)
3659 "Update magic."
3660 (unless (eq (widget-get widget :custom-state) 'hidden)
3661 (let* ((children (widget-get widget :children))
3662 (states (mapcar (lambda (child)
3663 (widget-get child :custom-state))
3664 children))
3665 (magics custom-magic-alist)
3666 (found 'standard))
3667 (while magics
3668 (let ((magic (car (car magics))))
3669 (if (and (not (eq magic 'hidden))
3670 (memq magic states))
3671 (setq found magic
3672 magics nil)
3673 (setq magics (cdr magics)))))
3674 (widget-put widget :custom-state found)))
3675 (custom-magic-reset widget))
3676
3677 ;;; The `custom-save-all' Function.
3678 ;;;###autoload
3679 (defcustom custom-file nil
3680 "File used for storing customization information.
3681 The default is nil, which means to use your init file
3682 as specified by `user-init-file'. If the value is not nil,
3683 it should be an absolute file name.
3684
3685 You can set this option through Custom, if you carefully read the
3686 last paragraph below. However, usually it is simpler to write
3687 something like the following in your init file:
3688
3689 \(setq custom-file \"~/.emacs-custom.el\")
3690 \(load custom-file)
3691
3692 Note that both lines are necessary: the first line tells Custom to
3693 save all customizations in this file, but does not load it.
3694
3695 When you change this variable outside Custom, look in the
3696 previous custom file \(usually your init file) for the
3697 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
3698 and copy them (whichever ones you find) to the new custom file.
3699 This will preserve your existing customizations.
3700
3701 If you save this option using Custom, Custom will write all
3702 currently saved customizations, including the new one for this
3703 option itself, into the file you specify, overwriting any
3704 `custom-set-variables' and `custom-set-faces' forms already
3705 present in that file. It will not delete any customizations from
3706 the old custom file. You should do that manually if that is what you
3707 want. You also have to put something like `\(load \"CUSTOM-FILE\")
3708 in your init file, where CUSTOM-FILE is the actual name of the
3709 file. Otherwise, Emacs will not load the file when it starts up,
3710 and hence will not set `custom-file' to that file either."
3711 :type '(choice (const :tag "Your Emacs init file" nil)
3712 (file :format "%t:%v%d"
3713 :doc
3714 "Please read entire docstring below before setting \
3715 this through Custom.
3716 Click om \"More\" \(or position point there and press RETURN)
3717 if only the first line of the docstring is shown."))
3718 :group 'customize)
3719
3720 (defun custom-file ()
3721 "Return the file name for saving customizations."
3722 (or custom-file
3723 (let ((user-init-file user-init-file)
3724 (default-init-file
3725 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
3726 (when (null user-init-file)
3727 (if (or (file-exists-p default-init-file)
3728 (and (eq system-type 'windows-nt)
3729 (file-exists-p "~/_emacs")))
3730 ;; Started with -q, i.e. the file containing
3731 ;; Custom settings hasn't been read. Saving
3732 ;; settings there would overwrite other settings.
3733 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3734 (setq user-init-file default-init-file))
3735 user-init-file)))
3736
3737 (defun custom-save-delete (symbol)
3738 "Visit `custom-file' and delete all calls to SYMBOL from it.
3739 Leave point at the old location of the first such call,
3740 or (if there were none) at the end of the buffer."
3741 (let ((default-major-mode 'emacs-lisp-mode))
3742 (set-buffer (find-file-noselect (custom-file))))
3743 (goto-char (point-min))
3744 ;; Skip all whitespace and comments.
3745 (while (forward-comment 1))
3746 (or (eobp)
3747 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3748 (let (first)
3749 (catch 'found
3750 (while t ;; We exit this loop only via throw.
3751 ;; Skip all whitespace and comments.
3752 (while (forward-comment 1))
3753 (let ((start (point))
3754 (sexp (condition-case nil
3755 (read (current-buffer))
3756 (end-of-file (throw 'found nil)))))
3757 (when (and (listp sexp)
3758 (eq (car sexp) symbol))
3759 (delete-region start (point))
3760 (unless first
3761 (setq first (point)))))))
3762 (if first
3763 (goto-char first)
3764 ;; Move in front of local variables, otherwise long Custom
3765 ;; entries would make them ineffective.
3766 (let ((pos (point-max))
3767 (case-fold-search t))
3768 (save-excursion
3769 (goto-char (point-max))
3770 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3771 'move)
3772 (when (search-forward "Local Variables:" nil t)
3773 (setq pos (line-beginning-position))))
3774 (goto-char pos)))))
3775
3776 (defun custom-save-variables ()
3777 "Save all customized variables in `custom-file'."
3778 (save-excursion
3779 (custom-save-delete 'custom-load-themes)
3780 (custom-save-delete 'custom-reset-variables)
3781 (custom-save-delete 'custom-set-variables)
3782 (custom-save-loaded-themes)
3783 (custom-save-resets 'theme-value 'custom-reset-variables nil)
3784 (let ((standard-output (current-buffer))
3785 (saved-list (make-list 1 0))
3786 sort-fold-case)
3787 ;; First create a sorted list of saved variables.
3788 (mapatoms
3789 (lambda (symbol)
3790 (if (get symbol 'saved-value)
3791 (nconc saved-list (list symbol)))))
3792 (setq saved-list (sort (cdr saved-list) 'string<))
3793 (unless (bolp)
3794 (princ "\n"))
3795 (princ "(custom-set-variables
3796 ;; custom-set-variables was added by Custom.
3797 ;; If you edit it by hand, you could mess it up, so be careful.
3798 ;; Your init file should contain only one such instance.
3799 ;; If there is more than one, they won't work right.\n")
3800 (dolist (symbol saved-list)
3801 (let ((spec (car-safe (get symbol 'theme-value)))
3802 (value (get symbol 'saved-value))
3803 (requests (get symbol 'custom-requests))
3804 (now (not (or (custom-variable-p symbol)
3805 (and (not (boundp symbol))
3806 (not (eq (get symbol 'force-value)
3807 'rogue))))))
3808 (comment (get symbol 'saved-variable-comment)))
3809 ;; Check `requests'.
3810 (dolist (request requests)
3811 (when (and (symbolp request) (not (featurep request)))
3812 (message "Unknown requested feature: %s" request)
3813 (setq requests (delq request requests))))
3814 (when (or (and spec
3815 (eq (nth 0 spec) 'user)
3816 (eq (nth 1 spec) 'set))
3817 comment
3818 (and (null spec) (get symbol 'saved-value)))
3819 (unless (bolp)
3820 (princ "\n"))
3821 (princ " '(")
3822 (prin1 symbol)
3823 (princ " ")
3824 (prin1 (car value))
3825 (when (or now requests comment)
3826 (princ " ")
3827 (prin1 now)
3828 (when (or requests comment)
3829 (princ " ")
3830 (prin1 requests)
3831 (when comment
3832 (princ " ")
3833 (prin1 comment))))
3834 (princ ")"))))
3835 (if (bolp)
3836 (princ " "))
3837 (princ ")")
3838 (unless (looking-at "\n")
3839 (princ "\n")))))
3840
3841 (defun custom-save-faces ()
3842 "Save all customized faces in `custom-file'."
3843 (save-excursion
3844 (custom-save-delete 'custom-reset-faces)
3845 (custom-save-delete 'custom-set-faces)
3846 (custom-save-resets 'theme-face 'custom-reset-faces '(default))
3847 (let ((standard-output (current-buffer))
3848 (saved-list (make-list 1 0))
3849 sort-fold-case)
3850 ;; First create a sorted list of saved faces.
3851 (mapatoms
3852 (lambda (symbol)
3853 (if (get symbol 'saved-face)
3854 (nconc saved-list (list symbol)))))
3855 (setq saved-list (sort (cdr saved-list) 'string<))
3856 ;; The default face must be first, since it affects the others.
3857 (if (memq 'default saved-list)
3858 (setq saved-list (cons 'default (delq 'default saved-list))))
3859 (unless (bolp)
3860 (princ "\n"))
3861 (princ "(custom-set-faces
3862 ;; custom-set-faces was added by Custom.
3863 ;; If you edit it by hand, you could mess it up, so be careful.
3864 ;; Your init file should contain only one such instance.
3865 ;; If there is more than one, they won't work right.\n")
3866 (dolist (symbol saved-list)
3867 (let ((spec (car-safe (get symbol 'theme-face)))
3868 (value (get symbol 'saved-face))
3869 (now (not (or (get symbol 'face-defface-spec)
3870 (and (not (custom-facep symbol))
3871 (not (get symbol 'force-face))))))
3872 (comment (get symbol 'saved-face-comment)))
3873 (when (or (and spec
3874 (eq (nth 0 spec) 'user)
3875 (eq (nth 1 spec) 'set))
3876 comment
3877 (and (null spec) (get symbol 'saved-face)))
3878 ;; Don't print default face here.
3879 (unless (bolp)
3880 (princ "\n"))
3881 (princ " '(")
3882 (prin1 symbol)
3883 (princ " ")
3884 (prin1 value)
3885 (when (or now comment)
3886 (princ " ")
3887 (prin1 now)
3888 (when comment
3889 (princ " ")
3890 (prin1 comment)))
3891 (princ ")"))))
3892 (if (bolp)
3893 (princ " "))
3894 (princ ")")
3895 (unless (looking-at "\n")
3896 (princ "\n")))))
3897
3898 (defun custom-save-resets (property setter special)
3899 (let (started-writing ignored-special)
3900 ;; (custom-save-delete setter) Done by caller
3901 (let ((standard-output (current-buffer))
3902 (mapper `(lambda (object)
3903 (let ((spec (car-safe (get object (quote ,property)))))
3904 (when (and (not (memq object ignored-special))
3905 (eq (nth 0 spec) 'user)
3906 (eq (nth 1 spec) 'reset))
3907 ;; Do not write reset statements unless necessary.
3908 (unless started-writing
3909 (setq started-writing t)
3910 (unless (bolp)
3911 (princ "\n"))
3912 (princ "(")
3913 (princ (quote ,setter))
3914 (princ "\n '(")
3915 (prin1 object)
3916 (princ " ")
3917 (prin1 (nth 3 spec))
3918 (princ ")")))))))
3919 (mapc mapper special)
3920 (setq ignored-special special)
3921 (mapatoms mapper)
3922 (when started-writing
3923 (princ ")\n")))))
3924
3925 (defun custom-save-loaded-themes ()
3926 (let ((themes (reverse (get 'user 'theme-loads-themes)))
3927 (standard-output (current-buffer)))
3928 (when themes
3929 (unless (bolp) (princ "\n"))
3930 (princ "(custom-load-themes")
3931 (mapc (lambda (theme)
3932 (princ "\n '")
3933 (prin1 theme)) themes)
3934 (princ " )\n"))))
3935
3936 ;;;###autoload
3937 (defun customize-save-customized ()
3938 "Save all user options which have been set in this session."
3939 (interactive)
3940 (mapatoms (lambda (symbol)
3941 (let ((face (get symbol 'customized-face))
3942 (value (get symbol 'customized-value))
3943 (face-comment (get symbol 'customized-face-comment))
3944 (variable-comment
3945 (get symbol 'customized-variable-comment)))
3946 (when face
3947 (put symbol 'saved-face face)
3948 (custom-push-theme 'theme-face symbol 'user 'set value)
3949 (put symbol 'customized-face nil))
3950 (when value
3951 (put symbol 'saved-value value)
3952 (custom-push-theme 'theme-value symbol 'user 'set value)
3953 (put symbol 'customized-value nil))
3954 (when variable-comment
3955 (put symbol 'saved-variable-comment variable-comment)
3956 (put symbol 'customized-variable-comment nil))
3957 (when face-comment
3958 (put symbol 'saved-face-comment face-comment)
3959 (put symbol 'customized-face-comment nil)))))
3960 ;; We really should update all custom buffers here.
3961 (custom-save-all))
3962
3963 ;;;###autoload
3964 (defun custom-save-all ()
3965 "Save all customizations in `custom-file'."
3966 (let ((inhibit-read-only t))
3967 (custom-save-variables)
3968 (custom-save-faces)
3969 (save-excursion
3970 (let ((default-major-mode nil))
3971 (set-buffer (find-file-noselect (custom-file))))
3972 (let ((file-precious-flag t))
3973 (save-buffer)))))
3974
3975 ;;; The Customize Menu.
3976
3977 ;;; Menu support
3978
3979 (defcustom custom-menu-nesting 2
3980 "Maximum nesting in custom menus."
3981 :type 'integer
3982 :group 'custom-menu)
3983
3984 (defun custom-face-menu-create (widget symbol)
3985 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3986 (vector (custom-unlispify-menu-entry symbol)
3987 `(customize-face ',symbol)
3988 t))
3989
3990 (defun custom-variable-menu-create (widget symbol)
3991 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3992 (let ((type (get symbol 'custom-type)))
3993 (unless (listp type)
3994 (setq type (list type)))
3995 (if (and type (widget-get type :custom-menu))
3996 (widget-apply type :custom-menu symbol)
3997 (vector (custom-unlispify-menu-entry symbol)
3998 `(customize-variable ',symbol)
3999 t))))
4000
4001 ;; Add checkboxes to boolean variable entries.
4002 (widget-put (get 'boolean 'widget-type)
4003 :custom-menu (lambda (widget symbol)
4004 (vector (custom-unlispify-menu-entry symbol)
4005 `(customize-variable ',symbol)
4006 ':style 'toggle
4007 ':selected symbol)))
4008
4009 (defun custom-group-menu-create (widget symbol)
4010 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4011 `( ,(custom-unlispify-menu-entry symbol t)
4012 :filter (lambda (&rest junk)
4013 (let ((menu (custom-menu-create ',symbol)))
4014 (if (consp menu) (cdr menu) menu)))))
4015
4016 ;;;###autoload
4017 (defun custom-menu-create (symbol)
4018 "Create menu for customization group SYMBOL.
4019 The menu is in a format applicable to `easy-menu-define'."
4020 (let* ((item (vector (custom-unlispify-menu-entry symbol)
4021 `(customize-group ',symbol)
4022 t)))
4023 (if (and (or (not (boundp 'custom-menu-nesting))
4024 (>= custom-menu-nesting 0))
4025 (progn
4026 (custom-load-symbol symbol)
4027 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
4028 (let ((custom-prefix-list (custom-prefix-add symbol
4029 custom-prefix-list))
4030 (members (custom-sort-items (get symbol 'custom-group)
4031 custom-menu-sort-alphabetically
4032 custom-menu-order-groups)))
4033 `(,(custom-unlispify-menu-entry symbol t)
4034 ,item
4035 "--"
4036 ,@(mapcar (lambda (entry)
4037 (widget-apply (if (listp (nth 1 entry))
4038 (nth 1 entry)
4039 (list (nth 1 entry)))
4040 :custom-menu (nth 0 entry)))
4041 members)))
4042 item)))
4043
4044 ;;;###autoload
4045 (defun customize-menu-create (symbol &optional name)
4046 "Return a customize menu for customization group SYMBOL.
4047 If optional NAME is given, use that as the name of the menu.
4048 Otherwise the menu will be named `Customize'.
4049 The format is suitable for use with `easy-menu-define'."
4050 (unless name
4051 (setq name "Customize"))
4052 `(,name
4053 :filter (lambda (&rest junk)
4054 (let ((menu (custom-menu-create ',symbol)))
4055 (if (consp menu) (cdr menu) menu)))))
4056
4057 ;;; The Custom Mode.
4058
4059 (defvar custom-mode-map
4060 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4061 ;; "\r" bindings from the parent map.
4062 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4063 (let ((map (make-keymap)))
4064 (set-keymap-parent map widget-keymap)
4065 (suppress-keymap map)
4066 (define-key map " " 'scroll-up)
4067 (define-key map "\177" 'scroll-down)
4068 (define-key map "\C-x\C-s" 'Custom-save)
4069 (define-key map "q" 'Custom-buffer-done)
4070 (define-key map "u" 'Custom-goto-parent)
4071 (define-key map "n" 'widget-forward)
4072 (define-key map "p" 'widget-backward)
4073 (define-key map [mouse-1] 'Custom-move-and-invoke)
4074 map)
4075 "Keymap for `custom-mode'.")
4076
4077 (defun Custom-move-and-invoke (event)
4078 "Move to where you click, and if it is an active field, invoke it."
4079 (interactive "e")
4080 (mouse-set-point event)
4081 (if (widget-event-point event)
4082 (let* ((pos (widget-event-point event))
4083 (button (get-char-property pos 'button)))
4084 (if button
4085 (widget-button-click event)))))
4086
4087 (easy-menu-define Custom-mode-menu
4088 custom-mode-map
4089 "Menu used in customization buffers."
4090 `("Custom"
4091 ,(customize-menu-create 'customize)
4092 ["Set" Custom-set t]
4093 ["Save" Custom-save t]
4094 ["Reset to Current" Custom-reset-current t]
4095 ["Reset to Saved" Custom-reset-saved t]
4096 ["Reset to Standard Settings" Custom-reset-standard t]
4097 ["Info" (Info-goto-node "(emacs)Easy Customization") t]))
4098
4099 (defun Custom-goto-parent ()
4100 "Go to the parent group listed at the top of this buffer.
4101 If several parents are listed, go to the first of them."
4102 (interactive)
4103 (save-excursion
4104 (goto-char (point-min))
4105 (if (search-forward "\nGo to parent group: " nil t)
4106 (let* ((button (get-char-property (point) 'button))
4107 (parent (downcase (widget-get button :tag))))
4108 (customize-group parent)))))
4109
4110 (defcustom custom-mode-hook nil
4111 "Hook called when entering Custom mode."
4112 :type 'hook
4113 :group 'custom-buffer )
4114
4115 (defun custom-state-buffer-message (widget)
4116 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4117 (message "To install your edits, invoke [State] and choose the Set operation")))
4118
4119 (defun custom-mode ()
4120 "Major mode for editing customization buffers.
4121
4122 The following commands are available:
4123
4124 Move to next button or editable field. \\[widget-forward]
4125 Move to previous button or editable field. \\[widget-backward]
4126 \\<widget-field-keymap>\
4127 Complete content of editable text field. \\[widget-complete]
4128 \\<custom-mode-map>\
4129 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4130 Invoke button under point. \\[widget-button-press]
4131 Set all modifications. \\[Custom-set]
4132 Make all modifications default. \\[Custom-save]
4133 Reset all modified options. \\[Custom-reset-current]
4134 Reset all modified or set options. \\[Custom-reset-saved]
4135 Reset all options. \\[Custom-reset-standard]
4136
4137 Entry to this mode calls the value of `custom-mode-hook'
4138 if that value is non-nil."
4139 (kill-all-local-variables)
4140 (setq major-mode 'custom-mode
4141 mode-name "Custom")
4142 (use-local-map custom-mode-map)
4143 (easy-menu-add Custom-mode-menu)
4144 (make-local-variable 'custom-options)
4145 (make-local-variable 'custom-local-buffer)
4146 (make-local-variable 'widget-documentation-face)
4147 (setq widget-documentation-face 'custom-documentation-face)
4148 (make-local-variable 'widget-button-face)
4149 (setq widget-button-face 'custom-button-face)
4150 (set (make-local-variable 'widget-button-pressed-face)
4151 'custom-button-pressed-face)
4152 (set (make-local-variable 'widget-mouse-face)
4153 'custom-button-pressed-face) ; buttons `depress' when moused
4154 ;; When possible, use relief for buttons, not bracketing. This test
4155 ;; may not be optimal.
4156 (when custom-raised-buttons
4157 (set (make-local-variable 'widget-push-button-prefix) "")
4158 (set (make-local-variable 'widget-push-button-suffix) "")
4159 (set (make-local-variable 'widget-link-prefix) "")
4160 (set (make-local-variable 'widget-link-suffix) ""))
4161 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
4162 (run-hooks 'custom-mode-hook))
4163
4164 (put 'custom-mode 'mode-class 'special)
4165
4166 (add-to-list
4167 'debug-ignored-errors
4168 "^No user options have changed defaults in recent Emacs versions$")
4169
4170 ;;; The End.
4171
4172 (provide 'cus-edit)
4173
4174 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4175 ;;; cus-edit.el ends here