Skip to content

Instantly share code, notes, and snippets.

@jonEbird
Created April 16, 2015 04:28
Show Gist options
  • Save jonEbird/1e6746893b9059d1408e to your computer and use it in GitHub Desktop.
Save jonEbird/1e6746893b9059d1408e to your computer and use it in GitHub Desktop.
Add :el-get option to use-package that mimics :ensure
(require 'use-package)
(defun use-package-normalize/:el-get (name-symbol keyword args)
(if (null args)
t
(use-package-only-one (symbol-name keyword) args
(lambda (label arg)
(if (symbolp arg)
arg
(use-package-error
(concat ":el-get wants an optional package name "
"(an unquoted symbol name)")))))))
(defun use-package-el-get (package)
(when (not (el-get-package-is-installed package))
(el-get-install package)))
(defun use-package-handler/:el-get (name-symbol keyword ensure rest state)
(let ((body (use-package-process-keywords name-symbol rest state)))
;; This happens at macro expansion time, not when the expanded code is
;; compiled or evaluated.
(let ((package-name (or (and (eq ensure t) name-symbol) ensure)))
(when package-name
(require 'package)
(use-package-el-get package-name)))
body))
(defun insertafter (lst mark item)
"Update list LST by inserting after MARK the ITEM"
(if (eq nil lst)
nil
(if (equal mark (car lst))
(cons (car lst)
(cons item (cdr lst)))
(cons (car lst)
(insertafter (cdr lst) mark item)))))
(setq use-package-keywords
(insertafter use-package-keywords :ensure :el-get))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment