Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keypad self insert regression #698

Open
Haxxflaxx opened this issue Dec 15, 2024 · 18 comments
Open

Keypad self insert regression #698

Haxxflaxx opened this issue Dec 15, 2024 · 18 comments

Comments

@Haxxflaxx
Copy link
Contributor

It is no longer possible to insert characters from the keypad.
The regression was introduced in 8ae8b2c.

@DogLooksGood
Copy link
Collaborator

I'm curious about the use case on this feature. In which scenario it is useful?

@Haxxflaxx
Copy link
Contributor Author

Haxxflaxx commented Dec 16, 2024

It allows for interaction with electric pair mode from normal mode. You can select some thing, then press "SPC (" to surround it with parens.

It is possible that this should be it's own thing, like a self insert next key.

@DogLooksGood
Copy link
Collaborator

Probably it's better to just bind self-insert-command to ( in leader to achieve this? I'm thinking maybe we shouldn't support with an option, it's kind pointless to always call a self-insert-command when the key is not defined.

@bplubell
Copy link

I thought the intent was to insert a key when it was undefined. Isn't that the behavior that meow-keypad-self-insert-undefined is supposed to enable/disable?

(defcustom meow-keypad-self-insert-undefined t
  "Whether to self-insert a key in keypad mode if it is undefined"
  :group 'meow
  :type 'boolean)

I, too, have become used to using it in the way described by @Haxxflaxx. If we want to change how undefined keys are handled in the leader map, it's important to recognize that it's a breaking change. That would ideally involve some notice of deprecation and clear way to migrate.

Furthermore, I can't seem to achieve the effect you indicate by binding ( to self-insert-command. With the following form, SPC ( just inserts a space at the end of the selection. Am I misunderstanding?

(meow-leader-define-key
 ;; SPC j/k will run the original command in MOTION state.
 '("j" . "H-j")
 '("k" . "H-k")
 '("(" . self-insert-command)
 '("/" . meow-keypad-describe-key)
 '("?" . meow-cheatsheet))

@Haxxflaxx
Copy link
Contributor Author

It seems like character isn't updated to whatever is pressed inside the prefix, but instead remains the space key.
I also noticed that digit-argument has the same problem.

@DogLooksGood
Copy link
Collaborator

I see.

But we need to find a way to make it work again. After the keypad refactor, now the whole key sequences are input in a loop in one command instead of a list of meow-keypad-self-inserts. So even if we call a self-insert-command, it won't insert the last char, instead it inserts the SPC which is the key that used to enter keypad.

@Haxxflaxx
Copy link
Contributor Author

I've tried adding an explicit self-insert-command to meow--keypad-try-execute

(if meow-keypad-self-insert-undefined
            (self-insert-command (or current-prefix-arg 1) (string-to-char key-str))
          (message "%s is undefined" (meow--keypad-format-keys nil)))

but it doesn't work as expected. The electric-pair-post-self-insert-function uses last-command-event which I then assume just goes back to sending Space.

For this to work as before I think we would need to get last-command-event to be what we pressed in the keypad.

@Haxxflaxx
Copy link
Contributor Author

Haxxflaxx commented Dec 17, 2024

(setq last-command-event (string-to-char key-str))
(if meow-keypad-self-insert-undefined
    (call-interactively 'self-insert-command)
  (message "%s is undefined" (meow--keypad-format-keys nil)))

Could be an option if it is save to set the variable.

@Haxxflaxx
Copy link
Contributor Author

I made a PR with a suggestion on how we can solve this, but I need to research further as it doesn't interact well with beacon state.
#700

@DogLooksGood
Copy link
Collaborator

DogLooksGood commented Dec 17, 2024

It would be tricky because in kmacro recording, it is the KEY that gets recorded. We could think a better way to achieve the result instead of hacking here.

@Haxxflaxx
Copy link
Contributor Author

I don't know if I would consider this a hack, but it is an implementation with quite a narrow understanding of the codebase.

After some further research into how keypad execution on beacons work I understand that naturally I need to let meow--keypad-execute handle calling the command.
With this tweaked it works as expected.
I also added an undo-boundary before the call to make the undo ring as expected.

I also now see that my previous assumption that it would work to bind self insert with a disabled meow-keypad-self-insert-undefined. This is due to meow--keypad-lookup-key filtering on the same variable.
We should probably update this and it might also require the same undo-boundary placement.

@Haxxflaxx
Copy link
Contributor Author

Haxxflaxx commented Dec 18, 2024

I've also updated meow--keypad-lookup-key to not filter the keypad. I assume the reason we had to do this was that all keys were bound to self insert unless overridden before the refactoring?

After updating meow--keypad-lookup-key it made me think that maybe this is a good time to change the default value of meow-keypad-self-insert-undefined.
While I think it is a good thing to be able to insert on undefined if you want, I don't think it's a good default when we support mapping self insert explicitly in the keypad.

@Haxxflaxx
Copy link
Contributor Author

I just noticed that keypad no longer triggers repeat maps either. I wonder if the reason is similar?
I would need to explore how repeat-mode works, but I would assume that it checks the last run command and we would report keypad and not the thing run by keypad.

@Haxxflaxx
Copy link
Contributor Author

After digging into the issue a bit more found that it is indeed the same issue. In the solution which means we can't set last-command-event in a let as the value may be required by functions running after our keypad.

@Kenneth-Mata
Copy link

Kenneth-Mata commented Dec 23, 2024

This feels somehow related, after updating using straight (I tend to recompile emacs every few days) I noticed that digit argument is beginning with a -16 prefix when using with leader key, I tried using a clean slate manually loading meow and the issue persists
Screenshot From 2024-12-23 02-47-45

Screenshot From 2024-12-23 02-47-50

@Haxxflaxx
Copy link
Contributor Author

@Kenneth-Mata yes, this is the same thing. It is due to last-command-event not getting updated when executing something from the keypad.

A quick fix could be to do something like:

(defun my/meow-digit-argument ()
    (interactive)
    (let ((last-command-event last-input-event))
      (meow-digit-argument)))

Note that this fix will work poorly for some things as it won't register modifier keys (as you don't press them while using the keypad) but it should work for numbers.

@DogLooksGood
Copy link
Collaborator

Just opened another PR #705 for another potential solution.

@Kenneth-Mata
Copy link

Kenneth-Mata commented Dec 26, 2024

I tried using that PR but I'm still getting the same -16 prefix behavior, used the default qwerty keymap changing meow-motion-overwrite-define-key to meow-motion-define-key as per the updates
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants