From a14349f7ed4d5d7987502fa4646fe20ddfe1100e Mon Sep 17 00:00:00 2001 From: DogLooksGood Date: Sat, 30 Nov 2024 17:26:08 +0800 Subject: [PATCH 1/6] Use loop with read-event in keypad --- meow-command.el | 26 -------------- meow-keymap.el | 37 +++----------------- meow-keypad.el | 91 ++++++++++++++++++++++++++++++++----------------- meow-shims.el | 7 ++-- meow-var.el | 3 ++ 5 files changed, 73 insertions(+), 91 deletions(-) diff --git a/meow-command.el b/meow-command.el index 448b59d..b7d2581 100644 --- a/meow-command.el +++ b/meow-command.el @@ -1724,30 +1724,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. @@ -1771,8 +1747,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)) diff --git a/meow-keymap.el b/meow-keymap.el index 0aca757..e58c853 100644 --- a/meow-keymap.el +++ b/meow-keymap.el @@ -33,8 +33,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) @@ -60,8 +58,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) @@ -77,33 +73,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 "") 'meow-keypad-undo) - (define-key map (kbd "") 'meow-keypad-quit) - (define-key map [remap keyboard-quit] 'meow-keypad-quit) - (define-key map (kbd "") 'meow-keypad-self-insert) - (define-key map (kbd "") 'meow-keypad-self-insert) - (define-key map (kbd "TAB") 'meow-keypad-self-insert) - (define-key map (kbd "") 'meow-keypad-self-insert) - (define-key map (kbd "") 'meow-keypad-self-insert) - (define-key map (kbd "") 'meow-keypad-self-insert) - (define-key map (kbd "") 'meow-keypad-self-insert) - (define-key map (kbd "") 'meow-keypad-self-insert) - (define-key map (kbd "") 'meow-keypad-self-insert) - (define-key map (kbd "") 'meow-keypad-self-insert) - (define-key map (kbd "") 'meow-keypad-self-insert) - (define-key map (kbd "") 'meow-keypad-self-insert) - (define-key map (kbd "") '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 "") 'meow-keypad-undo) + (define-key map (kbd "") '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.") @@ -123,9 +99,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 diff --git a/meow-keypad.el b/meow-keypad.el index fd71f53..52736d7 100644 --- a/meow-keypad.el +++ b/meow-keypad.el @@ -118,7 +118,10 @@ meow--use-both nil meow--keypad-help nil) (setq overriding-local-map nil) - (meow--exit-keypad-state)) + (meow--keypad-clear-message) + (meow--exit-keypad-state) + ;; Return t to indicate the keypad loop should be stopped + t) (defun meow-keypad-quit () "Quit keypad state." @@ -222,6 +225,9 @@ keymap) km))))))) +(defun meow--keypad-clear-message () + (funcall meow-keypad-clear-describe-keymap-function)) + (defun meow--keypad-display-message () (let (overriding-local-map) (when meow-keypad-describe-keymap-function @@ -368,24 +374,30 @@ Returning DEF will result in a generated title." (propertize pre 'face 'font-lock-comment-face))) (propertize (meow--keypad-format-keys nil) 'face 'font-lock-string-face)))) +(defun meow--keypad-in-beacon-p () + (and (meow--beacon-inside-secondary-selection) + meow--beacon-overlays)) + (defun meow--keypad-execute (command) "Execute the COMMAND. If there are beacons, execute it at every beacon." - (cond - ((and meow-keypad-execute-on-beacons - (not defining-kbd-macro) - (not executing-kbd-macro) - (meow--beacon-inside-secondary-selection) - meow--beacon-overlays) - (call-interactively command) - (meow--beacon-apply-command command)) - (t - (call-interactively command)))) + (if (meow--keypad-in-beacon-p) + (cond + ((member command '(kmacro-start-macro kmacro-start-macro-or-insert-counter)) + (call-interactively 'meow-beacon-start)) + ((member command '(kmacro-end-macro meow-end-kmacro)) + (call-interactively 'meow-beacon-end-and-apply-kmacro)) + ((and (not defining-kbd-macro) + (not executing-kbd-macro) + meow-keypad-execute-on-beacons) + (call-interactively command) + (meow--beacon-apply-command command))) + (call-interactively command))) (defun meow--keypad-try-execute () - "Try execute command. + "Try execute command, return t when the translation progress can be ended. If there is a command available on the current key binding, try replacing the last modifier and try again." @@ -401,28 +413,36 @@ try replacing the last modifier and try again." (if meow--keypad-help (progn (meow--keypad-quit) - (describe-function cmd)) + (describe-function cmd) + t) (let ((meow--keypad-this-command cmd)) (meow--keypad-quit) (setq real-this-command cmd this-command cmd) - (meow--keypad-execute cmd)))) + (meow--keypad-execute cmd) + t))) ((keymapp cmd) (when meow-keypad-message (meow--keypad-show-message)) - (meow--keypad-display-message)) + (meow--keypad-display-message) + nil) ((equal 'control (caar meow--keypad-keys)) (setcar meow--keypad-keys (cons 'literal (cdar meow--keypad-keys))) (meow--keypad-try-execute)) (t (setq meow--prefix-arg nil) (message "%s is undefined" (meow--keypad-format-keys nil)) - (meow--keypad-quit)))))) - -(defun meow-keypad-self-insert () - "Default command when keypad state is enabled." - (interactive) - (setq this-command last-command) - (when-let* ((e (meow--event-key last-input-event)) + (meow--keypad-quit) + t))))) + +(defun meow--keypad-handle-input-with-keymap (input-event) + (let ((cmd (lookup-key meow-keypad-state-keymap (vector input-event)))) + (if cmd + (call-interactively cmd) + (meow--keypad-handle-input-event input-event)))) + +(defun meow--keypad-handle-input-event (input-event) + (meow--keypad-clear-message) + (when-let* ((e (meow--event-key input-event)) (key (meow--parse-input-event e))) (let ((has-sub-meta (meow--keypad-has-sub-meta-keymap-p))) (cond @@ -468,18 +488,15 @@ try replacing the last modifier and try again." meow--use-both) (progn (when meow-keypad-message (meow--keypad-show-message)) - (meow--keypad-display-message)) + (meow--keypad-display-message) + nil) (meow--keypad-try-execute)))) -(defun meow-keypad () - "Enter keypad state." +(defun meow-keypad-self-insert () + "Default command when keypad state is enabled." (interactive) (setq this-command last-command) - (setq meow--keypad-previous-state (meow--current-state)) - (meow--switch-state 'keypad) - (setq overriding-local-map meow-keypad-state-keymap - overriding-terminal-local-map nil) - (meow--keypad-display-message)) + (meow--keypad-handle-input-event last-input-event)) (defun meow-keypad-start () "Enter keypad state with current input as initial key sequences." @@ -490,7 +507,19 @@ try replacing the last modifier and try again." (setq overriding-local-map meow-keypad-state-keymap overriding-terminal-local-map nil meow--keypad-allow-quick-dispatch nil) - (call-interactively 'meow-keypad-self-insert)) + (meow--keypad-handle-input-event last-input-event) + (while (not (meow--keypad-handle-input-with-keymap (read-key))))) + +(defun meow-keypad () + "Enter keypad state and convert inputs." + (interactive) + (setq this-command last-command) + (setq meow--keypad-previous-state (meow--current-state)) + (meow--switch-state 'keypad) + (setq overriding-local-map meow-keypad-state-keymap + overriding-terminal-local-map nil + meow--keypad-allow-quick-dispatch t) + (while (not (meow--keypad-handle-input-with-keymap (read-key))))) (defun meow-keypad-start-with (input) "Enter keypad state with INPUT. diff --git a/meow-shims.el b/meow-shims.el index 6405f91..0767aac 100644 --- a/meow-shims.el +++ b/meow-shims.el @@ -396,8 +396,11 @@ Argument ENABLE non-nil means turn on." (if which-key-mode (setq meow-keypad-describe-keymap-function (lambda (keymap) - (which-key--create-buffer-and-show nil keymap nil (concat "Meow: " (meow--keypad-format-keys))))) - (setq meow-keypad-describe-keymap-function 'meow-describe-keymap))) + (which-key--create-buffer-and-show nil keymap nil (concat "Meow: " (meow--keypad-format-keys)))) + meow-keypad-clear-describe-keymap-function 'which-key--hide-popup) + + (setq meow-keypad-describe-keymap-function 'meow-describe-keymap + meow-keypad-clear-describe-keymap-function nil))) (defun meow--setup-which-key (enable) (setq meow--which-key-setup enable) diff --git a/meow-var.el b/meow-var.el index 2debe76..da44f0e 100644 --- a/meow-var.el +++ b/meow-var.el @@ -353,6 +353,9 @@ Currently, keypad is not working well with which-key, so Meow ships a default `meow-describe-keymap'. Use (setq meow-keypad-describe-keymap-function \\='nil) to disable popup.") +(defvar meow-keypad-clear-describe-keymap-function nil + "The function used to clear the effect of `meow-keypad-describe-keymap-function'.") + (defvar meow-keypad-get-title-function 'meow-keypad-get-title "The function used to get the title of a keymap or command.") From b246a61450bd4a916db56c1eb49d5361a684ee78 Mon Sep 17 00:00:00 2001 From: DogLooksGood Date: Sat, 30 Nov 2024 18:56:43 +0800 Subject: [PATCH 2/6] Display popup right after switching to keypad --- meow-keypad.el | 1 + 1 file changed, 1 insertion(+) diff --git a/meow-keypad.el b/meow-keypad.el index 52736d7..a8dfdcf 100644 --- a/meow-keypad.el +++ b/meow-keypad.el @@ -519,6 +519,7 @@ try replacing the last modifier and try again." (setq overriding-local-map meow-keypad-state-keymap overriding-terminal-local-map nil meow--keypad-allow-quick-dispatch t) + (meow--keypad-display-message) (while (not (meow--keypad-handle-input-with-keymap (read-key))))) (defun meow-keypad-start-with (input) From 989add22068f4def6e4eeaf70a1d1d83b1257c1e Mon Sep 17 00:00:00 2001 From: DogLooksGood Date: Sat, 30 Nov 2024 23:26:14 +0800 Subject: [PATCH 3/6] Fix non-ascii key handling in keypad --- meow-keypad.el | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/meow-keypad.el b/meow-keypad.el index a8dfdcf..11469c6 100644 --- a/meow-keypad.el +++ b/meow-keypad.el @@ -435,15 +435,15 @@ try replacing the last modifier and try again." t))))) (defun meow--keypad-handle-input-with-keymap (input-event) - (let ((cmd (lookup-key meow-keypad-state-keymap (vector input-event)))) + (let* ((k (kbd (single-key-description input-event))) + (cmd (lookup-key meow-keypad-state-keymap k))) (if cmd (call-interactively cmd) (meow--keypad-handle-input-event input-event)))) (defun meow--keypad-handle-input-event (input-event) (meow--keypad-clear-message) - (when-let* ((e (meow--event-key input-event)) - (key (meow--parse-input-event e))) + (when-let* ((key (single-key-description input-event))) (let ((has-sub-meta (meow--keypad-has-sub-meta-keymap-p))) (cond (meow--use-literal @@ -456,23 +456,23 @@ try replacing the last modifier and try again." (meow--use-meta (push (cons 'meta key) meow--keypad-keys) (setq meow--use-meta nil)) - ((and (equal e meow-keypad-meta-prefix) + ((and (equal input-event meow-keypad-meta-prefix) (not meow--use-meta) has-sub-meta) (setq meow--use-meta t)) - ((and (equal e meow-keypad-ctrl-meta-prefix) + ((and (equal input-event meow-keypad-ctrl-meta-prefix) (not meow--use-both) has-sub-meta) (setq meow--use-both t)) - ((and (equal e meow-keypad-literal-prefix) + ((and (equal input-event meow-keypad-literal-prefix) (not meow--use-literal) meow--keypad-keys) (setq meow--use-literal t)) (meow--keypad-keys (push (cons 'control key) meow--keypad-keys)) - ((alist-get e meow-keypad-start-keys) + ((alist-get input-event meow-keypad-start-keys) (push (cons 'control (meow--parse-input-event - (alist-get e meow-keypad-start-keys))) + (alist-get input-event meow-keypad-start-keys))) meow--keypad-keys)) (meow--keypad-allow-quick-dispatch (if-let* ((keymap (meow--get-leader-keymap))) From 835e52de31abea19b89a185d97d7c9697fbc8d2c Mon Sep 17 00:00:00 2001 From: DogLooksGood Date: Sun, 1 Dec 2024 18:00:40 +0800 Subject: [PATCH 4/6] Fix meow-keypad-start, meow-keypad-start-with and meow-keypad-describe-key --- meow-core.el | 8 ++------ meow-helpers.el | 3 ++- meow-keypad.el | 54 ++++++++++++++++++++----------------------------- 3 files changed, 26 insertions(+), 39 deletions(-) diff --git a/meow-core.el b/meow-core.el index 942c289..459d87e 100644 --- a/meow-core.el +++ b/meow-core.el @@ -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))) @@ -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 diff --git a/meow-helpers.el b/meow-helpers.el index 88eeb03..afda9a7 100644 --- a/meow-helpers.el +++ b/meow-helpers.el @@ -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 diff --git a/meow-keypad.el b/meow-keypad.el index 11469c6..b1956ac 100644 --- a/meow-keypad.el +++ b/meow-keypad.el @@ -405,7 +405,7 @@ try replacing the last modifier and try again." meow--use-meta meow--use-both) (let* ((key-str (meow--keypad-format-keys nil)) - (cmd (meow--keypad-lookup-key (read-kbd-macro key-str)))) + (cmd (keymap-lookup nil key-str t))) (cond ((commandp cmd t) (setq current-prefix-arg meow--prefix-arg @@ -498,51 +498,41 @@ try replacing the last modifier and try again." (setq this-command last-command) (meow--keypad-handle-input-event last-input-event)) -(defun meow-keypad-start () - "Enter keypad state with current input as initial key sequences." - (interactive) - (setq this-command last-command) - (setq meow--keypad-previous-state (meow--current-state)) - (meow--switch-state 'keypad) - (setq overriding-local-map meow-keypad-state-keymap - overriding-terminal-local-map nil - meow--keypad-allow-quick-dispatch nil) - (meow--keypad-handle-input-event last-input-event) - (while (not (meow--keypad-handle-input-with-keymap (read-key))))) - (defun meow-keypad () "Enter keypad state and convert inputs." (interactive) - (setq this-command last-command) - (setq meow--keypad-previous-state (meow--current-state)) + (meow-keypad-start-with nil)) + +(defun meow-keypad-start () + "Enter keypad state with current input as initial key sequences." + (interactive) + (setq this-command last-command + meow--keypad-keys nil + meow--keypad-previous-state (meow--current-state) + meow--prefix-arg current-prefix-arg) (meow--switch-state 'keypad) - (setq overriding-local-map meow-keypad-state-keymap - overriding-terminal-local-map nil - meow--keypad-allow-quick-dispatch t) - (meow--keypad-display-message) + (meow--keypad-handle-input-with-keymap last-input-event) (while (not (meow--keypad-handle-input-with-keymap (read-key))))) (defun meow-keypad-start-with (input) "Enter keypad state with INPUT. -INPUT is a string, stands for initial keys." - (setq meow--keypad-previous-state (meow--current-state)) +A string INPUT, stands for initial keys. +When INPUT is nil, start without initial keys." + (setq this-command last-command + meow--keypad-keys (when input (meow--parse-string-to-keypad-keys input)) + meow--keypad-previous-state (meow--current-state) + meow--prefix-arg current-prefix-arg) (meow--switch-state 'keypad) - (setq meow--keypad-keys (meow--parse-string-to-keypad-keys input) - overriding-terminal-local-map nil - overriding-local-map meow-keypad-state-keymap) - (meow--keypad-try-execute)) + (meow--keypad-show-message) + (meow--keypad-display-message) + (while (not (meow--keypad-handle-input-with-keymap (read-key))))) (defun meow-keypad-describe-key () "Describe key via KEYPAD input." (interactive) - (setq this-command last-command) - (setq overriding-local-map meow-keypad-state-keymap - meow--keypad-help t - meow--keypad-previous-state (meow--current-state)) - (meow--switch-state 'keypad) - (meow--keypad-show-message) - (meow--keypad-display-message)) + (setq meow--keypad-help t) + (meow-keypad)) (provide 'meow-keypad) ;;; meow-keypad.el ends here From 888615ab7340fe8aeef51335821c3dfe973396ea Mon Sep 17 00:00:00 2001 From: DogLooksGood Date: Sun, 1 Dec 2024 18:05:52 +0800 Subject: [PATCH 5/6] Remove keymap-lookup usage --- meow-keypad.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meow-keypad.el b/meow-keypad.el index b1956ac..f88e737 100644 --- a/meow-keypad.el +++ b/meow-keypad.el @@ -405,7 +405,7 @@ try replacing the last modifier and try again." meow--use-meta meow--use-both) (let* ((key-str (meow--keypad-format-keys nil)) - (cmd (keymap-lookup nil key-str t))) + (cmd (key-binding (kbd key-str)))) (cond ((commandp cmd t) (setq current-prefix-arg meow--prefix-arg From b3281d4ad89fcf1b948d17b20ac5b23d3e70daeb Mon Sep 17 00:00:00 2001 From: DogLooksGood Date: Sun, 1 Dec 2024 18:35:34 +0800 Subject: [PATCH 6/6] Fix some docs --- meow-cheatsheet.el | 8 ++++---- meow-core.el | 2 +- meow-keymap.el | 4 ++++ meow-keypad.el | 42 +++++++++++++++++++++++------------------- meow-shims.el | 17 ++++++++++++++--- meow-var.el | 5 +++-- 6 files changed, 49 insertions(+), 29 deletions(-) diff --git a/meow-cheatsheet.el b/meow-cheatsheet.el index 6ca2790..855023d 100644 --- a/meow-cheatsheet.el +++ b/meow-cheatsheet.el @@ -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) diff --git a/meow-core.el b/meow-core.el index 459d87e..3fd662a 100644 --- a/meow-core.el +++ b/meow-core.el @@ -160,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))) diff --git a/meow-keymap.el b/meow-keymap.el index e58c853..a386006 100644 --- a/meow-keymap.el +++ b/meow-keymap.el @@ -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) diff --git a/meow-keypad.el b/meow-keypad.el index f88e737..02d17d2 100644 --- a/meow-keypad.el +++ b/meow-keypad.el @@ -19,21 +19,15 @@ ;;; Commentary: ;; Keypad state is a special state to simulate C-x and C-c key sequences. -;; There are three commands: +;; +;; Useful commands: +;; +;; meow-keypad +;; Enter keypad state. ;; ;; meow-keypad-start ;; Enter keypad state, and simulate this key with Control modifier. ;; -;; meow-keypad-self-insert -;; This command is bound to every single key in keypad state. -;; The rules, -;; - If current key is SPC, the next will be considered without modifier. -;; - If current key is m, the next will be considered with Meta modifier. -;; - Other keys, or SPC and m after a prefix, means append a key input, by default, with Control modifier. -;; -;; meow-keypad-undo -;; Remove the last input, if there's no input in the sequence, exit the keypad state. - ;;; Code: (require 'subr-x) @@ -43,7 +37,7 @@ (require 'meow-beacon) (defun meow--keypad-format-upcase (k) - "Return S-k for upcase k." + "Return S-k for upcase K." (let ((case-fold-search nil)) (if (and (stringp k) (string-match-p "^[A-Z]$" k)) @@ -68,6 +62,7 @@ (t ""))) (defun meow--keypad-lookup-key (keys) + "Lookup the command which is bound at KEYS." (let* ((overriding-local-map meow--keypad-base-keymap) (keybind (key-binding keys))) (unless (and (meow--is-self-insertp keybind) @@ -75,6 +70,9 @@ keybind))) (defun meow--keypad-has-sub-meta-keymap-p () + "Check if there's a keymap belongs to Meta prefix. + +A key sequences starts with ESC is accessible via Meta key." (and (not meow--use-literal) (not meow--use-both) (not meow--use-meta) @@ -85,7 +83,9 @@ (lookup-key keymap "")))))) (defun meow--keypad-format-keys (&optional prompt) - "Return a display format for current input keys." + "Return a display format for current input keys. + +The message is prepended with an optional PROMPT." (let ((result "")) (setq result (thread-first @@ -132,6 +132,9 @@ (meow--keypad-quit)) (defun meow--make-keymap-for-describe (keymap control) + "Parse the KEYMAP to make it suitable for describe. + +Argument CONTROL, non-nils stands for current input is prefixed with Control." (let ((km (make-keymap))) (suppress-keymap km t) (when (keymapp keymap) @@ -146,6 +149,7 @@ km)) (defun meow--keypad-get-keymap-for-describe () + "Get a keymap for describe." (let* ((input (thread-first (mapcar #'meow--keypad-format-key-1 meow--keypad-keys) (reverse) @@ -226,9 +230,11 @@ km))))))) (defun meow--keypad-clear-message () + "Clear displayed message by calling `meow-keypad-clear-describe-keymap-function'." (funcall meow-keypad-clear-describe-keymap-function)) (defun meow--keypad-display-message () + "Display a message for current input state." (let (overriding-local-map) (when meow-keypad-describe-keymap-function (when (or @@ -365,6 +371,7 @@ Returning DEF will result in a generated title." (meow--keypad-quit))) (defun meow--keypad-show-message () + "Show message for current keypad input." (let ((message-log-max)) (message "KEYPAD%s: %s%s" (if meow--keypad-help " describe key" "") @@ -375,6 +382,7 @@ Returning DEF will result in a generated title." (propertize (meow--keypad-format-keys nil) 'face 'font-lock-string-face)))) (defun meow--keypad-in-beacon-p () + "Return whether keypad is started from BEACON state." (and (meow--beacon-inside-secondary-selection) meow--beacon-overlays)) @@ -435,6 +443,7 @@ try replacing the last modifier and try again." t))))) (defun meow--keypad-handle-input-with-keymap (input-event) + "Handle INPUT-EVENT with `meow-keypad-state-keymap'." (let* ((k (kbd (single-key-description input-event))) (cmd (lookup-key meow-keypad-state-keymap k))) (if cmd @@ -442,6 +451,7 @@ try replacing the last modifier and try again." (meow--keypad-handle-input-event input-event)))) (defun meow--keypad-handle-input-event (input-event) + "" (meow--keypad-clear-message) (when-let* ((key (single-key-description input-event))) (let ((has-sub-meta (meow--keypad-has-sub-meta-keymap-p))) @@ -492,12 +502,6 @@ try replacing the last modifier and try again." nil) (meow--keypad-try-execute)))) -(defun meow-keypad-self-insert () - "Default command when keypad state is enabled." - (interactive) - (setq this-command last-command) - (meow--keypad-handle-input-event last-input-event)) - (defun meow-keypad () "Enter keypad state and convert inputs." (interactive) diff --git a/meow-shims.el b/meow-shims.el index 0767aac..ab55593 100644 --- a/meow-shims.el +++ b/meow-shims.el @@ -240,7 +240,7 @@ Argument ENABLE non-nil means turn on." (defvar meow--magit-setup nil) (defun meow--magit-blame-hook-function () - "Switch meow state when entering/leaving magit-blame-read-only-mode." + "Switch meow state when entering/leaving `magit-blame-read-only-mode'." (if (bound-and-true-p magit-blame-read-only-mode) (meow--switch-to-motion) (meow--switch-to-normal))) @@ -393,6 +393,7 @@ Argument ENABLE non-nil means turn on." (defvar meow--which-key-setup nil) (defun meow--which-key-describe-keymap () + "Use which-key for keypad popup." (if which-key-mode (setq meow-keypad-describe-keymap-function (lambda (keymap) @@ -403,6 +404,8 @@ Argument ENABLE non-nil means turn on." meow-keypad-clear-describe-keymap-function nil))) (defun meow--setup-which-key (enable) + "Setup which-key. +Argument ENABLE non-nil means turn on." (setq meow--which-key-setup enable) (if enable (add-hook 'which-key-mode-hook 'meow--which-key-describe-keymap) @@ -416,10 +419,14 @@ Argument ENABLE non-nil means turn on." (defun meow--input-method-advice (fnc key) "Advice for `quail-input-method'. -Only use the input method in insert mode." +Only use the input method in insert mode. +Argument FNC, input method function. +Argument KEY, the current input." (funcall (if (and (boundp 'meow-mode) meow-mode (not (meow-insert-mode-p))) #'list fnc) key)) (defun meow--setup-input-method (enable) + "Setup input-method. +Argument ENABLE non-nil means turn on." (setq meow--input-method-setup enable) (if enable (advice-add 'quail-input-method :around 'meow--input-method-advice) @@ -482,11 +489,13 @@ Argument ENABLE non-nil means turn on." (declare-function eat-eshell-semi-char-mode "eat") (declare-function eat-eshell-char-mode "eat") +(declare-function meow-insert-mode "meow-core") + (defun meow--eat-eshell-mode-override-enable () (setq-local meow--eat-eshell-mode-override t) (add-hook 'meow-insert-enter-hook #'eat-eshell-char-mode nil t) (add-hook 'meow-insert-exit-hook #'eat-eshell-emacs-mode nil t) - (if meow-insert-mode + (if (bound-and-true-p meow-insert-mode) (eat-eshell-char-mode) (eat-eshell-emacs-mode))) @@ -511,6 +520,8 @@ Argument ENABLE non-nil means turn on." (defvar meow--ediff-setup nil) (defun meow--setup-ediff (enable) + "Setup Ediff. +Argument ENABLE, non-nil means turn on." (if enable (add-hook 'ediff-mode-hook 'meow-motion-mode) (remove-hook 'ediff-mode-hook 'meow-motion-mode))) diff --git a/meow-var.el b/meow-var.el index da44f0e..a8d6563 100644 --- a/meow-var.el +++ b/meow-var.el @@ -113,8 +113,9 @@ This doesn't affect how keypad works on recording or executing a kmacro." Each item is a (THING FORWARD_SYNTAX_TO_INCLUDE BACKWARD-SYNTAX_TO_INCLUDE)." :group 'meow - :type '(list :key-type (symbol :tag "Thing") - :value-type (list string))) + :type '(repeat (list (symbol :tag "Thing") + (string :tag "Forward Syntax") + (string :tag "Backward Syntax")))) (defcustom meow-expand-hint-counts '((word . 30)