unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Macro expansion containing ‘interactive’
@ 2021-08-19 10:30 Marcus Harnisch
  2021-08-19 13:24 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 10+ messages in thread
From: Marcus Harnisch @ 2021-08-19 10:30 UTC (permalink / raw)
  To: help-gnu-emacs

In an attempt to create a compatibility wrapper for the new optional 
mode list parameter of ‘interactive’ I am facing difficulties. The 
definition looks like this:

   (defmacro foo--interactive (&optional arg-descriptor)
     "Compatibility wrapper to support `interactive' with additional
   MODE parameter (Emacs 28+)."
     ;; https://lars.ingebrigtsen.no/2021/02/16/command-discovery-in-emacs/
     (if (and (featurep 'emacs)
              (>= emacs-major-version 28))
         `(interactive ,arg-descriptor foo-mode)
       `(interactive ,arg-descriptor)))

According to ‘(macroexpand '(foo--interactive "bar"))’ the expansion 
itself seems to work. However, I still see all of foo-mode's interactive 
functions being completed with ‘M-x foo TAB’ from buffer ‘*scratch*’ 
(which is not in ‘foo-mode’).

The Emacs process itself is started with:

   emacs -l foo-mode.el -Q

Any ideas how to debug/fix this?

Thanks,
Marcus




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

* Re: Macro expansion containing ‘interactive’
  2021-08-19 10:30 Macro expansion containing ‘interactive’ Marcus Harnisch
@ 2021-08-19 13:24 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2021-08-19 13:37   ` Lars Ingebrigtsen
  2021-08-19 14:51   ` Michael Heerdegen
  0 siblings, 2 replies; 10+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2021-08-19 13:24 UTC (permalink / raw)
  To: help-gnu-emacs

> In an attempt to create a compatibility wrapper for the new optional mode
> list parameter of ‘interactive’ I am facing difficulties. The definition
> looks like this:

`interactive` is not a special form.  Just like docstrings, it's a part
of the syntax of `lambda`, so you need to define a `foo-lambda` if you
want it to work reliably.


        Stefan




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

* Re: Macro expansion containing ‘interactive’
  2021-08-19 13:24 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2021-08-19 13:37   ` Lars Ingebrigtsen
  2021-08-19 15:42     ` [External] : " Drew Adams
  2021-08-24  8:52     ` Marcus Harnisch
  2021-08-19 14:51   ` Michael Heerdegen
  1 sibling, 2 replies; 10+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-19 13:37 UTC (permalink / raw)
  To: Stefan Monnier via Users list for the GNU Emacs text editor
  Cc: Stefan Monnier

Stefan Monnier via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

>> In an attempt to create a compatibility wrapper for the new optional mode
>> list parameter of ‘interactive’ I am facing difficulties. The definition
>> looks like this:
>
> `interactive` is not a special form.  Just like docstrings, it's a part
> of the syntax of `lambda`, so you need to define a `foo-lambda` if you
> want it to work reliably.

Yup.  When doing code that needs to be backwards-compatible here, it's
better to use a declare form instead:

(defun foo ()
  (declare (modes dired-mode))
  (interactive)
  ...)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



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

* Re: Macro expansion containing ‘interactive’
  2021-08-19 13:24 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2021-08-19 13:37   ` Lars Ingebrigtsen
@ 2021-08-19 14:51   ` Michael Heerdegen
  2021-08-19 15:14     ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 10+ messages in thread
From: Michael Heerdegen @ 2021-08-19 14:51 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

> `interactive` is not a special form.

C-h f says it is a special form.

Must be a special special form then ;-)

Michael.




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

* Re: Macro expansion containing ‘interactive’
  2021-08-19 14:51   ` Michael Heerdegen
@ 2021-08-19 15:14     ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2021-08-19 15:14 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen [2021-08-19 16:51:35] wrote:
> Stefan Monnier via Users list for the GNU Emacs text editor
> <help-gnu-emacs@gnu.org> writes:
>> `interactive` is not a special form.
> C-h f says it is a special form.
> Must be a special special form then ;-)

Well, it's *also* a special form, but one that just ignores its args and
returns nil.  It doesn't "store its arg in the surrounding function".


        Stefan




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

* RE: [External] : Re: Macro expansion containing ‘interactive’
  2021-08-19 13:37   ` Lars Ingebrigtsen
@ 2021-08-19 15:42     ` Drew Adams
  2021-08-20 21:51       ` Stefan Monnier
  2021-08-24  8:52     ` Marcus Harnisch
  1 sibling, 1 reply; 10+ messages in thread
From: Drew Adams @ 2021-08-19 15:42 UTC (permalink / raw)
  To: Lars Ingebrigtsen,
	Stefan Monnier via Users list for the GNU Emacs text editor
  Cc: Stefan Monnier

> >> In an attempt to create a compatibility wrapper for the new optional mode
> >> list parameter of ‘interactive’ I am facing difficulties. The definition
> >> looks like this:
> >
> > `interactive` is not a special form.  Just like docstrings, it's a part
> > of the syntax of `lambda`, so you need to define a `foo-lambda` if you
> > want it to work reliably.
> 
> Yup.  When doing code that needs to be backwards-compatible here, it's
> better to use a declare form instead:
> 
> (defun foo ()
>   (declare (modes dired-mode))
>   (interactive)
>   ...)

Are you sure that that modes `declare' form is
backward-compatible with, say, Emacs 20?  This
is the only definition of `declare' in Emacs 20,
and it's in `cl-macs.el' - i.e., a (primitive)
emulation of Common Lisp's `declare':

(defmacro declare (&rest specs)
  (if (cl-compiling-file)
      (while specs
	(if (listp cl-declare-stack)
          (cl-push (car specs)
        cl-declare-stack))
	(cl-do-proclaim (cl-pop specs) nil)))
  nil)

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

* Re: [External] : Re: Macro expansion containing ‘interactive’
  2021-08-19 15:42     ` [External] : " Drew Adams
@ 2021-08-20 21:51       ` Stefan Monnier
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2021-08-20 21:51 UTC (permalink / raw)
  To: Drew Adams
  Cc: Lars Ingebrigtsen,
	Stefan Monnier via Users list for the GNU Emacs text editor

> Are you sure that that modes `declare' form is
> backward-compatible with, say, Emacs 20?

`declare` was added in Emacs-21, so I don't think that would work.
But packages which care a bout Emacs<21 are pretty rare nowadays.


        Stefan




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

* Re: Macro expansion containing ‘interactive’
  2021-08-19 13:37   ` Lars Ingebrigtsen
  2021-08-19 15:42     ` [External] : " Drew Adams
@ 2021-08-24  8:52     ` Marcus Harnisch
  2021-08-25 11:06       ` Lars Ingebrigtsen
  1 sibling, 1 reply; 10+ messages in thread
From: Marcus Harnisch @ 2021-08-24  8:52 UTC (permalink / raw)
  To: help-gnu-emacs

Hi Lars

On 19/08/2021 15.37, Lars Ingebrigtsen wrote:
> Yup.  When doing code that needs to be backwards-compatible here, it's
> better to use a declare form instead:

Indeed, the code has to be backwards-compatible to some not-too-distant 
past.

> (defun foo ()
>    (declare (modes dired-mode))
>    (interactive)
>    ...)

This, literally? Doesn't seem to work here. Steps to reproduce:

1. Start ‘emacs -Q’

2. In ‘*scratch*’ buffer eval

    (defun foo ()
      (declare (modes dired-mode))
      (interactive)
      (message "foo"))

3. Type ‘M-x fo TAB’ and notice that ‘foo’ gets listed among all other 
completion candidates.

4. The ‘eww’ example from you blog doesn't seem to work for me either. 
Before loading ‘eww.el’, only autoloaded functions are listed, and after 
loading the command ‘M-x eww TAB’ lists all sorts of different commands 
while in ‘*scratch*’.

Did I miss anything? Any special completion config needed?

Cheers,
Marcus




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

* Re: Macro expansion containing ‘interactive’
  2021-08-24  8:52     ` Marcus Harnisch
@ 2021-08-25 11:06       ` Lars Ingebrigtsen
  2021-08-25 12:53         ` Marcus Harnisch
  0 siblings, 1 reply; 10+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-25 11:06 UTC (permalink / raw)
  To: Marcus Harnisch; +Cc: help-gnu-emacs

Marcus Harnisch <mh-gmane@online.de> writes:

> 3. Type ‘M-x fo TAB’ and notice that ‘foo’ gets listed among all other
> completion candidates.

You need

(setq read-extended-command-predicate 'command-completion-default-include-p)


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



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

* Re: Macro expansion containing ‘interactive’
  2021-08-25 11:06       ` Lars Ingebrigtsen
@ 2021-08-25 12:53         ` Marcus Harnisch
  0 siblings, 0 replies; 10+ messages in thread
From: Marcus Harnisch @ 2021-08-25 12:53 UTC (permalink / raw)
  To: help-gnu-emacs

On 25/08/2021 13.06, Lars Ingebrigtsen wrote:
> (setq read-extended-command-predicate 'command-completion-default-include-p)

That did it, thanks!




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

end of thread, other threads:[~2021-08-25 12:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-19 10:30 Macro expansion containing ‘interactive’ Marcus Harnisch
2021-08-19 13:24 ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-08-19 13:37   ` Lars Ingebrigtsen
2021-08-19 15:42     ` [External] : " Drew Adams
2021-08-20 21:51       ` Stefan Monnier
2021-08-24  8:52     ` Marcus Harnisch
2021-08-25 11:06       ` Lars Ingebrigtsen
2021-08-25 12:53         ` Marcus Harnisch
2021-08-19 14:51   ` Michael Heerdegen
2021-08-19 15:14     ` Stefan Monnier 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).