Hi!
I’ve made a few plugins, and most of the time, when I need to replace a some text in a file, because of the edit
thing, I’m oblige to create a text command that takes a list and a string, and run the .replace(edit, region, text)
for me.
Here it is:
import sublime
import sublime_plugin
class ReplaceCommand(sublime_plugin.TextCommand):
def run(self, edit, region, text):
if len(region) != 2:
raise ValueError('ReplaceCommand: a region like should be a list with 2 items. Got {0}'.format(region))
self.view.replace(edit, sublime.Region(region[0], region[1]), text)
But, to make sure I’m using the right command and that I am not over writing anything, I prefix it with something. And I’m getting sick of it. I’ve got at least 5 commands that does exactly the same thing. (what I just told you :D)
So, here’s what comes out of it:
@jps Could you make a command that comes in the default package, with this gist for example (basically, takes a list, a text, and replace)? And it would have to come on st3 and st2 (otherwise it’s going to be even more annoying)
I’ll see if John agrees, but if not, here’s what I’d like to do:
Create kind of a convention: nobody creates a command called ReplaceCommand
And then, we have the choice:
- add a file in our packages that would automatically create the file with the command (in the
$packages
directory I guess). Here’s the file that’d do it - just add in our
README
a part saying: if you haven’t done it for an other package, create a file called<convention_name>.py
and paste this content in it. - create a “package” with one file with the command, and add it in our dependencies.
I guess the last solution (or the very first one ;)) is the best one, but it feels a bit weird to create a package for one file command…
I’m pretty sure some of you are wondering why we don’t just create this file in every package. The problem is that they’re going to overwrite themselves, and if someone changes it, and its package is load last, then every other package are going to get an unexpected behaviour.
If John doesn’t agree, there is in every case a convention to take. So, please let me (us) know your opinion, so we could stop dealing with this issue.
Thanks for reading,