Git Product home page Git Product logo

Comments (2)

utoddl avatar utoddl commented on July 21, 2024

If I understand you, you've made it so that find arbitrary_string in a macro doesn't update cur_buffer->find_string like it would if you did the same command on the command line.

I can see how it may seem useful. It would avoid the situation where a macro has the unintended side effect of changing cur_buffer->find_string.

However, it also changes the RepeatLast command's behavior, breaking it entirely when playing back a recorded macro containing a Find command and a subsequent RepeatLast command.

We already have a mechanism to avoid side effects from macros. See PushPrefs and PopPrefs. I think it's reasonable to consider whether to extend the function of PushPrefs and PopPrefs to include saving and restoring the current buffer's find_string, last_was_replace, and last_was_regexp. Then you could craft your macros to avoid the issue while preserving the ability to use — and without breaking the semantics of — RepeatLast.

This is an interesting idea. Thanks for the suggestion.

from ne.

soveran avatar soveran commented on July 21, 2024

Sorry I didn't share the diff earlier:

diff --git a/src/command.c b/src/command.c
index a00d87b..7eed69b 100644
--- a/src/command.c
+++ b/src/command.c
@@ -503,6 +503,8 @@ void optimize_macro(char_stream *cs, bool verbose) {
 int play_macro(char_stream *cs, int64_t c) {
 	if (!cs) return ERROR;
 
+	char *find_string = str_dup(cur_buffer->find_string);
+
 	/* If len is 0 or 1, the character stream does not contain anything. */
 	const int64_t len = cs->len;
 	if (len < 2 || c < 1) return OK;
@@ -547,6 +549,8 @@ int play_macro(char_stream *cs, int64_t c) {
 	free(stream);
 	if (--call_depth == 0) executing_macro = false;
 
+	cur_buffer->find_string = str_dup(find_string);
+
 	return stop ? STOPPED : error;
 }
 

I had not checked what would happen if a macro contains a call to RepeatLast, but I've just tried it and it seems to work fine. I agree that it would be more elegant to extend PushPrefs and PopPrefs. Also, even if you guessed my intentions correctly, I didn't share my motivation: I have some macros that use Find/FindRegExp and I did not like to lose the value of find_string after running them.

from ne.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.