Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Last active May 27, 2020 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattdesl/1f642afe2786c27433e4 to your computer and use it in GitHub Desktop.
Save mattdesl/1f642afe2786c27433e4 to your computer and use it in GitHub Desktop.
sublime lint auto save hack

quick hack to explore auto-saving on lint-free code

Using SublimeLint3

Sublime Text -> Preferences -> Browser Packages Open sublimelinter.py in Sublime.

Seek to the highlight method (Cmd + R)

replace with function (see below)

save file to update plugin

def highlight(self, view, linters, hit_time):
"""
Highlight any errors found during a lint of the given view.
This method is called by Linter.lint_view after linting is finished.
linters is a list of the linters that ran. hit_time has the same meaning
as in lint(), and if the view was modified since the lint request was
made, this method aborts drawing marks.
If the view has not been modified since hit_time, all of the marks and
errors from the list of linters are aggregated and drawn, and the status
is updated.
"""
vid = view.id()
# If the view has been modified since the lint was triggered,
# don't draw marks.
if hit_time is not None and persist.last_hit_times.get(vid, 0) > hit_time:
return
errors = {}
highlights = persist.highlights[vid] = HighlightSet()
# SAVE HACK
hasErrors = False
for linter in linters:
if linter.highlight:
# SAVE HACK
if len(linter.highlight.marks['error']) > 0:
hasErrors = True
highlights.add(linter.highlight)
if linter.errors:
for line, errs in linter.errors.items():
errors.setdefault(line, []).extend(errs)
# Keep track of one view in each window that shares view's buffer
window_views = {}
buffer_id = view.buffer_id()
for window in sublime.windows():
wid = window.id()
for other_view in window.views():
if other_view.buffer_id() == buffer_id:
vid = other_view.id()
persist.highlights[vid] = highlights
highlights.clear(other_view)
highlights.draw(other_view)
persist.errors[vid] = errors
if window_views.get(wid) is None:
window_views[wid] = other_view
for view in window_views.values():
self.on_selection_modified_async(view)
# SAVE HACK
if not hasErrors:
persist.debug("Auto-saving file...")
view.run_command("save")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment