unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* editable-list widgets: how to create one child automatically
@ 2024-03-13  7:23 Michael Heerdegen
  2024-03-13 10:41 ` Mauro Aranda
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Heerdegen @ 2024-03-13  7:23 UTC (permalink / raw)
  To: Emacs mailing list; +Cc: Mauro Aranda

Hello,

and sorry to Mauro, I CC'd you directly because I know you are a widget
expert, and there are only few of them.

I often want an editable-list widget to be created along with one child
instead of none.  Zero childs often has no useful meaning in the context
of the widget, and starting with one child already created when the
editable-list widget gets inserted is often is good choice and nicer to
the user.

Is there some tool designed for this purpose I have missed?  So far the
only way I know of is to specify a widget property

#+begin_src emacs-lisp
  :value-create
  (lambda (w)
    (unless (widget-get w :value)
      (widget-put w :value (list my-first-default)))
    (widget-editable-list-value-create w))
#+end_src

Is there a better way?

TIA,

Michael.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: editable-list widgets: how to create one child automatically
  2024-03-13  7:23 editable-list widgets: how to create one child automatically Michael Heerdegen
@ 2024-03-13 10:41 ` Mauro Aranda
  2024-03-14  1:58   ` Michael Heerdegen via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 5+ messages in thread
From: Mauro Aranda @ 2024-03-13 10:41 UTC (permalink / raw)
  To: help-gnu-emacs

On 13/3/24 04:23, Michael Heerdegen wrote:
 > Hello,
 >
 > and sorry to Mauro, I CC'd you directly because I know you are a widget
 > expert, and there are only few of them.

Hi Michael.  I appreciate you CCing me, so no need to feel sorry.

 > Is there some tool designed for this purpose I have missed?  So far the
 > only way I know of is to specify a widget property
 >
 > #+begin_src emacs-lisp
 >   :value-create
 >   (lambda (w)
 >     (unless (widget-get w :value)
 >       (widget-put w :value (list my-first-default)))
 >     (widget-editable-list-value-create w))
 > #+end_src
 >
 > Is there a better way?
 >

You should be able to specify the :value property directly, rather than
overriding :value-create.  Something like:

(widget-create 'editable-list
                :value (list my-first-default)
                ;; Change according to the child type.
                '(editable-field))

Does that not do what you want?





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: editable-list widgets: how to create one child automatically
  2024-03-13 10:41 ` Mauro Aranda
@ 2024-03-14  1:58   ` Michael Heerdegen via Users list for the GNU Emacs text editor
  2024-03-14 11:19     ` Mauro Aranda
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Heerdegen via Users list for the GNU Emacs text editor @ 2024-03-14  1:58 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 970 bytes --]

Mauro Aranda <maurooaranda@gmail.com> writes:

> (widget-create 'editable-list
>                :value (list my-first-default)
>                ;; Change according to the child type.
>                '(editable-field))
>
> Does that not do what you want?

I think I can't use this: I don't create an ad-hoc widget, I need an
`define-widget' expression to define the widget to behave accordingly
when created.

And the widget this is about is a part of a group widget definition so
there will never be an explicit `widget-create' call by me, the widget
will always be created implicitly by the parent.

And in this definition a :value spec is more or less ignored - in my
tests that child widget will always be created with a nil widget value.

I am attaching the code in question so that you don't have to guess -
you can find the relevant part by searching for the comment

  ;; Is there a better approach, Mauro?

or simply just your name.


Thanks so far,

Michael.


[-- Attachment #2: find-cmd-widget.el.zip --]
[-- Type: application/zip, Size: 12562 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: editable-list widgets: how to create one child automatically
  2024-03-14  1:58   ` Michael Heerdegen via Users list for the GNU Emacs text editor
@ 2024-03-14 11:19     ` Mauro Aranda
  2024-03-15 12:53       ` Michael Heerdegen via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 5+ messages in thread
From: Mauro Aranda @ 2024-03-14 11:19 UTC (permalink / raw)
  To: Michael Heerdegen, help-gnu-emacs

On 13/3/24 22:58, Michael Heerdegen via Users list for the GNU Emacs 
text editor wrote:
 > Mauro Aranda <maurooaranda@gmail.com> writes:
 >
 >> (widget-create 'editable-list
 >>                 :value (list my-first-default)
 >>                 ;; Change according to the child type.
 >>                 '(editable-field))
 >>
 >> Does that not do what you want?
 >
 > I think I can't use this: I don't create an ad-hoc widget, I need an
 > `define-widget' expression to define the widget to behave accordingly
 > when created.

OK, but still the :value should be respected when given inside a
define-widget.

 > And the widget this is about is a part of a group widget definition so
 > there will never be an explicit `widget-create' call by me, the widget
 > will always be created implicitly by the parent.
 >
 > And in this definition a :value spec is more or less ignored - in my
 > tests that child widget will always be created with a nil widget value.

This shouldn't happen.  But what I think is happening is that when
you're creating the find widget, I guess when funcalling this:

(defvar find-cmd-widget-default-start-fun
   (lambda ()
     (setq-local find-cmd-widget-main-widget (widget-create 'find))))

The find widget gets created with a nil value, which, when trying to
match against its children values, won't match when the editable-list
has a different value, like (list default-directory)

Because of that, the code understands that it should override the :value
property of the editable-list to a nil value, hence the empty
editable-list.

So I think a better way is to provide a matching value for the find
widget that will allow it to create its children with their default
values.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: editable-list widgets: how to create one child automatically
  2024-03-14 11:19     ` Mauro Aranda
@ 2024-03-15 12:53       ` Michael Heerdegen via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Heerdegen via Users list for the GNU Emacs text editor @ 2024-03-15 12:53 UTC (permalink / raw)
  To: help-gnu-emacs

Mauro Aranda <maurooaranda@gmail.com> writes:

> So I think a better way is to provide a matching value for the find
> widget that will allow it to create its children with their default
> values.

Thank you very much.  I think your analysis is correct.

But this approach sounds inconvenient: I would have to maintain default
values of inner widgets in separate code locations (right?), and I would
also have to remember that I need to update the structure of the default
value of the "big" widget to be in sync with the structure of the widget
definition, should I once change it.

So, that the outer widget forces a value that I did not even specify
explicitly does not seem so useful to me.

Michael.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-15 12:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-13  7:23 editable-list widgets: how to create one child automatically Michael Heerdegen
2024-03-13 10:41 ` Mauro Aranda
2024-03-14  1:58   ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-03-14 11:19     ` Mauro Aranda
2024-03-15 12:53       ` Michael Heerdegen via Users list for the GNU Emacs text editor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).