Break out ensure/diminish/delight into their own support files
This commit is contained in:
parent
cdbb2cbe97
commit
fff47a1331
7 changed files with 1850 additions and 1625 deletions
|
@ -27,24 +27,41 @@
|
|||
### Other changes
|
||||
|
||||
- Upgrade license to GPL 3.
|
||||
|
||||
- New `:hook` keyword.
|
||||
|
||||
- New keywords `:custom (foo1 bar1) (foo2 bar2)` etc., and `:custom-face`.
|
||||
|
||||
- New `:magic` and `:magic-fallback` keywords.
|
||||
|
||||
- New `:defer-install` keyword.
|
||||
|
||||
- New customization variable `use-package-enable-imenu-support`.
|
||||
|
||||
- Allow `:diminish` to take no arguments.
|
||||
|
||||
- Support multiple symbols passed to `:after`, and a mini-DSL using `:all` and
|
||||
`:any`.
|
||||
|
||||
- `:mode` and `:interpreter` can now accept `(rx ...)` forms.
|
||||
|
||||
- Using `:load-path` without also using `:ensure` now implies `:ensure nil`.
|
||||
|
||||
- `:bind (:map foo-map ...)` now defers binding in the map until the package
|
||||
has been loaded.
|
||||
|
||||
- Print key bindings for keymaps in `describe-personal-keybindings`.
|
||||
|
||||
- When `use-package-inject-hooks` is non-nil, always fire `:init` and
|
||||
`:config` hooks.
|
||||
|
||||
- Documentation added for the `:after`, `:defer-install`, `:delight`,
|
||||
`:requires`, `:when` and `:unless` keywords.
|
||||
|
||||
- The source code is now broken into several files, so that certain optional
|
||||
features (diminish, delight, ensure) may be maintained separately from the
|
||||
core functionality.
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- Repeating a bind no longer causes duplicates in personal-keybindings.
|
||||
|
|
File diff suppressed because it is too large
Load diff
1476
up-core.el
Normal file
1476
up-core.el
Normal file
File diff suppressed because it is too large
Load diff
87
up-delight.el
Normal file
87
up-delight.el
Normal file
|
@ -0,0 +1,87 @@
|
|||
;;; up-delight.el --- Support for the :delight keyword
|
||||
|
||||
;; Copyright (C) 2012-2017 John Wiegley
|
||||
|
||||
;; Author: John Wiegley <johnw@newartisans.com>
|
||||
;; Maintainer: John Wiegley <johnw@newartisans.com>
|
||||
;; Created: 17 Jun 2012
|
||||
;; Modified: 3 Dec 2017
|
||||
;; Version: 1.0
|
||||
;; Package-Requires: ((emacs "24.3") (use-package "2.4") (delight "1.5"))
|
||||
;; Keywords: dotemacs startup speed config package
|
||||
;; URL: https://github.com/jwiegley/use-package
|
||||
|
||||
;; This program is free software; you can redistribute it and/or
|
||||
;; modify it under the terms of the GNU General Public License as
|
||||
;; published by the Free Software Foundation; either version 3, or (at
|
||||
;; your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful, but
|
||||
;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
;; General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
||||
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
;; Boston, MA 02111-1307, USA.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Provides support for the :delight keyword, which is made available by
|
||||
;; default by requiring `use-package'.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'up-core)
|
||||
|
||||
(defun use-package-normalize-delight (name args)
|
||||
"Normalize ARGS for a single call to `delight'."
|
||||
(when (eq :eval (car args))
|
||||
;; Handle likely common mistake.
|
||||
(use-package-error ":delight mode line constructs must be quoted"))
|
||||
(cond ((and (= (length args) 1)
|
||||
(use-package-non-nil-symbolp (car args)))
|
||||
`(,(nth 0 args) nil ,name))
|
||||
((= (length args) 2)
|
||||
`(,(nth 0 args) ,(nth 1 args) ,name))
|
||||
((= (length args) 3)
|
||||
args)
|
||||
(t
|
||||
(use-package-error
|
||||
":delight expects `delight' arguments or a list of them"))))
|
||||
|
||||
(defun use-package-normalize/:delight (name keyword args)
|
||||
"Normalize arguments to delight."
|
||||
(cond ((null args)
|
||||
`((,(use-package-as-mode name) nil ,name)))
|
||||
((and (= (length args) 1)
|
||||
(use-package-non-nil-symbolp (car args)))
|
||||
`((,(car args) nil ,name)))
|
||||
((and (= (length args) 1)
|
||||
(stringp (car args)))
|
||||
`((,(use-package-as-mode name) ,(car args) ,name)))
|
||||
((and (= (length args) 1)
|
||||
(listp (car args))
|
||||
(eq 'quote (caar args)))
|
||||
`((,(use-package-as-mode name) ,@(cdar args) ,name)))
|
||||
((and (= (length args) 2)
|
||||
(listp (nth 1 args))
|
||||
(eq 'quote (car (nth 1 args))))
|
||||
`((,(car args) ,@(cdr (nth 1 args)) ,name)))
|
||||
(t (mapcar
|
||||
(apply-partially #'use-package-normalize-delight name)
|
||||
(if (use-package-non-nil-symbolp (car args))
|
||||
(list args)
|
||||
args)))))
|
||||
|
||||
(defun use-package-handler/:delight (name keyword args rest state)
|
||||
(let ((body (use-package-process-keywords name rest state)))
|
||||
(use-package-concat
|
||||
body
|
||||
`((if (fboundp 'delight)
|
||||
(delight '(,@args)))))))
|
||||
|
||||
(add-to-list 'use-package-keywords :delight t)
|
||||
|
||||
(provide 'up-delight)
|
76
up-diminish.el
Normal file
76
up-diminish.el
Normal file
|
@ -0,0 +1,76 @@
|
|||
;;; up-diminish.el --- Support for the :diminish keyword
|
||||
|
||||
;; Copyright (C) 2012-2017 John Wiegley
|
||||
|
||||
;; Author: John Wiegley <johnw@newartisans.com>
|
||||
;; Maintainer: John Wiegley <johnw@newartisans.com>
|
||||
;; Created: 17 Jun 2012
|
||||
;; Modified: 3 Dec 2017
|
||||
;; Version: 1.0
|
||||
;; Package-Requires: ((emacs "24.3") (use-package "2.4") (diminish "0.45"))
|
||||
;; Keywords: dotemacs startup speed config package
|
||||
;; URL: https://github.com/jwiegley/use-package
|
||||
|
||||
;; This program is free software; you can redistribute it and/or
|
||||
;; modify it under the terms of the GNU General Public License as
|
||||
;; published by the Free Software Foundation; either version 3, or (at
|
||||
;; your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful, but
|
||||
;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
;; General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
||||
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
;; Boston, MA 02111-1307, USA.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Provides support for the :diminish keyword, which is made available by
|
||||
;; default by requiring `use-package'.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'up-core)
|
||||
|
||||
(defun use-package-normalize-diminish (name label arg &optional recursed)
|
||||
"Normalize the arguments to diminish down to a list of one of two forms:
|
||||
SYMBOL
|
||||
(SYMBOL . STRING)"
|
||||
(cond
|
||||
((not arg)
|
||||
(list (use-package-as-mode name)))
|
||||
((use-package-non-nil-symbolp arg)
|
||||
(list arg))
|
||||
((stringp arg)
|
||||
(list (cons (use-package-as-mode name) arg)))
|
||||
((and (consp arg) (stringp (cdr arg)))
|
||||
(list arg))
|
||||
((and (not recursed) (listp arg) (listp (cdr arg)))
|
||||
(mapcar #'(lambda (x) (car (use-package-normalize-diminish
|
||||
name label x t))) arg))
|
||||
(t
|
||||
(use-package-error
|
||||
(concat label " wants a string, symbol, "
|
||||
"(symbol . string) or list of these")))))
|
||||
|
||||
(defun use-package-normalize/:diminish (name keyword args)
|
||||
(use-package-as-one (symbol-name keyword) args
|
||||
(apply-partially #'use-package-normalize-diminish name) t))
|
||||
|
||||
(defun use-package-handler/:diminish (name keyword arg rest state)
|
||||
(let ((body (use-package-process-keywords name rest state)))
|
||||
(use-package-concat
|
||||
(mapcar #'(lambda (var)
|
||||
`(if (fboundp 'diminish)
|
||||
,(if (consp var)
|
||||
`(diminish ',(car var) ,(cdr var))
|
||||
`(diminish ',var))))
|
||||
arg)
|
||||
body)))
|
||||
|
||||
(add-to-list 'use-package-keywords :diminish t)
|
||||
|
||||
(provide 'up-diminish)
|
190
up-ensure.el
Normal file
190
up-ensure.el
Normal file
|
@ -0,0 +1,190 @@
|
|||
;;; up-ensure.el --- Support for the :ensure and :pin keywords
|
||||
|
||||
;; Copyright (C) 2012-2017 John Wiegley
|
||||
|
||||
;; Author: John Wiegley <johnw@newartisans.com>
|
||||
;; Maintainer: John Wiegley <johnw@newartisans.com>
|
||||
;; Created: 17 Jun 2012
|
||||
;; Modified: 3 Dec 2017
|
||||
;; Version: 1.0
|
||||
;; Package-Requires: ((emacs "24.3") (use-package "2.4"))
|
||||
;; Keywords: dotemacs startup speed config package
|
||||
;; URL: https://github.com/jwiegley/use-package
|
||||
|
||||
;; This program is free software; you can redistribute it and/or
|
||||
;; modify it under the terms of the GNU General Public License as
|
||||
;; published by the Free Software Foundation; either version 3, or (at
|
||||
;; your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful, but
|
||||
;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
;; General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
||||
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
;; Boston, MA 02111-1307, USA.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Provides support for the :ensure and :pin keywords, which is made available
|
||||
;; by default by requiring `use-package'.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'up-core)
|
||||
|
||||
(defcustom use-package-always-ensure nil
|
||||
"Treat every package as though it had specified using `:ensure SEXP'.
|
||||
See also `use-package-defaults', which uses this value."
|
||||
:type 'sexp
|
||||
:group 'use-package)
|
||||
|
||||
(defcustom use-package-always-pin nil
|
||||
"Treat every package as though it had specified using `:pin SYM'.
|
||||
See also `use-package-defaults', which uses this value."
|
||||
:type 'symbol
|
||||
:group 'use-package)
|
||||
|
||||
(defcustom use-package-ensure-function 'use-package-ensure-elpa
|
||||
"Function that ensures a package is installed.
|
||||
This function is called with three arguments: the name of the
|
||||
package declared in the `use-package' form; the argument passed
|
||||
to `:ensure'; and the current `state' plist created by previous
|
||||
handlers.
|
||||
|
||||
Note that this function is called whenever `:ensure' is provided,
|
||||
even if it is nil. It is up to the function to decide on the
|
||||
semantics of the various values for `:ensure'.
|
||||
|
||||
This function should return non-nil if the package is installed.
|
||||
|
||||
The default value uses package.el to install the package."
|
||||
:type '(choice (const :tag "package.el" use-package-ensure-elpa)
|
||||
(function :tag "Custom"))
|
||||
:group 'use-package)
|
||||
|
||||
;;;; :pin
|
||||
|
||||
(defun use-package-normalize/:pin (name keyword args)
|
||||
(use-package-only-one (symbol-name keyword) args
|
||||
#'(lambda (label arg)
|
||||
(cond
|
||||
((stringp arg) arg)
|
||||
((use-package-non-nil-symbolp arg) (symbol-name arg))
|
||||
(t
|
||||
(use-package-error
|
||||
":pin wants an archive name (a string)"))))))
|
||||
|
||||
(eval-when-compile
|
||||
(defvar package-pinned-packages)
|
||||
(defvar package-archives))
|
||||
|
||||
(defun use-package-archive-exists-p (archive)
|
||||
"Check if a given ARCHIVE is enabled.
|
||||
|
||||
ARCHIVE can be a string or a symbol or 'manual to indicate a
|
||||
manually updated package."
|
||||
(if (member archive '(manual "manual"))
|
||||
't
|
||||
(let ((valid nil))
|
||||
(dolist (pa package-archives)
|
||||
(when (member archive (list (car pa) (intern (car pa))))
|
||||
(setq valid 't)))
|
||||
valid)))
|
||||
|
||||
(defun use-package-pin-package (package archive)
|
||||
"Pin PACKAGE to ARCHIVE."
|
||||
(unless (boundp 'package-pinned-packages)
|
||||
(setq package-pinned-packages ()))
|
||||
(let ((archive-symbol (if (symbolp archive) archive (intern archive)))
|
||||
(archive-name (if (stringp archive) archive (symbol-name archive))))
|
||||
(if (use-package-archive-exists-p archive-symbol)
|
||||
(add-to-list 'package-pinned-packages (cons package archive-name))
|
||||
(error "Archive '%s' requested for package '%s' is not available."
|
||||
archive-name package))
|
||||
(unless (bound-and-true-p package--initialized)
|
||||
(package-initialize t))))
|
||||
|
||||
(defun use-package-handler/:pin (name keyword archive-name rest state)
|
||||
(let ((body (use-package-process-keywords name rest state))
|
||||
(pin-form (if archive-name
|
||||
`(use-package-pin-package ',(use-package-as-symbol name)
|
||||
,archive-name))))
|
||||
;; Pinning should occur just before ensuring
|
||||
;; See `use-package-handler/:ensure'.
|
||||
(if (bound-and-true-p byte-compile-current-file)
|
||||
(eval pin-form) ; Eval when byte-compiling,
|
||||
(push pin-form body)) ; or else wait until runtime.
|
||||
body))
|
||||
|
||||
;;;; :ensure
|
||||
|
||||
(defvar package-archive-contents)
|
||||
|
||||
(defun use-package-normalize/:ensure (name 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 ":ensure wants an optional package name "
|
||||
"(an unquoted symbol name)")))))))
|
||||
|
||||
(defun use-package-ensure-elpa (name ensure state &optional no-refresh)
|
||||
(let ((package
|
||||
(or (and (eq ensure t) (use-package-as-symbol name))
|
||||
ensure)))
|
||||
(when package
|
||||
(require 'package)
|
||||
(unless (package-installed-p package)
|
||||
(condition-case-unless-debug err
|
||||
(progn
|
||||
(when (assoc package (bound-and-true-p
|
||||
package-pinned-packages))
|
||||
(package-read-all-archive-contents))
|
||||
(if (assoc package package-archive-contents)
|
||||
(package-install package)
|
||||
(package-refresh-contents)
|
||||
(when (assoc package (bound-and-true-p
|
||||
package-pinned-packages))
|
||||
(package-read-all-archive-contents))
|
||||
(package-install package))
|
||||
t)
|
||||
(error
|
||||
(ignore
|
||||
(display-warning 'use-package
|
||||
(format "Failed to install %s: %s"
|
||||
name (error-message-string err))
|
||||
:error))))))))
|
||||
|
||||
(defun use-package-handler/:ensure (name keyword ensure rest state)
|
||||
(let* ((body (use-package-process-keywords name rest state)))
|
||||
;; We want to avoid installing packages when the `use-package' macro is
|
||||
;; being macro-expanded by elisp completion (see `lisp--local-variables'),
|
||||
;; but still install packages when byte-compiling, to avoid requiring
|
||||
;; `package' at runtime.
|
||||
(if (bound-and-true-p byte-compile-current-file)
|
||||
;; Eval when byte-compiling,
|
||||
(funcall use-package-ensure-function name ensure state)
|
||||
;; or else wait until runtime.
|
||||
(push `(,use-package-ensure-function ',name ',ensure ',state)
|
||||
body))
|
||||
body))
|
||||
|
||||
(add-to-list 'use-package-defaults
|
||||
'(:ensure use-package-always-ensure
|
||||
(lambda (args)
|
||||
(and use-package-always-ensure
|
||||
(not (plist-member args :load-path))))) t)
|
||||
|
||||
(add-to-list 'use-package-defaults
|
||||
'(:pin use-package-always-pin use-package-always-pin) t)
|
||||
|
||||
(add-to-list 'use-package-keywords :ensure)
|
||||
(add-to-list 'use-package-keywords :pin)
|
||||
|
||||
(provide 'up-ensure)
|
Loading…
Add table
Reference in a new issue