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