unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Re: Making a function than can only be used interactively
@ 2022-07-04 20:10 Christopher Dimech
  2022-07-04 20:35 ` Stefan Monnier
  0 siblings, 1 reply; 58+ messages in thread
From: Christopher Dimech @ 2022-07-04 20:10 UTC (permalink / raw)
  To: monnier, tsdh, help-gnu-emacs

Jul 4, 2022, 19:40 by monnier@iro.umontreal.ca:

>>>        Only after byte-compile of a file?
>>>        So there is no way to actually make a function interactive only?


>    Please define what it is you mean by "make a function interactive only".

>    Do you mean that it should be illegal to write code that calls the
>    function directly, so whoever writes it can be sued?
>    Would it be acceptable for someone to just think about writing such code
>    as long as they don't actually write it?

>    More seriously, what are you trying to gain by "mak[ing] a function
>    interactive only"? Usually, the reason why one might want to make
>    a function "interactive only" is that code that calls this function is
>    probably incorrect and would likely be served better by some
>    other function.

I could envisage a situation where someone wants to concentrate on the
interactive parts, if taking care of non-interactive use would make the
function difficult to maintain.  I am not sure that it will always be
because of bad design.

>    So the purpose is to help people write better code.
>    For this reason the declaration only has an effect in terms of
>    byte-compiler warnings: those who don't bother to byte-compile their
>    code presumably don't care about the quality of their code anyway.

>    Emacs doesn't offer any pre-defined way to really enforce that
>    a function is only used interactively, and in large parts this is
>    because, as a matter of design principle, Emacs makes no effort to stop
>    people from shooting themselves in the foot (instead, it tries to make
>    it easier for people not to shoot themselves in the foot).

>    Stefan

I also say that it would be better to have declarations that are somewhat
safer for the general elisp user as well.




^ permalink raw reply	[flat|nested] 58+ messages in thread
* Re: Making a function than can only be used interactively
@ 2022-07-04 23:42 Christopher Dimech
  0 siblings, 0 replies; 58+ messages in thread
From: Christopher Dimech @ 2022-07-04 23:42 UTC (permalink / raw)
  To: monnier, help-gnu-emacs

Jul 4, 2022, 22:35 by help-gnu-emacs@gnu.org:

>>>>>        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

Even with a concrete example, it is quite likely that we would not be able to capture
the way it was used.  Especially if one uses

(defun foo ()
(interactive)
(let ((a ...)
(b ...)
(c ...))
...))





^ permalink raw reply	[flat|nested] 58+ messages in thread
* 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; 58+ 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] 58+ messages in thread
* Re: Making a function than can only be used interactively
@ 2022-07-04 19:32 Christopher Dimech
  0 siblings, 0 replies; 58+ messages in thread
From: Christopher Dimech @ 2022-07-04 19:32 UTC (permalink / raw)
  To: monnier, tsdh, help-gnu-emacs

Jul 4, 2022, 13:21 by monnier@iro.umontreal.ca:

>        "interactive-only" should go far beyond a byte-compilation warning.
>
>        I suggest that "interactive-only" does actually make the function work
>       in an interactive-only way.
>
>>>
>>>    What would be the benefit?
>>>
>>>    Stefan

That it would do what it says.  Defining a function `interactive-only` would only work
interactively.  Currently, even with `interactive-only` the function would still run as
if `interactive-only` did not exist.  Currently it does not seem to me that `interactive-only`
has any operational effect.





^ permalink raw reply	[flat|nested] 58+ messages in thread
* Making a function than can only be used interactively
@ 2022-07-03 19:16 carlmarcos--- via Users list for the GNU Emacs text editor
  2022-07-03 19:28 ` Bruno Barbier
       [not found] ` <N64WnlX--3-2@missing-mail-id>
  0 siblings, 2 replies; 58+ messages in thread
From: carlmarcos--- via Users list for the GNU Emacs text editor @ 2022-07-03 19:16 UTC (permalink / raw)
  To: Help Gnu Emacs


Is it possible to make an interactive function than can only be used interactively?


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

end of thread, other threads:[~2022-07-10  4:33 UTC | newest]

Thread overview: 58+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-04 20:10 Making a function than can only be used interactively Christopher Dimech
2022-07-04 20:35 ` Stefan Monnier
2022-07-04 20:46   ` Christopher Dimech
2022-07-04 21:18     ` Stefan Monnier
2022-07-04 21:59       ` Christopher Dimech
2022-07-05 22:34       ` carlmarcos--- via Users list for the GNU Emacs text editor
  -- strict thread matches above, loose matches on Subject: below --
2022-07-04 23:42 Christopher Dimech
2022-07-04 21:07 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-04 23:33     ` Christopher Dimech
2022-07-04 19:32 Christopher Dimech
2022-07-03 19:16 carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-03 19:28 ` Bruno Barbier
     [not found] ` <N64WnlX--3-2@missing-mail-id>
2022-07-03 19:36   ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-03 19:53     ` Tassilo Horn
2022-07-03 20:17       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-04  4:51         ` Tassilo Horn
2022-07-05 23:13       ` Emanuel Berg
2022-07-03 20:14     ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-07-03 20:27       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-03 20:51       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-03 21:18         ` Stefan Monnier
2022-07-03 21:29       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-03 22:01         ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-07-03 22:45           ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-04  1:13             ` Stefan Monnier
     [not found]             ` <jwvczelllyq.fsf-monnier+emacs@gnu.org-N65lQ2m----2>
2022-07-04 10:36               ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-04 10:55                 ` Tassilo Horn
2022-07-04 11:43                   ` Christopher Dimech
2022-07-04 13:21                     ` Stefan Monnier
2022-07-04 14:08                       ` Robert Pluim
2022-07-04 21:40                       ` Christopher Dimech
2022-07-05 17:35                         ` Jean Louis
2022-07-04 19:17                   ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-04 19:40                     ` Stefan Monnier
2022-07-04 19:50                       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-04 20:45                         ` Stefan Monnier
2022-07-06  0:07                         ` Jean Louis
2022-07-06 20:00                           ` Christopher Dimech
2022-07-06 20:29                             ` Jean Louis
2022-07-07 11:03                               ` Christopher Dimech
2022-07-07 21:06                               ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-07 21:28                                 ` Emanuel Berg
2022-07-07 22:14                                   ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-08  3:40                                     ` Emanuel Berg
2022-07-08  6:08                                     ` Yuri Khan
2022-07-08  6:30                                       ` Emanuel Berg
2022-07-08  6:55                                         ` Yuri Khan
2022-07-08 11:44                                           ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-09  2:05                                             ` Emanuel Berg
2022-07-10  4:33                                             ` Emanuel Berg
2022-07-08 12:06                                           ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-08 12:11                                           ` Christopher Dimech
     [not found]                                           ` <N6Sh4jm--3-2@tutanota.com-N6ShCt5----2>
2022-07-08 12:18                                             ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-08 16:14                                           ` Christopher Dimech
2022-07-04  1:06     ` Po Lu

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).