Home Download Buy Blog Forum Support

OpenInclude

OpenInclude

Postby jbrooksuk on Sat Feb 19, 2011 12:20 am

Hey all,

My second plugin; OpenInclude allows you to open files by simply pressing whatever mapped key you have (I use Alt+D)

It's a modified version of code posted by adzenith - so thanks :)

Code: Select all
import sublime, sublime_plugin
import os.path
import re

class OpenInclude(sublime_plugin.TextCommand):
   def run(self, edit):
      for region in self.view.sel():
         syntax = self.view.syntax_name(region.begin())
         if re.match(".*string.quoted.double", syntax): self.select(self.view, region, '"') # Match & Select Doubles
         if re.match(".*string.quoted.single", syntax): self.select(self.view, region, "'") # Match & Select Singles
         
         for region in self.view.sel():
            if region.empty():
               line = self.view.line(region)
               filepath = self.view.substr(line).strip()
            else:
               filepath = self.view.substr(region)

            if os.path.isfile(filepath):
               self.view.window().open_file(filepath)
               sublime.status_message("Opening file " + filepath)

   def select(self, view, region, char):
      begin = region.begin() - 1
      end = region.begin()
      while view.substr(begin) != char or view.substr(begin - 1) == '\\': begin -= 1
      while view.substr(end) != char or view.substr(end - 1) == '\\': end += 1
      view.sel().subtract(region)
      view.sel().add(sublime.Region(begin + 1, end))

James
jbrooksuk
 
Posts: 781
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: OpenInclude

Postby theblacklion on Sun Feb 20, 2011 11:41 pm

Would you mind putting it into a repo? Could also be a collection of scripts for st2 like I have... That would be easier for me to track it for future changes ;).
theblacklion
 
Posts: 67
Joined: Sat Feb 05, 2011 10:07 pm
Location: Hannover, Germany

Re: OpenInclude

Postby jbrooksuk on Mon Feb 21, 2011 8:11 am

theblacklion wrote:Would you mind putting it into a repo? Could also be a collection of scripts for st2 like I have... That would be easier for me to track it for future changes ;).

I was thinking of doing this the other day :)

GitHub ok?
jbrooksuk
 
Posts: 781
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: OpenInclude

Postby theblacklion on Mon Feb 21, 2011 9:50 am

jbrooksuk wrote:GitHub ok?


I prefer bitbucket but you're the author ;).
theblacklion
 
Posts: 67
Joined: Sat Feb 05, 2011 10:07 pm
Location: Hannover, Germany


Return to Plugin Announcements

Who is online

Users browsing this forum: Yahoo [Bot] and 8 guests