This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
For a long time, my init.el
file was full of lots of sections of the form
(quelpa 'my-package) (use-package my-package :init (initialize-my-package))
(quelpa
is a package that downloads Emacs packages from the Internet using
Git. use-package
is a macro that makes loading and initializing these
packages convenient.)
Eventually I realized that the file could be simplified greatly were there a macro to chain the two operations together. The macro is trivial, but I wrote it and it is published here.
The syntax of quse-package
is virtually identical to that of
use-package
. The significant difference is that instead of looking for the
specified package name locally it will build it using quelpa
and can thus
accept a package recipe in the same format that the quelpa
function
accepts. In addition, if the first parameter after the package name is the
keyword :upgrade
, quse-package
will treat that parameter and the one
succeeding it as part of the quelpa
call. See the quelpa
documentation for
details on how :upgrade
works.
quse-package
will also add the requested package to
package-selected-packages
. This allows one to use quelpa-upgrade
followed
by package-menu-mark-obsolete-for-deletion
followed by package-autoremove
to get a clean system.
Without further ado, the macro itself.
The convention to adhere to comes from the Emacs Lisp section of the Emacs manual. The section is called “Conventional Headers for Emacs Libraries”. Check it out in your own Emacs.
In any case, the snippets below are the skeletion of quse-package
.
The header of the package contains metadata and a magic comment telling the packaging system where the actual code starts.
;;; quse-package.el --- Install and configure packages in one convenient macro. -*- lexical-binding: t; -*-
;; Copyright (C) 2014-2018 Jacob MacDonald.
;; Author: Jacob MacDonald <jaccarmac@gmail.com>.
;; Created: 18 December 2014.
;; Version: 2.2.5
;; Keywords: extensions lisp
;; Homepage: github.com/jaccarmac/quse-package
;; Package-Requires: ((quelpa "0") (use-package "0"))
;;; Commentary:
;; Use this package exactly like you would use-package, with the exception that
;; the package name should be a quelpa recipe. If the first argument after the
;; recipe is :upgrade, it will be treated as an :upgrade argument to quelpa.
;;; Code:
All the footer has to do is provide a system with a certain name and have a magic comment.
(provide 'quse-package)
;;; quse-package.el ends here
The comment on the first line is just a magic comment to load the main macro when the package is loaded.
The macro determines whether or not the first argument is a list. It passes
the first argument to quelpa
regardless, then passes either the first
argument and the &rest
or the car
of the first argument and the &rest
to use-package
. If the second parameter to the macro is the symbol
:upgrade
, quse-package
will interpret it and the next parameter to be
part of the quelpa
call. Read the quelpa
documentation to see what
:upgrade
does.
;;;###autoload
(defmacro quse-package (quelpa-form &rest use-package-forms)
"Download a package with quelpa and initialize it with ‘use-package’.
QUELPA-FORM should be an *unquoted* name or list compatible with
quelpa. USE-PACKAGE-FORMS should be whatever comes after the
package name in a ‘use-package’ call. If the first element of
USE-PACKAGE-FORMS is :upgrade, the next element is used as
the :upgrade parameter to the quelpa call."
(declare (indent 1))
(let* ((upgrade-form (if (and use-package-forms
(eq :upgrade (car use-package-forms)))
(list (car use-package-forms)
(cadr use-package-forms))))
(use-package-name (if (listp quelpa-form)
(car quelpa-form)
quelpa-form))
(use-package-forms (if upgrade-form
(cddr use-package-forms)
use-package-forms)))
`(progn (add-to-list 'package-selected-packages ',use-package-name)
(quelpa ',quelpa-form ,@upgrade-form)
(use-package ,use-package-name
,@use-package-forms))))
<<header>>
<<quse-package>>
<<footer>>