Skip to content

Commit

Permalink
Make search in selected files opt-in
Browse files Browse the repository at this point in the history
By default we search everywhere now. To search only on the selected files,
start your query with a ':' (a single colon sign).

The colon sign will be removed from the query but will enable the selected
files filter.

I did this because I prefer the default to be search everywhere.
I rarely use the "search in selected files" feature.

Signed-off-by: Pedro Melo <melo@simplicidade.org>
  • Loading branch information
melo committed Aug 11, 2008
1 parent 6abdeb4 commit a598b52
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
19 changes: 17 additions & 2 deletions SearchInProjectWithAck.tmCommand
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
# Updated to use with ack by Pedro Melo &lt;melo@simplicidade.org&gt; 2008-05-26
# Support for TM_SELECTED_FILES by Corey Jewett &lt;ml@syntheticplayground.com&gt; 2008-05-30
#
# 2008-08-11 (melo): Added flag &apos;:&apos; you must start your query with a : to
# search only in the &quot;selected files&quot;. I added this because using the
# selected files ends up not being something that I commonly do.
#
#
# **NOTE WELL**: TextMate does not inherit your PATH, so if you this
# command does not find it define the environment variable
# TM_ACK_COMMAND_PATH in your Preferences &gt; Advanced &gt; Shell Variables with
Expand Down Expand Up @@ -121,18 +126,28 @@ bail(&quot;Not in a saved file&quot;) unless directory
query = TextMate::UI.request_string(:title =&gt; &quot;Search in Project with ack&quot;, :prompt =&gt; &quot;Find this:&quot;, :default =&gt; %x{pbpaste -pboard find})
bail(&quot;Search aborted&quot;) unless query
if query[0,1] == &apos;:&apos;
query[0,1] = &apos;&apos;
use_selected_files = true
else
use_selected_files = false
end
IO.popen(&apos;pbcopy -pboard find&apos;, &apos;w&apos;) { |copy| copy.print query }
puts &lt;&lt;-HTML
&lt;h2&gt;Searching for #{ escape(query) }&lt;/h2&gt;
HTML
selected_files=TextMate.selected_files
if use_selected_files
selected_files=TextMate.selected_files
end
if selected_files
command = [ack_cmd, &quot;-H&quot;, &apos;--&apos;, query, selected_files]
puts &lt;&lt;-HTML
&lt;p&gt;&lt;small&gt;Search limited to #{ escape(selected_files.join(&apos; &apos;)) }&lt;/small&gt;&lt;/p&gt;
&lt;p&gt;&lt;small&gt;Search limited to #{ escape(selected_files.join(&apos; &apos;)) }&lt;/small&gt;&lt;/p&gt;
HTML
else
Dir.chdir(directory)
Expand Down
17 changes: 16 additions & 1 deletion search_with_ack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
# Updated to use with ack by Pedro Melo <melo@simplicidade.org> 2008-05-26
# Support for TM_SELECTED_FILES by Corey Jewett <ml@syntheticplayground.com> 2008-05-30
#
# 2008-08-11 (melo): Added flag ':' you must start your query with a : to
# search only in the "selected files". I added this because using the
# selected files ends up not being something that I commonly do.
#
#
# **NOTE WELL**: TextMate does not inherit your PATH, so if you this
# command does not find it define the environment variable
# TM_ACK_COMMAND_PATH in your Preferences > Advanced > Shell Variables with
Expand Down Expand Up @@ -112,13 +117,23 @@ def bail(message)

query = TextMate::UI.request_string(:title => "Search in Project with ack", :prompt => "Find this:", :default => %x{pbpaste -pboard find})
bail("Search aborted") unless query

if query[0,1] == ':'
query[0,1] = ''
use_selected_files = true
else
use_selected_files = false
end

IO.popen('pbcopy -pboard find', 'w') { |copy| copy.print query }

puts <<-HTML
<h2>Searching for #{ escape(query) }</h2>
HTML

selected_files=TextMate.selected_files
if use_selected_files
selected_files=TextMate.selected_files
end

if selected_files
command = [ack_cmd, "-H", '--', query, selected_files]
Expand Down

0 comments on commit a598b52

Please sign in to comment.