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!"))
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 ').
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.
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.
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 listfeatures
, 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,
andload
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.
Seeget-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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With