Sublime Forum

Porting begin_edit() ... end_edit() code

#1

I’m trying to get Nodejs to work for me on Linux (or any platform, for that matter). I’m running build 3065. I’ve read the Porting Guide, as well as several threads on here regarding converting begin_edit() … end_edit() blocks to TextCommands, but for the life of me I can’t figure out how to do that for this code. The full code in question is here, and the function I’m having trouble with is:

def _output_to_view(self, output_file, output, clear=False, syntax="Packages/JavaScriptNext - ES6 Syntax/JavaScriptNext.tmLanguage"):
    output_file.set_syntax_file(syntax)
    edit = output_file.begin_edit()
    if clear:
        region = sublime.Region(0, self.output_view.size())
        output_file.erase(edit, region)
    output_file.insert(edit, 0, output)
    output_file.end_edit(edit)

Does anyone have any ideas about turning this into a text command, or alternatively which arguments I should supply to begin_edit()?

0 Likes

#2

Something like:


try:
    from .Edit import Edit as Edit
except:
    from Edit import Edit as Edit

def _output_to_view(self, output_file, output, clear=False, syntax="Packages/JavaScriptNext - ES6 Syntax/JavaScriptNext.tmLanguage"):
    output_file.set_syntax_file(syntax)
    with Edit(self.output_view) as edit:
        region = sublime.Region(0, self.output_view.size())
        edit.erase(region)
        edit.insert(0, content)
0 Likes

#3

[quote=“tito”]ST2/3 Edit Abstraction

[/quote]

Tito,
Thanks a lot for the link, I hadn’t come across that part of AAAPackageDev yet. Instead of fooling around with dependencies, I just grabbed edit.py and put it in this project’s codebase for now. Your code was almost spot-on, I just replaced content in the last line with str(output) (since it’s coming in as a bytes object) and everything (with that function, at least) seems to be working great.

Thanks again!
Matt

0 Likes

#4

Cool B-)

0 Likes