summaryrefslogtreecommitdiff
path: root/lisp/use-package
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/use-package')
-rw-r--r--lisp/use-package/bind-chord.el81
-rw-r--r--lisp/use-package/use-package-chords.el6
2 files changed, 64 insertions, 23 deletions
diff --git a/lisp/use-package/bind-chord.el b/lisp/use-package/bind-chord.el
index 0cb6b01857c..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 -*- 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/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