unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#33170: 27.0.50; interactive spec with cl-defgeneric/method
@ 2018-10-26 22:19 Alex Branham
  2018-10-27  6:54 ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Alex Branham @ 2018-10-26 22:19 UTC (permalink / raw)
  To: 33170

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

I'm struggling to understand how to make functions defined with
cl-defgeneric interactive:

(require 'cl-lib)

(cl-defgeneric my/test ()
  (interactive)
  (message "generic"))

If you evaluate that you can do M-x my/test, as expected. However, as
soon as you evaluate this:

(cl-defgeneric my/test (&context (major-mode emacs-lisp-mode))
  (interactive)
  (message "method"))

M-x my/test no longer works.

Is this a bug or am I misunderstanding how this works?

Thanks,
Alex

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

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

* bug#33170: 27.0.50; interactive spec with cl-defgeneric/method
  2018-10-26 22:19 bug#33170: 27.0.50; interactive spec with cl-defgeneric/method Alex Branham
@ 2018-10-27  6:54 ` Eli Zaretskii
  2018-10-27 12:40   ` Alex Branham
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2018-10-27  6:54 UTC (permalink / raw)
  To: Alex Branham; +Cc: 33170

> From: Alex Branham <alex.branham@gmail.com>
> Date: Fri, 26 Oct 2018 17:19:44 -0500
> 
> I'm struggling to understand how to make functions defined with
> cl-defgeneric interactive:
> 
> (require 'cl-lib)
> 
> (cl-defgeneric my/test ()
>   (interactive)
>   (message "generic"))
> 
> If you evaluate that you can do M-x my/test, as expected. However, as
> soon as you evaluate this:
> 
> (cl-defgeneric my/test (&context (major-mode emacs-lisp-mode))
>   (interactive)
>   (message "method"))
> 
> M-x my/test no longer works.

'&context' is documented only as part of cl-defmethod, so why are you
trying to use it with cl-defgeneric?





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

* bug#33170: 27.0.50; interactive spec with cl-defgeneric/method
  2018-10-27  6:54 ` Eli Zaretskii
@ 2018-10-27 12:40   ` Alex Branham
  2018-10-27 14:47     ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Alex Branham @ 2018-10-27 12:40 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 33170

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


On Sat 27 Oct 2018 at 01:54, Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Alex Branham <alex.branham@gmail.com>
>> Date: Fri, 26 Oct 2018 17:19:44 -0500
>> 
>> I'm struggling to understand how to make functions defined with
>> cl-defgeneric interactive:
>> 
>> (require 'cl-lib)
>> 
>> (cl-defgeneric my/test ()
>>   (interactive)
>>   (message "generic"))
>> 
>> If you evaluate that you can do M-x my/test, as expected. However, as
>> soon as you evaluate this:
>> 
>> (cl-defgeneric my/test (&context (major-mode emacs-lisp-mode))
>>   (interactive)
>>   (message "method"))
>> 
>> M-x my/test no longer works.
>
> '&context' is documented only as part of cl-defmethod, so why are you
> trying to use it with cl-defgeneric?

Sorry, that was a typo. The same thing happens if you use defmethod:

(require 'cl-lib)

(cl-defgeneric my/test ()
  (interactive)
  (message "generic"))

here, M-x my/test works

(cl-defmethod my/test (&context (major-mode emacs-lisp-mode))
  (interactive)
  (message "method"))

Here, M-x my/test does not work.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

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

* bug#33170: 27.0.50; interactive spec with cl-defgeneric/method
  2018-10-27 12:40   ` Alex Branham
@ 2018-10-27 14:47     ` Eli Zaretskii
  2018-10-27 14:50       ` Alex Branham
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2018-10-27 14:47 UTC (permalink / raw)
  To: Alex Branham; +Cc: 33170

> From: Alex Branham <alex.branham@gmail.com>
> Cc: 33170@debbugs.gnu.org
> Date: Sat, 27 Oct 2018 07:40:11 -0500
> 
> (require 'cl-lib)
> 
> (cl-defgeneric my/test ()
>   (interactive)
>   (message "generic"))
> 
> here, M-x my/test works
> 
> (cl-defmethod my/test (&context (major-mode emacs-lisp-mode))
>   (interactive)
>   (message "method"))
> 
> Here, M-x my/test does not work.

But "M-: (my/test) RET" does.

I don't think generic functions can be interactive.  At least it is
not documented anywhere that they can be.





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

* bug#33170: 27.0.50; interactive spec with cl-defgeneric/method
  2018-10-27 14:47     ` Eli Zaretskii
@ 2018-10-27 14:50       ` Alex Branham
  2018-10-27 16:11         ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Alex Branham @ 2018-10-27 14:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 33170


On Sat 27 Oct 2018 at 09:47, Eli Zaretskii <eliz@gnu.org> wrote:

>> (require 'cl-lib)
>>
>> (cl-defgeneric my/test ()
>>   (interactive)
>>   (message "generic"))
>>
>> here, M-x my/test works
>>
>> (cl-defmethod my/test (&context (major-mode emacs-lisp-mode))
>>   (interactive)
>>   (message "method"))
>>
>> Here, M-x my/test does not work.
>
> But "M-: (my/test) RET" does.

Right. I'd like them to be interactive though so I can e.g. use them
from a keymap.

> I don't think generic functions can be interactive.  At least it is
> not documented anywhere that they can be.

Ah, that's unfortunate. Perhaps this limitation should be documented
somewhere?

Thanks,
Alex





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

* bug#33170: 27.0.50; interactive spec with cl-defgeneric/method
  2018-10-27 14:50       ` Alex Branham
@ 2018-10-27 16:11         ` Eli Zaretskii
  2018-10-27 16:14           ` Alex Branham
  2018-10-27 21:49           ` Stefan Monnier
  0 siblings, 2 replies; 13+ messages in thread
From: Eli Zaretskii @ 2018-10-27 16:11 UTC (permalink / raw)
  To: Alex Branham, Stefan Monnier; +Cc: 33170

> From: Alex Branham <alex.branham@gmail.com>
> Cc: 33170@debbugs.gnu.org
> Date: Sat, 27 Oct 2018 09:50:26 -0500
> 
> >> Here, M-x my/test does not work.
> >
> > But "M-: (my/test) RET" does.
> 
> Right. I'd like them to be interactive though so I can e.g. use them
> from a keymap.

You could have a single command that invoked my/test, I think that
would do what you want.

> > I don't think generic functions can be interactive.  At least it is
> > not documented anywhere that they can be.
> 
> Ah, that's unfortunate. Perhaps this limitation should be documented
> somewhere?

If Stefan (CC'ed) says it's a limitation and not a bug, I will
document it.





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

* bug#33170: 27.0.50; interactive spec with cl-defgeneric/method
  2018-10-27 16:11         ` Eli Zaretskii
@ 2018-10-27 16:14           ` Alex Branham
  2018-10-27 21:49           ` Stefan Monnier
  1 sibling, 0 replies; 13+ messages in thread
From: Alex Branham @ 2018-10-27 16:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 33170, Stefan Monnier

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


On Sat 27 Oct 2018 at 11:11, Eli Zaretskii <eliz@gnu.org> wrote:

> You could have a single command that invoked my/test, I think that
> would do what you want.

Ah, good idea. That does work, thanks!

Alex

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

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

* bug#33170: 27.0.50; interactive spec with cl-defgeneric/method
  2018-10-27 16:11         ` Eli Zaretskii
  2018-10-27 16:14           ` Alex Branham
@ 2018-10-27 21:49           ` Stefan Monnier
  2018-10-29 14:18             ` Alex Branham
  1 sibling, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2018-10-27 21:49 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 33170, Alex Branham

>> > I don't think generic functions can be interactive.  At least it is
>> > not documented anywhere that they can be.
>> Ah, that's unfortunate. Perhaps this limitation should be documented
>> somewhere?
> If Stefan (CC'ed) says it's a limitation and not a bug, I will
> document it.

AFAIC it's a limitation.  We could support interactive specs, but I'm
really not convinced it's worth the trouble.  If using 2 functions (one
generic and one interactive, which calls the generic one) is really
annoying for some reason, I guess you could use

    (put '<GENERIC> 'interactive-form <FORM>)

but I think this property should be deprecated, so don't tell anyone
(especially don't tell me) that I even mentioned it to you,


        Stefan





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

* bug#33170: 27.0.50; interactive spec with cl-defgeneric/method
  2018-10-27 21:49           ` Stefan Monnier
@ 2018-10-29 14:18             ` Alex Branham
  2018-10-30 10:15               ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Alex Branham @ 2018-10-29 14:18 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 33170

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


On Sat 27 Oct 2018 at 16:49, Stefan Monnier <monnier@IRO.UMontreal.CA> wrote:

> AFAIC it's a limitation.  We could support interactive specs, but I'm
> really not convinced it's worth the trouble.  If using 2 functions (one
> generic and one interactive, which calls the generic one) is really
> annoying for some reason, I guess you could use
>
>     (put '<GENERIC> 'interactive-form <FORM>)
>
> but I think this property should be deprecated, so don't tell anyone
> (especially don't tell me) that I even mentioned it to you,

Thanks for the response. Seems like the two-function solution is the way
to go I guess. I do think this should be documented as a limitation
somewhere though. Perhaps a note at the end of that section in the
manual along the lines:

Note that a current limitation of generic functions is that they may not
be interactive. The recommended way of working around this is to define
an interactive function that simply calls the generic function.

That's not strictly true of course since (cl-defgeneric foo ()
(interactive) (message "foo")) works just fine. It's adding methods that
seems to mess it up.

Alex

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

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

* bug#33170: 27.0.50; interactive spec with cl-defgeneric/method
  2018-10-29 14:18             ` Alex Branham
@ 2018-10-30 10:15               ` Eli Zaretskii
  2018-10-30 12:48                 ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2018-10-30 10:15 UTC (permalink / raw)
  To: Alex Branham; +Cc: 33170-done, monnier

> From: Alex Branham <alex.branham@gmail.com>
> Cc: Eli Zaretskii <eliz@gnu.org>, 33170@debbugs.gnu.org
> Date: Mon, 29 Oct 2018 09:18:53 -0500
> 
> On Sat 27 Oct 2018 at 16:49, Stefan Monnier <monnier@IRO.UMontreal.CA> wrote:
> 
> > AFAIC it's a limitation.  We could support interactive specs, but I'm
> > really not convinced it's worth the trouble.  If using 2 functions (one
> > generic and one interactive, which calls the generic one) is really
> > annoying for some reason, I guess you could use
> >
> >     (put '<GENERIC> 'interactive-form <FORM>)
> >
> > but I think this property should be deprecated, so don't tell anyone
> > (especially don't tell me) that I even mentioned it to you,
> 
> Thanks for the response. Seems like the two-function solution is the way
> to go I guess. I do think this should be documented as a limitation
> somewhere though.

Done.





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

* bug#33170: 27.0.50; interactive spec with cl-defgeneric/method
  2018-10-30 10:15               ` Eli Zaretskii
@ 2018-10-30 12:48                 ` Stefan Monnier
  2018-10-30 13:09                   ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2018-10-30 12:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Alex Branham, 33170-done

>> Thanks for the response. Seems like the two-function solution is the way
>> to go I guess. I do think this should be documented as a limitation
>> somewhere though.
> Done.

Should we add a warning for it?


        Stefan


diff --git a/lisp/emacs-lisp/cl-generic.el b/lisp/emacs-lisp/cl-generic.el
index fb4f3ab680..025653de70 100644
--- a/lisp/emacs-lisp/cl-generic.el
+++ b/lisp/emacs-lisp/cl-generic.el
@@ -355,6 +355,9 @@ cl-generic-define-context-rewriter
                                    . ,(lambda () spec-args))
                                  macroexpand-all-environment)))
       (require 'cl-lib)        ;Needed to expand `cl-flet' and `cl-function'.
+      (when (interactive-form (cadr fun))
+        (message "Interactive forms unsupported in generic functions: %S"
+                 (interactive-form (cadr fun))))
       ;; First macroexpand away the cl-function stuff (e.g. &key and
       ;; destructuring args, `declare' and whatnot).
       (pcase (macroexpand fun macroenv)





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

* bug#33170: 27.0.50; interactive spec with cl-defgeneric/method
  2018-10-30 12:48                 ` Stefan Monnier
@ 2018-10-30 13:09                   ` Eli Zaretskii
  2018-10-31 14:49                     ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2018-10-30 13:09 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: alex.branham, 33170-done

> From: Stefan Monnier <monnier@IRO.UMontreal.CA>
> Cc: Alex Branham <alex.branham@gmail.com>, 33170-done@debbugs.gnu.org
> Date: Tue, 30 Oct 2018 08:48:49 -0400
> 
> >> Thanks for the response. Seems like the two-function solution is the way
> >> to go I guess. I do think this should be documented as a limitation
> >> somewhere though.
> > Done.
> 
> Should we add a warning for it?

No objections from me.





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

* bug#33170: 27.0.50; interactive spec with cl-defgeneric/method
  2018-10-30 13:09                   ` Eli Zaretskii
@ 2018-10-31 14:49                     ` Stefan Monnier
  0 siblings, 0 replies; 13+ messages in thread
From: Stefan Monnier @ 2018-10-31 14:49 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: alex.branham, 33170-done

>> Should we add a warning for it?
> No objections from me.

Done in `master`.


        Stefan





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

end of thread, other threads:[~2018-10-31 14:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-26 22:19 bug#33170: 27.0.50; interactive spec with cl-defgeneric/method Alex Branham
2018-10-27  6:54 ` Eli Zaretskii
2018-10-27 12:40   ` Alex Branham
2018-10-27 14:47     ` Eli Zaretskii
2018-10-27 14:50       ` Alex Branham
2018-10-27 16:11         ` Eli Zaretskii
2018-10-27 16:14           ` Alex Branham
2018-10-27 21:49           ` Stefan Monnier
2018-10-29 14:18             ` Alex Branham
2018-10-30 10:15               ` Eli Zaretskii
2018-10-30 12:48                 ` Stefan Monnier
2018-10-30 13:09                   ` Eli Zaretskii
2018-10-31 14:49                     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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