diff options
Diffstat (limited to 'lisp/use-package')
-rw-r--r-- | lisp/use-package/bind-chord.el | 83 | ||||
-rw-r--r-- | lisp/use-package/bind-key.el | 86 | ||||
-rw-r--r-- | lisp/use-package/use-package-bind-key.el | 7 | ||||
-rw-r--r-- | lisp/use-package/use-package-chords.el | 6 | ||||
-rw-r--r-- | lisp/use-package/use-package-core.el | 104 | ||||
-rw-r--r-- | lisp/use-package/use-package-ensure-system-package.el | 13 | ||||
-rw-r--r-- | lisp/use-package/use-package-ensure.el | 2 |
7 files changed, 237 insertions, 64 deletions
diff --git a/lisp/use-package/bind-chord.el b/lisp/use-package/bind-chord.el index e5184bff60e..ff19c81fc78 100644 --- a/lisp/use-package/bind-chord.el +++ b/lisp/use-package/bind-chord.el @@ -1,11 +1,11 @@ -;;; bind-chord.el --- key-chord binding helper for use-package-chords +;;; bind-chord.el --- key-chord binding helper for use-package-chords -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2017 Justin Talbott +;; Copyright (C) 2015-2019 Justin Talbott ;; Author: Justin Talbott <justin@waymondo.com> ;; Keywords: convenience, tools, extensions -;; URL: https://github.com/waymondo/use-package-chords -;; Version: 0.2 +;; URL: https://github.com/jwiegley/use-package +;; Version: 0.2.1 ;; Package-Requires: ((bind-key "1.0") (key-chord "0.6")) ;; Filename: bind-chord.el ;; License: GNU General Public License version 3, or (at your option) any later version @@ -30,6 +30,63 @@ (bind-key (vector 'key-chord ,key1 ,key2) ,command ,keymap) (bind-key (vector 'key-chord ,key2 ,key1) ,command ,keymap))))) +(defun bind-chords-form (args keymap) + "Bind multiple chords at once. + +Accepts keyword arguments: +:map MAP - a keymap into which the keybindings should be + added + +The rest of the arguments are conses of keybinding string and a +function symbol (unquoted)." + (let (map pkg) + (let ((cont t)) + (while (and cont args) + (if (cond ((eq :map (car args)) + (setq map (cadr args))) + ((eq :package (car args)) + (setq pkg (cadr args)))) + (setq args (cddr args)) + (setq cont nil)))) + + (unless map (setq map keymap)) + + (let (first next) + (while args + (if (keywordp (car args)) + (progn + (setq next args) + (setq args nil)) + (if first + (nconc first (list (car args))) + (setq first (list (car args)))) + (setq args (cdr args)))) + + (cl-flet + ((wrap (map bindings) + (if (and map pkg (not (memq map '(global-map + override-global-map)))) + `((if (boundp ',map) + ,(macroexp-progn bindings) + (eval-after-load + ,(if (symbolp pkg) `',pkg pkg) + ',(macroexp-progn bindings)))) + bindings))) + + (append + (wrap map + (cl-mapcan + (lambda (form) + (let ((fun (and (cdr form) (list 'function (cdr form))))) + (if (and map (not (eq map 'global-map))) + `((bind-chord ,(car form) ,fun ,map)) + `((bind-chord ,(car form) ,fun nil))))) + first)) + (when next + (bind-chords-form (if pkg + (cons :package (cons pkg next)) + next) map))))))) + ;;;###autoload (defmacro bind-chords (&rest args) "Bind multiple chords at once. @@ -39,23 +96,7 @@ Accepts keyword argument: The rest of the arguments are conses of keybinding string and a function symbol (unquoted)." - (let* ((map (plist-get args :map)) - (maps (if (listp map) map (list map))) - (key-bindings (progn - (while (keywordp (car args)) - (pop args) - (pop args)) - args))) - (macroexp-progn - (apply - #'nconc - (mapcar (lambda (form) - (if maps - (mapcar - #'(lambda (m) - `(bind-chord ,(car form) ',(cdr form) ,m)) maps) - `((bind-chord ,(car form) ',(cdr form))))) - key-bindings))))) + (macroexp-progn (bind-chords-form args nil))) (provide 'bind-chord) diff --git a/lisp/use-package/bind-key.el b/lisp/use-package/bind-key.el index 1d611c2933c..1f775711ef3 100644 --- a/lisp/use-package/bind-key.el +++ b/lisp/use-package/bind-key.el @@ -1,4 +1,4 @@ -;;; bind-key.el --- A simple way to manage personal keybindings +;;; bind-key.el --- A simple way to manage personal keybindings -*- lexical-binding: t; -*- ;; Copyright (c) 2012-2017 John Wiegley @@ -131,7 +131,8 @@ (define-minor-mode override-global-mode "A minor mode so that keymap settings override other modes." - t "") + :init-value t + :lighter "") ;; the keymaps in `emulation-mode-map-alists' take precedence over ;; `minor-mode-map-alist' @@ -159,7 +160,7 @@ For example: (bind-key \"M-h\" #'some-interactive-function my-mode-map) - (bind-key \"M-h\" #'some-interactive-function 'my-mode-map) + (bind-key \"M-h\" #'some-interactive-function \\='my-mode-map) If PREDICATE is non-nil, it is a form evaluated to determine when a key should be bound. It must return non-nil in such cases. @@ -172,8 +173,9 @@ can safely be called at any time." (kdescvar (make-symbol "kdesc")) (bindingvar (make-symbol "binding"))) `(let* ((,namevar ,key-name) - (,keyvar (if (vectorp ,namevar) ,namevar - (read-kbd-macro ,namevar))) + (,keyvar ,(if (stringp key-name) (read-kbd-macro key-name) + `(if (vectorp ,namevar) ,namevar + (read-kbd-macro ,namevar)))) (,kmapvar (or (if (and ,keymap (symbolp ,keymap)) (symbol-value ,keymap) ,keymap) global-map)) @@ -257,30 +259,60 @@ Accepts keyword arguments: for these bindings :prefix-docstring STR - docstring for the prefix-map variable :menu-name NAME - optional menu string for prefix map +:repeat-docstring STR - docstring for the repeat-map variable +:repeat-map MAP - name of the repeat map that should be created + for these bindings. If specified, the + `repeat-map' property of each command bound + (within the scope of the `:repeat-map' keyword) + is set to this map. +:exit BINDINGS - Within the scope of `:repeat-map' will bind the + key in the repeat map, but will not set the + `repeat-map' property of the bound command. +:continue BINDINGS - Within the scope of `:repeat-map' forces the + same behaviour as if no special keyword had + been used (that is, the command is bound, and + it's `repeat-map' property set) :filter FORM - optional form to determine when bindings apply The rest of the arguments are conses of keybinding string and a function symbol (unquoted)." (let (map - doc + prefix-doc prefix-map prefix + repeat-map + repeat-doc + repeat-type ;; Only used internally filter menu-name pkg) ;; Process any initial keyword arguments - (let ((cont t)) + (let ((cont t) + (arg-change-func 'cddr)) (while (and cont args) (if (cond ((and (eq :map (car args)) (not prefix-map)) (setq map (cadr args))) ((eq :prefix-docstring (car args)) - (setq doc (cadr args))) + (setq prefix-doc (cadr args))) ((and (eq :prefix-map (car args)) (not (memq map '(global-map override-global-map)))) (setq prefix-map (cadr args))) + ((eq :repeat-docstring (car args)) + (setq repeat-doc (cadr args))) + ((and (eq :repeat-map (car args)) + (not (memq map '(global-map + override-global-map)))) + (setq repeat-map (cadr args)) + (setq map repeat-map)) + ((eq :continue (car args)) + (setq repeat-type :continue + arg-change-func 'cdr)) + ((eq :exit (car args)) + (setq repeat-type :exit + arg-change-func 'cdr)) ((eq :prefix (car args)) (setq prefix (cadr args))) ((eq :filter (car args)) @@ -289,13 +321,17 @@ function symbol (unquoted)." (setq menu-name (cadr args))) ((eq :package (car args)) (setq pkg (cadr args)))) - (setq args (cddr args)) + (setq args (funcall arg-change-func args)) (setq cont nil)))) (when (or (and prefix-map (not prefix)) (and prefix (not prefix-map))) (error "Both :prefix-map and :prefix must be supplied")) + (when repeat-type + (unless repeat-map + (error ":continue and :exit require specifying :repeat-map"))) + (when (and menu-name (not prefix)) (error "If :menu-name is supplied, :prefix must be too")) @@ -327,13 +363,16 @@ function symbol (unquoted)." (append (when prefix-map `((defvar ,prefix-map) - ,@(when doc `((put ',prefix-map 'variable-documentation ,doc))) + ,@(when prefix-doc `((put ',prefix-map 'variable-documentation ,prefix-doc))) ,@(if menu-name `((define-prefix-command ',prefix-map nil ,menu-name)) `((define-prefix-command ',prefix-map))) ,@(if (and map (not (eq map 'global-map))) (wrap map `((bind-key ,prefix ',prefix-map ,map ,filter))) `((bind-key ,prefix ',prefix-map nil ,filter))))) + (when repeat-map + `((defvar ,repeat-map (make-sparse-keymap) + ,@(when repeat-doc `(,repeat-doc))))) (wrap map (cl-mapcan (lambda (form) @@ -341,13 +380,19 @@ function symbol (unquoted)." (if prefix-map `((bind-key ,(car form) ,fun ,prefix-map ,filter)) (if (and map (not (eq map 'global-map))) - `((bind-key ,(car form) ,fun ,map ,filter)) + ;; Only needed in this branch, since when + ;; repeat-map is non-nil, map is always + ;; non-nil + `(,@(when (and repeat-map (not (eq repeat-type :exit))) + `((put ,fun 'repeat-map ',repeat-map))) + (bind-key ,(car form) ,fun ,map ,filter)) `((bind-key ,(car form) ,fun nil ,filter)))))) first)) (when next - (bind-keys-form (if pkg - (cons :package (cons pkg next)) - next) map))))))) + (bind-keys-form `(,@(when repeat-map `(:repeat-map ,repeat-map)) + ,@(if pkg + (cons :package (cons pkg next)) + next)) map))))))) ;;;###autoload (defmacro bind-keys (&rest args) @@ -361,6 +406,19 @@ Accepts keyword arguments: for these bindings :prefix-docstring STR - docstring for the prefix-map variable :menu-name NAME - optional menu string for prefix map +:repeat-docstring STR - docstring for the repeat-map variable +:repeat-map MAP - name of the repeat map that should be created + for these bindings. If specified, the + `repeat-map' property of each command bound + (within the scope of the `:repeat-map' keyword) + is set to this map. +:exit BINDINGS - Within the scope of `:repeat-map' will bind the + key in the repeat map, but will not set the + `repeat-map' property of the bound command. +:continue BINDINGS - Within the scope of `:repeat-map' forces the + same behaviour as if no special keyword had + been used (that is, the command is bound, and + it's `repeat-map' property set) :filter FORM - optional form to determine when bindings apply The rest of the arguments are conses of keybinding string and a diff --git a/lisp/use-package/use-package-bind-key.el b/lisp/use-package/use-package-bind-key.el index e476b060ad6..9642f311750 100644 --- a/lisp/use-package/use-package-bind-key.el +++ b/lisp/use-package/use-package-bind-key.el @@ -86,13 +86,20 @@ deferred until the prefix key sequence is pressed." ;; :prefix-docstring STRING ;; :prefix-map SYMBOL ;; :prefix STRING + ;; :repeat-docstring STRING + ;; :repeat-map SYMBOL ;; :filter SEXP ;; :menu-name STRING ;; :package SYMBOL + ;; :continue and :exit are used within :repeat-map ((or (and (eq x :map) (symbolp (cadr arg))) (and (eq x :prefix) (stringp (cadr arg))) (and (eq x :prefix-map) (symbolp (cadr arg))) (and (eq x :prefix-docstring) (stringp (cadr arg))) + (and (eq x :repeat-map) (symbolp (cadr arg))) + (eq x :continue) + (eq x :exit) + (and (eq x :repeat-docstring) (stringp (cadr arg))) (eq x :filter) (and (eq x :menu-name) (stringp (cadr arg))) (and (eq x :package) (symbolp (cadr arg)))) diff --git a/lisp/use-package/use-package-chords.el b/lisp/use-package/use-package-chords.el index 547adc27427..cf390dbe593 100644 --- a/lisp/use-package/use-package-chords.el +++ b/lisp/use-package/use-package-chords.el @@ -1,11 +1,11 @@ ;;; use-package-chords.el --- key-chord keyword for use-package -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2017 Justin Talbott +;; Copyright (C) 2015-2019 Justin Talbott ;; Author: Justin Talbott <justin@waymondo.com> ;; Keywords: convenience, tools, extensions -;; URL: https://github.com/waymondo/use-package-chords -;; Version: 0.2 +;; URL: https://github.com/jwiegley/use-package +;; Version: 0.2.1 ;; Package-Requires: ((use-package "2.1") (bind-key "1.0") (bind-chord "0.2") (key-chord "0.6")) ;; Filename: use-package-chords.el ;; License: GNU General Public License version 3, or (at your option) any later version diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el index a82e7b145c7..dc9b77bc5bf 100644 --- a/lisp/use-package/use-package-core.el +++ b/lisp/use-package/use-package-core.el @@ -100,7 +100,8 @@ :load ;; This must occur almost last; the only forms which should appear after ;; are those that must happen directly after the config forms. - :config) + :config + :local) "The set of valid keywords, in the order they are processed in. The order of this list is *very important*, so it is only advisable to insert new keywords, never to delete or reorder @@ -316,14 +317,15 @@ include support for finding `use-package' and `require' forms. Must be set before loading use-package." :type 'boolean :set - #'(lambda (_sym value) + #'(lambda (sym value) (eval-after-load 'lisp-mode (if value `(add-to-list 'lisp-imenu-generic-expression (list "Packages" ,use-package-form-regexp-eval 2)) `(setq lisp-imenu-generic-expression (remove (list "Packages" ,use-package-form-regexp-eval 2) - lisp-imenu-generic-expression))))) + lisp-imenu-generic-expression)))) + (set-default sym value)) :group 'use-package) (defconst use-package-font-lock-keywords @@ -906,14 +908,14 @@ If RECURSED is non-nil, recurse into sublists." "A predicate that recognizes functional constructions: nil sym - 'sym + \\='sym (quote sym) - #'sym + #\\='sym (function sym) (lambda () ...) - '(lambda () ...) + \\='(lambda () ...) (quote (lambda () ...)) - #'(lambda () ...) + #\\='(lambda () ...) (function (lambda () ...))" (or (if binding (symbolp v) @@ -928,7 +930,7 @@ If RECURSED is non-nil, recurse into sublists." (defun use-package-normalize-function (v) "Reduce functional constructions to one of two normal forms: sym - #'(lambda () ...)" + #\\='(lambda () ...)" (cond ((symbolp v) v) ((and (listp v) (memq (car v) '(quote function)) @@ -998,11 +1000,10 @@ If RECURSED is non-nil, recurse into sublists." (defun use-package-statistics-last-event (package) "Return the date when PACKAGE's status last changed. The date is returned as a string." - (format-time-string "%Y-%m-%d %a %H:%M" - (or (gethash :config package) - (gethash :init package) - (gethash :preface package) - (gethash :use-package package)))) + (or (gethash :config package) + (gethash :init package) + (gethash :preface package) + (gethash :use-package package))) (defun use-package-statistics-time (package) "Return the time is took for PACKAGE to load." @@ -1022,7 +1023,9 @@ The information is formatted in a way suitable for (vector (symbol-name package) (use-package-statistics-status statistics) - (use-package-statistics-last-event statistics) + (format-time-string + "%H:%M:%S.%6N" + (use-package-statistics-last-event statistics)) (format "%.2f" (use-package-statistics-time statistics)))))) (defun use-package-report () @@ -1042,15 +1045,43 @@ meaning: (tabulated-list-print) (display-buffer (current-buffer)))) +(defvar use-package-statistics-status-order + '(("Declared" . 0) + ("Prefaced" . 1) + ("Initialized" . 2) + ("Configured" . 3))) + (define-derived-mode use-package-statistics-mode tabulated-list-mode "use-package statistics" "Show current statistics gathered about use-package declarations." (setq tabulated-list-format ;; The sum of column width is 80 characters: [("Package" 25 t) - ("Status" 13 t) - ("Last Event" 23 t) - ("Time" 10 t)]) + ("Status" 13 + (lambda (a b) + (< (assoc-default + (use-package-statistics-status + (gethash (car a) use-package-statistics)) + use-package-statistics-status-order) + (assoc-default + (use-package-statistics-status + (gethash (car b) use-package-statistics)) + use-package-statistics-status-order)))) + ("Last Event" 23 + (lambda (a b) + (< (float-time + (use-package-statistics-last-event + (gethash (car a) use-package-statistics))) + (float-time + (use-package-statistics-last-event + (gethash (car b) use-package-statistics)))))) + ("Time" 10 + (lambda (a b) + (< (use-package-statistics-time + (gethash (car a) use-package-statistics)) + (use-package-statistics-time + (gethash (car b) use-package-statistics)))))]) + (setq tabulated-list-sort-key '("Time" . t)) (tabulated-list-init-header)) (defun use-package-statistics-gather (keyword name after) @@ -1287,9 +1318,13 @@ meaning: (concat (symbol-name sym) use-package-hook-name-suffix))) (function ,fun))) - (if (use-package-non-nil-symbolp syms) (list syms) syms))))) + (use-package-hook-handler-normalize-mode-symbols syms))))) (use-package-normalize-commands args)))) +(defun use-package-hook-handler-normalize-mode-symbols (syms) + "Ensure that `SYMS' turns into a list of modes." + (if (use-package-non-nil-symbolp syms) (list syms) syms)) + ;;;; :commands (defalias 'use-package-normalize/:commands 'use-package-normalize-symlist) @@ -1520,6 +1555,31 @@ no keyword implies `:all'." (when use-package-compute-statistics `((use-package-statistics-gather :config ',name t)))))) +;;;; :local + +(defun use-package-normalize/:local (name keyword args) + (let ((first-arg-name (symbol-name (caar args)))) + (if (not (string-suffix-p "-hook" first-arg-name)) + (let* ((sym-name (symbol-name name)) + (addition (if (string-suffix-p "-mode" sym-name) + "-hook" + "-mode-hook")) + (hook (intern (concat sym-name addition)))) + `((,hook . ,(use-package-normalize-forms name keyword args)))) + (cl-loop for (hook . code) in args + collect `(,hook . ,(use-package-normalize-forms name keyword code)))))) + +(defun use-package-handler/:local (name _keyword arg rest state) + (let* ((body (use-package-process-keywords name rest state))) + (use-package-concat + body + (cl-loop for (hook . code) in arg + for func-name = (intern (concat "use-package-func/" (symbol-name hook))) + collect (progn + (push 'progn code) + `(defun ,func-name () ,code)) + collect `(add-hook ',hook ',func-name))))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; The main macro @@ -1600,13 +1660,13 @@ this file. Usage: :load-path Add to the `load-path' before attempting to load the package. :diminish Support for diminish.el (if installed). :delight Support for delight.el (if installed). -:custom Call `custom-set' or `set-default' with each variable +:custom Call `Custom-set' or `set-default' with each variable definition without modifying the Emacs `custom-file'. (compare with `custom-set-variables'). -:custom-face Call `customize-set-faces' with each face definition. +:custom-face Call `custom-set-faces' with each face definition. :ensure Loads the package using package.el if necessary. :pin Pin the package to an archive." - (declare (indent 1)) + (declare (indent defun)) (unless (memq :disabled args) (macroexp-progn (use-package-concat @@ -1625,8 +1685,6 @@ this file. Usage: (when use-package-compute-statistics `((use-package-statistics-gather :use-package ',name t))))))) -(put 'use-package 'lisp-indent-function 'defun) - (provide 'use-package-core) ;; Local Variables: diff --git a/lisp/use-package/use-package-ensure-system-package.el b/lisp/use-package/use-package-ensure-system-package.el index 87abf407020..7c591af7d9b 100644 --- a/lisp/use-package/use-package-ensure-system-package.el +++ b/lisp/use-package/use-package-ensure-system-package.el @@ -25,6 +25,8 @@ (eval-when-compile (declare-function system-packages-get-command "system-packages")) +(defvar use-package-ensure-system-package--custom-packages '() + "List of custom packages installed.") (defun use-package-ensure-system-package-consify (arg) "Turn `arg' into a cons of (`package-name' . `install-command')." @@ -38,15 +40,22 @@ ((not (cdr arg)) (use-package-ensure-system-package-consify (car arg))) ((stringp (cdr arg)) - (cons (car arg) `(async-shell-command ,(cdr arg)))) + (progn + (push (cdr arg) use-package-ensure-system-package--custom-packages) + (cons (car arg) `(async-shell-command ,(cdr arg))))) (t (cons (car arg) `(system-packages-install ,(symbol-name (cdr arg))))))))) +(defun use-package-ensure-system-package-update-custom-packages () + (interactive) + (dolist (cmd use-package-ensure-system-package--custom-packages) + (async-shell-command cmd))) + ;;;###autoload (defun use-package-normalize/:ensure-system-package (_name-symbol keyword args) "Turn `arg' into a list of cons-es of (`package-name' . `install-command')." - (use-package-only-one (symbol-name keyword) args + (use-package-as-one (symbol-name keyword) args (lambda (_label arg) (cond ((and (listp arg) (listp (cdr arg))) diff --git a/lisp/use-package/use-package-ensure.el b/lisp/use-package/use-package-ensure.el index 50005a9e990..cb31b4b7dd4 100644 --- a/lisp/use-package/use-package-ensure.el +++ b/lisp/use-package/use-package-ensure.el @@ -93,7 +93,7 @@ The default value uses package.el to install the package." (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 +ARCHIVE can be a string or a symbol or `manual' to indicate a manually updated package." (if (member archive '(manual "manual")) 't |