[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/guru-mode 1086b77 20/42: only block keys with bindings in
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/guru-mode 1086b77 20/42: only block keys with bindings in global-map |
Date: |
Wed, 11 Aug 2021 09:58:29 -0400 (EDT) |
branch: elpa/guru-mode
commit 1086b77b7c037fbbaf76b55d4df786697e3d7bee
Author: Charles Lowell <cowboyd@frontside.io>
Commit: Charles Lowell <cowboyd@frontside.io>
only block keys with bindings in global-map
Some minor-modes "reclaim" key sequences that are better used through
their "guru" mappings. An example is smartparens, which binds <C-right>
to `sp-slurp-forward-sexp` or drag-stuff, which binds <M-up> to
`drag-stuff-up`. In these instances, we want to check if the key has
been remapped elsewhere before blocking it.
`guru-affected-bindings-list` has been modified to also contain a
reference to the original key binding. If, upon entering the original
key sequence, the bound function is different than the original binding,
then we let it proceed unhindered.
Some additional fixes:
* remove <M-up> and <M-down> remappings which are not bound to
anything by default.
* point <home> and <end> to beginning-of-buffer and end-of-buffer
respectively, since these are what they are bound to by default
---
guru-mode.el | 70 ++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 40 insertions(+), 30 deletions(-)
diff --git a/guru-mode.el b/guru-mode.el
index 1d75347..885be81 100644
--- a/guru-mode.el
+++ b/guru-mode.el
@@ -39,41 +39,51 @@
"When non-nil you'll only get an error message.")
(defvar guru-affected-bindings-list
- '(("<left>" . "C-b")
- ("<right>" . "C-f")
- ("<up>" . "C-p")
- ("<down>" . "C-n")
- ("<C-left>" . "M-b")
- ("<C-right>" . "M-f")
- ("<C-up>" . "M-{")
- ("<C-down>" . "M-}")
- ("<M-left>" . "M-b")
- ("<M-right>" . "M-f")
- ("<M-up>" . "M-{")
- ("<M-down>" . "M-}")
- ("<delete>" . "C-d")
- ("<C-delete>" . "M-d")
- ("<M-delete>" . "M-d")
- ("<next>" . "C-v")
- ("<C-next>" . "M-x <")
- ("<prior>" . "M-v")
- ("<C-prior>" . "M-x >")
- ("<home>" . "C-a")
- ("<C-home>" . "M-<")
- ("<end>" . "C-e")
- ("<C-end>" . "M->")))
+ '(("<left>" "C-b" left-char)
+ ("<right>" "C-f" right-char)
+ ("<up>" "C-p" previous-line)
+ ("<down>" "C-n" next-line)
+ ("<C-left>" "M-b" left-word)
+ ("<C-right>" "M-f" right-word)
+ ("<C-up>" "M-{" backward-paragraph)
+ ("<C-down>" "M-}" forward-paragraph)
+ ("<M-left>" "M-b" left-word)
+ ("<M-right>" "M-f" right-word)
+ ("<delete>" "C-d" delete-char)
+ ("<C-delete>" "M-d" kill-word)
+ ("<next>" "C-v" scroll-up-command)
+ ("<C-next>" "M-x <" scroll-left)
+ ("<prior>" "M-v" scroll-down-command)
+ ("<C-prior>" "M-x >" scroll-right)
+ ("<home>" "M-<" beginning-of-buffer)
+ ("<C-home>" "M-<" beginning-of-buffer)
+ ("<end>" "M->" end-of-buffer)
+ ("<C-end>" "M->" end-of-buffer)))
-(defun guru-rebind (original-key alt-key)
+(defun guru-current-key-binding (key)
+ "Look up the current binding for KEY without guru-mode."
+ (prog2 (guru-mode -1) (key-binding (kbd key)) (guru-mode +1)))
+
+(defun guru-rebind (original-key alt-key original-binding)
(lambda ()
(interactive)
- (let ((warning-text (if guru-warn-only "discouraged" "disabled")))
- (message "%s keybinding is %s! Use <%s> instead" original-key
warning-text alt-key))
- (when guru-warn-only
- (call-interactively (key-binding (kbd alt-key))))))
+ (let ((current-binding (guru-current-key-binding original-key)))
+ (if (eq current-binding original-binding)
+ (progn
+ (let ((warning-text (if guru-warn-only "discouraged" "disabled")))
+ (message "%s keybinding is %s! Use <%s> instead" original-key
warning-text alt-key))
+ (when guru-warn-only
+ (call-interactively (key-binding (kbd alt-key)))))
+ ;; else: the key has been re-mapped from the global default,
+ ;; use it without interference.
+ (call-interactively current-binding)))))
(dolist (cell guru-affected-bindings-list)
- (define-key guru-mode-map
- (read-kbd-macro (car cell)) (guru-rebind (car cell) (cdr cell))))
+ (let ((original-key (car cell))
+ (recommended-key (car (cdr cell)))
+ (original-binding (car (cdr (cdr cell)))))
+ (define-key guru-mode-map
+ (read-kbd-macro (car cell)) (guru-rebind original-key recommended-key
original-binding))))
;;;###autoload
(define-minor-mode guru-mode
- [nongnu] elpa/guru-mode 4decfe5 06/42: get rid of the useless concat, (continued)
- [nongnu] elpa/guru-mode 4decfe5 06/42: get rid of the useless concat, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode 5e117f2 05/42: renamed to guru-mode, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode be0e3aa 11/42: Merge pull request #3 from dneelyep/master, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode 62058a8 07/42: added missing autoload, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode a4f88ba 03/42: renamed to guru-mode, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode 12d55ac 04/42: Update master, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode 3221bcd 08/42: provided a non-global version of guru-mode, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode 62a9a00 16/42: Bump version to 0.2, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode fc9dc59 17/42: Clean up a bit, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode b33e4d1 18/42: Update hook example, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode 1086b77 20/42: only block keys with bindings in global-map,
ELPA Syncer <=
- [nongnu] elpa/guru-mode db23636 21/42: Merge pull request #5 from cowboyd/allow-minor-modes-to-reclaim-beginner-keys, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode eb38fb2 23/42: Fix delete key handling, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode 062a417 27/42: Merge pull request #8 from ThibautVerron/keybindings-horizontal-scroll, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode fd80d94 14/42: added contribution guidelines, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode da632fa 26/42: Merge pull request #10 from syohex/update-url, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode ba88b73 09/42: minor documentation update, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode adf92d9 12/42: docs & code clean-up, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode a227ee5 15/42: Add the ability to only warn when arrow keys are being used, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode 704a47d 25/42: Update MELPA URL, ELPA Syncer, 2021/08/11
- [nongnu] elpa/guru-mode c180e05 30/42: Change "Home" and "End" replacements, ELPA Syncer, 2021/08/11