(sun4H:SunOS:5.*:*): New case.
[emacs/old-mirror.git] / lisp / cus-edit.el
blob20ce781158c710292b52d3cc01a3bba4e28ec7e7
1 ;;; cus-edit.el --- Tools for customizating Emacs and Lisp packages.
2 ;;
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
4 ;;
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: help, faces
7 ;; Version: 1.9954
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
27 ;;; Commentary:
29 ;; This file implements the code to create and edit customize buffers.
30 ;;
31 ;; See `custom.el'.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
37 ;;; Code:
39 (require 'cus-face)
40 (require 'wid-edit)
41 (require 'easymenu)
42 (eval-when-compile (require 'cl))
44 (condition-case nil
45 (require 'cus-load)
46 (error nil))
48 (condition-case nil
49 (require 'cus-start)
50 (error nil))
52 (define-widget-keywords :custom-last :custom-prefix :custom-category
53 :custom-prefixes :custom-menu
54 :custom-show
55 :custom-magic :custom-state :custom-level :custom-form
56 :custom-set :custom-save :custom-reset-current :custom-reset-saved
57 :custom-reset-standard)
59 (put 'custom-define-hook 'custom-type 'hook)
60 (put 'custom-define-hook 'standard-value '(nil))
61 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
63 ;;; Customization Groups.
65 (defgroup emacs nil
66 "Customization of the One True Editor."
67 :link '(custom-manual "(emacs)Top"))
69 ;; Most of these groups are stolen from `finder.el',
70 (defgroup editing nil
71 "Basic text editing facilities."
72 :group 'emacs)
74 (defgroup abbrev nil
75 "Abbreviation handling, typing shortcuts, macros."
76 :tag "Abbreviations"
77 :group 'editing)
79 (defgroup matching nil
80 "Various sorts of searching and matching."
81 :group 'editing)
83 (defgroup emulations nil
84 "Emulations of other editors."
85 :group 'editing)
87 (defgroup mouse nil
88 "Mouse support."
89 :group 'editing)
91 (defgroup outlines nil
92 "Support for hierarchical outlining."
93 :group 'editing)
95 (defgroup external nil
96 "Interfacing to external utilities."
97 :group 'emacs)
99 (defgroup bib nil
100 "Code related to the `bib' bibliography processor."
101 :tag "Bibliography"
102 :group 'external)
104 (defgroup processes nil
105 "Process, subshell, compilation, and job control support."
106 :group 'external
107 :group 'development)
109 (defgroup convenience nil
110 "Convenience features for faster editing."
111 :group 'emacs)
113 (defgroup programming nil
114 "Support for programming in other languages."
115 :group 'emacs)
117 (defgroup languages nil
118 "Specialized modes for editing programming languages."
119 :group 'programming)
121 (defgroup lisp nil
122 "Lisp support, including Emacs Lisp."
123 :group 'languages
124 :group 'development)
126 (defgroup c nil
127 "Support for the C language and related languages."
128 :group 'languages)
130 (defgroup tools nil
131 "Programming tools."
132 :group 'programming)
134 (defgroup oop nil
135 "Support for object-oriented programming."
136 :group 'programming)
138 (defgroup applications nil
139 "Applications written in Emacs."
140 :group 'emacs)
142 (defgroup calendar nil
143 "Calendar and time management support."
144 :group 'applications)
146 (defgroup mail nil
147 "Modes for electronic-mail handling."
148 :group 'applications)
150 (defgroup news nil
151 "Support for netnews reading and posting."
152 :group 'applications)
154 (defgroup games nil
155 "Games, jokes and amusements."
156 :group 'applications)
158 (defgroup development nil
159 "Support for further development of Emacs."
160 :group 'emacs)
162 (defgroup docs nil
163 "Support for Emacs documentation."
164 :group 'development)
166 (defgroup extensions nil
167 "Emacs Lisp language extensions."
168 :group 'development)
170 (defgroup internal nil
171 "Code for Emacs internals, build process, defaults."
172 :group 'development)
174 (defgroup maint nil
175 "Maintenance aids for the Emacs development group."
176 :tag "Maintenance"
177 :group 'development)
179 (defgroup environment nil
180 "Fitting Emacs with its environment."
181 :group 'emacs)
183 (defgroup comm nil
184 "Communications, networking, remote access to files."
185 :tag "Communication"
186 :group 'environment)
188 (defgroup hardware nil
189 "Support for interfacing with exotic hardware."
190 :group 'environment)
192 (defgroup terminals nil
193 "Support for terminal types."
194 :group 'environment)
196 (defgroup unix nil
197 "Front-ends/assistants for, or emulators of, UNIX features."
198 :group 'environment)
200 (defgroup vms nil
201 "Support code for vms."
202 :group 'environment)
204 (defgroup i18n nil
205 "Internationalization and alternate character-set support."
206 :group 'environment
207 :group 'editing)
209 (defgroup x nil
210 "The X Window system."
211 :group 'environment)
213 (defgroup frames nil
214 "Support for Emacs frames and window systems."
215 :group 'environment)
217 (defgroup data nil
218 "Support editing files of data."
219 :group 'emacs)
221 (defgroup files nil
222 "Support editing files."
223 :group 'emacs)
225 (defgroup wp nil
226 "Word processing."
227 :group 'emacs)
229 (defgroup tex nil
230 "Code related to the TeX formatter."
231 :group 'wp)
233 (defgroup faces nil
234 "Support for multiple fonts."
235 :group 'emacs)
237 (defgroup hypermedia nil
238 "Support for links between text or other media types."
239 :group 'emacs)
241 (defgroup help nil
242 "Support for on-line help systems."
243 :group 'emacs)
245 (defgroup local nil
246 "Code local to your site."
247 :group 'emacs)
249 (defgroup customize '((widgets custom-group))
250 "Customization of the Customization support."
251 :link '(custom-manual "(custom)Top")
252 :link '(url-link :tag "Development Page"
253 "http://www.dina.kvl.dk/~abraham/custom/")
254 :prefix "custom-"
255 :group 'help)
257 (defgroup custom-faces nil
258 "Faces used by customize."
259 :group 'customize
260 :group 'faces)
262 (defgroup custom-browse nil
263 "Control customize browser."
264 :prefix "custom-"
265 :group 'customize)
267 (defgroup custom-buffer nil
268 "Control customize buffers."
269 :prefix "custom-"
270 :group 'customize)
272 (defgroup custom-menu nil
273 "Control customize menus."
274 :prefix "custom-"
275 :group 'customize)
277 (defgroup abbrev-mode nil
278 "Word abbreviations mode."
279 :group 'abbrev)
281 (defgroup alloc nil
282 "Storage allocation and gc for GNU Emacs Lisp interpreter."
283 :tag "Storage Allocation"
284 :group 'internal)
286 (defgroup undo nil
287 "Undoing changes in buffers."
288 :group 'editing)
290 (defgroup modeline nil
291 "Content of the modeline."
292 :group 'environment)
294 (defgroup fill nil
295 "Indenting and filling text."
296 :group 'editing)
298 (defgroup editing-basics nil
299 "Most basic editing facilities."
300 :group 'editing)
302 (defgroup display nil
303 "How characters are displayed in buffers."
304 :group 'environment)
306 (defgroup execute nil
307 "Executing external commands."
308 :group 'processes)
310 (defgroup installation nil
311 "The Emacs installation."
312 :group 'environment)
314 (defgroup dired nil
315 "Directory editing."
316 :group 'environment)
318 (defgroup limits nil
319 "Internal Emacs limits."
320 :group 'internal)
322 (defgroup debug nil
323 "Debugging Emacs itself."
324 :group 'development)
326 (defgroup minibuffer nil
327 "Controling the behaviour of the minibuffer."
328 :group 'environment)
330 (defgroup keyboard nil
331 "Input from the keyboard."
332 :group 'environment)
334 (defgroup mouse nil
335 "Input from the mouse."
336 :group 'environment)
338 (defgroup menu nil
339 "Input from the menus."
340 :group 'environment)
342 (defgroup auto-save nil
343 "Preventing accidential loss of data."
344 :group 'files)
346 (defgroup processes-basics nil
347 "Basic stuff dealing with processes."
348 :group 'processes)
350 (defgroup mule nil
351 "MULE Emacs internationalization."
352 :group 'i18n)
354 (defgroup windows nil
355 "Windows within a frame."
356 :group 'environment)
358 ;;; Utilities.
360 (defun custom-last (x &optional n)
361 ;; Stolen from `cl.el'.
362 "Returns the last link in the list LIST.
363 With optional argument N, returns Nth-to-last link (default 1)."
364 (if n
365 (let ((m 0) (p x))
366 (while (consp p) (incf m) (pop p))
367 (if (<= n 0) p
368 (if (< n m) (nthcdr (- m n) x) x)))
369 (while (consp (cdr x)) (pop x))
372 (defun custom-quote (sexp)
373 "Quote SEXP iff it is not self quoting."
374 (if (or (memq sexp '(t nil))
375 (and (symbolp sexp)
376 (eq (aref (symbol-name sexp) 0) ?:))
377 (and (listp sexp)
378 (memq (car sexp) '(lambda)))
379 (stringp sexp)
380 (numberp sexp)
381 (and (fboundp 'characterp)
382 (characterp sexp)))
383 sexp
384 (list 'quote sexp)))
386 (defun custom-split-regexp-maybe (regexp)
387 "If REGEXP is a string, split it to a list at `\\|'.
388 You can get the original back with from the result with:
389 (mapconcat 'identity result \"\\|\")
391 IF REGEXP is not a string, return it unchanged."
392 (if (stringp regexp)
393 (let ((start 0)
394 all)
395 (while (string-match "\\\\|" regexp start)
396 (setq all (cons (substring regexp start (match-beginning 0)) all)
397 start (match-end 0)))
398 (nreverse (cons (substring regexp start) all)))
399 regexp))
401 (defun custom-variable-prompt ()
402 ;; Code stolen from `help.el'.
403 "Prompt for a variable, defaulting to the variable at point.
404 Return a list suitable for use in `interactive'."
405 (let ((v (variable-at-point))
406 (enable-recursive-minibuffers t)
407 val)
408 (setq val (completing-read
409 (if (symbolp v)
410 (format "Customize option: (default %s) " v)
411 "Customize variable: ")
412 obarray (lambda (symbol)
413 (and (boundp symbol)
414 (or (get symbol 'custom-type)
415 (user-variable-p symbol)))) t))
416 (list (if (equal val "")
417 (if (symbolp v) v nil)
418 (intern val)))))
420 (defun custom-menu-filter (menu widget)
421 "Convert MENU to the form used by `widget-choose'.
422 MENU should be in the same format as `custom-variable-menu'.
423 WIDGET is the widget to apply the filter entries of MENU on."
424 (let ((result nil)
425 current name action filter)
426 (while menu
427 (setq current (car menu)
428 name (nth 0 current)
429 action (nth 1 current)
430 filter (nth 2 current)
431 menu (cdr menu))
432 (if (or (null filter) (funcall filter widget))
433 (push (cons name action) result)
434 (push name result)))
435 (nreverse result)))
437 ;;; Unlispify.
439 (defvar custom-prefix-list nil
440 "List of prefixes that should be ignored by `custom-unlispify'")
442 (defcustom custom-unlispify-menu-entries t
443 "Display menu entries as words instead of symbols if non nil."
444 :group 'custom-menu
445 :type 'boolean)
447 (defcustom custom-unlispify-remove-prefixes nil
448 "Non-nil means remove group prefixes from option names in buffer."
449 :group 'custom-menu
450 :type 'boolean)
452 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
453 "Convert symbol into a menu entry."
454 (cond ((not custom-unlispify-menu-entries)
455 (symbol-name symbol))
456 ((get symbol 'custom-tag)
457 (if no-suffix
458 (get symbol 'custom-tag)
459 (concat (get symbol 'custom-tag) "...")))
461 (save-excursion
462 (set-buffer (get-buffer-create " *Custom-Work*"))
463 (erase-buffer)
464 (princ symbol (current-buffer))
465 (goto-char (point-min))
466 (when (and (eq (get symbol 'custom-type) 'boolean)
467 (re-search-forward "-p\\'" nil t))
468 (replace-match "" t t)
469 (goto-char (point-min)))
470 (if custom-unlispify-remove-prefixes
471 (let ((prefixes custom-prefix-list)
472 prefix)
473 (while prefixes
474 (setq prefix (car prefixes))
475 (if (search-forward prefix (+ (point) (length prefix)) t)
476 (progn
477 (setq prefixes nil)
478 (delete-region (point-min) (point)))
479 (setq prefixes (cdr prefixes))))))
480 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
481 (capitalize-region (point-min) (point-max))
482 (unless no-suffix
483 (goto-char (point-max))
484 (insert "..."))
485 (buffer-string)))))
487 (defcustom custom-unlispify-tag-names t
488 "Display tag names as words instead of symbols if non nil."
489 :group 'custom-buffer
490 :type 'boolean)
492 (defun custom-unlispify-tag-name (symbol)
493 "Convert symbol into a menu entry."
494 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
495 (custom-unlispify-menu-entry symbol t)))
497 (defun custom-prefix-add (symbol prefixes)
498 ;; Addd SYMBOL to list of ignored PREFIXES.
499 (cons (or (get symbol 'custom-prefix)
500 (concat (symbol-name symbol) "-"))
501 prefixes))
503 ;;; Guess.
505 (defcustom custom-guess-name-alist
506 '(("-p\\'" boolean)
507 ("-hook\\'" hook)
508 ("-face\\'" face)
509 ("-file\\'" file)
510 ("-function\\'" function)
511 ("-functions\\'" (repeat function))
512 ("-list\\'" (repeat sexp))
513 ("-alist\\'" (repeat (cons sexp sexp))))
514 "Alist of (MATCH TYPE).
516 MATCH should be a regexp matching the name of a symbol, and TYPE should
517 be a widget suitable for editing the value of that symbol. The TYPE
518 of the first entry where MATCH matches the name of the symbol will be
519 used.
521 This is used for guessing the type of variables not declared with
522 customize."
523 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
524 :group 'customize)
526 (defcustom custom-guess-doc-alist
527 '(("\\`\\*?Non-nil " boolean))
528 "Alist of (MATCH TYPE).
530 MATCH should be a regexp matching a documentation string, and TYPE
531 should be a widget suitable for editing the value of a variable with
532 that documentation string. The TYPE of the first entry where MATCH
533 matches the name of the symbol will be used.
535 This is used for guessing the type of variables not declared with
536 customize."
537 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
538 :group 'customize)
540 (defun custom-guess-type (symbol)
541 "Guess a widget suitable for editing the value of SYMBOL.
542 This is done by matching SYMBOL with `custom-guess-name-alist' and
543 if that fails, the doc string with `custom-guess-doc-alist'."
544 (let ((name (symbol-name symbol))
545 (names custom-guess-name-alist)
546 current found)
547 (while names
548 (setq current (car names)
549 names (cdr names))
550 (when (string-match (nth 0 current) name)
551 (setq found (nth 1 current)
552 names nil)))
553 (unless found
554 (let ((doc (documentation-property symbol 'variable-documentation))
555 (docs custom-guess-doc-alist))
556 (when doc
557 (while docs
558 (setq current (car docs)
559 docs (cdr docs))
560 (when (string-match (nth 0 current) doc)
561 (setq found (nth 1 current)
562 docs nil))))))
563 found))
565 ;;; Sorting.
567 (defcustom custom-browse-sort-alphabetically nil
568 "If non-nil, sort members of each customization group alphabetically."
569 :type 'boolean
570 :group 'custom-browse)
572 (defcustom custom-browse-order-groups nil
573 "If non-nil, order group members within each customization group.
574 If `first', order groups before non-groups.
575 If `last', order groups after non-groups."
576 :type '(choice (const first)
577 (const last)
578 (const :tag "none" nil))
579 :group 'custom-browse)
581 (defcustom custom-browse-only-groups nil
582 "If non-nil, show group members only within each customization group."
583 :type 'boolean
584 :group 'custom-browse)
586 (defcustom custom-buffer-sort-alphabetically nil
587 "If non-nil, sort members of each customization group alphabetically."
588 :type 'boolean
589 :group 'custom-buffer)
591 (defcustom custom-buffer-order-groups 'last
592 "If non-nil, order group members within each customization group.
593 If `first', order groups before non-groups.
594 If `last', order groups after non-groups."
595 :type '(choice (const first)
596 (const last)
597 (const :tag "none" nil))
598 :group 'custom-buffer)
600 (defcustom custom-menu-sort-alphabetically nil
601 "If non-nil, sort members of each customization group alphabetically."
602 :type 'boolean
603 :group 'custom-menu)
605 (defcustom custom-menu-order-groups 'first
606 "If non-nil, order group members within each customization group.
607 If `first', order groups before non-groups.
608 If `last', order groups after non-groups."
609 :type '(choice (const first)
610 (const last)
611 (const :tag "none" nil))
612 :group 'custom-menu)
614 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
616 (defun custom-sort-items (items sort-alphabetically order-groups)
617 "Return a sorted copy of ITEMS.
618 ITEMS should be a `custom-group' property.
619 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
620 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
621 groups after non-groups, if nil do not order groups at all."
622 (sort (copy-sequence items)
623 (lambda (a b)
624 (let ((typea (nth 1 a)) (typeb (nth 1 b))
625 (namea (symbol-name (nth 0 a))) (nameb (symbol-name (nth 0 b))))
626 (cond ((not order-groups)
627 ;; Since we don't care about A and B order, maybe sort.
628 (when sort-alphabetically
629 (string-lessp namea nameb)))
630 ((eq typea 'custom-group)
631 ;; If B is also a group, maybe sort. Otherwise, order A and B.
632 (if (eq typeb 'custom-group)
633 (when sort-alphabetically
634 (string-lessp namea nameb))
635 (eq order-groups 'first)))
636 ((eq typeb 'custom-group)
637 ;; Since A cannot be a group, order A and B.
638 (eq order-groups 'last))
639 (sort-alphabetically
640 ;; Since A and B cannot be groups, sort.
641 (string-lessp namea nameb)))))))
643 ;;; Custom Mode Commands.
645 (defvar custom-options nil
646 "Customization widgets in the current buffer.")
648 (defun Custom-set ()
649 "Set changes in all modified options."
650 (interactive)
651 (let ((children custom-options))
652 (mapcar (lambda (child)
653 (when (eq (widget-get child :custom-state) 'modified)
654 (widget-apply child :custom-set)))
655 children)))
657 (defun Custom-save ()
658 "Set all modified group members and save them."
659 (interactive)
660 (let ((children custom-options))
661 (mapcar (lambda (child)
662 (when (memq (widget-get child :custom-state) '(modified set))
663 (widget-apply child :custom-save)))
664 children))
665 (custom-save-all))
667 (defvar custom-reset-menu
668 '(("Current" . Custom-reset-current)
669 ("Saved" . Custom-reset-saved)
670 ("Standard Settings" . Custom-reset-standard))
671 "Alist of actions for the `Reset' button.
672 The key is a string containing the name of the action, the value is a
673 lisp function taking the widget as an element which will be called
674 when the action is chosen.")
676 (defun custom-reset (event)
677 "Select item from reset menu."
678 (let* ((completion-ignore-case t)
679 (answer (widget-choose "Reset to"
680 custom-reset-menu
681 event)))
682 (if answer
683 (funcall answer))))
685 (defun Custom-reset-current (&rest ignore)
686 "Reset all modified group members to their current value."
687 (interactive)
688 (let ((children custom-options))
689 (mapcar (lambda (child)
690 (when (eq (widget-get child :custom-state) 'modified)
691 (widget-apply child :custom-reset-current)))
692 children)))
694 (defun Custom-reset-saved (&rest ignore)
695 "Reset all modified or set group members to their saved value."
696 (interactive)
697 (let ((children custom-options))
698 (mapcar (lambda (child)
699 (when (eq (widget-get child :custom-state) 'modified)
700 (widget-apply child :custom-reset-saved)))
701 children)))
703 (defun Custom-reset-standard (&rest ignore)
704 "Reset all modified, set, or saved group members to their standard settings."
705 (interactive)
706 (let ((children custom-options))
707 (mapcar (lambda (child)
708 (when (eq (widget-get child :custom-state) 'modified)
709 (widget-apply child :custom-reset-standard)))
710 children)))
712 ;;; The Customize Commands
714 (defun custom-prompt-variable (prompt-var prompt-val)
715 "Prompt for a variable and a value and return them as a list.
716 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
717 prompt for the value. The %s escape in PROMPT-VAL is replaced with
718 the name of the variable.
720 If the variable has a `variable-interactive' property, that is used as if
721 it were the arg to `interactive' (which see) to interactively read the value.
723 If the variable has a `custom-type' property, it must be a widget and the
724 `:prompt-value' property of that widget will be used for reading the value."
725 (let* ((var (read-variable prompt-var))
726 (minibuffer-help-form '(describe-variable var)))
727 (list var
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)))))))
748 ;;;###autoload
749 (defun customize-set-value (var val)
750 "Set VARIABLE to VALUE. VALUE is a Lisp object.
752 If VARIABLE has a `variable-interactive' property, that is used as if
753 it were the arg to `interactive' (which see) to interactively read the value.
755 If VARIABLE has a `custom-type' property, it must be a widget and the
756 `:prompt-value' property of that widget will be used for reading the value."
757 (interactive (custom-prompt-variable "Set variable: "
758 "Set %s to value: "))
760 (set var val))
762 ;;;###autoload
763 (defun customize-set-variable (var val)
764 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
766 If VARIABLE has a `custom-set' property, that is used for setting
767 VARIABLE, otherwise `set-default' is used.
769 The `customized-value' property of the VARIABLE will be set to a list
770 with a quoted VALUE as its sole list member.
772 If VARIABLE has a `variable-interactive' property, that is used as if
773 it were the arg to `interactive' (which see) to interactively read the value.
775 If VARIABLE has a `custom-type' property, it must be a widget and the
776 `:prompt-value' property of that widget will be used for reading the value. "
777 (interactive (custom-prompt-variable "Set variable: "
778 "Set customized value for %s to: "))
779 (funcall (or (get var 'custom-set) 'set-default) var val)
780 (put var 'customized-value (list (custom-quote val))))
782 ;;;###autoload
783 (defun customize-save-variable (var val)
784 "Set the default for VARIABLE to VALUE, and save it for future sessions.
785 If VARIABLE has a `custom-set' property, that is used for setting
786 VARIABLE, otherwise `set-default' is used.
788 The `customized-value' property of the VARIABLE will be set to a list
789 with a quoted VALUE as its sole list member.
791 If VARIABLE has a `variable-interactive' property, that is used as if
792 it were the arg to `interactive' (which see) to interactively read the value.
794 If VARIABLE has a `custom-type' property, it must be a widget and the
795 `:prompt-value' property of that widget will be used for reading the value. "
796 (interactive (custom-prompt-variable "Set and ave variable: "
797 "Set and save value for %s as: "))
798 (funcall (or (get var 'custom-set) 'set-default) var val)
799 (put var 'saved-value (list (custom-quote val)))
800 (custom-save-all))
802 ;;;###autoload
803 (defun customize ()
804 "Select a customization buffer which you can use to set user options.
805 User options are structured into \"groups\".
806 Initially the top-level group `Emacs' and its immediate subgroups
807 are shown; the contents of those subgroups are initially hidden."
808 (interactive)
809 (customize-group 'emacs))
811 ;;;###autoload
812 (defun customize-group (group)
813 "Customize GROUP, which must be a customization group."
814 (interactive (list (let ((completion-ignore-case t))
815 (completing-read "Customize group: (default emacs) "
816 obarray
817 (lambda (symbol)
818 (or (get symbol 'custom-loads)
819 (get symbol 'custom-group)))
820 t))))
821 (when (stringp group)
822 (if (string-equal "" group)
823 (setq group 'emacs)
824 (setq group (intern group))))
825 (or (get group 'custom-group)
826 (custom-load-symbol group))
827 (let ((name (format "*Customize Group: %s*"
828 (custom-unlispify-tag-name group))))
829 (if (get-buffer name)
830 (pop-to-buffer name)
831 (custom-buffer-create (list (list group 'custom-group))
832 name
833 (concat " for group "
834 (custom-unlispify-tag-name group))))))
836 ;;;###autoload
837 (defun customize-group-other-window (group)
838 "Customize GROUP, which must be a customization group."
839 (interactive (list (let ((completion-ignore-case t))
840 (completing-read "Customize group: (default emacs) "
841 obarray
842 (lambda (symbol)
843 (or (get symbol 'custom-loads)
844 (get symbol 'custom-group)))
845 t))))
846 (when (stringp group)
847 (if (string-equal "" group)
848 (setq group 'emacs)
849 (setq group (intern group))))
850 (or (get group 'custom-group)
851 (custom-load-symbol group))
852 (let ((name (format "*Customize Group: %s*"
853 (custom-unlispify-tag-name group))))
854 (if (get-buffer name)
855 (let ((window (selected-window)))
856 (pop-to-buffer name)
857 (select-window window))
858 (custom-buffer-create-other-window
859 (list (list group 'custom-group))
860 name
861 (concat " for group "
862 (custom-unlispify-tag-name group))))))
864 ;;;###autoload
865 (defalias 'customize-variable 'customize-option)
867 ;;;###autoload
868 (defun customize-option (symbol)
869 "Customize SYMBOL, which must be a user option variable."
870 (interactive (custom-variable-prompt))
871 (custom-buffer-create (list (list symbol 'custom-variable))
872 (format "*Customize Option: %s*"
873 (custom-unlispify-tag-name symbol))))
875 ;;;###autoload
876 (defun customize-changed-options (since-version)
877 "Customize all user option variables whose default values changed recently.
878 This means, in other words, variables and groups defined with a `:version'
879 option."
880 (interactive "sCustomize options changed, since version (default all versions): ")
881 (if (equal since-version "")
882 (setq since-version nil))
883 (let ((found nil))
884 (mapatoms (lambda (symbol)
885 (and (or (boundp symbol)
886 ;; For groups the previous test fails, this one
887 ;; could be used to determine if symbol is a
888 ;; group. Is there a better way for this?
889 (get symbol 'group-documentation))
890 (let ((version (get symbol 'custom-version)))
891 (and version
892 (or (null since-version)
893 (customize-version-lessp since-version version))))
894 (setq found
895 ;; We have to set the right thing here,
896 ;; depending if we have a group or a
897 ;; variable.
898 (if (get symbol 'group-documentation)
899 (cons (list symbol 'custom-group) found)
900 (cons (list symbol 'custom-variable) found))))))
901 (if (not found)
902 (error "No user options have changed defaults in recent Emacs versions")
903 (custom-buffer-create (custom-sort-items found t nil)
904 "*Customize Changed Options*"))))
906 (defun customize-version-lessp (version1 version2)
907 (let (major1 major2 minor1 minor2)
908 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1)
909 (setq major1 (read (match-string 1 version1)))
910 (setq minor1 (read (match-string 2 version1)))
911 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2)
912 (setq major2 (read (match-string 1 version2)))
913 (setq minor2 (read (match-string 2 version2)))
914 (or (< major1 major2)
915 (and (= major1 major2)
916 (< minor1 minor2)))))
918 ;;;###autoload
919 (defalias 'customize-variable-other-window 'customize-option-other-window)
921 ;;;###autoload
922 (defun customize-option-other-window (symbol)
923 "Customize SYMBOL, which must be a user option variable.
924 Show the buffer in another window, but don't select it."
925 (interactive (custom-variable-prompt))
926 (custom-buffer-create-other-window
927 (list (list symbol 'custom-variable))
928 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
930 ;;;###autoload
931 (defun customize-face (&optional symbol)
932 "Customize SYMBOL, which should be a face name or nil.
933 If SYMBOL is nil, customize all faces."
934 (interactive (list (completing-read "Customize face: (default all) "
935 obarray 'custom-facep)))
936 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
937 (custom-buffer-create (custom-sort-items
938 (mapcar (lambda (symbol)
939 (list symbol 'custom-face))
940 (face-list))
941 t nil)
942 "*Customize Faces*")
943 (when (stringp symbol)
944 (setq symbol (intern symbol)))
945 (unless (symbolp symbol)
946 (error "Should be a symbol %S" symbol))
947 (custom-buffer-create (list (list symbol 'custom-face))
948 (format "*Customize Face: %s*"
949 (custom-unlispify-tag-name symbol)))))
951 ;;;###autoload
952 (defun customize-face-other-window (&optional symbol)
953 "Show customization buffer for FACE in other window."
954 (interactive (list (completing-read "Customize face: "
955 obarray 'custom-facep)))
956 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
958 (if (stringp symbol)
959 (setq symbol (intern symbol)))
960 (unless (symbolp symbol)
961 (error "Should be a symbol %S" symbol))
962 (custom-buffer-create-other-window
963 (list (list symbol 'custom-face))
964 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol)))))
966 ;;;###autoload
967 (defun customize-customized ()
968 "Customize all user options set since the last save in this session."
969 (interactive)
970 (let ((found nil))
971 (mapatoms (lambda (symbol)
972 (and (get symbol 'customized-face)
973 (custom-facep symbol)
974 (push (list symbol 'custom-face) found))
975 (and (get symbol 'customized-value)
976 (boundp symbol)
977 (push (list symbol 'custom-variable) found))))
978 (if (not found)
979 (error "No customized user options")
980 (custom-buffer-create (custom-sort-items found t nil)
981 "*Customize Customized*"))))
983 ;;;###autoload
984 (defun customize-saved ()
985 "Customize all already saved user options."
986 (interactive)
987 (let ((found nil))
988 (mapatoms (lambda (symbol)
989 (and (get symbol 'saved-face)
990 (custom-facep symbol)
991 (push (list symbol 'custom-face) found))
992 (and (get symbol 'saved-value)
993 (boundp symbol)
994 (push (list symbol 'custom-variable) found))))
995 (if (not found )
996 (error "No saved user options")
997 (custom-buffer-create (custom-sort-items found t nil)
998 "*Customize Saved*"))))
1000 ;;;###autoload
1001 (defun customize-apropos (regexp &optional all)
1002 "Customize all user options matching REGEXP.
1003 If ALL is `options', include only options.
1004 If ALL is `faces', include only faces.
1005 If ALL is `groups', include only groups.
1006 If ALL is t (interactively, with prefix arg), include options which are not
1007 user-settable, as well as faces and groups."
1008 (interactive "sCustomize regexp: \nP")
1009 (let ((found nil))
1010 (mapatoms (lambda (symbol)
1011 (when (string-match regexp (symbol-name symbol))
1012 (when (and (not (memq all '(faces options)))
1013 (get symbol 'custom-group))
1014 (push (list symbol 'custom-group) found))
1015 (when (and (not (memq all '(options groups)))
1016 (custom-facep symbol))
1017 (push (list symbol 'custom-face) found))
1018 (when (and (not (memq all '(groups faces)))
1019 (boundp symbol)
1020 (or (get symbol 'saved-value)
1021 (get symbol 'standard-value)
1022 (if (memq all '(nil options))
1023 (user-variable-p symbol)
1024 (get symbol 'variable-documentation))))
1025 (push (list symbol 'custom-variable) found)))))
1026 (if (not found)
1027 (error "No matches")
1028 (custom-buffer-create (custom-sort-items found t
1029 custom-buffer-order-groups)
1030 "*Customize Apropos*"))))
1032 ;;;###autoload
1033 (defun customize-apropos-options (regexp &optional arg)
1034 "Customize all user options matching REGEXP.
1035 With prefix arg, include options which are not user-settable."
1036 (interactive "sCustomize regexp: \nP")
1037 (customize-apropos regexp (or arg 'options)))
1039 ;;;###autoload
1040 (defun customize-apropos-faces (regexp)
1041 "Customize all user faces matching REGEXP."
1042 (interactive "sCustomize regexp: \n")
1043 (customize-apropos regexp 'faces))
1045 ;;;###autoload
1046 (defun customize-apropos-groups (regexp)
1047 "Customize all user groups matching REGEXP."
1048 (interactive "sCustomize regexp: \n")
1049 (customize-apropos regexp 'groups))
1051 ;;; Buffer.
1053 (defcustom custom-buffer-style 'links
1054 "Control the presentation style for customization buffers.
1055 The value should be a symbol, one of:
1057 brackets: groups nest within each other with big horizontal brackets.
1058 links: groups have links to subgroups."
1059 :type '(radio (const brackets)
1060 (const links))
1061 :group 'custom-buffer)
1063 (defcustom custom-buffer-indent 3
1064 "Number of spaces to indent nested groups."
1065 :type 'integer
1066 :group 'custom-buffer)
1068 ;;;###autoload
1069 (defun custom-buffer-create (options &optional name description)
1070 "Create a buffer containing OPTIONS.
1071 Optional NAME is the name of the buffer.
1072 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1073 SYMBOL is a customization option, and WIDGET is a widget for editing
1074 that option."
1075 (unless name (setq name "*Customization*"))
1076 (kill-buffer (get-buffer-create name))
1077 (pop-to-buffer (get-buffer-create name))
1078 (custom-buffer-create-internal options description))
1080 ;;;###autoload
1081 (defun custom-buffer-create-other-window (options &optional name description)
1082 "Create a buffer containing OPTIONS.
1083 Optional NAME is the name of the buffer.
1084 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1085 SYMBOL is a customization option, and WIDGET is a widget for editing
1086 that option."
1087 (unless name (setq name "*Customization*"))
1088 (kill-buffer (get-buffer-create name))
1089 (let ((window (selected-window))
1090 (pop-up-windows t)
1091 (special-display-buffer-names nil)
1092 (special-display-regexps nil)
1093 (same-window-buffer-names nil)
1094 (same-window-regexps nil))
1095 (pop-to-buffer (get-buffer-create name))
1096 (custom-buffer-create-internal options description)
1097 (select-window window)))
1099 (defcustom custom-reset-button-menu nil
1100 "If non-nil, only show a single reset button in customize buffers.
1101 This button will have a menu with all three reset operations."
1102 :type 'boolean
1103 :group 'custom-buffer)
1105 (defun custom-buffer-create-internal (options &optional description)
1106 (message "Creating customization buffer...")
1107 (custom-mode)
1108 (widget-insert "This is a customization buffer")
1109 (if description
1110 (widget-insert description))
1111 (widget-insert ".
1112 Square brackets show active fields; type RET or click mouse-1
1113 on an active field to invoke its action. Editing an option value
1114 changes the text in the buffer; invoke the State button and
1115 choose the Set operation to set the option value.
1116 Invoke ")
1117 (widget-create 'info-link
1118 :tag "Help"
1119 :help-echo "Read the online help."
1120 "(emacs)Easy Customization")
1121 (widget-insert " for more information.\n\n")
1122 (message "Creating customization buttons...")
1123 (widget-insert "Operate on everything in this buffer:\n ")
1124 (widget-create 'push-button
1125 :tag "Set for Current Session"
1126 :help-echo "\
1127 Make your editing in this buffer take effect for this session."
1128 :action (lambda (widget &optional event)
1129 (Custom-set)))
1130 (widget-insert " ")
1131 (widget-create 'push-button
1132 :tag "Save for Future Sessions"
1133 :help-echo "\
1134 Make your editing in this buffer take effect for future Emacs sessions."
1135 :action (lambda (widget &optional event)
1136 (Custom-save)))
1137 (if custom-reset-button-menu
1138 (progn
1139 (widget-insert " ")
1140 (widget-create 'push-button
1141 :tag "Reset"
1142 :help-echo "Show a menu with reset operations."
1143 :mouse-down-action (lambda (&rest junk) t)
1144 :action (lambda (widget &optional event)
1145 (custom-reset event))))
1146 (widget-insert "\n ")
1147 (widget-create 'push-button
1148 :tag "Reset"
1149 :help-echo "\
1150 Reset all edited text in this buffer to reflect current values."
1151 :action 'Custom-reset-current)
1152 (widget-insert " ")
1153 (widget-create 'push-button
1154 :tag "Reset to Saved"
1155 :help-echo "\
1156 Reset all values in this buffer to their saved settings."
1157 :action 'Custom-reset-saved)
1158 (widget-insert " ")
1159 (widget-create 'push-button
1160 :tag "Reset to Standard"
1161 :help-echo "\
1162 Reset all values in this buffer to their standard settings."
1163 :action 'Custom-reset-standard))
1164 (widget-insert " ")
1165 (widget-create 'push-button
1166 :tag "Bury Buffer"
1167 :help-echo "Bury the buffer."
1168 :action (lambda (widget &optional event)
1169 (bury-buffer)))
1170 (widget-insert "\n\n")
1171 (message "Creating customization items...")
1172 (setq custom-options
1173 (if (= (length options) 1)
1174 (mapcar (lambda (entry)
1175 (widget-create (nth 1 entry)
1176 :documentation-shown t
1177 :custom-state 'unknown
1178 :tag (custom-unlispify-tag-name
1179 (nth 0 entry))
1180 :value (nth 0 entry)))
1181 options)
1182 (let ((count 0)
1183 (length (length options)))
1184 (mapcar (lambda (entry)
1185 (prog2
1186 (message "Creating customization items %2d%%..."
1187 (/ (* 100.0 count) length))
1188 (widget-create (nth 1 entry)
1189 :tag (custom-unlispify-tag-name
1190 (nth 0 entry))
1191 :value (nth 0 entry))
1192 (setq count (1+ count))
1193 (unless (eq (preceding-char) ?\n)
1194 (widget-insert "\n"))
1195 (widget-insert "\n")))
1196 options))))
1197 (unless (eq (preceding-char) ?\n)
1198 (widget-insert "\n"))
1199 (message "Creating customization items %2d%%...done" 100)
1200 (unless (eq custom-buffer-style 'tree)
1201 (mapcar 'custom-magic-reset custom-options))
1202 (message "Creating customization setup...")
1203 (widget-setup)
1204 (goto-char (point-min))
1205 (message "Creating customization buffer...done"))
1207 ;;; The Tree Browser.
1209 ;;;###autoload
1210 (defun customize-browse (&optional group)
1211 "Create a tree browser for the customize hierarchy."
1212 (interactive)
1213 (unless group
1214 (setq group 'emacs))
1215 (let ((name "*Customize Browser*"))
1216 (kill-buffer (get-buffer-create name))
1217 (pop-to-buffer (get-buffer-create name)))
1218 (custom-mode)
1219 (widget-insert "\
1220 Square brackets show active fields; type RET or click mouse-1
1221 on an active field to invoke its action.
1222 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1223 (if custom-browse-only-groups
1224 (widget-insert "\
1225 Invoke the [Group] button below to edit that item in another window.\n\n")
1226 (widget-insert "Invoke the ")
1227 (widget-create 'item
1228 :format "%t"
1229 :tag "[Group]"
1230 :tag-glyph "folder")
1231 (widget-insert ", ")
1232 (widget-create 'item
1233 :format "%t"
1234 :tag "[Face]"
1235 :tag-glyph "face")
1236 (widget-insert ", and ")
1237 (widget-create 'item
1238 :format "%t"
1239 :tag "[Option]"
1240 :tag-glyph "option")
1241 (widget-insert " buttons below to edit that
1242 item in another window.\n\n"))
1243 (let ((custom-buffer-style 'tree))
1244 (widget-create 'custom-group
1245 :custom-last t
1246 :custom-state 'unknown
1247 :tag (custom-unlispify-tag-name group)
1248 :value group))
1249 (goto-char (point-min)))
1251 (define-widget 'custom-browse-visibility 'item
1252 "Control visibility of items in the customize tree browser."
1253 :format "%[[%t]%]"
1254 :action 'custom-browse-visibility-action)
1256 (defun custom-browse-visibility-action (widget &rest ignore)
1257 (let ((custom-buffer-style 'tree))
1258 (custom-toggle-parent widget)))
1260 (define-widget 'custom-browse-group-tag 'push-button
1261 "Show parent in other window when activated."
1262 :tag "Group"
1263 :tag-glyph "folder"
1264 :action 'custom-browse-group-tag-action)
1266 (defun custom-browse-group-tag-action (widget &rest ignore)
1267 (let ((parent (widget-get widget :parent)))
1268 (customize-group-other-window (widget-value parent))))
1270 (define-widget 'custom-browse-variable-tag 'push-button
1271 "Show parent in other window when activated."
1272 :tag "Option"
1273 :tag-glyph "option"
1274 :action 'custom-browse-variable-tag-action)
1276 (defun custom-browse-variable-tag-action (widget &rest ignore)
1277 (let ((parent (widget-get widget :parent)))
1278 (customize-variable-other-window (widget-value parent))))
1280 (define-widget 'custom-browse-face-tag 'push-button
1281 "Show parent in other window when activated."
1282 :tag "Face"
1283 :tag-glyph "face"
1284 :action 'custom-browse-face-tag-action)
1286 (defun custom-browse-face-tag-action (widget &rest ignore)
1287 (let ((parent (widget-get widget :parent)))
1288 (customize-face-other-window (widget-value parent))))
1290 (defconst custom-browse-alist '((" " "space")
1291 (" | " "vertical")
1292 ("-\\ " "top")
1293 (" |-" "middle")
1294 (" `-" "bottom")))
1296 (defun custom-browse-insert-prefix (prefix)
1297 "Insert PREFIX. On XEmacs convert it to line graphics."
1298 (if nil ; (string-match "XEmacs" emacs-version)
1299 (progn
1300 (insert "*")
1301 (while (not (string-equal prefix ""))
1302 (let ((entry (substring prefix 0 3)))
1303 (setq prefix (substring prefix 3))
1304 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1305 (name (nth 1 (assoc entry custom-browse-alist))))
1306 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1307 (overlay-put overlay 'start-open t)
1308 (overlay-put overlay 'end-open t)))))
1309 (insert prefix)))
1311 ;;; Modification of Basic Widgets.
1313 ;; We add extra properties to the basic widgets needed here. This is
1314 ;; fine, as long as we are careful to stay within out own namespace.
1316 ;; We want simple widgets to be displayed by default, but complex
1317 ;; widgets to be hidden.
1319 (widget-put (get 'item 'widget-type) :custom-show t)
1320 (widget-put (get 'editable-field 'widget-type)
1321 :custom-show (lambda (widget value)
1322 (let ((pp (pp-to-string value)))
1323 (cond ((string-match "\n" pp)
1324 nil)
1325 ((> (length pp) 40)
1326 nil)
1327 (t t)))))
1328 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1330 ;;; The `custom-manual' Widget.
1332 (define-widget 'custom-manual 'info-link
1333 "Link to the manual entry for this customization option."
1334 :help-echo "Read the manual entry for this option."
1335 :tag "Manual")
1337 ;;; The `custom-magic' Widget.
1339 (defgroup custom-magic-faces nil
1340 "Faces used by the magic button."
1341 :group 'custom-faces
1342 :group 'custom-buffer)
1344 (defface custom-invalid-face '((((class color))
1345 (:foreground "yellow" :background "red"))
1347 (:bold t :italic t :underline t)))
1348 "Face used when the customize item is invalid."
1349 :group 'custom-magic-faces)
1351 (defface custom-rogue-face '((((class color))
1352 (:foreground "pink" :background "black"))
1354 (:underline t)))
1355 "Face used when the customize item is not defined for customization."
1356 :group 'custom-magic-faces)
1358 (defface custom-modified-face '((((class color))
1359 (:foreground "white" :background "blue"))
1361 (:italic t :bold)))
1362 "Face used when the customize item has been modified."
1363 :group 'custom-magic-faces)
1365 (defface custom-set-face '((((class color))
1366 (:foreground "blue" :background "white"))
1368 (:italic t)))
1369 "Face used when the customize item has been set."
1370 :group 'custom-magic-faces)
1372 (defface custom-changed-face '((((class color))
1373 (:foreground "white" :background "blue"))
1375 (:italic t)))
1376 "Face used when the customize item has been changed."
1377 :group 'custom-magic-faces)
1379 (defface custom-saved-face '((t (:underline t)))
1380 "Face used when the customize item has been saved."
1381 :group 'custom-magic-faces)
1383 (defconst custom-magic-alist '((nil "#" underline "\
1384 uninitialized, you should not see this.")
1385 (unknown "?" italic "\
1386 unknown, you should not see this.")
1387 (hidden "-" default "\
1388 hidden, invoke \"Show\" in the previous line to show." "\
1389 group now hidden, invoke \"Show\", above, to show contents.")
1390 (invalid "x" custom-invalid-face "\
1391 the value displayed for this %c is invalid and cannot be set.")
1392 (modified "*" custom-modified-face "\
1393 you have edited the value as text, but you have not set the %c." "\
1394 you have edited something in this group, but not set it.")
1395 (set "+" custom-set-face "\
1396 you have set this %c, but not saved it for future sessions." "\
1397 something in this group has been set, but not saved.")
1398 (changed ":" custom-changed-face "\
1399 this %c has been changed outside the customize buffer." "\
1400 something in this group has been changed outside customize.")
1401 (saved "!" custom-saved-face "\
1402 this %c has been set and saved." "\
1403 something in this group has been set and saved.")
1404 (rogue "@" custom-rogue-face "\
1405 this %c has not been changed with customize." "\
1406 something in this group is not prepared for customization.")
1407 (standard " " nil "\
1408 this %c is unchanged from its standard setting." "\
1409 visible group members are all at standard settings."))
1410 "Alist of customize option states.
1411 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1413 STATE is one of the following symbols:
1415 `nil'
1416 For internal use, should never occur.
1417 `unknown'
1418 For internal use, should never occur.
1419 `hidden'
1420 This item is not being displayed.
1421 `invalid'
1422 This item is modified, but has an invalid form.
1423 `modified'
1424 This item is modified, and has a valid form.
1425 `set'
1426 This item has been set but not saved.
1427 `changed'
1428 The current value of this item has been changed temporarily.
1429 `saved'
1430 This item is marked for saving.
1431 `rogue'
1432 This item has no customization information.
1433 `standard'
1434 This item is unchanged from the standard setting.
1436 MAGIC is a string used to present that state.
1438 FACE is a face used to present the state.
1440 ITEM-DESC is a string describing the state for options.
1442 GROUP-DESC is a string describing the state for groups. If this is
1443 left out, ITEM-DESC will be used.
1445 The string %c in either description will be replaced with the
1446 category of the item. These are `group'. `option', and `face'.
1448 The list should be sorted most significant first.")
1450 (defcustom custom-magic-show 'long
1451 "If non-nil, show textual description of the state.
1452 If `long', show a full-line description, not just one word."
1453 :type '(choice (const :tag "no" nil)
1454 (const short)
1455 (const long))
1456 :group 'custom-buffer)
1458 (defcustom custom-magic-show-hidden '(option face)
1459 "Control whether the State button is shown for hidden items.
1460 The value should be a list with the custom categories where the State
1461 button should be visible. Possible categories are `group', `option',
1462 and `face'."
1463 :type '(set (const group) (const option) (const face))
1464 :group 'custom-buffer)
1466 (defcustom custom-magic-show-button nil
1467 "Show a \"magic\" button indicating the state of each customization option."
1468 :type 'boolean
1469 :group 'custom-buffer)
1471 (define-widget 'custom-magic 'default
1472 "Show and manipulate state for a customization option."
1473 :format "%v"
1474 :action 'widget-parent-action
1475 :notify 'ignore
1476 :value-get 'ignore
1477 :value-create 'custom-magic-value-create
1478 :value-delete 'widget-children-value-delete)
1480 (defun widget-magic-mouse-down-action (widget &optional event)
1481 ;; Non-nil unless hidden.
1482 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1483 :custom-state)
1484 'hidden)))
1486 (defun custom-magic-value-create (widget)
1487 ;; Create compact status report for WIDGET.
1488 (let* ((parent (widget-get widget :parent))
1489 (state (widget-get parent :custom-state))
1490 (hidden (eq state 'hidden))
1491 (entry (assq state custom-magic-alist))
1492 (magic (nth 1 entry))
1493 (face (nth 2 entry))
1494 (category (widget-get parent :custom-category))
1495 (text (or (and (eq category 'group)
1496 (nth 4 entry))
1497 (nth 3 entry)))
1498 (form (widget-get parent :custom-form))
1499 children)
1500 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1501 (setq text (concat (match-string 1 text)
1502 (symbol-name category)
1503 (match-string 2 text))))
1504 (when (and custom-magic-show
1505 (or (not hidden)
1506 (memq category custom-magic-show-hidden)))
1507 (insert " ")
1508 (when (and (eq category 'group)
1509 (not (and (eq custom-buffer-style 'links)
1510 (> (widget-get parent :custom-level) 1))))
1511 (insert-char ?\ (* custom-buffer-indent
1512 (widget-get parent :custom-level))))
1513 (push (widget-create-child-and-convert
1514 widget 'choice-item
1515 :help-echo "Change the state of this item."
1516 :format (if hidden "%t" "%[%t%]")
1517 :button-prefix 'widget-push-button-prefix
1518 :button-suffix 'widget-push-button-suffix
1519 :mouse-down-action 'widget-magic-mouse-down-action
1520 :tag "State")
1521 children)
1522 (insert ": ")
1523 (let ((start (point)))
1524 (if (eq custom-magic-show 'long)
1525 (insert text)
1526 (insert (symbol-name state)))
1527 (cond ((eq form 'lisp)
1528 (insert " (lisp)"))
1529 ((eq form 'mismatch)
1530 (insert " (mismatch)")))
1531 (put-text-property start (point) 'face 'custom-state-face))
1532 (insert "\n"))
1533 (when (and (eq category 'group)
1534 (not (and (eq custom-buffer-style 'links)
1535 (> (widget-get parent :custom-level) 1))))
1536 (insert-char ?\ (* custom-buffer-indent
1537 (widget-get parent :custom-level))))
1538 (when custom-magic-show-button
1539 (when custom-magic-show
1540 (let ((indent (widget-get parent :indent)))
1541 (when indent
1542 (insert-char ? indent))))
1543 (push (widget-create-child-and-convert
1544 widget 'choice-item
1545 :mouse-down-action 'widget-magic-mouse-down-action
1546 :button-face face
1547 :button-prefix ""
1548 :button-suffix ""
1549 :help-echo "Change the state."
1550 :format (if hidden "%t" "%[%t%]")
1551 :tag (if (memq form '(lisp mismatch))
1552 (concat "(" magic ")")
1553 (concat "[" magic "]")))
1554 children)
1555 (insert " "))
1556 (widget-put widget :children children)))
1558 (defun custom-magic-reset (widget)
1559 "Redraw the :custom-magic property of WIDGET."
1560 (let ((magic (widget-get widget :custom-magic)))
1561 (widget-value-set magic (widget-value magic))))
1563 ;;; The `custom' Widget.
1565 (defface custom-button-face nil
1566 "Face used for buttons in customization buffers."
1567 :group 'custom-faces)
1569 (defface custom-documentation-face nil
1570 "Face used for documentation strings in customization buffers."
1571 :group 'custom-faces)
1573 (defface custom-state-face '((((class color)
1574 (background dark))
1575 (:foreground "lime green"))
1576 (((class color)
1577 (background light))
1578 (:foreground "dark green"))
1579 (t nil))
1580 "Face used for State descriptions in the customize buffer."
1581 :group 'custom-faces)
1583 (define-widget 'custom 'default
1584 "Customize a user option."
1585 :format "%v"
1586 :convert-widget 'custom-convert-widget
1587 :notify 'custom-notify
1588 :custom-prefix ""
1589 :custom-level 1
1590 :custom-state 'hidden
1591 :documentation-property 'widget-subclass-responsibility
1592 :value-create 'widget-subclass-responsibility
1593 :value-delete 'widget-children-value-delete
1594 :value-get 'widget-value-value-get
1595 :validate 'widget-children-validate
1596 :match (lambda (widget value) (symbolp value)))
1598 (defun custom-convert-widget (widget)
1599 ;; Initialize :value and :tag from :args in WIDGET.
1600 (let ((args (widget-get widget :args)))
1601 (when args
1602 (widget-put widget :value (widget-apply widget
1603 :value-to-internal (car args)))
1604 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1605 (widget-put widget :args nil)))
1606 widget)
1608 (defun custom-notify (widget &rest args)
1609 "Keep track of changes."
1610 (let ((state (widget-get widget :custom-state)))
1611 (unless (eq state 'modified)
1612 (unless (memq state '(nil unknown hidden))
1613 (widget-put widget :custom-state 'modified))
1614 (custom-magic-reset widget)
1615 (apply 'widget-default-notify widget args))))
1617 (defun custom-redraw (widget)
1618 "Redraw WIDGET with current settings."
1619 (let ((line (count-lines (point-min) (point)))
1620 (column (current-column))
1621 (pos (point))
1622 (from (marker-position (widget-get widget :from)))
1623 (to (marker-position (widget-get widget :to))))
1624 (save-excursion
1625 (widget-value-set widget (widget-value widget))
1626 (custom-redraw-magic widget))
1627 (when (and (>= pos from) (<= pos to))
1628 (condition-case nil
1629 (progn
1630 (if (> column 0)
1631 (goto-line line)
1632 (goto-line (1+ line)))
1633 (move-to-column column))
1634 (error nil)))))
1636 (defun custom-redraw-magic (widget)
1637 "Redraw WIDGET state with current settings."
1638 (while widget
1639 (let ((magic (widget-get widget :custom-magic)))
1640 (cond (magic
1641 (widget-value-set magic (widget-value magic))
1642 (when (setq widget (widget-get widget :group))
1643 (custom-group-state-update widget)))
1645 (setq widget nil)))))
1646 (widget-setup))
1648 (defun custom-show (widget value)
1649 "Non-nil if WIDGET should be shown with VALUE by default."
1650 (let ((show (widget-get widget :custom-show)))
1651 (cond ((null show)
1652 nil)
1653 ((eq t show)
1656 (funcall show widget value)))))
1658 (defvar custom-load-recursion nil
1659 "Hack to avoid recursive dependencies.")
1661 (defun custom-load-symbol (symbol)
1662 "Load all dependencies for SYMBOL."
1663 (unless custom-load-recursion
1664 (let ((custom-load-recursion t)
1665 (loads (get symbol 'custom-loads))
1666 load)
1667 (while loads
1668 (setq load (car loads)
1669 loads (cdr loads))
1670 (cond ((symbolp load)
1671 (condition-case nil
1672 (require load)
1673 (error nil)))
1674 ;; Don't reload a file already loaded.
1675 ((and (boundp 'preloaded-file-list)
1676 (member load preloaded-file-list)))
1677 ((assoc load load-history))
1678 ((assoc (locate-library load) load-history))
1680 (condition-case nil
1681 ;; Without this, we would load cus-edit recursively.
1682 ;; We are still loading it when we call this,
1683 ;; and it is not in load-history yet.
1684 (or (equal load "cus-edit")
1685 (load-library load))
1686 (error nil))))))))
1688 (defun custom-load-widget (widget)
1689 "Load all dependencies for WIDGET."
1690 (custom-load-symbol (widget-value widget)))
1692 (defun custom-unloaded-symbol-p (symbol)
1693 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1694 (let ((found nil)
1695 (loads (get symbol 'custom-loads))
1696 load)
1697 (while loads
1698 (setq load (car loads)
1699 loads (cdr loads))
1700 (cond ((symbolp load)
1701 (unless (featurep load)
1702 (setq found t)))
1703 ((assoc load load-history))
1704 ((assoc (locate-library load) load-history)
1705 (message nil))
1707 (setq found t))))
1708 found))
1710 (defun custom-unloaded-widget-p (widget)
1711 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1712 (custom-unloaded-symbol-p (widget-value widget)))
1714 (defun custom-toggle-hide (widget)
1715 "Toggle visibility of WIDGET."
1716 (custom-load-widget widget)
1717 (let ((state (widget-get widget :custom-state)))
1718 (cond ((memq state '(invalid modified))
1719 (error "There are unset changes"))
1720 ((eq state 'hidden)
1721 (widget-put widget :custom-state 'unknown))
1723 (widget-put widget :documentation-shown nil)
1724 (widget-put widget :custom-state 'hidden)))
1725 (custom-redraw widget)
1726 (widget-setup)))
1728 (defun custom-toggle-parent (widget &rest ignore)
1729 "Toggle visibility of parent of WIDGET."
1730 (custom-toggle-hide (widget-get widget :parent)))
1732 (defun custom-add-see-also (widget &optional prefix)
1733 "Add `See also ...' to WIDGET if there are any links.
1734 Insert PREFIX first if non-nil."
1735 (let* ((symbol (widget-get widget :value))
1736 (links (get symbol 'custom-links))
1737 (many (> (length links) 2))
1738 (buttons (widget-get widget :buttons))
1739 (indent (widget-get widget :indent)))
1740 (when links
1741 (when indent
1742 (insert-char ?\ indent))
1743 (when prefix
1744 (insert prefix))
1745 (insert "See also ")
1746 (while links
1747 (push (widget-create-child-and-convert widget (car links))
1748 buttons)
1749 (setq links (cdr links))
1750 (cond ((null links)
1751 (insert ".\n"))
1752 ((null (cdr links))
1753 (if many
1754 (insert ", and ")
1755 (insert " and ")))
1757 (insert ", "))))
1758 (widget-put widget :buttons buttons))))
1760 (defun custom-add-parent-links (widget &optional initial-string)
1761 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1762 The value if non-nil if any parents were found.
1763 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1764 (let ((name (widget-value widget))
1765 (type (widget-type widget))
1766 (buttons (widget-get widget :buttons))
1767 (start (point))
1768 found)
1769 (insert (or initial-string "Parent groups:"))
1770 (mapatoms (lambda (symbol)
1771 (let ((entry (assq name (get symbol 'custom-group))))
1772 (when (eq (nth 1 entry) type)
1773 (insert " ")
1774 (push (widget-create-child-and-convert
1775 widget 'custom-group-link
1776 :tag (custom-unlispify-tag-name symbol)
1777 symbol)
1778 buttons)
1779 (setq found t)))))
1780 (widget-put widget :buttons buttons)
1781 (if found
1782 (insert "\n")
1783 (delete-region start (point)))
1784 found))
1786 ;;; The `custom-variable' Widget.
1788 (defface custom-variable-tag-face '((((class color)
1789 (background dark))
1790 (:foreground "light blue" :underline t))
1791 (((class color)
1792 (background light))
1793 (:foreground "blue" :underline t))
1794 (t (:underline t)))
1795 "Face used for unpushable variable tags."
1796 :group 'custom-faces)
1798 (defface custom-variable-button-face '((t (:underline t :bold t)))
1799 "Face used for pushable variable tags."
1800 :group 'custom-faces)
1802 (defcustom custom-variable-default-form 'edit
1803 "Default form of displaying variable values."
1804 :type '(choice (const edit)
1805 (const lisp))
1806 :group 'custom-buffer
1807 :version "20.3")
1809 (define-widget 'custom-variable 'custom
1810 "Customize variable."
1811 :format "%v"
1812 :help-echo "Set or reset this variable."
1813 :documentation-property 'variable-documentation
1814 :custom-category 'option
1815 :custom-state nil
1816 :custom-menu 'custom-variable-menu-create
1817 :custom-form nil ; defaults to value of `custom-variable-default-form'
1818 :value-create 'custom-variable-value-create
1819 :action 'custom-variable-action
1820 :custom-set 'custom-variable-set
1821 :custom-save 'custom-variable-save
1822 :custom-reset-current 'custom-redraw
1823 :custom-reset-saved 'custom-variable-reset-saved
1824 :custom-reset-standard 'custom-variable-reset-standard)
1826 (defun custom-variable-type (symbol)
1827 "Return a widget suitable for editing the value of SYMBOL.
1828 If SYMBOL has a `custom-type' property, use that.
1829 Otherwise, look up symbol in `custom-guess-type-alist'."
1830 (let* ((type (or (get symbol 'custom-type)
1831 (and (not (get symbol 'standard-value))
1832 (custom-guess-type symbol))
1833 'sexp))
1834 (options (get symbol 'custom-options))
1835 (tmp (if (listp type)
1836 (copy-sequence type)
1837 (list type))))
1838 (when options
1839 (widget-put tmp :options options))
1840 tmp))
1842 (defun custom-variable-value-create (widget)
1843 "Here is where you edit the variables value."
1844 (custom-load-widget widget)
1845 (unless (widget-get widget :custom-form)
1846 (widget-put widget :custom-form custom-variable-default-form))
1847 (let* ((buttons (widget-get widget :buttons))
1848 (children (widget-get widget :children))
1849 (form (widget-get widget :custom-form))
1850 (state (widget-get widget :custom-state))
1851 (symbol (widget-get widget :value))
1852 (tag (widget-get widget :tag))
1853 (type (custom-variable-type symbol))
1854 (conv (widget-convert type))
1855 (get (or (get symbol 'custom-get) 'default-value))
1856 (prefix (widget-get widget :custom-prefix))
1857 (last (widget-get widget :custom-last))
1858 (value (if (default-boundp symbol)
1859 (funcall get symbol)
1860 (widget-get conv :value))))
1861 ;; If the widget is new, the child determine whether it is hidden.
1862 (cond (state)
1863 ((custom-show type value)
1864 (setq state 'unknown))
1866 (setq state 'hidden)))
1867 ;; If we don't know the state, see if we need to edit it in lisp form.
1868 (when (eq state 'unknown)
1869 (unless (widget-apply conv :match value)
1870 ;; (widget-apply (widget-convert type) :match value)
1871 (setq form 'mismatch)))
1872 ;; Now we can create the child widget.
1873 (cond ((eq custom-buffer-style 'tree)
1874 (insert prefix (if last " `--- " " |--- "))
1875 (push (widget-create-child-and-convert
1876 widget 'custom-browse-variable-tag)
1877 buttons)
1878 (insert " " tag "\n")
1879 (widget-put widget :buttons buttons))
1880 ((eq state 'hidden)
1881 ;; Indicate hidden value.
1882 (push (widget-create-child-and-convert
1883 widget 'item
1884 :format "%{%t%}: "
1885 :sample-face 'custom-variable-tag-face
1886 :tag tag
1887 :parent widget)
1888 buttons)
1889 (push (widget-create-child-and-convert
1890 widget 'visibility
1891 :help-echo "Show the value of this option."
1892 :action 'custom-toggle-parent
1893 nil)
1894 buttons))
1895 ((memq form '(lisp mismatch))
1896 ;; In lisp mode edit the saved value when possible.
1897 (let* ((value (cond ((get symbol 'saved-value)
1898 (car (get symbol 'saved-value)))
1899 ((get symbol 'standard-value)
1900 (car (get symbol 'standard-value)))
1901 ((default-boundp symbol)
1902 (custom-quote (funcall get symbol)))
1904 (custom-quote (widget-get conv :value))))))
1905 (insert (symbol-name symbol) ": ")
1906 (push (widget-create-child-and-convert
1907 widget 'visibility
1908 :help-echo "Hide the value of this option."
1909 :action 'custom-toggle-parent
1911 buttons)
1912 (insert " ")
1913 (push (widget-create-child-and-convert
1914 widget 'sexp
1915 :button-face 'custom-variable-button-face
1916 :format "%v"
1917 :tag (symbol-name symbol)
1918 :parent widget
1919 :value value)
1920 children)))
1922 ;; Edit mode.
1923 (let* ((format (widget-get type :format))
1924 tag-format value-format)
1925 (unless (string-match ":" format)
1926 (error "Bad format"))
1927 (setq tag-format (substring format 0 (match-end 0)))
1928 (setq value-format (substring format (match-end 0)))
1929 (push (widget-create-child-and-convert
1930 widget 'item
1931 :format tag-format
1932 :action 'custom-tag-action
1933 :help-echo "Change value of this option."
1934 :mouse-down-action 'custom-tag-mouse-down-action
1935 :button-face 'custom-variable-button-face
1936 :sample-face 'custom-variable-tag-face
1937 tag)
1938 buttons)
1939 (insert " ")
1940 (push (widget-create-child-and-convert
1941 widget 'visibility
1942 :help-echo "Hide the value of this option."
1943 :action 'custom-toggle-parent
1945 buttons)
1946 (push (widget-create-child-and-convert
1947 widget type
1948 :format value-format
1949 :value value)
1950 children))))
1951 (unless (eq custom-buffer-style 'tree)
1952 ;; Now update the state.
1953 (unless (eq (preceding-char) ?\n)
1954 (widget-insert "\n"))
1955 (if (eq state 'hidden)
1956 (widget-put widget :custom-state state)
1957 (custom-variable-state-set widget))
1958 ;; Create the magic button.
1959 (let ((magic (widget-create-child-and-convert
1960 widget 'custom-magic nil)))
1961 (widget-put widget :custom-magic magic)
1962 (push magic buttons))
1963 ;; Update properties.
1964 (widget-put widget :custom-form form)
1965 (widget-put widget :buttons buttons)
1966 (widget-put widget :children children)
1967 ;; Insert documentation.
1968 (widget-default-format-handler widget ?h)
1969 ;; See also.
1970 (unless (eq state 'hidden)
1971 (when (eq (widget-get widget :custom-level) 1)
1972 (custom-add-parent-links widget))
1973 (custom-add-see-also widget)))))
1975 (defun custom-tag-action (widget &rest args)
1976 "Pass :action to first child of WIDGET's parent."
1977 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
1978 :action args))
1980 (defun custom-tag-mouse-down-action (widget &rest args)
1981 "Pass :mouse-down-action to first child of WIDGET's parent."
1982 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
1983 :mouse-down-action args))
1985 (defun custom-variable-state-set (widget)
1986 "Set the state of WIDGET."
1987 (let* ((symbol (widget-value widget))
1988 (get (or (get symbol 'custom-get) 'default-value))
1989 (value (if (default-boundp symbol)
1990 (funcall get symbol)
1991 (widget-get widget :value)))
1993 (state (cond ((setq tmp (get symbol 'customized-value))
1994 (if (condition-case nil
1995 (equal value (eval (car tmp)))
1996 (error nil))
1997 'set
1998 'changed))
1999 ((setq tmp (get symbol 'saved-value))
2000 (if (condition-case nil
2001 (equal value (eval (car tmp)))
2002 (error nil))
2003 'saved
2004 'changed))
2005 ((setq tmp (get symbol 'standard-value))
2006 (if (condition-case nil
2007 (equal value (eval (car tmp)))
2008 (error nil))
2009 'standard
2010 'changed))
2011 (t 'rogue))))
2012 (widget-put widget :custom-state state)))
2014 (defvar custom-variable-menu
2015 '(("Set for Current Session" custom-variable-set
2016 (lambda (widget)
2017 (eq (widget-get widget :custom-state) 'modified)))
2018 ("Save for Future Sessions" custom-variable-save
2019 (lambda (widget)
2020 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2021 ("Reset to Current" custom-redraw
2022 (lambda (widget)
2023 (and (default-boundp (widget-value widget))
2024 (memq (widget-get widget :custom-state) '(modified changed)))))
2025 ("Reset to Saved" custom-variable-reset-saved
2026 (lambda (widget)
2027 (and (get (widget-value widget) 'saved-value)
2028 (memq (widget-get widget :custom-state)
2029 '(modified set changed rogue)))))
2030 ("Reset to Standard Settings" custom-variable-reset-standard
2031 (lambda (widget)
2032 (and (get (widget-value widget) 'standard-value)
2033 (memq (widget-get widget :custom-state)
2034 '(modified set changed saved rogue)))))
2035 ("---" ignore ignore)
2036 ("Don't show as Lisp expression" custom-variable-edit
2037 (lambda (widget)
2038 (eq (widget-get widget :custom-form) 'lisp)))
2039 ("Show initial Lisp expression" custom-variable-edit-lisp
2040 (lambda (widget)
2041 (eq (widget-get widget :custom-form) 'edit))))
2042 "Alist of actions for the `custom-variable' widget.
2043 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2044 the menu entry, ACTION is the function to call on the widget when the
2045 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2046 widget as an argument, and returns non-nil if ACTION is valid on that
2047 widget. If FILTER is nil, ACTION is always valid.")
2049 (defun custom-variable-action (widget &optional event)
2050 "Show the menu for `custom-variable' WIDGET.
2051 Optional EVENT is the location for the menu."
2052 (if (eq (widget-get widget :custom-state) 'hidden)
2053 (custom-toggle-hide widget)
2054 (unless (eq (widget-get widget :custom-state) 'modified)
2055 (custom-variable-state-set widget))
2056 (custom-redraw-magic widget)
2057 (let* ((completion-ignore-case t)
2058 (answer (widget-choose (concat "Operation on "
2059 (custom-unlispify-tag-name
2060 (widget-get widget :value)))
2061 (custom-menu-filter custom-variable-menu
2062 widget)
2063 event)))
2064 (if answer
2065 (funcall answer widget)))))
2067 (defun custom-variable-edit (widget)
2068 "Edit value of WIDGET."
2069 (widget-put widget :custom-state 'unknown)
2070 (widget-put widget :custom-form 'edit)
2071 (custom-redraw widget))
2073 (defun custom-variable-edit-lisp (widget)
2074 "Edit the lisp representation of the value of WIDGET."
2075 (widget-put widget :custom-state 'unknown)
2076 (widget-put widget :custom-form 'lisp)
2077 (custom-redraw widget))
2079 (defun custom-variable-set (widget)
2080 "Set the current value for the variable being edited by WIDGET."
2081 (let* ((form (widget-get widget :custom-form))
2082 (state (widget-get widget :custom-state))
2083 (child (car (widget-get widget :children)))
2084 (symbol (widget-value widget))
2085 (set (or (get symbol 'custom-set) 'set-default))
2086 val)
2087 (cond ((eq state 'hidden)
2088 (error "Cannot set hidden variable"))
2089 ((setq val (widget-apply child :validate))
2090 (goto-char (widget-get val :from))
2091 (error "%s" (widget-get val :error)))
2092 ((memq form '(lisp mismatch))
2093 (funcall set symbol (eval (setq val (widget-value child))))
2094 (put symbol 'customized-value (list val)))
2096 (funcall set symbol (setq val (widget-value child)))
2097 (put symbol 'customized-value (list (custom-quote val)))))
2098 (custom-variable-state-set widget)
2099 (custom-redraw-magic widget)))
2101 (defun custom-variable-save (widget)
2102 "Set and save the value for the variable being edited by WIDGET."
2103 (let* ((form (widget-get widget :custom-form))
2104 (state (widget-get widget :custom-state))
2105 (child (car (widget-get widget :children)))
2106 (symbol (widget-value widget))
2107 (set (or (get symbol 'custom-set) 'set-default))
2108 val)
2109 (cond ((eq state 'hidden)
2110 (error "Cannot set hidden variable"))
2111 ((setq val (widget-apply child :validate))
2112 (goto-char (widget-get val :from))
2113 (error "%s" (widget-get val :error)))
2114 ((memq form '(lisp mismatch))
2115 (put symbol 'saved-value (list (widget-value child)))
2116 (funcall set symbol (eval (widget-value child))))
2118 (put symbol
2119 'saved-value (list (custom-quote (widget-value
2120 child))))
2121 (funcall set symbol (widget-value child))))
2122 (put symbol 'customized-value nil)
2123 (custom-save-all)
2124 (custom-variable-state-set widget)
2125 (custom-redraw-magic widget)))
2127 (defun custom-variable-reset-saved (widget)
2128 "Restore the saved value for the variable being edited by WIDGET."
2129 (let* ((symbol (widget-value widget))
2130 (set (or (get symbol 'custom-set) 'set-default)))
2131 (if (get symbol 'saved-value)
2132 (condition-case nil
2133 (funcall set symbol (eval (car (get symbol 'saved-value))))
2134 (error nil))
2135 (error "No saved value for %s" symbol))
2136 (put symbol 'customized-value nil)
2137 (widget-put widget :custom-state 'unknown)
2138 (custom-redraw widget)))
2140 (defun custom-variable-reset-standard (widget)
2141 "Restore the standard setting for the variable being edited by WIDGET."
2142 (let* ((symbol (widget-value widget))
2143 (set (or (get symbol 'custom-set) 'set-default)))
2144 (if (get symbol 'standard-value)
2145 (funcall set symbol (eval (car (get symbol 'standard-value))))
2146 (error "No standard setting known for %S" symbol))
2147 (put symbol 'customized-value nil)
2148 (when (get symbol 'saved-value)
2149 (put symbol 'saved-value nil)
2150 (custom-save-all))
2151 (widget-put widget :custom-state 'unknown)
2152 (custom-redraw widget)))
2154 ;;; The `custom-face-edit' Widget.
2156 (define-widget 'custom-face-edit 'checklist
2157 "Edit face attributes."
2158 :format "%t: %v"
2159 :tag "Attributes"
2160 :extra-offset 12
2161 :button-args '(:help-echo "Control whether this attribute have any effect.")
2162 :args (mapcar (lambda (att)
2163 (list 'group
2164 :inline t
2165 :sibling-args (widget-get (nth 1 att) :sibling-args)
2166 (list 'const :format "" :value (nth 0 att))
2167 (nth 1 att)))
2168 custom-face-attributes))
2170 ;;; The `custom-display' Widget.
2172 (define-widget 'custom-display 'menu-choice
2173 "Select a display type."
2174 :tag "Display"
2175 :value t
2176 :help-echo "Specify frames where the face attributes should be used."
2177 :args '((const :tag "all" t)
2178 (checklist
2179 :offset 0
2180 :extra-offset 9
2181 :args ((group :sibling-args (:help-echo "\
2182 Only match the specified window systems.")
2183 (const :format "Type: "
2184 type)
2185 (checklist :inline t
2186 :offset 0
2187 (const :format "X "
2188 :sibling-args (:help-echo "\
2189 The X11 Window System.")
2191 (const :format "PM "
2192 :sibling-args (:help-echo "\
2193 OS/2 Presentation Manager.")
2195 (const :format "W32 "
2196 :sibling-args (:help-echo "\
2197 Windows NT/9X.")
2198 w32)
2199 (const :format "DOS "
2200 :sibling-args (:help-echo "\
2201 Plain MS-DOS.")
2203 (const :format "TTY%n"
2204 :sibling-args (:help-echo "\
2205 Plain text terminals.")
2206 tty)))
2207 (group :sibling-args (:help-echo "\
2208 Only match the frames with the specified color support.")
2209 (const :format "Class: "
2210 class)
2211 (checklist :inline t
2212 :offset 0
2213 (const :format "Color "
2214 :sibling-args (:help-echo "\
2215 Match color frames.")
2216 color)
2217 (const :format "Grayscale "
2218 :sibling-args (:help-echo "\
2219 Match grayscale frames.")
2220 grayscale)
2221 (const :format "Monochrome%n"
2222 :sibling-args (:help-echo "\
2223 Match frames with no color support.")
2224 mono)))
2225 (group :sibling-args (:help-echo "\
2226 Only match frames with the specified intensity.")
2227 (const :format "\
2228 Background brightness: "
2229 background)
2230 (checklist :inline t
2231 :offset 0
2232 (const :format "Light "
2233 :sibling-args (:help-echo "\
2234 Match frames with light backgrounds.")
2235 light)
2236 (const :format "Dark\n"
2237 :sibling-args (:help-echo "\
2238 Match frames with dark backgrounds.")
2239 dark)))))))
2241 ;;; The `custom-face' Widget.
2243 (defface custom-face-tag-face '((t (:underline t)))
2244 "Face used for face tags."
2245 :group 'custom-faces)
2247 (defcustom custom-face-default-form 'selected
2248 "Default form of displaying face definition."
2249 :type '(choice (const all)
2250 (const selected)
2251 (const lisp))
2252 :group 'custom-buffer
2253 :version "20.3")
2255 (define-widget 'custom-face 'custom
2256 "Customize face."
2257 :sample-face 'custom-face-tag-face
2258 :help-echo "Set or reset this face."
2259 :documentation-property '(lambda (face)
2260 (face-doc-string face))
2261 :value-create 'custom-face-value-create
2262 :action 'custom-face-action
2263 :custom-category 'face
2264 :custom-form nil ; defaults to value of `custom-face-default-form'
2265 :custom-set 'custom-face-set
2266 :custom-save 'custom-face-save
2267 :custom-reset-current 'custom-redraw
2268 :custom-reset-saved 'custom-face-reset-saved
2269 :custom-reset-standard 'custom-face-reset-standard
2270 :custom-menu 'custom-face-menu-create)
2272 (define-widget 'custom-face-all 'editable-list
2273 "An editable list of display specifications and attributes."
2274 :entry-format "%i %d %v"
2275 :insert-button-args '(:help-echo "Insert new display specification here.")
2276 :append-button-args '(:help-echo "Append new display specification here.")
2277 :delete-button-args '(:help-echo "Delete this display specification.")
2278 :args '((group :format "%v" custom-display custom-face-edit)))
2280 (defconst custom-face-all (widget-convert 'custom-face-all)
2281 "Converted version of the `custom-face-all' widget.")
2283 (define-widget 'custom-display-unselected 'item
2284 "A display specification that doesn't match the selected display."
2285 :match 'custom-display-unselected-match)
2287 (defun custom-display-unselected-match (widget value)
2288 "Non-nil if VALUE is an unselected display specification."
2289 (not (face-spec-set-match-display value (selected-frame))))
2291 (define-widget 'custom-face-selected 'group
2292 "Edit the attributes of the selected display in a face specification."
2293 :args '((repeat :format ""
2294 :inline t
2295 (group custom-display-unselected sexp))
2296 (group (sexp :format "") custom-face-edit)
2297 (repeat :format ""
2298 :inline t
2299 sexp)))
2301 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2302 "Converted version of the `custom-face-selected' widget.")
2304 (defun custom-face-value-create (widget)
2305 "Create a list of the display specifications for WIDGET."
2306 (let ((buttons (widget-get widget :buttons))
2307 (symbol (widget-get widget :value))
2308 (tag (widget-get widget :tag))
2309 (state (widget-get widget :custom-state))
2310 (begin (point))
2311 (is-last (widget-get widget :custom-last))
2312 (prefix (widget-get widget :custom-prefix)))
2313 (unless tag
2314 (setq tag (prin1-to-string symbol)))
2315 (cond ((eq custom-buffer-style 'tree)
2316 (insert prefix (if is-last " `--- " " |--- "))
2317 (push (widget-create-child-and-convert
2318 widget 'custom-browse-face-tag)
2319 buttons)
2320 (insert " " tag "\n")
2321 (widget-put widget :buttons buttons))
2323 ;; Create tag.
2324 (insert tag)
2325 (if (eq custom-buffer-style 'face)
2326 (insert " ")
2327 (widget-specify-sample widget begin (point))
2328 (insert ": "))
2329 ;; Sample.
2330 (and (string-match "XEmacs" emacs-version)
2331 ;; XEmacs cannot display uninitialized faces.
2332 (not (custom-facep symbol))
2333 (copy-face 'custom-face-empty symbol))
2334 (push (widget-create-child-and-convert widget 'item
2335 :format "(%{%t%})"
2336 :sample-face symbol
2337 :tag "sample")
2338 buttons)
2339 ;; Visibility.
2340 (insert " ")
2341 (push (widget-create-child-and-convert
2342 widget 'visibility
2343 :help-echo "Hide or show this face."
2344 :action 'custom-toggle-parent
2345 (not (eq state 'hidden)))
2346 buttons)
2347 ;; Magic.
2348 (insert "\n")
2349 (let ((magic (widget-create-child-and-convert
2350 widget 'custom-magic nil)))
2351 (widget-put widget :custom-magic magic)
2352 (push magic buttons))
2353 ;; Update buttons.
2354 (widget-put widget :buttons buttons)
2355 ;; Insert documentation.
2356 (widget-default-format-handler widget ?h)
2357 ;; See also.
2358 (unless (eq state 'hidden)
2359 (when (eq (widget-get widget :custom-level) 1)
2360 (custom-add-parent-links widget))
2361 (custom-add-see-also widget))
2362 ;; Editor.
2363 (unless (eq (preceding-char) ?\n)
2364 (insert "\n"))
2365 (unless (eq state 'hidden)
2366 (message "Creating face editor...")
2367 (custom-load-widget widget)
2368 (unless (widget-get widget :custom-form)
2369 (widget-put widget :custom-form custom-face-default-form))
2370 (let* ((symbol (widget-value widget))
2371 (spec (or (get symbol 'saved-face)
2372 (get symbol 'face-defface-spec)
2373 ;; Attempt to construct it.
2374 (list (list t (custom-face-attributes-get
2375 symbol (selected-frame))))))
2376 (form (widget-get widget :custom-form))
2377 (indent (widget-get widget :indent))
2378 edit)
2379 ;; If the user has changed this face in some other way,
2380 ;; edit it as the user has specified it.
2381 (if (not (face-spec-match-p symbol spec (selected-frame)))
2382 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
2383 (setq edit (widget-create-child-and-convert
2384 widget
2385 (cond ((and (eq form 'selected)
2386 (widget-apply custom-face-selected
2387 :match spec))
2388 (when indent (insert-char ?\ indent))
2389 'custom-face-selected)
2390 ((and (not (eq form 'lisp))
2391 (widget-apply custom-face-all
2392 :match spec))
2393 'custom-face-all)
2395 (when indent (insert-char ?\ indent))
2396 'sexp))
2397 :value spec))
2398 (custom-face-state-set widget)
2399 (widget-put widget :children (list edit)))
2400 (message "Creating face editor...done"))))))
2402 (defvar custom-face-menu
2403 '(("Set for Current Session" custom-face-set)
2404 ("Save for Future Sessions" custom-face-save-command)
2405 ("Reset to Saved" custom-face-reset-saved
2406 (lambda (widget)
2407 (get (widget-value widget) 'saved-face)))
2408 ("Reset to Standard Setting" custom-face-reset-standard
2409 (lambda (widget)
2410 (get (widget-value widget) 'face-defface-spec)))
2411 ("---" ignore ignore)
2412 ("Show all display specs" custom-face-edit-all
2413 (lambda (widget)
2414 (not (eq (widget-get widget :custom-form) 'all))))
2415 ("Just current attributes" custom-face-edit-selected
2416 (lambda (widget)
2417 (not (eq (widget-get widget :custom-form) 'selected))))
2418 ("Show as Lisp expression" custom-face-edit-lisp
2419 (lambda (widget)
2420 (not (eq (widget-get widget :custom-form) 'lisp)))))
2421 "Alist of actions for the `custom-face' widget.
2422 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2423 the menu entry, ACTION is the function to call on the widget when the
2424 menu is selected, and FILTER is a predicate which takes a `custom-face'
2425 widget as an argument, and returns non-nil if ACTION is valid on that
2426 widget. If FILTER is nil, ACTION is always valid.")
2428 (defun custom-face-edit-selected (widget)
2429 "Edit selected attributes of the value of WIDGET."
2430 (widget-put widget :custom-state 'unknown)
2431 (widget-put widget :custom-form 'selected)
2432 (custom-redraw widget))
2434 (defun custom-face-edit-all (widget)
2435 "Edit all attributes of the value of WIDGET."
2436 (widget-put widget :custom-state 'unknown)
2437 (widget-put widget :custom-form 'all)
2438 (custom-redraw widget))
2440 (defun custom-face-edit-lisp (widget)
2441 "Edit the lisp representation of the value of WIDGET."
2442 (widget-put widget :custom-state 'unknown)
2443 (widget-put widget :custom-form 'lisp)
2444 (custom-redraw widget))
2446 (defun custom-face-state-set (widget)
2447 "Set the state of WIDGET."
2448 (let ((symbol (widget-value widget)))
2449 (widget-put widget :custom-state (cond ((get symbol 'customized-face)
2450 'set)
2451 ((get symbol 'saved-face)
2452 'saved)
2453 ((get symbol 'face-defface-spec)
2454 'standard)
2456 'rogue)))))
2458 (defun custom-face-action (widget &optional event)
2459 "Show the menu for `custom-face' WIDGET.
2460 Optional EVENT is the location for the menu."
2461 (if (eq (widget-get widget :custom-state) 'hidden)
2462 (custom-toggle-hide widget)
2463 (let* ((completion-ignore-case t)
2464 (symbol (widget-get widget :value))
2465 (answer (widget-choose (concat "Operation on "
2466 (custom-unlispify-tag-name symbol))
2467 (custom-menu-filter custom-face-menu
2468 widget)
2469 event)))
2470 (if answer
2471 (funcall answer widget)))))
2473 (defun custom-face-set (widget)
2474 "Make the face attributes in WIDGET take effect."
2475 (let* ((symbol (widget-value widget))
2476 (child (car (widget-get widget :children)))
2477 (value (widget-value child)))
2478 (put symbol 'customized-face value)
2479 (face-spec-set symbol value)
2480 (custom-face-state-set widget)
2481 (custom-redraw-magic widget)))
2483 (defun custom-face-save-command (widget)
2484 "Save in `.emacs' the face attributes in WIDGET."
2485 (custom-face-save widget)
2486 (custom-save-all))
2488 (defun custom-face-save (widget)
2489 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2490 (let* ((symbol (widget-value widget))
2491 (child (car (widget-get widget :children)))
2492 (value (widget-value child)))
2493 (face-spec-set symbol value)
2494 (put symbol 'saved-face value)
2495 (put symbol 'customized-face nil)
2496 (custom-save-all)
2497 (custom-face-state-set widget)
2498 (custom-redraw-magic widget)))
2500 (defun custom-face-reset-saved (widget)
2501 "Restore WIDGET to the face's default attributes."
2502 (let* ((symbol (widget-value widget))
2503 (child (car (widget-get widget :children)))
2504 (value (get symbol 'saved-face)))
2505 (unless value
2506 (error "No saved value for this face"))
2507 (put symbol 'customized-face nil)
2508 (face-spec-set symbol value)
2509 (widget-value-set child value)
2510 (custom-face-state-set widget)
2511 (custom-redraw-magic widget)))
2513 (defun custom-face-reset-standard (widget)
2514 "Restore WIDGET to the face's standard settings."
2515 (let* ((symbol (widget-value widget))
2516 (child (car (widget-get widget :children)))
2517 (value (get symbol 'face-defface-spec)))
2518 (unless value
2519 (error "No standard setting for this face"))
2520 (put symbol 'customized-face nil)
2521 (when (get symbol 'saved-face)
2522 (put symbol 'saved-face nil)
2523 (custom-save-all))
2524 (face-spec-set symbol value)
2525 (widget-value-set child value)
2526 (custom-face-state-set widget)
2527 (custom-redraw-magic widget)))
2529 ;;; The `face' Widget.
2531 (define-widget 'face 'default
2532 "Select and customize a face."
2533 :convert-widget 'widget-value-convert-widget
2534 :button-prefix 'widget-push-button-prefix
2535 :button-suffix 'widget-push-button-suffix
2536 :format "%t: %[select face%] %v"
2537 :tag "Face"
2538 :value 'default
2539 :value-create 'widget-face-value-create
2540 :value-delete 'widget-face-value-delete
2541 :value-get 'widget-value-value-get
2542 :validate 'widget-children-validate
2543 :action 'widget-face-action
2544 :match '(lambda (widget value) (symbolp value)))
2546 (defun widget-face-value-create (widget)
2547 ;; Create a `custom-face' child.
2548 (let* ((symbol (widget-value widget))
2549 (custom-buffer-style 'face)
2550 (child (widget-create-child-and-convert
2551 widget 'custom-face
2552 :custom-level nil
2553 :value symbol)))
2554 (custom-magic-reset child)
2555 (setq custom-options (cons child custom-options))
2556 (widget-put widget :children (list child))))
2558 (defun widget-face-value-delete (widget)
2559 ;; Remove the child from the options.
2560 (let ((child (car (widget-get widget :children))))
2561 (setq custom-options (delq child custom-options))
2562 (widget-children-value-delete widget)))
2564 (defvar face-history nil
2565 "History of entered face names.")
2567 (defun widget-face-action (widget &optional event)
2568 "Prompt for a face."
2569 (let ((answer (completing-read "Face: "
2570 (mapcar (lambda (face)
2571 (list (symbol-name face)))
2572 (face-list))
2573 nil nil nil
2574 'face-history)))
2575 (unless (zerop (length answer))
2576 (widget-value-set widget (intern answer))
2577 (widget-apply widget :notify widget event)
2578 (widget-setup))))
2580 ;;; The `hook' Widget.
2582 (define-widget 'hook 'list
2583 "A emacs lisp hook"
2584 :value-to-internal (lambda (widget value)
2585 (if (and value (symbolp value))
2586 (list value)
2587 value))
2588 :match (lambda (widget value)
2589 (or (symbolp value)
2590 (widget-group-match widget value)))
2591 :convert-widget 'custom-hook-convert-widget
2592 :tag "Hook")
2594 (defun custom-hook-convert-widget (widget)
2595 ;; Handle `:custom-options'.
2596 (let* ((options (widget-get widget :options))
2597 (other `(editable-list :inline t
2598 :entry-format "%i %d%v"
2599 (function :format " %v")))
2600 (args (if options
2601 (list `(checklist :inline t
2602 ,@(mapcar (lambda (entry)
2603 `(function-item ,entry))
2604 options))
2605 other)
2606 (list other))))
2607 (widget-put widget :args args)
2608 widget))
2610 ;;; The `custom-group-link' Widget.
2612 (define-widget 'custom-group-link 'link
2613 "Show parent in other window when activated."
2614 :help-echo "Create customization buffer for this group."
2615 :action 'custom-group-link-action)
2617 (defun custom-group-link-action (widget &rest ignore)
2618 (customize-group (widget-value widget)))
2620 ;;; The `custom-group' Widget.
2622 (defcustom custom-group-tag-faces nil
2623 ;; In XEmacs, this ought to play games with font size.
2624 "Face used for group tags.
2625 The first member is used for level 1 groups, the second for level 2,
2626 and so forth. The remaining group tags are shown with
2627 `custom-group-tag-face'."
2628 :type '(repeat face)
2629 :group 'custom-faces)
2631 (defface custom-group-tag-face-1 '((((class color)
2632 (background dark))
2633 (:foreground "pink" :underline t))
2634 (((class color)
2635 (background light))
2636 (:foreground "red" :underline t))
2637 (t (:underline t)))
2638 "Face used for group tags.")
2640 (defface custom-group-tag-face '((((class color)
2641 (background dark))
2642 (:foreground "light blue" :underline t))
2643 (((class color)
2644 (background light))
2645 (:foreground "blue" :underline t))
2646 (t (:underline t)))
2647 "Face used for low level group tags."
2648 :group 'custom-faces)
2650 (define-widget 'custom-group 'custom
2651 "Customize group."
2652 :format "%v"
2653 :sample-face-get 'custom-group-sample-face-get
2654 :documentation-property 'group-documentation
2655 :help-echo "Set or reset all members of this group."
2656 :value-create 'custom-group-value-create
2657 :action 'custom-group-action
2658 :custom-category 'group
2659 :custom-set 'custom-group-set
2660 :custom-save 'custom-group-save
2661 :custom-reset-current 'custom-group-reset-current
2662 :custom-reset-saved 'custom-group-reset-saved
2663 :custom-reset-standard 'custom-group-reset-standard
2664 :custom-menu 'custom-group-menu-create)
2666 (defun custom-group-sample-face-get (widget)
2667 ;; Use :sample-face.
2668 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
2669 'custom-group-tag-face))
2671 (define-widget 'custom-group-visibility 'visibility
2672 "An indicator and manipulator for hidden group contents."
2673 :create 'custom-group-visibility-create)
2675 (defun custom-group-visibility-create (widget)
2676 (let ((visible (widget-value widget)))
2677 (if visible
2678 (insert "--------")))
2679 (widget-default-create widget))
2681 (defun custom-group-members (symbol groups-only)
2682 "Return SYMBOL's custom group members.
2683 If GROUPS-ONLY non-nil, return only those members that are groups."
2684 (if (not groups-only)
2685 (get symbol 'custom-group)
2686 (let (members)
2687 (dolist (entry (get symbol 'custom-group))
2688 (when (eq (nth 1 entry) 'custom-group)
2689 (push entry members)))
2690 (nreverse members))))
2692 (defun custom-group-value-create (widget)
2693 "Insert a customize group for WIDGET in the current buffer."
2694 (let* ((state (widget-get widget :custom-state))
2695 (level (widget-get widget :custom-level))
2696 ;; (indent (widget-get widget :indent))
2697 (prefix (widget-get widget :custom-prefix))
2698 (buttons (widget-get widget :buttons))
2699 (tag (widget-get widget :tag))
2700 (symbol (widget-value widget))
2701 (members (custom-group-members symbol
2702 (and (eq custom-buffer-style 'tree)
2703 custom-browse-only-groups))))
2704 (cond ((and (eq custom-buffer-style 'tree)
2705 (eq state 'hidden)
2706 (or members (custom-unloaded-widget-p widget)))
2707 (custom-browse-insert-prefix prefix)
2708 (push (widget-create-child-and-convert
2709 widget 'custom-browse-visibility
2710 ;; :tag-glyph "plus"
2711 :tag "+")
2712 buttons)
2713 (insert "-- ")
2714 ;; (widget-glyph-insert nil "-- " "horizontal")
2715 (push (widget-create-child-and-convert
2716 widget 'custom-browse-group-tag)
2717 buttons)
2718 (insert " " tag "\n")
2719 (widget-put widget :buttons buttons))
2720 ((and (eq custom-buffer-style 'tree)
2721 (zerop (length members)))
2722 (custom-browse-insert-prefix prefix)
2723 (insert "[ ]-- ")
2724 ;; (widget-glyph-insert nil "[ ]" "empty")
2725 ;; (widget-glyph-insert nil "-- " "horizontal")
2726 (push (widget-create-child-and-convert
2727 widget 'custom-browse-group-tag)
2728 buttons)
2729 (insert " " tag "\n")
2730 (widget-put widget :buttons buttons))
2731 ((eq custom-buffer-style 'tree)
2732 (custom-browse-insert-prefix prefix)
2733 (custom-load-widget widget)
2734 (if (zerop (length members))
2735 (progn
2736 (custom-browse-insert-prefix prefix)
2737 (insert "[ ]-- ")
2738 ;; (widget-glyph-insert nil "[ ]" "empty")
2739 ;; (widget-glyph-insert nil "-- " "horizontal")
2740 (push (widget-create-child-and-convert
2741 widget 'custom-browse-group-tag)
2742 buttons)
2743 (insert " " tag "\n")
2744 (widget-put widget :buttons buttons))
2745 (push (widget-create-child-and-convert
2746 widget 'custom-browse-visibility
2747 ;; :tag-glyph "minus"
2748 :tag "-")
2749 buttons)
2750 (insert "-\\ ")
2751 ;; (widget-glyph-insert nil "-\\ " "top")
2752 (push (widget-create-child-and-convert
2753 widget 'custom-browse-group-tag)
2754 buttons)
2755 (insert " " tag "\n")
2756 (widget-put widget :buttons buttons)
2757 (message "Creating group...")
2758 (let* ((members (custom-sort-items members
2759 custom-browse-sort-alphabetically
2760 custom-browse-order-groups))
2761 (prefixes (widget-get widget :custom-prefixes))
2762 (custom-prefix-list (custom-prefix-add symbol prefixes))
2763 (extra-prefix (if (widget-get widget :custom-last)
2765 " | "))
2766 (prefix (concat prefix extra-prefix))
2767 children entry)
2768 (while members
2769 (setq entry (car members)
2770 members (cdr members))
2771 (push (widget-create-child-and-convert
2772 widget (nth 1 entry)
2773 :group widget
2774 :tag (custom-unlispify-tag-name (nth 0 entry))
2775 :custom-prefixes custom-prefix-list
2776 :custom-level (1+ level)
2777 :custom-last (null members)
2778 :value (nth 0 entry)
2779 :custom-prefix prefix)
2780 children))
2781 (widget-put widget :children (reverse children)))
2782 (message "Creating group...done")))
2783 ;; Nested style.
2784 ((eq state 'hidden)
2785 ;; Create level indicator.
2786 (unless (eq custom-buffer-style 'links)
2787 (insert-char ?\ (* custom-buffer-indent (1- level)))
2788 (insert "-- "))
2789 ;; Create tag.
2790 (let ((begin (point)))
2791 (insert tag)
2792 (widget-specify-sample widget begin (point)))
2793 (insert " group: ")
2794 ;; Create link/visibility indicator.
2795 (if (eq custom-buffer-style 'links)
2796 (push (widget-create-child-and-convert
2797 widget 'custom-group-link
2798 :tag "Go to Group"
2799 symbol)
2800 buttons)
2801 (push (widget-create-child-and-convert
2802 widget 'custom-group-visibility
2803 :help-echo "Show members of this group."
2804 :action 'custom-toggle-parent
2805 (not (eq state 'hidden)))
2806 buttons))
2807 (insert " \n")
2808 ;; Create magic button.
2809 (let ((magic (widget-create-child-and-convert
2810 widget 'custom-magic nil)))
2811 (widget-put widget :custom-magic magic)
2812 (push magic buttons))
2813 ;; Update buttons.
2814 (widget-put widget :buttons buttons)
2815 ;; Insert documentation.
2816 (if (and (eq custom-buffer-style 'links) (> level 1))
2817 (widget-put widget :documentation-indent 0))
2818 (widget-default-format-handler widget ?h))
2819 ;; Nested style.
2820 (t ;Visible.
2821 ;; Add parent groups references above the group.
2822 (if t ;;; This should test that the buffer
2823 ;;; was made to display a group.
2824 (when (eq level 1)
2825 (if (custom-add-parent-links widget
2826 "Go to parent group:")
2827 (insert "\n"))))
2828 ;; Create level indicator.
2829 (insert-char ?\ (* custom-buffer-indent (1- level)))
2830 (insert "/- ")
2831 ;; Create tag.
2832 (let ((start (point)))
2833 (insert tag)
2834 (widget-specify-sample widget start (point)))
2835 (insert " group: ")
2836 ;; Create visibility indicator.
2837 (unless (eq custom-buffer-style 'links)
2838 (insert "--------")
2839 (push (widget-create-child-and-convert
2840 widget 'visibility
2841 :help-echo "Hide members of this group."
2842 :action 'custom-toggle-parent
2843 (not (eq state 'hidden)))
2844 buttons)
2845 (insert " "))
2846 ;; Create more dashes.
2847 ;; Use 76 instead of 75 to compensate for the temporary "<"
2848 ;; added by `widget-insert'.
2849 (insert-char ?- (- 76 (current-column)
2850 (* custom-buffer-indent level)))
2851 (insert "\\\n")
2852 ;; Create magic button.
2853 (let ((magic (widget-create-child-and-convert
2854 widget 'custom-magic
2855 :indent 0
2856 nil)))
2857 (widget-put widget :custom-magic magic)
2858 (push magic buttons))
2859 ;; Update buttons.
2860 (widget-put widget :buttons buttons)
2861 ;; Insert documentation.
2862 (widget-default-format-handler widget ?h)
2863 ;; Parent groups.
2864 (if nil ;;; This should test that the buffer
2865 ;;; was not made to display a group.
2866 (when (eq level 1)
2867 (insert-char ?\ custom-buffer-indent)
2868 (custom-add-parent-links widget)))
2869 (custom-add-see-also widget
2870 (make-string (* custom-buffer-indent level)
2871 ?\ ))
2872 ;; Members.
2873 (message "Creating group...")
2874 (custom-load-widget widget)
2875 (let* ((members (custom-sort-items members
2876 custom-buffer-sort-alphabetically
2877 custom-buffer-order-groups))
2878 (prefixes (widget-get widget :custom-prefixes))
2879 (custom-prefix-list (custom-prefix-add symbol prefixes))
2880 (length (length members))
2881 (count 0)
2882 (children (mapcar (lambda (entry)
2883 (widget-insert "\n")
2884 (message "\
2885 Creating group members... %2d%%"
2886 (/ (* 100.0 count) length))
2887 (setq count (1+ count))
2888 (prog1
2889 (widget-create-child-and-convert
2890 widget (nth 1 entry)
2891 :group widget
2892 :tag (custom-unlispify-tag-name
2893 (nth 0 entry))
2894 :custom-prefixes custom-prefix-list
2895 :custom-level (1+ level)
2896 :value (nth 0 entry))
2897 (unless (eq (preceding-char) ?\n)
2898 (widget-insert "\n"))))
2899 members)))
2900 (message "Creating group magic...")
2901 (mapcar 'custom-magic-reset children)
2902 (message "Creating group state...")
2903 (widget-put widget :children children)
2904 (custom-group-state-update widget)
2905 (message "Creating group... done"))
2906 ;; End line
2907 (insert "\n")
2908 (insert-char ?\ (* custom-buffer-indent (1- level)))
2909 (insert "\\- " (widget-get widget :tag) " group end ")
2910 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
2911 (insert "/\n")))))
2913 (defvar custom-group-menu
2914 '(("Set for Current Session" custom-group-set
2915 (lambda (widget)
2916 (eq (widget-get widget :custom-state) 'modified)))
2917 ("Save for Future Sessions" custom-group-save
2918 (lambda (widget)
2919 (memq (widget-get widget :custom-state) '(modified set))))
2920 ("Reset to Current" custom-group-reset-current
2921 (lambda (widget)
2922 (memq (widget-get widget :custom-state) '(modified))))
2923 ("Reset to Saved" custom-group-reset-saved
2924 (lambda (widget)
2925 (memq (widget-get widget :custom-state) '(modified set))))
2926 ("Reset to standard setting" custom-group-reset-standard
2927 (lambda (widget)
2928 (memq (widget-get widget :custom-state) '(modified set saved)))))
2929 "Alist of actions for the `custom-group' widget.
2930 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2931 the menu entry, ACTION is the function to call on the widget when the
2932 menu is selected, and FILTER is a predicate which takes a `custom-group'
2933 widget as an argument, and returns non-nil if ACTION is valid on that
2934 widget. If FILTER is nil, ACTION is always valid.")
2936 (defun custom-group-action (widget &optional event)
2937 "Show the menu for `custom-group' WIDGET.
2938 Optional EVENT is the location for the menu."
2939 (if (eq (widget-get widget :custom-state) 'hidden)
2940 (custom-toggle-hide widget)
2941 (let* ((completion-ignore-case t)
2942 (answer (widget-choose (concat "Operation on "
2943 (custom-unlispify-tag-name
2944 (widget-get widget :value)))
2945 (custom-menu-filter custom-group-menu
2946 widget)
2947 event)))
2948 (if answer
2949 (funcall answer widget)))))
2951 (defun custom-group-set (widget)
2952 "Set changes in all modified group members."
2953 (let ((children (widget-get widget :children)))
2954 (mapcar (lambda (child)
2955 (when (eq (widget-get child :custom-state) 'modified)
2956 (widget-apply child :custom-set)))
2957 children )))
2959 (defun custom-group-save (widget)
2960 "Save all modified group members."
2961 (let ((children (widget-get widget :children)))
2962 (mapcar (lambda (child)
2963 (when (memq (widget-get child :custom-state) '(modified set))
2964 (widget-apply child :custom-save)))
2965 children )))
2967 (defun custom-group-reset-current (widget)
2968 "Reset all modified group members."
2969 (let ((children (widget-get widget :children)))
2970 (mapcar (lambda (child)
2971 (when (eq (widget-get child :custom-state) 'modified)
2972 (widget-apply child :custom-reset-current)))
2973 children )))
2975 (defun custom-group-reset-saved (widget)
2976 "Reset all modified or set group members."
2977 (let ((children (widget-get widget :children)))
2978 (mapcar (lambda (child)
2979 (when (memq (widget-get child :custom-state) '(modified set))
2980 (widget-apply child :custom-reset-saved)))
2981 children )))
2983 (defun custom-group-reset-standard (widget)
2984 "Reset all modified, set, or saved group members."
2985 (let ((children (widget-get widget :children)))
2986 (mapcar (lambda (child)
2987 (when (memq (widget-get child :custom-state)
2988 '(modified set saved))
2989 (widget-apply child :custom-reset-standard)))
2990 children )))
2992 (defun custom-group-state-update (widget)
2993 "Update magic."
2994 (unless (eq (widget-get widget :custom-state) 'hidden)
2995 (let* ((children (widget-get widget :children))
2996 (states (mapcar (lambda (child)
2997 (widget-get child :custom-state))
2998 children))
2999 (magics custom-magic-alist)
3000 (found 'standard))
3001 (while magics
3002 (let ((magic (car (car magics))))
3003 (if (and (not (eq magic 'hidden))
3004 (memq magic states))
3005 (setq found magic
3006 magics nil)
3007 (setq magics (cdr magics)))))
3008 (widget-put widget :custom-state found)))
3009 (custom-magic-reset widget))
3011 ;;; The `custom-save-all' Function.
3012 ;;;###autoload
3013 (defcustom custom-file nil
3014 "File used for storing customization information.
3015 The default is nil, which means to use your init file
3016 as specified by `user-init-file'. If you specify some other file,
3017 you need to explicitly load that file for the settings to take effect."
3018 :type '(choice (const :tag "Your Emacs init file" nil) file)
3019 :group 'customize)
3021 (defun custom-file ()
3022 "Return the file name for saving customizations."
3023 (setq custom-file
3024 (or custom-file
3025 user-init-file
3026 (read-file-name "File for customizations: "
3027 "~/" nil nil ".emacs"))))
3029 (defun custom-save-delete (symbol)
3030 "Delete the call to SYMBOL from `custom-file'.
3031 Leave point at the location of the call, or after the last expression."
3032 (let ((default-major-mode))
3033 (set-buffer (find-file-noselect (custom-file))))
3034 (goto-char (point-min))
3035 (catch 'found
3036 (while t
3037 (let ((sexp (condition-case nil
3038 (read (current-buffer))
3039 (end-of-file (throw 'found nil)))))
3040 (when (and (listp sexp)
3041 (eq (car sexp) symbol))
3042 (delete-region (save-excursion
3043 (backward-sexp)
3044 (point))
3045 (point))
3046 (throw 'found nil))))))
3048 (defun custom-save-variables ()
3049 "Save all customized variables in `custom-file'."
3050 (save-excursion
3051 (custom-save-delete 'custom-set-variables)
3052 (let ((standard-output (current-buffer)))
3053 (unless (bolp)
3054 (princ "\n"))
3055 (princ "(custom-set-variables")
3056 (mapatoms (lambda (symbol)
3057 (let ((value (get symbol 'saved-value))
3058 (requests (get symbol 'custom-requests))
3059 (now (not (or (get symbol 'standard-value)
3060 (and (not (boundp symbol))
3061 (not (get symbol 'force-value)))))))
3062 (when value
3063 (princ "\n '(")
3064 (princ symbol)
3065 (princ " ")
3066 (prin1 (car value))
3067 (cond (requests
3068 (if now
3069 (princ " t ")
3070 (princ " nil "))
3071 (prin1 requests)
3072 (princ ")"))
3073 (now
3074 (princ " t)"))
3076 (princ ")")))))))
3077 (princ ")")
3078 (unless (looking-at "\n")
3079 (princ "\n")))))
3081 (defun custom-save-faces ()
3082 "Save all customized faces in `custom-file'."
3083 (save-excursion
3084 (custom-save-delete 'custom-set-faces)
3085 (let ((standard-output (current-buffer)))
3086 (unless (bolp)
3087 (princ "\n"))
3088 (princ "(custom-set-faces")
3089 (let ((value (get 'default 'saved-face)))
3090 ;; The default face must be first, since it affects the others.
3091 (when value
3092 (princ "\n '(default ")
3093 (prin1 value)
3094 (if (or (get 'default 'face-defface-spec)
3095 (and (not (custom-facep 'default))
3096 (not (get 'default 'force-face))))
3097 (princ ")")
3098 (princ " t)"))))
3099 (mapatoms (lambda (symbol)
3100 (let ((value (get symbol 'saved-face)))
3101 (when (and (not (eq symbol 'default))
3102 ;; Don't print default face here.
3103 value)
3104 (princ "\n '(")
3105 (princ symbol)
3106 (princ " ")
3107 (prin1 value)
3108 (if (or (get symbol 'face-defface-spec)
3109 (and (not (custom-facep symbol))
3110 (not (get symbol 'force-face))))
3111 (princ ")")
3112 (princ " t)"))))))
3113 (princ ")")
3114 (unless (looking-at "\n")
3115 (princ "\n")))))
3117 ;;;###autoload
3118 (defun customize-save-customized ()
3119 "Save all user options which have been set in this session."
3120 (interactive)
3121 (mapatoms (lambda (symbol)
3122 (let ((face (get symbol 'customized-face))
3123 (value (get symbol 'customized-value)))
3124 (when face
3125 (put symbol 'saved-face face)
3126 (put symbol 'customized-face nil))
3127 (when value
3128 (put symbol 'saved-value value)
3129 (put symbol 'customized-value nil)))))
3130 ;; We really should update all custom buffers here.
3131 (custom-save-all))
3133 ;;;###autoload
3134 (defun custom-save-all ()
3135 "Save all customizations in `custom-file'."
3136 (let ((inhibit-read-only t))
3137 (custom-save-variables)
3138 (custom-save-faces)
3139 (save-excursion
3140 (let ((default-major-mode nil))
3141 (set-buffer (find-file-noselect (custom-file))))
3142 (save-buffer))))
3144 ;;; The Customize Menu.
3146 ;;; Menu support
3148 (defcustom custom-menu-nesting 2
3149 "Maximum nesting in custom menus."
3150 :type 'integer
3151 :group 'custom-menu)
3153 (defun custom-face-menu-create (widget symbol)
3154 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3155 (vector (custom-unlispify-menu-entry symbol)
3156 `(customize-face ',symbol)
3159 (defun custom-variable-menu-create (widget symbol)
3160 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3161 (let ((type (get symbol 'custom-type)))
3162 (unless (listp type)
3163 (setq type (list type)))
3164 (if (and type (widget-get type :custom-menu))
3165 (widget-apply type :custom-menu symbol)
3166 (vector (custom-unlispify-menu-entry symbol)
3167 `(customize-variable ',symbol)
3168 t))))
3170 ;; Add checkboxes to boolean variable entries.
3171 (widget-put (get 'boolean 'widget-type)
3172 :custom-menu (lambda (widget symbol)
3173 (vector (custom-unlispify-menu-entry symbol)
3174 `(customize-variable ',symbol)
3175 ':style 'toggle
3176 ':selected symbol)))
3178 (if (string-match "XEmacs" emacs-version)
3179 ;; XEmacs can create menus dynamically.
3180 (defun custom-group-menu-create (widget symbol)
3181 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3182 `( ,(custom-unlispify-menu-entry symbol t)
3183 :filter (lambda (&rest junk)
3184 (cdr (custom-menu-create ',symbol)))))
3185 ;; But emacs can't.
3186 (defun custom-group-menu-create (widget symbol)
3187 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3188 ;; Limit the nesting.
3189 (let ((custom-menu-nesting (1- custom-menu-nesting)))
3190 (custom-menu-create symbol))))
3192 ;;;###autoload
3193 (defun custom-menu-create (symbol)
3194 "Create menu for customization group SYMBOL.
3195 The menu is in a format applicable to `easy-menu-define'."
3196 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3197 `(customize-group ',symbol)
3198 t)))
3199 (if (and (or (not (boundp 'custom-menu-nesting))
3200 (>= custom-menu-nesting 0))
3201 (< (length (get symbol 'custom-group)) widget-menu-max-size))
3202 (let ((custom-prefix-list (custom-prefix-add symbol
3203 custom-prefix-list))
3204 (members (custom-sort-items (get symbol 'custom-group)
3205 custom-menu-sort-alphabetically
3206 custom-menu-order-groups)))
3207 (custom-load-symbol symbol)
3208 `(,(custom-unlispify-menu-entry symbol t)
3209 ,item
3210 "--"
3211 ,@(mapcar (lambda (entry)
3212 (widget-apply (if (listp (nth 1 entry))
3213 (nth 1 entry)
3214 (list (nth 1 entry)))
3215 :custom-menu (nth 0 entry)))
3216 members)))
3217 item)))
3219 ;;;###autoload
3220 (defun customize-menu-create (symbol &optional name)
3221 "Return a customize menu for customization group SYMBOL.
3222 If optional NAME is given, use that as the name of the menu.
3223 Otherwise the menu will be named `Customize'.
3224 The format is suitable for use with `easy-menu-define'."
3225 (unless name
3226 (setq name "Customize"))
3227 (if (string-match "XEmacs" emacs-version)
3228 ;; We can delay it under XEmacs.
3229 `(,name
3230 :filter (lambda (&rest junk)
3231 (cdr (custom-menu-create ',symbol))))
3232 ;; But we must create it now under Emacs.
3233 (cons name (cdr (custom-menu-create symbol)))))
3235 ;;; The Custom Mode.
3237 (defvar custom-mode-map nil
3238 "Keymap for `custom-mode'.")
3240 (unless custom-mode-map
3241 (setq custom-mode-map (make-sparse-keymap))
3242 (set-keymap-parent custom-mode-map widget-keymap)
3243 (suppress-keymap custom-mode-map)
3244 (define-key custom-mode-map " " 'scroll-up)
3245 (define-key custom-mode-map "\177" 'scroll-down)
3246 (define-key custom-mode-map "q" 'bury-buffer)
3247 (define-key custom-mode-map "u" 'Custom-goto-parent)
3248 (define-key custom-mode-map "n" 'widget-forward)
3249 (define-key custom-mode-map "p" 'widget-backward)
3250 (define-key custom-mode-map [mouse-1] 'Custom-move-and-invoke))
3252 (defun Custom-move-and-invoke (event)
3253 "Move to where you click, and if it is an active field, invoke it."
3254 (interactive "e")
3255 (mouse-set-point event)
3256 (if (widget-event-point event)
3257 (let* ((pos (widget-event-point event))
3258 (button (get-char-property pos 'button)))
3259 (if button
3260 (widget-button-click event)))))
3262 (easy-menu-define Custom-mode-menu
3263 custom-mode-map
3264 "Menu used in customization buffers."
3265 `("Custom"
3266 ,(customize-menu-create 'customize)
3267 ["Set" Custom-set t]
3268 ["Save" Custom-save t]
3269 ["Reset to Current" Custom-reset-current t]
3270 ["Reset to Saved" Custom-reset-saved t]
3271 ["Reset to Standard Settings" Custom-reset-standard t]
3272 ["Info" (Info-goto-node "(custom)The Customization Buffer") t]))
3274 (defun Custom-goto-parent ()
3275 "Go to the parent group listed at the top of this buffer.
3276 If several parents are listed, go to the first of them."
3277 (interactive)
3278 (save-excursion
3279 (goto-char (point-min))
3280 (if (search-forward "\nGo to parent group: " nil t)
3281 (let* ((button (get-char-property (point) 'button))
3282 (parent (downcase (widget-get button :tag))))
3283 (customize-group parent)))))
3285 (defcustom custom-mode-hook nil
3286 "Hook called when entering custom-mode."
3287 :type 'hook
3288 :group 'custom-buffer )
3290 (defun custom-state-buffer-message (widget)
3291 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
3292 (message "To install your edits, invoke [State] and choose the Set operation")))
3294 (defun custom-mode ()
3295 "Major mode for editing customization buffers.
3297 The following commands are available:
3299 Move to next button or editable field. \\[widget-forward]
3300 Move to previous button or editable field. \\[widget-backward]
3301 \\<widget-field-keymap>\
3302 Complete content of editable text field. \\[widget-complete]
3303 \\<custom-mode-map>\
3304 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3305 Invoke button under point. \\[widget-button-press]
3306 Set all modifications. \\[Custom-set]
3307 Make all modifications default. \\[Custom-save]
3308 Reset all modified options. \\[Custom-reset-current]
3309 Reset all modified or set options. \\[Custom-reset-saved]
3310 Reset all options. \\[Custom-reset-standard]
3312 Entry to this mode calls the value of `custom-mode-hook'
3313 if that value is non-nil."
3314 (kill-all-local-variables)
3315 (setq major-mode 'custom-mode
3316 mode-name "Custom")
3317 (use-local-map custom-mode-map)
3318 (easy-menu-add Custom-mode-menu)
3319 (make-local-variable 'custom-options)
3320 (make-local-variable 'widget-documentation-face)
3321 (setq widget-documentation-face 'custom-documentation-face)
3322 (make-local-variable 'widget-button-face)
3323 (setq widget-button-face 'custom-button-face)
3324 (make-local-hook 'widget-edit-functions)
3325 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
3326 (run-hooks 'custom-mode-hook))
3328 ;;; The End.
3330 (provide 'cus-edit)
3332 ;; cus-edit.el ends here