OK this is a seriously awesome plugin.
I decided to extend it to PHP so that it uses the PHP in your path to do a lint check on the source. It doesnât give you the nice granularity of errors, but it will immediately highlight a line when it has a problem, which is incredibly useful for me (once we can extend the Autocomplete API Iâm pretty sure I can make ST2 my full time PHP editor).
Here is my file, I just used your python.py module as an example. It is called php.py
[code]# php.py - sublimelint package for checking php files
start code to actually work with PHP and lint check input
import subprocess, os, tempfile
def check(codeString, filename):
info = None
if os.name == ântâ:
info = subprocess.STARTUPINFO()
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = subprocess.SW_HIDE
tmpFile = tempfile.NamedTemporaryFile(delete=False)
tmpFileName = tmpFile.name
tmpFile.write(codeString)
tmpFile.close()
result = subprocess.Popen(âphpâ, â-lâ, tmpFileName], stdout=subprocess.PIPE, startupinfo=info).communicate()[0]
os.unlink(tmpFileName)
return result, tmpFileName
start sublimelint php plugin
import re
all = ârunâ, âlanguageâ]
language = âPHPâ
def run(code, view, filename=âuntitledâ):
errors, tmpFile = check(code, filename)
lines = set()
underline = ] # leave this here for compatibility with original plugin
errorMessages = {}
def addMessage(lineno, message):
message = str(message)
if lineno in errorMessages:
errorMessages[lineno].append(message)
else:
errorMessages[lineno] = [message]
m = re.search(r"on line (\d+)", errors);
if m:
lineno = int(m.group(1))
lineno -= 1
lines.add(lineno)
errorLines = errors.splitlines();
tmpFile = tmpFile.replace("\\", "\\\\")
m2 = re.search(r"(.*) in " + tmpFile + " on line \d+", errorLines[1])
addMessage(lineno, m2.group(1))
return underline, lines, errorMessages, True
[/code]
As well I decided to implement one of your TODO lists, the automatic loading of modules based on their file names. Here is the head of my file (until drawType):
import sublime, sublime_plugin
import os, glob
# todo:
# * fix lag
languages = ]
# fix for __import__ returning 'sublimelint.modules.foo'.split('.')[0] as the module name
def importhelper(name):
mod = __import__(name)
components = name.split('.')
for comp in components[1:]:
mod = getattr(mod, comp)
return mod
# auto include our modules
for modfile in glob.glob('sublimelint/modules/*.py') :
if '__init__' in modfile: continue
modname = os.path.basename(modfile).split('.')[0]
vars()[modname] = importhelper('sublimelint.modules.'+ modname)
languages.append(vars()[modname])
also delete line 10 in: github.com/lunixbochs/sublimeli ⊠_plugin.py
and it should work.
Sorry if the code is garbage, this is my first foray ever into Python, definitely an interesting language.