Skip to content

Commit

Permalink
add fallback support for meta & ctrl-meta prefix in keypad
Browse files Browse the repository at this point in the history
  • Loading branch information
tianshu committed Jan 6, 2022
1 parent 9c36f3d commit 643aa5f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Enhancements
* Remap `describe-key` to `meow-describe-key` which handles the dispatched keybinds.
* Allow leader in beacon state(still can not switch to keypad).
* [#164](https://github.com/meow-edit/meow/issues/164) Add fallback support for meta & control-meta prefix in keypad.

### Bugs fixed
* [#148](https://github.com/meow-edit/meow/issues/148) Wrap `regexp-quote` for raw search in `meow-search`.
Expand Down
68 changes: 42 additions & 26 deletions meow-keypad.el
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@
(format "%s " meow--prefix-arg))
(t "")))

(defun meow--keypad-has-sub-meta-keymap-p ()
(and (not meow--use-literal)
(not meow--use-both)
(not meow--use-meta)
(or (not meow--keypad-keys)
(let* ((key-str (meow--keypad-format-keys nil))
(keymap (key-binding (kbd key-str))))
(and (keymapp keymap)
(lookup-key keymap (kbd "ESC")))))))

(defun meow--keypad-format-keys (&optional prompt)
"Return a display format for current input keys."
(let ((result ""))
Expand Down Expand Up @@ -187,10 +197,13 @@
(t
(when-let ((keymap (key-binding (read-kbd-macro input))))
(when (keymapp keymap)
(let ((km '())
(ignores (list meow-keypad-meta-prefix
meow-keypad-ctrl-meta-prefix
meow-keypad-literal-prefix)))
(let* ((km '())
(has-sub-meta (meow--keypad-has-sub-meta-keymap-p))
(ignores (if has-sub-meta
(list meow-keypad-meta-prefix
meow-keypad-ctrl-meta-prefix
meow-keypad-literal-prefix)
(list meow-keypad-literal-prefix))))
(map-keymap
(lambda (key def)
(when (member 'control (event-modifiers key))
Expand Down Expand Up @@ -388,28 +401,31 @@ try replacing the last modifier and try again."
(interactive)
(when-let ((e (meow--event-key last-input-event))
(key (meow--parse-input-event e)))
(cond
(meow--use-literal
(push (cons 'literal key)
meow--keypad-keys)
(setq meow--use-literal nil))
(meow--use-both
(push (cons 'both key) meow--keypad-keys)
(setq meow--use-both nil))
(meow--use-meta
(push (cons 'meta key) meow--keypad-keys)
(setq meow--use-meta nil))
((and (equal e meow-keypad-meta-prefix)
(not meow--use-meta))
(setq meow--use-meta t))
((and (equal e meow-keypad-ctrl-meta-prefix)
(not meow--use-both))
(setq meow--use-both t))
((and (equal e meow-keypad-literal-prefix)
(not meow--use-literal))
(setq meow--use-literal t))
(t
(push (cons 'control key) meow--keypad-keys)))
(let ((has-sub-meta (meow--keypad-has-sub-meta-keymap-p)))
(cond
(meow--use-literal
(push (cons 'literal key)
meow--keypad-keys)
(setq meow--use-literal nil))
(meow--use-both
(push (cons 'both key) meow--keypad-keys)
(setq meow--use-both nil))
(meow--use-meta
(push (cons 'meta key) meow--keypad-keys)
(setq meow--use-meta nil))
((and (equal e meow-keypad-meta-prefix)
(not meow--use-meta)
has-sub-meta)
(setq meow--use-meta t))
((and (equal e meow-keypad-ctrl-meta-prefix)
(not meow--use-both)
has-sub-meta)
(setq meow--use-both t))
((and (equal e meow-keypad-literal-prefix)
(not meow--use-literal))
(setq meow--use-literal t))
(t
(push (cons 'control key) meow--keypad-keys))))

;; Try execute if the input is valid.
(if (or meow--use-literal
Expand Down

0 comments on commit 643aa5f

Please sign in to comment.