Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading packages installed through 'package.el' in Emacs24 [duplicate]

Possible Duplicate:
Emacs 24 Package System Initialization Problems

I am using Emacs 24. I have the ELPA and Marmalade repos added. Using 'package' I installed 'auto-complete'. I have the following lines added to my init.el:

(require 'auto-complete-config)
(ac-config-default)

When I start Emacs, I get the error

File error: Cannot open load file, auto-complete-config

But then I use

M-x load-file

and load the same ~/.emacs.d/init.el file, it then works fine with the prompt saying

Loading /home/user/.emacs.d/init.el (source)...done

How is the usual loading different from the 'M-x load-file' command? In the start of the init.el file I do the following, is this somehow effecting the package from loading.

(add-to-list 'load-path "~/.emacs.d")
(load "custom_code")

like image 477
pcx Avatar asked Aug 21 '12 11:08

pcx


1 Answers

As mentioned in the comment below: The answer by phils to the duplicate question is probably more helpful than this one

This almost certainly means that your init.el file is getting run before the code that sorts out the packages for package.el. The latter code adds the directory with the auto-complete library to your load path.

I'm still using ELPA, rather than package.el. With elpa, there's a snippet that looks like this that gets installed at the bottom of your .emacs.

;;; This was installed by package-install.el.
;;; This provides support for the package system and
;;; interfacing with ELPA, the package archive.
;;; Move this code earlier if you want to reference
;;; packages in your .emacs.
(when
    (load
     (expand-file-name "~/.emacs.d/elpa/package.el"))
  (package-initialize))

As the comment suggests, you probably want to put your equivalent package.el initialization code before the stuff that loads init.el.

Finally: I notice you mention adding .emacs.d to your load-path. The Emacs load path is not recursive, so that probably won't do what you need (assuming that your libraries live in subdirectories). Years ago, I wrote this snippet to load up various libraries of elisp code that I'd written. You might find it useful. (Obviously, it'll only work on unixy systems with a shell and a find command. It's reasonably slow, but this seems to be shell-command-to-string, which takes several milliseconds even running "echo hello" or the like)

(defun find-elisp-dirs (dir)
  "Find all directories below DIR containing elisp sources, ignoring those"
  (split-string
   (shell-command-to-string
    (format "find %s -iname '*.el' -printf '%%h\\n' | sort -u"
            (expand-file-name dir t)))))
like image 145
Rupert Swarbrick Avatar answered Oct 14 '22 23:10

Rupert Swarbrick