add-to-list 'load-path doesn't seem to work

rabidmachine9 picture rabidmachine9 · Aug 2, 2011 · Viewed 11.2k times · Source

Whenever I see some installation instruction for an emacs package it always suggests to use add-to-list 'load-path it never works for me. For some reason and I have to use load-file. For example, this will not work:

(add-to-list 'load-path "~/.emacs.d/jade-mode")
(require 'sws-mode)
(require 'jade-mode)    
(add-to-list 'auto-mode-alist '("\\.styl$" . sws-mode))
(add-to-list 'auto-mode-alist '("\\.jade$" . sws-mode))

but this will work:

(load-file "~/.emacs.d/jade-mode/sws-mode.el")
(load-file "~/.emacs.d/jade-mode/jade-mode.el")
(require 'sws-mode)
(require 'jade-mode)    

anybody can tell me why? EDIT: I use Carbon Emacs on MAC OS X 10.5

Answer

seh picture seh · Aug 2, 2011

Perhaps the problem is that the leading tilde ('~') is not expanded when require searches the entries in the load-path list. Consider using the expand-file-name function to prepare your entry for subsequent use by require:

(add-to-list 'load-path (expand-file-name "jademode" "~/.emacs.d"))

or

(add-to-list 'load-path (expand-file-name "~/.emacs.d/jademode"))

It would help to know which Emacs you're using on which operating system.