Skip to content

Instantly share code, notes, and snippets.

@darkfeline
Last active August 29, 2015 14:17
Show Gist options
  • Save darkfeline/f615f8ccb4cc104ca6a6 to your computer and use it in GitHub Desktop.
Save darkfeline/f615f8ccb4cc104ca6a6 to your computer and use it in GitHub Desktop.
Delight plugin for use-package.el
(use-package delight)
(add-to-list 'use-package-keywords :delight t)
(defun use-package-normalize/:delight (name-symbol keyword args)
"Normalize arguments to delight."
(cond
((and (= (length args) 1)
(symbolp (car args)))
(list (car args) nil name-symbol))
((and (= (length args) 2)
(symbolp (car args)))
(list (car args) (cadr args) name-symbol))
((and (= (length args) 3)
(symbolp (car args)))
args)
(t
(use-package-error ":delight expects same args as delight function"))))
(defun use-package-handler/:delight (name-symbol keyword args rest state)
(let ((body (use-package-process-keywords name-symbol rest state)))
(use-package-concat
body
`((delight
(quote ,(nth 0 args))
,(nth 1 args)
(quote ,(nth 2 args)))
t))))
(provide 'use-package-delight)
@jwiegley
Copy link

@darkfeline Isn't it impossible for the first test in the cond to ever return t?

@npostavs
Copy link

Actually, since (symbolp nil) => t it will return t for any list of length 1, but that means the symbolp call is entirely redundant.

@darkfeline
Copy link
Author

@jwiegley You're right, my inexperience with Elisp is showing. It should be checking (car args), not (cdr args). The restriction on delight is that the first argument is a symbol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment