Skip to content

Commit

Permalink
Use loop with read-event in keypad (meow-edit#680)
Browse files Browse the repository at this point in the history
* Use loop with read-event in keypad

* Display popup right after switching to keypad

* Fix non-ascii key handling in keypad

* Fix meow-keypad-start, meow-keypad-start-with and meow-keypad-describe-key

* Remove keymap-lookup usage

* Fix some docs
  • Loading branch information
DogLooksGood authored Dec 1, 2024
1 parent cde5f4c commit 8ae8b2c
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 146 deletions.
8 changes: 4 additions & 4 deletions meow-cheatsheet.el
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ Currently `meow-cheatsheet-layout-qwerty', `meow-cheatsheet-layout-dvorak',
(goto-char (point-min))
(when (search-forward tgt nil t)
(let ((x (- (point) (line-beginning-position))))
(backward-delete-char 9)
(delete-char -9)
(insert (concat " " upper " "))
(forward-line 1)
(forward-char x)
(backward-delete-char 9)
(delete-char -9)
(insert (propertize (meow--short-command-name upper-cmd) 'face 'meow-cheatsheet-highlight))
(forward-line 2)
(forward-char x)
(backward-delete-char 9)
(delete-char -9)
(insert (concat " " lower " "))
(forward-line 1)
(forward-char x)
(backward-delete-char 9)
(delete-char -9)
(insert (propertize (meow--short-command-name lower-cmd) 'face 'meow-cheatsheet-highlight)))))))

(defun meow--cheatsheet-render-char-thing-table (&optional key-face)
Expand Down
26 changes: 0 additions & 26 deletions meow-command.el
Original file line number Diff line number Diff line change
Expand Up @@ -1734,30 +1734,6 @@ Use negative argument for backward application."
(goto-char (max (point) (overlay-end ov))))
(delete-overlay ov))))))))

(defun meow-start-kmacro ()
"Start kmacro.
This command is a replacement for built-in `kmacro-start-macro'."
(interactive)
(cond
((or (meow-normal-mode-p) (meow-motion-mode-p))
(call-interactively #'kmacro-start-macro))
(t
(message "Can only start recording in NORMAL or MOTION state."))))

(defun meow-start-kmacro-or-insert-counter ()
"Start kmacro or insert counter.
This command is a replacement for built-in
`kmacro-start-macro-or-insert-counter'."
(interactive)
(cond
((or defining-kbd-macro executing-kbd-macro)
(call-interactively #'kmacro-insert-counter))
((or (meow-normal-mode-p) (meow-motion-mode-p))
(call-interactively #'kmacro-start-macro-or-insert-counter))
(t (message "Can only start recording in NORMAL or MOTION state."))))

(defun meow-end-or-call-kmacro ()
"End kmacro recording or call macro.
Expand All @@ -1781,8 +1757,6 @@ This command is a replacement for built-in `kmacro-end-or-call-macro'."
This command is a replacement for built-in `kmacro-end-macro'."
(interactive)
(cond
(meow--keypad-this-command
(message "Can't end kmacro with KEYPAD command"))
((or (meow-normal-mode-p)
(meow-motion-mode-p))
(call-interactively #'kmacro-end-or-call-macro))
Expand Down
10 changes: 3 additions & 7 deletions meow-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@
(meow-define-state keypad
"Meow KEYPAD state minor mode."
:lighter " [K]"
:keymap meow-keypad-state-keymap
:face meow-keypad-cursor
(when meow-keypad-mode
(setq meow--prefix-arg current-prefix-arg
meow--keypad-keymap-description-activated nil
meow--keypad-allow-quick-dispatch t
meow--keypad-keymap-description-activated nil
meow--keypad-allow-quick-dispatch t
meow--keypad-base-keymap nil
meow--keypad-keys nil
meow--use-literal nil
meow--use-meta nil
meow--use-both nil)))
Expand Down Expand Up @@ -162,7 +160,7 @@ there's no chance for meow to call an init function."
(meow--cancel-second-selection)))

(defun meow--enable-theme-advice (theme)
"Prepare face if the theme to enable is `user'."
"Prepare face if the THEME to enable is `user'."
(when (eq theme 'user)
(meow--prepare-face)))

Expand All @@ -187,8 +185,6 @@ there's no chance for meow to call an init function."
`((meow-motion-mode . ,meow-motion-state-keymap)))
(add-to-ordered-list 'emulation-mode-map-alists
`((meow-normal-mode . ,meow-normal-state-keymap)))
(add-to-ordered-list 'emulation-mode-map-alists
`((meow-keypad-mode . ,meow-keypad-state-keymap)))
(add-to-ordered-list 'emulation-mode-map-alists
`((meow-beacon-mode . ,meow-beacon-state-keymap)))
(when meow-use-cursor-position-hack
Expand Down
3 changes: 2 additions & 1 deletion meow-helpers.el
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ meow--set-cursor-type and meow--set-cursor-color."
`(,name . ,(upcase (symbol-name name))))
(add-to-list 'meow-update-cursor-functions-alist
`(,activep . ,cursorf))
(add-to-list 'meow-keymap-alist `(,name . ,keymap)))
(when keymap
(add-to-list 'meow-keymap-alist `(,name . ,keymap))))

;;;###autoload
(defmacro meow-define-state (name-sym
Expand Down
41 changes: 9 additions & 32 deletions meow-keymap.el
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

(require 'meow-var)

(declare-function meow-describe-key "meow-command")
(declare-function meow-end-or-call-kmacro "meow-command")
(declare-function meow-end-kmacro "meow-command")

(defvar meow-keymap
(let ((keymap (make-sparse-keymap)))
(define-key keymap [remap describe-key] #'meow-describe-key)
Expand All @@ -33,8 +37,6 @@
(defvar meow-insert-state-keymap
(let ((keymap (make-keymap)))
(define-key keymap [escape] 'meow-insert-exit)
(define-key keymap [remap kmacro-start-macro] #'meow-start-kmacro)
(define-key keymap [remap kmacro-start-macro-or-insert-counter] #'meow-start-kmacro-or-insert-counter)
(define-key keymap [remap kmacro-end-or-call-macro] #'meow-end-or-call-kmacro)
(define-key keymap [remap kmacro-end-macro] #'meow-end-kmacro)
keymap)
Expand All @@ -60,8 +62,6 @@
(define-key keymap (kbd "SPC") 'meow-keypad)
(define-key keymap (kbd "i") 'meow-insert)
(define-key keymap (kbd "a") 'meow-append)
(define-key keymap [remap kmacro-start-macro] #'meow-start-kmacro)
(define-key keymap [remap kmacro-start-macro-or-insert-counter] #'meow-start-kmacro-or-insert-counter)
(define-key keymap [remap kmacro-end-or-call-macro] #'meow-end-or-call-kmacro)
(define-key keymap [remap kmacro-end-macro] #'meow-end-kmacro)
keymap)
Expand All @@ -77,33 +77,13 @@
(defvar meow-keypad-state-keymap
(let ((map (make-sparse-keymap)))
(suppress-keymap map t)
(define-key map [remap self-insert-command] 'meow-keypad-self-insert)
(define-key map [remap kmacro-start-macro] #'meow-start-kmacro)
(define-key map [remap kmacro-start-macro-or-insert-counter] #'meow-start-kmacro-or-insert-counter)
(define-key map [remap kmacro-end-or-call-macro] #'meow-end-or-call-kmacro)
(define-key map [remap kmacro-end-macro] #'meow-end-kmacro)
(let ((i ?\s))
(while (< i 256)
(define-key map (vector i) 'meow-keypad-self-insert)
(setq i (1+ i)))
(define-key map (kbd "DEL") 'meow-keypad-undo)
(define-key map (kbd "<backspace>") 'meow-keypad-undo)
(define-key map (kbd "<escape>") 'meow-keypad-quit)
(define-key map [remap keyboard-quit] 'meow-keypad-quit)
(define-key map (kbd "<deletechar>") 'meow-keypad-self-insert)
(define-key map (kbd "<tab>") 'meow-keypad-self-insert)
(define-key map (kbd "TAB") 'meow-keypad-self-insert)
(define-key map (kbd "<return>") 'meow-keypad-self-insert)
(define-key map (kbd "<up>") 'meow-keypad-self-insert)
(define-key map (kbd "<down>") 'meow-keypad-self-insert)
(define-key map (kbd "<left>") 'meow-keypad-self-insert)
(define-key map (kbd "<right>") 'meow-keypad-self-insert)
(define-key map (kbd "<home>") 'meow-keypad-self-insert)
(define-key map (kbd "<end>") 'meow-keypad-self-insert)
(define-key map (kbd "<next>") 'meow-keypad-self-insert)
(define-key map (kbd "<prior>") 'meow-keypad-self-insert)
(define-key map (kbd "<insert>") 'meow-keypad-self-insert)
(define-key map (kbd "RET") 'meow-keypad-self-insert))
(define-key map (kbd "DEL") 'meow-keypad-undo)
(define-key map (kbd "<backspace>") 'meow-keypad-undo)
(define-key map (kbd "<escape>") 'meow-keypad-quit)
(define-key map (kbd "ESC") 'meow-keypad-quit)
(define-key map [remap keyboard-quit] 'meow-keypad-quit)
map)
"Keymap for Meow keypad state.")

Expand All @@ -123,9 +103,6 @@
(define-key map [remap kmacro-end-or-call-macro] 'meow-beacon-apply-kmacro)
(define-key map [remap kmacro-start-macro-or-insert-counter] 'meow-beacon-start)
(define-key map [remap kmacro-start-macro] 'meow-beacon-start)

(define-key map [remap meow-start-kmacro] 'meow-beacon-start)
(define-key map [remap meow-start-kmacro-or-insert-counter] 'meow-beacon-start)
(define-key map [remap meow-end-or-call-kmacro] 'meow-beacon-apply-kmacro)

;; noops
Expand Down
Loading

0 comments on commit 8ae8b2c

Please sign in to comment.