Skip to content

Commit

Permalink
Use loop with read-event in keypad (#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)

Check failure on line 85 in meow-keymap.el

View workflow job for this annotation

GitHub Actions / check (26.3, true)

This key sequence is reserved (see Key Binding Conventions in the Emacs Lisp manual)

Check failure on line 85 in meow-keymap.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

This key sequence is reserved (see Key Binding Conventions in the Emacs Lisp manual)

Check failure on line 85 in meow-keymap.el

View workflow job for this annotation

GitHub Actions / check (28.2, true)

This key sequence is reserved (see Key Binding Conventions in the Emacs Lisp manual)
(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

2 comments on commit 8ae8b2c

@jixiuf
Copy link
Contributor

@jixiuf jixiuf commented on 8ae8b2c Dec 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keypad is broken after this commit
got funcall: Symbol’s function definition is void: nil
after space+k or space+1

emacs -q -L . -l meow.el
  (defun meow-setup ()
    (setq meow-cheatsheet-layout meow-cheatsheet-layout-qwerty)
    (meow-motion-overwrite-define-key
     '("j" . meow-next)
     '("k" . meow-prev)
     '("<escape>" . ignore))
    (meow-leader-define-key
     ;; SPC j/k will run the original command in MOTION state.
     '("j" . "H-j")
     '("k" . "H-k")
     ;; Use SPC (0-9) for digit arguments.
     '("1" . meow-digit-argument)
     '("2" . meow-digit-argument)
     '("3" . meow-digit-argument)
     '("4" . meow-digit-argument)
     '("5" . meow-digit-argument)
     '("6" . meow-digit-argument)
     '("7" . meow-digit-argument)
     '("8" . meow-digit-argument)
     '("9" . meow-digit-argument)
     '("0" . meow-digit-argument)
     '("/" . meow-keypad-describe-key)
     '("?" . meow-cheatsheet))
    (meow-normal-define-key
     '("0" . meow-expand-0)
     '("9" . meow-expand-9)
     '("8" . meow-expand-8)
     '("7" . meow-expand-7)
     '("6" . meow-expand-6)
     '("5" . meow-expand-5)
     '("4" . meow-expand-4)
     '("3" . meow-expand-3)
     '("2" . meow-expand-2)
     '("1" . meow-expand-1)
     '("-" . negative-argument)
     '(";" . meow-reverse)
     '("," . meow-inner-of-thing)
     '("." . meow-bounds-of-thing)
     '("[" . meow-beginning-of-thing)
     '("]" . meow-end-of-thing)
     '("a" . meow-append)
     '("A" . meow-open-below)
     '("b" . meow-back-word)
     '("B" . meow-back-symbol)
     '("c" . meow-change)
     '("d" . meow-delete)
     '("D" . meow-backward-delete)
     '("e" . meow-next-word)
     '("E" . meow-next-symbol)
     '("f" . meow-find)
     '("g" . meow-cancel-selection)
     '("G" . meow-grab)
     '("h" . meow-left)
     '("H" . meow-left-expand)
     '("i" . meow-insert)
     '("I" . meow-open-above)
     '("j" . meow-next)
     '("J" . meow-next-expand)
     '("k" . meow-prev)
     '("K" . meow-prev-expand)
     '("l" . meow-right)
     '("L" . meow-right-expand)
     '("m" . meow-join)
     '("n" . meow-search)
     '("o" . meow-block)
     '("O" . meow-to-block)
     '("p" . meow-yank)
     '("q" . meow-quit)
     '("Q" . meow-goto-line)
     '("r" . meow-replace)
     '("R" . meow-swap-grab)
     '("s" . meow-kill)
     '("t" . meow-till)
     '("u" . meow-undo)
     '("U" . meow-undo-in-selection)
     '("v" . meow-visit)
     '("w" . meow-mark-word)
     '("W" . meow-mark-symbol)
     '("x" . meow-line)
     '("X" . meow-goto-line)
     '("y" . meow-save)
     '("Y" . meow-sync-grab)
     '("z" . meow-pop-selection)
     '("'" . repeat)
     '("<escape>" . ignore)))
  (require 'meow)
  (meow-setup)
  (meow-global-mode 1)

@DogLooksGood
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Please sign in to comment.