(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
[emacs.git] / lisp / cus-edit.el
blob50759537ecb34ba0830468956feab6a0199e817e
1 ;;; cus-edit.el --- Tools for customizing Emacs and Lisp packages.
2 ;;
3 ;; Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
4 ;;
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: help, faces
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;; Commentary:
27 ;; This file implements the code to create and edit customize buffers.
28 ;;
29 ;; See `custom.el'.
31 ;; No commands should have names starting with `custom-' because
32 ;; that interferes with completion. Use `customize-' for commands
33 ;; that the user will run with M-x, and `Custom-' for interactive commands.
35 ;;; Code:
37 (require 'cus-face)
38 (require 'wid-edit)
39 (require 'easymenu)
40 (eval-when-compile
41 (require 'cl)
42 (defvar custom-versions-load-alist)) ; from cus-load
44 (condition-case nil
45 (require 'cus-load)
46 (error nil))
48 (condition-case nil
49 (require 'cus-start)
50 (error nil))
52 (put 'custom-define-hook 'custom-type 'hook)
53 (put 'custom-define-hook 'standard-value '(nil))
54 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
56 ;;; Customization Groups.
58 (defgroup emacs nil
59 "Customization of the One True Editor."
60 :link '(custom-manual "(emacs)Top"))
62 ;; Most of these groups are stolen from `finder.el',
63 (defgroup editing nil
64 "Basic text editing facilities."
65 :group 'emacs)
67 (defgroup abbrev nil
68 "Abbreviation handling, typing shortcuts, macros."
69 :tag "Abbreviations"
70 :group 'editing)
72 (defgroup matching nil
73 "Various sorts of searching and matching."
74 :group 'editing)
76 (defgroup emulations nil
77 "Emulations of other editors."
78 :group 'editing)
80 (defgroup mouse nil
81 "Mouse support."
82 :group 'editing)
84 (defgroup outlines nil
85 "Support for hierarchical outlining."
86 :group 'editing)
88 (defgroup external nil
89 "Interfacing to external utilities."
90 :group 'emacs)
92 (defgroup bib nil
93 "Code related to the `bib' bibliography processor."
94 :tag "Bibliography"
95 :group 'external)
97 (defgroup processes nil
98 "Process, subshell, compilation, and job control support."
99 :group 'external
100 :group 'development)
102 (defgroup convenience nil
103 "Convenience features for faster editing."
104 :group 'emacs)
106 (defgroup programming nil
107 "Support for programming in other languages."
108 :group 'emacs)
110 (defgroup languages nil
111 "Specialized modes for editing programming languages."
112 :group 'programming)
114 (defgroup lisp nil
115 "Lisp support, including Emacs Lisp."
116 :group 'languages
117 :group 'development)
119 (defgroup c nil
120 "Support for the C language and related languages."
121 :group 'languages)
123 (defgroup tools nil
124 "Programming tools."
125 :group 'programming)
127 (defgroup oop nil
128 "Support for object-oriented programming."
129 :group 'programming)
131 (defgroup applications nil
132 "Applications written in Emacs."
133 :group 'emacs)
135 (defgroup calendar nil
136 "Calendar and time management support."
137 :group 'applications)
139 (defgroup mail nil
140 "Modes for electronic-mail handling."
141 :group 'applications)
143 (defgroup news nil
144 "Support for netnews reading and posting."
145 :group 'applications)
147 (defgroup games nil
148 "Games, jokes and amusements."
149 :group 'applications)
151 (defgroup development nil
152 "Support for further development of Emacs."
153 :group 'emacs)
155 (defgroup docs nil
156 "Support for Emacs documentation."
157 :group 'development)
159 (defgroup extensions nil
160 "Emacs Lisp language extensions."
161 :group 'development)
163 (defgroup internal nil
164 "Code for Emacs internals, build process, defaults."
165 :group 'development)
167 (defgroup maint nil
168 "Maintenance aids for the Emacs development group."
169 :tag "Maintenance"
170 :group 'development)
172 (defgroup environment nil
173 "Fitting Emacs with its environment."
174 :group 'emacs)
176 (defgroup comm nil
177 "Communications, networking, remote access to files."
178 :tag "Communication"
179 :group 'environment)
181 (defgroup hardware nil
182 "Support for interfacing with exotic hardware."
183 :group 'environment)
185 (defgroup terminals nil
186 "Support for terminal types."
187 :group 'environment)
189 (defgroup unix nil
190 "Front-ends/assistants for, or emulators of, UNIX features."
191 :group 'environment)
193 (defgroup vms nil
194 "Support code for vms."
195 :group 'environment)
197 (defgroup i18n nil
198 "Internationalization and alternate character-set support."
199 :group 'environment
200 :group 'editing)
202 (defgroup x nil
203 "The X Window system."
204 :group 'environment)
206 (defgroup frames nil
207 "Support for Emacs frames and window systems."
208 :group 'environment)
210 (defgroup data nil
211 "Support editing files of data."
212 :group 'emacs)
214 (defgroup files nil
215 "Support editing files."
216 :group 'emacs)
218 (defgroup wp nil
219 "Word processing."
220 :group 'emacs)
222 (defgroup tex nil
223 "Code related to the TeX formatter."
224 :group 'wp)
226 (defgroup faces nil
227 "Support for multiple fonts."
228 :group 'emacs)
230 (defgroup hypermedia nil
231 "Support for links between text or other media types."
232 :group 'emacs)
234 (defgroup help nil
235 "Support for on-line help systems."
236 :group 'emacs)
238 (defgroup multimedia nil
239 "Non-textual support, specifically images and sound."
240 :group 'emacs)
242 (defgroup local nil
243 "Code local to your site."
244 :group 'emacs)
246 (defgroup customize '((widgets custom-group))
247 "Customization of the Customization support."
248 :link '(custom-manual "(elisp)Customization")
249 :link '(url-link :tag "(Old?) Development Page"
250 "http://www.dina.kvl.dk/~abraham/custom/")
251 :prefix "custom-"
252 :group 'help)
254 (defgroup custom-faces nil
255 "Faces used by customize."
256 :group 'customize
257 :group 'faces)
259 (defgroup custom-browse nil
260 "Control customize browser."
261 :prefix "custom-"
262 :group 'customize)
264 (defgroup custom-buffer nil
265 "Control customize buffers."
266 :prefix "custom-"
267 :group 'customize)
269 (defgroup custom-menu nil
270 "Control customize menus."
271 :prefix "custom-"
272 :group 'customize)
274 (defgroup abbrev-mode nil
275 "Word abbreviations mode."
276 :group 'abbrev)
278 (defgroup alloc nil
279 "Storage allocation and gc for GNU Emacs Lisp interpreter."
280 :tag "Storage Allocation"
281 :group 'internal)
283 (defgroup undo nil
284 "Undoing changes in buffers."
285 :group 'editing)
287 (defgroup modeline nil
288 "Content of the modeline."
289 :group 'environment)
291 (defgroup fill nil
292 "Indenting and filling text."
293 :group 'editing)
295 (defgroup editing-basics nil
296 "Most basic editing facilities."
297 :group 'editing)
299 (defgroup display nil
300 "How characters are displayed in buffers."
301 :group 'environment)
303 (defgroup execute nil
304 "Executing external commands."
305 :group 'processes)
307 (defgroup installation nil
308 "The Emacs installation."
309 :group 'environment)
311 (defgroup dired nil
312 "Directory editing."
313 :group 'environment)
315 (defgroup limits nil
316 "Internal Emacs limits."
317 :group 'internal)
319 (defgroup debug nil
320 "Debugging Emacs itself."
321 :group 'development)
323 (defgroup minibuffer nil
324 "Controling the behaviour of the minibuffer."
325 :group 'environment)
327 (defgroup keyboard nil
328 "Input from the keyboard."
329 :group 'environment)
331 (defgroup mouse nil
332 "Input from the mouse."
333 :group 'environment)
335 (defgroup menu nil
336 "Input from the menus."
337 :group 'environment)
339 (defgroup auto-save nil
340 "Preventing accidential loss of data."
341 :group 'files)
343 (defgroup processes-basics nil
344 "Basic stuff dealing with processes."
345 :group 'processes)
347 (defgroup mule nil
348 "MULE Emacs internationalization."
349 :group 'i18n)
351 (defgroup windows nil
352 "Windows within a frame."
353 :group 'environment)
355 ;;; Utilities.
357 (defun custom-quote (sexp)
358 "Quote SEXP iff it is not self quoting."
359 (if (or (memq sexp '(t nil))
360 (keywordp sexp)
361 (and (listp sexp)
362 (memq (car sexp) '(lambda)))
363 (stringp sexp)
364 (numberp sexp)
365 (vectorp sexp)
366 ;;; (and (fboundp 'characterp)
367 ;;; (characterp sexp))
369 sexp
370 (list 'quote sexp)))
372 (defun custom-split-regexp-maybe (regexp)
373 "If REGEXP is a string, split it to a list at `\\|'.
374 You can get the original back with from the result with:
375 (mapconcat 'identity result \"\\|\")
377 IF REGEXP is not a string, return it unchanged."
378 (if (stringp regexp)
379 (let ((start 0)
380 all)
381 (while (string-match "\\\\|" regexp start)
382 (setq all (cons (substring regexp start (match-beginning 0)) all)
383 start (match-end 0)))
384 (nreverse (cons (substring regexp start) all)))
385 regexp))
387 (defun custom-variable-prompt ()
388 ;; Code stolen from `help.el'.
389 "Prompt for a variable, defaulting to the variable at point.
390 Return a list suitable for use in `interactive'."
391 (let ((v (variable-at-point))
392 (enable-recursive-minibuffers t)
393 val)
394 (setq val (completing-read
395 (if (symbolp v)
396 (format "Customize option: (default %s) " v)
397 "Customize variable: ")
398 obarray (lambda (symbol)
399 (and (boundp symbol)
400 (or (get symbol 'custom-type)
401 (get symbol 'custom-loads)
402 (user-variable-p symbol)))) t))
403 (list (if (equal val "")
404 (if (symbolp v) v nil)
405 (intern val)))))
407 (defun custom-menu-filter (menu widget)
408 "Convert MENU to the form used by `widget-choose'.
409 MENU should be in the same format as `custom-variable-menu'.
410 WIDGET is the widget to apply the filter entries of MENU on."
411 (let ((result nil)
412 current name action filter)
413 (while menu
414 (setq current (car menu)
415 name (nth 0 current)
416 action (nth 1 current)
417 filter (nth 2 current)
418 menu (cdr menu))
419 (if (or (null filter) (funcall filter widget))
420 (push (cons name action) result)
421 (push name result)))
422 (nreverse result)))
424 ;;; Unlispify.
426 (defvar custom-prefix-list nil
427 "List of prefixes that should be ignored by `custom-unlispify'.")
429 (defcustom custom-unlispify-menu-entries t
430 "Display menu entries as words instead of symbols if non nil."
431 :group 'custom-menu
432 :type 'boolean)
434 (defcustom custom-unlispify-remove-prefixes nil
435 "Non-nil means remove group prefixes from option names in buffer."
436 :group 'custom-menu
437 :type 'boolean)
439 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
440 "Convert SYMBOL into a menu entry."
441 (cond ((not custom-unlispify-menu-entries)
442 (symbol-name symbol))
443 ((get symbol 'custom-tag)
444 (if no-suffix
445 (get symbol 'custom-tag)
446 (concat (get symbol 'custom-tag) "...")))
448 (save-excursion
449 (set-buffer (get-buffer-create " *Custom-Work*"))
450 (erase-buffer)
451 (princ symbol (current-buffer))
452 (goto-char (point-min))
453 (when (and (eq (get symbol 'custom-type) 'boolean)
454 (re-search-forward "-p\\'" nil t))
455 (replace-match "" t t)
456 (goto-char (point-min)))
457 (if custom-unlispify-remove-prefixes
458 (let ((prefixes custom-prefix-list)
459 prefix)
460 (while prefixes
461 (setq prefix (car prefixes))
462 (if (search-forward prefix (+ (point) (length prefix)) t)
463 (progn
464 (setq prefixes nil)
465 (delete-region (point-min) (point)))
466 (setq prefixes (cdr prefixes))))))
467 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
468 (capitalize-region (point-min) (point-max))
469 (unless no-suffix
470 (goto-char (point-max))
471 (insert "..."))
472 (buffer-string)))))
474 (defcustom custom-unlispify-tag-names t
475 "Display tag names as words instead of symbols if non nil."
476 :group 'custom-buffer
477 :type 'boolean)
479 (defun custom-unlispify-tag-name (symbol)
480 "Convert SYMBOL into a menu entry."
481 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
482 (custom-unlispify-menu-entry symbol t)))
484 (defun custom-prefix-add (symbol prefixes)
485 "Add SYMBOL to list of ignored PREFIXES."
486 (cons (or (get symbol 'custom-prefix)
487 (concat (symbol-name symbol) "-"))
488 prefixes))
490 ;;; Guess.
492 (defcustom custom-guess-name-alist
493 '(("-p\\'" boolean)
494 ("-hook\\'" hook)
495 ("-face\\'" face)
496 ("-file\\'" file)
497 ("-function\\'" function)
498 ("-functions\\'" (repeat function))
499 ("-list\\'" (repeat sexp))
500 ("-alist\\'" (repeat (cons sexp sexp))))
501 "Alist of (MATCH TYPE).
503 MATCH should be a regexp matching the name of a symbol, and TYPE should
504 be a widget suitable for editing the value of that symbol. The TYPE
505 of the first entry where MATCH matches the name of the symbol will be
506 used.
508 This is used for guessing the type of variables not declared with
509 customize."
510 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
511 :group 'customize)
513 (defcustom custom-guess-doc-alist
514 '(("\\`\\*?Non-nil " boolean))
515 "Alist of (MATCH TYPE).
517 MATCH should be a regexp matching a documentation string, and TYPE
518 should be a widget suitable for editing the value of a variable with
519 that documentation string. The TYPE of the first entry where MATCH
520 matches the name of the symbol will be used.
522 This is used for guessing the type of variables not declared with
523 customize."
524 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
525 :group 'customize)
527 (defun custom-guess-type (symbol)
528 "Guess a widget suitable for editing the value of SYMBOL.
529 This is done by matching SYMBOL with `custom-guess-name-alist' and
530 if that fails, the doc string with `custom-guess-doc-alist'."
531 (let ((name (symbol-name symbol))
532 (names custom-guess-name-alist)
533 current found)
534 (while names
535 (setq current (car names)
536 names (cdr names))
537 (when (string-match (nth 0 current) name)
538 (setq found (nth 1 current)
539 names nil)))
540 (unless found
541 (let ((doc (documentation-property symbol 'variable-documentation))
542 (docs custom-guess-doc-alist))
543 (when doc
544 (while docs
545 (setq current (car docs)
546 docs (cdr docs))
547 (when (string-match (nth 0 current) doc)
548 (setq found (nth 1 current)
549 docs nil))))))
550 found))
552 ;;; Sorting.
554 (defcustom custom-browse-sort-alphabetically nil
555 "If non-nil, sort members of each customization group alphabetically."
556 :type 'boolean
557 :group 'custom-browse)
559 (defcustom custom-browse-order-groups nil
560 "If non-nil, order group members within each customization group.
561 If `first', order groups before non-groups.
562 If `last', order groups after non-groups."
563 :type '(choice (const first)
564 (const last)
565 (const :tag "none" nil))
566 :group 'custom-browse)
568 (defcustom custom-browse-only-groups nil
569 "If non-nil, show group members only within each customization group."
570 :type 'boolean
571 :group 'custom-browse)
573 (defcustom custom-buffer-sort-alphabetically nil
574 "If non-nil, sort members of each customization group alphabetically."
575 :type 'boolean
576 :group 'custom-buffer)
578 (defcustom custom-buffer-order-groups 'last
579 "If non-nil, order group members within each customization group.
580 If `first', order groups before non-groups.
581 If `last', order groups after non-groups."
582 :type '(choice (const first)
583 (const last)
584 (const :tag "none" nil))
585 :group 'custom-buffer)
587 (defcustom custom-menu-sort-alphabetically nil
588 "If non-nil, sort members of each customization group alphabetically."
589 :type 'boolean
590 :group 'custom-menu)
592 (defcustom custom-menu-order-groups 'first
593 "If non-nil, order group members within each customization group.
594 If `first', order groups before non-groups.
595 If `last', order groups after non-groups."
596 :type '(choice (const first)
597 (const last)
598 (const :tag "none" nil))
599 :group 'custom-menu)
601 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
603 (defun custom-sort-items (items sort-alphabetically order-groups)
604 "Return a sorted copy of ITEMS.
605 ITEMS should be a `custom-group' property.
606 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
607 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
608 groups after non-groups, if nil do not order groups at all."
609 (sort (copy-sequence items)
610 (lambda (a b)
611 (let ((typea (nth 1 a)) (typeb (nth 1 b))
612 (namea (symbol-name (nth 0 a))) (nameb (symbol-name (nth 0 b))))
613 (cond ((not order-groups)
614 ;; Since we don't care about A and B order, maybe sort.
615 (when sort-alphabetically
616 (string-lessp namea nameb)))
617 ((eq typea 'custom-group)
618 ;; If B is also a group, maybe sort. Otherwise, order A and B.
619 (if (eq typeb 'custom-group)
620 (when sort-alphabetically
621 (string-lessp namea nameb))
622 (eq order-groups 'first)))
623 ((eq typeb 'custom-group)
624 ;; Since A cannot be a group, order A and B.
625 (eq order-groups 'last))
626 (sort-alphabetically
627 ;; Since A and B cannot be groups, sort.
628 (string-lessp namea nameb)))))))
630 ;;; Custom Mode Commands.
632 (defvar custom-options nil
633 "Customization widgets in the current buffer.")
635 (defun Custom-set ()
636 "Set changes in all modified options."
637 (interactive)
638 (let ((children custom-options))
639 (mapcar (lambda (child)
640 (when (eq (widget-get child :custom-state) 'modified)
641 (widget-apply child :custom-set)))
642 children)))
644 (defun Custom-save ()
645 "Set all modified group members and save them."
646 (interactive)
647 (let ((children custom-options))
648 (mapcar (lambda (child)
649 (when (memq (widget-get child :custom-state)
650 '(modified set changed rogue))
651 (widget-apply child :custom-save)))
652 children))
653 (custom-save-all))
655 (defvar custom-reset-menu
656 '(("Current" . Custom-reset-current)
657 ("Saved" . Custom-reset-saved)
658 ("Erase Customization (use standard settings)" . Custom-reset-standard))
659 "Alist of actions for the `Reset' button.
660 The key is a string containing the name of the action, the value is a
661 Lisp function taking the widget as an element which will be called
662 when the action is chosen.")
664 (defun custom-reset (event)
665 "Select item from reset menu."
666 (let* ((completion-ignore-case t)
667 (answer (widget-choose "Reset to"
668 custom-reset-menu
669 event)))
670 (if answer
671 (funcall answer))))
673 (defun Custom-reset-current (&rest ignore)
674 "Reset all modified group members to their current value."
675 (interactive)
676 (let ((children custom-options))
677 (mapcar (lambda (widget)
678 (and (default-boundp (widget-value widget))
679 (if (memq (widget-get widget :custom-state)
680 '(modified changed))
681 (widget-apply widget :custom-reset-current))))
682 children)))
684 (defun Custom-reset-saved (&rest ignore)
685 "Reset all modified or set group members to their saved value."
686 (interactive)
687 (let ((children custom-options))
688 (mapcar (lambda (widget)
689 (and (get (widget-value widget) 'saved-value)
690 (if (memq (widget-get widget :custom-state)
691 '(modified set changed rogue))
692 (widget-apply widget :custom-reset-saved))))
693 children)))
695 (defun Custom-reset-standard (&rest ignore)
696 "Erase all customization (either current or saved) for the group members.
697 The immediate result is to restore them to their standard settings.
698 This operation eliminates any saved settings for the group members,
699 making them as if they had never been customized at all."
700 (interactive)
701 (let ((children custom-options))
702 (mapcar (lambda (widget)
703 (and (get (widget-value widget) 'standard-value)
704 (if (memq (widget-get widget :custom-state)
705 '(modified set changed saved rogue))
706 (widget-apply widget :custom-reset-standard))))
707 children)))
709 ;;; The Customize Commands
711 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
712 "Prompt for a variable and a value and return them as a list.
713 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
714 prompt for the value. The %s escape in PROMPT-VAL is replaced with
715 the name of the variable.
717 If the variable has a `variable-interactive' property, that is used as if
718 it were the arg to `interactive' (which see) to interactively read the value.
720 If the variable has a `custom-type' property, it must be a widget and the
721 `:prompt-value' property of that widget will be used for reading the value.
723 If optional COMMENT argument is non nil, also prompt for a comment and return
724 it as the third element in the list."
725 (let* ((var (read-variable prompt-var))
726 (minibuffer-help-form '(describe-variable var))
727 (val
728 (let ((prop (get var 'variable-interactive))
729 (type (get var 'custom-type))
730 (prompt (format prompt-val var)))
731 (unless (listp type)
732 (setq type (list type)))
733 (cond (prop
734 ;; Use VAR's `variable-interactive' property
735 ;; as an interactive spec for prompting.
736 (call-interactively (list 'lambda '(arg)
737 (list 'interactive prop)
738 'arg)))
739 (type
740 (widget-prompt-value type
741 prompt
742 (if (boundp var)
743 (symbol-value var))
744 (not (boundp var))))
746 (eval-minibuffer prompt))))))
747 (if comment
748 (list var val
749 (read-string "Comment: " (get var 'variable-comment)))
750 (list var val))))
752 ;;;###autoload
753 (defun customize-set-value (var val &optional comment)
754 "Set VARIABLE to VALUE. VALUE is a Lisp object.
756 If VARIABLE has a `variable-interactive' property, that is used as if
757 it were the arg to `interactive' (which see) to interactively read the value.
759 If VARIABLE has a `custom-type' property, it must be a widget and the
760 `:prompt-value' property of that widget will be used for reading the value.
762 If given a prefix (or a COMMENT argument), also prompt for a comment."
763 (interactive (custom-prompt-variable "Set variable: "
764 "Set %s to value: "
765 current-prefix-arg))
767 (set var val)
768 (cond ((string= comment "")
769 (put var 'variable-comment nil))
770 (comment
771 (put var 'variable-comment comment))))
773 ;;;###autoload
774 (defun customize-set-variable (variable value &optional comment)
775 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
777 If VARIABLE has a `custom-set' property, that is used for setting
778 VARIABLE, otherwise `set-default' is used.
780 The `customized-value' property of the VARIABLE will be set to a list
781 with a quoted VALUE as its sole list member.
783 If VARIABLE has a `variable-interactive' property, that is used as if
784 it were the arg to `interactive' (which see) to interactively read the value.
786 If VARIABLE has a `custom-type' property, it must be a widget and the
787 `:prompt-value' property of that widget will be used for reading the value.
789 If given a prefix (or a COMMENT argument), also prompt for a comment."
790 (interactive (custom-prompt-variable "Set variable: "
791 "Set customized value for %s to: "
792 current-prefix-arg))
793 (funcall (or (get variable 'custom-set) 'set-default) variable value)
794 (put variable 'customized-value (list (custom-quote value)))
795 (cond ((string= comment "")
796 (put variable 'variable-comment nil)
797 (put variable 'customized-variable-comment nil))
798 (comment
799 (put variable 'variable-comment comment)
800 (put variable 'customized-variable-comment comment))))
802 ;;;###autoload
803 (defun customize-save-variable (var value &optional comment)
804 "Set the default for VARIABLE to VALUE, and save it for future sessions.
805 If VARIABLE has a `custom-set' property, that is used for setting
806 VARIABLE, otherwise `set-default' is used.
808 The `customized-value' property of the VARIABLE will be set to a list
809 with a quoted VALUE as its sole list member.
811 If VARIABLE has a `variable-interactive' property, that is used as if
812 it were the arg to `interactive' (which see) to interactively read the value.
814 If VARIABLE has a `custom-type' property, it must be a widget and the
815 `:prompt-value' property of that widget will be used for reading the value.
817 If given a prefix (or a COMMENT argument), also prompt for a comment."
818 (interactive (custom-prompt-variable "Set and ave variable: "
819 "Set and save value for %s as: "
820 current-prefix-arg))
821 (funcall (or (get var 'custom-set) 'set-default) var value)
822 (put var 'saved-value (list (custom-quote value)))
823 (cond ((string= comment "")
824 (put var 'variable-comment nil)
825 (put var 'saved-variable-comment nil))
826 (comment
827 (put var 'variable-comment comment)
828 (put var 'saved-variable-comment comment)))
829 (custom-save-all))
831 ;;;###autoload
832 (defun customize ()
833 "Select a customization buffer which you can use to set user options.
834 User options are structured into \"groups\".
835 Initially the top-level group `Emacs' and its immediate subgroups
836 are shown; the contents of those subgroups are initially hidden."
837 (interactive)
838 (customize-group 'emacs))
840 ;;;###autoload
841 (defun customize-group (group)
842 "Customize GROUP, which must be a customization group."
843 (interactive (list (let ((completion-ignore-case t))
844 (completing-read "Customize group: (default emacs) "
845 obarray
846 (lambda (symbol)
847 (or (get symbol 'custom-loads)
848 (get symbol 'custom-group)))
849 t))))
850 (when (stringp group)
851 (if (string-equal "" group)
852 (setq group 'emacs)
853 (setq group (intern group))))
854 (or (get group 'custom-group)
855 (custom-load-symbol group))
856 (let ((name (format "*Customize Group: %s*"
857 (custom-unlispify-tag-name group))))
858 (if (get-buffer name)
859 (pop-to-buffer name)
860 (custom-buffer-create (list (list group 'custom-group))
861 name
862 (concat " for group "
863 (custom-unlispify-tag-name group))))))
865 ;;;###autoload
866 (defun customize-group-other-window (group)
867 "Customize GROUP, which must be a customization group."
868 (interactive (list (let ((completion-ignore-case t))
869 (completing-read "Customize group: (default emacs) "
870 obarray
871 (lambda (symbol)
872 (or (get symbol 'custom-loads)
873 (get symbol 'custom-group)))
874 t))))
875 (when (stringp group)
876 (if (string-equal "" group)
877 (setq group 'emacs)
878 (setq group (intern group))))
879 (or (get group 'custom-group)
880 (custom-load-symbol group))
881 (let ((name (format "*Customize Group: %s*"
882 (custom-unlispify-tag-name group))))
883 (if (get-buffer name)
884 (let ((window (selected-window)))
885 (pop-to-buffer name)
886 (select-window window))
887 (custom-buffer-create-other-window
888 (list (list group 'custom-group))
889 name
890 (concat " for group "
891 (custom-unlispify-tag-name group))))))
893 ;;;###autoload
894 (defalias 'customize-variable 'customize-option)
896 ;;;###autoload
897 (defun customize-option (symbol)
898 "Customize SYMBOL, which must be a user option variable."
899 (interactive (custom-variable-prompt))
900 ;; If we don't have SYMBOL's real definition loaded,
901 ;; try to load it.
902 (unless (get symbol 'custom-type)
903 (let ((loaddefs-file (locate-library "loaddefs.el" t))
904 file)
905 ;; See if it is autoloaded from some library.
906 (when loaddefs-file
907 (with-temp-buffer
908 (insert-file-contents loaddefs-file)
909 (when (re-search-forward (concat "^(defvar " (symbol-name symbol))
910 nil t)
911 (search-backward "\n;;; Generated autoloads from ")
912 (goto-char (match-end 0))
913 (setq file (buffer-substring (point)
914 (progn (end-of-line) (point)))))))
915 ;; If it is, load that library.
916 (when file
917 (when (string-match "\\.el\\'" file)
918 (setq file (substring file 0 (match-beginning 0))))
919 (load file))))
920 (unless (get symbol 'custom-type)
921 (error "Variable %s cannot be customized" symbol))
922 (custom-buffer-create (list (list symbol 'custom-variable))
923 (format "*Customize Option: %s*"
924 (custom-unlispify-tag-name symbol))))
926 (defvar customize-changed-options-previous-release "20.2"
927 "Version for `customize-changed-options' to refer back to by default.")
929 ;;;###autoload
930 (defun customize-changed-options (since-version)
931 "Customize all user option variables changed in Emacs itself.
932 This includes new user option variables and faces, and new
933 customization groups, as well as older options and faces whose default
934 values have changed since the previous major Emacs release.
936 With argument SINCE-VERSION (a string), customize all user option
937 variables that were added (or their meanings were changed) since that
938 version."
940 (interactive "sCustomize options changed, since version (default all versions): ")
941 (if (equal since-version "")
942 (setq since-version nil))
943 (unless since-version
944 (setq since-version customize-changed-options-previous-release))
945 (let ((found nil)
946 (versions nil))
947 (mapatoms (lambda (symbol)
948 (and (or (boundp symbol)
949 ;; For variables not yet loaded.
950 (get symbol 'standard-value)
951 ;; For groups the previous test fails, this one
952 ;; could be used to determine if symbol is a
953 ;; group. Is there a better way for this?
954 (get symbol 'group-documentation))
955 (let ((version (get symbol 'custom-version)))
956 (and version
957 (or (null since-version)
958 (customize-version-lessp since-version version))
959 (if (member version versions)
961 ;;; Collect all versions that we use.
962 (push version versions))))
963 (setq found
964 ;; We have to set the right thing here,
965 ;; depending if we have a group or a
966 ;; variable.
967 (if (get symbol 'group-documentation)
968 (cons (list symbol 'custom-group) found)
969 (cons (list symbol 'custom-variable) found))))))
970 (if (not found)
971 (error "No user option defaults have been changed since Emacs %s"
972 since-version)
973 (let ((flist nil))
974 (while versions
975 (push (copy-sequence
976 (cdr (assoc (car versions) custom-versions-load-alist)))
977 flist)
978 (setq versions (cdr versions)))
979 (put 'custom-versions-load-alist 'custom-loads
980 ;; Get all the files that correspond to element from the
981 ;; VERSIONS list. This could use some simplification.
982 (apply 'nconc flist)))
983 ;; Because we set all the files needed to be loaded as a
984 ;; `custom-loads' property to `custom-versions-load-alist' this
985 ;; call will actually load them.
986 (custom-load-symbol 'custom-versions-load-alist)
987 ;; Clean up
988 (put 'custom-versions-load-alist 'custom-loads nil)
989 (custom-buffer-create (custom-sort-items found t 'first)
990 "*Customize Changed Options*"))))
992 (defun customize-version-lessp (version1 version2)
993 ;; In case someone made a mistake and left out the quotes
994 ;; in the :version value.
995 (if (numberp version2)
996 (setq version2 (prin1-to-string version2)))
997 (let (major1 major2 minor1 minor2)
998 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1)
999 (setq major1 (read (match-string 1 version1)))
1000 (setq minor1 (read (match-string 2 version1)))
1001 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2)
1002 (setq major2 (read (match-string 1 version2)))
1003 (setq minor2 (read (match-string 2 version2)))
1004 (or (< major1 major2)
1005 (and (= major1 major2)
1006 (< minor1 minor2)))))
1008 ;;;###autoload
1009 (defalias 'customize-variable-other-window 'customize-option-other-window)
1011 ;;;###autoload
1012 (defun customize-option-other-window (symbol)
1013 "Customize SYMBOL, which must be a user option variable.
1014 Show the buffer in another window, but don't select it."
1015 (interactive (custom-variable-prompt))
1016 (custom-buffer-create-other-window
1017 (list (list symbol 'custom-variable))
1018 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
1020 ;;;###autoload
1021 (defun customize-face (&optional symbol)
1022 "Customize SYMBOL, which should be a face name or nil.
1023 If SYMBOL is nil, customize all faces."
1024 (interactive (list (completing-read "Customize face: (default all) "
1025 obarray 'custom-facep t)))
1026 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
1027 (custom-buffer-create (custom-sort-items
1028 (mapcar (lambda (symbol)
1029 (list symbol 'custom-face))
1030 (face-list))
1031 t nil)
1032 "*Customize Faces*")
1033 (when (stringp symbol)
1034 (setq symbol (intern symbol)))
1035 (unless (symbolp symbol)
1036 (error "Should be a symbol %S" symbol))
1037 (custom-buffer-create (list (list symbol 'custom-face))
1038 (format "*Customize Face: %s*"
1039 (custom-unlispify-tag-name symbol)))))
1041 ;;;###autoload
1042 (defun customize-face-other-window (&optional symbol)
1043 "Show customization buffer for face SYMBOL in other window."
1044 (interactive (list (completing-read "Customize face: "
1045 obarray 'custom-facep t)))
1046 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
1048 (if (stringp symbol)
1049 (setq symbol (intern symbol)))
1050 (unless (symbolp symbol)
1051 (error "Should be a symbol %S" symbol))
1052 (custom-buffer-create-other-window
1053 (list (list symbol 'custom-face))
1054 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol)))))
1056 ;;;###autoload
1057 (defun customize-customized ()
1058 "Customize all user options set since the last save in this session."
1059 (interactive)
1060 (let ((found nil))
1061 (mapatoms (lambda (symbol)
1062 (and (or (get symbol 'customized-face)
1063 (get symbol 'customized-face-comment))
1064 (custom-facep symbol)
1065 (push (list symbol 'custom-face) found))
1066 (and (or (get symbol 'customized-value)
1067 (get symbol 'customized-variable-comment))
1068 (boundp symbol)
1069 (push (list symbol 'custom-variable) found))))
1070 (if (not found)
1071 (error "No customized user options")
1072 (custom-buffer-create (custom-sort-items found t nil)
1073 "*Customize Customized*"))))
1075 ;;;###autoload
1076 (defun customize-saved ()
1077 "Customize all already saved user options."
1078 (interactive)
1079 (let ((found nil))
1080 (mapatoms (lambda (symbol)
1081 (and (or (get symbol 'saved-face)
1082 (get symbol 'saved-face-comment))
1083 (custom-facep symbol)
1084 (push (list symbol 'custom-face) found))
1085 (and (or (get symbol 'saved-value)
1086 (get symbol 'saved-variable-comment))
1087 (boundp symbol)
1088 (push (list symbol 'custom-variable) found))))
1089 (if (not found )
1090 (error "No saved user options")
1091 (custom-buffer-create (custom-sort-items found t nil)
1092 "*Customize Saved*"))))
1094 ;;;###autoload
1095 (defun customize-apropos (regexp &optional all)
1096 "Customize all user options matching REGEXP.
1097 If ALL is `options', include only options.
1098 If ALL is `faces', include only faces.
1099 If ALL is `groups', include only groups.
1100 If ALL is t (interactively, with prefix arg), include options which are not
1101 user-settable, as well as faces and groups."
1102 (interactive "sCustomize regexp: \nP")
1103 (let ((found nil))
1104 (mapatoms (lambda (symbol)
1105 (when (string-match regexp (symbol-name symbol))
1106 (when (and (not (memq all '(faces options)))
1107 (get symbol 'custom-group))
1108 (push (list symbol 'custom-group) found))
1109 (when (and (not (memq all '(options groups)))
1110 (custom-facep symbol))
1111 (push (list symbol 'custom-face) found))
1112 (when (and (not (memq all '(groups faces)))
1113 (boundp symbol)
1114 (or (get symbol 'saved-value)
1115 (get symbol 'standard-value)
1116 (if (memq all '(nil options))
1117 (user-variable-p symbol)
1118 (get symbol 'variable-documentation))))
1119 (push (list symbol 'custom-variable) found)))))
1120 (if (not found)
1121 (error "No matches")
1122 (custom-buffer-create (custom-sort-items found t
1123 custom-buffer-order-groups)
1124 "*Customize Apropos*"))))
1126 ;;;###autoload
1127 (defun customize-apropos-options (regexp &optional arg)
1128 "Customize all user options matching REGEXP.
1129 With prefix arg, include options which are not user-settable."
1130 (interactive "sCustomize regexp: \nP")
1131 (customize-apropos regexp (or arg 'options)))
1133 ;;;###autoload
1134 (defun customize-apropos-faces (regexp)
1135 "Customize all user faces matching REGEXP."
1136 (interactive "sCustomize regexp: \n")
1137 (customize-apropos regexp 'faces))
1139 ;;;###autoload
1140 (defun customize-apropos-groups (regexp)
1141 "Customize all user groups matching REGEXP."
1142 (interactive "sCustomize regexp: \n")
1143 (customize-apropos regexp 'groups))
1145 ;;; Buffer.
1147 (defcustom custom-buffer-style 'links
1148 "Control the presentation style for customization buffers.
1149 The value should be a symbol, one of:
1151 brackets: groups nest within each other with big horizontal brackets.
1152 links: groups have links to subgroups."
1153 :type '(radio (const brackets)
1154 (const links))
1155 :group 'custom-buffer)
1157 ;; If we pass BUFFER to `bury-buffer', the buffer isn't removed from
1158 ;; the window.
1159 (defun custom-bury-buffer (buffer)
1160 (bury-buffer))
1162 (defcustom custom-buffer-done-function 'custom-bury-buffer
1163 "*Function called to remove a Custom buffer when the user is done with it.
1164 Called with one argument, the buffer to remove."
1165 :type '(choice (function-item :tag "Bury buffer" custom-bury-buffer)
1166 (function-item :tag "Kill buffer" kill-buffer)
1167 (function :tag "Other"))
1168 :version "21.1"
1169 :group 'custom-buffer)
1171 (defcustom custom-buffer-indent 3
1172 "Number of spaces to indent nested groups."
1173 :type 'integer
1174 :group 'custom-buffer)
1176 ;;;###autoload
1177 (defun custom-buffer-create (options &optional name description)
1178 "Create a buffer containing OPTIONS.
1179 Optional NAME is the name of the buffer.
1180 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1181 SYMBOL is a customization option, and WIDGET is a widget for editing
1182 that option."
1183 (unless name (setq name "*Customization*"))
1184 (kill-buffer (get-buffer-create name))
1185 (pop-to-buffer (get-buffer-create name))
1186 (custom-buffer-create-internal options description))
1188 ;;;###autoload
1189 (defun custom-buffer-create-other-window (options &optional name description)
1190 "Create a buffer containing OPTIONS.
1191 Optional NAME is the name of the buffer.
1192 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1193 SYMBOL is a customization option, and WIDGET is a widget for editing
1194 that option."
1195 (unless name (setq name "*Customization*"))
1196 (kill-buffer (get-buffer-create name))
1197 (let ((window (selected-window))
1198 (pop-up-windows t)
1199 (special-display-buffer-names nil)
1200 (special-display-regexps nil)
1201 (same-window-buffer-names nil)
1202 (same-window-regexps nil))
1203 (pop-to-buffer (get-buffer-create name))
1204 (custom-buffer-create-internal options description)
1205 (select-window window)))
1207 (defcustom custom-reset-button-menu nil
1208 "If non-nil, only show a single reset button in customize buffers.
1209 This button will have a menu with all three reset operations."
1210 :type 'boolean
1211 :group 'custom-buffer)
1213 (defun Custom-buffer-done (&rest ignore)
1214 "Remove current buffer by calling `custom-buffer-done-function'."
1215 (interactive)
1216 (funcall custom-buffer-done-function (current-buffer)))
1218 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1219 '(("unspecified" . unspecified))))
1220 "If non-nil, indicate active buttons in a `raised-button' style.
1221 Otherwise use brackets."
1222 :type 'boolean
1223 :version "21.1"
1224 :group 'custom-buffer)
1226 (defun custom-buffer-create-internal (options &optional description)
1227 (message "Creating customization buffer...")
1228 (custom-mode)
1229 (widget-insert "This is a customization buffer")
1230 (if description
1231 (widget-insert description))
1232 (widget-insert (format ".
1233 %s show active fields; type RET or click mouse-1
1234 on an active field to invoke its action. Editing an option value
1235 changes the text in the buffer; invoke the State button and
1236 choose the Set operation to set the option value.
1237 Invoke " (if custom-raised-buttons
1238 "`Raised' buttons"
1239 "Square brackets")))
1240 (widget-create 'info-link
1241 :tag "Help"
1242 :help-echo "Read the online help."
1243 "(emacs)Easy Customization")
1244 (widget-insert " for more information.\n\n")
1245 (message "Creating customization buttons...")
1246 (widget-insert "Operate on everything in this buffer:\n ")
1247 (widget-create 'push-button
1248 :tag "Set for Current Session"
1249 :help-echo "\
1250 Make your editing in this buffer take effect for this session."
1251 :action (lambda (widget &optional event)
1252 (Custom-set)))
1253 (widget-insert " ")
1254 (widget-create 'push-button
1255 :tag "Save for Future Sessions"
1256 :help-echo "\
1257 Make your editing in this buffer take effect for future Emacs sessions."
1258 :action (lambda (widget &optional event)
1259 (Custom-save)))
1260 (if custom-reset-button-menu
1261 (progn
1262 (widget-insert " ")
1263 (widget-create 'push-button
1264 :tag "Reset"
1265 :help-echo "Show a menu with reset operations."
1266 :mouse-down-action (lambda (&rest junk) t)
1267 :action (lambda (widget &optional event)
1268 (custom-reset event))))
1269 (widget-insert "\n ")
1270 (widget-create 'push-button
1271 :tag "Reset"
1272 :help-echo "\
1273 Reset all edited text in this buffer to reflect current values."
1274 :action 'Custom-reset-current)
1275 (widget-insert " ")
1276 (widget-create 'push-button
1277 :tag "Reset to Saved"
1278 :help-echo "\
1279 Reset all values in this buffer to their saved settings."
1280 :action 'Custom-reset-saved)
1281 (widget-insert " ")
1282 (widget-create 'push-button
1283 :tag "Erase Customization"
1284 :help-echo "\
1285 Un-customize all values in this buffer. They get their standard settings."
1286 :action 'Custom-reset-standard))
1287 (widget-insert " ")
1288 (widget-create 'push-button
1289 :tag "Finish"
1290 :help-echo "Bury or kill the buffer."
1291 :action #'Custom-buffer-done)
1292 (widget-insert "\n\n")
1293 (message "Creating customization items...")
1294 (setq custom-options
1295 (if (= (length options) 1)
1296 (mapcar (lambda (entry)
1297 (widget-create (nth 1 entry)
1298 :documentation-shown t
1299 :custom-state 'unknown
1300 :tag (custom-unlispify-tag-name
1301 (nth 0 entry))
1302 :value (nth 0 entry)))
1303 options)
1304 (let ((count 0)
1305 (length (length options)))
1306 (mapcar (lambda (entry)
1307 (prog2
1308 (message "Creating customization items ...%2d%%"
1309 (/ (* 100.0 count) length))
1310 (widget-create (nth 1 entry)
1311 :tag (custom-unlispify-tag-name
1312 (nth 0 entry))
1313 :value (nth 0 entry))
1314 (setq count (1+ count))
1315 (unless (eq (preceding-char) ?\n)
1316 (widget-insert "\n"))
1317 (widget-insert "\n")))
1318 options))))
1319 (unless (eq (preceding-char) ?\n)
1320 (widget-insert "\n"))
1321 (message "Creating customization items ...%2d%%done" 100)
1322 (unless (eq custom-buffer-style 'tree)
1323 (mapcar 'custom-magic-reset custom-options))
1324 (message "Creating customization setup...")
1325 (widget-setup)
1326 (goto-char (point-min))
1327 (message "Creating customization buffer...done"))
1329 ;;; The Tree Browser.
1331 ;;;###autoload
1332 (defun customize-browse (&optional group)
1333 "Create a tree browser for the customize hierarchy."
1334 (interactive)
1335 (unless group
1336 (setq group 'emacs))
1337 (let ((name "*Customize Browser*"))
1338 (kill-buffer (get-buffer-create name))
1339 (pop-to-buffer (get-buffer-create name)))
1340 (custom-mode)
1341 (widget-insert "\
1342 Square brackets show active fields; type RET or click mouse-1
1343 on an active field to invoke its action.
1344 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1345 (if custom-browse-only-groups
1346 (widget-insert "\
1347 Invoke the [Group] button below to edit that item in another window.\n\n")
1348 (widget-insert "Invoke the ")
1349 (widget-create 'item
1350 :format "%t"
1351 :tag "[Group]"
1352 :tag-glyph "folder")
1353 (widget-insert ", ")
1354 (widget-create 'item
1355 :format "%t"
1356 :tag "[Face]"
1357 :tag-glyph "face")
1358 (widget-insert ", and ")
1359 (widget-create 'item
1360 :format "%t"
1361 :tag "[Option]"
1362 :tag-glyph "option")
1363 (widget-insert " buttons below to edit that
1364 item in another window.\n\n"))
1365 (let ((custom-buffer-style 'tree))
1366 (widget-create 'custom-group
1367 :custom-last t
1368 :custom-state 'unknown
1369 :tag (custom-unlispify-tag-name group)
1370 :value group))
1371 (goto-char (point-min)))
1373 (define-widget 'custom-browse-visibility 'item
1374 "Control visibility of items in the customize tree browser."
1375 :format "%[[%t]%]"
1376 :action 'custom-browse-visibility-action)
1378 (defun custom-browse-visibility-action (widget &rest ignore)
1379 (let ((custom-buffer-style 'tree))
1380 (custom-toggle-parent widget)))
1382 (define-widget 'custom-browse-group-tag 'push-button
1383 "Show parent in other window when activated."
1384 :tag "Group"
1385 :tag-glyph "folder"
1386 :action 'custom-browse-group-tag-action)
1388 (defun custom-browse-group-tag-action (widget &rest ignore)
1389 (let ((parent (widget-get widget :parent)))
1390 (customize-group-other-window (widget-value parent))))
1392 (define-widget 'custom-browse-variable-tag 'push-button
1393 "Show parent in other window when activated."
1394 :tag "Option"
1395 :tag-glyph "option"
1396 :action 'custom-browse-variable-tag-action)
1398 (defun custom-browse-variable-tag-action (widget &rest ignore)
1399 (let ((parent (widget-get widget :parent)))
1400 (customize-variable-other-window (widget-value parent))))
1402 (define-widget 'custom-browse-face-tag 'push-button
1403 "Show parent in other window when activated."
1404 :tag "Face"
1405 :tag-glyph "face"
1406 :action 'custom-browse-face-tag-action)
1408 (defun custom-browse-face-tag-action (widget &rest ignore)
1409 (let ((parent (widget-get widget :parent)))
1410 (customize-face-other-window (widget-value parent))))
1412 (defconst custom-browse-alist '((" " "space")
1413 (" | " "vertical")
1414 ("-\\ " "top")
1415 (" |-" "middle")
1416 (" `-" "bottom")))
1418 (defun custom-browse-insert-prefix (prefix)
1419 "Insert PREFIX. On XEmacs convert it to line graphics."
1420 ;; Fixme: do graphics.
1421 (if nil ; (string-match "XEmacs" emacs-version)
1422 (progn
1423 (insert "*")
1424 (while (not (string-equal prefix ""))
1425 (let ((entry (substring prefix 0 3)))
1426 (setq prefix (substring prefix 3))
1427 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1428 (name (nth 1 (assoc entry custom-browse-alist))))
1429 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1430 (overlay-put overlay 'start-open t)
1431 (overlay-put overlay 'end-open t)))))
1432 (insert prefix)))
1434 ;;; Modification of Basic Widgets.
1436 ;; We add extra properties to the basic widgets needed here. This is
1437 ;; fine, as long as we are careful to stay within out own namespace.
1439 ;; We want simple widgets to be displayed by default, but complex
1440 ;; widgets to be hidden.
1442 (widget-put (get 'item 'widget-type) :custom-show t)
1443 (widget-put (get 'editable-field 'widget-type)
1444 :custom-show (lambda (widget value)
1445 (let ((pp (pp-to-string value)))
1446 (cond ((string-match "\n" pp)
1447 nil)
1448 ((> (length pp) 40)
1449 nil)
1450 (t t)))))
1451 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1453 ;;; The `custom-manual' Widget.
1455 (define-widget 'custom-manual 'info-link
1456 "Link to the manual entry for this customization option."
1457 :help-echo "Read the manual entry for this option."
1458 :tag "Manual")
1460 ;;; The `custom-magic' Widget.
1462 (defgroup custom-magic-faces nil
1463 "Faces used by the magic button."
1464 :group 'custom-faces
1465 :group 'custom-buffer)
1467 (defface custom-invalid-face '((((class color))
1468 (:foreground "yellow" :background "red"))
1470 (:bold t :italic t :underline t)))
1471 "Face used when the customize item is invalid."
1472 :group 'custom-magic-faces)
1474 (defface custom-rogue-face '((((class color))
1475 (:foreground "pink" :background "black"))
1477 (:underline t)))
1478 "Face used when the customize item is not defined for customization."
1479 :group 'custom-magic-faces)
1481 (defface custom-modified-face '((((class color))
1482 (:foreground "white" :background "blue"))
1484 (:italic t :bold)))
1485 "Face used when the customize item has been modified."
1486 :group 'custom-magic-faces)
1488 (defface custom-set-face '((((class color))
1489 (:foreground "blue" :background "white"))
1491 (:italic t)))
1492 "Face used when the customize item has been set."
1493 :group 'custom-magic-faces)
1495 (defface custom-changed-face '((((class color))
1496 (:foreground "white" :background "blue"))
1498 (:italic t)))
1499 "Face used when the customize item has been changed."
1500 :group 'custom-magic-faces)
1502 (defface custom-saved-face '((t (:underline t)))
1503 "Face used when the customize item has been saved."
1504 :group 'custom-magic-faces)
1506 (defconst custom-magic-alist '((nil "#" underline "\
1507 uninitialized, you should not see this.")
1508 (unknown "?" italic "\
1509 unknown, you should not see this.")
1510 (hidden "-" default "\
1511 hidden, invoke \"Show\" in the previous line to show." "\
1512 group now hidden, invoke \"Show\", above, to show contents.")
1513 (invalid "x" custom-invalid-face "\
1514 the value displayed for this %c is invalid and cannot be set.")
1515 (modified "*" custom-modified-face "\
1516 you have edited the value as text, but you have not set the %c." "\
1517 you have edited something in this group, but not set it.")
1518 (set "+" custom-set-face "\
1519 you have set this %c, but not saved it for future sessions." "\
1520 something in this group has been set, but not saved.")
1521 (changed ":" custom-changed-face "\
1522 this %c has been changed outside the customize buffer." "\
1523 something in this group has been changed outside customize.")
1524 (saved "!" custom-saved-face "\
1525 this %c has been set and saved." "\
1526 something in this group has been set and saved.")
1527 (rogue "@" custom-rogue-face "\
1528 this %c has not been changed with customize." "\
1529 something in this group is not prepared for customization.")
1530 (standard " " nil "\
1531 this %c is unchanged from its standard setting." "\
1532 visible group members are all at standard settings."))
1533 "Alist of customize option states.
1534 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1536 STATE is one of the following symbols:
1538 `nil'
1539 For internal use, should never occur.
1540 `unknown'
1541 For internal use, should never occur.
1542 `hidden'
1543 This item is not being displayed.
1544 `invalid'
1545 This item is modified, but has an invalid form.
1546 `modified'
1547 This item is modified, and has a valid form.
1548 `set'
1549 This item has been set but not saved.
1550 `changed'
1551 The current value of this item has been changed temporarily.
1552 `saved'
1553 This item is marked for saving.
1554 `rogue'
1555 This item has no customization information.
1556 `standard'
1557 This item is unchanged from the standard setting.
1559 MAGIC is a string used to present that state.
1561 FACE is a face used to present the state.
1563 ITEM-DESC is a string describing the state for options.
1565 GROUP-DESC is a string describing the state for groups. If this is
1566 left out, ITEM-DESC will be used.
1568 The string %c in either description will be replaced with the
1569 category of the item. These are `group'. `option', and `face'.
1571 The list should be sorted most significant first.")
1573 (defcustom custom-magic-show 'long
1574 "If non-nil, show textual description of the state.
1575 If `long', show a full-line description, not just one word."
1576 :type '(choice (const :tag "no" nil)
1577 (const long)
1578 (other :tag "short" short))
1579 :group 'custom-buffer)
1581 (defcustom custom-magic-show-hidden '(option face)
1582 "Control whether the State button is shown for hidden items.
1583 The value should be a list with the custom categories where the State
1584 button should be visible. Possible categories are `group', `option',
1585 and `face'."
1586 :type '(set (const group) (const option) (const face))
1587 :group 'custom-buffer)
1589 (defcustom custom-magic-show-button nil
1590 "Show a \"magic\" button indicating the state of each customization option."
1591 :type 'boolean
1592 :group 'custom-buffer)
1594 (define-widget 'custom-magic 'default
1595 "Show and manipulate state for a customization option."
1596 :format "%v"
1597 :action 'widget-parent-action
1598 :notify 'ignore
1599 :value-get 'ignore
1600 :value-create 'custom-magic-value-create
1601 :value-delete 'widget-children-value-delete)
1603 (defun widget-magic-mouse-down-action (widget &optional event)
1604 ;; Non-nil unless hidden.
1605 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1606 :custom-state)
1607 'hidden)))
1609 (defun custom-magic-value-create (widget)
1610 "Create compact status report for WIDGET."
1611 (let* ((parent (widget-get widget :parent))
1612 (state (widget-get parent :custom-state))
1613 (hidden (eq state 'hidden))
1614 (entry (assq state custom-magic-alist))
1615 (magic (nth 1 entry))
1616 (face (nth 2 entry))
1617 (category (widget-get parent :custom-category))
1618 (text (or (and (eq category 'group)
1619 (nth 4 entry))
1620 (nth 3 entry)))
1621 (form (widget-get parent :custom-form))
1622 children)
1623 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1624 (setq text (concat (match-string 1 text)
1625 (symbol-name category)
1626 (match-string 2 text))))
1627 (when (and custom-magic-show
1628 (or (not hidden)
1629 (memq category custom-magic-show-hidden)))
1630 (insert " ")
1631 (when (and (eq category 'group)
1632 (not (and (eq custom-buffer-style 'links)
1633 (> (widget-get parent :custom-level) 1))))
1634 (insert-char ?\ (* custom-buffer-indent
1635 (widget-get parent :custom-level))))
1636 (push (widget-create-child-and-convert
1637 widget 'choice-item
1638 :help-echo "Change the state of this item."
1639 :format (if hidden "%t" "%[%t%]")
1640 :button-prefix 'widget-push-button-prefix
1641 :button-suffix 'widget-push-button-suffix
1642 :mouse-down-action 'widget-magic-mouse-down-action
1643 :tag "State")
1644 children)
1645 (insert ": ")
1646 (let ((start (point)))
1647 (if (eq custom-magic-show 'long)
1648 (insert text)
1649 (insert (symbol-name state)))
1650 (cond ((eq form 'lisp)
1651 (insert " (lisp)"))
1652 ((eq form 'mismatch)
1653 (insert " (mismatch)")))
1654 (put-text-property start (point) 'face 'custom-state-face))
1655 (insert "\n"))
1656 (when (and (eq category 'group)
1657 (not (and (eq custom-buffer-style 'links)
1658 (> (widget-get parent :custom-level) 1))))
1659 (insert-char ?\ (* custom-buffer-indent
1660 (widget-get parent :custom-level))))
1661 (when custom-magic-show-button
1662 (when custom-magic-show
1663 (let ((indent (widget-get parent :indent)))
1664 (when indent
1665 (insert-char ? indent))))
1666 (push (widget-create-child-and-convert
1667 widget 'choice-item
1668 :mouse-down-action 'widget-magic-mouse-down-action
1669 :button-face face
1670 :button-prefix ""
1671 :button-suffix ""
1672 :help-echo "Change the state."
1673 :format (if hidden "%t" "%[%t%]")
1674 :tag (if (memq form '(lisp mismatch))
1675 (concat "(" magic ")")
1676 (concat "[" magic "]")))
1677 children)
1678 (insert " "))
1679 (widget-put widget :children children)))
1681 (defun custom-magic-reset (widget)
1682 "Redraw the :custom-magic property of WIDGET."
1683 (let ((magic (widget-get widget :custom-magic)))
1684 (widget-value-set magic (widget-value magic))))
1686 ;;; The `custom' Widget.
1688 (defface custom-button-face
1689 '((((type x) (class color)) ; Like default modeline
1690 (:box (:line-width 2 :style released-button) :background "lightgrey"))
1691 (((type w32) (class color)) ; Like default modeline
1692 (:box (:line-width 2 :style released-button) :background "lightgrey"))
1694 nil))
1695 "Face used for buttons in customization buffers."
1696 :version "21.1"
1697 :group 'custom-faces)
1699 (defface custom-button-pressed-face
1700 '((((type x) (class color))
1701 (:box (:line-width 2 :style pressed-button) :background "lightgrey"))
1702 (((type w32) (class color))
1703 (:box (:line-width 2 :style pressed-button) :background "lightgrey"))
1705 (:inverse-video t)))
1706 "Face used for buttons in customization buffers."
1707 :version "21.1"
1708 :group 'custom-faces)
1710 (defface custom-documentation-face nil
1711 "Face used for documentation strings in customization buffers."
1712 :group 'custom-faces)
1714 (defface custom-state-face '((((class color)
1715 (background dark))
1716 (:foreground "lime green"))
1717 (((class color)
1718 (background light))
1719 (:foreground "dark green"))
1720 (t nil))
1721 "Face used for State descriptions in the customize buffer."
1722 :group 'custom-faces)
1724 (define-widget 'custom 'default
1725 "Customize a user option."
1726 :format "%v"
1727 :convert-widget 'custom-convert-widget
1728 :notify 'custom-notify
1729 :custom-prefix ""
1730 :custom-level 1
1731 :custom-state 'hidden
1732 :documentation-property 'widget-subclass-responsibility
1733 :value-create 'widget-subclass-responsibility
1734 :value-delete 'widget-children-value-delete
1735 :value-get 'widget-value-value-get
1736 :validate 'widget-children-validate
1737 :match (lambda (widget value) (symbolp value)))
1739 (defun custom-convert-widget (widget)
1740 "Initialize :value and :tag from :args in WIDGET."
1741 (let ((args (widget-get widget :args)))
1742 (when args
1743 (widget-put widget :value (widget-apply widget
1744 :value-to-internal (car args)))
1745 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1746 (widget-put widget :args nil)))
1747 widget)
1749 (defun custom-notify (widget &rest args)
1750 "Keep track of changes."
1751 (let ((state (widget-get widget :custom-state)))
1752 (unless (eq state 'modified)
1753 (unless (memq state '(nil unknown hidden))
1754 (widget-put widget :custom-state 'modified))
1755 (custom-magic-reset widget)
1756 (apply 'widget-default-notify widget args))))
1758 (defun custom-redraw (widget)
1759 "Redraw WIDGET with current settings."
1760 (let ((line (count-lines (point-min) (point)))
1761 (column (current-column))
1762 (pos (point))
1763 (from (marker-position (widget-get widget :from)))
1764 (to (marker-position (widget-get widget :to))))
1765 (save-excursion
1766 (widget-value-set widget (widget-value widget))
1767 (custom-redraw-magic widget))
1768 (when (and (>= pos from) (<= pos to))
1769 (condition-case nil
1770 (progn
1771 (if (> column 0)
1772 (goto-line line)
1773 (goto-line (1+ line)))
1774 (move-to-column column))
1775 (error nil)))))
1777 (defun custom-redraw-magic (widget)
1778 "Redraw WIDGET state with current settings."
1779 (while widget
1780 (let ((magic (widget-get widget :custom-magic)))
1781 (cond (magic
1782 (widget-value-set magic (widget-value magic))
1783 (when (setq widget (widget-get widget :group))
1784 (custom-group-state-update widget)))
1786 (setq widget nil)))))
1787 (widget-setup))
1789 (defun custom-show (widget value)
1790 "Non-nil if WIDGET should be shown with VALUE by default."
1791 (let ((show (widget-get widget :custom-show)))
1792 (cond ((null show)
1793 nil)
1794 ((eq t show)
1797 (funcall show widget value)))))
1799 (defvar custom-load-recursion nil
1800 "Hack to avoid recursive dependencies.")
1802 (defun custom-load-symbol (symbol)
1803 "Load all dependencies for SYMBOL."
1804 (unless custom-load-recursion
1805 (let ((custom-load-recursion t)
1806 (loads (get symbol 'custom-loads))
1807 load)
1808 (while loads
1809 (setq load (car loads)
1810 loads (cdr loads))
1811 (cond ((symbolp load)
1812 (condition-case nil
1813 (require load)
1814 (error nil)))
1815 ;; Don't reload a file already loaded.
1816 ((and (boundp 'preloaded-file-list)
1817 (member load preloaded-file-list)))
1818 ((assoc load load-history))
1819 ((assoc (locate-library load) load-history))
1821 (condition-case nil
1822 ;; Without this, we would load cus-edit recursively.
1823 ;; We are still loading it when we call this,
1824 ;; and it is not in load-history yet.
1825 (or (equal load "cus-edit")
1826 (load-library load))
1827 (error nil))))))))
1829 (defun custom-load-widget (widget)
1830 "Load all dependencies for WIDGET."
1831 (custom-load-symbol (widget-value widget)))
1833 (defun custom-unloaded-symbol-p (symbol)
1834 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1835 (let ((found nil)
1836 (loads (get symbol 'custom-loads))
1837 load)
1838 (while loads
1839 (setq load (car loads)
1840 loads (cdr loads))
1841 (cond ((symbolp load)
1842 (unless (featurep load)
1843 (setq found t)))
1844 ((assoc load load-history))
1845 ((assoc (locate-library load) load-history)
1846 (message nil))
1848 (setq found t))))
1849 found))
1851 (defun custom-unloaded-widget-p (widget)
1852 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1853 (custom-unloaded-symbol-p (widget-value widget)))
1855 (defun custom-toggle-hide (widget)
1856 "Toggle visibility of WIDGET."
1857 (custom-load-widget widget)
1858 (let ((state (widget-get widget :custom-state)))
1859 (cond ((memq state '(invalid modified))
1860 (error "There are unset changes"))
1861 ((eq state 'hidden)
1862 (widget-put widget :custom-state 'unknown))
1864 (widget-put widget :documentation-shown nil)
1865 (widget-put widget :custom-state 'hidden)))
1866 (custom-redraw widget)
1867 (widget-setup)))
1869 (defun custom-toggle-parent (widget &rest ignore)
1870 "Toggle visibility of parent of WIDGET."
1871 (custom-toggle-hide (widget-get widget :parent)))
1873 (defun custom-add-see-also (widget &optional prefix)
1874 "Add `See also ...' to WIDGET if there are any links.
1875 Insert PREFIX first if non-nil."
1876 (let* ((symbol (widget-get widget :value))
1877 (links (get symbol 'custom-links))
1878 (many (> (length links) 2))
1879 (buttons (widget-get widget :buttons))
1880 (indent (widget-get widget :indent)))
1881 (when links
1882 (when indent
1883 (insert-char ?\ indent))
1884 (when prefix
1885 (insert prefix))
1886 (insert "See also ")
1887 (while links
1888 (push (widget-create-child-and-convert widget (car links))
1889 buttons)
1890 (setq links (cdr links))
1891 (cond ((null links)
1892 (insert ".\n"))
1893 ((null (cdr links))
1894 (if many
1895 (insert ", and ")
1896 (insert " and ")))
1898 (insert ", "))))
1899 (widget-put widget :buttons buttons))))
1901 (defun custom-add-parent-links (widget &optional initial-string)
1902 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1903 The value if non-nil if any parents were found.
1904 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1905 (let ((name (widget-value widget))
1906 (type (widget-type widget))
1907 (buttons (widget-get widget :buttons))
1908 (start (point))
1909 found)
1910 (insert (or initial-string "Parent groups:"))
1911 (mapatoms (lambda (symbol)
1912 (let ((entry (assq name (get symbol 'custom-group))))
1913 (when (eq (nth 1 entry) type)
1914 (insert " ")
1915 (push (widget-create-child-and-convert
1916 widget 'custom-group-link
1917 :tag (custom-unlispify-tag-name symbol)
1918 symbol)
1919 buttons)
1920 (setq found t)))))
1921 (widget-put widget :buttons buttons)
1922 (if found
1923 (insert "\n")
1924 (delete-region start (point)))
1925 found))
1927 ;;; The `custom-comment' Widget.
1929 ;; like the editable field
1930 (defface custom-comment-face '((((class grayscale color)
1931 (background light))
1932 (:background "gray85"))
1933 (((class grayscale color)
1934 (background dark))
1935 (:background "dim gray"))
1937 (:italic t)))
1938 "Face used for comments on variables or faces"
1939 :version "21.1"
1940 :group 'custom-faces)
1942 ;; like font-lock-comment-face
1943 (defface custom-comment-tag-face
1944 '((((class color) (background dark)) (:foreground "gray80"))
1945 (((class color) (background light)) (:foreground "blue4"))
1946 (((class grayscale) (background light))
1947 (:foreground "DimGray" :bold t :italic t))
1948 (((class grayscale) (background dark))
1949 (:foreground "LightGray" :bold t :italic t))
1950 (t (:bold t)))
1951 "Face used for variables or faces comment tags"
1952 :group 'custom-faces)
1954 (define-widget 'custom-comment 'string
1955 "User comment."
1956 :tag "Comment"
1957 :help-echo "Edit a comment here."
1958 :sample-face 'custom-comment-tag-face
1959 :value-face 'custom-comment-face
1960 :shown nil
1961 :create 'custom-comment-create)
1963 (defun custom-comment-create (widget)
1964 (let* ((null-comment (equal "" (widget-value widget))))
1965 (if (or (widget-get (widget-get widget :parent) :comment-shown)
1966 (not null-comment))
1967 (widget-default-create widget)
1968 ;; `widget-default-delete' expects markers in these slots --
1969 ;; maybe it shouldn't.
1970 (widget-put widget :from (point-marker))
1971 (widget-put widget :to (point-marker)))))
1973 (defun custom-comment-hide (widget)
1974 (widget-put (widget-get widget :parent) :comment-shown nil))
1976 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
1977 ;; the global custom one
1978 (defun custom-comment-show (widget)
1979 (widget-put widget :comment-shown t)
1980 (custom-redraw widget)
1981 (widget-setup))
1983 (defun custom-comment-invisible-p (widget)
1984 (let ((val (widget-value (widget-get widget :comment-widget))))
1985 (and (equal "" val)
1986 (not (widget-get widget :comment-shown)))))
1988 ;;; The `custom-variable' Widget.
1990 ;; When this was underlined blue, users confused it with a
1991 ;; Mosaic-style hyperlink...
1992 (defface custom-variable-tag-face
1993 `((((class color)
1994 (background dark))
1995 (:foreground "light blue" :bold t :family "helv"
1996 :height ,(let ((height (face-attribute 'default :height)))
1997 (if (numberp height)
1998 (floor height 0.9)
1999 height))))
2000 (((class color)
2001 (background light))
2002 (:foreground "blue" :family "helv" :bold t
2003 :height ,(let ((height (face-attribute 'default :height)))
2004 (if (numberp height)
2005 (floor height 0.9)
2006 height))))
2007 (t (:bold t)))
2008 "Face used for unpushable variable tags."
2009 :group 'custom-faces)
2011 (defface custom-variable-button-face '((t (:underline t :bold t)))
2012 "Face used for pushable variable tags."
2013 :group 'custom-faces)
2015 (defcustom custom-variable-default-form 'edit
2016 "Default form of displaying variable values."
2017 :type '(choice (const edit)
2018 (const lisp))
2019 :group 'custom-buffer
2020 :version "20.3")
2022 (define-widget 'custom-variable 'custom
2023 "Customize variable."
2024 :format "%v"
2025 :help-echo "Set or reset this variable."
2026 :documentation-property 'variable-documentation
2027 :custom-category 'option
2028 :custom-state nil
2029 :custom-menu 'custom-variable-menu-create
2030 :custom-form nil ; defaults to value of `custom-variable-default-form'
2031 :value-create 'custom-variable-value-create
2032 :action 'custom-variable-action
2033 :custom-set 'custom-variable-set
2034 :custom-save 'custom-variable-save
2035 :custom-reset-current 'custom-redraw
2036 :custom-reset-saved 'custom-variable-reset-saved
2037 :custom-reset-standard 'custom-variable-reset-standard)
2039 (defun custom-variable-type (symbol)
2040 "Return a widget suitable for editing the value of SYMBOL.
2041 If SYMBOL has a `custom-type' property, use that.
2042 Otherwise, look up symbol in `custom-guess-type-alist'."
2043 (let* ((type (or (get symbol 'custom-type)
2044 (and (not (get symbol 'standard-value))
2045 (custom-guess-type symbol))
2046 'sexp))
2047 (options (get symbol 'custom-options))
2048 (tmp (if (listp type)
2049 (copy-sequence type)
2050 (list type))))
2051 (when options
2052 (widget-put tmp :options options))
2053 tmp))
2055 (defun custom-variable-value-create (widget)
2056 "Here is where you edit the variable's value."
2057 (custom-load-widget widget)
2058 (unless (widget-get widget :custom-form)
2059 (widget-put widget :custom-form custom-variable-default-form))
2060 (let* ((buttons (widget-get widget :buttons))
2061 (children (widget-get widget :children))
2062 (form (widget-get widget :custom-form))
2063 (state (widget-get widget :custom-state))
2064 (symbol (widget-get widget :value))
2065 (tag (widget-get widget :tag))
2066 (type (custom-variable-type symbol))
2067 (conv (widget-convert type))
2068 (get (or (get symbol 'custom-get) 'default-value))
2069 (prefix (widget-get widget :custom-prefix))
2070 (last (widget-get widget :custom-last))
2071 (value (if (default-boundp symbol)
2072 (funcall get symbol)
2073 (widget-get conv :value))))
2074 ;; If the widget is new, the child determines whether it is hidden.
2075 (cond (state)
2076 ((custom-show type value)
2077 (setq state 'unknown))
2079 (setq state 'hidden)))
2080 ;; If we don't know the state, see if we need to edit it in lisp form.
2081 (when (eq state 'unknown)
2082 (unless (widget-apply conv :match value)
2083 ;; (widget-apply (widget-convert type) :match value)
2084 (setq form 'mismatch)))
2085 ;; Now we can create the child widget.
2086 (cond ((eq custom-buffer-style 'tree)
2087 (insert prefix (if last " `--- " " |--- "))
2088 (push (widget-create-child-and-convert
2089 widget 'custom-browse-variable-tag)
2090 buttons)
2091 (insert " " tag "\n")
2092 (widget-put widget :buttons buttons))
2093 ((eq state 'hidden)
2094 ;; Indicate hidden value.
2095 (push (widget-create-child-and-convert
2096 widget 'item
2097 :format "%{%t%}: "
2098 :sample-face 'custom-variable-tag-face
2099 :tag tag
2100 :parent widget)
2101 buttons)
2102 (push (widget-create-child-and-convert
2103 widget 'visibility
2104 :help-echo "Show the value of this option."
2105 :action 'custom-toggle-parent
2106 nil)
2107 buttons))
2108 ((memq form '(lisp mismatch))
2109 ;; In lisp mode edit the saved value when possible.
2110 (let* ((value (cond ((get symbol 'saved-value)
2111 (car (get symbol 'saved-value)))
2112 ((get symbol 'standard-value)
2113 (car (get symbol 'standard-value)))
2114 ((default-boundp symbol)
2115 (custom-quote (funcall get symbol)))
2117 (custom-quote (widget-get conv :value))))))
2118 (insert (symbol-name symbol) ": ")
2119 (push (widget-create-child-and-convert
2120 widget 'visibility
2121 :help-echo "Hide the value of this option."
2122 :action 'custom-toggle-parent
2124 buttons)
2125 (insert " ")
2126 (push (widget-create-child-and-convert
2127 widget 'sexp
2128 :button-face 'custom-variable-button-face
2129 :format "%v"
2130 :tag (symbol-name symbol)
2131 :parent widget
2132 :value value)
2133 children)))
2135 ;; Edit mode.
2136 (let* ((format (widget-get type :format))
2137 tag-format value-format)
2138 (unless (string-match ":" format)
2139 (error "Bad format"))
2140 (setq tag-format (substring format 0 (match-end 0)))
2141 (setq value-format (substring format (match-end 0)))
2142 (push (widget-create-child-and-convert
2143 widget 'item
2144 :format tag-format
2145 :action 'custom-tag-action
2146 :help-echo "Change value of this option."
2147 :mouse-down-action 'custom-tag-mouse-down-action
2148 :button-face 'custom-variable-button-face
2149 :sample-face 'custom-variable-tag-face
2150 tag)
2151 buttons)
2152 (insert " ")
2153 (push (widget-create-child-and-convert
2154 widget 'visibility
2155 :help-echo "Hide the value of this option."
2156 :action 'custom-toggle-parent
2158 buttons)
2159 (push (widget-create-child-and-convert
2160 widget type
2161 :format value-format
2162 :value value)
2163 children))))
2164 (unless (eq custom-buffer-style 'tree)
2165 (unless (eq (preceding-char) ?\n)
2166 (widget-insert "\n"))
2167 ;; Create the magic button.
2168 (let ((magic (widget-create-child-and-convert
2169 widget 'custom-magic nil)))
2170 (widget-put widget :custom-magic magic)
2171 (push magic buttons))
2172 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2173 ;; before the call to `widget-default-format-handler'. Otherwise, I
2174 ;; loose my current `buttons'. This function shouldn't be called like
2175 ;; this anyway. The doc string widget should be added like the others.
2176 ;; --dv
2177 (widget-put widget :buttons buttons)
2178 ;; Insert documentation.
2179 (widget-default-format-handler widget ?h)
2181 ;; The comment field
2182 (unless (eq state 'hidden)
2183 (let* ((comment (get symbol 'variable-comment))
2184 (comment-widget
2185 (widget-create-child-and-convert
2186 widget 'custom-comment
2187 :parent widget
2188 :value (or comment ""))))
2189 (widget-put widget :comment-widget comment-widget)
2190 ;; Don't push it !!! Custom assumes that the first child is the
2191 ;; value one.
2192 (setq children (append children (list comment-widget)))))
2193 ;; Update the rest of the properties properties.
2194 (widget-put widget :custom-form form)
2195 (widget-put widget :children children)
2196 ;; Now update the state.
2197 (if (eq state 'hidden)
2198 (widget-put widget :custom-state state)
2199 (custom-variable-state-set widget))
2200 ;; See also.
2201 (unless (eq state 'hidden)
2202 (when (eq (widget-get widget :custom-level) 1)
2203 (custom-add-parent-links widget))
2204 (custom-add-see-also widget)))))
2206 (defun custom-tag-action (widget &rest args)
2207 "Pass :action to first child of WIDGET's parent."
2208 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2209 :action args))
2211 (defun custom-tag-mouse-down-action (widget &rest args)
2212 "Pass :mouse-down-action to first child of WIDGET's parent."
2213 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2214 :mouse-down-action args))
2216 (defun custom-variable-state-set (widget)
2217 "Set the state of WIDGET."
2218 (let* ((symbol (widget-value widget))
2219 (get (or (get symbol 'custom-get) 'default-value))
2220 (value (if (default-boundp symbol)
2221 (funcall get symbol)
2222 (widget-get widget :value)))
2223 (comment (get symbol 'variable-comment))
2225 temp
2226 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2227 (setq temp
2228 (get symbol 'customized-variable-comment))
2229 (or tmp temp))
2230 (if (condition-case nil
2231 (and (equal value (eval (car tmp)))
2232 (equal comment temp))
2233 (error nil))
2234 'set
2235 'changed))
2236 ((progn (setq tmp (get symbol 'saved-value))
2237 (setq temp (get symbol 'saved-variable-comment))
2238 (or tmp temp))
2239 (if (condition-case nil
2240 (and (equal value (eval (car tmp)))
2241 (equal comment temp))
2242 (error nil))
2243 'saved
2244 'changed))
2245 ((setq tmp (get symbol 'standard-value))
2246 (if (condition-case nil
2247 (and (equal value (eval (car tmp)))
2248 (equal comment nil))
2249 (error nil))
2250 'standard
2251 'changed))
2252 (t 'rogue))))
2253 (widget-put widget :custom-state state)))
2255 (defvar custom-variable-menu
2256 '(("Set for Current Session" custom-variable-set
2257 (lambda (widget)
2258 (eq (widget-get widget :custom-state) 'modified)))
2259 ("Save for Future Sessions" custom-variable-save
2260 (lambda (widget)
2261 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2262 ("Reset to Current" custom-redraw
2263 (lambda (widget)
2264 (and (default-boundp (widget-value widget))
2265 (memq (widget-get widget :custom-state) '(modified changed)))))
2266 ("Reset to Saved" custom-variable-reset-saved
2267 (lambda (widget)
2268 (and (or (get (widget-value widget) 'saved-value)
2269 (get (widget-value widget) 'saved-variable-comment))
2270 (memq (widget-get widget :custom-state)
2271 '(modified set changed rogue)))))
2272 ("Erase Customization" custom-variable-reset-standard
2273 (lambda (widget)
2274 (and (get (widget-value widget) 'standard-value)
2275 (memq (widget-get widget :custom-state)
2276 '(modified set changed saved rogue)))))
2277 ("---" ignore ignore)
2278 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2279 ("---" ignore ignore)
2280 ("Don't show as Lisp expression" custom-variable-edit
2281 (lambda (widget)
2282 (eq (widget-get widget :custom-form) 'lisp)))
2283 ("Show initial Lisp expression" custom-variable-edit-lisp
2284 (lambda (widget)
2285 (eq (widget-get widget :custom-form) 'edit))))
2286 "Alist of actions for the `custom-variable' widget.
2287 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2288 the menu entry, ACTION is the function to call on the widget when the
2289 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2290 widget as an argument, and returns non-nil if ACTION is valid on that
2291 widget. If FILTER is nil, ACTION is always valid.")
2293 (defun custom-variable-action (widget &optional event)
2294 "Show the menu for `custom-variable' WIDGET.
2295 Optional EVENT is the location for the menu."
2296 (if (eq (widget-get widget :custom-state) 'hidden)
2297 (custom-toggle-hide widget)
2298 (unless (eq (widget-get widget :custom-state) 'modified)
2299 (custom-variable-state-set widget))
2300 (custom-redraw-magic widget)
2301 (let* ((completion-ignore-case t)
2302 (answer (widget-choose (concat "Operation on "
2303 (custom-unlispify-tag-name
2304 (widget-get widget :value)))
2305 (custom-menu-filter custom-variable-menu
2306 widget)
2307 event)))
2308 (if answer
2309 (funcall answer widget)))))
2311 (defun custom-variable-edit (widget)
2312 "Edit value of WIDGET."
2313 (widget-put widget :custom-state 'unknown)
2314 (widget-put widget :custom-form 'edit)
2315 (custom-redraw widget))
2317 (defun custom-variable-edit-lisp (widget)
2318 "Edit the Lisp representation of the value of WIDGET."
2319 (widget-put widget :custom-state 'unknown)
2320 (widget-put widget :custom-form 'lisp)
2321 (custom-redraw widget))
2323 (defun custom-variable-set (widget)
2324 "Set the current value for the variable being edited by WIDGET."
2325 (let* ((form (widget-get widget :custom-form))
2326 (state (widget-get widget :custom-state))
2327 (child (car (widget-get widget :children)))
2328 (symbol (widget-value widget))
2329 (set (or (get symbol 'custom-set) 'set-default))
2330 (comment-widget (widget-get widget :comment-widget))
2331 (comment (widget-value comment-widget))
2332 val)
2333 (cond ((eq state 'hidden)
2334 (error "Cannot set hidden variable"))
2335 ((setq val (widget-apply child :validate))
2336 (goto-char (widget-get val :from))
2337 (error "%s" (widget-get val :error)))
2338 ((memq form '(lisp mismatch))
2339 (when (equal comment "")
2340 (setq comment nil)
2341 ;; Make the comment invisible by hand if it's empty
2342 (custom-comment-hide comment-widget))
2343 (funcall set symbol (eval (setq val (widget-value child))))
2344 (put symbol 'customized-value (list val))
2345 (put symbol 'variable-comment comment)
2346 (put symbol 'customized-variable-comment comment))
2348 (when (equal comment "")
2349 (setq comment nil)
2350 ;; Make the comment invisible by hand if it's empty
2351 (custom-comment-hide comment-widget))
2352 (funcall set symbol (setq val (widget-value child)))
2353 (put symbol 'customized-value (list (custom-quote val)))
2354 (put symbol 'variable-comment comment)
2355 (put symbol 'customized-variable-comment comment)))
2356 (custom-variable-state-set widget)
2357 (custom-redraw-magic widget)))
2359 (defun custom-variable-save (widget)
2360 "Set and save the value for the variable being edited by WIDGET."
2361 (let* ((form (widget-get widget :custom-form))
2362 (state (widget-get widget :custom-state))
2363 (child (car (widget-get widget :children)))
2364 (symbol (widget-value widget))
2365 (set (or (get symbol 'custom-set) 'set-default))
2366 (comment-widget (widget-get widget :comment-widget))
2367 (comment (widget-value comment-widget))
2368 val)
2369 (cond ((eq state 'hidden)
2370 (error "Cannot set hidden variable"))
2371 ((setq val (widget-apply child :validate))
2372 (goto-char (widget-get val :from))
2373 (error "%s" (widget-get val :error)))
2374 ((memq form '(lisp mismatch))
2375 (when (equal comment "")
2376 (setq comment nil)
2377 ;; Make the comment invisible by hand if it's empty
2378 (custom-comment-hide comment-widget))
2379 (put symbol 'saved-value (list (widget-value child)))
2380 (funcall set symbol (eval (widget-value child)))
2381 (put symbol 'variable-comment comment)
2382 (put symbol 'saved-variable-comment comment))
2384 (when (equal comment "")
2385 (setq comment nil)
2386 ;; Make the comment invisible by hand if it's empty
2387 (custom-comment-hide comment-widget))
2388 (put symbol 'saved-value
2389 (list (custom-quote (widget-value child))))
2390 (funcall set symbol (widget-value child))
2391 (put symbol 'variable-comment comment)
2392 (put symbol 'saved-variable-comment comment)))
2393 (put symbol 'customized-value nil)
2394 (put symbol 'customized-variable-comment nil)
2395 (custom-save-all)
2396 (custom-variable-state-set widget)
2397 (custom-redraw-magic widget)))
2399 (defun custom-variable-reset-saved (widget)
2400 "Restore the saved value for the variable being edited by WIDGET."
2401 (let* ((symbol (widget-value widget))
2402 (set (or (get symbol 'custom-set) 'set-default))
2403 (comment-widget (widget-get widget :comment-widget))
2404 (value (get symbol 'saved-value))
2405 (comment (get symbol 'saved-variable-comment)))
2406 (cond ((or value comment)
2407 (put symbol 'variable-comment comment)
2408 (condition-case nil
2409 (funcall set symbol (eval (car value)))
2410 (error nil)))
2412 (error "No saved value for %s" symbol)))
2413 (put symbol 'customized-value nil)
2414 (put symbol 'customized-variable-comment nil)
2415 (widget-put widget :custom-state 'unknown)
2416 ;; This call will possibly make the comment invisible
2417 (custom-redraw widget)))
2419 (defun custom-variable-reset-standard (widget)
2420 "Restore the standard setting for the variable being edited by WIDGET.
2421 This operation eliminates any saved setting for the variable,
2422 restoring it to the state of a variable that has never been customized."
2423 (let* ((symbol (widget-value widget))
2424 (set (or (get symbol 'custom-set) 'set-default))
2425 (comment-widget (widget-get widget :comment-widget)))
2426 (if (get symbol 'standard-value)
2427 (funcall set symbol (eval (car (get symbol 'standard-value))))
2428 (error "No standard setting known for %S" symbol))
2429 (put symbol 'variable-comment nil)
2430 (put symbol 'customized-value nil)
2431 (put symbol 'customized-variable-comment nil)
2432 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2433 (put symbol 'saved-value nil)
2434 (put symbol 'saved-variable-comment nil)
2435 (custom-save-all))
2436 (widget-put widget :custom-state 'unknown)
2437 ;; This call will possibly make the comment invisible
2438 (custom-redraw widget)))
2440 ;;; The `custom-face-edit' Widget.
2442 (define-widget 'custom-face-edit 'checklist
2443 "Edit face attributes."
2444 :format "%t: %v"
2445 :tag "Attributes"
2446 :extra-offset 12
2447 :button-args '(:help-echo "Control whether this attribute has any effect.")
2448 :args (mapcar (lambda (att)
2449 (list 'group
2450 :inline t
2451 :sibling-args (widget-get (nth 1 att) :sibling-args)
2452 (list 'const :format "" :value (nth 0 att))
2453 (nth 1 att)))
2454 custom-face-attributes))
2456 ;;; The `custom-display' Widget.
2458 (define-widget 'custom-display 'menu-choice
2459 "Select a display type."
2460 :tag "Display"
2461 :value t
2462 :help-echo "Specify frames where the face attributes should be used."
2463 :args '((const :tag "all" t)
2464 (checklist
2465 :offset 0
2466 :extra-offset 9
2467 :args ((group :sibling-args (:help-echo "\
2468 Only match the specified window systems.")
2469 (const :format "Type: "
2470 type)
2471 (checklist :inline t
2472 :offset 0
2473 (const :format "X "
2474 :sibling-args (:help-echo "\
2475 The X11 Window System.")
2477 (const :format "PM "
2478 :sibling-args (:help-echo "\
2479 OS/2 Presentation Manager.")
2481 (const :format "W32 "
2482 :sibling-args (:help-echo "\
2483 Windows NT/9X.")
2484 w32)
2485 (const :format "DOS "
2486 :sibling-args (:help-echo "\
2487 Plain MS-DOS.")
2489 (const :format "TTY%n"
2490 :sibling-args (:help-echo "\
2491 Plain text terminals.")
2492 tty)))
2493 (group :sibling-args (:help-echo "\
2494 Only match the frames with the specified color support.")
2495 (const :format "Class: "
2496 class)
2497 (checklist :inline t
2498 :offset 0
2499 (const :format "Color "
2500 :sibling-args (:help-echo "\
2501 Match color frames.")
2502 color)
2503 (const :format "Grayscale "
2504 :sibling-args (:help-echo "\
2505 Match grayscale frames.")
2506 grayscale)
2507 (const :format "Monochrome%n"
2508 :sibling-args (:help-echo "\
2509 Match frames with no color support.")
2510 mono)))
2511 (group :sibling-args (:help-echo "\
2512 Only match frames with the specified intensity.")
2513 (const :format "\
2514 Background brightness: "
2515 background)
2516 (checklist :inline t
2517 :offset 0
2518 (const :format "Light "
2519 :sibling-args (:help-echo "\
2520 Match frames with light backgrounds.")
2521 light)
2522 (const :format "Dark\n"
2523 :sibling-args (:help-echo "\
2524 Match frames with dark backgrounds.")
2525 dark)))))))
2527 ;;; The `custom-face' Widget.
2529 (defface custom-face-tag-face
2530 `((t (:bold t :family "helv"
2531 :height ,(let ((height (face-attribute 'default :height)))
2532 (if (numberp height)
2533 (floor height 0.9)
2534 height)))))
2535 "Face used for face tags."
2536 :group 'custom-faces)
2538 (defcustom custom-face-default-form 'selected
2539 "Default form of displaying face definition."
2540 :type '(choice (const all)
2541 (const selected)
2542 (const lisp))
2543 :group 'custom-buffer
2544 :version "20.3")
2546 (define-widget 'custom-face 'custom
2547 "Customize face."
2548 :sample-face 'custom-face-tag-face
2549 :help-echo "Set or reset this face."
2550 :documentation-property '(lambda (face)
2551 (face-doc-string face))
2552 :value-create 'custom-face-value-create
2553 :action 'custom-face-action
2554 :custom-category 'face
2555 :custom-form nil ; defaults to value of `custom-face-default-form'
2556 :custom-set 'custom-face-set
2557 :custom-save 'custom-face-save
2558 :custom-reset-current 'custom-redraw
2559 :custom-reset-saved 'custom-face-reset-saved
2560 :custom-reset-standard 'custom-face-reset-standard
2561 :custom-menu 'custom-face-menu-create)
2563 (define-widget 'custom-face-all 'editable-list
2564 "An editable list of display specifications and attributes."
2565 :entry-format "%i %d %v"
2566 :insert-button-args '(:help-echo "Insert new display specification here.")
2567 :append-button-args '(:help-echo "Append new display specification here.")
2568 :delete-button-args '(:help-echo "Delete this display specification.")
2569 :args '((group :format "%v" custom-display custom-face-edit)))
2571 (defconst custom-face-all (widget-convert 'custom-face-all)
2572 "Converted version of the `custom-face-all' widget.")
2574 (define-widget 'custom-display-unselected 'item
2575 "A display specification that doesn't match the selected display."
2576 :match 'custom-display-unselected-match)
2578 (defun custom-display-unselected-match (widget value)
2579 "Non-nil if VALUE is an unselected display specification."
2580 (not (face-spec-set-match-display value (selected-frame))))
2582 (define-widget 'custom-face-selected 'group
2583 "Edit the attributes of the selected display in a face specification."
2584 :args '((repeat :format ""
2585 :inline t
2586 (group custom-display-unselected sexp))
2587 (group (sexp :format "") custom-face-edit)
2588 (repeat :format ""
2589 :inline t
2590 sexp)))
2592 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2593 "Converted version of the `custom-face-selected' widget.")
2595 (defun custom-face-value-create (widget)
2596 "Create a list of the display specifications for WIDGET."
2597 (let ((buttons (widget-get widget :buttons))
2598 children
2599 (symbol (widget-get widget :value))
2600 (tag (widget-get widget :tag))
2601 (state (widget-get widget :custom-state))
2602 (begin (point))
2603 (is-last (widget-get widget :custom-last))
2604 (prefix (widget-get widget :custom-prefix)))
2605 (unless tag
2606 (setq tag (prin1-to-string symbol)))
2607 (cond ((eq custom-buffer-style 'tree)
2608 (insert prefix (if is-last " `--- " " |--- "))
2609 (push (widget-create-child-and-convert
2610 widget 'custom-browse-face-tag)
2611 buttons)
2612 (insert " " tag "\n")
2613 (widget-put widget :buttons buttons))
2615 ;; Create tag.
2616 (insert tag)
2617 (if (eq custom-buffer-style 'face)
2618 (insert " ")
2619 (widget-specify-sample widget begin (point))
2620 (insert ": "))
2621 ;; Sample.
2622 (push (widget-create-child-and-convert widget 'item
2623 :format "(%{%t%})"
2624 :sample-face symbol
2625 :tag "sample")
2626 buttons)
2627 ;; Visibility.
2628 (insert " ")
2629 (push (widget-create-child-and-convert
2630 widget 'visibility
2631 :help-echo "Hide or show this face."
2632 :action 'custom-toggle-parent
2633 (not (eq state 'hidden)))
2634 buttons)
2635 ;; Magic.
2636 (insert "\n")
2637 (let ((magic (widget-create-child-and-convert
2638 widget 'custom-magic nil)))
2639 (widget-put widget :custom-magic magic)
2640 (push magic buttons))
2641 ;; Update buttons.
2642 (widget-put widget :buttons buttons)
2643 ;; Insert documentation.
2644 (widget-default-format-handler widget ?h)
2645 ;; The comment field
2646 (unless (eq state 'hidden)
2647 (let* ((comment (get symbol 'face-comment))
2648 (comment-widget
2649 (widget-create-child-and-convert
2650 widget 'custom-comment
2651 :parent widget
2652 :value (or comment ""))))
2653 (widget-put widget :comment-widget comment-widget)
2654 (push comment-widget children)))
2655 ;; See also.
2656 (unless (eq state 'hidden)
2657 (when (eq (widget-get widget :custom-level) 1)
2658 (custom-add-parent-links widget))
2659 (custom-add-see-also widget))
2660 ;; Editor.
2661 (unless (eq (preceding-char) ?\n)
2662 (insert "\n"))
2663 (unless (eq state 'hidden)
2664 (message "Creating face editor...")
2665 (custom-load-widget widget)
2666 (unless (widget-get widget :custom-form)
2667 (widget-put widget :custom-form custom-face-default-form))
2668 (let* ((symbol (widget-value widget))
2669 (spec (or (get symbol 'saved-face)
2670 (get symbol 'face-defface-spec)
2671 ;; Attempt to construct it.
2672 (list (list t (custom-face-attributes-get
2673 symbol (selected-frame))))))
2674 (form (widget-get widget :custom-form))
2675 (indent (widget-get widget :indent))
2676 edit)
2677 ;; If the user has changed this face in some other way,
2678 ;; edit it as the user has specified it.
2679 (if (not (face-spec-match-p symbol spec (selected-frame)))
2680 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
2681 (setq edit (widget-create-child-and-convert
2682 widget
2683 (cond ((and (eq form 'selected)
2684 (widget-apply custom-face-selected
2685 :match spec))
2686 (when indent (insert-char ?\ indent))
2687 'custom-face-selected)
2688 ((and (not (eq form 'lisp))
2689 (widget-apply custom-face-all
2690 :match spec))
2691 'custom-face-all)
2693 (when indent (insert-char ?\ indent))
2694 'sexp))
2695 :value spec))
2696 (custom-face-state-set widget)
2697 (push edit children)
2698 (widget-put widget :children children))
2699 (message "Creating face editor...done"))))))
2701 (defvar custom-face-menu
2702 '(("Set for Current Session" custom-face-set)
2703 ("Save for Future Sessions" custom-face-save-command)
2704 ("Reset to Saved" custom-face-reset-saved
2705 (lambda (widget)
2706 (or (get (widget-value widget) 'saved-face)
2707 (get (widget-value widget) 'saved-face-comment))))
2708 ("Erase Customization" custom-face-reset-standard
2709 (lambda (widget)
2710 (get (widget-value widget) 'face-defface-spec)))
2711 ("---" ignore ignore)
2712 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2713 ("---" ignore ignore)
2714 ("Show all display specs" custom-face-edit-all
2715 (lambda (widget)
2716 (not (eq (widget-get widget :custom-form) 'all))))
2717 ("Just current attributes" custom-face-edit-selected
2718 (lambda (widget)
2719 (not (eq (widget-get widget :custom-form) 'selected))))
2720 ("Show as Lisp expression" custom-face-edit-lisp
2721 (lambda (widget)
2722 (not (eq (widget-get widget :custom-form) 'lisp)))))
2723 "Alist of actions for the `custom-face' widget.
2724 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2725 the menu entry, ACTION is the function to call on the widget when the
2726 menu is selected, and FILTER is a predicate which takes a `custom-face'
2727 widget as an argument, and returns non-nil if ACTION is valid on that
2728 widget. If FILTER is nil, ACTION is always valid.")
2730 (defun custom-face-edit-selected (widget)
2731 "Edit selected attributes of the value of WIDGET."
2732 (widget-put widget :custom-state 'unknown)
2733 (widget-put widget :custom-form 'selected)
2734 (custom-redraw widget))
2736 (defun custom-face-edit-all (widget)
2737 "Edit all attributes of the value of WIDGET."
2738 (widget-put widget :custom-state 'unknown)
2739 (widget-put widget :custom-form 'all)
2740 (custom-redraw widget))
2742 (defun custom-face-edit-lisp (widget)
2743 "Edit the Lisp representation of the value of WIDGET."
2744 (widget-put widget :custom-state 'unknown)
2745 (widget-put widget :custom-form 'lisp)
2746 (custom-redraw widget))
2748 (defun custom-face-state-set (widget)
2749 "Set the state of WIDGET."
2750 (let* ((symbol (widget-value widget))
2751 (comment (get symbol 'face-comment))
2752 tmp temp)
2753 (widget-put widget :custom-state
2754 (cond ((progn
2755 (setq tmp (get symbol 'customized-face))
2756 (setq temp (get symbol 'customized-face-comment))
2757 (or tmp temp))
2758 (if (equal temp comment)
2759 'set
2760 'changed))
2761 ((progn
2762 (setq tmp (get symbol 'saved-face))
2763 (setq temp (get symbol 'saved-face-comment))
2764 (or tmp temp))
2765 (if (equal temp comment)
2766 'saved
2767 'changed))
2768 ((get symbol 'face-defface-spec)
2769 (if (equal comment nil)
2770 'standard
2771 'changed))
2773 'rogue)))))
2775 (defun custom-face-action (widget &optional event)
2776 "Show the menu for `custom-face' WIDGET.
2777 Optional EVENT is the location for the menu."
2778 (if (eq (widget-get widget :custom-state) 'hidden)
2779 (custom-toggle-hide widget)
2780 (let* ((completion-ignore-case t)
2781 (symbol (widget-get widget :value))
2782 (answer (widget-choose (concat "Operation on "
2783 (custom-unlispify-tag-name symbol))
2784 (custom-menu-filter custom-face-menu
2785 widget)
2786 event)))
2787 (if answer
2788 (funcall answer widget)))))
2790 (defun custom-face-set (widget)
2791 "Make the face attributes in WIDGET take effect."
2792 (let* ((symbol (widget-value widget))
2793 (child (car (widget-get widget :children)))
2794 (value (widget-value child))
2795 (comment-widget (widget-get widget :comment-widget))
2796 (comment (widget-value comment-widget)))
2797 (when (equal comment "")
2798 (setq comment nil)
2799 ;; Make the comment invisible by hand if it's empty
2800 (custom-comment-hide comment-widget))
2801 (put symbol 'customized-face value)
2802 (face-spec-set symbol value)
2803 (put symbol 'customized-face-comment comment)
2804 (put symbol 'face-comment comment)
2805 (custom-face-state-set widget)
2806 (custom-redraw-magic widget)))
2808 (defun custom-face-save-command (widget)
2809 "Save in `.emacs' the face attributes in WIDGET."
2810 (custom-face-save widget)
2811 (custom-save-all))
2813 (defun custom-face-save (widget)
2814 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2815 (let* ((symbol (widget-value widget))
2816 (child (car (widget-get widget :children)))
2817 (value (widget-value child))
2818 (comment-widget (widget-get widget :comment-widget))
2819 (comment (widget-value comment-widget)))
2820 (when (equal comment "")
2821 (setq comment nil)
2822 ;; Make the comment invisible by hand if it's empty
2823 (custom-comment-hide comment-widget))
2824 (face-spec-set symbol value)
2825 (put symbol 'saved-face value)
2826 (put symbol 'customized-face nil)
2827 (put symbol 'face-comment comment)
2828 (put symbol 'customized-face-comment nil)
2829 (put symbol 'saved-face-comment comment)
2830 (custom-save-all)
2831 (custom-face-state-set widget)
2832 (custom-redraw-magic widget)))
2834 (defun custom-face-reset-saved (widget)
2835 "Restore WIDGET to the face's default attributes."
2836 (let* ((symbol (widget-value widget))
2837 (child (car (widget-get widget :children)))
2838 (value (get symbol 'saved-face))
2839 (comment (get symbol 'saved-face-comment))
2840 (comment-widget (widget-get widget :comment-widget)))
2841 (unless (or value comment)
2842 (error "No saved value for this face"))
2843 (put symbol 'customized-face nil)
2844 (put symbol 'customized-face-comment nil)
2845 (face-spec-set symbol value)
2846 (put symbol 'face-comment comment)
2847 (widget-value-set child value)
2848 ;; This call manages the comment visibility
2849 (widget-value-set comment-widget (or comment ""))
2850 (custom-face-state-set widget)
2851 (custom-redraw-magic widget)))
2853 (defun custom-face-reset-standard (widget)
2854 "Restore WIDGET to the face's standard settings.
2855 This operation eliminates any saved setting for the face,
2856 restoring it to the state of a face that has never been customized."
2857 (let* ((symbol (widget-value widget))
2858 (child (car (widget-get widget :children)))
2859 (value (get symbol 'face-defface-spec))
2860 (comment-widget (widget-get widget :comment-widget)))
2861 (unless value
2862 (error "No standard setting for this face"))
2863 (put symbol 'customized-face nil)
2864 (put symbol 'customized-face-comment nil)
2865 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
2866 (put symbol 'saved-face nil)
2867 (put symbol 'saved-face-comment nil)
2868 (custom-save-all))
2869 (face-spec-set symbol value)
2870 (put symbol 'face-comment nil)
2871 (widget-value-set child value)
2872 ;; This call manages the comment visibility
2873 (widget-value-set comment-widget "")
2874 (custom-face-state-set widget)
2875 (custom-redraw-magic widget)))
2877 ;;; The `face' Widget.
2879 (define-widget 'face 'default
2880 "Select and customize a face."
2881 :convert-widget 'widget-value-convert-widget
2882 :button-prefix 'widget-push-button-prefix
2883 :button-suffix 'widget-push-button-suffix
2884 :format "%t: %[select face%] %v"
2885 :tag "Face"
2886 :value 'default
2887 :value-create 'widget-face-value-create
2888 :value-delete 'widget-face-value-delete
2889 :value-get 'widget-value-value-get
2890 :validate 'widget-children-validate
2891 :action 'widget-face-action
2892 :match '(lambda (widget value) (symbolp value)))
2894 (defun widget-face-value-create (widget)
2895 "Create a `custom-face' child."
2896 (let* ((symbol (widget-value widget))
2897 (custom-buffer-style 'face)
2898 (child (widget-create-child-and-convert
2899 widget 'custom-face
2900 :custom-level nil
2901 :value symbol)))
2902 (custom-magic-reset child)
2903 (setq custom-options (cons child custom-options))
2904 (widget-put widget :children (list child))))
2906 (defun widget-face-value-delete (widget)
2907 "Remove the child from the options."
2908 (let ((child (car (widget-get widget :children))))
2909 (setq custom-options (delq child custom-options))
2910 (widget-children-value-delete widget)))
2912 (defvar face-history nil
2913 "History of entered face names.")
2915 (defun widget-face-action (widget &optional event)
2916 "Prompt for a face."
2917 (let ((answer (completing-read "Face: "
2918 (mapcar (lambda (face)
2919 (list (symbol-name face)))
2920 (face-list))
2921 nil nil nil
2922 'face-history)))
2923 (unless (zerop (length answer))
2924 (widget-value-set widget (intern answer))
2925 (widget-apply widget :notify widget event)
2926 (widget-setup))))
2928 ;;; The `hook' Widget.
2930 (define-widget 'hook 'list
2931 "A emacs lisp hook"
2932 :value-to-internal (lambda (widget value)
2933 (if (and value (symbolp value))
2934 (list value)
2935 value))
2936 :match (lambda (widget value)
2937 (or (symbolp value)
2938 (widget-group-match widget value)))
2939 ;; Avoid adding undefined functions to the hook, especially for
2940 ;; things like `find-file-hook' or even more basic ones, to avoid
2941 ;; chaos.
2942 :set (lambda (symbol value)
2943 (dolist (elt value)
2944 (if (fboundp elt)
2945 (add-hook symbol elt))))
2946 :convert-widget 'custom-hook-convert-widget
2947 :tag "Hook")
2949 (defun custom-hook-convert-widget (widget)
2950 ;; Handle `:options'.
2951 (let* ((options (widget-get widget :options))
2952 (other `(editable-list :inline t
2953 :entry-format "%i %d%v"
2954 (function :format " %v")))
2955 (args (if options
2956 (list `(checklist :inline t
2957 ,@(mapcar (lambda (entry)
2958 `(function-item ,entry))
2959 options))
2960 other)
2961 (list other))))
2962 (widget-put widget :args args)
2963 widget))
2965 ;;; The `custom-group-link' Widget.
2967 (define-widget 'custom-group-link 'link
2968 "Show parent in other window when activated."
2969 :help-echo "Create customization buffer for this group."
2970 :action 'custom-group-link-action)
2972 (defun custom-group-link-action (widget &rest ignore)
2973 (customize-group (widget-value widget)))
2975 ;;; The `custom-group' Widget.
2977 (defcustom custom-group-tag-faces nil
2978 ;; In XEmacs, this ought to play games with font size.
2979 ;; Fixme: make it do so in Emacs.
2980 "Face used for group tags.
2981 The first member is used for level 1 groups, the second for level 2,
2982 and so forth. The remaining group tags are shown with
2983 `custom-group-tag-face'."
2984 :type '(repeat face)
2985 :group 'custom-faces)
2987 (defface custom-group-tag-face-1
2988 `((((class color)
2989 (background dark))
2990 (:foreground "pink" :family "helv"
2991 :height ,(let ((height (face-attribute 'default :height)))
2992 (if (numberp height)
2993 (floor height 0.9)
2994 height))
2995 :bold t))
2996 (((class color)
2997 (background light))
2998 (:foreground "red" :bold t
2999 :height ,(let ((height (face-attribute 'default :height)))
3000 (if (numberp height)
3001 (floor height 0.9)
3002 height))))
3003 (t (:bold t)))
3004 "Face used for group tags."
3005 :group 'custom-faces)
3007 (defface custom-group-tag-face
3008 `((((class color)
3009 (background dark))
3010 (:foreground "light blue" :bold t
3011 :height ,(let ((height (face-attribute 'default :height)))
3012 (if (numberp height)
3013 (floor height 0.9)
3014 height))))
3015 (((class color)
3016 (background light))
3017 (:foreground "blue" :bold t
3018 :height ,(let ((height (face-attribute 'default :height)))
3019 (if (numberp height)
3020 (floor height 0.9)
3021 height))))
3022 (t (:bold t)))
3023 "Face used for low level group tags."
3024 :group 'custom-faces)
3026 (define-widget 'custom-group 'custom
3027 "Customize group."
3028 :format "%v"
3029 :sample-face-get 'custom-group-sample-face-get
3030 :documentation-property 'group-documentation
3031 :help-echo "Set or reset all members of this group."
3032 :value-create 'custom-group-value-create
3033 :action 'custom-group-action
3034 :custom-category 'group
3035 :custom-set 'custom-group-set
3036 :custom-save 'custom-group-save
3037 :custom-reset-current 'custom-group-reset-current
3038 :custom-reset-saved 'custom-group-reset-saved
3039 :custom-reset-standard 'custom-group-reset-standard
3040 :custom-menu 'custom-group-menu-create)
3042 (defun custom-group-sample-face-get (widget)
3043 ;; Use :sample-face.
3044 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3045 'custom-group-tag-face))
3047 (define-widget 'custom-group-visibility 'visibility
3048 "An indicator and manipulator for hidden group contents."
3049 :create 'custom-group-visibility-create)
3051 (defun custom-group-visibility-create (widget)
3052 (let ((visible (widget-value widget)))
3053 (if visible
3054 (insert "--------")))
3055 (widget-default-create widget))
3057 (defun custom-group-members (symbol groups-only)
3058 "Return SYMBOL's custom group members.
3059 If GROUPS-ONLY non-nil, return only those members that are groups."
3060 (if (not groups-only)
3061 (get symbol 'custom-group)
3062 (let (members)
3063 (dolist (entry (get symbol 'custom-group))
3064 (when (eq (nth 1 entry) 'custom-group)
3065 (push entry members)))
3066 (nreverse members))))
3068 (defun custom-group-value-create (widget)
3069 "Insert a customize group for WIDGET in the current buffer."
3070 (let* ((state (widget-get widget :custom-state))
3071 (level (widget-get widget :custom-level))
3072 ;; (indent (widget-get widget :indent))
3073 (prefix (widget-get widget :custom-prefix))
3074 (buttons (widget-get widget :buttons))
3075 (tag (widget-get widget :tag))
3076 (symbol (widget-value widget))
3077 (members (custom-group-members symbol
3078 (and (eq custom-buffer-style 'tree)
3079 custom-browse-only-groups))))
3080 (cond ((and (eq custom-buffer-style 'tree)
3081 (eq state 'hidden)
3082 (or members (custom-unloaded-widget-p widget)))
3083 (custom-browse-insert-prefix prefix)
3084 (push (widget-create-child-and-convert
3085 widget 'custom-browse-visibility
3086 ;; :tag-glyph "plus"
3087 :tag "+")
3088 buttons)
3089 (insert "-- ")
3090 ;; (widget-glyph-insert nil "-- " "horizontal")
3091 (push (widget-create-child-and-convert
3092 widget 'custom-browse-group-tag)
3093 buttons)
3094 (insert " " tag "\n")
3095 (widget-put widget :buttons buttons))
3096 ((and (eq custom-buffer-style 'tree)
3097 (zerop (length members)))
3098 (custom-browse-insert-prefix prefix)
3099 (insert "[ ]-- ")
3100 ;; (widget-glyph-insert nil "[ ]" "empty")
3101 ;; (widget-glyph-insert nil "-- " "horizontal")
3102 (push (widget-create-child-and-convert
3103 widget 'custom-browse-group-tag)
3104 buttons)
3105 (insert " " tag "\n")
3106 (widget-put widget :buttons buttons))
3107 ((eq custom-buffer-style 'tree)
3108 (custom-browse-insert-prefix prefix)
3109 (custom-load-widget widget)
3110 (if (zerop (length members))
3111 (progn
3112 (custom-browse-insert-prefix prefix)
3113 (insert "[ ]-- ")
3114 ;; (widget-glyph-insert nil "[ ]" "empty")
3115 ;; (widget-glyph-insert nil "-- " "horizontal")
3116 (push (widget-create-child-and-convert
3117 widget 'custom-browse-group-tag)
3118 buttons)
3119 (insert " " tag "\n")
3120 (widget-put widget :buttons buttons))
3121 (push (widget-create-child-and-convert
3122 widget 'custom-browse-visibility
3123 ;; :tag-glyph "minus"
3124 :tag "-")
3125 buttons)
3126 (insert "-\\ ")
3127 ;; (widget-glyph-insert nil "-\\ " "top")
3128 (push (widget-create-child-and-convert
3129 widget 'custom-browse-group-tag)
3130 buttons)
3131 (insert " " tag "\n")
3132 (widget-put widget :buttons buttons)
3133 (message "Creating group...")
3134 (let* ((members (custom-sort-items members
3135 custom-browse-sort-alphabetically
3136 custom-browse-order-groups))
3137 (prefixes (widget-get widget :custom-prefixes))
3138 (custom-prefix-list (custom-prefix-add symbol prefixes))
3139 (extra-prefix (if (widget-get widget :custom-last)
3141 " | "))
3142 (prefix (concat prefix extra-prefix))
3143 children entry)
3144 (while members
3145 (setq entry (car members)
3146 members (cdr members))
3147 (push (widget-create-child-and-convert
3148 widget (nth 1 entry)
3149 :group widget
3150 :tag (custom-unlispify-tag-name (nth 0 entry))
3151 :custom-prefixes custom-prefix-list
3152 :custom-level (1+ level)
3153 :custom-last (null members)
3154 :value (nth 0 entry)
3155 :custom-prefix prefix)
3156 children))
3157 (widget-put widget :children (reverse children)))
3158 (message "Creating group...done")))
3159 ;; Nested style.
3160 ((eq state 'hidden)
3161 ;; Create level indicator.
3162 (unless (eq custom-buffer-style 'links)
3163 (insert-char ?\ (* custom-buffer-indent (1- level)))
3164 (insert "-- "))
3165 ;; Create tag.
3166 (let ((begin (point)))
3167 (insert tag)
3168 (widget-specify-sample widget begin (point)))
3169 (insert " group: ")
3170 ;; Create link/visibility indicator.
3171 (if (eq custom-buffer-style 'links)
3172 (push (widget-create-child-and-convert
3173 widget 'custom-group-link
3174 :tag "Go to Group"
3175 symbol)
3176 buttons)
3177 (push (widget-create-child-and-convert
3178 widget 'custom-group-visibility
3179 :help-echo "Show members of this group."
3180 :action 'custom-toggle-parent
3181 (not (eq state 'hidden)))
3182 buttons))
3183 (insert " \n")
3184 ;; Create magic button.
3185 (let ((magic (widget-create-child-and-convert
3186 widget 'custom-magic nil)))
3187 (widget-put widget :custom-magic magic)
3188 (push magic buttons))
3189 ;; Update buttons.
3190 (widget-put widget :buttons buttons)
3191 ;; Insert documentation.
3192 (if (and (eq custom-buffer-style 'links) (> level 1))
3193 (widget-put widget :documentation-indent 0))
3194 (widget-default-format-handler widget ?h))
3195 ;; Nested style.
3196 (t ;Visible.
3197 ;; Add parent groups references above the group.
3198 (if t ;;; This should test that the buffer
3199 ;;; was made to display a group.
3200 (when (eq level 1)
3201 (if (custom-add-parent-links widget
3202 "Go to parent group:")
3203 (insert "\n"))))
3204 ;; Create level indicator.
3205 (insert-char ?\ (* custom-buffer-indent (1- level)))
3206 (insert "/- ")
3207 ;; Create tag.
3208 (let ((start (point)))
3209 (insert tag)
3210 (widget-specify-sample widget start (point)))
3211 (insert " group: ")
3212 ;; Create visibility indicator.
3213 (unless (eq custom-buffer-style 'links)
3214 (insert "--------")
3215 (push (widget-create-child-and-convert
3216 widget 'visibility
3217 :help-echo "Hide members of this group."
3218 :action 'custom-toggle-parent
3219 (not (eq state 'hidden)))
3220 buttons)
3221 (insert " "))
3222 ;; Create more dashes.
3223 ;; Use 76 instead of 75 to compensate for the temporary "<"
3224 ;; added by `widget-insert'.
3225 (insert-char ?- (- 76 (current-column)
3226 (* custom-buffer-indent level)))
3227 (insert "\\\n")
3228 ;; Create magic button.
3229 (let ((magic (widget-create-child-and-convert
3230 widget 'custom-magic
3231 :indent 0
3232 nil)))
3233 (widget-put widget :custom-magic magic)
3234 (push magic buttons))
3235 ;; Update buttons.
3236 (widget-put widget :buttons buttons)
3237 ;; Insert documentation.
3238 (widget-default-format-handler widget ?h)
3239 ;; Parent groups.
3240 (if nil ;;; This should test that the buffer
3241 ;;; was not made to display a group.
3242 (when (eq level 1)
3243 (insert-char ?\ custom-buffer-indent)
3244 (custom-add-parent-links widget)))
3245 (custom-add-see-also widget
3246 (make-string (* custom-buffer-indent level)
3247 ?\ ))
3248 ;; Members.
3249 (message "Creating group...")
3250 (custom-load-widget widget)
3251 (let* ((members (custom-sort-items members
3252 custom-buffer-sort-alphabetically
3253 custom-buffer-order-groups))
3254 (prefixes (widget-get widget :custom-prefixes))
3255 (custom-prefix-list (custom-prefix-add symbol prefixes))
3256 (length (length members))
3257 (count 0)
3258 (children (mapcar (lambda (entry)
3259 (widget-insert "\n")
3260 (message "\
3261 Creating group members... %2d%%"
3262 (/ (* 100.0 count) length))
3263 (setq count (1+ count))
3264 (prog1
3265 (widget-create-child-and-convert
3266 widget (nth 1 entry)
3267 :group widget
3268 :tag (custom-unlispify-tag-name
3269 (nth 0 entry))
3270 :custom-prefixes custom-prefix-list
3271 :custom-level (1+ level)
3272 :value (nth 0 entry))
3273 (unless (eq (preceding-char) ?\n)
3274 (widget-insert "\n"))))
3275 members)))
3276 (message "Creating group magic...")
3277 (mapcar 'custom-magic-reset children)
3278 (message "Creating group state...")
3279 (widget-put widget :children children)
3280 (custom-group-state-update widget)
3281 (message "Creating group... done"))
3282 ;; End line
3283 (insert "\n")
3284 (insert-char ?\ (* custom-buffer-indent (1- level)))
3285 (insert "\\- " (widget-get widget :tag) " group end ")
3286 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3287 (insert "/\n")))))
3289 (defvar custom-group-menu
3290 '(("Set for Current Session" custom-group-set
3291 (lambda (widget)
3292 (eq (widget-get widget :custom-state) 'modified)))
3293 ("Save for Future Sessions" custom-group-save
3294 (lambda (widget)
3295 (memq (widget-get widget :custom-state) '(modified set))))
3296 ("Reset to Current" custom-group-reset-current
3297 (lambda (widget)
3298 (memq (widget-get widget :custom-state) '(modified))))
3299 ("Reset to Saved" custom-group-reset-saved
3300 (lambda (widget)
3301 (memq (widget-get widget :custom-state) '(modified set))))
3302 ("Reset to standard setting" custom-group-reset-standard
3303 (lambda (widget)
3304 (memq (widget-get widget :custom-state) '(modified set saved)))))
3305 "Alist of actions for the `custom-group' widget.
3306 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3307 the menu entry, ACTION is the function to call on the widget when the
3308 menu is selected, and FILTER is a predicate which takes a `custom-group'
3309 widget as an argument, and returns non-nil if ACTION is valid on that
3310 widget. If FILTER is nil, ACTION is always valid.")
3312 (defun custom-group-action (widget &optional event)
3313 "Show the menu for `custom-group' WIDGET.
3314 Optional EVENT is the location for the menu."
3315 (if (eq (widget-get widget :custom-state) 'hidden)
3316 (custom-toggle-hide widget)
3317 (let* ((completion-ignore-case t)
3318 (answer (widget-choose (concat "Operation on "
3319 (custom-unlispify-tag-name
3320 (widget-get widget :value)))
3321 (custom-menu-filter custom-group-menu
3322 widget)
3323 event)))
3324 (if answer
3325 (funcall answer widget)))))
3327 (defun custom-group-set (widget)
3328 "Set changes in all modified group members."
3329 (let ((children (widget-get widget :children)))
3330 (mapcar (lambda (child)
3331 (when (eq (widget-get child :custom-state) 'modified)
3332 (widget-apply child :custom-set)))
3333 children )))
3335 (defun custom-group-save (widget)
3336 "Save all modified group members."
3337 (let ((children (widget-get widget :children)))
3338 (mapcar (lambda (child)
3339 (when (memq (widget-get child :custom-state) '(modified set))
3340 (widget-apply child :custom-save)))
3341 children )))
3343 (defun custom-group-reset-current (widget)
3344 "Reset all modified group members."
3345 (let ((children (widget-get widget :children)))
3346 (mapcar (lambda (child)
3347 (when (eq (widget-get child :custom-state) 'modified)
3348 (widget-apply child :custom-reset-current)))
3349 children )))
3351 (defun custom-group-reset-saved (widget)
3352 "Reset all modified or set group members."
3353 (let ((children (widget-get widget :children)))
3354 (mapcar (lambda (child)
3355 (when (memq (widget-get child :custom-state) '(modified set))
3356 (widget-apply child :custom-reset-saved)))
3357 children )))
3359 (defun custom-group-reset-standard (widget)
3360 "Reset all modified, set, or saved group members."
3361 (let ((children (widget-get widget :children)))
3362 (mapcar (lambda (child)
3363 (when (memq (widget-get child :custom-state)
3364 '(modified set saved))
3365 (widget-apply child :custom-reset-standard)))
3366 children )))
3368 (defun custom-group-state-update (widget)
3369 "Update magic."
3370 (unless (eq (widget-get widget :custom-state) 'hidden)
3371 (let* ((children (widget-get widget :children))
3372 (states (mapcar (lambda (child)
3373 (widget-get child :custom-state))
3374 children))
3375 (magics custom-magic-alist)
3376 (found 'standard))
3377 (while magics
3378 (let ((magic (car (car magics))))
3379 (if (and (not (eq magic 'hidden))
3380 (memq magic states))
3381 (setq found magic
3382 magics nil)
3383 (setq magics (cdr magics)))))
3384 (widget-put widget :custom-state found)))
3385 (custom-magic-reset widget))
3387 ;;; The `custom-save-all' Function.
3388 ;;;###autoload
3389 (defcustom custom-file nil
3390 "File used for storing customization information.
3391 The default is nil, which means to use your init file
3392 as specified by `user-init-file'. If you specify some other file,
3393 you need to explicitly load that file for the settings to take effect.
3395 When you change this variable, look in the previous custom file
3396 \(usually your init file) for the forms `(custom-set-variables ...)'
3397 and `(custom-set-faces ...)', and copy them (whichever ones you find)
3398 to the new custom file. This will preserve your existing customizations."
3399 :type '(choice (const :tag "Your Emacs init file" nil) file)
3400 :group 'customize)
3402 (defun custom-file ()
3403 "Return the file name for saving customizations."
3404 (setq custom-file
3405 (or custom-file
3406 user-init-file
3407 (read-file-name "File for customizations: "
3408 "~/" nil nil ".emacs"))))
3410 (defun custom-save-delete (symbol)
3411 "Visit `custom-file' and delete all calls to SYMBOL from it.
3412 Leave point at the old location of the first such call,
3413 or (if there were none) at the end of the buffer."
3414 (let ((default-major-mode))
3415 (set-buffer (find-file-noselect (custom-file))))
3416 (goto-char (point-min))
3417 ;; Skip all whitespace and comments.
3418 (while (forward-comment 1))
3419 (or (eobp)
3420 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3421 (let (first)
3422 (catch 'found
3423 (while t ;; We exit this loop only via throw.
3424 ;; Skip all whitespace and comments.
3425 (while (forward-comment 1))
3426 (let ((start (point))
3427 (sexp (condition-case nil
3428 (read (current-buffer))
3429 (end-of-file (throw 'found nil)))))
3430 (when (and (listp sexp)
3431 (eq (car sexp) symbol))
3432 (delete-region start (point))
3433 (unless first
3434 (setq first (point)))))))
3435 (if first
3436 (goto-char first)
3437 (goto-char (point-max)))))
3439 (defun custom-save-variables ()
3440 "Save all customized variables in `custom-file'."
3441 (save-excursion
3442 (custom-save-delete 'custom-set-variables)
3443 (let ((standard-output (current-buffer))
3444 (saved-list (make-list 1 0))
3445 sort-fold-case)
3446 ;; First create a sorted list of saved variables.
3447 (mapatoms
3448 (lambda (symbol)
3449 (if (get symbol 'saved-value)
3450 (nconc saved-list (list symbol)))))
3451 (setq saved-list (sort (cdr saved-list) 'string<))
3452 (unless (bolp)
3453 (princ "\n"))
3454 (princ "(custom-set-variables
3455 ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
3456 ;; Your init file must only contain one such instance.\n")
3457 (mapcar
3458 (lambda (symbol)
3459 (let ((value (get symbol 'saved-value))
3460 (requests (get symbol 'custom-requests))
3461 (now (not (or (get symbol 'standard-value)
3462 (and (not (boundp symbol))
3463 (not (get symbol 'force-value))))))
3464 (comment (get symbol 'saved-variable-comment))
3465 sep)
3466 (when (or value comment)
3467 (unless (bolp)
3468 (princ "\n"))
3469 (princ " '(")
3470 (prin1 symbol)
3471 (princ " ")
3472 (prin1 (car value))
3473 (cond ((or now requests comment)
3474 (princ " ")
3475 (if now
3476 (princ "t")
3477 (princ "nil"))
3478 (cond ((or requests comment)
3479 (princ " ")
3480 (if requests
3481 (prin1 requests)
3482 (princ "nil"))
3483 (cond (comment
3484 (princ " ")
3485 (prin1 comment)
3486 (princ ")"))
3488 (princ ")"))))
3490 (princ ")"))))
3492 (princ ")"))))))
3493 saved-list)
3494 (if (bolp)
3495 (princ " "))
3496 (princ ")")
3497 (unless (looking-at "\n")
3498 (princ "\n")))))
3500 (defun custom-save-faces ()
3501 "Save all customized faces in `custom-file'."
3502 (save-excursion
3503 (custom-save-delete 'custom-set-faces)
3504 (let ((standard-output (current-buffer))
3505 (saved-list (make-list 1 0))
3506 sort-fold-case)
3507 ;; First create a sorted list of saved faces.
3508 (mapatoms
3509 (lambda (symbol)
3510 (if (get symbol 'saved-face)
3511 (nconc saved-list (list symbol)))))
3512 (setq saved-list (sort (cdr saved-list) 'string<))
3513 ;; The default face must be first, since it affects the others.
3514 (if (memq 'default saved-list)
3515 (setq saved-list (cons 'default (delq 'default saved-list))))
3516 (unless (bolp)
3517 (princ "\n"))
3518 (princ "(custom-set-faces
3519 ;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
3520 ;; Your init file must only contain one such instance.\n")
3521 (mapcar
3522 (lambda (symbol)
3523 (let ((value (get symbol 'saved-face))
3524 (now (not (or (get 'default 'face-defface-spec)
3525 (and (not (custom-facep 'default))
3526 (not (get 'default 'force-face))))))
3527 (comment (get 'default 'saved-face-comment)))
3528 (unless (eq symbol 'default))
3529 ;; Don't print default face here.
3530 (unless (bolp)
3531 (princ "\n"))
3532 (princ " '(")
3533 (prin1 symbol)
3534 (princ " ")
3535 (prin1 value)
3536 (cond ((or now comment)
3537 (princ " ")
3538 (if now
3539 (princ "t")
3540 (princ "nil"))
3541 (cond (comment
3542 (princ " ")
3543 (prin1 comment)
3544 (princ ")"))
3546 (princ ")"))))
3548 (princ ")")))))
3549 saved-list)
3550 (if (bolp)
3551 (princ " "))
3552 (princ ")")
3553 (unless (looking-at "\n")
3554 (princ "\n")))))
3556 ;;;###autoload
3557 (defun customize-save-customized ()
3558 "Save all user options which have been set in this session."
3559 (interactive)
3560 (mapatoms (lambda (symbol)
3561 (let ((face (get symbol 'customized-face))
3562 (value (get symbol 'customized-value))
3563 (face-comment (get symbol 'customized-face-comment))
3564 (variable-comment
3565 (get symbol 'customized-variable-comment)))
3566 (when face
3567 (put symbol 'saved-face face)
3568 (put symbol 'customized-face nil))
3569 (when value
3570 (put symbol 'saved-value value)
3571 (put symbol 'customized-value nil))
3572 (when variable-comment
3573 (put symbol 'saved-variable-comment variable-comment)
3574 (put symbol 'customized-variable-comment nil))
3575 (when face-comment
3576 (put symbol 'saved-face-comment face-comment)
3577 (put symbol 'customized-face-comment nil)))))
3578 ;; We really should update all custom buffers here.
3579 (custom-save-all))
3581 ;;;###autoload
3582 (defun custom-save-all ()
3583 "Save all customizations in `custom-file'."
3584 (let ((inhibit-read-only t))
3585 (custom-save-variables)
3586 (custom-save-faces)
3587 (save-excursion
3588 (let ((default-major-mode nil))
3589 (set-buffer (find-file-noselect (custom-file))))
3590 (save-buffer))))
3592 ;;; The Customize Menu.
3594 ;;; Menu support
3596 (defcustom custom-menu-nesting 2
3597 "Maximum nesting in custom menus."
3598 :type 'integer
3599 :group 'custom-menu)
3601 (defun custom-face-menu-create (widget symbol)
3602 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3603 (vector (custom-unlispify-menu-entry symbol)
3604 `(customize-face ',symbol)
3607 (defun custom-variable-menu-create (widget symbol)
3608 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3609 (let ((type (get symbol 'custom-type)))
3610 (unless (listp type)
3611 (setq type (list type)))
3612 (if (and type (widget-get type :custom-menu))
3613 (widget-apply type :custom-menu symbol)
3614 (vector (custom-unlispify-menu-entry symbol)
3615 `(customize-variable ',symbol)
3616 t))))
3618 ;; Add checkboxes to boolean variable entries.
3619 (widget-put (get 'boolean 'widget-type)
3620 :custom-menu (lambda (widget symbol)
3621 (vector (custom-unlispify-menu-entry symbol)
3622 `(customize-variable ',symbol)
3623 ':style 'toggle
3624 ':selected symbol)))
3626 ;; Fixme: sort out use of :filter in Emacs 21.
3627 (if nil ; (string-match "XEmacs" emacs-version)
3628 ;; XEmacs can create menus dynamically.
3629 (defun custom-group-menu-create (widget symbol)
3630 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3631 `( ,(custom-unlispify-menu-entry symbol t)
3632 :filter (lambda (&rest junk)
3633 (cdr (custom-menu-create ',symbol)))))
3634 ;; But emacs can't.
3635 (defun custom-group-menu-create (widget symbol)
3636 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3637 ;; Limit the nesting.
3638 (let ((custom-menu-nesting (1- custom-menu-nesting)))
3639 (custom-menu-create symbol))))
3641 ;;;###autoload
3642 (defun custom-menu-create (symbol)
3643 "Create menu for customization group SYMBOL.
3644 The menu is in a format applicable to `easy-menu-define'."
3645 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3646 `(customize-group ',symbol)
3647 t)))
3648 (if (and (or (not (boundp 'custom-menu-nesting))
3649 (>= custom-menu-nesting 0))
3650 (< (length (get symbol 'custom-group)) widget-menu-max-size))
3651 (let ((custom-prefix-list (custom-prefix-add symbol
3652 custom-prefix-list))
3653 (members (custom-sort-items (get symbol 'custom-group)
3654 custom-menu-sort-alphabetically
3655 custom-menu-order-groups)))
3656 (custom-load-symbol symbol)
3657 `(,(custom-unlispify-menu-entry symbol t)
3658 ,item
3659 "--"
3660 ,@(mapcar (lambda (entry)
3661 (widget-apply (if (listp (nth 1 entry))
3662 (nth 1 entry)
3663 (list (nth 1 entry)))
3664 :custom-menu (nth 0 entry)))
3665 members)))
3666 item)))
3668 ;;;###autoload
3669 (defun customize-menu-create (symbol &optional name)
3670 "Return a customize menu for customization group SYMBOL.
3671 If optional NAME is given, use that as the name of the menu.
3672 Otherwise the menu will be named `Customize'.
3673 The format is suitable for use with `easy-menu-define'."
3674 (unless name
3675 (setq name "Customize"))
3676 ;; Fixme: sort out use of :filter in Emacs 21.
3677 (if nil ;(string-match "XEmacs" emacs-version)
3678 ;; We can delay it under XEmacs.
3679 `(,name
3680 :filter (lambda (&rest junk)
3681 (cdr (custom-menu-create ',symbol))))
3682 ;; But we must create it now under Emacs.
3683 (cons name (cdr (custom-menu-create symbol)))))
3685 ;;; The Custom Mode.
3687 (defvar custom-mode-map nil
3688 "Keymap for `custom-mode'.")
3690 (unless custom-mode-map
3691 (setq custom-mode-map (make-sparse-keymap))
3692 (set-keymap-parent custom-mode-map widget-keymap)
3693 (suppress-keymap custom-mode-map)
3694 (define-key custom-mode-map " " 'scroll-up)
3695 (define-key custom-mode-map "\177" 'scroll-down)
3696 (define-key custom-mode-map "q" 'Custom-buffer-done)
3697 (define-key custom-mode-map "u" 'Custom-goto-parent)
3698 (define-key custom-mode-map "n" 'widget-forward)
3699 (define-key custom-mode-map "p" 'widget-backward)
3700 (define-key custom-mode-map [mouse-1] 'Custom-move-and-invoke))
3702 (defun Custom-move-and-invoke (event)
3703 "Move to where you click, and if it is an active field, invoke it."
3704 (interactive "e")
3705 (mouse-set-point event)
3706 (if (widget-event-point event)
3707 (let* ((pos (widget-event-point event))
3708 (button (get-char-property pos 'button)))
3709 (if button
3710 (widget-button-click event)))))
3712 (easy-menu-define Custom-mode-menu
3713 custom-mode-map
3714 "Menu used in customization buffers."
3715 `("Custom"
3716 ,(customize-menu-create 'customize)
3717 ["Set" Custom-set t]
3718 ["Save" Custom-save t]
3719 ["Reset to Current" Custom-reset-current t]
3720 ["Reset to Saved" Custom-reset-saved t]
3721 ["Reset to Standard Settings" Custom-reset-standard t]
3722 ["Info" (Info-goto-node "(emacs)Easy Customization") t]))
3724 (defun Custom-goto-parent ()
3725 "Go to the parent group listed at the top of this buffer.
3726 If several parents are listed, go to the first of them."
3727 (interactive)
3728 (save-excursion
3729 (goto-char (point-min))
3730 (if (search-forward "\nGo to parent group: " nil t)
3731 (let* ((button (get-char-property (point) 'button))
3732 (parent (downcase (widget-get button :tag))))
3733 (customize-group parent)))))
3735 (defcustom custom-mode-hook nil
3736 "Hook called when entering Custom mode."
3737 :type 'hook
3738 :group 'custom-buffer )
3740 (defun custom-state-buffer-message (widget)
3741 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
3742 (message "To install your edits, invoke [State] and choose the Set operation")))
3744 (defun custom-mode ()
3745 "Major mode for editing customization buffers.
3747 The following commands are available:
3749 Move to next button or editable field. \\[widget-forward]
3750 Move to previous button or editable field. \\[widget-backward]
3751 \\<widget-field-keymap>\
3752 Complete content of editable text field. \\[widget-complete]
3753 \\<custom-mode-map>\
3754 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3755 Invoke button under point. \\[widget-button-press]
3756 Set all modifications. \\[Custom-set]
3757 Make all modifications default. \\[Custom-save]
3758 Reset all modified options. \\[Custom-reset-current]
3759 Reset all modified or set options. \\[Custom-reset-saved]
3760 Reset all options. \\[Custom-reset-standard]
3762 Entry to this mode calls the value of `custom-mode-hook'
3763 if that value is non-nil."
3764 (kill-all-local-variables)
3765 (setq major-mode 'custom-mode
3766 mode-name "Custom")
3767 (use-local-map custom-mode-map)
3768 (easy-menu-add Custom-mode-menu)
3769 (make-local-variable 'custom-options)
3770 (make-local-variable 'widget-documentation-face)
3771 (setq widget-documentation-face 'custom-documentation-face)
3772 (make-local-variable 'widget-button-face)
3773 (setq widget-button-face 'custom-button-face)
3774 (set (make-local-variable 'widget-button-pressed-face)
3775 'custom-button-pressed-face)
3776 (set (make-local-variable 'widget-mouse-face)
3777 'custom-button-pressed-face) ; buttons `depress' when moused
3778 ;; When possible, use relief for buttons, not bracketing. This test
3779 ;; may not be optimal.
3780 (when custom-raised-buttons
3781 (set (make-local-variable 'widget-push-button-prefix) "")
3782 (set (make-local-variable 'widget-push-button-suffix) "")
3783 (set (make-local-variable 'widget-link-prefix) "")
3784 (set (make-local-variable 'widget-link-suffix) ""))
3785 (make-local-hook 'widget-edit-functions)
3786 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
3787 (run-hooks 'custom-mode-hook))
3789 (add-to-list
3790 'debug-ignored-errors
3791 "^No user options have changed defaults in recent Emacs versions$")
3793 ;;; The End.
3795 (provide 'cus-edit)
3797 ;;; cus-edit.el ends here