unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Something like `with-eval-before-load'?
@ 2014-11-25 16:35 Alexander Shukaev
  2014-11-26  2:17 ` Yuri Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Shukaev @ 2014-11-25 16:35 UTC (permalink / raw)
  To: help-gnu-emacs

`with-eval-after-load' is indeed very handy form. But currently I'm in the
situation where I need its counterpart --- `with-eval-before-load'.

Let me give you an example. Imagine that I want to wipe out
`undo-tree-map'. How would you expect one to do so? Here is one way:

(set 'undo-tree-map (make-sparse-keymap))
(require 'undo-tree)


So far so good, but it will only work if `undo-tree' has not been ever
required before. In my case I don't want to track whether it was required
before or not (by other packages which depend on it of course) because my
configuration is modular and all I would like to do would be to write
something like

(with-eval-before-load 'undo-tree
  (set 'undo-tree-map (make-sparse-keymap)))


in some separate file which is dedicated for configuring only `undo-tree'
say `init-undo-tree.el'.

Then in some global configuration file, for example, `init.el' we can have

...
(require 'init-this)
(require 'init-that)
(require 'init-them)
(require 'init-him)
(require 'init-her)
(require 'init-undo-tree)
...


and the key feature here would be that the order where I put `(require
'init-undo-tree)' would not matter.

Is there any facility like `with-eval-before-load' available?


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

* Re: Something like `with-eval-before-load'?
  2014-11-25 16:35 Something like `with-eval-before-load'? Alexander Shukaev
@ 2014-11-26  2:17 ` Yuri Khan
  2014-11-26  9:36   ` Alexander Shukaev
  0 siblings, 1 reply; 3+ messages in thread
From: Yuri Khan @ 2014-11-26  2:17 UTC (permalink / raw)
  To: Alexander Shukaev; +Cc: help-gnu-emacs

On Tue, Nov 25, 2014 at 10:35 PM, Alexander Shukaev <haroogan@gmail.com> wrote:
> `with-eval-after-load' is indeed very handy form. But currently I'm in the
> situation where I need its counterpart --- `with-eval-before-load'.

“with-eval-after-load” is possible because time flows forward.

At the time (with-eval-after-load MODULE FORM) is evaluated, there are
two possibilities: either MODULE has already been loaded, or not. If
it has, the FORM is evaluated immediately. If not, a hook is created
that will be called when and if MODULE is eventually loaded.

Now imagine your hypothetical “with-eval-before-load” form.

(with-eval-before-load MODULE FORM)

If MODULE has not yet been loaded, easy. Create a hook; when a request
to load MODULE is made, call the hook before loading it.

But if MODULE has already been loaded, we’re out of luck. Try as we
might, we cannot execute FORM *before* loading MODULE — it would
require us to go back in time.

Either that, or your modular config system has to resolve dependencies
so that the module which evaluates (with-eval-before-load MODULE) is
always loaded before MODULE. But that’s precisely what you’re trying
to solve with “with-eval-before-load” — the problem reduces to itself.

You can achieve what you want by introducing a convention: *first*
load all your init-* modules and arrange them so that they do not
(require) anything; and only *then* selectively (require) anything you
want.



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

* Re: Something like `with-eval-before-load'?
  2014-11-26  2:17 ` Yuri Khan
@ 2014-11-26  9:36   ` Alexander Shukaev
  0 siblings, 0 replies; 3+ messages in thread
From: Alexander Shukaev @ 2014-11-26  9:36 UTC (permalink / raw)
  To: Yuri Khan; +Cc: help-gnu-emacs

Thank you for expanded answer, Yuri.


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

end of thread, other threads:[~2014-11-26  9:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-25 16:35 Something like `with-eval-before-load'? Alexander Shukaev
2014-11-26  2:17 ` Yuri Khan
2014-11-26  9:36   ` Alexander Shukaev

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