10
  1. According to Emacs Eclim, I added the following to ~/.emacs.d/init.d for emacs-eclim:

    (require 'eclim)
    (global-eclim-mode)
    
    ; If you want to control eclimd from emacs, also add:
    (require 'eclimd)
    

    The output of emacs -nw --debug-init is:

    Debugger entered--Lisp error: (file-error "Cannot open load file" "eclim")
      require(eclim)
      eval-buffer(#<buffer  *load*> nil "/home/tim/.emacs.d/init.el" nil t)  ; Reading at buffer position 4117
      load-with-code-conversion("/home/tim/.emacs.d/init.el" "/home/tim/.emacs.d/init.el" t t)
      load("/home/tim/.emacs.d/init" t t)
      #[0 "^H\205\262^@     \306=\203^Q^@\307^H\310Q\202;^@ \311=\204^^^@\307^H\312Q\202;^@\313\307\314\315#\203*^@\316\202;^@\313\307\314\317#\$
      command-line()
      normal-top-level()
    
  2. If I add the following line at the beginning:

    (add-to-list 'load-path "~/.emacs.d/elpa/emacs-eclim-20140809.207/")
    
    (require 'eclim)
    (global-eclim-mode)
    
    ; If you want to control eclimd from emacs, also add:
    (require 'eclimd)
    

    The output of emacs -nw --debug-init is:

    Debugger entered--Lisp error: (file-error "Cannot open load file" "s")
      require(s)
      byte-code("\300\301!\210\300\302!\210\303\304\305\306\307\310%\210\311\312\313\314\315\316\307\304&^G\207"
    [require etags s custom-declare$
      require(eclim)
      eval-buffer(#<buffer  *load*> nil "/home/tim/.emacs.d/init.el" nil t)  ; Reading at buffer position 4115
      load-with-code-conversion("/home/tim/.emacs.d/init.el" "/home/tim/.emacs.d/init.el" t t)
      load("/home/tim/.emacs.d/init" t t)
      #[0 "^H\205\262^@     \306=\203^Q^@\307^H\310Q\202;^@ \311=\204^^^@\307^H\312Q\202;^@\313\307\314\315#\203*^@\316\202;^@\313\307\314\317#\$
      command-line()
      normal-top-level()
    
  3. If I instead add a different line at the beginning, it works without error:

    (package-initialize)
    
    (require 'eclim)
    (global-eclim-mode)
    
    ; If you want to control eclimd from emacs, also add:
    (require 'eclimd)
    
  4. If I add both lines at the beginning, it also works:

    (add-to-list 'load-path "~/.emacs.d/elpa/emacs-eclim-20140809.207/")
    (package-initialize)
    
    (require 'eclim)
    (global-eclim-mode)
    
    ; If you want to control eclimd from emacs, also add:
    (require 'eclimd)
    

I wonder what the two lines I added do, and why they can work or not work? Thanks.

0

2 Answers 2

12

Your problem is that the package eclim as a dependency on the package s, so when you require eclim, you need to have s in your load-path. package-initialize ensure that every installed package are in you load-path, and load them too, so:

  • you don't need to require eclim when you call package-initialize
  • you need to add s to the load path if you don't call package-initialize

As you have installed those extension using package, better (and simpler) to use package-initialize.

6
  • Are you saying (package-initialize) is to replace require and load-path?
    – Tim
    Commented Oct 25, 2014 at 15:08
  • Yes. Well I don't know the specific for eclim, but normally a package installed through elpa don't need any load-path tangling nor require.
    – Rémi
    Commented Oct 25, 2014 at 15:17
  • (1) Is "installed through elpa" same as "installed by package.el"? (2) what about those packages installed manually? Do they still need load-path and require?
    – Tim
    Commented Oct 25, 2014 at 15:23
  • (1) Well, I should have said installed by package.el, as the source might be something else than elpa. (2) Short answer: probably not, package-initialize is for package installation known by package.el, and I don't known how package.el know how to initialize them.
    – Rémi
    Commented Oct 25, 2014 at 16:38
  • Thanks. I asked " Do they still need load-path and require?", and what do you mean by "probably not"?
    – Tim
    Commented Oct 25, 2014 at 16:59
3

It simply initializes all packages before running .emacs file. This way, you already have symbol eclim created, and you can use function "require" to require it. If you don't add package-initialize, then this package isn't initialized, eclim symbol is unbound, and you get situation that you had before :)

2
  • thanks. (1) but in part 1, I followed the emacs-eclim site, why is there no (package-initialize)? (2) why is (add-to-list 'load-path "~/.emacs.d/elpa/emacs-eclim-20140809.207/") not needed?
    – Tim
    Commented Oct 25, 2014 at 14:53
  • 1) Maybe they assumed you already have it. 2) Because when you install package, some information are given to emacs - like the package path. If you installed some package manually, you would have to provide its path. Also, I can't comment on other posts since I don't have >50 rep, but I'll answer your question: gnu.org/software/emacs/manual/html_node/emacs/… In short: require is used to load package if other code in .emacs depends on it. A bit like #include in C/C++ Commented Oct 25, 2014 at 16:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.