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