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