Take the 2-minute tour ×

I am trying to make my Emacs configuration file written for OS X work on Ubuntu. I have this line:

(add-to-list 'load-path "/usr/local/Cellar/emacs/23.3/share/emacs/site-lisp/w3m")

It is used to load emacs-w3m. On OS X I installed Emacs using Homebrew, thus it is in /usr/local/Cellar/.The site-lisp directory on Ubuntu is in a different place. How can I write this line in a way that will work on both operating systems? Is there an Emacs Lisp function to retrieve the site-lisp directory?

share|improve this question
add comment

6 Answers

up vote 6 down vote accepted

No, there's no way. The site-lisp directory is a convention and only its existence not its path is agreed on.

Either you set a symbolic link on your Mac/Ubuntu or you use a system switch:

(defconst my-lisp-dir (cond
    ((equal system-type 'gnu/linux) "/usr/share/emacs/site-lisp/")
    ((equal system-type 'darwin) (concat "/usr/local/Cellar/emacs/" (number-to-string emacs-major-version) "." (number-to-string emacs-minor-version) "/share/emacs/site-lisp/"))
    (t (concat "/usr/local/emacs/site-lisp/")))

and then

(add-to-list 'load-path (concat my-lisp-dir "w3m"))
share|improve this answer
This looks like the best that Emacs Lisp can do for this problem. –  hekevintran Aug 4 '11 at 0:48
Or for a more general solution, you could loop over your current load-path and look for subdirectories named w3m then add them all to the load path. However, I don't think this should really be necessary. Doesn't w3m install its own autoloads? It should! –  tripleee Oct 3 '12 at 6:57
add comment

Create a subdirs.el file in your site-lisp directory which does (add-to-list 'load-path (expand-file-name "w3m" (file-name-directory load-file-name))). This said, you can also just place your w3m directory anywhere you like, so you don't have to worry about where is site-lisp but only where is w3m.

share|improve this answer
add comment

site-lisp is intended for making libraries available to all users on a given system, and so would be managed on a per-system basis.

If you are just trying to manage your own config consistently across servers, don't put things in site-lisp; put them under a sub-directory of your user directory, such as ~/.emacs.d/lisp/ and then use:

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

If you do want to query your load-path for a "site-lisp" directory (or those which look like one), you can do this:

 (lambda (path) (string-match-p "/site-lisp\\'" path))

(but Stefan's answer is best if you really want to keep things in site-lisp)

share|improve this answer
add comment

For some reason (see below) I wanted to set package-user-dir (ELPA) to the site-lisp-directory.

It should be possible to deduce the site-lisp-directory from the standard exec-directory variable:

(setq site-lisp-directory (concat exec-directory "../site-lisp")

At least with the precompiled Emacs-versions from GNU this works (the directory already exists). Eventually create the directory:

(unless (file-accessible-directory-p site-lisp-directory)
    (make-directory site-lisp-directory))

My motivation was that package-user-dir by default is %USERPROFILE%/.emacs.d/elpa/, which seems to be a rather strange location. Packages shall be installed system-wide for all users. Also ~/.emacs.d contains server settings, auto-save-lists and backups. What have packages to do there when Emacs has a dedicated site-lisp-directory one can ask.

However, the real "problem" was the precompiled Emacs 24.3 for Windows. It requires no installation and hence can be run portably, like from a stick. IMHO ELPA should then use its site-lisp-directory, so that the packages are installed portably too.

share|improve this answer
add comment

I tried this on my Windows Emacs (23.4.1) and Mac OS Emacs (23.4.1) for my other add-on and it worked.

(concat (car load-path) "/w3m")

Usually, the load-path has the site-lisp as the first item in the list.

share|improve this answer
I wouldn't consider that reliable. –  phils Oct 2 '12 at 20:42
add comment

If you are using Emacs 23 you can use the following:

(concat user-emacs-directory

However, this will only find the "default" location for user-installed lisp files.

share|improve this answer
That's the user directory not a system one. –  Michael Markert Aug 3 '11 at 19:35
Yes, you are correct. –  zev Aug 3 '11 at 19:41
add comment

Your Answer


