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

Alt+; invokes InsertEnd hooks #2699

Closed
andreyorst opened this issue Jan 20, 2019 · 10 comments
Closed

Alt+; invokes InsertEnd hooks #2699

andreyorst opened this issue Jan 20, 2019 · 10 comments

Comments

@andreyorst
Copy link
Contributor

andreyorst commented Jan 20, 2019

I need to execute some commands from mapping that will change text in current line. Those commands are kind of smart and can do different things. To execute a command from insert mode I need to get back to normal mode. Thankfully there is a Alt+; mapping that can be used to "escape to normal mode for a single command". So I map my command like so:

map global insert '<key>' '<a-;>:<space>command<ret>'

Everything works so far. But if I execute this mapping on a line that only contains whitespaces, Alt+; will clear those whitespaces for me, since when we escape insert mode with Esc that's what happens. However I don't want to loose my whitespaces. If I enter insertmode withno-hooks` switch (\) and then exit it with either Alt+; or Esc, whitespaces won't be deleted.

Is there any way to exit to normal mode without doing any hooks or not loosing whitespaces at least?

Seems like <a-:> isn't mapped to anything in insert mode, and could be a no-hooks <a-;>

@Screwtapello
Copy link
Contributor

If the whitespaces are deleted by an InsertEnd hook, it should be fine - <a-;> doesn't end insert mode, it just adds a temporary normal mode on top.

However, there have also been some attempts to generalise the InsertBegin/InsertEnd/NormalBegin/NormalEnd hooks to cover other modes. The first such attempt was the ModeChange hook (#1772), but because there's only one such hook, it triggers the same way for both "exit insert back to normal" and "enter normal from insert", and you won't be able to do anything about it.

The proposed PushMode and PopMode hooks (#2513) should fix that problem, but although there's a PR (#2545), it seems to have stalled and probably needs a bit of a nudge.

@andreyorst
Copy link
Contributor Author

If the whitespaces are deleted by an InsertEnd hook, it should be fine

If I understood you correctly, you mean that Kakoune sets this InsertEnd hook somewhere, and this hook gets executed with <a-j> which should not happen, so it is a bug here?

@Screwtapello
Copy link
Contributor

Screwtapello commented Jan 21, 2019

The filetype plugin you're using has some hook that removes trailing whitespace.

If that hook used InsertEnd, I believe you wouldn't have this problem.

Therefore, I expect that hook is using ModeChange, and you can fix this problem by updating the hook to use InsertEnd instead.

(there are legitimate reasons to use ModeChange, so it can't be removed everywhere. On the other hand, if #2545 or something like it lands, that should be able to replace both ModeChange and InsertBegin/InsertEnd/NormalBegin/NormalEnd.)

@andreyorst
Copy link
Contributor Author

Ive found this hook in rc/core/kakrc.kak line 102. It is using ModeChange hook, as you've said

@andreyorst
Copy link
Contributor Author

As a workaround for now I've added inserting a letter before <a-;>, and then execute-keys <backspace> as fist what comes inside the command I call.

@andreyorst andreyorst changed the title Alt+; without hooks Alt+; invokes InsertEnd hooks Feb 4, 2019
@andreyorst
Copy link
Contributor Author

As a workaround for now I've added inserting a letter before <a-;>, and then execute-keys <backspace> as fist what comes inside the command I call.

Though when occivink/kakoune-snippets#28 will be merged, I won't be able to use this workaround with snippets, as it will replace everything to this letter on jumping.

@andreyorst
Copy link
Contributor Author

andreyorst commented May 15, 2019

there are legitimate reasons to use ModeChange

I wonder why it is so. Why can't InsertEnd be used?

@Screwtapello
Copy link
Contributor

To be clear, InsertEnd might be the right choice for this particular situation (I don't know, I haven't looked closely) and perhaps it should be changed. However, ModeChange is useful in other places so we don't want to get rid of it entirely, even if we get rid of it here.

@mawww
Copy link
Owner

mawww commented Oct 17, 2019

ModeChange pop:insert:.* is the way to do that now.

@mawww mawww closed this as completed Oct 17, 2019
@andreyorst
Copy link
Contributor Author

Nice! I've checked some filetypes and it seem towork as expected

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

3 participants