SublimeLinter/SublimeLinter3 — pull request #122 by fgimian (2014-06-28 12:21:58+00:00)
Title: Made scratch detection less I/O intensive and more robust

Hi there,

I've spent the afternoon looking carefully into ways to improve SublimeLinter's I/O utilisation.

The additions that you made recently to address this were greatly appreciated and I have attempted to take them a tiny bit further.

The Sublime Text bug that has been worked around in is_scratch() method unfortunately appears to occur on the first on_modified event (rather than the on_activate event). I've tested this rather thoroughly across OSX, Linux and Windows to confirm. As such, the workaround put in place with the on_activated kwarg doesn't quite do the trick and causes exceptions when editing settings files in packages.

As such, this pull request does the following:

* Ensures that os.chdir is run to return the user to their original cwd even if cmd is ''
* Works around the Sublime Text bug by only checking existence of files if the file being edited is in the user's package path (which is where all package files turn up, including files in compressod .sublime-package packages). This has dramatically improved I/O performance which is especially noticable on network volumes.
* Due to the changes in the is_scratch() method, I have ensured that chdir is simply ignored if the file's directory no longer exists. Please note that I have intentionall caught an exception instead of checking for the existence with os.path.exists as this method is much less I/O intensive.

I have tested this patch on OSX (Mavericks), Linux (Linux Mint 14) and Windows (Windows 8.1) under the following 3 circumstances with success:

* Test case 1: Ensure that regular linting of ordinary files works
* Test case 2: Ensure that linting of files in Sublime packages is disabled and throws no errors
* Test case 3: Ensure that linting of files who's directory no longer exists continues to work without error

Both flake8 and pep257 checks pass too.

Thanks a lot for your time
Fotis