Sublime Forum

My VCS plugin

#1

Hi together,

I searched for a combined plugin for Git and SVN, but I didn’t find a package that I liked. The existing ones are fairly complete, but they have too much functionality in my oppinion, which I don’t need. And for instance HypnotoadSVN creates too much menu entries, which I also don’t like. So I tried to make my own VCS plugin, which combines Git and SVN in one. I thought it is a good exercise since I am new to Python and plugin development as well.

I didn’t find a way to attach files, so I paste the code of my plugin below. Because I have some questions about it.

First of all:
panel is a global variable for the output panel, where I want to display SVN and Git text messages. It works well, but when I open a second Sublime Text window, then it keeps printing at the old window, and if the old window is closed, there is no output panel anymore :slight_smile: So the question is: how can I print always in the active window?

Second question:
When I do a “Git Pull” or “SVN Update” command, which can take a few seconds, Sublime Text hangs during that time. I know the reason; it is because Python waits until the Git or SVN process started has finished. But how can I change the behaviour of this, such that Sublime does not hang?

Many thanks in advance for any help!

edit:
does not work to paste the code here. Link: http://pastebin.com/m3L93DSm

0 Likes

#2

You can call your function with sublime.set_timeout_async(my_func)
If your function need parameter you can use lambda

0 Likes

#3

Hi @Clams I don’t know lambda very well. Could you give me a sample? I have no idea how to use lambda in this context.

0 Likes

#4

Let’s say your function take one parameter, you want to set this parameter to the value v:

sublime.set_timeout_async(lambda x=v: my_func(x))

And with two parameters:

sublime.set_timeout_async(lambda x0=v0, x1=v1: my_func(x0,x1))
0 Likes

#5

Thank you, I’ll try that!

Do you have any ideas concerning the output panel?

0 Likes

#6

Not sure but a panel is attached to a window: if you change window you need to create a new panel associated with this window.
Personally I wrote a small function to print to a panel, where I basically always create the panel (if the panel already exist then nothing happens, this does not clear the panel).

def print_to_panel(txt,name):
    window = sublime.active_window()
    p = window.create_output_panel(name)
    p.run_command('append', {'characters': txt})
    window.run_command("show_panel", {"panel": "output."+name})
0 Likes

#7

Hmm, I copied your code snippet to my project, but it clears the panel all the time so I can just see the last printed line! It looks like window.create_output_panel(name) always creates a new panel.

0 Likes

#8

Ah yes correct, I forgot how I used this function (i need the clean in fact :P)
Just use the find_output_panel(name) function to decide if you need the create_output_panel

def print_to_panel(txt,name):
    window = sublime.active_window()
    v = window.find_output_panel(name)
    if not v:
        v = window.create_output_panel(name)
    v.run_command('append', {'characters': txt})
    window.run_command("show_panel", {"panel": "output."+name})
0 Likes

#9

Hey this is just brilliant, it works absolutely perfect! Thank you :slight_smile:

0 Likes