[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/meow 7598b4b96c 2/2: Consider local keybindings when movin
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/meow 7598b4b96c 2/2: Consider local keybindings when moving commands for the Motion state. (#517) |
Date: |
Tue, 30 Jan 2024 04:01:20 -0500 (EST) |
branch: elpa/meow
commit 7598b4b96ce9dbea1c336d3e9f15c03b6ed7bb8c
Author: okamsn <28612288+okamsn@users.noreply.github.com>
Commit: GitHub <noreply@github.com>
Consider local keybindings when moving commands for the Motion state. (#517)
Instead of directly binding `H-j` to what was bound to `j`, for example,
bind
`H-j` to an interactive lambda which first checks whether there is a local
binding for `j`. If there is, use that. If there is not, then call the
orignal
command bound to `j`.
This should fix using the overrides in Magit buffers (see #493), where the
command bound to `H-k` seems to be based on where point is located when
`meow--save-origin-commands` is run.
Co-authored-by: okamsn <okamsn@users.noreply.github.com>
---
meow-util.el | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/meow-util.el b/meow-util.el
index 4d581c6399..b92e3c5990 100644
--- a/meow-util.el
+++ b/meow-util.el
@@ -452,6 +452,17 @@ Looks up the state in meow-replace-state-name-list"
(t nil)))
(defun meow--save-origin-commands ()
+ "Save the commands overridden by the Motion map to modified bindings.
+
+The new key binding, modified by the prefix in
+`meow-motion-remap-prefix', is bound to a command that calls the
+command locally bound to the original key binding, or, if that is
+nil, the original command.
+
+For example, under the default and suggested settings, in a
+Magit status buffer, `k' could be bound to `meow-previous'
+and `H-k' would be bound to a command that would try
+to use the status buffer's original `k' binding at point."
(cl-loop for key-code being the key-codes of meow-motion-state-keymap do
(ignore-errors
(let* ((key (meow--parse-input-event key-code))
@@ -459,7 +470,16 @@ Looks up the state in meow-replace-state-name-list"
(when (and (commandp cmd)
(not (equal cmd 'undefined)))
(let ((rebind-key (concat meow-motion-remap-prefix key)))
- (local-set-key (kbd rebind-key) cmd)))))))
+ (local-set-key (kbd rebind-key)
+ (lambda ()
+ (interactive)
+ (call-interactively
+ ;; Local maps are those local to the
buffer
+ ;; or a region of the buffer.
+ (if-let ((local (lookup-key
(current-local-map) key)))
+ (or (command-remapping local)
+ local)
+ cmd))))))))))
(defun meow--prepare-region-for-kill ()
(when (and (equal 'line (cdr (meow--selection-type)))