[slime-devel] Daily ChangeLog diff
Mark Harig
idirectscm at aim.com
Sat Mar 20 15:44:01 UTC 2010
> >> + * slime.el (slime-dispatch-event): Add clause for :gdb-attach.
> >> + (slime-attach-gdb): New.
> >> +
> >
> > The new function `slime-attach-gdb' references the function
> >> `gud-gdb'
> > and the variable `gud-comint-buffer', which are defined in Emacs's
> > gud.el, but does not include
> >
> > (require 'gud)
> >
> > Was this omission intentional?
>
> Under what circumstances is it necessary to explicitly require
> packages?
Here is the first sentence from the "Autoload" section of the Emacs
Lisp manual:
"The 'autoload' facility allows you to make a function or macro known in
Lisp, but put off loading the file that defines it."
So, as long as code is referencing only functions or macros that have
been marked as autoloaded, it is not be necessary to require
explicitly the packages that define them.
The change to add the new function `slime-attach-gdb' does not
reference only functions or macros. It also references a variable.
Because `slime-attach-gdb' references an autoloaded function, this
reference to the variable does not cause a problem -- its definition
is loaded when the autoload for the function takes place.
However, the compilation of slime.el will cause the variable to be
flagged as undefined because the autoloading (by definition) takes
place at run-time. So, everyone who compiles slime.el will, if they
are being careful, need to check the code to confirm that it is
calling an autoloaded function (searching for `gud-gdb', in this case)
and looking it up in the defining file (gud.el). In this instance in
slime.el, the autoloaded function is called quite near in the code to
the reference to the variable, but that will not always be the case.
> Won't the autoload magic do that automatically?
In this instance, yes. It is more a stylistic consideration. The
code is written once, but (at least potentially) compiled and read by
many people, who would then need to investigate to confirm that the
definition of `gud-comint-buffer' will be loaded when `gud-gdb' is
autoloaded.
The stylistic rule I am proposing is that if the code references any
non-autoloaded symbols (only functions and macros are autoloaded),
then it should include a '(require ...)', regardless of whether the
code also includes some autoloaded symbols.
This should also help with robustness because if some future change
were to remove the autoloaded symbols, then the non-autoloaded
symbols would no longer have their definitions loaded.
More information about the slime-devel
mailing list