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