I've been thinking about what macros in 4coder should be like, and I realize I have unanswered questions about what a macro system should do in a lot of cases.
The most basic use case
If I have the code:
| init_a_thingy(thingy_ctx, "Foo", 0, foo_func);
init_a_thingy(thingy_ctx, "Bar", 0, bar_func);
init_a_thingy(thingy_ctx, "Fiz", 1, foo_func);
init_a_thingy(thingy_ctx, "Faz", 2, faz_func);
init_a_thingy(thingy_ctx, "Bat", 1, bar_func);
init_a_thingy(thingy_ctx, "Foo Big", 3, foo_func);
init_a_thingy(thingy_ctx, "Bar Big", 3, bar_func);
init_a_thingy(thingy_ctx, "Fiz Gigantic", 100, foo_func);
init_a_thingy(thingy_ctx, "Faz Tiny", -1, faz_func);
init_a_thingy(thingy_ctx, "Bat Goofy", 10, foo_func);
|
And if I want to turn it into this code:
| {"Foo", 0, foo_func,},
{"Bar", 0, bar_func,},
{"Fiz", 1, foo_func,},
{"Faz", 2, faz_func,},
{"Bat", 1, bar_func,},
{"Foo Big", 3, foo_func,},
{"Bar Big", 3, bar_func,},
{"Fiz Gigantic", 100, foo_func,},
{"Faz Tiny", -1, faz_func,},
{"Bat Goofy", 10, foo_func,},
|
Then I have a fairly basic use case for a macro system. I should be able to record a macro for editing the first line and then apply it to all the lines. So how does that process look for me as I literally type?
- Navigate to the beginning of the line; this is important because when I don't want the recorded macro to start with some arbitrary navigation.
- Begin macro recording.
- Set Mark.
- I-Search.
- Delete range.
- Type { .
- I-Search.
- Delete.
- Delete.
- Type } .
- Type , .
- Navigate to the the beginning of the next line.
- Complete macro recording.
This is not the case that confounds me, but it does raise an interesting question, which is "What is meant to happen when a macro replays a command that takes sub-inputs?" It could either be that we only replay command streams, but then this basic use case would require the user to re-type ", enter, ), enter for each application of the macro. Obviously the most useful thing would be to recreate the intention of the command. In this case the intention of the those commands are to search for " and ), no question about that. But now that I know there is some need to recreate the "intention" of each command, I can't help but wonder if I can come up with a case where I wouldn't know how 4coder should interpret the intention.
A case where I don't know how 4coder should interpret the intention
It's a little bit hard to imagine the
use case that would lead to an ambiguous user intention, not impossible, but it's easier to come up with the
input case that is ambiguous, and maybe we can talk about the use case that gives rise to this later.
- Navigate to a good anchor point (like before).
- Begin macro recording.
- I-Search to ( .
- Navigate one character right.
- Paste.
- Type , .
- Type <space> .
- Navigate to the next good anchor point.
- Finish macro recording.
This could mean one of two things at the "Paste" command. It could mean insert whatever string is currently at the top of the clipboard stack, which would be the easiest thing to implement. It could also mean insert whatever string
was at the top of the clipboard stack when the macro was recorded. I could see the second being an easy expectation and even sometimes a useful thing to have available.
If you're not convinced that this is ambiguous, then imagine sticking the output of paste into a sub-input to an I-Search, and then copy pasting something within the macro recording (forgive me for not writing out the beat for beat inputs for this case).
My question is
What does everyone else think about macros? In the case of the paste command how should things work? I'm not exactly sure what the best way to generalize this concept is, but my theory is that this ambiguity is coming from indirection. It is unclear when the macro system records a paste command whether the the intention was to record inserting the "value" pulled from the clipboard or inserting the "reference" to the clipboard. So in the general case how should a macro system be implemented around these ambiguities?