Searching the Emacs lisp Site Directory

I am trying to configure an Emacs configuration file written for OS X on Ubuntu. I have this line:

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

Used to download emacs-w3m. On OS X, I installed Emacs using Homebrew, so it is located in the / usr / local / Cellar / directory. The lisp site directory on Ubuntu is located elsewhere. How can I write this line so that it works on both operating systems? Is there an Emacs Lisp function to get the lisp site directory?

+7
source share
6 answers

No no. The site-lisp directory is a convention, and only its existence is inconsistent with its path.

Either you install a symbolic link on your Mac / Ubuntu, or use the 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")) 
+7
source

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

Typically, the download path has a lisp site as the first item on the list.

+1
source

Create a subdirs.el file in the directory of your site - lisp that does (add-to-list 'load-path (expand-file-name "w3m" (file-name-directory load-file-name))) . In this case, you can simply place your w3m directory anywhere, so you do not need to worry about where the site is located - lisp, but only where w3m.

+1
source

site-lisp designed to make libraries accessible to all users on a given system and therefore will be managed on a per-system basis.

If you're just trying to consistently manage your own configuration on different servers, don't put things in site-lisp ; put them under a subdirectory of your user directory, for example ~/.emacs.d/lisp/ , and then use:

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

If you want to request your load-path for the "site-lisp" directory (or one that looks 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 )

+1
source

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

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

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

At least with pre-compiled versions of GNU Emacs, this works (the directory already exists). Over time, create a directory:

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

My motivation was that package-user-dir by default %USERPROFILE%/.emacs.d/elpa/ , which seems like a rather strange place. Packages must be installed on the system for all users. Also ~/.emacs.d contains server settings, autosave-lists and backups. What to do where Emacs has a dedicated lisp directory that you can specify.

However, the real "problem" was the pre-compiled Emacs 24.3 for Windows. It does not require installation and, therefore, can be carried out portable, for example, from a stick. Then IMHO ELPA must use its lisp directory, so packages are also installed with delivery.

+1
source

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

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

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

-one
source

All Articles