Sublime Forum

OpenInclude

#1

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 :smile:

[code]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))[/code]

James

0 Likes

#2

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 :wink:.

0 Likes

#3

I was thinking of doing this the other day :smile:

GitHub ok?

0 Likes

#4

I prefer bitbucket but you’re the author :wink:.

0 Likes