10

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?

hekevintran
  • 22,822
  • 32
  • 111
  • 180

6 Answers6

8

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"))
hekevintran
  • 22,822
  • 32
  • 111
  • 180
Michael Markert
  • 3,986
  • 2
  • 19
  • 19
  • 1
    This looks like the best that Emacs Lisp can do for this problem. – hekevintran Aug 04 '11 at 00: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 03 '12 at 06:57
1

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.

TX T
  • 817
  • 2
  • 16
  • 25
1

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.

Stefan
  • 27,908
  • 4
  • 53
  • 82
1

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:

(remove-if-not
 (lambda (path) (string-match-p "/site-lisp\\'" path))
 load-path)

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

phils
  • 71,335
  • 11
  • 153
  • 198
1

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.

Andreas Spindler
  • 7,568
  • 4
  • 43
  • 34
-1

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

(concat user-emacs-directory
        (convert-standard-filename "site-lisp/")) 

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

zev
  • 3,480
  • 18
  • 13