Sublime Forum

ST State Buffer (Or Something Similar)

#1

Preamble:

The final plugin might be called NoRegEx or something similar, and be a few functionalities/commands. Although regex is fantastic, I’m terrible at it. By the time I’ve learned enough regex to tweak what ever regex the internet has given me, it would have been quicker to do everything by hand. I then don’t need regex for another 6 months, so have then forgotten everything the next time I come to use it, thus something I can use from the keyboard, that doesn’t require regex, but does regex like things (in python). ( I know there’s regex in python )

For Example:

Say I want to find every thing (or select everything) between an open and closed parenthesis, perhaps min/max length is set in a setting; it would be reasonably easy to write a function that looks for each instance of “(” and “)” and then do something with self.view.replace(edit, region, replace_by) or some other sublime function, but what I’d like to do is select “(” in the file I’m editing, press a key combo, then select “)” and press some more keys combo and voila, the function selects all strings in the doc twixt “(” & “)”.

Thus it would appear that I need to store information between the first key press and the second. I’ve got a general find function (that @OdatNurd wrote for me so that I could use it in a macro a million years ago) so finding the first “(” (or whatever set of characters I want to find) is relatively easy, but then where or how do I store the information of that selection (i.e. that the NoRegex function has been engaged, position and contents of that selection i.e. where the “(” is etc.) so that I can return to the editor, do some stuff and then select the second string which will bound my search, in this case “)”. I could save it to a file and read that file when the second key combo is pressed (and if the file is empty just return), but that seems a bit cumbersome. Is there some kind of buffer, that can store info, that commands can use ?

Coming at this in a different way, basically I want to write a find function that stores all the info of what is found and where, for access later on.
I need to store state between command calls, is it possible and how do I do it ? Or do I just save to a file ? Sorry it’s a bit of a mammoth read for something fairly simple…

0 Likes