Reader small image

You're reading from  Mastering Sublime Text

Product typeBook
Published inDec 2013
PublisherPackt
ISBN-139781849698429
Edition1st Edition
Right arrow
Author (1)
Dan Peleg
Dan Peleg
author image
Dan Peleg

Dan Peleg is an accomplished software engineer. As a former developer in the Israeli Intelligence Force, he holds extensive experience in both defense and robotic industries, and has previously lectured at DefCon conventions. Dan has developed unique algorithms for robotic platforms, specializes in a variety of software platforms, and currently works as the CTO for an American startup company.
Read more about Dan Peleg

Right arrow

Developing the plugin


Now that we have a plugin with a basic command that shows up in the command palette, we can start developing our plugin; we'll start with hiding the command when it's unusable. We'll do it by overriding the is_visible function and checking that the current file extension is .rb and the first line contains a ActiveRecord::Base inheritance. Let's import the python os lib by adding import os below the import sublime line. Add the following to our command:

def is_visible(self):
   view = self.window.active_view()
   file_name, file_extension = os.path.splitext(view.file_name())
   return file_extension == ".rb" and "ActiveRecord::Base" in view.substr(view.line(0))

When the command palette is being opened, it will run all the is_visible functions of all the exposed commands to check whether or not they should be shown. We are checking whether or not the current view (file) extension is set as .rb and the first line of the file contains ActiveRecord::Base and only if both conditions...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Mastering Sublime Text
Published in: Dec 2013Publisher: PacktISBN-13: 9781849698429

Author (1)

author image
Dan Peleg

Dan Peleg is an accomplished software engineer. As a former developer in the Israeli Intelligence Force, he holds extensive experience in both defense and robotic industries, and has previously lectured at DefCon conventions. Dan has developed unique algorithms for robotic platforms, specializes in a variety of software platforms, and currently works as the CTO for an American startup company.
Read more about Dan Peleg