简体   繁体   中英

emacs: load-path and require (cannot open load file)

I've got "Cannot open load file" error at (require 'org-mime) while load-path variable seems to be all right:

load-path is a variable defined in `C source code'.
Its value is
("/home/alexey/.emacs.d/elpa/bbdb-20130526.1945" "/home/alexey/.emacs.d/elpa/org-mime-20120112" "/home/alexey/.emacs.d/elpa/smex-20130421.2153" "/usr/share/emacs/24.3/site-lisp" "/usr/share/emacs/site-lisp" "/usr/share/emacs/24.3/lisp
...

Curiously, the remedy looks like this (.emacs):

(add-to-list 'load-path "~/.emacs.d/elpa/org-mime-20120112")

It isn't merely ugly: it's dysfunctional, because the versioned path is subject to change. But why the error?

There is an interesting issue that happens when you load a file that requires another file -- the file that is required must be loaded in chronological order before the next file. For example, if B requires A then A must be placed higher up in chronological order so that when B loads, A is already loaded.

I've had really good luck with this type of setup. Most files end with el or elc, so I'm not sure why you want to load a file with a different or no extension, but it is certainly possible to do that if you want.

(let* ((root.d "~/") (sub-dir (concat root.d ".emacs.d/")))
    (load-file (concat sub-dir "init.el"))
    (setq load-path
(append `(,root.d ,sub-dir
    ,(concat sub-dir "elpa/yasnippet")
) load-path)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM