SpartanJ / ecode

Lightweight multi-platform code editor designed for modern hardware with a focus on responsiveness and performance.
MIT License
938 stars 13 forks source link

Scripting the editor / Macros support #338

Open Curculigo opened 1 month ago

Curculigo commented 1 month ago
  1. Replace \n with ).
  2. Replace - with (.
  3. Replace \([^()]*\) with .

The input:

foo-1.0
bar-2.0

The output:

foo bar

I want to automate this boring task.

SpartanJ commented 1 month ago

I'll implement some Lua bindings for eepp at some point where you'll be able to implement Lua scripts using eepp resources, but that's not going to happen soon (huge task). This feature can be implemented in several ways, it's also commonly called as "macros" in editors. Some editors like Sublime Text and Notepad++ let you record your actions and generate a macro file with the actions recorded and you can then re-run them at any time. I'm not very fond of that feature, I've never used it because it can be much more limiting than just editing a script and also much more prone to errors. I think that scriptable macros are much more powerful and I would go that way for ecode.

Curculigo commented 1 month ago

Scripting the whole eepp is too much. I don't want to write eepp applications in Lua (or other scripting languages). I only want to script ecode, and to be clear, only the find and replace feature. I think my regex is flawed. One could do the same thing with only one find and replace step instead of three like me. What I'm thinking now is I will write a sed script and have the build and run feature to invoke it to change the current opening file's content on the fly. Maybe easier than scripting ecode. After having to do this task more than a couple of times a day, I started to think about automating it.

SpartanJ commented 1 month ago

Yeah, I wasn't saying that for this particular feature I want to bind all eepp, I want to bind it for other stuff, what you need is much simpler and probably does not require even a macro.

For your particular example you can use regex captures and replace with those captured parts of the regex (you'll need to update eepp to test it, there was a small bug there with regex captures):

foo-1.0
bar-2.0

Find (for example, I don't know your real case): (\w+)-[\d\.]+\n? Replace: $1

$1 is the number of capture to use as replacement, this will capture the first word (\w+) and use it in the replacement, so result will be: foo bar

This is very powerful, something that is pending since forever is saving the find history per-project, that could help for some situations where some searches are commonly repeated. Regarding macros I'll think about a good design, I don't particularly care much about it so I have no rush for this one.