From f809d39fa15c564ec6ea110571226903ecd2ce9c Mon Sep 17 00:00:00 2001 From: ztDell <> Date: Wed, 18 Sep 2024 15:57:17 +0800 Subject: [PATCH 1/2] add: key-seq-define-evil --- key-seq.el | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/key-seq.el b/key-seq.el index 020902b..8ebc257 100644 --- a/key-seq.el +++ b/key-seq.el @@ -7,7 +7,7 @@ ;; Maintainer: Vyacheslav Levit ;; Version: 1.0.1 ;; Created: 15 June 2015 -;; Package-Requires: ((key-chord "0.6")) +;; Package-Requires: ((key-chord "0.6") (evil "1.15.0")) ;; Keywords: convenience keyboard keybindings ;; URL: http://github.com/vlevit/key-seq.el @@ -63,6 +63,8 @@ ;;; Code: ;;;###autoload +(require 'evil) + (defun key-seq-define-global (keys command) "Define a key sequence of the two keys in KEYS starting a COMMAND. \nKEYS can be a string or a vector of two elements. Currently only elements @@ -101,6 +103,22 @@ If COMMAND is nil, the key-chord is removed." (define-key keymap (vector 'key-chord key1 key2) command) (define-key keymap (vector 'key-chord key1 key2) command)))) +(defun key-seq-define-evil (state keymap keys command) + "Define in KEYMAP, a key sequence of the two keys in KEYS starting a COMMAND. +\nKEYS can be a string or a vector of two elements. Currently only elements +that corresponds to ascii codes in the range 32 to 126 can be used. +\nCOMMAND can be an interactive function, a string, or nil. +If COMMAND is nil, the key-chord is removed." + (if (/= 2 (length keys)) + (error "Key-chord keys must have two elements")) + ;; Exotic chars in a string are >255 but define-key wants 128..255 for those + (let ((key1 (logand 255 (aref keys 0))) + (key2 (logand 255 (aref keys 1)))) + ;; (define-key keymap (vector 'key-chord key1 key2) command) + (evil-define-key state keymap (vector 'key-chord key1 key2) command) + ) + ) + (defun key-seq-unset-global (keys) "Remove global key sequence of the two keys in KEYS." (interactive "sUnset key sequence globally (2 keys): ") From 899f63c318d8c8505d6e75b3a871118f625fb09b Mon Sep 17 00:00:00 2001 From: ztDell <> Date: Wed, 26 Aug 2026 15:51:52 +0800 Subject: [PATCH 2/2] Fix key-seq-define-evil under lexical-binding Enable lexical-binding and switch key-seq-define-evil from the `evil-define-key` macro to the `evil-define-key*` function form. `evil-define-key` expands to a `boundp` check on the keymap argument; with lexical-binding a lexically scoped parameter is invisible to `boundp`, so the binding was deferred to `after-load-functions` and never applied. `evil-define-key*` binds immediately. --- key-seq.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/key-seq.el b/key-seq.el index 8ebc257..319e5f2 100644 --- a/key-seq.el +++ b/key-seq.el @@ -1,4 +1,4 @@ -;;; key-seq.el --- map pairs of sequentially pressed keys to commands +;;; key-seq.el --- map pairs of sequentially pressed keys to commands -*- lexical-binding: t; -*- ;; Copyright (C) 2015 Vyacheslav Levit ;; Copyright (C) 2003,2005,2008,2012 David Andersson @@ -115,7 +115,7 @@ If COMMAND is nil, the key-chord is removed." (let ((key1 (logand 255 (aref keys 0))) (key2 (logand 255 (aref keys 1)))) ;; (define-key keymap (vector 'key-chord key1 key2) command) - (evil-define-key state keymap (vector 'key-chord key1 key2) command) + (evil-define-key* state keymap (vector 'key-chord key1 key2) command) ) )