12

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

kgui
  • 4,015
  • 5
  • 41
  • 53
rabidmachine9
  • 7,775
  • 11
  • 46
  • 59
  • When you say it "doesn't work," how does it fail? Is it that the `require` calls fail? – seh Aug 02 '11 at 17:32
  • Did you evaluate each expression with eval-buffer or eval-expression? Or put it in your. Emacs file then save and restart? – justinhj Aug 02 '11 at 22:17

3 Answers3

13

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.

seh
  • 14,999
  • 2
  • 48
  • 58
1

The first answer didn't work for me. Adding the directory path, not individual .el files, worked for me, i.e.:

(add-to-list 'load-path (expand-file-name "~/.emacs.d"))
smonff
  • 3,399
  • 3
  • 36
  • 46
Kuro
  • 301
  • 2
  • 10
  • 1
    You're correct; but **no one** suggested adding individual .el files to the load-path. Your answer is no different to the accepted answer. Also, [don't put ~/.emacs.d in your load-path](http://stackoverflow.com/a/24791753/324105). – phils Nov 24 '14 at 20:32
  • I misunderstood. I thought jademode means jademode.el but I guess it is a directory name. And thank you for the reference to the other article. – Kuro Nov 25 '14 at 22:06
  • Ah, that explains it. No, `load-path` is directories only. The source of the confusion might be that when you're `load`ing a specific library, you can (and typically should) omit the extension, and let Emacs choose which one to use. – phils Nov 26 '14 at 04:30
1

i'm not 100% sure but i would guess that the list is not instantiated and thus you can't add anything to the load-path list, i just instantiate the list with

    (setq load-path (cons (expand-file-name "~/.emacs.d/lisp")
              load-path))
horseyguy
  • 29,455
  • 20
  • 103
  • 145
Xtroce
  • 1,749
  • 3
  • 19
  • 43