开发者

Finding the Emacs site-lisp directory

开发者 https://www.devze.com 2023-03-25 12:20 出处:网络
I am trying to make my Emacs configuration file written for OS X work on Ubuntu. I have this line: 开发者_StackOverflow社区(add-to-list \'load-path \"/usr/local/Cellar/emacs/23.3/share/emacs/site-lis

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

开发者_StackOverflow社区(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?


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


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.


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.


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)


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消