Home Download Buy Blog Forum Support

New begin_edit() signature in ST3

New begin_edit() signature in ST3

Postby fcoury on Wed Jan 30, 2013 2:10 am

I noticed in ST3, begin_edit requires two arguments: cmd and args. What are those attributes supposed to receive?
fcoury
 
Posts: 17
Joined: Wed Dec 14, 2011 5:13 pm

Re: New begin_edit() signature in ST3

Postby fcoury on Wed Jan 30, 2013 3:28 am

OK, I got this working. When you have a TextCommand, instead of creating an edit yourself with begin_edit(), you receive an additional edit parameter that is prepended to the usual args in ST2. On to the next challenge: async processing.
fcoury
 
Posts: 17
Joined: Wed Dec 14, 2011 5:13 pm

Re: New begin_edit() signature in ST3

Postby Clams on Wed Jan 30, 2013 7:29 am

I have the same issue with begin_edit, except that i was using for an output panel :

Code: Select all
   def print_to_panel_mainthread(self,cmd,str_a):
      win = sublime.active_window()
      strtxt = u"".join(str(line) for line in str_a)
      if(len(str_a)):
         v = win.create_output_panel('hg_out')
         if cmd=="diff" :
            v.set_syntax_file('Packages/Diff/Diff.tmLanguage')
            v.settings().set('word_wrap', self.view.settings().get('word_wrap'))
         edit = v.begin_edit(None,None) ##### ISSUE HERE #####
         v.insert(edit, 0, strtxt)
         v.end_edit(edit)
         win.run_command("show_panel", {"panel": "output.hg_out"})

To have the code compile i tried None and 0, but the issue is that now my panel shows up empty. Any idea ?

I don't mind using sublime.py and sublime_plugin.py as "documentation" for the API, but slightly more comment (as just a bit more than none :P ) would help a lot, at least for stuff that change compare to ST2.
Clams
 
Posts: 46
Joined: Fri Dec 30, 2011 7:44 am

Re: New begin_edit() signature in ST3

Postby quarnster on Wed Jan 30, 2013 9:01 am

Clams wrote:but slightly more comment (as just a bit more than none )


I take it you haven't read the porting guide.
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: New begin_edit() signature in ST3

Postby Clams on Wed Jan 30, 2013 12:52 pm

I did read it, but I'm talking about the .py file that jon suggest to use as reference for the new API functions. Putting some comment about the parameter expected by the function could help plugin dev a lot (and could even be used to automatically generate basic API reference).

Anyway, in my case i found a way to make it work: replacing all the part between begin_edit end_edit by a v.run_command('append', {'characters':strtxt})
Clams
 
Posts: 46
Joined: Fri Dec 30, 2011 7:44 am

Re: New begin_edit() signature in ST3

Postby Clams on Wed Feb 06, 2013 10:45 pm

I was trying to update the excellent plugin AlignTab for ST3 and i had an issue around this edit parameter.

After modification to remove begin_edit/end_edit, and using directly the edit from the TextCommand I get:
Code: Select all
class AlignTabCommand(sublime_plugin.TextCommand):

    def run(self, edit, user_input=None):
        self.edit = edit
        print("Called with params " + str(user_input))
        if not user_input:
            v = self.view.window().show_input_panel('Align with regex:', '',
                    self.align_tab, None, None)
            # print os.getcwd()
            v.set_syntax_file('Packages/AlignTab/AlignTab.tmLanguage')
            v.settings().set('gutter', False)
            v.settings().set('rulers', [])
        else:
           self.align_tab(user_input)


If the command is called directly with some parameters everything works fine. But if there is no parameters, it shows the panel and then the text is not aligned (but the function is correctly called, i can see some change in selection and stuff).

I managed to workaround the issue (instead of calling align_tab when show_input_panel is done, I do a lambda x : self.view.run_command("align_tab",{"user_input":x}) ), but I still don't understand what is wrong in the initial code .Is it a bug, or I'm missing something ?
Clams
 
Posts: 46
Joined: Fri Dec 30, 2011 7:44 am

Re: New begin_edit() signature in ST3

Postby sublimator on Fri Feb 08, 2013 4:37 am

It's async code, so after showing the input panel, the command finishes and that original edit object (that you stowing away as self.edit) has expired
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 648
Joined: Thu Mar 20, 2008 5:41 am

Re: New begin_edit() signature in ST3

Postby Clams on Fri Feb 08, 2013 5:35 am

Ok I understand now :) So the way I handle it is fine I guess .
Clams
 
Posts: 46
Joined: Fri Dec 30, 2011 7:44 am

Re: New begin_edit() signature in ST3

Postby Brendon77 on Tue Jun 18, 2013 8:36 am

Clams wrote:Ok I understand now :) So the way I handle it is fine I guess .

Please me and share with examples. Thank you...
Brendon77
 
Posts: 1
Joined: Tue Jun 18, 2013 8:26 am

Re: New begin_edit() signature in ST3

Postby pondshus2 on Mon Feb 17, 2014 11:17 am

args attribute receives a numerical value corresponding to the command that is passed to the cmd attribute. This is how it usually works. But I have heard that there is some differences in ST3. So just run through the guide once again to make sure the attributes goes as mentioned above.
pondshus2
 
Posts: 3
Joined: Fri Oct 25, 2013 6:07 am


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 14 guests