From bccfe3459d1e1afb7775f71c8c7e1670845ba97a Mon Sep 17 00:00:00 2001 From: DogLooksGood Date: Thu, 26 Dec 2024 02:48:04 +0800 Subject: [PATCH] Remove motion remap --- CUSTOMIZATIONS.org | 12 ------------ meow-core.el | 20 +++----------------- meow-helpers.el | 7 +++---- meow-keypad.el | 15 +++++++++------ meow-util.el | 35 ----------------------------------- meow-var.el | 27 +++++++++++++-------------- 6 files changed, 28 insertions(+), 88 deletions(-) diff --git a/CUSTOMIZATIONS.org b/CUSTOMIZATIONS.org index 9a39787..0207c6f 100644 --- a/CUSTOMIZATIONS.org +++ b/CUSTOMIZATIONS.org @@ -313,18 +313,6 @@ Default: ~select~ The type of selection activated by ~meow-expand-*~ commands. -** meow-motion-remap-prefix - -Default: "H-" - -The prefix string used when remapping an occupied key in MOTION state. - -For examples: -#+begin_example - "C-x C-v" will remap the occupied j to C-x C-v j. - "C-M-" will remap the occupied j to C-M-j. -#+end_example - ** meow-state-mode-alist Association list of symbols of meow states to their corresponding mode functions. diff --git a/meow-core.el b/meow-core.el index e3563e5..82a5631 100644 --- a/meow-core.el +++ b/meow-core.el @@ -129,27 +129,13 @@ test on the commands bound to the keys a-z. If any of the command names contains \"self-insert\", then NORMAL state will be used. Otherwise, MOTION state will be used. -Before turning on MOTION state, the original commands will be -remapped. The new keybinding is generated by prepending -`meow-motion-remap-prefix' to the original keybinding. - Note: When this function is called, NORMAL state is already enabled. NORMAL state is enabled globally when `meow-global-mode' is used, because in `fundamental-mode', there's no chance for meow to call an init function." - (let ((state (meow--mode-get-state)) - (motion (lambda () - (meow--disable-current-state) - (meow--save-origin-commands) - (meow-motion-mode 1)))) - (cond - ;; if MOTION is specified - ((eq state 'motion) - (funcall motion)) - - (state - (meow--disable-current-state) - (meow--switch-state state t))))) + (let ((state (meow--mode-get-state))) + (meow--disable-current-state) + (meow--switch-state state t))) (defun meow--disable () "Disable Meow." diff --git a/meow-helpers.el b/meow-helpers.el index afda9a7..81af536 100644 --- a/meow-helpers.el +++ b/meow-helpers.el @@ -94,15 +94,14 @@ with this helper, it will result in recursive calls. Check `meow-normal-define-key' for usages." (apply #'meow-define-keys 'leader keybinds)) -;; Remap Leader SPC -(meow-leader-define-key (cons "SPC" (concat meow-motion-remap-prefix "SPC"))) - -(defun meow-motion-overwrite-define-key (&rest keybinds) +(defun meow-motion-define-key (&rest keybinds) "Define key for MOTION state. Check `meow-normal-define-key' for usages." (apply #'meow-define-keys 'motion keybinds)) +(make-obsolete 'meow-motion-overwrite-define-key 'meow-motion-define-key "1.6.0") + (defun meow-setup-line-number () (add-hook 'display-line-numbers-mode-hook #'meow--toggle-relative-line-number) (add-hook 'meow-insert-mode-hook #'meow--toggle-relative-line-number)) diff --git a/meow-keypad.el b/meow-keypad.el index 105bf92..b7ff1a3 100644 --- a/meow-keypad.el +++ b/meow-keypad.el @@ -66,9 +66,7 @@ (let* ((keybind (if meow--keypad-base-keymap (lookup-key meow--keypad-base-keymap keys) (key-binding keys)))) - (unless (and (meow--is-self-insertp keybind) - (not meow-keypad-self-insert-undefined)) - keybind))) + keybind)) (defun meow--keypad-has-sub-meta-keymap-p () "Check if there's a keymap belongs to Meta prefix. @@ -408,8 +406,8 @@ If there are beacons, execute it at every beacon." (defun meow--keypad-try-execute () "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." +This function supports a fallback behavior, where it allows to use `SPC +x f' to execute `C-x C-f' or `C-x f' when `C-x C-f' is not bound." (unless (or meow--use-literal meow--use-meta meow--use-both) @@ -439,8 +437,13 @@ try replacing the last modifier and try again." (meow--keypad-try-execute)) (t (setq meow--prefix-arg nil) - (message "%s is undefined" (meow--keypad-format-keys nil)) (meow--keypad-quit) + (if (or (eq t meow-keypad-leader-transparent) + (eq meow--keypad-previous-state meow-keypad-leader-transparent)) + (let* ((local (lookup-key (current-local-map) (meow--parse-input-event last-input-event))) + (cmd (command-remapping local))) + (call-interactively (or cmd local 'undefined))) + (message "%s is undefined" key-str)) t))))) (defun meow--keypad-handle-input-with-keymap (input-event) diff --git a/meow-util.el b/meow-util.el index 212ed6c..07e7555 100644 --- a/meow-util.el +++ b/meow-util.el @@ -470,41 +470,6 @@ Looks up the state in meow-replace-state-name-list" (format "<%s>" e)) (t nil))) -(defun meow--save-origin-commands () - "Save the commands overridden by the Motion map to modified bindings. - -The new key binding, modified by the prefix in -`meow-motion-remap-prefix', is bound to a command that calls the -command locally bound to the original key binding, or, if that is -nil, the original command. - -For example, under the default and suggested settings, in a -Magit status buffer, `k' could be bound to `meow-previous' -and `H-k' would be bound to a command that would try -to use the status buffer's original `k' binding at point." - (cl-loop for key-code being the key-codes of meow-motion-state-keymap do - (ignore-errors - (let* ((key (meow--parse-input-event key-code)) - (cmd (key-binding (kbd key)))) - (when (and (commandp cmd) - (not (equal cmd 'undefined))) - (let ((rebind-key (concat meow-motion-remap-prefix key))) - (local-set-key (kbd rebind-key) - (lambda () - (interactive) - ;; Local maps are those local to the buffer - ;; or a region of the buffer. - (let* ((local (lookup-key (current-local-map) key)) - (remapped (command-remapping local))) - (call-interactively - (cond - ((commandp remapped) - remapped) - ((commandp local) - local) - (t - cmd)))))))))))) - (defun meow--prepare-region-for-kill () (when (and (equal 'line (cdr (meow--selection-type))) (meow--direction-forward-p) diff --git a/meow-var.el b/meow-var.el index d6f198f..f418850 100644 --- a/meow-var.el +++ b/meow-var.el @@ -134,11 +134,6 @@ Each item is a (THING FORWARD_SYNTAX_TO_INCLUDE BACKWARD-SYNTAX_TO_INCLUDE)." :group 'meow :type 'boolean) -(defcustom meow-keypad-self-insert-undefined t - "Whether to self-insert a key in keypad mode if it is undefined" - :group 'meow - :type 'boolean) - (defcustom meow-char-thing-table '((?r . round) (?s . square) @@ -282,6 +277,19 @@ Set to `t' to always update. :type '(choice (const select) (const expand))) +(defcustom meow-keypad-leader-transparent 'motion + "Use transparent behaivor when a bound command is found in leader dispatch. + +Value `t' stands for always be transparent. +Value `motion' stands for only be transparent in MOTION state. +Value `normal' stands for only be transparent in NORMAL state. +Value `nil' stands for never be transparent." + :group 'meow + :type '(choice (const t :tag "Always be transparent") + (const motion :tag "Transparent only in MOTION state") + (const normal :tag "Transparent only in NORMAL state") + (const nil :tag "Never be transparent"))) + (defcustom meow-keypad-leader-dispatch nil "The fallback dispatching in KEYPAD when there's no translation. @@ -320,15 +328,6 @@ prompted to finish the command." :type '(alist :key-type (character :tag "From") :value-type (character :tag "To"))) -(defcustom meow-motion-remap-prefix "H-" - "The prefix string used when remapping an occupied key in MOTION state. - -For examples: - \"C-x C-v\" will remap the occupied j to C-x C-v j. - \"C-M-\" will remap the occupied j to C-M-j." - :group 'meow - :type 'string) - (defcustom meow-goto-line-function nil "Function to use in `meow-goto-line'.