Home Download Buy Blog Forum Support

SublimeLint (Realtime lint highlighting)

Re: SublimeFlakes (Inline realtime Python lint)

Postby rspeer on Wed Feb 02, 2011 9:33 pm

It took me a bit to figure out how to run the plugin with the directions given here. I was about to ask for more explicit directions, but then I figured it out, so I might as well say what I did for anyone else who's confused.

If you unzip the file using Finder, it gives you a folder called "sublimeflakes_3-3". If you put that folder in ~/Library/Application Support/Sublime Text 2/Packages/User/, nothing happens. You need to put the contents of that folder, which are "pyflakes" and "sublimeflakes.py", in ~/Library/Application Support/Sublime Text 2/Packages/User/.
Posts: 7
Joined: Tue Feb 01, 2011 8:43 pm

Re: SublimeFlakes (Inline realtime Python lint)

Postby val.sv on Thu Feb 03, 2011 9:08 pm

This looks promising. I can't get it to work though. I'm using version 20110203 of ST2 on Windows 7.
I can see a sublimeflakes.pyc getting created when I start Sublime Text.

After I've started Sublime Text 2 I can see this at the end of the console:
Code: Select all
loaded 919 snippets
Unhandled exception in thread started by <function validate_runner at 0x0241EBF0>
Traceback (most recent call last):
  File ".\sublimeflakes.py", line 232, in validate_runner
  File ".\sublimeflakes.py", line 75, in validate
RuntimeError: Must call on main thread, consider using sublime.set_timeout(function, timeout)

Nothing happens when I edit a pythonfile.
Posts: 3
Joined: Sun Mar 21, 2010 11:02 pm

Re: SublimeFlakes (Inline realtime Python lint)

Postby jps on Thu Feb 03, 2011 11:30 pm

This is due to a change in 20110203 which enforces that plugins are only allowed to call API functions from the main thread.
Site Admin
Posts: 3058
Joined: Wed Mar 19, 2008 12:33 pm

Re: SublimeFlakes (Inline realtime Python lint)

Postby sovarm on Fri Feb 04, 2011 2:37 pm

Nothing happens when I edit my python code. :( I'm using the latest Sublime 2 for Mac.
Posts: 2
Joined: Fri Feb 04, 2011 2:35 pm

Re: SublimeFlakes (Inline realtime Python lint)

Postby theblacklion on Sat Feb 05, 2011 10:13 pm

I've hacked the code a bit so that it works for me. Hope that it helps.
(2.8 KiB) Downloaded 198 times
Posts: 67
Joined: Sat Feb 05, 2011 10:07 pm
Location: Hannover, Germany

Re: SublimeFlakes (Inline realtime Python lint)

Postby lunixbochs on Sun Feb 06, 2011 7:32 pm

theblacklion wrote:I've hacked the code a bit
oh nice, we can use set_timeout from a thread? I'll include that in the master version until I craft a better solution.

zeeg: I shot you a PM back, looks like this forum might not send emails for PM notifications

everyone else:
it's now on github with a few fixes and more updates to come: https://github.com/lunixbochs/sublimelint
Posts: 91
Joined: Fri Oct 08, 2010 10:18 pm

Re: SublimeFlakes (Inline realtime Python lint)

Postby sovarm on Wed Feb 09, 2011 11:45 am

It works! Great! Thanks!
Posts: 2
Joined: Fri Feb 04, 2011 2:35 pm

Re: SublimeFlakes (Inline realtime Python lint)

Postby evilkarlothian on Mon Feb 14, 2011 6:30 am

Works great for me too (Ubuntu 10.10 64bit):

Code: Select all
cd ~/.Sublime\ Text\ 2/Packages
git clone https://github.com/lunixbochs/sublimelint.git
Posts: 1
Joined: Mon Feb 14, 2011 6:28 am

Re: SublimeFlakes (Inline realtime Python lint)

Postby gpfsmurf on Tue Feb 15, 2011 9:42 pm

lunixbochs wrote:Afaik you just need to put the contents of the zip file directly inside:
  • OS X: ~/Library/Application Support/Sublime Text 2/Packages/User/
  • Windows: %APPDATA%/Sublime Text 2/Packages/User/
  • Linux: ~/.Sublime Text 2/Packages/User/

You can also put it in its own folder: [...]/Packages/SublimeFlakes/ instead of [...]/Packages/User/
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: SublimeFlakes (Inline realtime Python lint)

Postby vostok4 on Sun Feb 20, 2011 7:06 am

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: Select all
# 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
   result = subprocess.Popen(['php', '-l', tmpFileName], stdout=subprocess.PIPE, startupinfo=info).communicate()[0]   
   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] = [message]
   m = re.search(r"on line (\d+)", errors);
   if m:
      lineno = int(m.group(1))
      lineno -= 1
      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

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

Code: Select all
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)   

also delete line 10 in: https://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.
Posts: 25
Joined: Fri Oct 22, 2010 6:09 pm


Return to Plugin Announcements

Who is online

Users browsing this forum: sankglory and 6 guests