[Solved] Can I represent (and use) a search-and-replace instruction in text?

#1

Atom seems great, and I am trying to standardize on it. My one big sticking point is simple command re-use, specifically search-and-replace actions using complex regexes.

EG: Right now, I want to develop a series of regex translations to convert a latex formula, like this:

\frac{2-t}{t^{2}(t-1)(t+1)}-\frac{x(t-1)}{t}&=\frac{1}{t^{2}(t^{2}-1)}+\frac{x(2t^{2}-2t)}{(t^{2}-1)}

Into a simplified version that can be pasted into wolfram alpha, like this:

((2-t)/(t^(2)(t-1)(t+1)))-((x(t-1))/(t)) = ((1)/(t^(2)(t^(2)-1)))+((x(2t^(2)-2t))/((t^(2)-1)))

In tools like vi or kedit, I could easily represent my series of transformations with strings that could be copy-pasted into the vi commandline.

s/\\(\w+){([^}]+)}/\1(\2)/
s/\\frac{(\w+)}{(\w+)}/(($1)/($2))/
s/[\\&]//


Atom doesn’t appear to have anything like a commandline. The command palette doesn’t seem to allow parameterized commands. Am I missing something?

#2

Ctrl-F Gives the find-replace function that can handle regular expressions if .* button is selected.

If this transform is used regularly, you could code it to a shortcut key.

#3

Thanks for your interest! Please correct me if I’m wrong, but what I’m hearing is a suggestion that I do the following actions:

• type ctrl-F,
• find / copy my search string,
• mouse to the search field,
• paste,
• find / copy my replace string,
• mouse to the replace field,
• paste,
• mouse to the replace-all key (OK, maybe there’s a hotkey)

Repeat for each of my 3 operations. That’s a total of 24-30 user inputs, depending how I access my search/replace strings. Worse, the actions alternate between keyboard and mouse. Increasing by 8-10 for every new transform that I wish to add. This is quite precisely the sequence that I’m trying to avoid.

Rephrased, my question is: does Atom provide a way for me to script this to one (or perhaps 3) actions without writing a plugin?

#4

As novice I would code a small segment in init.coffee or search for a package.
However I cannot help but wonder -

Does this offer what you ask?

#5

Aha! My flawed assumption was that the only way to create new commands was to build a whole new package.

Init.coffee should do it. I just need to create a new command consisting of a few simple calls to replace. That will fulfill my need, and be easily editable as my (complex) replace function evolves.

One note - realize even if the default is Coffeescript, you could use Javascript instead by replacing init.coffee with init.js. My novice recommendation is to stay with Coffeescript.