unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* question about macro `minibuffer-with-setup-hook', byte-compilation
@ 2012-10-05 18:35 Drew Adams
  2012-10-05 19:03 ` Stefan Monnier
  2012-10-06  7:12 ` Stephen J. Turnbull
  0 siblings, 2 replies; 8+ messages in thread
From: Drew Adams @ 2012-10-05 18:35 UTC (permalink / raw)
  To: emacs-devel

In a file foo.el I define function foo, wrapping the defun in
(when (> emacs-major-version 22)...)

Function foo uses `minibuffer-with-setup-hook' which is a macro defined in
files.el.  (The code for foo is similar to that for `read-file-name-default',
and it is used similarly.)

I byte-compile foo.el in an Emacs version that does not have macro
`minibuffer-with-setup-hook', so the byte code contains a call to
`minibuffer-with-setup-hook' instead of the macro expansion.

In Emacs versions that define `minibuffer-with-setup-hook', the byte-compiled
code does not work.

File files.elc is preloaded, and it contains a defalias for
`minibuffer-with-setup-hook'.  And (symbol-function 'minibuffer-setup-hook)
shows its usual, byte-compiled definition.

But when foo is invoked an error is raised saying that `minibuffer-setup-hook'
is an invalid function.

If I load source file foo.el instead of foo.elc, there is of course no problem.
Likewise if I load source file files.el.

How to handle this?  What am I missing?  Thx.

---
Debugger entered--Lisp error: (invalid-function minibuffer-with-setup-hook)
  minibuffer-with-setup-hook(#[nil "..." [dir default-directory insdef
    minibuffer-default minibuffer-local-filename-syntax make-local-variable
    minibuffer-default-add-function #[nil "..." [dir initial window-buffer
    minibuffer-selected-window read-file-name--defaults] 3] boundp
    set-syntax-table] 2] "c:/dir/fooooo.el")
  icicle-foo("File or directory: " nil "c:/dir/toto"
    confirm-after-completion nil nil)
  read-file-name("File or directory: " nil "c:/dir/toto"
    confirm-after-completion nil nil)




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

* Re: question about macro `minibuffer-with-setup-hook', byte-compilation
  2012-10-05 18:35 question about macro `minibuffer-with-setup-hook', byte-compilation Drew Adams
@ 2012-10-05 19:03 ` Stefan Monnier
  2012-10-05 20:02   ` Drew Adams
  2012-10-06  7:12 ` Stephen J. Turnbull
  1 sibling, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2012-10-05 19:03 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel

> I byte-compile foo.el in an Emacs version that does not have macro
> `minibuffer-with-setup-hook',

So you get a .elc file that doesn't work.
Don't do that.  It's true of *all* macros, because they are run during
compilation, so if they're not present during compilation you're screwed.


        Stefan



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

* RE: question about macro `minibuffer-with-setup-hook', byte-compilation
  2012-10-05 19:03 ` Stefan Monnier
@ 2012-10-05 20:02   ` Drew Adams
  2012-10-05 20:21     ` Stefan Monnier
  0 siblings, 1 reply; 8+ messages in thread
From: Drew Adams @ 2012-10-05 20:02 UTC (permalink / raw)
  To: 'Stefan Monnier'; +Cc: emacs-devel

> > I byte-compile foo.el in an Emacs version that does not have macro
> > `minibuffer-with-setup-hook',
> 
> So you get a .elc file that doesn't work.
> Don't do that.  It's true of *all* macros, because they are run during
> compilation, so if they're not present during compilation 
> you're screwed.

Could you please explain what I am seeing, e.g., that the macro is defined at
runtime and the byte-code invokes it at runtime, but an invalid function error
is raised.  Thx.




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

* Re: question about macro `minibuffer-with-setup-hook', byte-compilation
  2012-10-05 20:02   ` Drew Adams
@ 2012-10-05 20:21     ` Stefan Monnier
  2012-10-05 20:33       ` Drew Adams
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2012-10-05 20:21 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel

>> > I byte-compile foo.el in an Emacs version that does not have macro
>> > `minibuffer-with-setup-hook',
>> So you get a .elc file that doesn't work.
>> Don't do that.  It's true of *all* macros, because they are run during
>> compilation, so if they're not present during compilation 
>> you're screwed.
> Could you please explain what I am seeing, e.g., that the macro is
> defined at runtime and the byte-code invokes it at runtime, but an
> invalid function error is raised.  Thx.

The byte-compiler issued a warning like "function
minibuffer-with-setup-hook is not known to be defined".  In reality what
it means is "minibuffer-with-setup-hook is not defined as a function nor
as a macro, so I'll assume it's a function that will be suitably defined
at run-time, since if it were a macro I'd need the macro's definition to
be able to compile the code".


        Stefan



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

* RE: question about macro `minibuffer-with-setup-hook', byte-compilation
  2012-10-05 20:21     ` Stefan Monnier
@ 2012-10-05 20:33       ` Drew Adams
  2012-10-05 20:49         ` Andreas Schwab
  0 siblings, 1 reply; 8+ messages in thread
From: Drew Adams @ 2012-10-05 20:33 UTC (permalink / raw)
  To: 'Stefan Monnier'; +Cc: emacs-devel

> > Could you please explain what I am seeing, e.g., that the macro is
> > defined at runtime and the byte-code invokes it at runtime, but an
> > invalid function error is raised.  Thx.
> 
> The byte-compiler issued a warning like "function
> minibuffer-with-setup-hook is not known to be defined".  In 
> reality what it means is "minibuffer-with-setup-hook is not
> defined as a function nor as a macro, so I'll assume it's a
> function that will be suitably defined at run-time, since
> if it were a macro I'd need the macro's definition to
> be able to compile the code".

I understand that.  I realize that the macro cannot be expanded into byte code
in this context.  What I think I see in the byte code is, as you seem to
confirm, a runtime invocation of `minibuffer-with-setup-hook'.

What is not clear to me is why it is a problem in this context to expect the
macro to exist at runtime (since it does, as shown by `symbol-function').

Doesn't the (old-version) byte code simply tell the runtime invocation of the
command to look up the function definition of `minibuffer-with-setup-hook' and
use that?  And if so, why wouldn't that cause the lookup to find that it is a
macro and DTRT (expand it at runtime).

I appreciate your explanation.




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

* Re: question about macro `minibuffer-with-setup-hook', byte-compilation
  2012-10-05 20:33       ` Drew Adams
@ 2012-10-05 20:49         ` Andreas Schwab
  2012-10-05 21:02           ` Drew Adams
  0 siblings, 1 reply; 8+ messages in thread
From: Andreas Schwab @ 2012-10-05 20:49 UTC (permalink / raw)
  To: Drew Adams; +Cc: 'Stefan Monnier', emacs-devel

"Drew Adams" <drew.adams@oracle.com> writes:

> And if so, why wouldn't that cause the lookup to find that it is a
> macro and DTRT (expand it at runtime).

That is impossible, since the unevaluated arguments are lost.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



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

* RE: question about macro `minibuffer-with-setup-hook', byte-compilation
  2012-10-05 20:49         ` Andreas Schwab
@ 2012-10-05 21:02           ` Drew Adams
  0 siblings, 0 replies; 8+ messages in thread
From: Drew Adams @ 2012-10-05 21:02 UTC (permalink / raw)
  To: 'Andreas Schwab'; +Cc: 'Stefan Monnier', emacs-devel

> > And if so, why wouldn't that cause the lookup to find that it is a
> > macro and DTRT (expand it at runtime).
> 
> That is impossible, since the unevaluated arguments are lost.

I see.  Thank you.




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

* question about macro `minibuffer-with-setup-hook', byte-compilation
  2012-10-05 18:35 question about macro `minibuffer-with-setup-hook', byte-compilation Drew Adams
  2012-10-05 19:03 ` Stefan Monnier
@ 2012-10-06  7:12 ` Stephen J. Turnbull
  1 sibling, 0 replies; 8+ messages in thread
From: Stephen J. Turnbull @ 2012-10-06  7:12 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel

Drew Adams writes:

 > What am I missing?

The macro definition.

Add it to some relevant file, protected if necessary by a macrop test,
and probably an eval-when-compile too.





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

end of thread, other threads:[~2012-10-06  7:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-05 18:35 question about macro `minibuffer-with-setup-hook', byte-compilation Drew Adams
2012-10-05 19:03 ` Stefan Monnier
2012-10-05 20:02   ` Drew Adams
2012-10-05 20:21     ` Stefan Monnier
2012-10-05 20:33       ` Drew Adams
2012-10-05 20:49         ` Andreas Schwab
2012-10-05 21:02           ` Drew Adams
2012-10-06  7:12 ` Stephen J. Turnbull

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