Sublime Forum

Plugin works in blank file, but not in .php file - what am i doing wrong?

#1

So, I took my first hack at writing a super simple plugin for Sublime 3.
All I needed were my initial and the current date, as you can tell, I started with the example Hello World plugin and the docs and just modified from there.

heres the code:

import sublime
import sublime_plugin
import datetime

class ExampleCommand(sublime_plugin.TextCommand):
	def run(self, edit):
		day = (datetime.datetime.now().strftime("%Y-%m-%d")) 
		sig = "OE " + day
		self.view.insert(edit, 0, sig)

I also registered the following key binding:

[
{"keys": ["f5"], "command": "example" },	
]

-Now, when I open up a new blank file and press f5, I get:

OE 2017-10-12

which is correct.

But, when I do this in say, index.php on a new line, a file where there is plenty of existing code, the plugin won’t fire, meaning that I hit f5 and NOTHING happens.

The console reports no errors, and I can run the command view.run_command(“example”) and get the proper output in a blank file but not in the php file.

Also, running sublime.log_input(True) to log my inputted keys is returning f5 for my keypress, so I know its not getting misinterpreted.

How can I make this plugin run in all files?

0 Likes

#2

Plugin works, was inserting at the top of my page instead of where my cursor was placed. I would have deleted this, but the forum wont let me.

0 Likes