(custom-unlispify-menu-entry): Don't remove
[emacs.git] / lisp / cus-edit.el
blob770f8f723f81960c86aac72db18a128549b6252b
1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
2 ;;
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002 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 :group 'custom-buffer
435 :type 'boolean)
437 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
438 "Convert SYMBOL into a menu entry."
439 (cond ((not custom-unlispify-menu-entries)
440 (symbol-name symbol))
441 ((get symbol 'custom-tag)
442 (if no-suffix
443 (get symbol 'custom-tag)
444 (concat (get symbol 'custom-tag) "...")))
446 (save-excursion
447 (set-buffer (get-buffer-create " *Custom-Work*"))
448 (erase-buffer)
449 (princ symbol (current-buffer))
450 (goto-char (point-min))
451 ;; FIXME: Boolean variables are not predicates, so they shouldn't
452 ;; end with `-p'. -stef
453 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
454 ;; (re-search-forward "-p\\'" nil t))
455 ;; (replace-match "" t t)
456 ;; (goto-char (point-min)))
457 (if custom-unlispify-remove-prefixes
458 (let ((prefixes custom-prefix-list)
459 prefix)
460 (while prefixes
461 (setq prefix (car prefixes))
462 (if (search-forward prefix (+ (point) (length prefix)) t)
463 (progn
464 (setq prefixes nil)
465 (delete-region (point-min) (point)))
466 (setq prefixes (cdr prefixes))))))
467 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
468 (capitalize-region (point-min) (point-max))
469 (unless no-suffix
470 (goto-char (point-max))
471 (insert "..."))
472 (buffer-string)))))
474 (defcustom custom-unlispify-tag-names t
475 "Display tag names as words instead of symbols if non nil."
476 :group 'custom-buffer
477 :type 'boolean)
479 (defun custom-unlispify-tag-name (symbol)
480 "Convert SYMBOL into a menu entry."
481 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
482 (custom-unlispify-menu-entry symbol t)))
484 (defun custom-prefix-add (symbol prefixes)
485 "Add SYMBOL to list of ignored PREFIXES."
486 (cons (or (get symbol 'custom-prefix)
487 (concat (symbol-name symbol) "-"))
488 prefixes))
490 ;;; Guess.
492 (defcustom custom-guess-name-alist
493 '(("-p\\'" boolean)
494 ("-hook\\'" hook)
495 ("-face\\'" face)
496 ("-file\\'" file)
497 ("-function\\'" function)
498 ("-functions\\'" (repeat function))
499 ("-list\\'" (repeat sexp))
500 ("-alist\\'" (repeat (cons sexp sexp))))
501 "Alist of (MATCH TYPE).
503 MATCH should be a regexp matching the name of a symbol, and TYPE should
504 be a widget suitable for editing the value of that symbol. The TYPE
505 of the first entry where MATCH matches the name of the symbol will be
506 used.
508 This is used for guessing the type of variables not declared with
509 customize."
510 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
511 :group 'customize)
513 (defcustom custom-guess-doc-alist
514 '(("\\`\\*?Non-nil " boolean))
515 "Alist of (MATCH TYPE).
517 MATCH should be a regexp matching a documentation string, and TYPE
518 should be a widget suitable for editing the value of a variable with
519 that documentation string. The TYPE of the first entry where MATCH
520 matches the name of the symbol will be used.
522 This is used for guessing the type of variables not declared with
523 customize."
524 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
525 :group 'customize)
527 (defun custom-guess-type (symbol)
528 "Guess a widget suitable for editing the value of SYMBOL.
529 This is done by matching SYMBOL with `custom-guess-name-alist' and
530 if that fails, the doc string with `custom-guess-doc-alist'."
531 (let ((name (symbol-name symbol))
532 (names custom-guess-name-alist)
533 current found)
534 (while names
535 (setq current (car names)
536 names (cdr names))
537 (when (string-match (nth 0 current) name)
538 (setq found (nth 1 current)
539 names nil)))
540 (unless found
541 (let ((doc (documentation-property symbol 'variable-documentation))
542 (docs custom-guess-doc-alist))
543 (when doc
544 (while docs
545 (setq current (car docs)
546 docs (cdr docs))
547 (when (string-match (nth 0 current) doc)
548 (setq found (nth 1 current)
549 docs nil))))))
550 found))
552 ;;; Sorting.
554 (defcustom custom-browse-sort-alphabetically nil
555 "If non-nil, sort members of each customization group alphabetically."
556 :type 'boolean
557 :group 'custom-browse)
559 (defcustom custom-browse-order-groups nil
560 "If non-nil, order group members within each customization group.
561 If `first', order groups before non-groups.
562 If `last', order groups after non-groups."
563 :type '(choice (const first)
564 (const last)
565 (const :tag "none" nil))
566 :group 'custom-browse)
568 (defcustom custom-browse-only-groups nil
569 "If non-nil, show group members only within each customization group."
570 :type 'boolean
571 :group 'custom-browse)
573 (defcustom custom-buffer-sort-alphabetically nil
574 "If non-nil, sort members of each customization group alphabetically."
575 :type 'boolean
576 :group 'custom-buffer)
578 (defcustom custom-buffer-order-groups 'last
579 "If non-nil, order group members within each customization group.
580 If `first', order groups before non-groups.
581 If `last', order groups after non-groups."
582 :type '(choice (const first)
583 (const last)
584 (const :tag "none" nil))
585 :group 'custom-buffer)
587 (defcustom custom-menu-sort-alphabetically nil
588 "If non-nil, sort members of each customization group alphabetically."
589 :type 'boolean
590 :group 'custom-menu)
592 (defcustom custom-menu-order-groups 'first
593 "If non-nil, order group members within each customization group.
594 If `first', order groups before non-groups.
595 If `last', order groups after non-groups."
596 :type '(choice (const first)
597 (const last)
598 (const :tag "none" nil))
599 :group 'custom-menu)
601 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
603 (defun custom-sort-items (items sort-alphabetically order-groups)
604 "Return a sorted copy of ITEMS.
605 ITEMS should be a `custom-group' property.
606 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
607 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
608 groups after non-groups, if nil do not order groups at all."
609 (sort (copy-sequence items)
610 (lambda (a b)
611 (let ((typea (nth 1 a)) (typeb (nth 1 b))
612 (namea (nth 0 a)) (nameb (nth 0 b)))
613 (cond ((not order-groups)
614 ;; Since we don't care about A and B order, maybe sort.
615 (when sort-alphabetically
616 (string-lessp namea nameb)))
617 ((eq typea 'custom-group)
618 ;; If B is also a group, maybe sort. Otherwise, order A and B.
619 (if (eq typeb 'custom-group)
620 (when sort-alphabetically
621 (string-lessp namea nameb))
622 (eq order-groups 'first)))
623 ((eq typeb 'custom-group)
624 ;; Since A cannot be a group, order A and B.
625 (eq order-groups 'last))
626 (sort-alphabetically
627 ;; Since A and B cannot be groups, sort.
628 (string-lessp namea nameb)))))))
630 ;;; Custom Mode Commands.
632 (defvar custom-options nil
633 "Customization widgets in the current buffer.")
635 (defun Custom-set ()
636 "Set changes in all modified options."
637 (interactive)
638 (let ((children custom-options))
639 (mapc (lambda (child)
640 (when (eq (widget-get child :custom-state) 'modified)
641 (widget-apply child :custom-set)))
642 children)))
644 (defun Custom-save ()
645 "Set all modified group members and save them."
646 (interactive)
647 (let ((children custom-options))
648 (mapc (lambda (child)
649 (when (memq (widget-get child :custom-state)
650 '(modified set changed rogue))
651 (widget-apply child :custom-save)))
652 children))
653 (custom-save-all))
655 (defvar custom-reset-menu
656 '(("Current" . Custom-reset-current)
657 ("Saved" . Custom-reset-saved)
658 ("Erase Customization (use standard settings)" . Custom-reset-standard))
659 "Alist of actions for the `Reset' button.
660 The key is a string containing the name of the action, the value is a
661 Lisp function taking the widget as an element which will be called
662 when the action is chosen.")
664 (defun custom-reset (event)
665 "Select item from reset menu."
666 (let* ((completion-ignore-case t)
667 (answer (widget-choose "Reset to"
668 custom-reset-menu
669 event)))
670 (if answer
671 (funcall answer))))
673 (defun Custom-reset-current (&rest ignore)
674 "Reset all modified group members to their current value."
675 (interactive)
676 (let ((children custom-options))
677 (mapc (lambda (widget)
678 (and (default-boundp (widget-value widget))
679 (if (memq (widget-get widget :custom-state)
680 '(modified changed))
681 (widget-apply widget :custom-reset-current))))
682 children)))
684 (defun Custom-reset-saved (&rest ignore)
685 "Reset all modified or set group members to their saved value."
686 (interactive)
687 (let ((children custom-options))
688 (mapc (lambda (widget)
689 (and (get (widget-value widget) 'saved-value)
690 (if (memq (widget-get widget :custom-state)
691 '(modified set changed rogue))
692 (widget-apply widget :custom-reset-saved))))
693 children)))
695 (defun Custom-reset-standard (&rest ignore)
696 "Erase all customization (either current or saved) for the group members.
697 The immediate result is to restore them to their standard settings.
698 This operation eliminates any saved settings for the group members,
699 making them as if they had never been customized at all."
700 (interactive)
701 (let ((children custom-options))
702 (mapc (lambda (widget)
703 (and (widget-apply widget :custom-standard-value)
704 (if (memq (widget-get widget :custom-state)
705 '(modified set changed saved rogue))
706 (widget-apply widget :custom-reset-standard))))
707 children)))
709 ;;; The Customize Commands
711 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
712 "Prompt for a variable and a value and return them as a list.
713 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
714 prompt for the value. The %s escape in PROMPT-VAL is replaced with
715 the name of the variable.
717 If the variable has a `variable-interactive' property, that is used as if
718 it were the arg to `interactive' (which see) to interactively read the value.
720 If the variable has a `custom-type' property, it must be a widget and the
721 `:prompt-value' property of that widget will be used for reading the value.
723 If optional COMMENT argument is non nil, also prompt for a comment and return
724 it as the third element in the list."
725 (let* ((var (read-variable prompt-var))
726 (minibuffer-help-form '(describe-variable var))
727 (val
728 (let ((prop (get var 'variable-interactive))
729 (type (get var 'custom-type))
730 (prompt (format prompt-val var)))
731 (unless (listp type)
732 (setq type (list type)))
733 (cond (prop
734 ;; Use VAR's `variable-interactive' property
735 ;; as an interactive spec for prompting.
736 (call-interactively (list 'lambda '(arg)
737 (list 'interactive prop)
738 'arg)))
739 (type
740 (widget-prompt-value type
741 prompt
742 (if (boundp var)
743 (symbol-value var))
744 (not (boundp var))))
746 (eval-minibuffer prompt))))))
747 (if comment
748 (list var val
749 (read-string "Comment: " (get var 'variable-comment)))
750 (list var val))))
752 ;;;###autoload
753 (defun customize-set-value (variable value &optional comment)
754 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
756 If VARIABLE has a `variable-interactive' property, that is used as if
757 it were the arg to `interactive' (which see) to interactively read the value.
759 If VARIABLE has a `custom-type' property, it must be a widget and the
760 `:prompt-value' property of that widget will be used for reading the value.
762 If given a prefix (or a COMMENT argument), also prompt for a comment."
763 (interactive (custom-prompt-variable "Set variable: "
764 "Set %s to value: "
765 current-prefix-arg))
767 (cond ((string= comment "")
768 (put variable 'variable-comment nil))
769 (comment
770 (put variable 'variable-comment comment)))
771 (set variable value))
773 ;;;###autoload
774 (defun customize-set-variable (variable value &optional comment)
775 "Set the default for VARIABLE to VALUE, and return VALUE.
776 VALUE is a Lisp object.
778 If VARIABLE has a `custom-set' property, that is used for setting
779 VARIABLE, otherwise `set-default' is used.
781 The `customized-value' property of the VARIABLE will be set to a list
782 with a quoted VALUE as its sole list member.
784 If VARIABLE has a `variable-interactive' property, that is used as if
785 it were the arg to `interactive' (which see) to interactively read the value.
787 If VARIABLE has a `custom-type' property, it must be a widget and the
788 `:prompt-value' property of that widget will be used for reading the value.
790 If given a prefix (or a COMMENT argument), also prompt for a comment."
791 (interactive (custom-prompt-variable "Set variable: "
792 "Set customized value for %s to: "
793 current-prefix-arg))
794 (custom-load-symbol variable)
795 (funcall (or (get variable 'custom-set) 'set-default) variable value)
796 (put variable 'customized-value (list (custom-quote value)))
797 (cond ((string= comment "")
798 (put variable 'variable-comment nil)
799 (put variable 'customized-variable-comment nil))
800 (comment
801 (put variable 'variable-comment comment)
802 (put variable 'customized-variable-comment comment)))
803 value)
805 ;;;###autoload
806 (defun customize-save-variable (variable value &optional comment)
807 "Set the default for VARIABLE to VALUE, and save it for future sessions.
808 Return VALUE.
810 If VARIABLE has a `custom-set' property, that is used for setting
811 VARIABLE, otherwise `set-default' is used.
813 The `customized-value' property of the VARIABLE will be set to a list
814 with a quoted VALUE as its sole list member.
816 If VARIABLE has a `variable-interactive' property, that is used as if
817 it were the arg to `interactive' (which see) to interactively read the value.
819 If VARIABLE has a `custom-type' property, it must be a widget and the
820 `:prompt-value' property of that widget will be used for reading the value.
822 If given a prefix (or a COMMENT argument), also prompt for a comment."
823 (interactive (custom-prompt-variable "Set and save variable: "
824 "Set and save value for %s as: "
825 current-prefix-arg))
826 (funcall (or (get variable 'custom-set) 'set-default) variable value)
827 (put variable 'saved-value (list (custom-quote value)))
828 (cond ((string= comment "")
829 (put variable 'variable-comment nil)
830 (put variable 'saved-variable-comment nil))
831 (comment
832 (put variable 'variable-comment comment)
833 (put variable 'saved-variable-comment comment)))
834 (custom-save-all)
835 value)
837 ;;;###autoload
838 (defun customize ()
839 "Select a customization buffer which you can use to set user options.
840 User options are structured into \"groups\".
841 Initially the top-level group `Emacs' and its immediate subgroups
842 are shown; the contents of those subgroups are initially hidden."
843 (interactive)
844 (customize-group 'emacs))
846 ;;;###autoload
847 (defun customize-group (group)
848 "Customize GROUP, which must be a customization group."
849 (interactive (list (let ((completion-ignore-case t))
850 (completing-read "Customize group: (default emacs) "
851 obarray
852 (lambda (symbol)
853 (or (get symbol 'custom-loads)
854 (get symbol 'custom-group)))
855 t))))
856 (when (stringp group)
857 (if (string-equal "" group)
858 (setq group 'emacs)
859 (setq group (intern group))))
860 (or (get group 'custom-group)
861 (custom-load-symbol group))
862 (let ((name (format "*Customize Group: %s*"
863 (custom-unlispify-tag-name group))))
864 (if (get-buffer name)
865 (pop-to-buffer name)
866 (custom-buffer-create (list (list group 'custom-group))
867 name
868 (concat " for group "
869 (custom-unlispify-tag-name group))))))
871 ;;;###autoload
872 (defun customize-group-other-window (group)
873 "Customize GROUP, which must be a customization group."
874 (interactive (list (let ((completion-ignore-case t))
875 (completing-read "Customize group: (default emacs) "
876 obarray
877 (lambda (symbol)
878 (or (get symbol 'custom-loads)
879 (get symbol 'custom-group)))
880 t))))
881 (when (stringp group)
882 (if (string-equal "" group)
883 (setq group 'emacs)
884 (setq group (intern group))))
885 (or (get group 'custom-group)
886 (custom-load-symbol group))
887 (let ((name (format "*Customize Group: %s*"
888 (custom-unlispify-tag-name group))))
889 (if (get-buffer name)
890 (let ((window (selected-window)))
891 (pop-to-buffer name)
892 (select-window window))
893 (custom-buffer-create-other-window
894 (list (list group 'custom-group))
895 name
896 (concat " for group "
897 (custom-unlispify-tag-name group))))))
899 ;;;###autoload
900 (defalias 'customize-variable 'customize-option)
902 ;;;###autoload
903 (defun customize-option (symbol)
904 "Customize SYMBOL, which must be a user option variable."
905 (interactive (custom-variable-prompt))
906 ;; If we don't have SYMBOL's real definition loaded,
907 ;; try to load it.
908 (unless (get symbol 'custom-type)
909 (let ((loaddefs-file (locate-library "loaddefs.el" t))
910 file)
911 ;; See if it is autoloaded from some library.
912 (when loaddefs-file
913 (with-temp-buffer
914 (insert-file-contents loaddefs-file)
915 (when (re-search-forward (concat "^(defvar " (symbol-name symbol))
916 nil t)
917 (search-backward "\n;;; Generated autoloads from ")
918 (goto-char (match-end 0))
919 (setq file (buffer-substring (point)
920 (progn (end-of-line) (point)))))))
921 ;; If it is, load that library.
922 (when file
923 (when (string-match "\\.el\\'" file)
924 (setq file (substring file 0 (match-beginning 0))))
925 (load file))))
926 (unless (get symbol 'custom-type)
927 (error "Variable %s cannot be customized" symbol))
928 (custom-buffer-create (list (list symbol 'custom-variable))
929 (format "*Customize Option: %s*"
930 (custom-unlispify-tag-name symbol))))
932 (defvar customize-changed-options-previous-release "20.2"
933 "Version for `customize-changed-options' to refer back to by default.")
935 ;;;###autoload
936 (defun customize-changed-options (since-version)
937 "Customize all user option variables changed in Emacs itself.
938 This includes new user option variables and faces, and new
939 customization groups, as well as older options and faces whose default
940 values have changed since the previous major Emacs release.
942 With argument SINCE-VERSION (a string), customize all user option
943 variables that were added (or their meanings were changed) since that
944 version."
946 (interactive "sCustomize options changed, since version (default all versions): ")
947 (if (equal since-version "")
948 (setq since-version nil)
949 (unless (condition-case nil
950 (numberp (read since-version))
951 (error nil))
952 (signal 'wrong-type-argument (list 'numberp since-version))))
953 (unless since-version
954 (setq since-version customize-changed-options-previous-release))
955 (let ((found nil)
956 (versions nil))
957 (mapatoms (lambda (symbol)
958 (and (or (boundp symbol)
959 ;; For variables not yet loaded.
960 (get symbol 'standard-value)
961 ;; For groups the previous test fails, this one
962 ;; could be used to determine if symbol is a
963 ;; group. Is there a better way for this?
964 (get symbol 'group-documentation))
965 (let ((version (get symbol 'custom-version)))
966 (and version
967 (or (null since-version)
968 (customize-version-lessp since-version version))
969 (if (member version versions)
971 ;;; Collect all versions that we use.
972 (push version versions))))
973 (setq found
974 ;; We have to set the right thing here,
975 ;; depending if we have a group or a
976 ;; variable.
977 (if (get symbol 'group-documentation)
978 (cons (list symbol 'custom-group) found)
979 (cons (list symbol 'custom-variable) found))))))
980 (if (not found)
981 (error "No user option defaults have been changed since Emacs %s"
982 since-version)
983 (let ((flist nil))
984 (while versions
985 (push (copy-sequence
986 (cdr (assoc (car versions) custom-versions-load-alist)))
987 flist)
988 (setq versions (cdr versions)))
989 (put 'custom-versions-load-alist 'custom-loads
990 ;; Get all the files that correspond to element from the
991 ;; VERSIONS list. This could use some simplification.
992 (apply 'nconc flist)))
993 ;; Because we set all the files needed to be loaded as a
994 ;; `custom-loads' property to `custom-versions-load-alist' this
995 ;; call will actually load them.
996 (custom-load-symbol 'custom-versions-load-alist)
997 ;; Clean up
998 (put 'custom-versions-load-alist 'custom-loads nil)
999 (custom-buffer-create (custom-sort-items found t 'first)
1000 "*Customize Changed Options*"))))
1002 (defun customize-version-lessp (version1 version2)
1003 ;; Why are the versions strings, and given that they are, why aren't
1004 ;; they converted to numbers and compared as such here? -- fx
1006 ;; In case someone made a mistake and left out the quotes
1007 ;; in the :version value.
1008 (if (numberp version2)
1009 (setq version2 (prin1-to-string version2)))
1010 (let (major1 major2 minor1 minor2)
1011 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1012 (setq major1 (read (or (match-string 1 version1)
1013 "0")))
1014 (setq minor1 (read (or (match-string 3 version1)
1015 "0")))
1016 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1017 (setq major2 (read (or (match-string 1 version2)
1018 "0")))
1019 (setq minor2 (read (or (match-string 3 version2)
1020 "0")))
1021 (or (< major1 major2)
1022 (and (= major1 major2)
1023 (< minor1 minor2)))))
1025 ;;;###autoload
1026 (defalias 'customize-variable-other-window 'customize-option-other-window)
1028 ;;;###autoload
1029 (defun customize-option-other-window (symbol)
1030 "Customize SYMBOL, which must be a user option variable.
1031 Show the buffer in another window, but don't select it."
1032 (interactive (custom-variable-prompt))
1033 (custom-buffer-create-other-window
1034 (list (list symbol 'custom-variable))
1035 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
1037 ;;;###autoload
1038 (defun customize-face (&optional face)
1039 "Customize SYMBOL, which should be a face name or nil.
1040 If SYMBOL is nil, customize all faces.
1042 Interactively, when point is on text which has a face specified,
1043 suggest to customized that face, if it's customizable."
1044 (interactive
1045 (list (read-face-name "Customize face" "all faces" t)))
1046 (if (member face '(nil ""))
1047 (setq face (face-list)))
1048 (if (and (listp face) (null (cdr face)))
1049 (setq face (car face)))
1050 (if (listp face)
1051 (custom-buffer-create (custom-sort-items
1052 (mapcar (lambda (s)
1053 (list s 'custom-face))
1054 face)
1055 t nil)
1056 "*Customize Faces*")
1057 (unless (facep face)
1058 (error "Invalid face %S"))
1059 (custom-buffer-create (list (list face 'custom-face))
1060 (format "*Customize Face: %s*"
1061 (custom-unlispify-tag-name face)))))
1063 ;;;###autoload
1064 (defun customize-face-other-window (&optional face)
1065 "Show customization buffer for face SYMBOL in other window.
1067 Interactively, when point is on text which has a face specified,
1068 suggest to customized that face, if it's customizable."
1069 (interactive
1070 (list (read-face-name "Customize face" "all faces" t)))
1071 (if (member face '(nil ""))
1072 (setq face (face-list)))
1073 (if (and (listp face) (null (cdr face)))
1074 (setq face (car face)))
1075 (if (listp face)
1076 (custom-buffer-create-other-window
1077 (custom-sort-items
1078 (mapcar (lambda (s)
1079 (list s 'custom-face))
1080 face)
1081 t nil)
1082 "*Customize Faces*")
1083 (unless (facep face)
1084 (error "Invalid face %S"))
1085 (custom-buffer-create-other-window
1086 (list (list face 'custom-face))
1087 (format "*Customize Face: %s*"
1088 (custom-unlispify-tag-name face)))))
1090 ;;;###autoload
1091 (defun customize-customized ()
1092 "Customize all user options set since the last save in this session."
1093 (interactive)
1094 (let ((found nil))
1095 (mapatoms (lambda (symbol)
1096 (and (or (get symbol 'customized-face)
1097 (get symbol 'customized-face-comment))
1098 (custom-facep symbol)
1099 (push (list symbol 'custom-face) found))
1100 (and (or (get symbol 'customized-value)
1101 (get symbol 'customized-variable-comment))
1102 (boundp symbol)
1103 (push (list symbol 'custom-variable) found))))
1104 (if (not found)
1105 (error "No customized user options")
1106 (custom-buffer-create (custom-sort-items found t nil)
1107 "*Customize Customized*"))))
1109 ;;;###autoload
1110 (defun customize-saved ()
1111 "Customize all already saved user options."
1112 (interactive)
1113 (let ((found nil))
1114 (mapatoms (lambda (symbol)
1115 (and (or (get symbol 'saved-face)
1116 (get symbol 'saved-face-comment))
1117 (custom-facep symbol)
1118 (push (list symbol 'custom-face) found))
1119 (and (or (get symbol 'saved-value)
1120 (get symbol 'saved-variable-comment))
1121 (boundp symbol)
1122 (push (list symbol 'custom-variable) found))))
1123 (if (not found )
1124 (error "No saved user options")
1125 (custom-buffer-create (custom-sort-items found t nil)
1126 "*Customize Saved*"))))
1128 ;;;###autoload
1129 (defun customize-apropos (regexp &optional all)
1130 "Customize all user options matching REGEXP.
1131 If ALL is `options', include only options.
1132 If ALL is `faces', include only faces.
1133 If ALL is `groups', include only groups.
1134 If ALL is t (interactively, with prefix arg), include options which are not
1135 user-settable, as well as faces and groups."
1136 (interactive "sCustomize regexp: \nP")
1137 (let ((found nil))
1138 (mapatoms (lambda (symbol)
1139 (when (string-match regexp (symbol-name symbol))
1140 (when (and (not (memq all '(faces options)))
1141 (get symbol 'custom-group))
1142 (push (list symbol 'custom-group) found))
1143 (when (and (not (memq all '(options groups)))
1144 (custom-facep symbol))
1145 (push (list symbol 'custom-face) found))
1146 (when (and (not (memq all '(groups faces)))
1147 (boundp symbol)
1148 (or (get symbol 'saved-value)
1149 (get symbol 'standard-value)
1150 (if (memq all '(nil options))
1151 (user-variable-p symbol)
1152 (get symbol 'variable-documentation))))
1153 (push (list symbol 'custom-variable) found)))))
1154 (if (not found)
1155 (error "No matches")
1156 (custom-buffer-create (custom-sort-items found t
1157 custom-buffer-order-groups)
1158 "*Customize Apropos*"))))
1160 ;;;###autoload
1161 (defun customize-apropos-options (regexp &optional arg)
1162 "Customize all user options matching REGEXP.
1163 With prefix arg, include options which are not user-settable."
1164 (interactive "sCustomize regexp: \nP")
1165 (customize-apropos regexp (or arg 'options)))
1167 ;;;###autoload
1168 (defun customize-apropos-faces (regexp)
1169 "Customize all user faces matching REGEXP."
1170 (interactive "sCustomize regexp: \n")
1171 (customize-apropos regexp 'faces))
1173 ;;;###autoload
1174 (defun customize-apropos-groups (regexp)
1175 "Customize all user groups matching REGEXP."
1176 (interactive "sCustomize regexp: \n")
1177 (customize-apropos regexp 'groups))
1179 ;;; Buffer.
1181 (defcustom custom-buffer-style 'links
1182 "Control the presentation style for customization buffers.
1183 The value should be a symbol, one of:
1185 brackets: groups nest within each other with big horizontal brackets.
1186 links: groups have links to subgroups."
1187 :type '(radio (const brackets)
1188 (const links))
1189 :group 'custom-buffer)
1191 ;; If we pass BUFFER to `bury-buffer', the buffer isn't removed from
1192 ;; the window.
1193 (defun custom-bury-buffer (buffer)
1194 (bury-buffer))
1196 (defcustom custom-buffer-done-function 'custom-bury-buffer
1197 "*Function called to remove a Custom buffer when the user is done with it.
1198 Called with one argument, the buffer to remove."
1199 :type '(choice (function-item :tag "Bury buffer" custom-bury-buffer)
1200 (function-item :tag "Kill buffer" kill-buffer)
1201 (function :tag "Other"))
1202 :version "21.1"
1203 :group 'custom-buffer)
1205 (defcustom custom-buffer-indent 3
1206 "Number of spaces to indent nested groups."
1207 :type 'integer
1208 :group 'custom-buffer)
1210 ;;;###autoload
1211 (defun custom-buffer-create (options &optional name description)
1212 "Create a buffer containing OPTIONS.
1213 Optional NAME is the name of the buffer.
1214 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1215 SYMBOL is a customization option, and WIDGET is a widget for editing
1216 that option."
1217 (unless name (setq name "*Customization*"))
1218 (kill-buffer (get-buffer-create name))
1219 (pop-to-buffer (get-buffer-create name))
1220 (custom-buffer-create-internal options description))
1222 ;;;###autoload
1223 (defun custom-buffer-create-other-window (options &optional name description)
1224 "Create a buffer containing OPTIONS.
1225 Optional NAME is the name of the buffer.
1226 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1227 SYMBOL is a customization option, and WIDGET is a widget for editing
1228 that option."
1229 (unless name (setq name "*Customization*"))
1230 (kill-buffer (get-buffer-create name))
1231 (let ((window (selected-window))
1232 (pop-up-windows t)
1233 (special-display-buffer-names nil)
1234 (special-display-regexps nil)
1235 (same-window-buffer-names nil)
1236 (same-window-regexps nil))
1237 (pop-to-buffer (get-buffer-create name))
1238 (custom-buffer-create-internal options description)
1239 (select-window window)))
1241 (defcustom custom-reset-button-menu nil
1242 "If non-nil, only show a single reset button in customize buffers.
1243 This button will have a menu with all three reset operations."
1244 :type 'boolean
1245 :group 'custom-buffer)
1247 (defcustom custom-buffer-verbose-help t
1248 "If non-nil, include explanatory text in the customization buffer."
1249 :type 'boolean
1250 :group 'custom-buffer)
1252 (defun Custom-buffer-done (&rest ignore)
1253 "Remove current buffer by calling `custom-buffer-done-function'."
1254 (interactive)
1255 (funcall custom-buffer-done-function (current-buffer)))
1257 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1258 '(("unspecified" . unspecified))))
1259 "If non-nil, indicate active buttons in a `raised-button' style.
1260 Otherwise use brackets."
1261 :type 'boolean
1262 :version "21.1"
1263 :group 'custom-buffer)
1265 (defun custom-buffer-create-internal (options &optional description)
1266 (message "Creating customization buffer...")
1267 (custom-mode)
1268 (if custom-buffer-verbose-help
1269 (progn
1270 (widget-insert "This is a customization buffer")
1271 (if description
1272 (widget-insert description))
1273 (widget-insert (format ".
1274 %s show active fields; type RET or click mouse-1
1275 on an active field to invoke its action. Editing an option value
1276 changes the text in the buffer; invoke the State button and
1277 choose the Set operation to set the option value.
1278 Invoke " (if custom-raised-buttons
1279 "`Raised' buttons"
1280 "Square brackets")))
1281 (widget-create 'info-link
1282 :tag "Help"
1283 :help-echo "Read the online help."
1284 "(emacs)Easy Customization")
1285 (widget-insert " for more information.\n\n")
1286 (message "Creating customization buttons...")
1287 (widget-insert "Operate on everything in this buffer:\n "))
1288 (widget-insert " "))
1289 (widget-create 'push-button
1290 :tag "Set for Current Session"
1291 :help-echo "\
1292 Make your editing in this buffer take effect for this session."
1293 :action (lambda (widget &optional event)
1294 (Custom-set)))
1295 (widget-insert " ")
1296 (widget-create 'push-button
1297 :tag "Save for Future Sessions"
1298 :help-echo "\
1299 Make your editing in this buffer take effect for future Emacs sessions."
1300 :action (lambda (widget &optional event)
1301 (Custom-save)))
1302 (if custom-reset-button-menu
1303 (progn
1304 (widget-insert " ")
1305 (widget-create 'push-button
1306 :tag "Reset"
1307 :help-echo "Show a menu with reset operations."
1308 :mouse-down-action (lambda (&rest junk) t)
1309 :action (lambda (widget &optional event)
1310 (custom-reset event))))
1311 (widget-insert "\n ")
1312 (widget-create 'push-button
1313 :tag "Reset"
1314 :help-echo "\
1315 Reset all edited text in this buffer to reflect current values."
1316 :action 'Custom-reset-current)
1317 (widget-insert " ")
1318 (widget-create 'push-button
1319 :tag "Reset to Saved"
1320 :help-echo "\
1321 Reset all values in this buffer to their saved settings."
1322 :action 'Custom-reset-saved)
1323 (widget-insert " ")
1324 (widget-create 'push-button
1325 :tag "Erase Customization"
1326 :help-echo "\
1327 Un-customize all values in this buffer. They get their standard settings."
1328 :action 'Custom-reset-standard))
1329 (if (not custom-buffer-verbose-help)
1330 (progn
1331 (widget-insert " ")
1332 (widget-create 'info-link
1333 :tag "Help"
1334 :help-echo "Read the online help."
1335 "(emacs)Easy Customization")))
1336 (widget-insert " ")
1337 (widget-create 'push-button
1338 :tag "Finish"
1339 :help-echo
1340 (lambda (&rest ignore)
1341 (cond
1342 ((eq custom-buffer-done-function
1343 'custom-bury-buffer)
1344 "Bury this buffer")
1345 ((eq custom-buffer-done-function 'kill-buffer)
1346 "Kill this buffer")
1347 (t "Finish with this buffer")))
1348 :action #'Custom-buffer-done)
1349 (widget-insert "\n\n")
1350 (message "Creating customization items...")
1351 (buffer-disable-undo)
1352 (setq custom-options
1353 (if (= (length options) 1)
1354 (mapcar (lambda (entry)
1355 (widget-create (nth 1 entry)
1356 :documentation-shown t
1357 :custom-state 'unknown
1358 :tag (custom-unlispify-tag-name
1359 (nth 0 entry))
1360 :value (nth 0 entry)))
1361 options)
1362 (let ((count 0)
1363 (length (length options)))
1364 (mapcar (lambda (entry)
1365 (prog2
1366 (message "Creating customization items ...%2d%%"
1367 (/ (* 100.0 count) length))
1368 (widget-create (nth 1 entry)
1369 :tag (custom-unlispify-tag-name
1370 (nth 0 entry))
1371 :value (nth 0 entry))
1372 (setq count (1+ count))
1373 (unless (eq (preceding-char) ?\n)
1374 (widget-insert "\n"))
1375 (widget-insert "\n")))
1376 options))))
1377 (unless (eq (preceding-char) ?\n)
1378 (widget-insert "\n"))
1379 (message "Creating customization items ...done")
1380 (unless (eq custom-buffer-style 'tree)
1381 (mapc 'custom-magic-reset custom-options))
1382 (message "Creating customization setup...")
1383 (widget-setup)
1384 (buffer-enable-undo)
1385 (goto-char (point-min))
1386 (message "Creating customization buffer...done"))
1388 ;;; The Tree Browser.
1390 ;;;###autoload
1391 (defun customize-browse (&optional group)
1392 "Create a tree browser for the customize hierarchy."
1393 (interactive)
1394 (unless group
1395 (setq group 'emacs))
1396 (let ((name "*Customize Browser*"))
1397 (kill-buffer (get-buffer-create name))
1398 (pop-to-buffer (get-buffer-create name)))
1399 (custom-mode)
1400 (widget-insert "\
1401 Square brackets show active fields; type RET or click mouse-1
1402 on an active field to invoke its action.
1403 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1404 (if custom-browse-only-groups
1405 (widget-insert "\
1406 Invoke the [Group] button below to edit that item in another window.\n\n")
1407 (widget-insert "Invoke the ")
1408 (widget-create 'item
1409 :format "%t"
1410 :tag "[Group]"
1411 :tag-glyph "folder")
1412 (widget-insert ", ")
1413 (widget-create 'item
1414 :format "%t"
1415 :tag "[Face]"
1416 :tag-glyph "face")
1417 (widget-insert ", and ")
1418 (widget-create 'item
1419 :format "%t"
1420 :tag "[Option]"
1421 :tag-glyph "option")
1422 (widget-insert " buttons below to edit that
1423 item in another window.\n\n"))
1424 (let ((custom-buffer-style 'tree))
1425 (widget-create 'custom-group
1426 :custom-last t
1427 :custom-state 'unknown
1428 :tag (custom-unlispify-tag-name group)
1429 :value group))
1430 (goto-char (point-min)))
1432 (define-widget 'custom-browse-visibility 'item
1433 "Control visibility of items in the customize tree browser."
1434 :format "%[[%t]%]"
1435 :action 'custom-browse-visibility-action)
1437 (defun custom-browse-visibility-action (widget &rest ignore)
1438 (let ((custom-buffer-style 'tree))
1439 (custom-toggle-parent widget)))
1441 (define-widget 'custom-browse-group-tag 'push-button
1442 "Show parent in other window when activated."
1443 :tag "Group"
1444 :tag-glyph "folder"
1445 :action 'custom-browse-group-tag-action)
1447 (defun custom-browse-group-tag-action (widget &rest ignore)
1448 (let ((parent (widget-get widget :parent)))
1449 (customize-group-other-window (widget-value parent))))
1451 (define-widget 'custom-browse-variable-tag 'push-button
1452 "Show parent in other window when activated."
1453 :tag "Option"
1454 :tag-glyph "option"
1455 :action 'custom-browse-variable-tag-action)
1457 (defun custom-browse-variable-tag-action (widget &rest ignore)
1458 (let ((parent (widget-get widget :parent)))
1459 (customize-variable-other-window (widget-value parent))))
1461 (define-widget 'custom-browse-face-tag 'push-button
1462 "Show parent in other window when activated."
1463 :tag "Face"
1464 :tag-glyph "face"
1465 :action 'custom-browse-face-tag-action)
1467 (defun custom-browse-face-tag-action (widget &rest ignore)
1468 (let ((parent (widget-get widget :parent)))
1469 (customize-face-other-window (widget-value parent))))
1471 (defconst custom-browse-alist '((" " "space")
1472 (" | " "vertical")
1473 ("-\\ " "top")
1474 (" |-" "middle")
1475 (" `-" "bottom")))
1477 (defun custom-browse-insert-prefix (prefix)
1478 "Insert PREFIX. On XEmacs convert it to line graphics."
1479 ;; Fixme: do graphics.
1480 (if nil ; (string-match "XEmacs" emacs-version)
1481 (progn
1482 (insert "*")
1483 (while (not (string-equal prefix ""))
1484 (let ((entry (substring prefix 0 3)))
1485 (setq prefix (substring prefix 3))
1486 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1487 (name (nth 1 (assoc entry custom-browse-alist))))
1488 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1489 (overlay-put overlay 'start-open t)
1490 (overlay-put overlay 'end-open t)))))
1491 (insert prefix)))
1493 ;;; Modification of Basic Widgets.
1495 ;; We add extra properties to the basic widgets needed here. This is
1496 ;; fine, as long as we are careful to stay within out own namespace.
1498 ;; We want simple widgets to be displayed by default, but complex
1499 ;; widgets to be hidden.
1501 (widget-put (get 'item 'widget-type) :custom-show t)
1502 (widget-put (get 'editable-field 'widget-type)
1503 :custom-show (lambda (widget value)
1504 (let ((pp (pp-to-string value)))
1505 (cond ((string-match "\n" pp)
1506 nil)
1507 ((> (length pp) 40)
1508 nil)
1509 (t t)))))
1510 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1512 ;;; The `custom-manual' Widget.
1514 (define-widget 'custom-manual 'info-link
1515 "Link to the manual entry for this customization option."
1516 :help-echo "Read the manual entry for this option."
1517 :tag "Manual")
1519 ;;; The `custom-magic' Widget.
1521 (defgroup custom-magic-faces nil
1522 "Faces used by the magic button."
1523 :group 'custom-faces
1524 :group 'custom-buffer)
1526 (defface custom-invalid-face '((((class color))
1527 (:foreground "yellow" :background "red"))
1529 (:weight bold :slant italic :underline t)))
1530 "Face used when the customize item is invalid."
1531 :group 'custom-magic-faces)
1533 (defface custom-rogue-face '((((class color))
1534 (:foreground "pink" :background "black"))
1536 (:underline t)))
1537 "Face used when the customize item is not defined for customization."
1538 :group 'custom-magic-faces)
1540 (defface custom-modified-face '((((class color))
1541 (:foreground "white" :background "blue"))
1543 (:slant italic :bold)))
1544 "Face used when the customize item has been modified."
1545 :group 'custom-magic-faces)
1547 (defface custom-set-face '((((class color))
1548 (:foreground "blue" :background "white"))
1550 (:slant italic)))
1551 "Face used when the customize item has been set."
1552 :group 'custom-magic-faces)
1554 (defface custom-changed-face '((((class color))
1555 (:foreground "white" :background "blue"))
1557 (:slant italic)))
1558 "Face used when the customize item has been changed."
1559 :group 'custom-magic-faces)
1561 (defface custom-saved-face '((t (:underline t)))
1562 "Face used when the customize item has been saved."
1563 :group 'custom-magic-faces)
1565 (defconst custom-magic-alist '((nil "#" underline "\
1566 uninitialized, you should not see this.")
1567 (unknown "?" italic "\
1568 unknown, you should not see this.")
1569 (hidden "-" default "\
1570 hidden, invoke \"Show\" in the previous line to show." "\
1571 group now hidden, invoke \"Show\", above, to show contents.")
1572 (invalid "x" custom-invalid-face "\
1573 the value displayed for this %c is invalid and cannot be set.")
1574 (modified "*" custom-modified-face "\
1575 you have edited the value as text, but you have not set the %c." "\
1576 you have edited something in this group, but not set it.")
1577 (set "+" custom-set-face "\
1578 you have set this %c, but not saved it for future sessions." "\
1579 something in this group has been set, but not saved.")
1580 (changed ":" custom-changed-face "\
1581 this %c has been changed outside the customize buffer." "\
1582 something in this group has been changed outside customize.")
1583 (saved "!" custom-saved-face "\
1584 this %c has been set and saved." "\
1585 something in this group has been set and saved.")
1586 (rogue "@" custom-rogue-face "\
1587 this %c has not been changed with customize." "\
1588 something in this group is not prepared for customization.")
1589 (standard " " nil "\
1590 this %c is unchanged from its standard setting." "\
1591 visible group members are all at standard settings."))
1592 "Alist of customize option states.
1593 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1595 STATE is one of the following symbols:
1597 `nil'
1598 For internal use, should never occur.
1599 `unknown'
1600 For internal use, should never occur.
1601 `hidden'
1602 This item is not being displayed.
1603 `invalid'
1604 This item is modified, but has an invalid form.
1605 `modified'
1606 This item is modified, and has a valid form.
1607 `set'
1608 This item has been set but not saved.
1609 `changed'
1610 The current value of this item has been changed temporarily.
1611 `saved'
1612 This item is marked for saving.
1613 `rogue'
1614 This item has no customization information.
1615 `standard'
1616 This item is unchanged from the standard setting.
1618 MAGIC is a string used to present that state.
1620 FACE is a face used to present the state.
1622 ITEM-DESC is a string describing the state for options.
1624 GROUP-DESC is a string describing the state for groups. If this is
1625 left out, ITEM-DESC will be used.
1627 The string %c in either description will be replaced with the
1628 category of the item. These are `group'. `option', and `face'.
1630 The list should be sorted most significant first.")
1632 (defcustom custom-magic-show 'long
1633 "If non-nil, show textual description of the state.
1634 If `long', show a full-line description, not just one word."
1635 :type '(choice (const :tag "no" nil)
1636 (const long)
1637 (other :tag "short" short))
1638 :group 'custom-buffer)
1640 (defcustom custom-magic-show-hidden '(option face)
1641 "Control whether the State button is shown for hidden items.
1642 The value should be a list with the custom categories where the State
1643 button should be visible. Possible categories are `group', `option',
1644 and `face'."
1645 :type '(set (const group) (const option) (const face))
1646 :group 'custom-buffer)
1648 (defcustom custom-magic-show-button nil
1649 "Show a \"magic\" button indicating the state of each customization option."
1650 :type 'boolean
1651 :group 'custom-buffer)
1653 (define-widget 'custom-magic 'default
1654 "Show and manipulate state for a customization option."
1655 :format "%v"
1656 :action 'widget-parent-action
1657 :notify 'ignore
1658 :value-get 'ignore
1659 :value-create 'custom-magic-value-create
1660 :value-delete 'widget-children-value-delete)
1662 (defun widget-magic-mouse-down-action (widget &optional event)
1663 ;; Non-nil unless hidden.
1664 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1665 :custom-state)
1666 'hidden)))
1668 (defun custom-magic-value-create (widget)
1669 "Create compact status report for WIDGET."
1670 (let* ((parent (widget-get widget :parent))
1671 (state (widget-get parent :custom-state))
1672 (hidden (eq state 'hidden))
1673 (entry (assq state custom-magic-alist))
1674 (magic (nth 1 entry))
1675 (face (nth 2 entry))
1676 (category (widget-get parent :custom-category))
1677 (text (or (and (eq category 'group)
1678 (nth 4 entry))
1679 (nth 3 entry)))
1680 (form (widget-get parent :custom-form))
1681 children)
1682 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1683 (setq text (concat (match-string 1 text)
1684 (symbol-name category)
1685 (match-string 2 text))))
1686 (when (and custom-magic-show
1687 (or (not hidden)
1688 (memq category custom-magic-show-hidden)))
1689 (insert " ")
1690 (when (and (eq category 'group)
1691 (not (and (eq custom-buffer-style 'links)
1692 (> (widget-get parent :custom-level) 1))))
1693 (insert-char ?\ (* custom-buffer-indent
1694 (widget-get parent :custom-level))))
1695 (push (widget-create-child-and-convert
1696 widget 'choice-item
1697 :help-echo "Change the state of this item."
1698 :format (if hidden "%t" "%[%t%]")
1699 :button-prefix 'widget-push-button-prefix
1700 :button-suffix 'widget-push-button-suffix
1701 :mouse-down-action 'widget-magic-mouse-down-action
1702 :tag "State")
1703 children)
1704 (insert ": ")
1705 (let ((start (point)))
1706 (if (eq custom-magic-show 'long)
1707 (insert text)
1708 (insert (symbol-name state)))
1709 (cond ((eq form 'lisp)
1710 (insert " (lisp)"))
1711 ((eq form 'mismatch)
1712 (insert " (mismatch)")))
1713 (put-text-property start (point) 'face 'custom-state-face))
1714 (insert "\n"))
1715 (when (and (eq category 'group)
1716 (not (and (eq custom-buffer-style 'links)
1717 (> (widget-get parent :custom-level) 1))))
1718 (insert-char ?\ (* custom-buffer-indent
1719 (widget-get parent :custom-level))))
1720 (when custom-magic-show-button
1721 (when custom-magic-show
1722 (let ((indent (widget-get parent :indent)))
1723 (when indent
1724 (insert-char ? indent))))
1725 (push (widget-create-child-and-convert
1726 widget 'choice-item
1727 :mouse-down-action 'widget-magic-mouse-down-action
1728 :button-face face
1729 :button-prefix ""
1730 :button-suffix ""
1731 :help-echo "Change the state."
1732 :format (if hidden "%t" "%[%t%]")
1733 :tag (if (memq form '(lisp mismatch))
1734 (concat "(" magic ")")
1735 (concat "[" magic "]")))
1736 children)
1737 (insert " "))
1738 (widget-put widget :children children)))
1740 (defun custom-magic-reset (widget)
1741 "Redraw the :custom-magic property of WIDGET."
1742 (let ((magic (widget-get widget :custom-magic)))
1743 (widget-value-set magic (widget-value magic))))
1745 ;;; The `custom' Widget.
1747 (defface custom-button-face
1748 '((((type x w32 mac) (class color)) ; Like default modeline
1749 (:box (:line-width 2 :style released-button)
1750 :background "lightgrey" :foreground "black"))
1752 nil))
1753 "Face used for buttons in customization buffers."
1754 :version "21.1"
1755 :group 'custom-faces)
1757 (defface custom-button-pressed-face
1758 '((((type x w32 mac) (class color))
1759 (:box (:line-width 2 :style pressed-button)
1760 :background "lightgrey" :foreground "black"))
1762 (:inverse-video t)))
1763 "Face used for buttons in customization buffers."
1764 :version "21.1"
1765 :group 'custom-faces)
1767 (defface custom-documentation-face nil
1768 "Face used for documentation strings in customization buffers."
1769 :group 'custom-faces)
1771 (defface custom-state-face '((((class color)
1772 (background dark))
1773 (:foreground "lime green"))
1774 (((class color)
1775 (background light))
1776 (:foreground "dark green"))
1777 (t nil))
1778 "Face used for State descriptions in the customize buffer."
1779 :group 'custom-faces)
1781 (define-widget 'custom 'default
1782 "Customize a user option."
1783 :format "%v"
1784 :convert-widget 'custom-convert-widget
1785 :notify 'custom-notify
1786 :custom-prefix ""
1787 :custom-level 1
1788 :custom-state 'hidden
1789 :documentation-property 'widget-subclass-responsibility
1790 :value-create 'widget-subclass-responsibility
1791 :value-delete 'widget-children-value-delete
1792 :value-get 'widget-value-value-get
1793 :validate 'widget-children-validate
1794 :match (lambda (widget value) (symbolp value)))
1796 (defun custom-convert-widget (widget)
1797 "Initialize :value and :tag from :args in WIDGET."
1798 (let ((args (widget-get widget :args)))
1799 (when args
1800 (widget-put widget :value (widget-apply widget
1801 :value-to-internal (car args)))
1802 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1803 (widget-put widget :args nil)))
1804 widget)
1806 (defun custom-notify (widget &rest args)
1807 "Keep track of changes."
1808 (let ((state (widget-get widget :custom-state)))
1809 (unless (eq state 'modified)
1810 (unless (memq state '(nil unknown hidden))
1811 (widget-put widget :custom-state 'modified))
1812 (custom-magic-reset widget)
1813 (apply 'widget-default-notify widget args))))
1815 (defun custom-redraw (widget)
1816 "Redraw WIDGET with current settings."
1817 (let ((line (count-lines (point-min) (point)))
1818 (column (current-column))
1819 (pos (point))
1820 (from (marker-position (widget-get widget :from)))
1821 (to (marker-position (widget-get widget :to))))
1822 (save-excursion
1823 (widget-value-set widget (widget-value widget))
1824 (custom-redraw-magic widget))
1825 (when (and (>= pos from) (<= pos to))
1826 (condition-case nil
1827 (progn
1828 (if (> column 0)
1829 (goto-line line)
1830 (goto-line (1+ line)))
1831 (move-to-column column))
1832 (error nil)))))
1834 (defun custom-redraw-magic (widget)
1835 "Redraw WIDGET state with current settings."
1836 (while widget
1837 (let ((magic (widget-get widget :custom-magic)))
1838 (cond (magic
1839 (widget-value-set magic (widget-value magic))
1840 (when (setq widget (widget-get widget :group))
1841 (custom-group-state-update widget)))
1843 (setq widget nil)))))
1844 (widget-setup))
1846 (defun custom-show (widget value)
1847 "Non-nil if WIDGET should be shown with VALUE by default."
1848 (let ((show (widget-get widget :custom-show)))
1849 (cond ((null show)
1850 nil)
1851 ((eq t show)
1854 (funcall show widget value)))))
1856 (defun custom-load-widget (widget)
1857 "Load all dependencies for WIDGET."
1858 (custom-load-symbol (widget-value widget)))
1860 (defun custom-unloaded-symbol-p (symbol)
1861 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1862 (let ((found nil)
1863 (loads (get symbol 'custom-loads))
1864 load)
1865 (while loads
1866 (setq load (car loads)
1867 loads (cdr loads))
1868 (cond ((symbolp load)
1869 (unless (featurep load)
1870 (setq found t)))
1871 ((assoc load load-history))
1872 ((assoc (locate-library load) load-history)
1873 (message nil))
1875 (setq found t))))
1876 found))
1878 (defun custom-unloaded-widget-p (widget)
1879 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1880 (custom-unloaded-symbol-p (widget-value widget)))
1882 (defun custom-toggle-hide (widget)
1883 "Toggle visibility of WIDGET."
1884 (custom-load-widget widget)
1885 (let ((state (widget-get widget :custom-state)))
1886 (cond ((memq state '(invalid modified))
1887 (error "There are unset changes"))
1888 ((eq state 'hidden)
1889 (widget-put widget :custom-state 'unknown))
1891 (widget-put widget :documentation-shown nil)
1892 (widget-put widget :custom-state 'hidden)))
1893 (custom-redraw widget)
1894 (widget-setup)))
1896 (defun custom-toggle-parent (widget &rest ignore)
1897 "Toggle visibility of parent of WIDGET."
1898 (custom-toggle-hide (widget-get widget :parent)))
1900 (defun custom-add-see-also (widget &optional prefix)
1901 "Add `See also ...' to WIDGET if there are any links.
1902 Insert PREFIX first if non-nil."
1903 (let* ((symbol (widget-get widget :value))
1904 (links (get symbol 'custom-links))
1905 (many (> (length links) 2))
1906 (buttons (widget-get widget :buttons))
1907 (indent (widget-get widget :indent)))
1908 (when links
1909 (when indent
1910 (insert-char ?\ indent))
1911 (when prefix
1912 (insert prefix))
1913 (insert "See also ")
1914 (while links
1915 (push (widget-create-child-and-convert widget (car links))
1916 buttons)
1917 (setq links (cdr links))
1918 (cond ((null links)
1919 (insert ".\n"))
1920 ((null (cdr links))
1921 (if many
1922 (insert ", and ")
1923 (insert " and ")))
1925 (insert ", "))))
1926 (widget-put widget :buttons buttons))))
1928 (defun custom-add-parent-links (widget &optional initial-string)
1929 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1930 The value if non-nil if any parents were found.
1931 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1932 (let ((name (widget-value widget))
1933 (type (widget-type widget))
1934 (buttons (widget-get widget :buttons))
1935 (start (point))
1936 found)
1937 (insert (or initial-string "Parent groups:"))
1938 (mapatoms (lambda (symbol)
1939 (let ((entry (assq name (get symbol 'custom-group))))
1940 (when (eq (nth 1 entry) type)
1941 (insert " ")
1942 (push (widget-create-child-and-convert
1943 widget 'custom-group-link
1944 :tag (custom-unlispify-tag-name symbol)
1945 symbol)
1946 buttons)
1947 (setq found t)))))
1948 (widget-put widget :buttons buttons)
1949 (if found
1950 (insert "\n")
1951 (delete-region start (point)))
1952 found))
1954 ;;; The `custom-comment' Widget.
1956 ;; like the editable field
1957 (defface custom-comment-face '((((class grayscale color)
1958 (background light))
1959 (:background "gray85"))
1960 (((class grayscale color)
1961 (background dark))
1962 (:background "dim gray"))
1964 (:slant italic)))
1965 "Face used for comments on variables or faces"
1966 :version "21.1"
1967 :group 'custom-faces)
1969 ;; like font-lock-comment-face
1970 (defface custom-comment-tag-face
1971 '((((class color) (background dark)) (:foreground "gray80"))
1972 (((class color) (background light)) (:foreground "blue4"))
1973 (((class grayscale) (background light))
1974 (:foreground "DimGray" :weight bold :slant italic))
1975 (((class grayscale) (background dark))
1976 (:foreground "LightGray" :weight bold :slant italic))
1977 (t (:weight bold)))
1978 "Face used for variables or faces comment tags"
1979 :group 'custom-faces)
1981 (define-widget 'custom-comment 'string
1982 "User comment."
1983 :tag "Comment"
1984 :help-echo "Edit a comment here."
1985 :sample-face 'custom-comment-tag-face
1986 :value-face 'custom-comment-face
1987 :shown nil
1988 :create 'custom-comment-create)
1990 (defun custom-comment-create (widget)
1991 (let* ((null-comment (equal "" (widget-value widget))))
1992 (if (or (widget-get (widget-get widget :parent) :comment-shown)
1993 (not null-comment))
1994 (widget-default-create widget)
1995 ;; `widget-default-delete' expects markers in these slots --
1996 ;; maybe it shouldn't.
1997 (widget-put widget :from (point-marker))
1998 (widget-put widget :to (point-marker)))))
2000 (defun custom-comment-hide (widget)
2001 (widget-put (widget-get widget :parent) :comment-shown nil))
2003 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2004 ;; the global custom one
2005 (defun custom-comment-show (widget)
2006 (widget-put widget :comment-shown t)
2007 (custom-redraw widget)
2008 (widget-setup))
2010 (defun custom-comment-invisible-p (widget)
2011 (let ((val (widget-value (widget-get widget :comment-widget))))
2012 (and (equal "" val)
2013 (not (widget-get widget :comment-shown)))))
2015 ;;; The `custom-variable' Widget.
2017 ;; When this was underlined blue, users confused it with a
2018 ;; Mosaic-style hyperlink...
2019 (defface custom-variable-tag-face
2020 `((((class color)
2021 (background dark))
2022 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
2023 (((class color)
2024 (background light))
2025 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
2026 (t (:weight bold)))
2027 "Face used for unpushable variable tags."
2028 :group 'custom-faces)
2030 (defface custom-variable-button-face '((t (:underline t :weight bold)))
2031 "Face used for pushable variable tags."
2032 :group 'custom-faces)
2034 (defcustom custom-variable-default-form 'edit
2035 "Default form of displaying variable values."
2036 :type '(choice (const edit)
2037 (const lisp))
2038 :group 'custom-buffer
2039 :version "20.3")
2041 (define-widget 'custom-variable 'custom
2042 "Customize variable."
2043 :format "%v"
2044 :help-echo "Set or reset this variable."
2045 :documentation-property 'variable-documentation
2046 :custom-category 'option
2047 :custom-state nil
2048 :custom-menu 'custom-variable-menu-create
2049 :custom-form nil ; defaults to value of `custom-variable-default-form'
2050 :value-create 'custom-variable-value-create
2051 :action 'custom-variable-action
2052 :custom-set 'custom-variable-set
2053 :custom-save 'custom-variable-save
2054 :custom-reset-current 'custom-redraw
2055 :custom-reset-saved 'custom-variable-reset-saved
2056 :custom-reset-standard 'custom-variable-reset-standard
2057 :custom-standard-value 'custom-variable-standard-value)
2059 (defun custom-variable-type (symbol)
2060 "Return a widget suitable for editing the value of SYMBOL.
2061 If SYMBOL has a `custom-type' property, use that.
2062 Otherwise, look up symbol in `custom-guess-type-alist'."
2063 (let* ((type (or (get symbol 'custom-type)
2064 (and (not (get symbol 'standard-value))
2065 (custom-guess-type symbol))
2066 'sexp))
2067 (options (get symbol 'custom-options))
2068 (tmp (if (listp type)
2069 (copy-sequence type)
2070 (list type))))
2071 (when options
2072 (widget-put tmp :options options))
2073 tmp))
2075 (defun custom-variable-value-create (widget)
2076 "Here is where you edit the variable's value."
2077 (custom-load-widget widget)
2078 (unless (widget-get widget :custom-form)
2079 (widget-put widget :custom-form custom-variable-default-form))
2080 (let* ((buttons (widget-get widget :buttons))
2081 (children (widget-get widget :children))
2082 (form (widget-get widget :custom-form))
2083 (state (widget-get widget :custom-state))
2084 (symbol (widget-get widget :value))
2085 (tag (widget-get widget :tag))
2086 (type (custom-variable-type symbol))
2087 (conv (widget-convert type))
2088 (get (or (get symbol 'custom-get) 'default-value))
2089 (prefix (widget-get widget :custom-prefix))
2090 (last (widget-get widget :custom-last))
2091 (value (if (default-boundp symbol)
2092 (funcall get symbol)
2093 (widget-get conv :value))))
2094 ;; If the widget is new, the child determines whether it is hidden.
2095 (cond (state)
2096 ((custom-show type value)
2097 (setq state 'unknown))
2099 (setq state 'hidden)))
2100 ;; If we don't know the state, see if we need to edit it in lisp form.
2101 (when (eq state 'unknown)
2102 (unless (widget-apply conv :match value)
2103 ;; (widget-apply (widget-convert type) :match value)
2104 (setq form 'mismatch)))
2105 ;; Now we can create the child widget.
2106 (cond ((eq custom-buffer-style 'tree)
2107 (insert prefix (if last " `--- " " |--- "))
2108 (push (widget-create-child-and-convert
2109 widget 'custom-browse-variable-tag)
2110 buttons)
2111 (insert " " tag "\n")
2112 (widget-put widget :buttons buttons))
2113 ((eq state 'hidden)
2114 ;; Indicate hidden value.
2115 (push (widget-create-child-and-convert
2116 widget 'item
2117 :format "%{%t%}: "
2118 :sample-face 'custom-variable-tag-face
2119 :tag tag
2120 :parent widget)
2121 buttons)
2122 (push (widget-create-child-and-convert
2123 widget 'visibility
2124 :help-echo "Show the value of this option."
2125 :off "Show Value"
2126 :action 'custom-toggle-parent
2127 nil)
2128 buttons))
2129 ((memq form '(lisp mismatch))
2130 ;; In lisp mode edit the saved value when possible.
2131 (let* ((value (cond ((get symbol 'saved-value)
2132 (car (get symbol 'saved-value)))
2133 ((get symbol 'standard-value)
2134 (car (get symbol 'standard-value)))
2135 ((default-boundp symbol)
2136 (custom-quote (funcall get symbol)))
2138 (custom-quote (widget-get conv :value))))))
2139 (insert (symbol-name symbol) ": ")
2140 (push (widget-create-child-and-convert
2141 widget 'visibility
2142 :help-echo "Hide the value of this option."
2143 :on "Hide Value"
2144 :off "Show Value"
2145 :action 'custom-toggle-parent
2147 buttons)
2148 (insert " ")
2149 (push (widget-create-child-and-convert
2150 widget 'sexp
2151 :button-face 'custom-variable-button-face
2152 :format "%v"
2153 :tag (symbol-name symbol)
2154 :parent widget
2155 :value value)
2156 children)))
2158 ;; Edit mode.
2159 (let* ((format (widget-get type :format))
2160 tag-format value-format)
2161 (unless (string-match ":" format)
2162 (error "Bad format"))
2163 (setq tag-format (substring format 0 (match-end 0)))
2164 (setq value-format (substring format (match-end 0)))
2165 (push (widget-create-child-and-convert
2166 widget 'item
2167 :format tag-format
2168 :action 'custom-tag-action
2169 :help-echo "Change value of this option."
2170 :mouse-down-action 'custom-tag-mouse-down-action
2171 :button-face 'custom-variable-button-face
2172 :sample-face 'custom-variable-tag-face
2173 tag)
2174 buttons)
2175 (insert " ")
2176 (push (widget-create-child-and-convert
2177 widget 'visibility
2178 :help-echo "Hide the value of this option."
2179 :on "Hide Value"
2180 :off "Show Value"
2181 :action 'custom-toggle-parent
2183 buttons)
2184 (push (widget-create-child-and-convert
2185 widget type
2186 :format value-format
2187 :value value)
2188 children))))
2189 (unless (eq custom-buffer-style 'tree)
2190 (unless (eq (preceding-char) ?\n)
2191 (widget-insert "\n"))
2192 ;; Create the magic button.
2193 (let ((magic (widget-create-child-and-convert
2194 widget 'custom-magic nil)))
2195 (widget-put widget :custom-magic magic)
2196 (push magic buttons))
2197 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2198 ;; before the call to `widget-default-format-handler'. Otherwise, I
2199 ;; loose my current `buttons'. This function shouldn't be called like
2200 ;; this anyway. The doc string widget should be added like the others.
2201 ;; --dv
2202 (widget-put widget :buttons buttons)
2203 (insert "\n")
2204 ;; Insert documentation.
2205 (widget-default-format-handler widget ?h)
2207 ;; The comment field
2208 (unless (eq state 'hidden)
2209 (let* ((comment (get symbol 'variable-comment))
2210 (comment-widget
2211 (widget-create-child-and-convert
2212 widget 'custom-comment
2213 :parent widget
2214 :value (or comment ""))))
2215 (widget-put widget :comment-widget comment-widget)
2216 ;; Don't push it !!! Custom assumes that the first child is the
2217 ;; value one.
2218 (setq children (append children (list comment-widget)))))
2219 ;; Update the rest of the properties properties.
2220 (widget-put widget :custom-form form)
2221 (widget-put widget :children children)
2222 ;; Now update the state.
2223 (if (eq state 'hidden)
2224 (widget-put widget :custom-state state)
2225 (custom-variable-state-set widget))
2226 ;; See also.
2227 (unless (eq state 'hidden)
2228 (when (eq (widget-get widget :custom-level) 1)
2229 (custom-add-parent-links widget))
2230 (custom-add-see-also widget)))))
2232 (defun custom-tag-action (widget &rest args)
2233 "Pass :action to first child of WIDGET's parent."
2234 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2235 :action args))
2237 (defun custom-tag-mouse-down-action (widget &rest args)
2238 "Pass :mouse-down-action to first child of WIDGET's parent."
2239 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2240 :mouse-down-action args))
2242 (defun custom-variable-state-set (widget)
2243 "Set the state of WIDGET."
2244 (let* ((symbol (widget-value widget))
2245 (get (or (get symbol 'custom-get) 'default-value))
2246 (value (if (default-boundp symbol)
2247 (funcall get symbol)
2248 (widget-get widget :value)))
2249 (comment (get symbol 'variable-comment))
2251 temp
2252 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2253 (setq temp
2254 (get symbol 'customized-variable-comment))
2255 (or tmp temp))
2256 (if (condition-case nil
2257 (and (equal value (eval (car tmp)))
2258 (equal comment temp))
2259 (error nil))
2260 'set
2261 'changed))
2262 ((progn (setq tmp (get symbol 'saved-value))
2263 (setq temp (get symbol 'saved-variable-comment))
2264 (or tmp temp))
2265 (if (condition-case nil
2266 (and (equal value (eval (car tmp)))
2267 (equal comment temp))
2268 (error nil))
2269 'saved
2270 'changed))
2271 ((setq tmp (get symbol 'standard-value))
2272 (if (condition-case nil
2273 (and (equal value (eval (car tmp)))
2274 (equal comment nil))
2275 (error nil))
2276 'standard
2277 'changed))
2278 (t 'rogue))))
2279 (widget-put widget :custom-state state)))
2281 (defun custom-variable-standard-value (widget)
2282 (get (widget-value widget) 'standard-value))
2284 (defvar custom-variable-menu
2285 '(("Set for Current Session" custom-variable-set
2286 (lambda (widget)
2287 (eq (widget-get widget :custom-state) 'modified)))
2288 ("Save for Future Sessions" custom-variable-save
2289 (lambda (widget)
2290 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2291 ("Reset to Current" custom-redraw
2292 (lambda (widget)
2293 (and (default-boundp (widget-value widget))
2294 (memq (widget-get widget :custom-state) '(modified changed)))))
2295 ("Reset to Saved" custom-variable-reset-saved
2296 (lambda (widget)
2297 (and (or (get (widget-value widget) 'saved-value)
2298 (get (widget-value widget) 'saved-variable-comment))
2299 (memq (widget-get widget :custom-state)
2300 '(modified set changed rogue)))))
2301 ("Erase Customization" custom-variable-reset-standard
2302 (lambda (widget)
2303 (and (get (widget-value widget) 'standard-value)
2304 (memq (widget-get widget :custom-state)
2305 '(modified set changed saved rogue)))))
2306 ("---" ignore ignore)
2307 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2308 ("---" ignore ignore)
2309 ("Don't show as Lisp expression" custom-variable-edit
2310 (lambda (widget)
2311 (eq (widget-get widget :custom-form) 'lisp)))
2312 ("Show initial Lisp expression" custom-variable-edit-lisp
2313 (lambda (widget)
2314 (eq (widget-get widget :custom-form) 'edit))))
2315 "Alist of actions for the `custom-variable' widget.
2316 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2317 the menu entry, ACTION is the function to call on the widget when the
2318 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2319 widget as an argument, and returns non-nil if ACTION is valid on that
2320 widget. If FILTER is nil, ACTION is always valid.")
2322 (defun custom-variable-action (widget &optional event)
2323 "Show the menu for `custom-variable' WIDGET.
2324 Optional EVENT is the location for the menu."
2325 (if (eq (widget-get widget :custom-state) 'hidden)
2326 (custom-toggle-hide widget)
2327 (unless (eq (widget-get widget :custom-state) 'modified)
2328 (custom-variable-state-set widget))
2329 (custom-redraw-magic widget)
2330 (let* ((completion-ignore-case t)
2331 (answer (widget-choose (concat "Operation on "
2332 (custom-unlispify-tag-name
2333 (widget-get widget :value)))
2334 (custom-menu-filter custom-variable-menu
2335 widget)
2336 event)))
2337 (if answer
2338 (funcall answer widget)))))
2340 (defun custom-variable-edit (widget)
2341 "Edit value of WIDGET."
2342 (widget-put widget :custom-state 'unknown)
2343 (widget-put widget :custom-form 'edit)
2344 (custom-redraw widget))
2346 (defun custom-variable-edit-lisp (widget)
2347 "Edit the Lisp representation of the value of WIDGET."
2348 (widget-put widget :custom-state 'unknown)
2349 (widget-put widget :custom-form 'lisp)
2350 (custom-redraw widget))
2352 (defun custom-variable-set (widget)
2353 "Set the current value for the variable being edited by WIDGET."
2354 (let* ((form (widget-get widget :custom-form))
2355 (state (widget-get widget :custom-state))
2356 (child (car (widget-get widget :children)))
2357 (symbol (widget-value widget))
2358 (set (or (get symbol 'custom-set) 'set-default))
2359 (comment-widget (widget-get widget :comment-widget))
2360 (comment (widget-value comment-widget))
2361 val)
2362 (cond ((eq state 'hidden)
2363 (error "Cannot set hidden variable"))
2364 ((setq val (widget-apply child :validate))
2365 (goto-char (widget-get val :from))
2366 (error "%s" (widget-get val :error)))
2367 ((memq form '(lisp mismatch))
2368 (when (equal comment "")
2369 (setq comment nil)
2370 ;; Make the comment invisible by hand if it's empty
2371 (custom-comment-hide comment-widget))
2372 (funcall set symbol (eval (setq val (widget-value child))))
2373 (put symbol 'customized-value (list val))
2374 (put symbol 'variable-comment comment)
2375 (put symbol 'customized-variable-comment comment))
2377 (when (equal comment "")
2378 (setq comment nil)
2379 ;; Make the comment invisible by hand if it's empty
2380 (custom-comment-hide comment-widget))
2381 (funcall set symbol (setq val (widget-value child)))
2382 (put symbol 'customized-value (list (custom-quote val)))
2383 (put symbol 'variable-comment comment)
2384 (put symbol 'customized-variable-comment comment)))
2385 (custom-variable-state-set widget)
2386 (custom-redraw-magic widget)))
2388 (defun custom-variable-save (widget)
2389 "Set and save the value for the variable being edited by WIDGET."
2390 (let* ((form (widget-get widget :custom-form))
2391 (state (widget-get widget :custom-state))
2392 (child (car (widget-get widget :children)))
2393 (symbol (widget-value widget))
2394 (set (or (get symbol 'custom-set) 'set-default))
2395 (comment-widget (widget-get widget :comment-widget))
2396 (comment (widget-value comment-widget))
2397 val)
2398 (cond ((eq state 'hidden)
2399 (error "Cannot set hidden variable"))
2400 ((setq val (widget-apply child :validate))
2401 (goto-char (widget-get val :from))
2402 (error "Saving %s: %s" symbol (widget-get val :error)))
2403 ((memq form '(lisp mismatch))
2404 (when (equal comment "")
2405 (setq comment nil)
2406 ;; Make the comment invisible by hand if it's empty
2407 (custom-comment-hide comment-widget))
2408 (put symbol 'saved-value (list (widget-value child)))
2409 (funcall set symbol (eval (widget-value child)))
2410 (put symbol 'variable-comment comment)
2411 (put symbol 'saved-variable-comment comment))
2413 (when (equal comment "")
2414 (setq comment nil)
2415 ;; Make the comment invisible by hand if it's empty
2416 (custom-comment-hide comment-widget))
2417 (put symbol 'saved-value
2418 (list (custom-quote (widget-value child))))
2419 (funcall set symbol (widget-value child))
2420 (put symbol 'variable-comment comment)
2421 (put symbol 'saved-variable-comment comment)))
2422 (put symbol 'customized-value nil)
2423 (put symbol 'customized-variable-comment nil)
2424 (custom-save-all)
2425 (custom-variable-state-set widget)
2426 (custom-redraw-magic widget)))
2428 (defun custom-variable-reset-saved (widget)
2429 "Restore the saved value for the variable being edited by WIDGET."
2430 (let* ((symbol (widget-value widget))
2431 (set (or (get symbol 'custom-set) 'set-default))
2432 (value (get symbol 'saved-value))
2433 (comment (get symbol 'saved-variable-comment)))
2434 (cond ((or value comment)
2435 (put symbol 'variable-comment comment)
2436 (condition-case nil
2437 (funcall set symbol (eval (car value)))
2438 (error nil)))
2440 (error "No saved value for %s" symbol)))
2441 (put symbol 'customized-value nil)
2442 (put symbol 'customized-variable-comment nil)
2443 (widget-put widget :custom-state 'unknown)
2444 ;; This call will possibly make the comment invisible
2445 (custom-redraw widget)))
2447 (defun custom-variable-reset-standard (widget)
2448 "Restore the standard setting for the variable being edited by WIDGET.
2449 This operation eliminates any saved setting for the variable,
2450 restoring it to the state of a variable that has never been customized."
2451 (let* ((symbol (widget-value widget))
2452 (set (or (get symbol 'custom-set) 'set-default)))
2453 (if (get symbol 'standard-value)
2454 (funcall set symbol (eval (car (get symbol 'standard-value))))
2455 (error "No standard setting known for %S" symbol))
2456 (put symbol 'variable-comment nil)
2457 (put symbol 'customized-value nil)
2458 (put symbol 'customized-variable-comment nil)
2459 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2460 (put symbol 'saved-value nil)
2461 (put symbol 'saved-variable-comment nil)
2462 (custom-save-all))
2463 (widget-put widget :custom-state 'unknown)
2464 ;; This call will possibly make the comment invisible
2465 (custom-redraw widget)))
2467 ;;; The `custom-face-edit' Widget.
2469 (define-widget 'custom-face-edit 'checklist
2470 "Edit face attributes."
2471 :format "%t: %v"
2472 :tag "Attributes"
2473 :extra-offset 12
2474 :button-args '(:help-echo "Control whether this attribute has any effect.")
2475 :value-to-internal 'custom-face-edit-fix-value
2476 :match (lambda (widget value)
2477 (widget-checklist-match widget
2478 (custom-face-edit-fix-value widget value)))
2479 :convert-widget 'custom-face-edit-convert-widget
2480 :args (mapcar (lambda (att)
2481 (list 'group
2482 :inline t
2483 :sibling-args (widget-get (nth 1 att) :sibling-args)
2484 (list 'const :format "" :value (nth 0 att))
2485 (nth 1 att)))
2486 custom-face-attributes))
2488 (defun custom-face-edit-fix-value (widget value)
2489 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form."
2490 (if (listp value)
2491 (let (result)
2492 (while value
2493 (let ((key (car value))
2494 (val (car (cdr value))))
2495 (cond ((eq key :italic)
2496 (push :slant result)
2497 (push (if val 'italic 'normal) result))
2498 ((eq key :bold)
2499 (push :weight result)
2500 (push (if val 'bold 'normal) result))
2502 (push key result)
2503 (push val result))))
2504 (setq value (cdr (cdr value))))
2505 (setq result (nreverse result))
2506 result)
2507 value))
2509 (defun custom-face-edit-convert-widget (widget)
2510 "Convert :args as widget types in WIDGET."
2511 (widget-put
2512 widget
2513 :args (mapcar (lambda (arg)
2514 (widget-convert arg
2515 :deactivate 'custom-face-edit-deactivate
2516 :activate 'custom-face-edit-activate
2517 :delete 'custom-face-edit-delete))
2518 (widget-get widget :args)))
2519 widget)
2521 (defun custom-face-edit-deactivate (widget)
2522 "Make face widget WIDGET inactive for user modifications."
2523 (unless (widget-get widget :inactive)
2524 (let ((tag (custom-face-edit-attribute-tag widget))
2525 (from (copy-marker (widget-get widget :from)))
2526 (to (widget-get widget :to))
2527 (value (widget-value widget))
2528 (inhibit-read-only t)
2529 (inhibit-modification-hooks t))
2530 (save-excursion
2531 (goto-char from)
2532 (widget-default-delete widget)
2533 (insert tag ": *\n")
2534 (widget-put widget :inactive
2535 (cons value (cons from (- (point) from))))))))
2537 (defun custom-face-edit-activate (widget)
2538 "Make face widget WIDGET inactive for user modifications."
2539 (let ((inactive (widget-get widget :inactive))
2540 (inhibit-read-only t)
2541 (inhibit-modification-hooks t))
2542 (when (consp inactive)
2543 (save-excursion
2544 (goto-char (car (cdr inactive)))
2545 (delete-region (point) (+ (point) (cdr (cdr inactive))))
2546 (widget-put widget :inactive nil)
2547 (widget-apply widget :create)
2548 (widget-value-set widget (car inactive))
2549 (widget-setup)))))
2551 (defun custom-face-edit-delete (widget)
2552 "Remove widget from the buffer."
2553 (let ((inactive (widget-get widget :inactive))
2554 (inhibit-read-only t)
2555 (inhibit-modification-hooks t))
2556 (if (not inactive)
2557 ;; Widget is alive, we don't have to do anything special
2558 (widget-default-delete widget)
2559 ;; WIDGET is already deleted because we did so to inactivate it;
2560 ;; now just get rid of the label we put in its place.
2561 (delete-region (car (cdr inactive))
2562 (+ (car (cdr inactive)) (cdr (cdr inactive))))
2563 (widget-put widget :inactive nil))))
2566 (defun custom-face-edit-attribute-tag (widget)
2567 "Returns the first :tag property in WIDGET or one of its children."
2568 (let ((tag (widget-get widget :tag)))
2569 (or (and (not (equal tag "")) tag)
2570 (let ((children (widget-get widget :children)))
2571 (while (and (null tag) children)
2572 (setq tag (custom-face-edit-attribute-tag (pop children))))
2573 tag))))
2575 ;;; The `custom-display' Widget.
2577 (define-widget 'custom-display 'menu-choice
2578 "Select a display type."
2579 :tag "Display"
2580 :value t
2581 :help-echo "Specify frames where the face attributes should be used."
2582 :args '((const :tag "all" t)
2583 (checklist
2584 :offset 0
2585 :extra-offset 9
2586 :args ((group :sibling-args (:help-echo "\
2587 Only match the specified window systems.")
2588 (const :format "Type: "
2589 type)
2590 (checklist :inline t
2591 :offset 0
2592 (const :format "X "
2593 :sibling-args (:help-echo "\
2594 The X11 Window System.")
2596 (const :format "PM "
2597 :sibling-args (:help-echo "\
2598 OS/2 Presentation Manager.")
2600 (const :format "W32 "
2601 :sibling-args (:help-echo "\
2602 Windows NT/9X.")
2603 w32)
2604 (const :format "DOS "
2605 :sibling-args (:help-echo "\
2606 Plain MS-DOS.")
2608 (const :format "TTY%n"
2609 :sibling-args (:help-echo "\
2610 Plain text terminals.")
2611 tty)))
2612 (group :sibling-args (:help-echo "\
2613 Only match the frames with the specified color support.")
2614 (const :format "Class: "
2615 class)
2616 (checklist :inline t
2617 :offset 0
2618 (const :format "Color "
2619 :sibling-args (:help-echo "\
2620 Match color frames.")
2621 color)
2622 (const :format "Grayscale "
2623 :sibling-args (:help-echo "\
2624 Match grayscale frames.")
2625 grayscale)
2626 (const :format "Monochrome%n"
2627 :sibling-args (:help-echo "\
2628 Match frames with no color support.")
2629 mono)))
2630 (group :sibling-args (:help-echo "\
2631 Only match frames with the specified intensity.")
2632 (const :format "\
2633 Background brightness: "
2634 background)
2635 (checklist :inline t
2636 :offset 0
2637 (const :format "Light "
2638 :sibling-args (:help-echo "\
2639 Match frames with light backgrounds.")
2640 light)
2641 (const :format "Dark\n"
2642 :sibling-args (:help-echo "\
2643 Match frames with dark backgrounds.")
2644 dark)))
2645 (group :sibling-args (:help-echo "\
2646 Only match frames that support the specified face attributes.")
2647 (const :format "Supports attributes:" supports)
2648 (custom-face-edit :inline t :format "%n%v"))))))
2650 ;;; The `custom-face' Widget.
2652 (defface custom-face-tag-face
2653 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
2654 "Face used for face tags."
2655 :group 'custom-faces)
2657 (defcustom custom-face-default-form 'selected
2658 "Default form of displaying face definition."
2659 :type '(choice (const all)
2660 (const selected)
2661 (const lisp))
2662 :group 'custom-buffer
2663 :version "20.3")
2665 (define-widget 'custom-face 'custom
2666 "Customize face."
2667 :sample-face 'custom-face-tag-face
2668 :help-echo "Set or reset this face."
2669 :documentation-property #'face-doc-string
2670 :value-create 'custom-face-value-create
2671 :action 'custom-face-action
2672 :custom-category 'face
2673 :custom-form nil ; defaults to value of `custom-face-default-form'
2674 :custom-set 'custom-face-set
2675 :custom-save 'custom-face-save
2676 :custom-reset-current 'custom-redraw
2677 :custom-reset-saved 'custom-face-reset-saved
2678 :custom-reset-standard 'custom-face-reset-standard
2679 :custom-standard-value 'custom-face-standard-value
2680 :custom-menu 'custom-face-menu-create)
2682 (define-widget 'custom-face-all 'editable-list
2683 "An editable list of display specifications and attributes."
2684 :entry-format "%i %d %v"
2685 :insert-button-args '(:help-echo "Insert new display specification here.")
2686 :append-button-args '(:help-echo "Append new display specification here.")
2687 :delete-button-args '(:help-echo "Delete this display specification.")
2688 :args '((group :format "%v" custom-display custom-face-edit)))
2690 (defconst custom-face-all (widget-convert 'custom-face-all)
2691 "Converted version of the `custom-face-all' widget.")
2693 (define-widget 'custom-display-unselected 'item
2694 "A display specification that doesn't match the selected display."
2695 :match 'custom-display-unselected-match)
2697 (defun custom-display-unselected-match (widget value)
2698 "Non-nil if VALUE is an unselected display specification."
2699 (not (face-spec-set-match-display value (selected-frame))))
2701 (define-widget 'custom-face-selected 'group
2702 "Edit the attributes of the selected display in a face specification."
2703 :args '((repeat :format ""
2704 :inline t
2705 (group custom-display-unselected sexp))
2706 (group (sexp :format "") custom-face-edit)
2707 (repeat :format ""
2708 :inline t
2709 sexp)))
2711 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2712 "Converted version of the `custom-face-selected' widget.")
2714 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
2715 "Return a canonicalized version of SPEC using.
2716 FILTER-INDEX is the index in the entry for each attribute in
2717 `custom-face-attributes' at which the appropriate filter function can be
2718 found, and DEFAULT-FILTER is the filter to apply for attributes that
2719 don't specify one."
2720 (mapcar (lambda (entry)
2721 ;; Filter a single face-spec entry
2722 (let ((tests (car entry))
2723 (unfiltered-attrs
2724 ;; Handle both old- and new-style attribute syntax
2725 (if (listp (car (cdr entry)))
2726 (car (cdr entry))
2727 (cdr entry)))
2728 (filtered-attrs nil))
2729 ;; Filter each face attribute
2730 (while unfiltered-attrs
2731 (let* ((attr (pop unfiltered-attrs))
2732 (pre-filtered-value (pop unfiltered-attrs))
2733 (filter
2734 (or (nth filter-index (assq attr custom-face-attributes))
2735 default-filter))
2736 (filtered-value
2737 (if filter
2738 (funcall filter pre-filtered-value)
2739 pre-filtered-value)))
2740 (push filtered-value filtered-attrs)
2741 (push attr filtered-attrs)))
2743 (list tests filtered-attrs)))
2744 spec))
2746 (defun custom-pre-filter-face-spec (spec)
2747 "Return SPEC changed as necessary for editing by the face customization widget.
2748 SPEC must be a full face spec."
2749 (custom-filter-face-spec spec 2))
2751 (defun custom-post-filter-face-spec (spec)
2752 "Return the customized SPEC in a form suitable for setting the face."
2753 (custom-filter-face-spec spec 3))
2755 (defun custom-face-value-create (widget)
2756 "Create a list of the display specifications for WIDGET."
2757 (let ((buttons (widget-get widget :buttons))
2758 children
2759 (symbol (widget-get widget :value))
2760 (tag (widget-get widget :tag))
2761 (state (widget-get widget :custom-state))
2762 (begin (point))
2763 (is-last (widget-get widget :custom-last))
2764 (prefix (widget-get widget :custom-prefix)))
2765 (unless tag
2766 (setq tag (prin1-to-string symbol)))
2767 (cond ((eq custom-buffer-style 'tree)
2768 (insert prefix (if is-last " `--- " " |--- "))
2769 (push (widget-create-child-and-convert
2770 widget 'custom-browse-face-tag)
2771 buttons)
2772 (insert " " tag "\n")
2773 (widget-put widget :buttons buttons))
2775 ;; Create tag.
2776 (insert tag)
2777 (widget-specify-sample widget begin (point))
2778 (if (eq custom-buffer-style 'face)
2779 (insert " ")
2780 (if (string-match "face\\'" tag)
2781 (insert ":")
2782 (insert " face: ")))
2783 ;; Sample.
2784 (push (widget-create-child-and-convert widget 'item
2785 :format "(%{%t%})"
2786 :sample-face symbol
2787 :tag "sample")
2788 buttons)
2789 ;; Visibility.
2790 (insert " ")
2791 (push (widget-create-child-and-convert
2792 widget 'visibility
2793 :help-echo "Hide or show this face."
2794 :on "Hide Face"
2795 :off "Show Face"
2796 :action 'custom-toggle-parent
2797 (not (eq state 'hidden)))
2798 buttons)
2799 ;; Magic.
2800 (insert "\n")
2801 (let ((magic (widget-create-child-and-convert
2802 widget 'custom-magic nil)))
2803 (widget-put widget :custom-magic magic)
2804 (push magic buttons))
2805 ;; Update buttons.
2806 (widget-put widget :buttons buttons)
2807 ;; Insert documentation.
2808 (widget-default-format-handler widget ?h)
2809 ;; The comment field
2810 (unless (eq state 'hidden)
2811 (let* ((comment (get symbol 'face-comment))
2812 (comment-widget
2813 (widget-create-child-and-convert
2814 widget 'custom-comment
2815 :parent widget
2816 :value (or comment ""))))
2817 (widget-put widget :comment-widget comment-widget)
2818 (push comment-widget children)))
2819 ;; See also.
2820 (unless (eq state 'hidden)
2821 (when (eq (widget-get widget :custom-level) 1)
2822 (custom-add-parent-links widget))
2823 (custom-add-see-also widget))
2824 ;; Editor.
2825 (unless (eq (preceding-char) ?\n)
2826 (insert "\n"))
2827 (unless (eq state 'hidden)
2828 (message "Creating face editor...")
2829 (custom-load-widget widget)
2830 (unless (widget-get widget :custom-form)
2831 (widget-put widget :custom-form custom-face-default-form))
2832 (let* ((symbol (widget-value widget))
2833 (spec (or (get symbol 'customized-face)
2834 (get symbol 'saved-face)
2835 (get symbol 'face-defface-spec)
2836 ;; Attempt to construct it.
2837 (list (list t (custom-face-attributes-get
2838 symbol (selected-frame))))))
2839 (form (widget-get widget :custom-form))
2840 (indent (widget-get widget :indent))
2841 edit)
2842 ;; If the user has changed this face in some other way,
2843 ;; edit it as the user has specified it.
2844 (if (not (face-spec-match-p symbol spec (selected-frame)))
2845 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
2846 (setq spec (custom-pre-filter-face-spec spec))
2847 (setq edit (widget-create-child-and-convert
2848 widget
2849 (cond ((and (eq form 'selected)
2850 (widget-apply custom-face-selected
2851 :match spec))
2852 (when indent (insert-char ?\ indent))
2853 'custom-face-selected)
2854 ((and (not (eq form 'lisp))
2855 (widget-apply custom-face-all
2856 :match spec))
2857 'custom-face-all)
2859 (when indent (insert-char ?\ indent))
2860 'sexp))
2861 :value spec))
2862 (custom-face-state-set widget)
2863 (push edit children)
2864 (widget-put widget :children children))
2865 (message "Creating face editor...done"))))))
2867 (defvar custom-face-menu
2868 '(("Set for Current Session" custom-face-set)
2869 ("Save for Future Sessions" custom-face-save-command)
2870 ("Reset to Saved" custom-face-reset-saved
2871 (lambda (widget)
2872 (or (get (widget-value widget) 'saved-face)
2873 (get (widget-value widget) 'saved-face-comment))))
2874 ("Erase Customization" custom-face-reset-standard
2875 (lambda (widget)
2876 (get (widget-value widget) 'face-defface-spec)))
2877 ("---" ignore ignore)
2878 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2879 ("---" ignore ignore)
2880 ("Show all display specs" custom-face-edit-all
2881 (lambda (widget)
2882 (not (eq (widget-get widget :custom-form) 'all))))
2883 ("Just current attributes" custom-face-edit-selected
2884 (lambda (widget)
2885 (not (eq (widget-get widget :custom-form) 'selected))))
2886 ("Show as Lisp expression" custom-face-edit-lisp
2887 (lambda (widget)
2888 (not (eq (widget-get widget :custom-form) 'lisp)))))
2889 "Alist of actions for the `custom-face' widget.
2890 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2891 the menu entry, ACTION is the function to call on the widget when the
2892 menu is selected, and FILTER is a predicate which takes a `custom-face'
2893 widget as an argument, and returns non-nil if ACTION is valid on that
2894 widget. If FILTER is nil, ACTION is always valid.")
2896 (defun custom-face-edit-selected (widget)
2897 "Edit selected attributes of the value of WIDGET."
2898 (widget-put widget :custom-state 'unknown)
2899 (widget-put widget :custom-form 'selected)
2900 (custom-redraw widget))
2902 (defun custom-face-edit-all (widget)
2903 "Edit all attributes of the value of WIDGET."
2904 (widget-put widget :custom-state 'unknown)
2905 (widget-put widget :custom-form 'all)
2906 (custom-redraw widget))
2908 (defun custom-face-edit-lisp (widget)
2909 "Edit the Lisp representation of the value of WIDGET."
2910 (widget-put widget :custom-state 'unknown)
2911 (widget-put widget :custom-form 'lisp)
2912 (custom-redraw widget))
2914 (defun custom-face-state-set (widget)
2915 "Set the state of WIDGET."
2916 (let* ((symbol (widget-value widget))
2917 (comment (get symbol 'face-comment))
2918 tmp temp)
2919 (widget-put widget :custom-state
2920 (cond ((progn
2921 (setq tmp (get symbol 'customized-face))
2922 (setq temp (get symbol 'customized-face-comment))
2923 (or tmp temp))
2924 (if (equal temp comment)
2925 'set
2926 'changed))
2927 ((progn
2928 (setq tmp (get symbol 'saved-face))
2929 (setq temp (get symbol 'saved-face-comment))
2930 (or tmp temp))
2931 (if (equal temp comment)
2932 'saved
2933 'changed))
2934 ((get symbol 'face-defface-spec)
2935 (if (equal comment nil)
2936 'standard
2937 'changed))
2939 'rogue)))))
2941 (defun custom-face-action (widget &optional event)
2942 "Show the menu for `custom-face' WIDGET.
2943 Optional EVENT is the location for the menu."
2944 (if (eq (widget-get widget :custom-state) 'hidden)
2945 (custom-toggle-hide widget)
2946 (let* ((completion-ignore-case t)
2947 (symbol (widget-get widget :value))
2948 (answer (widget-choose (concat "Operation on "
2949 (custom-unlispify-tag-name symbol))
2950 (custom-menu-filter custom-face-menu
2951 widget)
2952 event)))
2953 (if answer
2954 (funcall answer widget)))))
2956 (defun custom-face-set (widget)
2957 "Make the face attributes in WIDGET take effect."
2958 (let* ((symbol (widget-value widget))
2959 (child (car (widget-get widget :children)))
2960 (value (custom-post-filter-face-spec (widget-value child)))
2961 (comment-widget (widget-get widget :comment-widget))
2962 (comment (widget-value comment-widget)))
2963 (when (equal comment "")
2964 (setq comment nil)
2965 ;; Make the comment invisible by hand if it's empty
2966 (custom-comment-hide comment-widget))
2967 (put symbol 'customized-face value)
2968 (if (face-spec-choose value)
2969 (face-spec-set symbol value)
2970 ;; face-set-spec ignores empty attribute lists, so just give it
2971 ;; something harmless instead.
2972 (face-spec-set symbol '((t :foreground unspecified))))
2973 (put symbol 'customized-face-comment comment)
2974 (put symbol 'face-comment comment)
2975 (custom-face-state-set widget)
2976 (custom-redraw-magic widget)))
2978 (defun custom-face-save-command (widget)
2979 "Save in `.emacs' the face attributes in WIDGET."
2980 (custom-face-save widget)
2981 (custom-save-all))
2983 (defun custom-face-save (widget)
2984 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2985 (let* ((symbol (widget-value widget))
2986 (child (car (widget-get widget :children)))
2987 (value (custom-post-filter-face-spec (widget-value child)))
2988 (comment-widget (widget-get widget :comment-widget))
2989 (comment (widget-value comment-widget)))
2990 (when (equal comment "")
2991 (setq comment nil)
2992 ;; Make the comment invisible by hand if it's empty
2993 (custom-comment-hide comment-widget))
2994 (if (face-spec-choose value)
2995 (face-spec-set symbol value)
2996 ;; face-set-spec ignores empty attribute lists, so just give it
2997 ;; something harmless instead.
2998 (face-spec-set symbol '((t :foreground unspecified))))
2999 (unless (eq (widget-get widget :custom-state) 'standard)
3000 (put symbol 'saved-face value))
3001 (put symbol 'customized-face nil)
3002 (put symbol 'face-comment comment)
3003 (put symbol 'customized-face-comment nil)
3004 (put symbol 'saved-face-comment comment)
3005 (custom-save-all)
3006 (custom-face-state-set widget)
3007 (custom-redraw-magic widget)))
3009 (defun custom-face-reset-saved (widget)
3010 "Restore WIDGET to the face's default attributes."
3011 (let* ((symbol (widget-value widget))
3012 (child (car (widget-get widget :children)))
3013 (value (get symbol 'saved-face))
3014 (comment (get symbol 'saved-face-comment))
3015 (comment-widget (widget-get widget :comment-widget)))
3016 (unless (or value comment)
3017 (error "No saved value for this face"))
3018 (put symbol 'customized-face nil)
3019 (put symbol 'customized-face-comment nil)
3020 (face-spec-set symbol value)
3021 (put symbol 'face-comment comment)
3022 (widget-value-set child value)
3023 ;; This call manages the comment visibility
3024 (widget-value-set comment-widget (or comment ""))
3025 (custom-face-state-set widget)
3026 (custom-redraw-magic widget)))
3028 (defun custom-face-standard-value (widget)
3029 (get (widget-value widget) 'face-defface-spec))
3031 (defun custom-face-reset-standard (widget)
3032 "Restore WIDGET to the face's standard settings.
3033 This operation eliminates any saved setting for the face,
3034 restoring it to the state of a face that has never been customized."
3035 (let* ((symbol (widget-value widget))
3036 (child (car (widget-get widget :children)))
3037 (value (get symbol 'face-defface-spec))
3038 (comment-widget (widget-get widget :comment-widget)))
3039 (unless value
3040 (error "No standard setting for this face"))
3041 (put symbol 'customized-face nil)
3042 (put symbol 'customized-face-comment nil)
3043 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3044 (put symbol 'saved-face nil)
3045 (put symbol 'saved-face-comment nil)
3046 (custom-save-all))
3047 (face-spec-set symbol value)
3048 (put symbol 'face-comment nil)
3049 (widget-value-set child value)
3050 ;; This call manages the comment visibility
3051 (widget-value-set comment-widget "")
3052 (custom-face-state-set widget)
3053 (custom-redraw-magic widget)))
3055 ;;; The `face' Widget.
3057 (define-widget 'face 'default
3058 "Select and customize a face."
3059 :convert-widget 'widget-value-convert-widget
3060 :button-prefix 'widget-push-button-prefix
3061 :button-suffix 'widget-push-button-suffix
3062 :format "%{%t%}: %[select face%] %v"
3063 :tag "Face"
3064 :value 'default
3065 :value-create 'widget-face-value-create
3066 :value-delete 'widget-face-value-delete
3067 :value-get 'widget-value-value-get
3068 :validate 'widget-children-validate
3069 :action 'widget-face-action
3070 :match (lambda (widget value) (symbolp value)))
3072 (defun widget-face-value-create (widget)
3073 "Create a `custom-face' child."
3074 (let* ((symbol (widget-value widget))
3075 (custom-buffer-style 'face)
3076 (child (widget-create-child-and-convert
3077 widget 'custom-face
3078 :custom-level nil
3079 :value symbol)))
3080 (custom-magic-reset child)
3081 (setq custom-options (cons child custom-options))
3082 (widget-put widget :children (list child))))
3084 (defun widget-face-value-delete (widget)
3085 "Remove the child from the options."
3086 (let ((child (car (widget-get widget :children))))
3087 (setq custom-options (delq child custom-options))
3088 (widget-children-value-delete widget)))
3090 (defvar face-history nil
3091 "History of entered face names.")
3093 (defun widget-face-action (widget &optional event)
3094 "Prompt for a face."
3095 (let ((answer (completing-read "Face: "
3096 (mapcar (lambda (face)
3097 (list (symbol-name face)))
3098 (face-list))
3099 nil nil nil
3100 'face-history)))
3101 (unless (zerop (length answer))
3102 (widget-value-set widget (intern answer))
3103 (widget-apply widget :notify widget event)
3104 (widget-setup))))
3106 ;;; The `hook' Widget.
3108 (define-widget 'hook 'list
3109 "A emacs lisp hook"
3110 :value-to-internal (lambda (widget value)
3111 (if (and value (symbolp value))
3112 (list value)
3113 value))
3114 :match (lambda (widget value)
3115 (or (symbolp value)
3116 (widget-group-match widget value)))
3117 ;; Avoid adding undefined functions to the hook, especially for
3118 ;; things like `find-file-hook' or even more basic ones, to avoid
3119 ;; chaos.
3120 :set (lambda (symbol value)
3121 (dolist (elt value)
3122 (if (fboundp elt)
3123 (add-hook symbol elt))))
3124 :convert-widget 'custom-hook-convert-widget
3125 :tag "Hook")
3127 (defun custom-hook-convert-widget (widget)
3128 ;; Handle `:options'.
3129 (let* ((options (widget-get widget :options))
3130 (other `(editable-list :inline t
3131 :entry-format "%i %d%v"
3132 (function :format " %v")))
3133 (args (if options
3134 (list `(checklist :inline t
3135 ,@(mapcar (lambda (entry)
3136 `(function-item ,entry))
3137 options))
3138 other)
3139 (list other))))
3140 (widget-put widget :args args)
3141 widget))
3143 ;;; The `custom-group-link' Widget.
3145 (define-widget 'custom-group-link 'link
3146 "Show parent in other window when activated."
3147 :help-echo "Create customization buffer for this group."
3148 :action 'custom-group-link-action)
3150 (defun custom-group-link-action (widget &rest ignore)
3151 (customize-group (widget-value widget)))
3153 ;;; The `custom-group' Widget.
3155 (defcustom custom-group-tag-faces nil
3156 ;; In XEmacs, this ought to play games with font size.
3157 ;; Fixme: make it do so in Emacs.
3158 "Face used for group tags.
3159 The first member is used for level 1 groups, the second for level 2,
3160 and so forth. The remaining group tags are shown with
3161 `custom-group-tag-face'."
3162 :type '(repeat face)
3163 :group 'custom-faces)
3165 (defface custom-group-tag-face-1
3166 `((((class color)
3167 (background dark))
3168 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3169 (((class color)
3170 (background light))
3171 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3172 (t (:weight bold)))
3173 "Face used for group tags."
3174 :group 'custom-faces)
3176 (defface custom-group-tag-face
3177 `((((class color)
3178 (background dark))
3179 (:foreground "light blue" :weight bold :height 1.2))
3180 (((class color)
3181 (background light))
3182 (:foreground "blue" :weight bold :height 1.2))
3183 (t (:weight bold)))
3184 "Face used for low level group tags."
3185 :group 'custom-faces)
3187 (define-widget 'custom-group 'custom
3188 "Customize group."
3189 :format "%v"
3190 :sample-face-get 'custom-group-sample-face-get
3191 :documentation-property 'group-documentation
3192 :help-echo "Set or reset all members of this group."
3193 :value-create 'custom-group-value-create
3194 :action 'custom-group-action
3195 :custom-category 'group
3196 :custom-set 'custom-group-set
3197 :custom-save 'custom-group-save
3198 :custom-reset-current 'custom-group-reset-current
3199 :custom-reset-saved 'custom-group-reset-saved
3200 :custom-reset-standard 'custom-group-reset-standard
3201 :custom-menu 'custom-group-menu-create)
3203 (defun custom-group-sample-face-get (widget)
3204 ;; Use :sample-face.
3205 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3206 'custom-group-tag-face))
3208 (define-widget 'custom-group-visibility 'visibility
3209 "An indicator and manipulator for hidden group contents."
3210 :create 'custom-group-visibility-create)
3212 (defun custom-group-visibility-create (widget)
3213 (let ((visible (widget-value widget)))
3214 (if visible
3215 (insert "--------")))
3216 (widget-default-create widget))
3218 (defun custom-group-members (symbol groups-only)
3219 "Return SYMBOL's custom group members.
3220 If GROUPS-ONLY non-nil, return only those members that are groups."
3221 (if (not groups-only)
3222 (get symbol 'custom-group)
3223 (let (members)
3224 (dolist (entry (get symbol 'custom-group))
3225 (when (eq (nth 1 entry) 'custom-group)
3226 (push entry members)))
3227 (nreverse members))))
3229 (defun custom-group-value-create (widget)
3230 "Insert a customize group for WIDGET in the current buffer."
3231 (let* ((state (widget-get widget :custom-state))
3232 (level (widget-get widget :custom-level))
3233 ;; (indent (widget-get widget :indent))
3234 (prefix (widget-get widget :custom-prefix))
3235 (buttons (widget-get widget :buttons))
3236 (tag (widget-get widget :tag))
3237 (symbol (widget-value widget))
3238 (members (custom-group-members symbol
3239 (and (eq custom-buffer-style 'tree)
3240 custom-browse-only-groups))))
3241 (cond ((and (eq custom-buffer-style 'tree)
3242 (eq state 'hidden)
3243 (or members (custom-unloaded-widget-p widget)))
3244 (custom-browse-insert-prefix prefix)
3245 (push (widget-create-child-and-convert
3246 widget 'custom-browse-visibility
3247 ;; :tag-glyph "plus"
3248 :tag "+")
3249 buttons)
3250 (insert "-- ")
3251 ;; (widget-glyph-insert nil "-- " "horizontal")
3252 (push (widget-create-child-and-convert
3253 widget 'custom-browse-group-tag)
3254 buttons)
3255 (insert " " tag "\n")
3256 (widget-put widget :buttons buttons))
3257 ((and (eq custom-buffer-style 'tree)
3258 (zerop (length members)))
3259 (custom-browse-insert-prefix prefix)
3260 (insert "[ ]-- ")
3261 ;; (widget-glyph-insert nil "[ ]" "empty")
3262 ;; (widget-glyph-insert nil "-- " "horizontal")
3263 (push (widget-create-child-and-convert
3264 widget 'custom-browse-group-tag)
3265 buttons)
3266 (insert " " tag "\n")
3267 (widget-put widget :buttons buttons))
3268 ((eq custom-buffer-style 'tree)
3269 (custom-browse-insert-prefix prefix)
3270 (custom-load-widget widget)
3271 (if (zerop (length members))
3272 (progn
3273 (custom-browse-insert-prefix prefix)
3274 (insert "[ ]-- ")
3275 ;; (widget-glyph-insert nil "[ ]" "empty")
3276 ;; (widget-glyph-insert nil "-- " "horizontal")
3277 (push (widget-create-child-and-convert
3278 widget 'custom-browse-group-tag)
3279 buttons)
3280 (insert " " tag "\n")
3281 (widget-put widget :buttons buttons))
3282 (push (widget-create-child-and-convert
3283 widget 'custom-browse-visibility
3284 ;; :tag-glyph "minus"
3285 :tag "-")
3286 buttons)
3287 (insert "-\\ ")
3288 ;; (widget-glyph-insert nil "-\\ " "top")
3289 (push (widget-create-child-and-convert
3290 widget 'custom-browse-group-tag)
3291 buttons)
3292 (insert " " tag "\n")
3293 (widget-put widget :buttons buttons)
3294 (message "Creating group...")
3295 (let* ((members (custom-sort-items members
3296 custom-browse-sort-alphabetically
3297 custom-browse-order-groups))
3298 (prefixes (widget-get widget :custom-prefixes))
3299 (custom-prefix-list (custom-prefix-add symbol prefixes))
3300 (extra-prefix (if (widget-get widget :custom-last)
3302 " | "))
3303 (prefix (concat prefix extra-prefix))
3304 children entry)
3305 (while members
3306 (setq entry (car members)
3307 members (cdr members))
3308 (push (widget-create-child-and-convert
3309 widget (nth 1 entry)
3310 :group widget
3311 :tag (custom-unlispify-tag-name (nth 0 entry))
3312 :custom-prefixes custom-prefix-list
3313 :custom-level (1+ level)
3314 :custom-last (null members)
3315 :value (nth 0 entry)
3316 :custom-prefix prefix)
3317 children))
3318 (widget-put widget :children (reverse children)))
3319 (message "Creating group...done")))
3320 ;; Nested style.
3321 ((eq state 'hidden)
3322 ;; Create level indicator.
3323 (unless (eq custom-buffer-style 'links)
3324 (insert-char ?\ (* custom-buffer-indent (1- level)))
3325 (insert "-- "))
3326 ;; Create tag.
3327 (let ((begin (point)))
3328 (insert tag)
3329 (widget-specify-sample widget begin (point)))
3330 (insert " group: ")
3331 ;; Create link/visibility indicator.
3332 (if (eq custom-buffer-style 'links)
3333 (push (widget-create-child-and-convert
3334 widget 'custom-group-link
3335 :tag "Go to Group"
3336 symbol)
3337 buttons)
3338 (push (widget-create-child-and-convert
3339 widget 'custom-group-visibility
3340 :help-echo "Show members of this group."
3341 :action 'custom-toggle-parent
3342 (not (eq state 'hidden)))
3343 buttons))
3344 (insert " \n")
3345 ;; Create magic button.
3346 (let ((magic (widget-create-child-and-convert
3347 widget 'custom-magic nil)))
3348 (widget-put widget :custom-magic magic)
3349 (push magic buttons))
3350 ;; Update buttons.
3351 (widget-put widget :buttons buttons)
3352 ;; Insert documentation.
3353 (if (and (eq custom-buffer-style 'links) (> level 1))
3354 (widget-put widget :documentation-indent 0))
3355 (widget-default-format-handler widget ?h))
3356 ;; Nested style.
3357 (t ;Visible.
3358 ;; Add parent groups references above the group.
3359 (if t ;;; This should test that the buffer
3360 ;;; was made to display a group.
3361 (when (eq level 1)
3362 (if (custom-add-parent-links widget
3363 "Go to parent group:")
3364 (insert "\n"))))
3365 ;; Create level indicator.
3366 (insert-char ?\ (* custom-buffer-indent (1- level)))
3367 (insert "/- ")
3368 ;; Create tag.
3369 (let ((start (point)))
3370 (insert tag)
3371 (widget-specify-sample widget start (point)))
3372 (insert " group: ")
3373 ;; Create visibility indicator.
3374 (unless (eq custom-buffer-style 'links)
3375 (insert "--------")
3376 (push (widget-create-child-and-convert
3377 widget 'visibility
3378 :help-echo "Hide members of this group."
3379 :action 'custom-toggle-parent
3380 (not (eq state 'hidden)))
3381 buttons)
3382 (insert " "))
3383 ;; Create more dashes.
3384 ;; Use 76 instead of 75 to compensate for the temporary "<"
3385 ;; added by `widget-insert'.
3386 (insert-char ?- (- 76 (current-column)
3387 (* custom-buffer-indent level)))
3388 (insert "\\\n")
3389 ;; Create magic button.
3390 (let ((magic (widget-create-child-and-convert
3391 widget 'custom-magic
3392 :indent 0
3393 nil)))
3394 (widget-put widget :custom-magic magic)
3395 (push magic buttons))
3396 ;; Update buttons.
3397 (widget-put widget :buttons buttons)
3398 ;; Insert documentation.
3399 (widget-default-format-handler widget ?h)
3400 ;; Parent groups.
3401 (if nil ;;; This should test that the buffer
3402 ;;; was not made to display a group.
3403 (when (eq level 1)
3404 (insert-char ?\ custom-buffer-indent)
3405 (custom-add-parent-links widget)))
3406 (custom-add-see-also widget
3407 (make-string (* custom-buffer-indent level)
3408 ?\ ))
3409 ;; Members.
3410 (message "Creating group...")
3411 (custom-load-widget widget)
3412 (let* ((members (custom-sort-items members
3413 custom-buffer-sort-alphabetically
3414 custom-buffer-order-groups))
3415 (prefixes (widget-get widget :custom-prefixes))
3416 (custom-prefix-list (custom-prefix-add symbol prefixes))
3417 (length (length members))
3418 (count 0)
3419 (children (mapcar (lambda (entry)
3420 (widget-insert "\n")
3421 (message "\
3422 Creating group members... %2d%%"
3423 (/ (* 100.0 count) length))
3424 (setq count (1+ count))
3425 (prog1
3426 (widget-create-child-and-convert
3427 widget (nth 1 entry)
3428 :group widget
3429 :tag (custom-unlispify-tag-name
3430 (nth 0 entry))
3431 :custom-prefixes custom-prefix-list
3432 :custom-level (1+ level)
3433 :value (nth 0 entry))
3434 (unless (eq (preceding-char) ?\n)
3435 (widget-insert "\n"))))
3436 members)))
3437 (message "Creating group magic...")
3438 (mapc 'custom-magic-reset children)
3439 (message "Creating group state...")
3440 (widget-put widget :children children)
3441 (custom-group-state-update widget)
3442 (message "Creating group... done"))
3443 ;; End line
3444 (insert "\n")
3445 (insert-char ?\ (* custom-buffer-indent (1- level)))
3446 (insert "\\- " (widget-get widget :tag) " group end ")
3447 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3448 (insert "/\n")))))
3450 (defvar custom-group-menu
3451 '(("Set for Current Session" custom-group-set
3452 (lambda (widget)
3453 (eq (widget-get widget :custom-state) 'modified)))
3454 ("Save for Future Sessions" custom-group-save
3455 (lambda (widget)
3456 (memq (widget-get widget :custom-state) '(modified set))))
3457 ("Reset to Current" custom-group-reset-current
3458 (lambda (widget)
3459 (memq (widget-get widget :custom-state) '(modified))))
3460 ("Reset to Saved" custom-group-reset-saved
3461 (lambda (widget)
3462 (memq (widget-get widget :custom-state) '(modified set))))
3463 ("Reset to standard setting" custom-group-reset-standard
3464 (lambda (widget)
3465 (memq (widget-get widget :custom-state) '(modified set saved)))))
3466 "Alist of actions for the `custom-group' widget.
3467 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3468 the menu entry, ACTION is the function to call on the widget when the
3469 menu is selected, and FILTER is a predicate which takes a `custom-group'
3470 widget as an argument, and returns non-nil if ACTION is valid on that
3471 widget. If FILTER is nil, ACTION is always valid.")
3473 (defun custom-group-action (widget &optional event)
3474 "Show the menu for `custom-group' WIDGET.
3475 Optional EVENT is the location for the menu."
3476 (if (eq (widget-get widget :custom-state) 'hidden)
3477 (custom-toggle-hide widget)
3478 (let* ((completion-ignore-case t)
3479 (answer (widget-choose (concat "Operation on "
3480 (custom-unlispify-tag-name
3481 (widget-get widget :value)))
3482 (custom-menu-filter custom-group-menu
3483 widget)
3484 event)))
3485 (if answer
3486 (funcall answer widget)))))
3488 (defun custom-group-set (widget)
3489 "Set changes in all modified group members."
3490 (let ((children (widget-get widget :children)))
3491 (mapc (lambda (child)
3492 (when (eq (widget-get child :custom-state) 'modified)
3493 (widget-apply child :custom-set)))
3494 children )))
3496 (defun custom-group-save (widget)
3497 "Save all modified group members."
3498 (let ((children (widget-get widget :children)))
3499 (mapc (lambda (child)
3500 (when (memq (widget-get child :custom-state) '(modified set))
3501 (widget-apply child :custom-save)))
3502 children )))
3504 (defun custom-group-reset-current (widget)
3505 "Reset all modified group members."
3506 (let ((children (widget-get widget :children)))
3507 (mapc (lambda (child)
3508 (when (eq (widget-get child :custom-state) 'modified)
3509 (widget-apply child :custom-reset-current)))
3510 children )))
3512 (defun custom-group-reset-saved (widget)
3513 "Reset all modified or set group members."
3514 (let ((children (widget-get widget :children)))
3515 (mapc (lambda (child)
3516 (when (memq (widget-get child :custom-state) '(modified set))
3517 (widget-apply child :custom-reset-saved)))
3518 children )))
3520 (defun custom-group-reset-standard (widget)
3521 "Reset all modified, set, or saved group members."
3522 (let ((children (widget-get widget :children)))
3523 (mapc (lambda (child)
3524 (when (memq (widget-get child :custom-state)
3525 '(modified set saved))
3526 (widget-apply child :custom-reset-standard)))
3527 children )))
3529 (defun custom-group-state-update (widget)
3530 "Update magic."
3531 (unless (eq (widget-get widget :custom-state) 'hidden)
3532 (let* ((children (widget-get widget :children))
3533 (states (mapcar (lambda (child)
3534 (widget-get child :custom-state))
3535 children))
3536 (magics custom-magic-alist)
3537 (found 'standard))
3538 (while magics
3539 (let ((magic (car (car magics))))
3540 (if (and (not (eq magic 'hidden))
3541 (memq magic states))
3542 (setq found magic
3543 magics nil)
3544 (setq magics (cdr magics)))))
3545 (widget-put widget :custom-state found)))
3546 (custom-magic-reset widget))
3548 ;;; The `custom-save-all' Function.
3549 ;;;###autoload
3550 (defcustom custom-file nil
3551 "File used for storing customization information.
3552 The default is nil, which means to use your init file
3553 as specified by `user-init-file'. If you specify some other file,
3554 you need to explicitly load that file for the settings to take effect.
3556 When you change this variable, look in the previous custom file
3557 \(usually your init file) for the forms `(custom-set-variables ...)'
3558 and `(custom-set-faces ...)', and copy them (whichever ones you find)
3559 to the new custom file. This will preserve your existing customizations."
3560 :type '(choice (const :tag "Your Emacs init file" nil) file)
3561 :group 'customize)
3563 (defun custom-file ()
3564 "Return the file name for saving customizations."
3565 (setq custom-file
3566 (or custom-file
3567 (let ((user-init-file user-init-file)
3568 (default-init-file
3569 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
3570 (when (null user-init-file)
3571 (if (or (file-exists-p default-init-file)
3572 (and (eq system-type 'windows-nt)
3573 (file-exists-p "~/_emacs")))
3574 ;; Started with -q, i.e. the file containing
3575 ;; Custom settings hasn't been read. Saving
3576 ;; settings there would overwrite other settings.
3577 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3578 (setq user-init-file default-init-file))
3579 user-init-file))))
3581 (defun custom-save-delete (symbol)
3582 "Visit `custom-file' and delete all calls to SYMBOL from it.
3583 Leave point at the old location of the first such call,
3584 or (if there were none) at the end of the buffer."
3585 (let ((default-major-mode))
3586 (set-buffer (find-file-noselect (custom-file))))
3587 (goto-char (point-min))
3588 ;; Skip all whitespace and comments.
3589 (while (forward-comment 1))
3590 (or (eobp)
3591 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3592 (let (first)
3593 (catch 'found
3594 (while t ;; We exit this loop only via throw.
3595 ;; Skip all whitespace and comments.
3596 (while (forward-comment 1))
3597 (let ((start (point))
3598 (sexp (condition-case nil
3599 (read (current-buffer))
3600 (end-of-file (throw 'found nil)))))
3601 (when (and (listp sexp)
3602 (eq (car sexp) symbol))
3603 (delete-region start (point))
3604 (unless first
3605 (setq first (point)))))))
3606 (if first
3607 (goto-char first)
3608 ;; Move in front of local variables, otherwise long Custom
3609 ;; entries would make them ineffective.
3610 (let ((pos (point-max))
3611 (case-fold-search t))
3612 (save-excursion
3613 (goto-char (point-max))
3614 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3615 'move)
3616 (when (search-forward "Local Variables:" nil t)
3617 (setq pos (line-beginning-position))))
3618 (goto-char pos)))))
3620 (defun custom-save-variables ()
3621 "Save all customized variables in `custom-file'."
3622 (save-excursion
3623 (custom-save-delete 'custom-set-variables)
3624 (let ((standard-output (current-buffer))
3625 (saved-list (make-list 1 0))
3626 sort-fold-case)
3627 ;; First create a sorted list of saved variables.
3628 (mapatoms
3629 (lambda (symbol)
3630 (if (get symbol 'saved-value)
3631 (nconc saved-list (list symbol)))))
3632 (setq saved-list (sort (cdr saved-list) 'string<))
3633 (unless (bolp)
3634 (princ "\n"))
3635 (princ "(custom-set-variables
3636 ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
3637 ;; Your init file should contain only one such instance.\n")
3638 (mapcar
3639 (lambda (symbol)
3640 (let ((value (get symbol 'saved-value))
3641 (requests (get symbol 'custom-requests))
3642 (now (not (or (get symbol 'standard-value)
3643 (and (not (boundp symbol))
3644 (not (get symbol 'force-value))))))
3645 (comment (get symbol 'saved-variable-comment))
3646 sep)
3647 (when (or value comment)
3648 (unless (bolp)
3649 (princ "\n"))
3650 (princ " '(")
3651 (prin1 symbol)
3652 (princ " ")
3653 (prin1 (car value))
3654 (cond ((or now requests comment)
3655 (princ " ")
3656 (if now
3657 (princ "t")
3658 (princ "nil"))
3659 (cond ((or requests comment)
3660 (princ " ")
3661 (if requests
3662 (prin1 requests)
3663 (princ "nil"))
3664 (cond (comment
3665 (princ " ")
3666 (prin1 comment)
3667 (princ ")"))
3669 (princ ")"))))
3671 (princ ")"))))
3673 (princ ")"))))))
3674 saved-list)
3675 (if (bolp)
3676 (princ " "))
3677 (princ ")")
3678 (unless (looking-at "\n")
3679 (princ "\n")))))
3681 (defun custom-save-faces ()
3682 "Save all customized faces in `custom-file'."
3683 (save-excursion
3684 (custom-save-delete 'custom-set-faces)
3685 (let ((standard-output (current-buffer))
3686 (saved-list (make-list 1 0))
3687 sort-fold-case)
3688 ;; First create a sorted list of saved faces.
3689 (mapatoms
3690 (lambda (symbol)
3691 (if (get symbol 'saved-face)
3692 (nconc saved-list (list symbol)))))
3693 (setq saved-list (sort (cdr saved-list) 'string<))
3694 ;; The default face must be first, since it affects the others.
3695 (if (memq 'default saved-list)
3696 (setq saved-list (cons 'default (delq 'default saved-list))))
3697 (unless (bolp)
3698 (princ "\n"))
3699 (princ "(custom-set-faces
3700 ;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
3701 ;; Your init file should contain only one such instance.\n")
3702 (mapcar
3703 (lambda (symbol)
3704 (let ((value (get symbol 'saved-face))
3705 (now (not (or (get symbol 'face-defface-spec)
3706 (and (not (custom-facep symbol))
3707 (not (get symbol 'force-face))))))
3708 (comment (get symbol 'saved-face-comment)))
3709 ;; Don't print default face here.
3710 (unless (bolp)
3711 (princ "\n"))
3712 (princ " '(")
3713 (prin1 symbol)
3714 (princ " ")
3715 (prin1 value)
3716 (cond ((or now comment)
3717 (princ " ")
3718 (if now
3719 (princ "t")
3720 (princ "nil"))
3721 (cond (comment
3722 (princ " ")
3723 (prin1 comment)
3724 (princ ")"))
3726 (princ ")"))))
3728 (princ ")")))))
3729 saved-list)
3730 (if (bolp)
3731 (princ " "))
3732 (princ ")")
3733 (unless (looking-at "\n")
3734 (princ "\n")))))
3736 ;;;###autoload
3737 (defun customize-save-customized ()
3738 "Save all user options which have been set in this session."
3739 (interactive)
3740 (mapatoms (lambda (symbol)
3741 (let ((face (get symbol 'customized-face))
3742 (value (get symbol 'customized-value))
3743 (face-comment (get symbol 'customized-face-comment))
3744 (variable-comment
3745 (get symbol 'customized-variable-comment)))
3746 (when face
3747 (put symbol 'saved-face face)
3748 (put symbol 'customized-face nil))
3749 (when value
3750 (put symbol 'saved-value value)
3751 (put symbol 'customized-value nil))
3752 (when variable-comment
3753 (put symbol 'saved-variable-comment variable-comment)
3754 (put symbol 'customized-variable-comment nil))
3755 (when face-comment
3756 (put symbol 'saved-face-comment face-comment)
3757 (put symbol 'customized-face-comment nil)))))
3758 ;; We really should update all custom buffers here.
3759 (custom-save-all))
3761 ;;;###autoload
3762 (defun custom-save-all ()
3763 "Save all customizations in `custom-file'."
3764 (let ((inhibit-read-only t))
3765 (custom-save-variables)
3766 (custom-save-faces)
3767 (save-excursion
3768 (let ((default-major-mode nil))
3769 (set-buffer (find-file-noselect (custom-file))))
3770 (let ((file-precious-flag t))
3771 (save-buffer)))))
3773 ;;; The Customize Menu.
3775 ;;; Menu support
3777 (defcustom custom-menu-nesting 2
3778 "Maximum nesting in custom menus."
3779 :type 'integer
3780 :group 'custom-menu)
3782 (defun custom-face-menu-create (widget symbol)
3783 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3784 (vector (custom-unlispify-menu-entry symbol)
3785 `(customize-face ',symbol)
3788 (defun custom-variable-menu-create (widget symbol)
3789 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3790 (let ((type (get symbol 'custom-type)))
3791 (unless (listp type)
3792 (setq type (list type)))
3793 (if (and type (widget-get type :custom-menu))
3794 (widget-apply type :custom-menu symbol)
3795 (vector (custom-unlispify-menu-entry symbol)
3796 `(customize-variable ',symbol)
3797 t))))
3799 ;; Add checkboxes to boolean variable entries.
3800 (widget-put (get 'boolean 'widget-type)
3801 :custom-menu (lambda (widget symbol)
3802 (vector (custom-unlispify-menu-entry symbol)
3803 `(customize-variable ',symbol)
3804 ':style 'toggle
3805 ':selected symbol)))
3807 (defun custom-group-menu-create (widget symbol)
3808 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3809 `( ,(custom-unlispify-menu-entry symbol t)
3810 :filter (lambda (&rest junk)
3811 (let ((menu (custom-menu-create ',symbol)))
3812 (if (consp menu) (cdr menu) menu)))))
3814 ;;;###autoload
3815 (defun custom-menu-create (symbol)
3816 "Create menu for customization group SYMBOL.
3817 The menu is in a format applicable to `easy-menu-define'."
3818 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3819 `(customize-group ',symbol)
3820 t)))
3821 (if (and (or (not (boundp 'custom-menu-nesting))
3822 (>= custom-menu-nesting 0))
3823 (< (length (get symbol 'custom-group)) widget-menu-max-size))
3824 (let ((custom-prefix-list (custom-prefix-add symbol
3825 custom-prefix-list))
3826 (members (custom-sort-items (get symbol 'custom-group)
3827 custom-menu-sort-alphabetically
3828 custom-menu-order-groups)))
3829 (custom-load-symbol symbol)
3830 `(,(custom-unlispify-menu-entry symbol t)
3831 ,item
3832 "--"
3833 ,@(mapcar (lambda (entry)
3834 (widget-apply (if (listp (nth 1 entry))
3835 (nth 1 entry)
3836 (list (nth 1 entry)))
3837 :custom-menu (nth 0 entry)))
3838 members)))
3839 item)))
3841 ;;;###autoload
3842 (defun customize-menu-create (symbol &optional name)
3843 "Return a customize menu for customization group SYMBOL.
3844 If optional NAME is given, use that as the name of the menu.
3845 Otherwise the menu will be named `Customize'.
3846 The format is suitable for use with `easy-menu-define'."
3847 (unless name
3848 (setq name "Customize"))
3849 `(,name
3850 :filter (lambda (&rest junk)
3851 (let ((menu (custom-menu-create ',symbol)))
3852 (if (consp menu) (cdr menu) menu)))))
3854 ;;; The Custom Mode.
3856 (defvar custom-mode-map nil
3857 "Keymap for `custom-mode'.")
3859 (unless custom-mode-map
3860 ;; This keymap should be dense, but a dense keymap would prevent inheriting
3861 ;; "\r" bindings from the parent map.
3862 (setq custom-mode-map (make-sparse-keymap))
3863 (set-keymap-parent custom-mode-map widget-keymap)
3864 (suppress-keymap custom-mode-map)
3865 (define-key custom-mode-map " " 'scroll-up)
3866 (define-key custom-mode-map "\177" 'scroll-down)
3867 (define-key custom-mode-map "q" 'Custom-buffer-done)
3868 (define-key custom-mode-map "u" 'Custom-goto-parent)
3869 (define-key custom-mode-map "n" 'widget-forward)
3870 (define-key custom-mode-map "p" 'widget-backward)
3871 (define-key custom-mode-map [mouse-1] 'Custom-move-and-invoke))
3873 (defun Custom-move-and-invoke (event)
3874 "Move to where you click, and if it is an active field, invoke it."
3875 (interactive "e")
3876 (mouse-set-point event)
3877 (if (widget-event-point event)
3878 (let* ((pos (widget-event-point event))
3879 (button (get-char-property pos 'button)))
3880 (if button
3881 (widget-button-click event)))))
3883 (easy-menu-define Custom-mode-menu
3884 custom-mode-map
3885 "Menu used in customization buffers."
3886 `("Custom"
3887 ,(customize-menu-create 'customize)
3888 ["Set" Custom-set t]
3889 ["Save" Custom-save t]
3890 ["Reset to Current" Custom-reset-current t]
3891 ["Reset to Saved" Custom-reset-saved t]
3892 ["Reset to Standard Settings" Custom-reset-standard t]
3893 ["Info" (Info-goto-node "(emacs)Easy Customization") t]))
3895 (defun Custom-goto-parent ()
3896 "Go to the parent group listed at the top of this buffer.
3897 If several parents are listed, go to the first of them."
3898 (interactive)
3899 (save-excursion
3900 (goto-char (point-min))
3901 (if (search-forward "\nGo to parent group: " nil t)
3902 (let* ((button (get-char-property (point) 'button))
3903 (parent (downcase (widget-get button :tag))))
3904 (customize-group parent)))))
3906 (defcustom custom-mode-hook nil
3907 "Hook called when entering Custom mode."
3908 :type 'hook
3909 :group 'custom-buffer )
3911 (defun custom-state-buffer-message (widget)
3912 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
3913 (message "To install your edits, invoke [State] and choose the Set operation")))
3915 (defun custom-mode ()
3916 "Major mode for editing customization buffers.
3918 The following commands are available:
3920 Move to next button or editable field. \\[widget-forward]
3921 Move to previous button or editable field. \\[widget-backward]
3922 \\<widget-field-keymap>\
3923 Complete content of editable text field. \\[widget-complete]
3924 \\<custom-mode-map>\
3925 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3926 Invoke button under point. \\[widget-button-press]
3927 Set all modifications. \\[Custom-set]
3928 Make all modifications default. \\[Custom-save]
3929 Reset all modified options. \\[Custom-reset-current]
3930 Reset all modified or set options. \\[Custom-reset-saved]
3931 Reset all options. \\[Custom-reset-standard]
3933 Entry to this mode calls the value of `custom-mode-hook'
3934 if that value is non-nil."
3935 (kill-all-local-variables)
3936 (setq major-mode 'custom-mode
3937 mode-name "Custom")
3938 (use-local-map custom-mode-map)
3939 (easy-menu-add Custom-mode-menu)
3940 (make-local-variable 'custom-options)
3941 (make-local-variable 'widget-documentation-face)
3942 (setq widget-documentation-face 'custom-documentation-face)
3943 (make-local-variable 'widget-button-face)
3944 (setq widget-button-face 'custom-button-face)
3945 (set (make-local-variable 'widget-button-pressed-face)
3946 'custom-button-pressed-face)
3947 (set (make-local-variable 'widget-mouse-face)
3948 'custom-button-pressed-face) ; buttons `depress' when moused
3949 ;; When possible, use relief for buttons, not bracketing. This test
3950 ;; may not be optimal.
3951 (when custom-raised-buttons
3952 (set (make-local-variable 'widget-push-button-prefix) "")
3953 (set (make-local-variable 'widget-push-button-suffix) "")
3954 (set (make-local-variable 'widget-link-prefix) "")
3955 (set (make-local-variable 'widget-link-suffix) ""))
3956 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
3957 (run-hooks 'custom-mode-hook))
3959 (put 'custom-mode 'mode-class 'special)
3961 (add-to-list
3962 'debug-ignored-errors
3963 "^No user options have changed defaults in recent Emacs versions$")
3965 ;;; The End.
3967 (provide 'cus-edit)
3969 ;;; cus-edit.el ends here