Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine whether a package is installed in elisp?

Tags:

emacs

elisp

I want to customize environment while the specific package is installed properly. How to check whether some package is installed in elisp? Something like this?:

(if (require 'ecb)     (progn (setq ....))   (message "ECB not installed!")) 
like image 655
Vivodo Avatar asked Oct 17 '11 07:10

Vivodo


People also ask

How do I see what packages are installed in Emacs?

The command M-x list-packages brings up the package menu. This is a buffer listing all the packages that Emacs knows about, one on each line, with the following information: The package name (e.g., ' auctex '). The package's version number (e.g., ' 11.86 ').

Where are melpa packages stored?

Packages are installed in ~/. emacs. d/elpa by default and will be set up for autoloading in this and all future Emacs sessions. After installing a package from the Package Menu, it is normally ready to go with no need to restart.

What is Package El Emacs?

package. el is bundled with Emacs 24, but it's not bound to Emacs 23. Before it became part of Emacs it was an external package, known as package. el that was tied to repository called ELPA (Emacs Lisp Package Archive). So even if you're an Emacs 23 user you can copy the latest version of package.


1 Answers

tripleee's answer is a handy example of error handling, but unnecessary in this instance.

(when (require 'some-library nil 'noerror)   do-things) 

That 'noerror can be any non-nil value, but of course it's more descriptive this way. I often see :noerror used as well, but I've no idea if there's any particular advantage to using a keyword argument over a symbol (comments, anyone? I'm quite interested to know).

require is a built-in function in C source code.

(require FEATURE &optional FILENAME NOERROR)

If feature FEATURE is not loaded, load it from FILENAME.
If FEATURE is not a member of the list features, then the feature
is not loaded; so load the file FILENAME.
If FILENAME is omitted, the printname of FEATURE is used as the file name,
and load will try to load this name appended with the suffix .elc or
.el, in that order. The name without appended suffix will not be used.
See get-load-suffixes for the complete list of suffixes.
If the optional third argument NOERROR is non-nil,
then return nil if the file is not found instead of signaling an error.
Normally the return value is FEATURE.
The normal messages at start and end of loading FILENAME are suppressed.

like image 95
phils Avatar answered Sep 24 '22 11:09

phils