Finding the Emacs site-lisp directory

hekevintran picture hekevintran · Aug 3, 2011 · Viewed 9.3k times · Source

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?

Answer

Michael Markert picture Michael Markert · Aug 3, 2011

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"))