Skip to content

Commit

Permalink
Remove motion remap
Browse files Browse the repository at this point in the history
  • Loading branch information
DogLooksGood committed Dec 25, 2024
1 parent af3f10e commit bccfe34
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 88 deletions.
12 changes: 0 additions & 12 deletions CUSTOMIZATIONS.org
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
20 changes: 3 additions & 17 deletions meow-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
7 changes: 3 additions & 4 deletions meow-helpers.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
15 changes: 9 additions & 6 deletions meow-keypad.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
35 changes: 0 additions & 35 deletions meow-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 13 additions & 14 deletions meow-var.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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'.
Expand Down

0 comments on commit bccfe34

Please sign in to comment.