Skip to content

Instantly share code, notes, and snippets.

@jordonbiondo
Created April 23, 2014 14:59
Show Gist options
  • Select an option

  • Save jordonbiondo/11218747 to your computer and use it in GitHub Desktop.

Select an option

Save jordonbiondo/11218747 to your computer and use it in GitHub Desktop.
(cl-defun my-custom-install (package &key then error)
"Install PACKAGE if not installed and configure it.
key :then specifies a function to run when package installs successfully or is already installed.
key :error specifies a function to run when package installation fails
this function recieves one argument, an error object."
(declare (indent defun))
(condition-case err
(progn (unless (package-installed-p package)
(package-install package))
(when then (funcall then)))
(error (when error (funcall error err)))))
(my-custom-install 'helm
:then (lambda ()
(message "Configuratin'!"))
:error (lambda(err) (message "OH NO! %s" (error-message-string err)))) ;; => "Configuratin'!"
(my-custom-install 'not-a-package
:then (lambda ()
(message "Configuratin'!"))
:error (lambda(err) (message "OH NO! %s" (error-message-string err)))) ;; => "OH NO! Package `not-a-package' is not available for installation"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment