Subject: Avoid recursive require of eshell

From: "Brendan O'Dea" <[email-masked]>
Date: Wed, 21 Sep 2016 13:14:33 +1000

Package: emacs
Version: 25.1.1
Tags: patch

Attempting add a function to eshell-load-hook, and that function is
autoloaded from a file which also requires eshell, produces the
following error:

  Recursive ‘require’ for feature ‘eshell’

Specifically, I'm trying to do this:

  (add-hook 'eshell-load-hook #'eshell-local-setup)

where eshell-local-setup is an autoloaded function which does a few
things, including adding to eshell-variable-aliases-list and the file
it is defined in has:

  (require 'esh-var)

which indirectly attempts to require eshell.

The simple fix for this is to run the hook after providing eshell.
This seems to be fairly common (see align.el, autorevert.el, dired.el,
expand.el, ibuffer.el, etc) although not consistent (bookmark.el,
cmuscheme.el, etc. do it in the other order).

--bod
diff --git a/lisp/eshell/eshell.el b/lisp/eshell/eshell.el
index 8b21730..baaeca3 100644
--- a/lisp/eshell/eshell.el
+++ b/lisp/eshell/eshell.el
@@ -401,8 +401,8 @@ eshell-unload-all-modules
 	    (message "Unloading %s...done" (symbol-name module)))))
     (message "Unloading eshell...done")))
 
-(run-hooks 'eshell-load-hook)
-
 (provide 'eshell)
 
+(run-hooks 'eshell-load-hook)
+
 ;;; eshell.el ends here