def tidyRegion(self, view, region):
		if os.path.isfile(self.DefaultPerlTidy):
			# use installed PerlTidy
			cmd = [self.DefaultPerlTidy]
			# print "using installed PerlTidy", cmd
		else:
			# use packaged PerlTidy, needs Perl to run
			cmd = ["perl", sublime.packagesPath() + "/PerlTidy/perltidy"]
			# print "using packaged PerlTidy", cmd

		cmd += [
			"-w", # report all errors and warnings
			"-se" # send error message to stderr rather than filename.err
		]

		cmd += self.PrettyPrintingParams # add pretty printing parameters

		p = subprocess.Popen(
			cmd,
			shell   = True,
			bufsize = -1,
			stdout  = subprocess.PIPE,
			stderr  = subprocess.PIPE,
			stdin   = subprocess.PIPE)

		output, error = p.communicate(view.substr(region))

		view.replace(region, output)

		if error:
			results = view.window().newFile()
			results.setScratch(True)
			results.setName("PerlTidy error output")
			results.insert(0, error)
示例#2
0
    def lintFile(self, view, openFull):
        basePath = sublime.packagesPath()+"\\Seld\\"
        startupinfo = STARTUPINFO()
        startupinfo.dwFlags |= STARTF_USESHOWWINDOW
        content = view.substr(Region(0, view.size()))
        process = Popen('cscript "'+basePath+'jslint.js"', stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=startupinfo)
        (stdout, stderr) = process.communicate(content)

        output = b''
        for line in stderr.splitlines():
            print line
            if line[0:7] == 'Lint at':
                if output.strip():
                    output += b"\n"
                try:
                    output += line.decode('utf-8').strip() + " >>"
                except UnicodeDecodeError:
                    print "File encoding error detected"
            elif output.strip() and line.strip():
                output += " "+line.decode('utf-8').strip()

        if not output.strip():
            if openFull:
                view.eraseRegions('jsLint')
                self.updateStatus('No syntax error detected')
            return

        if openFull:
            lines = output.splitlines()
            jsLint.highlightTexts(self, view, lines)
            view.window().showQuickPanel("", "jsLintGoto", lines, sublime.QUICK_PANEL_MONOSPACE_FONT)
        else:
            sublime.setTimeout(functools.partial(self.updateStatus, '<!> '+output.splitlines()[0]), 100)
	def run(self, view, args):
		options = ""
		#options = "-ayfpdUc"
		path = sublime.packagesPath()
		path = os.path.join(path, "User")
		dll = os.path.join(path, "AStyle.dll")

		# if the function name has a @ followed by number it probably uses the stdcall calling convention. 
		libc = windll.LoadLibrary(dll)
		astyle_main = libc[2]
		astyle_main.restype = c_char_p
		astyle_main.argtypes = [c_char_p, c_char_p, ErrorHandlerCallback, MemoryAllocationCallback]
		
		region = sublime.Region(0L, view.size())
		select_all = view.substr(region)
		pretty_code = astyle_main(select_all, options, ERROR_HANDLER, MEMORY_ALLOCATION)
		view.replace(region, pretty_code)
	def __init__(self):
		sublimeplugin.WindowCommand.__init__(self)
		self.__db = None
		# pluginDir = path.dirname(path.realpath(__file__))
		# self.dbfilename = path.join(pluginDir, "ProjectMRU.db")
		self.dbfilename = sublime.packagesPath() + "/ProjectMRU/ProjectMRU.db" # is there a better way to get the plugin's folder?