aboutsummaryrefslogtreecommitdiffstats
path: root/site-lisp/bind-key-2.4.1/bind-chord.el
diff options
context:
space:
mode:
authorAstounds <kirito@disroot.org>2026-08-07 16:18:49 -0500
committerAstounds <kirito@disroot.org>2026-08-07 16:18:49 -0500
commit79e04842d239770fbe86bcfa60c693480a6b60cc (patch)
tree24006eab643de7333e24ab80f96ac032766ddeb9 /site-lisp/bind-key-2.4.1/bind-chord.el
parente90e5cfbc6ca58c26a91a6b449b017b1102069be (diff)
downloademacs-personal-79e04842d239770fbe86bcfa60c693480a6b60cc.tar.lz
emacs-personal-79e04842d239770fbe86bcfa60c693480a6b60cc.tar.xz
emacs-personal-79e04842d239770fbe86bcfa60c693480a6b60cc.zip
test
Diffstat (limited to 'site-lisp/bind-key-2.4.1/bind-chord.el')
-rw-r--r--site-lisp/bind-key-2.4.1/bind-chord.el103
1 files changed, 103 insertions, 0 deletions
diff --git a/site-lisp/bind-key-2.4.1/bind-chord.el b/site-lisp/bind-key-2.4.1/bind-chord.el
new file mode 100644
index 0000000..bf0f586
--- /dev/null
+++ b/site-lisp/bind-key-2.4.1/bind-chord.el
@@ -0,0 +1,103 @@
+;;; bind-chord.el --- key-chord binding helper for use-package-chords -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2015-2022 Free Software Foundation, Inc.
+
+;; Author: Justin Talbott <justin@waymondo.com>
+;; Keywords: convenience, tools, extensions
+;; 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
+;;
+
+;;; Commentary:
+;;
+
+;;; Code:
+
+(require 'bind-key)
+(require 'key-chord nil t)
+
+;;;###autoload
+(defmacro bind-chord (chord command &optional keymap)
+ "Bind CHORD to COMMAND in KEYMAP (`global-map' if not passed)."
+ (let ((key1 (logand 255 (aref chord 0)))
+ (key2 (logand 255 (aref chord 1))))
+ (if (eq key1 key2)
+ `(bind-key (vector 'key-chord ,key1 ,key2) ,command ,keymap)
+ `(progn
+ (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.
+
+Accepts keyword argument:
+: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)."
+ (macroexp-progn (bind-chords-form args nil)))
+
+(provide 'bind-chord)
+
+;;; bind-chord.el ends here