Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions key-seq.el
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,7 +7,7 @@
;; Maintainer: Vyacheslav Levit <dev@vlevit.org>
;; 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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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): ")
Expand Down