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

Macros #1234

Merged
merged 8 commits into from
Dec 12, 2021
Merged

Macros #1234

merged 8 commits into from
Dec 12, 2021

Conversation

Omnikar
Copy link
Contributor

@Omnikar Omnikar commented Dec 5, 2021

  • q will begin recording to register @
  • "aq will begin recording to register a
  • q while recording will stop recording and save to the register
  • Q will play the recording from register @
  • "aQ will play the recording from register a

Macros are saved to registers as space-delimited serialized keypresses, such as x d o 0 esc h C-a.

I've had to change helix_term::compositor::Callback to take &mut Context as a parameter so that play_macro would have access to the handle_event method.

@Omnikar
Copy link
Contributor Author

Omnikar commented Dec 5, 2021

Looks like the CI had a submodule fetch failure.

@Omnikar
Copy link
Contributor Author

Omnikar commented Dec 5, 2021

I want to add recording status to the statusline but I don't think I am able to access it from the helix_term::ui::editor::EditorView::render_statusline function…

helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-view/src/editor.rs Outdated Show resolved Hide resolved
helix-view/src/input.rs Outdated Show resolved Hide resolved
Omnikar and others added 3 commits December 8, 2021 05:49
`helix_term::compositor::Callback` changed to take a `&mut Context` as
a parameter for use by `play_macro`
When macro recording is active, the pending keys display will be shifted
3 characters left, and the register being recorded to will be displayed
between brackets — e.g., `[@]` — right of the pending keys display.
@Omnikar
Copy link
Contributor Author

Omnikar commented Dec 10, 2021

I think this should be done now.

@Omnikar Omnikar marked this pull request as ready for review December 10, 2021 22:01
@archseer archseer merged commit e91d357 into helix-editor:master Dec 12, 2021
@Omnikar Omnikar deleted the macros branch December 12, 2021 12:23
Comment on lines 5879 to 5882
let reg = cx.register.take().unwrap_or('@');
cx.editor.macro_recording = Some((reg, Vec::new()));
cx.editor
.set_status(format!("Recording to register {}", reg));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does our macro reuse the same register as the normal registers? IIRC vim macros have separate registers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We reuse the normal register since that means you can edit the macro as text (paste it in the buffer, edit, yank it back). I think vim also allowed for that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vim macros do not have separate registers.

Comment on lines 596 to 597
"q" => record_macro,
"Q" => play_macro,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be the reverse, Q should record macro and q should play macro like in vim.

Since it's a macro, it's expected to play more than record. And since play is expected to be used more frequently, it would be best use without extra shift.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, kakoune has this as well. I didn't realize it during review

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Vim, record is q and play is @; I changed it here because I figured it's more consistent. But yeah, swapping q and Q here does make sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(it's also "replay" instead of "play" but I didn't have strong opinions there)

Copy link
Contributor Author

@Omnikar Omnikar Dec 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah sorry if I get stuff inconsistent with Kakoune, I've never used it and am not very familiar with it. Though in this situation, I do believe "play" makes very slightly more sense than "replay", since it is possible to play a macro without actually recording it, in which case playing it would not be a "replay".

Comment on lines 5891 to 5892
.get(reg)
.and_then(|reg| reg.read().get(0))
Copy link
Contributor

@pickfire pickfire Dec 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just use cx.editor.registers.read(reg) helper.

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

Successfully merging this pull request may close these issues.

None yet

3 participants