* Re: Making a function than can only be used interactively
@ 2022-07-04 21:07 Christopher Dimech
2022-07-04 21:45 ` Stefan Monnier
0 siblings, 1 reply; 10+ messages in thread
From: Christopher Dimech @ 2022-07-04 21:07 UTC (permalink / raw)
To: monnier, tsdh, help-gnu-emacs
> Jul 4, 2022, 20:45 by monnier@iro.umontreal.ca:
>>>>> More seriously, what are you trying to gain by "mak[ing] a function
>>>>> interactive only"?
>>> For instance, writing an interactive wrapper function calling a non-interactive
>>> mother function.
> A common enough case, which you can do just fine without having to
> prevent non-interactive calls to the interactive wrapper.
>>> Technically, you can use `completing-read` and `read-from-minibuffer` if you'd also
>>> like to set values interactively, while calling the function non-interactively.
> You mean you can turn
> (defun foo (a b c)
> (interactive ...)
> ...)
> into
> (defun foo ()
> (interactive)
> (let ((a ...)
> (b ...)
> (c ...))
> ...))
Yes, that is what I had in mind.
> Indeed. It's usually discouraged because it's incompatible with
> non-interactive uses of the function, but in the case under discussion
> you don't care about that because you already have another function to
> use for non-interactive calls.
It is indeed incompatible with non-interactive use. A thing that can be done
is fire the warning even when Lisp Code in not transformed into byte-code.
Although byte compilation in recommended, I wonder how often people actually
byte-compile every file. Byte compiling will often tell you errors or warning
in your elisp code that you normally wouldn't know, but I think that running
an interactive-only function non-interactively is serious enough to insert the
warning in the warnings buffer anyway.
>>> I am not sure if in practice that is ever desired.
> It's done occasionally, typically in cases where it's difficult to
> cleanly separate the part of the code that prompts the user from the
> part that actually performs the desired operation.
> Stefan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Making a function than can only be used interactively
2022-07-04 21:07 Making a function than can only be used interactively Christopher Dimech
@ 2022-07-04 21:45 ` Stefan Monnier
2022-07-04 22:05 ` Christopher Dimech
0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2022-07-04 21:45 UTC (permalink / raw)
To: Christopher Dimech; +Cc: tsdh, help-gnu-emacs
>> Indeed. It's usually discouraged because it's incompatible with
>> non-interactive uses of the function, but in the case under discussion
>> you don't care about that because you already have another function to
>> use for non-interactive calls.
> It is indeed incompatible with non-interactive use. A thing that can be done
> is fire the warning even when Lisp Code in not transformed into byte-code.
You could emit the warning/error during macro-expansion, indeed.
Something like:
(defun foo (a b c)
(interactive ...)
(declare (compiler-macro (lambda (_) (error "Called non-interactively"))))
...)
Not sure what's the benefit, still.
> Although byte compilation in recommended, I wonder how often people actually
> byte-compile every file.
`flymake-mode` will run the compiler for you to get those warnings right
while you're writing the code. If people don't see the warning because
they don't compile their files, then let's fix it by trying to convince
them to compile their files, which will come with a lot of other benefits.
> Byte compiling will often tell you errors or warning in your elisp
> code that you normally wouldn't know, but I think that running an
> interactive-only function non-interactively is serious enough to
> insert the warning in the warnings buffer anyway.
Usually calling an interactive-only function non-interactively is not
serious *at all* and very often it's The Right Thing to do.
Stefan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Making a function than can only be used interactively
2022-07-04 21:45 ` Stefan Monnier
@ 2022-07-04 22:05 ` Christopher Dimech
2022-07-04 22:35 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-07-04 23:33 ` Christopher Dimech
0 siblings, 2 replies; 10+ messages in thread
From: Christopher Dimech @ 2022-07-04 22:05 UTC (permalink / raw)
To: Stefan Monnier; +Cc: tsdh, help-gnu-emacs
> Sent: Tuesday, July 05, 2022 at 9:45 AM
> From: "Stefan Monnier" <monnier@iro.umontreal.ca>
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: tsdh@gnu.org, help-gnu-emacs@gnu.org
> Subject: Re: Making a function than can only be used interactively
>
> >> Indeed. It's usually discouraged because it's incompatible with
> >> non-interactive uses of the function, but in the case under discussion
> >> you don't care about that because you already have another function to
> >> use for non-interactive calls.
> > It is indeed incompatible with non-interactive use. A thing that can be done
> > is fire the warning even when Lisp Code in not transformed into byte-code.
>
> You could emit the warning/error during macro-expansion, indeed.
> Something like:
>
> (defun foo (a b c)
> (interactive ...)
> (declare (compiler-macro (lambda (_) (error "Called non-interactively"))))
> ...)
>
> Not sure what's the benefit, still.
>
> > Although byte compilation in recommended, I wonder how often people actually
> > byte-compile every file.
>
> `flymake-mode` will run the compiler for you to get those warnings right
> while you're writing the code. If people don't see the warning because
> they don't compile their files, then let's fix it by trying to convince
> them to compile their files, which will come with a lot of other benefits.
>
> > Byte compiling will often tell you errors or warning in your elisp
> > code that you normally wouldn't know, but I think that running an
> > interactive-only function non-interactively is serious enough to
> > insert the warning in the warnings buffer anyway.
>
> Usually calling an interactive-only function non-interactively is not
> serious *at all* and very often it's The Right Thing to do.
>
> Stefan
Depends whether the person coding that function thinks it is. What can he
do then? Issue warning as you suggested with `declare`?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Making a function than can only be used interactively
2022-07-04 22:05 ` Christopher Dimech
@ 2022-07-04 22:35 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-07-05 14:02 ` [External] : " Drew Adams
2022-07-04 23:33 ` Christopher Dimech
1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2022-07-04 22:35 UTC (permalink / raw)
To: help-gnu-emacs
> Depends whether the person coding that function thinks it is.
> What can he do then? Issue warning as you suggested with `declare`?
I don't think we can answer this in the abstract. So, we'd first need
to have some concrete scenario before we can start discussing it.
Stefan
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [External] : Re: Making a function than can only be used interactively
2022-07-04 22:35 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2022-07-05 14:02 ` Drew Adams
2022-07-05 15:35 ` RE: [External] : " Christopher Dimech
0 siblings, 1 reply; 10+ messages in thread
From: Drew Adams @ 2022-07-05 14:02 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'
[-- Attachment #1: Type: text/plain, Size: 1003 bytes --]
> > Depends whether the person coding that function thinks it is.
> > What can he do then? Issue warning as you suggested with `declare`?
>
> I don't think we can answer this in the abstract. So, we'd first need
> to have some concrete scenario before we can start discussing it.
Yup. Has any concrete description been presented
in this thread that makes clear what the real
problem to be solved is - the use case behind the
question?
I've only browsed the thread, so apologies if some
actual problem (and its "why") has been specified.
From just perusing, I haven't noticed any.
As I guessed before, I'm still guessing (so far):
there's an X-Y problem under the covers here
somewhere...)
What is it that OP is _really_ trying to do/solve?
I'm guessing that's behind an inability by folks
who've coded zillions of functions to understand
what's being asked/requested. What's the problem?
https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem
[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 14371 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: RE: [External] : Making a function than can only be used interactively
2022-07-05 14:02 ` [External] : " Drew Adams
@ 2022-07-05 15:35 ` Christopher Dimech
2022-07-05 16:34 ` Drew Adams
0 siblings, 1 reply; 10+ messages in thread
From: Christopher Dimech @ 2022-07-05 15:35 UTC (permalink / raw)
To: Drew Adams
Cc: Stefan Monnier, 'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'
> Sent: Wednesday, July 06, 2022 at 2:02 AM
> From: "Drew Adams" <drew.adams@oracle.com>
> To: "Stefan Monnier" <monnier@iro.umontreal.ca>
> Cc: "'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'" <help-gnu-emacs@gnu.org>
> Subject: RE: [External] : Re: Making a function than can only be used interactively
>
> > > Depends whether the person coding that function thinks it is.
> > > What can he do then? Issue warning as you suggested with `declare`?
> >
> > I don't think we can answer this in the abstract. So, we'd first need
> > to have some concrete scenario before we can start discussing it.
>
> Yup. Has any concrete description been presented
> in this thread that makes clear what the real
> problem to be solved is - the use case behind the
> question?
The filling of arguments could be difficult if a sequence of interactive
prompt depend on previous values.
One thing that has been discussed is the following
(defun foo ()
(interactive)
(let ((a ...)
(b ...)
(c ...))
...))
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: RE: [External] : Making a function than can only be used interactively
2022-07-05 15:35 ` RE: [External] : " Christopher Dimech
@ 2022-07-05 16:34 ` Drew Adams
[not found] ` <trinity-568779dc-3120-4001-a48b-df09d38f19a1-1657055684424@3c-app-mailcom-bs14>
0 siblings, 1 reply; 10+ messages in thread
From: Drew Adams @ 2022-07-05 16:34 UTC (permalink / raw)
To: Christopher Dimech
Cc: Stefan Monnier, 'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'
> > Has any concrete description been presented
> > in this thread that makes clear what the real
> > problem to be solved is - the use case behind
> > the question?
>
> The filling of arguments could be difficult
> if a sequence of interactive prompt depend
> on previous values.
Hard to guess what you mean. Example?
What's to prevent someone from calling the
function (whatever it is) with appropriate
arguments, whether or not some of them depend
on others?
> One thing that has been discussed is the following
> (defun foo ()
> (interactive)
> (let ((a ...)
> (b ...)
> (c ...))
> ...))
Didn't Stefan show that only to indicate that
you can prompt for values in the body of a
function, instead of (or in addition to) doing
so in an `interactive' spec?
IOW, presumably he was suggesting that some of
the "..." to provide values for a, b, and c
could come from prompting a user - IOW, making
the function interactive regardless of how
it's called.
I don't see what that has to do with any
problem of "filling arguments" when calling
from Lisp.
Sorry, but so far I'm not grasping what the
problem is - what OP is really trying to do.
But again, I only skimmed the thread. If you
think the question / use case is clear to
others then please ignore my feedback.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Making a function than can only be used interactively
2022-07-04 22:05 ` Christopher Dimech
2022-07-04 22:35 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2022-07-04 23:33 ` Christopher Dimech
1 sibling, 0 replies; 10+ messages in thread
From: Christopher Dimech @ 2022-07-04 23:33 UTC (permalink / raw)
To: Christopher Dimech; +Cc: Stefan Monnier, tsdh, help-gnu-emacs
> Sent: Tuesday, July 05, 2022 at 10:05 AM
> From: "Christopher Dimech" <dimech@gmx.com>
> To: "Stefan Monnier" <monnier@iro.umontreal.ca>
> Cc: tsdh@gnu.org, help-gnu-emacs@gnu.org
> Subject: Re: Making a function than can only be used interactively
>
>
>
> > Sent: Tuesday, July 05, 2022 at 9:45 AM
> > From: "Stefan Monnier" <monnier@iro.umontreal.ca>
> > To: "Christopher Dimech" <dimech@gmx.com>
> > Cc: tsdh@gnu.org, help-gnu-emacs@gnu.org
> > Subject: Re: Making a function than can only be used interactively
> >
> > >> Indeed. It's usually discouraged because it's incompatible with
> > >> non-interactive uses of the function, but in the case under discussion
> > >> you don't care about that because you already have another function to
> > >> use for non-interactive calls.
> > > It is indeed incompatible with non-interactive use. A thing that can be done
> > > is fire the warning even when Lisp Code in not transformed into byte-code.
> >
> > You could emit the warning/error during macro-expansion, indeed.
> > Something like:
> >
> > (defun foo (a b c)
> > (interactive ...)
> > (declare (compiler-macro (lambda (_) (error "Called non-interactively"))))
> > ...)
> >
> > Not sure what's the benefit, still.
I am not confident the declare command will always work.
Not for
(defun foo ()
(interactive)
(let ((a ...)
(b ...)
(c ...))
...))
> > > Although byte compilation in recommended, I wonder how often people actually
> > > byte-compile every file.
> >
> > `flymake-mode` will run the compiler for you to get those warnings right
> > while you're writing the code. If people don't see the warning because
> > they don't compile their files, then let's fix it by trying to convince
> > them to compile their files, which will come with a lot of other benefits.
> >
> > > Byte compiling will often tell you errors or warning in your elisp
> > > code that you normally wouldn't know, but I think that running an
> > > interactive-only function non-interactively is serious enough to
> > > insert the warning in the warnings buffer anyway.
> >
> > Usually calling an interactive-only function non-interactively is not
> > serious *at all* and very often it's The Right Thing to do.
> >
> > Stefan
>
> Depends whether the person coding that function thinks it is. What can he
> do then? Issue warning as you suggested with `declare`?
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-07-05 23:05 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-04 21:07 Making a function than can only be used interactively Christopher Dimech
2022-07-04 21:45 ` Stefan Monnier
2022-07-04 22:05 ` Christopher Dimech
2022-07-04 22:35 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-07-05 14:02 ` [External] : " Drew Adams
2022-07-05 15:35 ` RE: [External] : " Christopher Dimech
2022-07-05 16:34 ` Drew Adams
[not found] ` <trinity-568779dc-3120-4001-a48b-df09d38f19a1-1657055684424@3c-app-mailcom-bs14>
2022-07-05 22:40 ` FW: " Drew Adams
2022-07-05 23:05 ` Christopher Dimech
2022-07-04 23:33 ` Christopher Dimech
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).