segunda-feira, 15 de junho de 2015

Package-require: require a library, eventually loading the package from the Emacs package archives

package-require is an Emacs Lisp utility function that will install a package if not installed from the archives, and then load the corresponding library. If the library name differs from the package name, it can be supplied.

(defun package-require (package-name &optional library-name)
  "Install the package named PACKAGE-NAME from the repositories
  if it doesn't exist locally and then load the library given by
  LIBRARY-NAME, or PACKAGE-NAME if it is homonimous.  Both names
  are strings, not symbols."

  (let ((package (intern package-name)))
    (unless (package-installed-p package)
      (package-install package)))
  (load-library (or library-name package-name)))

To use it, write in your emacs file, for instance:

(package-require "bpe")

What if the package name differs from the library to load, like in AucTeX? Just write the library name after the package. The following example loads "tex-site", installing "auctex" first if it does not exist.

(package-require "auctex" "tex-site")

Sem comentários:

Enviar um comentário