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