changeset 47741:be7a44c8fe9c

wid-edit.el fixes
author Per Abrahamsen <abraham@dina.kvl.dk>
date Thu, 03 Oct 2002 13:46:25 +0000
parents c09fefd016a4
children 8d54d470f30d
files lisp/ChangeLog lisp/wid-edit.el man/widget.texi
diffstat 3 files changed, 54 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Thu Oct 03 04:21:12 2002 +0000
+++ b/lisp/ChangeLog	Thu Oct 03 13:46:25 2002 +0000
@@ -27,6 +27,24 @@
 	* startup.el (normal-top-level): Reset standard-value property of
 	`user-full-name' here.
 
+2002-10-02  Per Abrahamsen  <abraham@dina.kvl.dk>
+
+	* wid-edit.el (widget-default-get): Change to return external
+	value. 
+	(widget-choice-action): Update caller.
+	(widget-editable-list-entry-create): Update caller.
+
+	* wid-edit.el (widget-types-copy): New function.
+	(default): Added :copy keyword.
+	(menu-choice): Ditto.
+	(checklist): Ditto.
+	(radio-button-choice): Ditto.
+	(editable-list): Ditto.
+	(group): Ditto.
+	(widget-copy): New function.
+	(widget-create-child): Use it.
+	(widget-create-child-value): Use it.
+
 2002-10-01  Bill Wohler  <wohler@newt.com>
 
 	* mail/mh-comp.el, mail/mh-e.el, mail/mh-funcs.el,
--- a/lisp/wid-edit.el	Thu Oct 03 04:21:12 2002 +0000
+++ b/lisp/wid-edit.el	Thu Oct 03 13:46:25 2002 +0000
@@ -508,9 +508,10 @@
 					 :value-to-internal value)))
 
 (defun widget-default-get (widget)
-  "Extract the default value of WIDGET."
-  (or (widget-get widget :value)
-      (widget-apply widget :default-get)))
+  "Extract the default external value of WIDGET."
+  (widget-apply widget :value-to-external 
+		(or (widget-get widget :value)
+		    (widget-apply widget :default-get))))
 
 (defun widget-match-inline (widget vals)
   "In WIDGET, match the start of VALS."
@@ -688,7 +689,7 @@
 
 (defun widget-create-child (parent type)
   "Create widget of TYPE."
-  (let ((widget (copy-sequence type)))
+  (let ((widget (widget-copy type)))
     (widget-put widget :parent parent)
     (unless (widget-get widget :indent)
       (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
@@ -699,7 +700,7 @@
 
 (defun widget-create-child-value (parent type value)
   "Create widget of TYPE with value VALUE."
-  (let ((widget (copy-sequence type)))
+  (let ((widget (widget-copy type)))
     (widget-put widget :value (widget-apply widget :value-to-internal value))
     (widget-put widget :parent parent)
     (unless (widget-get widget :indent)
@@ -714,6 +715,10 @@
   "Delete WIDGET."
   (widget-apply widget :delete))
 
+(defun widget-copy (widget)
+  "Make a deep copy of WIDGET."
+  (widget-apply (copy-sequence widget) :copy))
+
 (defun widget-convert (type &rest args)
   "Convert TYPE to a widget without inserting it in the buffer.
 The optional ARGS are additional keyword arguments."
@@ -1271,6 +1276,11 @@
 	    found (widget-apply child :validate)))
     found))
 
+(defun widget-types-copy (widget)
+  "Copy :args as widget types in WIDGET."
+  (widget-put widget :args (mapcar 'widget-copy (widget-get widget :args)))
+  widget)
+
 ;; Made defsubst to speed up face editor creation.
 (defsubst widget-types-convert-widget (widget)
   "Convert :args as widget types in WIDGET."
@@ -1308,6 +1318,7 @@
   :button-face-get 'widget-default-button-face-get 
   :sample-face-get 'widget-default-sample-face-get 
   :delete 'widget-default-delete
+  :copy 'identity
   :value-set 'widget-default-value-set
   :value-inline 'widget-default-value-inline
   :default-get 'widget-default-default-get
@@ -1853,6 +1864,7 @@
 (define-widget 'menu-choice 'default
   "A menu of options."
   :convert-widget  'widget-types-convert-widget
+  :copy 'widget-types-copy
   :format "%[%t%]: %v"
   :case-fold t
   :tag "choice"
@@ -1982,9 +1994,7 @@
       (when this-explicit
 	(widget-put widget :explicit-choice current)
 	(widget-put widget :explicit-choice-value (widget-get widget :value)))
-      (widget-value-set
-       widget (widget-apply current
-			    :value-to-external (widget-default-get current)))
+      (widget-value-set widget (widget-default-get current))
       (widget-setup)
       (widget-apply widget :notify widget event)))
   (run-hook-with-args 'widget-edit-functions widget))
@@ -2091,6 +2101,7 @@
 (define-widget 'checklist 'default
   "A multiple choice widget."
   :convert-widget 'widget-types-convert-widget
+  :copy 'widget-types-copy
   :format "%v"
   :offset 4
   :entry-format "%b %v"
@@ -2268,6 +2279,7 @@
 (define-widget 'radio-button-choice 'default
   "Select one of multiple options."
   :convert-widget 'widget-types-convert-widget
+  :copy 'widget-types-copy
   :offset 4
   :format "%v"
   :entry-format "%b %v"
@@ -2456,6 +2468,7 @@
 (define-widget 'editable-list 'default
   "A variable list of widgets of the same type."
   :convert-widget 'widget-types-convert-widget
+  :copy 'widget-types-copy
   :offset 12
   :format "%v%i\n"
   :format-handler 'widget-editable-list-format-handler
@@ -2607,9 +2620,7 @@
 		    (setq child (widget-create-child-value
 				 widget type value))
 		  (setq child (widget-create-child-value
-			       widget type
-			       (widget-apply type :value-to-external
-					     (widget-default-get type))))))
+			       widget type (widget-default-get type)))))
 	       (t
 		(error "Unknown escape `%c'" escape)))))
      (widget-put widget
@@ -2631,6 +2642,7 @@
 (define-widget 'group 'default
   "A widget which groups other widgets inside."
   :convert-widget 'widget-types-convert-widget
+  :copy 'widget-types-copy
   :format "%v"
   :value-create 'widget-group-value-create
   :value-delete 'widget-children-value-delete
--- a/man/widget.texi	Thu Oct 03 04:21:12 2002 +0000
+++ b/man/widget.texi	Thu Oct 03 13:46:25 2002 +0000
@@ -1536,6 +1536,19 @@
 Initialize @code{:value} from @code{:args} in @var{widget}.
 @end defun
 
+@vindex copy@r{ keyword}
+@item :copy
+Function to deep copy a widget type.  It takes a shallow copy of the
+widget type as an argument (made by @code{copy-sequence}), and returns a
+deep copy.  The purpose of this is to avoid having different instances
+of combined widgets share nested attributes.
+
+The following predefined functions can be used here:
+
+@defun widget-types-copy widget
+Copy @code{:args} as widget types in @var{widget}.
+@end defun
+
 @vindex value-to-internal@r{ keyword}
 @item :value-to-internal
 Function to convert the value to the internal format.  The function