Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpeckham committed Dec 27, 2014
1 parent 1bcd553 commit ec6dfc4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.py[cod]
*.pyc
*.sublime-project
*.sublime-workspace
14 changes: 9 additions & 5 deletions Filter Lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import sublime_plugin


imap = itertools.imap


def match_line(needle, haystack, search_type, case_sensitive, invert_search = False):
if invert_search:
return not search_line(needle, haystack, search_type, case_sensitive)
Expand Down Expand Up @@ -105,6 +108,7 @@ def filter_to_new_buffer(self, edit, needle, search_type, case_sensitive,
results_view.set_name('Filter Results')
results_view.set_scratch(True)
results_view.settings().set('word_wrap', self.view.settings().get('word_wrap'))
results_edit = results_view.begin_edit()

# get non-empty selections
# regions = [s for s in self.view.sel() if not s.empty()]
Expand All @@ -116,7 +120,7 @@ def filter_to_new_buffer(self, edit, needle, search_type, case_sensitive,

if separator is None:
lines = (self.view.split_by_newlines(r) for r in regions)
lines = map(self.view.substr,
lines = imap(self.view.substr,
itertools.chain.from_iterable(lines))
else:
lines = itertools.chain.from_iterable(
Expand All @@ -131,15 +135,15 @@ def filter_to_new_buffer(self, edit, needle, search_type, case_sensitive,
line += '\n'
text += line

results_view.run_command(
'append', {'characters': text, 'force': True,
'scroll_to_end': False})
results_view.insert(results_edit, results_view.size(), text)

if results_view.size() > 0:
results_view.set_syntax_file(self.view.settings().get('syntax'))
else:
message = 'Filtering lines for "%s" %s\n\n0 matches\n' % (needle, '(case-sensitive)' if case_sensitive else '(not case-sensitive)')
results_view.run_command('append', { 'characters': message, 'force': True, 'scroll_to_end': False })
results_view.insert(results_edit, results_view.size(), message)

results_view.end_edit(results_edit)

def filter_in_place(self, edit, needle, search_type, case_sensitive, invert_search):
# get non-empty selections
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Filter Lines

Quickly find all lines matching a string or regular expression in Sublime Text 3.
Quickly find all lines matching a string or regular expression in Sublime Text 2.

* Edit > Line > Filter With Regex <kbd>⌘+K</kbd> <kbd>⌘+R</kbd>
* Edit > Line > Filter With String <kbd>⌘+K</kbd> <kbd>⌘+S</kbd>
Expand Down

0 comments on commit ec6dfc4

Please sign in to comment.