(interactive) arguments

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

(interactive) arguments

Jean-Christophe Helary-4
I'm looking for a way to add a default value to interactive by just using the "string" version:

(defun dailyTest (myDate)
  (interactive "ntoday: ")

I can do that with the "list" version:

(defun dailyIndex (myDate)
  (interactive (list
                (read-string "Date: " (format-time-string "%d")))))


Is that possible ?


Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune



Reply | Threaded
Open this post in threaded view
|

Re: (interactive) arguments

Stefan Monnier
> I'm looking for a way to add a default value to interactive by just
> using the "string" version:
[...]
> Is that possible ?

No: you have to use the "list" version (which is really the
"expression" version).


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: (interactive) arguments

Jean-Christophe Helary-4


> On Jan 2, 2020, at 0:51, Stefan Monnier <[hidden email]> wrote:
>
>> I'm looking for a way to add a default value to interactive by just
>> using the "string" version:
> [...]
>> Is that possible ?
>
> No: you have to use the "list" version (which is really the
> "expression" version).

Thank you Stefan !


Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune



Reply | Threaded
Open this post in threaded view
|

Re: (interactive) arguments

Jean-Christophe Helary-4

> On Jan 2, 2020, at 1:26, Jean-Christophe Helary <[hidden email]> wrote:
>
>> On Jan 2, 2020, at 0:51, Stefan Monnier <[hidden email]> wrote:
>>
>>> I'm looking for a way to add a default value to interactive by just
>>> using the "string" version:
>> [...]
>>> Is that possible ?
>>
>> No: you have to use the "list" version (which is really the
>> "expression" version).
>
> Thank you Stefan !

Now, when I use the "expression" version, it looks like the arguments are not assigned to variables as they are input, so for ex, I can't use a default value for the input based on the first input...

Is there a way around that ?

Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune



Reply | Threaded
Open this post in threaded view
|

Re: (interactive) arguments

Marcin Borkowski-3

On 2020-01-02, at 17:08, Jean-Christophe Helary <[hidden email]> wrote:

>> On Jan 2, 2020, at 1:26, Jean-Christophe Helary <[hidden email]> wrote:
>>
>>> On Jan 2, 2020, at 0:51, Stefan Monnier <[hidden email]> wrote:
>>>
>>>> I'm looking for a way to add a default value to interactive by just
>>>> using the "string" version:
>>> [...]
>>>> Is that possible ?
>>>
>>> No: you have to use the "list" version (which is really the
>>> "expression" version).
>>
>> Thank you Stefan !
>
> Now, when I use the "expression" version, it looks like the arguments are not assigned to variables as they are input, so for ex, I can't use a default value for the input based on the first input...
>
> Is there a way around that ?

Does this help?

http://mbork.pl/2015-09-12_A_trick_with_argument_for_interactive_call

Best,

--
Marcin Borkowski
http://mbork.pl

Reply | Threaded
Open this post in threaded view
|

Re: (interactive) arguments

Jean-Christophe Helary-4


> On Jan 3, 2020, at 1:30, Marcin Borkowski <[hidden email]> wrote:
>
>
> On 2020-01-02, at 17:08, Jean-Christophe Helary <[hidden email]> wrote:
>
>>> On Jan 2, 2020, at 1:26, Jean-Christophe Helary <[hidden email]> wrote:
>>>
>>>> On Jan 2, 2020, at 0:51, Stefan Monnier <[hidden email]> wrote:
>>>>
>>>>> I'm looking for a way to add a default value to interactive by just
>>>>> using the "string" version:
>>>> [...]
>>>>> Is that possible ?
>>>>
>>>> No: you have to use the "list" version (which is really the
>>>> "expression" version).
>>>
>>> Thank you Stefan !
>>
>> Now, when I use the "expression" version, it looks like the arguments are not assigned to variables as they are input, so for ex, I can't use a default value for the input based on the first input...
>>
>> Is there a way around that ?
>
> Does this help?
>
> http://mbork.pl/2015-09-12_A_trick_with_argument_for_interactive_call

Yes ! Excellent !

> Well, it is quite similar to the let=/=let* distinction. If only there were something like interactive*…

That's exactly what I was thinking !!! :)

Thank you.

Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune



Reply | Threaded
Open this post in threaded view
|

Re: (interactive) arguments

Jean-Christophe Helary-4
In reply to this post by Marcin Borkowski-3


> On Jan 3, 2020, at 1:30, Marcin Borkowski <[hidden email]> wrote:
>
>> Now, when I use the "expression" version, it looks like the arguments are not assigned to variables as they are input, so for ex, I can't use a default value for the input based on the first input...
>>
>> Is there a way around that ?
>
> Does this help?
>
> http://mbork.pl/2015-09-12_A_trick_with_argument_for_interactive_call


> The point is that the form right after interactive should return a list of two elements, and that is everything interactive cares for – what the (local) variables inside let* are called is none if its business.


That's really clever ! :)

> Now I’m quite sure that you could cook up a macro interactive*, which would wrap all this in a nice syntax. That, though, I will try some other day.

Have you tried ?


Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune



Reply | Threaded
Open this post in threaded view
|

Re: (interactive) arguments

Marcin Borkowski-3

On 2020-01-02, at 17:57, Jean-Christophe Helary <[hidden email]> wrote:

>> On Jan 3, 2020, at 1:30, Marcin Borkowski <[hidden email]> wrote:
>>
>>> Now, when I use the "expression" version, it looks like the arguments are not assigned to variables as they are input, so for ex, I can't use a default value for the input based on the first input...
>>>
>>> Is there a way around that ?
>>
>> Does this help?
>>
>> http://mbork.pl/2015-09-12_A_trick_with_argument_for_interactive_call
>
> →
>> The point is that the form right after interactive should return a list of two elements, and that is everything interactive cares for – what the (local) variables inside let* are called is none if its business.
>
>
> That's really clever ! :)
>
>> Now I’m quite sure that you could cook up a macro interactive*, which would wrap all this in a nice syntax. That, though, I will try some other day.
>
> Have you tried ?

Nope, and now that I know more about Elisp, I'm 99% sure it's
impossible, since `interactive' is not "evaluated" in any sense.  But
I'd like to hear from someone more competent.

Best,

--
Marcin Borkowski
http://mbork.pl

Reply | Threaded
Open this post in threaded view
|

Re: (interactive) arguments

Stefan Monnier
In reply to this post by Jean-Christophe Helary-4
> Now, when I use the "expression" version, it looks like the arguments are
> not assigned to variables as they are input, so for ex, I can't use
> a default value for the input based on the first input...

That was my whole point of describing it as "expression" rather than
"list": it is really an arbitrary Elisp *expression* whose evaluation
simply returns the list of arguments to pass to the function.

So it doesn't have to look like

    (list ...)

but can be anything else like

    (my-function-to-return-the-list-of-args)

or
    (let* ((x1 e1) (x2 e2) ...) (append e3 e4))
or
    ...


-- Stefan
   


Reply | Threaded
Open this post in threaded view
|

Re: (interactive) arguments

Jean-Christophe Helary-4


> On Jan 5, 2020, at 1:28, Stefan Monnier <[hidden email]> wrote:
>
>> Now, when I use the "expression" version, it looks like the arguments are
>> not assigned to variables as they are input, so for ex, I can't use
>> a default value for the input based on the first input...
>
> That was my whole point of describing it as "expression" rather than
> "list":

:)

> it is really an arbitrary Elisp *expression* whose evaluation
> simply returns the list of arguments to pass to the function.

Indeed, as the doc says. I just got stuck at the "should be a form that is evaluated to get a list of arguments to pass to the command".

>
> So it doesn't have to look like
>
>    (list ...)
>
> but can be anything else like
>
>    (my-function-to-return-the-list-of-args)
>
> or
>    (let* ((x1 e1) (x2 e2) ...) (append e3 e4))
> or
>    ...
>
>
> -- Stefan
>
>
>

Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune