Mercurial > hg > xemacs-beta
comparison lisp/custom/cus-edit.el @ 149:538048ae2ab8 r20-3b1
Import from CVS: tag r20-3b1
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:36:16 +0200 |
parents | b980b6286996 |
children | 59463afc5666 |
comparison
equal
deleted
inserted
replaced
148:f659db2a1f73 | 149:538048ae2ab8 |
---|---|
2 ;; | 2 ;; |
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc. |
4 ;; | 4 ;; |
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> | 5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> |
6 ;; Keywords: help, faces | 6 ;; Keywords: help, faces |
7 ;; Version: 1.84 | 7 ;; Version: 1.97 |
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ | 8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
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. | |
16 | |
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. | |
21 | |
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. | |
9 | 26 |
10 ;;; Commentary: | 27 ;;; Commentary: |
11 ;; | 28 ;; |
29 ;; This file implements the code to create and edit customize buffers. | |
30 ;; | |
12 ;; See `custom.el'. | 31 ;; See `custom.el'. |
13 | 32 |
14 ;;; Code: | 33 ;;; Code: |
15 | 34 |
16 (require 'cus-face) | 35 (require 'cus-face) |
17 (require 'wid-edit) | 36 (require 'wid-edit) |
18 (require 'easymenu) | 37 (require 'easymenu) |
38 (eval-when-compile (require 'cl)) | |
39 | |
40 (condition-case nil | |
41 (require 'cus-load) | |
42 (error nil)) | |
19 | 43 |
20 (define-widget-keywords :custom-prefixes :custom-menu :custom-show | 44 (define-widget-keywords :custom-prefixes :custom-menu :custom-show |
21 :custom-magic :custom-state :custom-level :custom-form | 45 :custom-magic :custom-state :custom-level :custom-form |
22 :custom-set :custom-save :custom-reset-current :custom-reset-saved | 46 :custom-set :custom-save :custom-reset-current :custom-reset-saved |
23 :custom-reset-factory) | 47 :custom-reset-factory) |
165 | 189 |
166 (defgroup i18n nil | 190 (defgroup i18n nil |
167 "Internationalization and alternate character-set support." | 191 "Internationalization and alternate character-set support." |
168 :group 'environment | 192 :group 'environment |
169 :group 'editing) | 193 :group 'editing) |
194 | |
195 (defgroup x nil | |
196 "The X Window system." | |
197 :group 'environment) | |
170 | 198 |
171 (defgroup frames nil | 199 (defgroup frames nil |
172 "Support for Emacs frames and window systems." | 200 "Support for Emacs frames and window systems." |
173 :group 'environment) | 201 :group 'environment) |
174 | 202 |
328 (let ((v (variable-at-point)) | 356 (let ((v (variable-at-point)) |
329 (enable-recursive-minibuffers t) | 357 (enable-recursive-minibuffers t) |
330 val) | 358 val) |
331 (setq val (completing-read | 359 (setq val (completing-read |
332 (if v | 360 (if v |
333 (format "Customize variable (default %s): " v) | 361 (format "Customize variable: (default %s) " v) |
334 "Customize variable: ") | 362 "Customize variable: ") |
335 obarray 'boundp t)) | 363 obarray (lambda (symbol) |
364 (and (boundp symbol) | |
365 (or (get symbol 'custom-type) | |
366 (user-variable-p symbol)))))) | |
336 (list (if (equal val "") | 367 (list (if (equal val "") |
337 v (intern val))))) | 368 v (intern val))))) |
369 | |
370 (defun custom-menu-filter (menu widget) | |
371 "Convert MENU to the form used by `widget-choose'. | |
372 MENU should be in the same format as `custom-variable-menu'. | |
373 WIDGET is the widget to apply the filter entries of MENU on." | |
374 (let ((result nil) | |
375 current name action filter) | |
376 (while menu | |
377 (setq current (car menu) | |
378 name (nth 0 current) | |
379 action (nth 1 current) | |
380 filter (nth 2 current) | |
381 menu (cdr menu)) | |
382 (if (or (null filter) (funcall filter widget)) | |
383 (push (cons name action) result) | |
384 (push name result))) | |
385 (nreverse result))) | |
338 | 386 |
339 ;;; Unlispify. | 387 ;;; Unlispify. |
340 | 388 |
341 (defvar custom-prefix-list nil | 389 (defvar custom-prefix-list nil |
342 "List of prefixes that should be ignored by `custom-unlispify'") | 390 "List of prefixes that should be ignored by `custom-unlispify'") |
527 (widget-apply child :custom-reset-current))) | 575 (widget-apply child :custom-reset-current))) |
528 children))) | 576 children))) |
529 | 577 |
530 ;;; The Customize Commands | 578 ;;; The Customize Commands |
531 | 579 |
580 (defun custom-prompt-variable (prompt-var prompt-val) | |
581 "Prompt for a variable and a value and return them as a list. | |
582 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the | |
583 prompt for the value. The %s escape in PROMPT-VAL is replaced with | |
584 the name of the variable. | |
585 | |
586 If the variable has a `variable-interactive' property, that is used as if | |
587 it were the arg to `interactive' (which see) to interactively read the value. | |
588 | |
589 If the variable has a `custom-type' property, it must be a widget and the | |
590 `:prompt-value' property of that widget will be used for reading the value." | |
591 (let* ((var (read-variable prompt-var)) | |
592 (minibuffer-help-form '(describe-variable var))) | |
593 (list var | |
594 (let ((prop (get var 'variable-interactive)) | |
595 (type (get var 'custom-type)) | |
596 (prompt (format prompt-val var))) | |
597 (unless (listp type) | |
598 (setq type (list type))) | |
599 (cond (prop | |
600 ;; Use VAR's `variable-interactive' property | |
601 ;; as an interactive spec for prompting. | |
602 (call-interactively (list 'lambda '(arg) | |
603 (list 'interactive prop) | |
604 'arg))) | |
605 (type | |
606 (widget-prompt-value type | |
607 prompt | |
608 (if (boundp var) | |
609 (symbol-value var)) | |
610 (not (boundp var)))) | |
611 (t | |
612 (eval-minibuffer prompt))))))) | |
613 | |
614 ;;;###autoload | |
615 (defun custom-set-value (var val) | |
616 "Set VARIABLE to VALUE. VALUE is a Lisp object. | |
617 | |
618 If VARIABLE has a `variable-interactive' property, that is used as if | |
619 it were the arg to `interactive' (which see) to interactively read the value. | |
620 | |
621 If VARIABLE has a `custom-type' property, it must be a widget and the | |
622 `:prompt-value' property of that widget will be used for reading the value." | |
623 (interactive (custom-prompt-variable "Set variable: " | |
624 "Set %s to value: ")) | |
625 | |
626 (set var val)) | |
627 | |
628 ;;;###autoload | |
629 (defun custom-set-variable (var val) | |
630 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object. | |
631 | |
632 If VARIABLE has a `custom-set' property, that is used for setting | |
633 VARIABLE, otherwise `set-default' is used. | |
634 | |
635 The `customized-value' property of the VARIABLE will be set to a list | |
636 with a quoted VALUE as its sole list member. | |
637 | |
638 If VARIABLE has a `variable-interactive' property, that is used as if | |
639 it were the arg to `interactive' (which see) to interactively read the value. | |
640 | |
641 If VARIABLE has a `custom-type' property, it must be a widget and the | |
642 `:prompt-value' property of that widget will be used for reading the value. " | |
643 (interactive (custom-prompt-variable "Set variable: " | |
644 "Set customized value for %s to: ")) | |
645 (funcall (or (get var 'custom-set) 'set-default) var val) | |
646 (put var 'customized-value (list (custom-quote val)))) | |
647 | |
532 ;;;###autoload | 648 ;;;###autoload |
533 (defun customize (symbol) | 649 (defun customize (symbol) |
534 "Customize SYMBOL, which must be a customization group." | 650 "Customize SYMBOL, which must be a customization group." |
535 (interactive (list (completing-read "Customize group: (default emacs) " | 651 (interactive (list (completing-read "Customize group: (default emacs) " |
536 obarray | 652 obarray |
540 | 656 |
541 (when (stringp symbol) | 657 (when (stringp symbol) |
542 (if (string-equal "" symbol) | 658 (if (string-equal "" symbol) |
543 (setq symbol 'emacs) | 659 (setq symbol 'emacs) |
544 (setq symbol (intern symbol)))) | 660 (setq symbol (intern symbol)))) |
545 (custom-buffer-create (list (list symbol 'custom-group)))) | 661 (custom-buffer-create (list (list symbol 'custom-group)) |
662 (format "*Customize Group: %s*" | |
663 (custom-unlispify-tag-name symbol)))) | |
664 | |
665 ;;;###autoload | |
666 (defun customize-other-window (symbol) | |
667 "Customize SYMBOL, which must be a customization group." | |
668 (interactive (list (completing-read "Customize group: (default emacs) " | |
669 obarray | |
670 (lambda (symbol) | |
671 (get symbol 'custom-group)) | |
672 t))) | |
673 | |
674 (when (stringp symbol) | |
675 (if (string-equal "" symbol) | |
676 (setq symbol 'emacs) | |
677 (setq symbol (intern symbol)))) | |
678 (custom-buffer-create-other-window | |
679 (list (list symbol 'custom-group)) | |
680 (format "*Customize Group: %s*" (custom-unlispify-tag-name symbol)))) | |
546 | 681 |
547 ;;;###autoload | 682 ;;;###autoload |
548 (defun customize-variable (symbol) | 683 (defun customize-variable (symbol) |
549 "Customize SYMBOL, which must be a variable." | 684 "Customize SYMBOL, which must be a variable." |
550 (interactive (custom-variable-prompt)) | 685 (interactive (custom-variable-prompt)) |
551 (custom-buffer-create (list (list symbol 'custom-variable)))) | 686 (custom-buffer-create (list (list symbol 'custom-variable)) |
687 (format "*Customize Variable: %s*" | |
688 (custom-unlispify-tag-name symbol)))) | |
552 | 689 |
553 ;;;###autoload | 690 ;;;###autoload |
554 (defun customize-variable-other-window (symbol) | 691 (defun customize-variable-other-window (symbol) |
555 "Customize SYMBOL, which must be a variable. | 692 "Customize SYMBOL, which must be a variable. |
556 Show the buffer in another window, but don't select it." | 693 Show the buffer in another window, but don't select it." |
557 (interactive (custom-variable-prompt)) | 694 (interactive (custom-variable-prompt)) |
558 (custom-buffer-create-other-window (list (list symbol 'custom-variable)))) | 695 (custom-buffer-create-other-window |
696 (list (list symbol 'custom-variable)) | |
697 (format "*Customize Variable: %s*" (custom-unlispify-tag-name symbol)))) | |
559 | 698 |
560 ;;;###autoload | 699 ;;;###autoload |
561 (defun customize-face (&optional symbol) | 700 (defun customize-face (&optional symbol) |
562 "Customize SYMBOL, which should be a face name or nil. | 701 "Customize SYMBOL, which should be a face name or nil. |
563 If SYMBOL is nil, customize all faces." | 702 If SYMBOL is nil, customize all faces." |
570 (setq found (cons (list symbol 'custom-face) found))) | 709 (setq found (cons (list symbol 'custom-face) found))) |
571 (nreverse (mapcar 'intern | 710 (nreverse (mapcar 'intern |
572 (sort (mapcar 'symbol-name (face-list)) | 711 (sort (mapcar 'symbol-name (face-list)) |
573 'string<)))) | 712 'string<)))) |
574 | 713 |
575 (custom-buffer-create found)) | 714 (custom-buffer-create found "*Customize Faces*")) |
576 (if (stringp symbol) | 715 (if (stringp symbol) |
577 (setq symbol (intern symbol))) | 716 (setq symbol (intern symbol))) |
578 (unless (symbolp symbol) | 717 (unless (symbolp symbol) |
579 (error "Should be a symbol %S" symbol)) | 718 (error "Should be a symbol %S" symbol)) |
580 (custom-buffer-create (list (list symbol 'custom-face))))) | 719 (custom-buffer-create (list (list symbol 'custom-face)) |
720 (format "*Customize Face: %s*" | |
721 (custom-unlispify-tag-name symbol))))) | |
581 | 722 |
582 ;;;###autoload | 723 ;;;###autoload |
583 (defun customize-face-other-window (&optional symbol) | 724 (defun customize-face-other-window (&optional symbol) |
584 "Show customization buffer for FACE in other window." | 725 "Show customization buffer for FACE in other window." |
585 (interactive (list (completing-read "Customize face: " | 726 (interactive (list (completing-read "Customize face: " |
588 () | 729 () |
589 (if (stringp symbol) | 730 (if (stringp symbol) |
590 (setq symbol (intern symbol))) | 731 (setq symbol (intern symbol))) |
591 (unless (symbolp symbol) | 732 (unless (symbolp symbol) |
592 (error "Should be a symbol %S" symbol)) | 733 (error "Should be a symbol %S" symbol)) |
593 (custom-buffer-create-other-window (list (list symbol 'custom-face))))) | 734 (custom-buffer-create-other-window |
735 (list (list symbol 'custom-face)) | |
736 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol))))) | |
594 | 737 |
595 ;;;###autoload | 738 ;;;###autoload |
596 (defun customize-customized () | 739 (defun customize-customized () |
597 "Customize all already customized user options." | 740 "Customize all user options set since the last save in this session." |
741 (interactive) | |
742 (let ((found nil)) | |
743 (mapatoms (lambda (symbol) | |
744 (and (get symbol 'customized-face) | |
745 (custom-facep symbol) | |
746 (setq found (cons (list symbol 'custom-face) found))) | |
747 (and (get symbol 'customized-value) | |
748 (boundp symbol) | |
749 (setq found | |
750 (cons (list symbol 'custom-variable) found))))) | |
751 (if found | |
752 (custom-buffer-create found "*Customize Customized*") | |
753 (error "No customized user options")))) | |
754 | |
755 ;;;###autoload | |
756 (defun customize-saved () | |
757 "Customize all already saved user options." | |
598 (interactive) | 758 (interactive) |
599 (let ((found nil)) | 759 (let ((found nil)) |
600 (mapatoms (lambda (symbol) | 760 (mapatoms (lambda (symbol) |
601 (and (get symbol 'saved-face) | 761 (and (get symbol 'saved-face) |
602 (custom-facep symbol) | 762 (custom-facep symbol) |
604 (and (get symbol 'saved-value) | 764 (and (get symbol 'saved-value) |
605 (boundp symbol) | 765 (boundp symbol) |
606 (setq found | 766 (setq found |
607 (cons (list symbol 'custom-variable) found))))) | 767 (cons (list symbol 'custom-variable) found))))) |
608 (if found | 768 (if found |
609 (custom-buffer-create found) | 769 (custom-buffer-create found "*Customize Saved*") |
610 (error "No customized user options")))) | 770 (error "No saved user options")))) |
611 | 771 |
612 ;;;###autoload | 772 ;;;###autoload |
613 (defun customize-apropos (regexp &optional all) | 773 (defun customize-apropos (regexp &optional all) |
614 "Customize all user options matching REGEXP. | 774 "Customize all user options matching REGEXP. |
615 If ALL (e.g., started with a prefix key), include options which are not | 775 If ALL (e.g., started with a prefix key), include options which are not |
629 (get symbol 'variable-documentation) | 789 (get symbol 'variable-documentation) |
630 (user-variable-p symbol)))) | 790 (user-variable-p symbol)))) |
631 (setq found | 791 (setq found |
632 (cons (list symbol 'custom-variable) found)))))) | 792 (cons (list symbol 'custom-variable) found)))))) |
633 (if found | 793 (if found |
634 (custom-buffer-create found) | 794 (custom-buffer-create found "*Customize Apropos*") |
635 (error "No matches")))) | 795 (error "No matches")))) |
636 | 796 |
797 ;;; Buffer. | |
798 | |
637 ;;;###autoload | 799 ;;;###autoload |
638 (defun custom-buffer-create (options) | 800 (defun custom-buffer-create (options &optional name) |
639 "Create a buffer containing OPTIONS. | 801 "Create a buffer containing OPTIONS. |
802 Optional NAME is the name of the buffer. | |
640 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where | 803 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where |
641 SYMBOL is a customization option, and WIDGET is a widget for editing | 804 SYMBOL is a customization option, and WIDGET is a widget for editing |
642 that option." | 805 that option." |
643 (kill-buffer (get-buffer-create "*Customization*")) | 806 (unless name (setq name "*Customization*")) |
644 (switch-to-buffer (get-buffer-create "*Customization*")) | 807 (kill-buffer (get-buffer-create name)) |
808 (switch-to-buffer (get-buffer-create name)) | |
645 (custom-buffer-create-internal options)) | 809 (custom-buffer-create-internal options)) |
646 | 810 |
647 (defun custom-buffer-create-other-window (options) | 811 ;;;###autoload |
812 (defun custom-buffer-create-other-window (options &optional name) | |
648 "Create a buffer containing OPTIONS. | 813 "Create a buffer containing OPTIONS. |
814 Optional NAME is the name of the buffer. | |
649 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where | 815 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where |
650 SYMBOL is a customization option, and WIDGET is a widget for editing | 816 SYMBOL is a customization option, and WIDGET is a widget for editing |
651 that option." | 817 that option." |
652 (kill-buffer (get-buffer-create "*Customization*")) | 818 (unless name (setq name "*Customization*")) |
819 (kill-buffer (get-buffer-create name)) | |
653 (let ((window (selected-window))) | 820 (let ((window (selected-window))) |
654 (switch-to-buffer-other-window (get-buffer-create "*Customization*")) | 821 (switch-to-buffer-other-window (get-buffer-create name)) |
655 (custom-buffer-create-internal options) | 822 (custom-buffer-create-internal options) |
656 (select-window window))) | 823 (select-window window))) |
657 | 824 |
658 | 825 |
659 (defun custom-buffer-create-internal (options) | 826 (defun custom-buffer-create-internal (options) |
718 (widget-insert " ") | 885 (widget-insert " ") |
719 (widget-create 'push-button | 886 (widget-create 'push-button |
720 :tag "Done" | 887 :tag "Done" |
721 :help-echo "Bury the buffer." | 888 :help-echo "Bury the buffer." |
722 :action (lambda (widget &optional event) | 889 :action (lambda (widget &optional event) |
723 (bury-buffer) | 890 (bury-buffer))) |
724 ;; Steal button release event. | |
725 (if (and (fboundp 'button-press-event-p) | |
726 (fboundp 'next-command-event)) | |
727 ;; XEmacs | |
728 (and event | |
729 (button-press-event-p event) | |
730 (next-command-event)) | |
731 ;; Emacs | |
732 (when (memq 'down (event-modifiers event)) | |
733 (read-event))))) | |
734 (widget-insert "\n") | 891 (widget-insert "\n") |
735 (message "Creating customization setup...") | 892 (message "Creating customization setup...") |
736 (widget-setup) | 893 (widget-setup) |
737 (goto-char (point-min)) | 894 (goto-char (point-min)) |
738 (forward-char) ;Kludge: bob is writable in XEmacs. | 895 (when (fboundp 'map-extents) |
896 ;; This horrible kludge should make bob and eob read-only in XEmacs. | |
897 (map-extents (lambda (extent &rest junk) | |
898 (set-extent-property extent 'start-closed t)) | |
899 nil (point-min) (1+ (point-min))) | |
900 (map-extents (lambda (extent &rest junk) | |
901 (set-extent-property extent 'end-closed t)) | |
902 nil (1- (point-max)) (point-max))) | |
739 (message "Creating customization buffer...done")) | 903 (message "Creating customization buffer...done")) |
740 | 904 |
741 ;;; Modification of Basic Widgets. | 905 ;;; Modification of Basic Widgets. |
742 ;; | 906 ;; |
743 ;; We add extra properties to the basic widgets needed here. This is | 907 ;; We add extra properties to the basic widgets needed here. This is |
914 :group 'customize) | 1078 :group 'customize) |
915 | 1079 |
916 (define-widget 'custom-magic 'default | 1080 (define-widget 'custom-magic 'default |
917 "Show and manipulate state for a customization option." | 1081 "Show and manipulate state for a customization option." |
918 :format "%v" | 1082 :format "%v" |
919 :action 'widget-choice-item-action | 1083 :action 'widget-parent-action |
1084 :notify 'ignore | |
920 :value-get 'ignore | 1085 :value-get 'ignore |
921 :value-create 'custom-magic-value-create | 1086 :value-create 'custom-magic-value-create |
922 :value-delete 'widget-children-value-delete) | 1087 :value-delete 'widget-children-value-delete) |
1088 | |
1089 (defun widget-magic-mouse-down-action (widget &optional event) | |
1090 ;; Non-nil unless hidden. | |
1091 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent) | |
1092 :custom-state) | |
1093 'hidden))) | |
923 | 1094 |
924 (defun custom-magic-value-create (widget) | 1095 (defun custom-magic-value-create (widget) |
925 ;; Create compact status report for WIDGET. | 1096 ;; Create compact status report for WIDGET. |
926 (let* ((parent (widget-get widget :parent)) | 1097 (let* ((parent (widget-get widget :parent)) |
927 (state (widget-get parent :custom-state)) | 1098 (state (widget-get parent :custom-state)) |
930 (face (nth 2 entry)) | 1101 (face (nth 2 entry)) |
931 (text (nth 3 entry)) | 1102 (text (nth 3 entry)) |
932 (lisp (eq (widget-get parent :custom-form) 'lisp)) | 1103 (lisp (eq (widget-get parent :custom-form) 'lisp)) |
933 children) | 1104 children) |
934 (when custom-magic-show | 1105 (when custom-magic-show |
935 (push (widget-create-child-and-convert widget 'choice-item | 1106 (push (widget-create-child-and-convert |
936 :help-echo "\ | 1107 widget 'choice-item |
1108 :help-echo "\ | |
937 Change the state of this item." | 1109 Change the state of this item." |
938 :format "%[%t%]" | 1110 :format "%[%t%]" |
939 :tag "State") | 1111 :mouse-down-action 'widget-magic-mouse-down-action |
1112 :tag "State") | |
940 children) | 1113 children) |
941 (insert ": ") | 1114 (insert ": ") |
942 (if (eq custom-magic-show 'long) | 1115 (if (eq custom-magic-show 'long) |
943 (insert text) | 1116 (insert text) |
944 (insert (symbol-name state))) | 1117 (insert (symbol-name state))) |
948 (when custom-magic-show-button | 1121 (when custom-magic-show-button |
949 (when custom-magic-show | 1122 (when custom-magic-show |
950 (let ((indent (widget-get parent :indent))) | 1123 (let ((indent (widget-get parent :indent))) |
951 (when indent | 1124 (when indent |
952 (insert-char ? indent)))) | 1125 (insert-char ? indent)))) |
953 (push (widget-create-child-and-convert widget 'choice-item | 1126 (push (widget-create-child-and-convert |
954 :button-face face | 1127 widget 'choice-item |
955 :help-echo "Change the state." | 1128 :mouse-down-action 'widget-magic-mouse-down-action |
956 :format "%[%t%]" | 1129 :button-face face |
957 :tag (if lisp | 1130 :help-echo "Change the state." |
958 (concat "(" magic ")") | 1131 :format "%[%t%]" |
959 (concat "[" magic "]"))) | 1132 :tag (if lisp |
1133 (concat "(" magic ")") | |
1134 (concat "[" magic "]"))) | |
960 children) | 1135 children) |
961 (insert " ")) | 1136 (insert " ")) |
962 (widget-put widget :children children))) | 1137 (widget-put widget :children children))) |
963 | 1138 |
964 (defun custom-magic-reset (widget) | 1139 (defun custom-magic-reset (widget) |
974 :help-echo "Expand or collapse this item." | 1149 :help-echo "Expand or collapse this item." |
975 :action 'custom-level-action) | 1150 :action 'custom-level-action) |
976 | 1151 |
977 (defun custom-level-action (widget &optional event) | 1152 (defun custom-level-action (widget &optional event) |
978 "Toggle visibility for parent to WIDGET." | 1153 "Toggle visibility for parent to WIDGET." |
979 (let* ((parent (widget-get widget :parent)) | 1154 (custom-toggle-hide (widget-get widget :parent))) |
980 (state (widget-get parent :custom-state))) | |
981 (cond ((memq state '(invalid modified)) | |
982 (error "There are unset changes")) | |
983 ((eq state 'hidden) | |
984 (widget-put parent :custom-state 'unknown)) | |
985 (t | |
986 (widget-put parent :custom-state 'hidden))) | |
987 (custom-redraw parent))) | |
988 | 1155 |
989 ;;; The `custom' Widget. | 1156 ;;; The `custom' Widget. |
990 | 1157 |
991 (define-widget 'custom 'default | 1158 (define-widget 'custom 'default |
992 "Customize a user option." | 1159 "Customize a user option." |
997 :custom-level 1 | 1164 :custom-level 1 |
998 :custom-state 'hidden | 1165 :custom-state 'hidden |
999 :documentation-property 'widget-subclass-responsibility | 1166 :documentation-property 'widget-subclass-responsibility |
1000 :value-create 'widget-subclass-responsibility | 1167 :value-create 'widget-subclass-responsibility |
1001 :value-delete 'widget-children-value-delete | 1168 :value-delete 'widget-children-value-delete |
1002 :value-get 'widget-item-value-get | 1169 :value-get 'widget-value-value-get |
1003 :validate 'widget-editable-list-validate | 1170 :validate 'widget-children-validate |
1004 :match (lambda (widget value) (symbolp value))) | 1171 :match (lambda (widget value) (symbolp value))) |
1005 | 1172 |
1006 (defun custom-convert-widget (widget) | 1173 (defun custom-convert-widget (widget) |
1007 ;; Initialize :value and :tag from :args in WIDGET. | 1174 ;; Initialize :value and :tag from :args in WIDGET. |
1008 (let ((args (widget-get widget :args))) | 1175 (let ((args (widget-get widget :args))) |
1070 (custom-magic-reset widget)) | 1237 (custom-magic-reset widget)) |
1071 (apply 'widget-default-notify widget args)) | 1238 (apply 'widget-default-notify widget args)) |
1072 | 1239 |
1073 (defun custom-redraw (widget) | 1240 (defun custom-redraw (widget) |
1074 "Redraw WIDGET with current settings." | 1241 "Redraw WIDGET with current settings." |
1075 (let ((pos (point)) | 1242 (let ((line (count-lines (point-min) (point))) |
1243 (column (current-column)) | |
1244 (pos (point)) | |
1076 (from (marker-position (widget-get widget :from))) | 1245 (from (marker-position (widget-get widget :from))) |
1077 (to (marker-position (widget-get widget :to)))) | 1246 (to (marker-position (widget-get widget :to)))) |
1078 (save-excursion | 1247 (save-excursion |
1079 (widget-value-set widget (widget-value widget)) | 1248 (widget-value-set widget (widget-value widget)) |
1080 (custom-redraw-magic widget)) | 1249 (custom-redraw-magic widget)) |
1081 (when (and (>= pos from) (<= pos to)) | 1250 (when (and (>= pos from) (<= pos to)) |
1082 (goto-char pos)))) | 1251 (condition-case nil |
1252 (progn | |
1253 (if (> column 0) | |
1254 (goto-line line) | |
1255 (goto-line (1+ line))) | |
1256 (move-to-column column)) | |
1257 (error nil))))) | |
1083 | 1258 |
1084 (defun custom-redraw-magic (widget) | 1259 (defun custom-redraw-magic (widget) |
1085 "Redraw WIDGET state with current settings." | 1260 "Redraw WIDGET state with current settings." |
1086 (while widget | 1261 (while widget |
1087 (let ((magic (widget-get widget :custom-magic))) | 1262 (let ((magic (widget-get widget :custom-magic))) |
1126 | 1301 |
1127 (defun custom-load-widget (widget) | 1302 (defun custom-load-widget (widget) |
1128 "Load all dependencies for WIDGET." | 1303 "Load all dependencies for WIDGET." |
1129 (custom-load-symbol (widget-value widget))) | 1304 (custom-load-symbol (widget-value widget))) |
1130 | 1305 |
1306 (defun custom-toggle-hide (widget) | |
1307 "Toggle visibility of WIDGET." | |
1308 (let ((state (widget-get widget :custom-state))) | |
1309 (cond ((memq state '(invalid modified)) | |
1310 (error "There are unset changes")) | |
1311 ((eq state 'hidden) | |
1312 (widget-put widget :custom-state 'unknown)) | |
1313 (t | |
1314 (widget-put widget :custom-state 'hidden))) | |
1315 (custom-redraw widget))) | |
1316 | |
1131 ;;; The `custom-variable' Widget. | 1317 ;;; The `custom-variable' Widget. |
1132 | 1318 |
1133 (defface custom-variable-sample-face '((t (:underline t))) | 1319 (defface custom-variable-sample-face '((t (:underline t))) |
1134 "Face used for unpushable variable tags." | 1320 "Face used for unpushable variable tags." |
1135 :group 'custom-faces) | 1321 :group 'custom-faces) |
1162 (and (not (get symbol 'factory-value)) | 1348 (and (not (get symbol 'factory-value)) |
1163 (custom-guess-type symbol)) | 1349 (custom-guess-type symbol)) |
1164 'sexp)) | 1350 'sexp)) |
1165 (options (get symbol 'custom-options)) | 1351 (options (get symbol 'custom-options)) |
1166 (tmp (if (listp type) | 1352 (tmp (if (listp type) |
1167 (copy-list type) | 1353 (copy-sequence type) |
1168 (list type)))) | 1354 (list type)))) |
1169 (when options | 1355 (when options |
1170 (widget-put tmp :options options)) | 1356 (widget-put tmp :options options)) |
1171 tmp)) | 1357 tmp)) |
1172 | 1358 |
1179 (state (widget-get widget :custom-state)) | 1365 (state (widget-get widget :custom-state)) |
1180 (symbol (widget-get widget :value)) | 1366 (symbol (widget-get widget :value)) |
1181 (tag (widget-get widget :tag)) | 1367 (tag (widget-get widget :tag)) |
1182 (type (custom-variable-type symbol)) | 1368 (type (custom-variable-type symbol)) |
1183 (conv (widget-convert type)) | 1369 (conv (widget-convert type)) |
1370 (get (or (get symbol 'custom-get) 'default-value)) | |
1184 (value (if (default-boundp symbol) | 1371 (value (if (default-boundp symbol) |
1185 (default-value symbol) | 1372 (funcall get symbol) |
1186 (widget-get conv :value)))) | 1373 (widget-get conv :value)))) |
1187 ;; If the widget is new, the child determine whether it is hidden. | 1374 ;; If the widget is new, the child determine whether it is hidden. |
1188 (cond (state) | 1375 (cond (state) |
1189 ((custom-show type value) | 1376 ((custom-show type value) |
1190 (setq state 'unknown)) | 1377 (setq state 'unknown)) |
1210 (let* ((value (cond ((get symbol 'saved-value) | 1397 (let* ((value (cond ((get symbol 'saved-value) |
1211 (car (get symbol 'saved-value))) | 1398 (car (get symbol 'saved-value))) |
1212 ((get symbol 'factory-value) | 1399 ((get symbol 'factory-value) |
1213 (car (get symbol 'factory-value))) | 1400 (car (get symbol 'factory-value))) |
1214 ((default-boundp symbol) | 1401 ((default-boundp symbol) |
1215 (custom-quote (default-value symbol))) | 1402 (custom-quote (funcall get symbol))) |
1216 (t | 1403 (t |
1217 (custom-quote (widget-get conv :value)))))) | 1404 (custom-quote (widget-get conv :value)))))) |
1218 (push (widget-create-child-and-convert | 1405 (push (widget-create-child-and-convert |
1219 widget 'sexp | 1406 widget 'sexp |
1220 :button-face 'custom-variable-button-face | 1407 :button-face 'custom-variable-button-face |
1242 (widget-put widget :children children))) | 1429 (widget-put widget :children children))) |
1243 | 1430 |
1244 (defun custom-variable-state-set (widget) | 1431 (defun custom-variable-state-set (widget) |
1245 "Set the state of WIDGET." | 1432 "Set the state of WIDGET." |
1246 (let* ((symbol (widget-value widget)) | 1433 (let* ((symbol (widget-value widget)) |
1434 (get (or (get symbol 'custom-get) 'default-value)) | |
1247 (value (if (default-boundp symbol) | 1435 (value (if (default-boundp symbol) |
1248 (default-value symbol) | 1436 (funcall get symbol) |
1249 (widget-get widget :value))) | 1437 (widget-get widget :value))) |
1250 tmp | 1438 tmp |
1251 (state (cond ((setq tmp (get symbol 'customized-value)) | 1439 (state (cond ((setq tmp (get symbol 'customized-value)) |
1252 (if (condition-case nil | 1440 (if (condition-case nil |
1253 (equal value (eval (car tmp))) | 1441 (equal value (eval (car tmp))) |
1268 'changed)) | 1456 'changed)) |
1269 (t 'rogue)))) | 1457 (t 'rogue)))) |
1270 (widget-put widget :custom-state state))) | 1458 (widget-put widget :custom-state state))) |
1271 | 1459 |
1272 (defvar custom-variable-menu | 1460 (defvar custom-variable-menu |
1273 '(("Edit" . custom-variable-edit) | 1461 '(("Hide" custom-toggle-hide |
1274 ("Edit Lisp" . custom-variable-edit-lisp) | 1462 (lambda (widget) |
1275 ("Set" . custom-variable-set) | 1463 (not (memq (widget-get widget :custom-state) '(modified invalid))))) |
1276 ("Save" . custom-variable-save) | 1464 ("Edit" custom-variable-edit |
1277 ("Reset to Current" . custom-redraw) | 1465 (lambda (widget) |
1278 ("Reset to Saved" . custom-variable-reset-saved) | 1466 (not (eq (widget-get widget :custom-form) 'edit)))) |
1279 ("Reset to Factory Settings" . custom-variable-reset-factory)) | 1467 ("Edit Lisp" custom-variable-edit-lisp |
1468 (lambda (widget) | |
1469 (not (eq (widget-get widget :custom-form) 'lisp)))) | |
1470 ("Set" custom-variable-set | |
1471 (lambda (widget) | |
1472 (eq (widget-get widget :custom-state) 'modified))) | |
1473 ("Save" custom-variable-save | |
1474 (lambda (widget) | |
1475 (memq (widget-get widget :custom-state) '(modified set changed rogue)))) | |
1476 ("Reset to Current" custom-redraw | |
1477 (lambda (widget) | |
1478 (and (default-boundp (widget-value widget)) | |
1479 (memq (widget-get widget :custom-state) '(modified changed))))) | |
1480 ("Reset to Saved" custom-variable-reset-saved | |
1481 (lambda (widget) | |
1482 (and (get (widget-value widget) 'saved-value) | |
1483 (memq (widget-get widget :custom-state) | |
1484 '(modified set changed rogue))))) | |
1485 ("Reset to Factory Settings" custom-variable-reset-factory | |
1486 (lambda (widget) | |
1487 (and (get (widget-value widget) 'factory-value) | |
1488 (memq (widget-get widget :custom-state) | |
1489 '(modified set changed saved rogue)))))) | |
1280 "Alist of actions for the `custom-variable' widget. | 1490 "Alist of actions for the `custom-variable' widget. |
1281 The key is a string containing the name of the action, the value is a | 1491 Each entry has the form (NAME ACTION FILTER) where NAME is the name of |
1282 lisp function taking the widget as an element which will be called | 1492 the menu entry, ACTION is the function to call on the widget when the |
1283 when the action is chosen.") | 1493 menu is selected, and FILTER is a predicate which takes a `custom-variable' |
1494 widget as an argument, and returns non-nil if ACTION is valid on that | |
1495 widget. If FILTER is nil, ACTION is always valid.") | |
1284 | 1496 |
1285 (defun custom-variable-action (widget &optional event) | 1497 (defun custom-variable-action (widget &optional event) |
1286 "Show the menu for `custom-variable' WIDGET. | 1498 "Show the menu for `custom-variable' WIDGET. |
1287 Optional EVENT is the location for the menu." | 1499 Optional EVENT is the location for the menu." |
1288 (if (eq (widget-get widget :custom-state) 'hidden) | 1500 (if (eq (widget-get widget :custom-state) 'hidden) |
1289 (progn | 1501 (custom-toggle-hide widget) |
1290 (widget-put widget :custom-state 'unknown) | 1502 (unless (eq (widget-get widget :custom-state) 'modified) |
1291 (custom-redraw widget)) | 1503 (custom-variable-state-set widget)) |
1504 (custom-redraw-magic widget) | |
1292 (let* ((completion-ignore-case t) | 1505 (let* ((completion-ignore-case t) |
1293 (answer (widget-choose (custom-unlispify-tag-name | 1506 (answer (widget-choose (custom-unlispify-tag-name |
1294 (widget-get widget :value)) | 1507 (widget-get widget :value)) |
1295 custom-variable-menu | 1508 (custom-menu-filter custom-variable-menu |
1509 widget) | |
1296 event))) | 1510 event))) |
1297 (if answer | 1511 (if answer |
1298 (funcall answer widget))))) | 1512 (funcall answer widget))))) |
1299 | 1513 |
1300 (defun custom-variable-edit (widget) | 1514 (defun custom-variable-edit (widget) |
1309 (widget-put widget :custom-form 'lisp) | 1523 (widget-put widget :custom-form 'lisp) |
1310 (custom-redraw widget)) | 1524 (custom-redraw widget)) |
1311 | 1525 |
1312 (defun custom-variable-set (widget) | 1526 (defun custom-variable-set (widget) |
1313 "Set the current value for the variable being edited by WIDGET." | 1527 "Set the current value for the variable being edited by WIDGET." |
1314 (let ((form (widget-get widget :custom-form)) | 1528 (let* ((form (widget-get widget :custom-form)) |
1315 (state (widget-get widget :custom-state)) | 1529 (state (widget-get widget :custom-state)) |
1316 (child (car (widget-get widget :children))) | 1530 (child (car (widget-get widget :children))) |
1317 (symbol (widget-value widget)) | 1531 (symbol (widget-value widget)) |
1318 val) | 1532 (set (or (get symbol 'custom-set) 'set-default)) |
1533 val) | |
1319 (cond ((eq state 'hidden) | 1534 (cond ((eq state 'hidden) |
1320 (error "Cannot set hidden variable.")) | 1535 (error "Cannot set hidden variable.")) |
1321 ((setq val (widget-apply child :validate)) | 1536 ((setq val (widget-apply child :validate)) |
1322 (goto-char (widget-get val :from)) | 1537 (goto-char (widget-get val :from)) |
1323 (error "%s" (widget-get val :error))) | 1538 (error "%s" (widget-get val :error))) |
1324 ((eq form 'lisp) | 1539 ((eq form 'lisp) |
1325 (set-default symbol (eval (setq val (widget-value child)))) | 1540 (funcall set symbol (eval (setq val (widget-value child)))) |
1326 (put symbol 'customized-value (list val))) | 1541 (put symbol 'customized-value (list val))) |
1327 (t | 1542 (t |
1328 (set-default symbol (setq val (widget-value child))) | 1543 (funcall set symbol (setq val (widget-value child))) |
1329 (put symbol 'customized-value (list (custom-quote val))))) | 1544 (put symbol 'customized-value (list (custom-quote val))))) |
1330 (custom-variable-state-set widget) | 1545 (custom-variable-state-set widget) |
1331 (custom-redraw-magic widget))) | 1546 (custom-redraw-magic widget))) |
1332 | 1547 |
1333 (defun custom-variable-save (widget) | 1548 (defun custom-variable-save (widget) |
1334 "Set the default value for the variable being edited by WIDGET." | 1549 "Set the default value for the variable being edited by WIDGET." |
1335 (let ((form (widget-get widget :custom-form)) | 1550 (let* ((form (widget-get widget :custom-form)) |
1336 (state (widget-get widget :custom-state)) | 1551 (state (widget-get widget :custom-state)) |
1337 (child (car (widget-get widget :children))) | 1552 (child (car (widget-get widget :children))) |
1338 (symbol (widget-value widget)) | 1553 (symbol (widget-value widget)) |
1339 val) | 1554 (set (or (get symbol 'custom-set) 'set-default)) |
1555 val) | |
1340 (cond ((eq state 'hidden) | 1556 (cond ((eq state 'hidden) |
1341 (error "Cannot set hidden variable.")) | 1557 (error "Cannot set hidden variable.")) |
1342 ((setq val (widget-apply child :validate)) | 1558 ((setq val (widget-apply child :validate)) |
1343 (goto-char (widget-get val :from)) | 1559 (goto-char (widget-get val :from)) |
1344 (error "%s" (widget-get val :error))) | 1560 (error "%s" (widget-get val :error))) |
1345 ((eq form 'lisp) | 1561 ((eq form 'lisp) |
1346 (put symbol 'saved-value (list (widget-value child))) | 1562 (put symbol 'saved-value (list (widget-value child))) |
1347 (set-default symbol (eval (widget-value child)))) | 1563 (funcall set symbol (eval (widget-value child)))) |
1348 (t | 1564 (t |
1349 (put symbol | 1565 (put symbol |
1350 'saved-value (list (custom-quote (widget-value | 1566 'saved-value (list (custom-quote (widget-value |
1351 child)))) | 1567 child)))) |
1352 (set-default symbol (widget-value child)))) | 1568 (funcall set symbol (widget-value child)))) |
1353 (put symbol 'customized-value nil) | 1569 (put symbol 'customized-value nil) |
1354 (custom-save-all) | 1570 (custom-save-all) |
1355 (custom-variable-state-set widget) | 1571 (custom-variable-state-set widget) |
1356 (custom-redraw-magic widget))) | 1572 (custom-redraw-magic widget))) |
1357 | 1573 |
1358 (defun custom-variable-reset-saved (widget) | 1574 (defun custom-variable-reset-saved (widget) |
1359 "Restore the saved value for the variable being edited by WIDGET." | 1575 "Restore the saved value for the variable being edited by WIDGET." |
1360 (let ((symbol (widget-value widget))) | 1576 (let* ((symbol (widget-value widget)) |
1577 (set (or (get symbol 'custom-set) 'set-default))) | |
1361 (if (get symbol 'saved-value) | 1578 (if (get symbol 'saved-value) |
1362 (condition-case nil | 1579 (condition-case nil |
1363 (set-default symbol (eval (car (get symbol 'saved-value)))) | 1580 (funcall set symbol (eval (car (get symbol 'saved-value)))) |
1364 (error nil)) | 1581 (error nil)) |
1365 (error "No saved value for %s" symbol)) | 1582 (error "No saved value for %s" symbol)) |
1366 (put symbol 'customized-value nil) | 1583 (put symbol 'customized-value nil) |
1367 (widget-put widget :custom-state 'unknown) | 1584 (widget-put widget :custom-state 'unknown) |
1368 (custom-redraw widget))) | 1585 (custom-redraw widget))) |
1369 | 1586 |
1370 (defun custom-variable-reset-factory (widget) | 1587 (defun custom-variable-reset-factory (widget) |
1371 "Restore the factory setting for the variable being edited by WIDGET." | 1588 "Restore the factory setting for the variable being edited by WIDGET." |
1372 (let ((symbol (widget-value widget))) | 1589 (let* ((symbol (widget-value widget)) |
1590 (set (or (get symbol 'custom-set) 'set-default))) | |
1373 (if (get symbol 'factory-value) | 1591 (if (get symbol 'factory-value) |
1374 (set-default symbol (eval (car (get symbol 'factory-value)))) | 1592 (funcall set symbol (eval (car (get symbol 'factory-value)))) |
1375 (error "No factory default for %S" symbol)) | 1593 (error "No factory default for %S" symbol)) |
1376 (put symbol 'customized-value nil) | 1594 (put symbol 'customized-value nil) |
1377 (when (get symbol 'saved-value) | 1595 (when (get symbol 'saved-value) |
1378 (put symbol 'saved-value nil) | 1596 (put symbol 'saved-value nil) |
1379 (custom-save-all)) | 1597 (custom-save-all)) |
1526 "A display specification that doesn't match the selected display." | 1744 "A display specification that doesn't match the selected display." |
1527 :match 'custom-display-unselected-match) | 1745 :match 'custom-display-unselected-match) |
1528 | 1746 |
1529 (defun custom-display-unselected-match (widget value) | 1747 (defun custom-display-unselected-match (widget value) |
1530 "Non-nil if VALUE is an unselected display specification." | 1748 "Non-nil if VALUE is an unselected display specification." |
1531 (and (listp value) | 1749 (not (face-spec-set-match-display value (selected-frame)))) |
1532 (eq (length value) 2) | |
1533 (not (custom-display-match-frame value (selected-frame))))) | |
1534 | 1750 |
1535 (define-widget 'custom-face-selected 'group | 1751 (define-widget 'custom-face-selected 'group |
1536 "Edit the attributes of the selected display in a face specification." | 1752 "Edit the attributes of the selected display in a face specification." |
1537 :args '((repeat :format "" | 1753 :args '((repeat :format "" |
1538 :inline t | 1754 :inline t |
1552 (when (not (eq (widget-get widget :custom-state) 'hidden)) | 1768 (when (not (eq (widget-get widget :custom-state) 'hidden)) |
1553 (message "Creating face editor...") | 1769 (message "Creating face editor...") |
1554 (custom-load-widget widget) | 1770 (custom-load-widget widget) |
1555 (let* ((symbol (widget-value widget)) | 1771 (let* ((symbol (widget-value widget)) |
1556 (spec (or (get symbol 'saved-face) | 1772 (spec (or (get symbol 'saved-face) |
1557 (get symbol 'factory-face) | 1773 (get symbol 'face-defface-spec) |
1558 ;; Attempt to construct it. | 1774 ;; Attempt to construct it. |
1559 (list (list t (custom-face-attributes-get | 1775 (list (list t (custom-face-attributes-get |
1560 symbol (selected-frame)))))) | 1776 symbol (selected-frame)))))) |
1561 (form (widget-get widget :custom-form)) | 1777 (form (widget-get widget :custom-form)) |
1562 (indent (widget-get widget :indent)) | 1778 (indent (widget-get widget :indent)) |
1576 (custom-face-state-set widget) | 1792 (custom-face-state-set widget) |
1577 (widget-put widget :children (list edit))) | 1793 (widget-put widget :children (list edit))) |
1578 (message "Creating face editor...done"))) | 1794 (message "Creating face editor...done"))) |
1579 | 1795 |
1580 (defvar custom-face-menu | 1796 (defvar custom-face-menu |
1581 '(("Edit Selected" . custom-face-edit-selected) | 1797 '(("Hide" custom-toggle-hide |
1582 ("Edit All" . custom-face-edit-all) | 1798 (lambda (widget) |
1583 ("Edit Lisp" . custom-face-edit-lisp) | 1799 (not (memq (widget-get widget :custom-state) '(modified invalid))))) |
1584 ("Set" . custom-face-set) | 1800 ("Edit Selected" custom-face-edit-selected |
1585 ("Save" . custom-face-save) | 1801 (lambda (widget) |
1586 ("Reset to Saved" . custom-face-reset-saved) | 1802 (not (eq (widget-get widget :custom-form) 'selected)))) |
1587 ("Reset to Factory Setting" . custom-face-reset-factory)) | 1803 ("Edit All" custom-face-edit-all |
1804 (lambda (widget) | |
1805 (not (eq (widget-get widget :custom-form) 'all)))) | |
1806 ("Edit Lisp" custom-face-edit-lisp | |
1807 (lambda (widget) | |
1808 (not (eq (widget-get widget :custom-form) 'lisp)))) | |
1809 ("Set" custom-face-set) | |
1810 ("Save" custom-face-save) | |
1811 ("Reset to Saved" custom-face-reset-saved | |
1812 (lambda (widget) | |
1813 (get (widget-value widget) 'saved-face))) | |
1814 ("Reset to Factory Setting" custom-face-reset-factory | |
1815 (lambda (widget) | |
1816 (get (widget-value widget) 'face-defface-spec)))) | |
1588 "Alist of actions for the `custom-face' widget. | 1817 "Alist of actions for the `custom-face' widget. |
1589 The key is a string containing the name of the action, the value is a | 1818 Each entry has the form (NAME ACTION FILTER) where NAME is the name of |
1590 lisp function taking the widget as an element which will be called | 1819 the menu entry, ACTION is the function to call on the widget when the |
1591 when the action is chosen.") | 1820 menu is selected, and FILTER is a predicate which takes a `custom-face' |
1821 widget as an argument, and returns non-nil if ACTION is valid on that | |
1822 widget. If FILTER is nil, ACTION is always valid.") | |
1592 | 1823 |
1593 (defun custom-face-edit-selected (widget) | 1824 (defun custom-face-edit-selected (widget) |
1594 "Edit selected attributes of the value of WIDGET." | 1825 "Edit selected attributes of the value of WIDGET." |
1595 (widget-put widget :custom-state 'unknown) | 1826 (widget-put widget :custom-state 'unknown) |
1596 (widget-put widget :custom-form 'selected) | 1827 (widget-put widget :custom-form 'selected) |
1613 (let ((symbol (widget-value widget))) | 1844 (let ((symbol (widget-value widget))) |
1614 (widget-put widget :custom-state (cond ((get symbol 'customized-face) | 1845 (widget-put widget :custom-state (cond ((get symbol 'customized-face) |
1615 'set) | 1846 'set) |
1616 ((get symbol 'saved-face) | 1847 ((get symbol 'saved-face) |
1617 'saved) | 1848 'saved) |
1618 ((get symbol 'factory-face) | 1849 ((get symbol 'face-defface-spec) |
1619 'factory) | 1850 'factory) |
1620 (t | 1851 (t |
1621 'rogue))))) | 1852 'rogue))))) |
1622 | 1853 |
1623 (defun custom-face-action (widget &optional event) | 1854 (defun custom-face-action (widget &optional event) |
1624 "Show the menu for `custom-face' WIDGET. | 1855 "Show the menu for `custom-face' WIDGET. |
1625 Optional EVENT is the location for the menu." | 1856 Optional EVENT is the location for the menu." |
1626 (if (eq (widget-get widget :custom-state) 'hidden) | 1857 (if (eq (widget-get widget :custom-state) 'hidden) |
1627 (progn | 1858 (custom-toggle-hide widget) |
1628 (widget-put widget :custom-state 'unknown) | |
1629 (custom-redraw widget)) | |
1630 (let* ((completion-ignore-case t) | 1859 (let* ((completion-ignore-case t) |
1631 (symbol (widget-get widget :value)) | 1860 (symbol (widget-get widget :value)) |
1632 (answer (widget-choose (custom-unlispify-tag-name symbol) | 1861 (answer (widget-choose (custom-unlispify-tag-name symbol) |
1633 custom-face-menu event))) | 1862 (custom-menu-filter custom-face-menu |
1863 widget) | |
1864 event))) | |
1634 (if answer | 1865 (if answer |
1635 (funcall answer widget))))) | 1866 (funcall answer widget))))) |
1636 | 1867 |
1637 (defun custom-face-set (widget) | 1868 (defun custom-face-set (widget) |
1638 "Make the face attributes in WIDGET take effect." | 1869 "Make the face attributes in WIDGET take effect." |
1639 (let* ((symbol (widget-value widget)) | 1870 (let* ((symbol (widget-value widget)) |
1640 (child (car (widget-get widget :children))) | 1871 (child (car (widget-get widget :children))) |
1641 (value (widget-value child))) | 1872 (value (widget-value child))) |
1642 (put symbol 'customized-face value) | 1873 (put symbol 'customized-face value) |
1643 (when (fboundp 'copy-face) | |
1644 (copy-face 'custom-face-empty symbol)) | |
1645 (custom-face-display-set symbol value) | 1874 (custom-face-display-set symbol value) |
1646 (custom-face-state-set widget) | 1875 (custom-face-state-set widget) |
1647 (custom-redraw-magic widget))) | 1876 (custom-redraw-magic widget))) |
1648 | 1877 |
1649 (defun custom-face-save (widget) | 1878 (defun custom-face-save (widget) |
1650 "Make the face attributes in WIDGET default." | 1879 "Make the face attributes in WIDGET default." |
1651 (let* ((symbol (widget-value widget)) | 1880 (let* ((symbol (widget-value widget)) |
1652 (child (car (widget-get widget :children))) | 1881 (child (car (widget-get widget :children))) |
1653 (value (widget-value child))) | 1882 (value (widget-value child))) |
1654 (when (fboundp 'copy-face) | |
1655 (copy-face 'custom-face-empty symbol)) | |
1656 (custom-face-display-set symbol value) | 1883 (custom-face-display-set symbol value) |
1657 (put symbol 'saved-face value) | 1884 (put symbol 'saved-face value) |
1658 (put symbol 'customized-face nil) | 1885 (put symbol 'customized-face nil) |
1659 (custom-face-state-set widget) | 1886 (custom-face-state-set widget) |
1660 (custom-redraw-magic widget))) | 1887 (custom-redraw-magic widget))) |
1665 (child (car (widget-get widget :children))) | 1892 (child (car (widget-get widget :children))) |
1666 (value (get symbol 'saved-face))) | 1893 (value (get symbol 'saved-face))) |
1667 (unless value | 1894 (unless value |
1668 (error "No saved value for this face")) | 1895 (error "No saved value for this face")) |
1669 (put symbol 'customized-face nil) | 1896 (put symbol 'customized-face nil) |
1670 (when (fboundp 'copy-face) | |
1671 (copy-face 'custom-face-empty symbol)) | |
1672 (custom-face-display-set symbol value) | 1897 (custom-face-display-set symbol value) |
1673 (widget-value-set child value) | 1898 (widget-value-set child value) |
1674 (custom-face-state-set widget) | 1899 (custom-face-state-set widget) |
1675 (custom-redraw-magic widget))) | 1900 (custom-redraw-magic widget))) |
1676 | 1901 |
1677 (defun custom-face-reset-factory (widget) | 1902 (defun custom-face-reset-factory (widget) |
1678 "Restore WIDGET to the face's factory settings." | 1903 "Restore WIDGET to the face's factory settings." |
1679 (let* ((symbol (widget-value widget)) | 1904 (let* ((symbol (widget-value widget)) |
1680 (child (car (widget-get widget :children))) | 1905 (child (car (widget-get widget :children))) |
1681 (value (get symbol 'factory-face))) | 1906 (value (get symbol 'face-defface-spec))) |
1682 (unless value | 1907 (unless value |
1683 (error "No factory default for this face")) | 1908 (error "No factory default for this face")) |
1684 (put symbol 'customized-face nil) | 1909 (put symbol 'customized-face nil) |
1685 (when (get symbol 'saved-face) | 1910 (when (get symbol 'saved-face) |
1686 (put symbol 'saved-face nil) | 1911 (put symbol 'saved-face nil) |
1687 (custom-save-all)) | 1912 (custom-save-all)) |
1688 (when (fboundp 'copy-face) | |
1689 (copy-face 'custom-face-empty symbol)) | |
1690 (custom-face-display-set symbol value) | 1913 (custom-face-display-set symbol value) |
1691 (widget-value-set child value) | 1914 (widget-value-set child value) |
1692 (custom-face-state-set widget) | 1915 (custom-face-state-set widget) |
1693 (custom-redraw-magic widget))) | 1916 (custom-redraw-magic widget))) |
1694 | 1917 |
1695 ;;; The `face' Widget. | 1918 ;;; The `face' Widget. |
1696 | 1919 |
1697 (define-widget 'face 'default | 1920 (define-widget 'face 'default |
1698 "Select and customize a face." | 1921 "Select and customize a face." |
1699 :convert-widget 'widget-item-convert-widget | 1922 :convert-widget 'widget-value-convert-widget |
1700 :format "%[%t%]: %v" | 1923 :format "%[%t%]: %v" |
1701 :tag "Face" | 1924 :tag "Face" |
1702 :value 'default | 1925 :value 'default |
1703 :value-create 'widget-face-value-create | 1926 :value-create 'widget-face-value-create |
1704 :value-delete 'widget-face-value-delete | 1927 :value-delete 'widget-face-value-delete |
1705 :value-get 'widget-item-value-get | 1928 :value-get 'widget-value-value-get |
1706 :validate 'widget-editable-list-validate | 1929 :validate 'widget-children-validate |
1707 :action 'widget-face-action | 1930 :action 'widget-face-action |
1708 :match '(lambda (widget value) (symbolp value))) | 1931 :match '(lambda (widget value) (symbolp value))) |
1709 | 1932 |
1710 (defun widget-face-value-create (widget) | 1933 (defun widget-face-value-create (widget) |
1711 ;; Create a `custom-face' child. | 1934 ;; Create a `custom-face' child. |
1849 (widget-put widget :children children) | 2072 (widget-put widget :children children) |
1850 (custom-group-state-update widget) | 2073 (custom-group-state-update widget) |
1851 (message "Creating group... done"))))) | 2074 (message "Creating group... done"))))) |
1852 | 2075 |
1853 (defvar custom-group-menu | 2076 (defvar custom-group-menu |
1854 '(("Set" . custom-group-set) | 2077 '(("Hide" custom-toggle-hide |
1855 ("Save" . custom-group-save) | 2078 (lambda (widget) |
1856 ("Reset to Current" . custom-group-reset-current) | 2079 (not (memq (widget-get widget :custom-state) '(modified invalid))))) |
1857 ("Reset to Saved" . custom-group-reset-saved) | 2080 ("Set" custom-group-set |
1858 ("Reset to Factory" . custom-group-reset-factory)) | 2081 (lambda (widget) |
2082 (eq (widget-get widget :custom-state) 'modified))) | |
2083 ("Save" custom-group-save | |
2084 (lambda (widget) | |
2085 (memq (widget-get widget :custom-state) '(modified set)))) | |
2086 ("Reset to Current" custom-group-reset-current | |
2087 (lambda (widget) | |
2088 (memq (widget-get widget :custom-state) '(modified)))) | |
2089 ("Reset to Saved" custom-group-reset-saved | |
2090 (lambda (widget) | |
2091 (memq (widget-get widget :custom-state) '(modified set)))) | |
2092 ("Reset to Factory" custom-group-reset-factory | |
2093 (lambda (widget) | |
2094 (memq (widget-get widget :custom-state) '(modified set saved))))) | |
1859 "Alist of actions for the `custom-group' widget. | 2095 "Alist of actions for the `custom-group' widget. |
1860 The key is a string containing the name of the action, the value is a | 2096 Each entry has the form (NAME ACTION FILTER) where NAME is the name of |
1861 lisp function taking the widget as an element which will be called | 2097 the menu entry, ACTION is the function to call on the widget when the |
1862 when the action is chosen.") | 2098 menu is selected, and FILTER is a predicate which takes a `custom-group' |
2099 widget as an argument, and returns non-nil if ACTION is valid on that | |
2100 widget. If FILTER is nil, ACTION is always valid.") | |
1863 | 2101 |
1864 (defun custom-group-action (widget &optional event) | 2102 (defun custom-group-action (widget &optional event) |
1865 "Show the menu for `custom-group' WIDGET. | 2103 "Show the menu for `custom-group' WIDGET. |
1866 Optional EVENT is the location for the menu." | 2104 Optional EVENT is the location for the menu." |
1867 (if (eq (widget-get widget :custom-state) 'hidden) | 2105 (if (eq (widget-get widget :custom-state) 'hidden) |
1868 (progn | 2106 (custom-toggle-hide widget) |
1869 (widget-put widget :custom-state 'unknown) | |
1870 (custom-redraw widget)) | |
1871 (let* ((completion-ignore-case t) | 2107 (let* ((completion-ignore-case t) |
1872 (answer (widget-choose (custom-unlispify-tag-name | 2108 (answer (widget-choose (custom-unlispify-tag-name |
1873 (widget-get widget :value)) | 2109 (widget-get widget :value)) |
1874 custom-group-menu | 2110 (custom-menu-filter custom-group-menu |
2111 widget) | |
1875 event))) | 2112 event))) |
1876 (if answer | 2113 (if answer |
1877 (funcall answer widget))))) | 2114 (funcall answer widget))))) |
1878 | 2115 |
1879 (defun custom-group-set (widget) | 2116 (defun custom-group-set (widget) |
1970 (let ((standard-output (current-buffer))) | 2207 (let ((standard-output (current-buffer))) |
1971 (unless (bolp) | 2208 (unless (bolp) |
1972 (princ "\n")) | 2209 (princ "\n")) |
1973 (princ "(custom-set-variables") | 2210 (princ "(custom-set-variables") |
1974 (mapatoms (lambda (symbol) | 2211 (mapatoms (lambda (symbol) |
1975 (let ((value (get symbol 'saved-value))) | 2212 (let ((value (get symbol 'saved-value)) |
2213 (requests (get symbol 'custom-requests)) | |
2214 (now (not (or (get symbol 'factory-value) | |
2215 (and (not (boundp symbol)) | |
2216 (not (get symbol 'force-value))))))) | |
1976 (when value | 2217 (when value |
1977 (princ "\n '(") | 2218 (princ "\n '(") |
1978 (princ symbol) | 2219 (princ symbol) |
1979 (princ " ") | 2220 (princ " ") |
1980 (prin1 (car value)) | 2221 (prin1 (car value)) |
1981 (if (or (get symbol 'factory-value) | 2222 (cond (requests |
1982 (and (not (boundp symbol)) | 2223 (if now |
1983 (not (get symbol 'force-value)))) | 2224 (princ " t ") |
1984 (princ ")") | 2225 (princ " nil ")) |
1985 (princ " t)")))))) | 2226 (prin1 requests) |
2227 (princ ")")) | |
2228 (now | |
2229 (princ " t)")) | |
2230 (t | |
2231 (princ ")"))))))) | |
1986 (princ ")") | 2232 (princ ")") |
1987 (unless (looking-at "\n") | 2233 (unless (looking-at "\n") |
1988 (princ "\n"))))) | 2234 (princ "\n"))))) |
1989 | 2235 |
1990 (defun custom-save-faces () | 2236 (defun custom-save-faces () |
1998 (let ((value (get 'default 'saved-face))) | 2244 (let ((value (get 'default 'saved-face))) |
1999 ;; The default face must be first, since it affects the others. | 2245 ;; The default face must be first, since it affects the others. |
2000 (when value | 2246 (when value |
2001 (princ "\n '(default ") | 2247 (princ "\n '(default ") |
2002 (prin1 value) | 2248 (prin1 value) |
2003 (if (or (get 'default 'factory-face) | 2249 (if (or (get 'default 'face-defface-spec) |
2004 (and (not (custom-facep 'default)) | 2250 (and (not (custom-facep 'default)) |
2005 (not (get 'default 'force-face)))) | 2251 (not (get 'default 'force-face)))) |
2006 (princ ")") | 2252 (princ ")") |
2007 (princ " t)")))) | 2253 (princ " t)")))) |
2008 (mapatoms (lambda (symbol) | 2254 (mapatoms (lambda (symbol) |
2012 value) | 2258 value) |
2013 (princ "\n '(") | 2259 (princ "\n '(") |
2014 (princ symbol) | 2260 (princ symbol) |
2015 (princ " ") | 2261 (princ " ") |
2016 (prin1 value) | 2262 (prin1 value) |
2017 (if (or (get symbol 'factory-face) | 2263 (if (or (get symbol 'face-defface-spec) |
2018 (and (not (custom-facep symbol)) | 2264 (and (not (custom-facep symbol)) |
2019 (not (get symbol 'force-face)))) | 2265 (not (get symbol 'force-face)))) |
2020 (princ ")") | 2266 (princ ")") |
2021 (princ " t)")))))) | 2267 (princ " t)")))))) |
2022 (princ ")") | 2268 (princ ")") |
2023 (unless (looking-at "\n") | 2269 (unless (looking-at "\n") |
2024 (princ "\n"))))) | 2270 (princ "\n"))))) |
2271 | |
2272 ;;;###autoload | |
2273 (defun custom-save-customized () | |
2274 "Save all user options which have been set in this session." | |
2275 (interactive) | |
2276 (mapatoms (lambda (symbol) | |
2277 (let ((face (get symbol 'customized-face)) | |
2278 (value (get symbol 'customized-value))) | |
2279 (when face | |
2280 (put symbol 'saved-face face) | |
2281 (put symbol 'customized-face nil)) | |
2282 (when value | |
2283 (put symbol 'saved-value value) | |
2284 (put symbol 'customized-value nil))))) | |
2285 ;; We really should update all custom buffers here. | |
2286 (custom-save-all)) | |
2025 | 2287 |
2026 ;;;###autoload | 2288 ;;;###autoload |
2027 (defun custom-save-all () | 2289 (defun custom-save-all () |
2028 "Save all customizations in `custom-file'." | 2290 "Save all customizations in `custom-file'." |
2029 (custom-save-variables) | 2291 (custom-save-variables) |
2073 :group 'customize)) | 2335 :group 'customize)) |
2074 | 2336 |
2075 (defun custom-face-menu-create (widget symbol) | 2337 (defun custom-face-menu-create (widget symbol) |
2076 "Ignoring WIDGET, create a menu entry for customization face SYMBOL." | 2338 "Ignoring WIDGET, create a menu entry for customization face SYMBOL." |
2077 (vector (custom-unlispify-menu-entry symbol) | 2339 (vector (custom-unlispify-menu-entry symbol) |
2078 `(custom-buffer-create '((,symbol custom-face))) | 2340 `(customize-face ',symbol) |
2079 t)) | 2341 t)) |
2080 | 2342 |
2081 (defun custom-variable-menu-create (widget symbol) | 2343 (defun custom-variable-menu-create (widget symbol) |
2082 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL." | 2344 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL." |
2083 (let ((type (get symbol 'custom-type))) | 2345 (let ((type (get symbol 'custom-type))) |
2084 (unless (listp type) | 2346 (unless (listp type) |
2085 (setq type (list type))) | 2347 (setq type (list type))) |
2086 (if (and type (widget-get type :custom-menu)) | 2348 (if (and type (widget-get type :custom-menu)) |
2087 (widget-apply type :custom-menu symbol) | 2349 (widget-apply type :custom-menu symbol) |
2088 (vector (custom-unlispify-menu-entry symbol) | 2350 (vector (custom-unlispify-menu-entry symbol) |
2089 `(custom-buffer-create '((,symbol custom-variable))) | 2351 `(customize-variable ',symbol) |
2090 t)))) | 2352 t)))) |
2091 | 2353 |
2092 ;; Add checkboxes to boolean variable entries. | 2354 ;; Add checkboxes to boolean variable entries. |
2093 (widget-put (get 'boolean 'widget-type) | 2355 (widget-put (get 'boolean 'widget-type) |
2094 :custom-menu (lambda (widget symbol) | 2356 :custom-menu (lambda (widget symbol) |
2095 (vector (custom-unlispify-menu-entry symbol) | 2357 (vector (custom-unlispify-menu-entry symbol) |
2096 `(custom-buffer-create | 2358 `(customize-variable ',symbol) |
2097 '((,symbol custom-variable))) | |
2098 ':style 'toggle | 2359 ':style 'toggle |
2099 ':selected symbol))) | 2360 ':selected symbol))) |
2100 | 2361 |
2101 (if (string-match "XEmacs" emacs-version) | 2362 (if (string-match "XEmacs" emacs-version) |
2102 ;; XEmacs can create menus dynamically. | 2363 ;; XEmacs can create menus dynamically. |
2115 ;;;###autoload | 2376 ;;;###autoload |
2116 (defun custom-menu-create (symbol) | 2377 (defun custom-menu-create (symbol) |
2117 "Create menu for customization group SYMBOL. | 2378 "Create menu for customization group SYMBOL. |
2118 The menu is in a format applicable to `easy-menu-define'." | 2379 The menu is in a format applicable to `easy-menu-define'." |
2119 (let* ((item (vector (custom-unlispify-menu-entry symbol) | 2380 (let* ((item (vector (custom-unlispify-menu-entry symbol) |
2120 `(custom-buffer-create '((,symbol custom-group))) | 2381 `(customize ',symbol) |
2121 t))) | 2382 t))) |
2122 (if (and (or (not (boundp 'custom-menu-nesting)) | 2383 (if (and (or (not (boundp 'custom-menu-nesting)) |
2123 (>= custom-menu-nesting 0)) | 2384 (>= custom-menu-nesting 0)) |
2124 (< (length (get symbol 'custom-group)) widget-menu-max-size)) | 2385 (< (length (get symbol 'custom-group)) widget-menu-max-size)) |
2125 (let ((custom-prefix-list (custom-prefix-add symbol | 2386 (let ((custom-prefix-list (custom-prefix-add symbol |
2162 (set-keymap-parent custom-mode-map widget-keymap) | 2423 (set-keymap-parent custom-mode-map widget-keymap) |
2163 (define-key custom-mode-map "q" 'bury-buffer)) | 2424 (define-key custom-mode-map "q" 'bury-buffer)) |
2164 | 2425 |
2165 (easy-menu-define custom-mode-customize-menu | 2426 (easy-menu-define custom-mode-customize-menu |
2166 custom-mode-map | 2427 custom-mode-map |
2167 "Menu used in customization buffers." | 2428 "Menu used to customize customization buffers." |
2168 (customize-menu-create 'customize)) | 2429 (customize-menu-create 'customize)) |
2169 | 2430 |
2170 (easy-menu-define custom-mode-menu | 2431 (easy-menu-define custom-mode-menu |
2171 custom-mode-map | 2432 custom-mode-map |
2172 "Menu used in customization buffers." | 2433 "Menu used in customization buffers." |