I’m trying to create a command that moves the cursor to the beginning of the file and then triggers a particular snippet. There was another question long ago that said that calling clear before the snippet was the problem, but I believe I’ve fixed that by making sure that there’s a region set after that.
So, here’s my little plugin:
class vhdlModeInsertHeaderCommand(sublime_plugin.TextCommand):
def run(self, edit):
print("Start of VMIH Command")
bof = self.view.text_point(0,0)
self.view.sel().clear
self.view.sel().add(sublime.Region(bof))
self.view.show(bof)
print("Point moved to beginning of file. Starting insert snippet command.")
self.view.run_command("insert_snippet", {"name" : "Packages/vhdl-mode/Snippets/vhdl-header.sublime_snippet"})
print("Post insert snippet command.")
So, I’ve tested the bits and pieces of this as follows:
-
The point moving routine is basically just the default “goto_line.py” routine but customized for my desires. I COULD just call goto_line I suppose, but for training purposes I was typing it all out myself.
-
In the console, I can type view.run_command(“insert_snippet”. …) and it inserts the snippet correctly at the location of the point. So I am pretty sure the actual command is right and it’s calling the snippet from the path, etc.
-
I added the print statements just to see where it was ending up. It actually seems to get to the end. Here’s the output:
view.run_command(“vhdl_mode_insert_header”)
Start of VMIH Command
Point moved to beginning of file. Starting insert snippet command.
Post insert snippet command.
Any ideas? I guess the command is running alright, but it’s not displaying to the user and doesn’t insert the template text.