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

Add meow-replace-pop. #509

Merged
merged 1 commit into from
Sep 25, 2023
Merged

Conversation

okamsn
Copy link
Contributor

@okamsn okamsn commented Sep 23, 2023

This command, when run after meow-replace or itself, replaces the just inserted text with the next item in the kill ring, without rotating the kill ring.

  • Add command meow-replace.
  • Add variables meow--replace-pop-index and meow--replace-start-marker.
  • Modify commands meow-replace, meow-replace-save, and meow-replace-char to set the marker before inserting the replacement text.

The marker was needed to support meow-replace-char, which doesn't use a region. Otherwise, one could use (mark t) to get the mark's position.

@okamsn
Copy link
Contributor Author

okamsn commented Sep 23, 2023

Why do meow-replace and the other commands strip a trailing new line from the replacement? I copied that, but I don't understand why it's needed.

@DogLooksGood
Copy link
Collaborator

DogLooksGood commented Sep 24, 2023

Well, the meow-replace is designed to replace the selected text with the head of kill-ring. So here is a breaking change?

@okamsn
Copy link
Contributor Author

okamsn commented Sep 24, 2023

The command meow-replace-pop isn't meant to replace meow-replace. It is meant to run run after it. For example, I use meow-replace-pop as the fallback for meow-replace in meow-selection-command-fallback.

Sometimes, I want to replace the region with text that is further into the kill ring. By using meow-replace-pop as the fallback of meow-replace, I can keep hitting r to reach the desired text in the kill ring. It is similar to running yank-pop after yank, except that meow-replace-pop does not cycle the kill ring, so that running meow-replace later will work as expected.

If the command meow-replace-pop is run after meow-replace, which part is the breaking change?

EDIT: I've made the code signal a user error in meow-replace-pop if the previous command isn't a replacement command. Hopefully that makes what I mean to say clearer.

@DogLooksGood
Copy link
Collaborator

Got it, thanks for the explanation. Are we ready for the merge?

This command, when run after a replacement command, such as `meow-replace` or
itself, replaces the just inserted text with the next item in the kill ring,
without rotating the kill ring.

- Add command `meow-replace`.
- Add variables `meow--replace-pop-index`, `meow--replace-start-marker`,
  and `meow-replace-pop-command-start-indexes`.
- Modify commands `meow-replace`, `meow-replace-save`, and `meow-replace-char`
  to set the marker before inserting the replacement text.
@okamsn
Copy link
Contributor Author

okamsn commented Sep 25, 2023

Yes, I'm happy with it. I thought about using a prefix argument to reverse the cycling direction, but I now think it's easier to just use undo.

@DogLooksGood DogLooksGood merged commit ec94fa6 into meow-edit:master Sep 25, 2023
3 checks passed
@DogLooksGood
Copy link
Collaborator

Thanks!

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.

2 participants