Skip to content

Commit

Permalink
add commands to show all errors and select next/prev error
Browse files Browse the repository at this point in the history
sublimelint_next_error
sublimelint_next_error, "args": {"direction": -1}
sublimelint_all_errors
  • Loading branch information
lunixbochs committed Apr 18, 2012
1 parent d427db3 commit 2bf99c5
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Default.sublime-commands
Expand Up @@ -12,5 +12,17 @@
{
"file": "${packages}/User/SublimeLint.sublime-settings"
}
},
{
"caption": "SublimeLint: Show All Errors",
"command": "sublimelint_all_errors"
},
{
"caption": "SublimeLint: Next Error",
"command": "sublimelint_next_error"
},
{
"caption": "SublimeLint: Previous Error",
"command": "sublimelint_next_error", "args": {"direction": -1}
}
]
]
63 changes: 63 additions & 0 deletions commands.py
@@ -0,0 +1,63 @@
import sublime
import sublime_plugin
from lint import persist

def error_command(f):
def run(self, edit, **kwargs):
vid = self.view.id()
if vid in persist.errors:
f(self, self.view, persist.errors[vid], **kwargs)

return run

def select_line(view, line):
sel = view.sel()
point = view.text_point(line, 0)
sel.clear()
sel.add(view.line(point))

class sublimelint_next_error(sublime_plugin.TextCommand):
@error_command
def run(self, view, errors, direction=1):
self.view.run_command('single_selection')
sel = view.sel()
if len(sel) == 0:
sel.add((0, 0))

line = view.rowcol(sel[0].a)[0]
errors = list(errors)
if line in errors: errors.remove(line)
errors = sorted(errors + [line])

i = errors.index(line) + direction
if i >= len(errors):
i -= len(errors)

select_line(view, errors[i])
view.show_at_center(sel[0])

class sublimelint_all_errors(sublime_plugin.TextCommand):
@error_command
def run(self, view, errors):
options = []
option_to_line = []

for lineno, messages in sorted(errors.items()):
line = view.substr(
view.full_line(view.text_point(lineno, 0))
)
while messages:
option_to_line.append(lineno)
options.append(
[("%i| %s" % (lineno + 1, line.strip())).encode('ascii', 'replace')] +
[m.encode('ascii', 'replace') for m in messages[:2]]
)

messages = messages[2:]

def center_line(i):
if i != -1:
select_line(view, option_to_line[i])
view.show_at_center(view.sel()[0])

view.window().show_quick_panel(options, center_line, sublime.MONOSPACE_FONT)

0 comments on commit 2bf99c5

Please sign in to comment.