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