public
Description: "Ack in Project" TextMate bundle
Clone URL: git://github.com/protocool/ack-tmbundle.git
Several enhancements
* ability to define a .ackrc in your TM_PROJECT_DIRECTORY
* ability to switch on/off reading of .ackrc
* search history
* clean up dialog ui - stick advanced/rarely-used stuff in a drawer
protocool (author)
Fri May 23 02:51:06 -0700 2008
commit  e8b1f7255dc9301839674bde8bf347f524763ba1
tree    ba5e055114af829912f4e576e567f525abcc7be9
parent  4ca55c1b72b1b6a356c26faa27991fb7ff0bc182
...
 
 
1
2
3
...
76
77
78
79
 
80
81
82
83
84
 
85
86
87
...
93
94
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
97
98
...
1
2
3
4
5
...
78
79
80
 
81
82
83
84
85
86
87
88
89
90
...
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
0
@@ -1,3 +1,5 @@
0
+require 'base64'
0
+
0
 class Module
0
   # lifted from Rails
0
   def delegate(*methods)
0
@@ -76,12 +78,13 @@ module AckInProject
0
       end
0
     end
0
     
0
- delegate :bundle_support, :ack, :support_file, :lib_file, :nib_file,
0
+ delegate :bundle_support, :ack, :support_file, :lib_file, :nib_file, :project_directory,
0
       :search_directory, :file_in_search_directory, :searched_in, :to => '::AckInProject::Environment'
0
   end
0
 
0
   class << self
0
     include Environment
0
+ AckInProject::Environment.ghetto_include %w(escape), binding
0
     
0
     def show_search_dialog(&block)
0
       require lib_file('search_dialog')
0
@@ -93,6 +96,30 @@ module AckInProject
0
       require lib_file('search')
0
       AckInProject::SearchResults.new(plist).show
0
     end
0
+
0
+ # sigh... defaults is giving me grief when searches contain quotes
0
+ def search_history
0
+ unless @search_history
0
+ history_command = "defaults read com.macromates.textmate ackHistory 2>/dev/null"
0
+ @search_history = OSX::PropertyList::load(Base64.decode64(%x{#{history_command}}))
0
+ end
0
+ @search_history
0
+ rescue
0
+ @search_history = [] # oh the humanity!
0
+ end
0
+
0
+ def update_search_history(search)
0
+ search_history.unshift(search)
0
+ search_history.uniq!
0
+ search_history.compact!
0
+ search_history.replace search_history[0..9]
0
+
0
+ history = Base64.encode64(search_history.to_plist)
0
+
0
+ history_command = %Q|defaults write com.macromates.textmate ackHistory -string #{e_sh history} 2>/dev/null|
0
+ %x{#{history_command}}
0
+ rescue
0
+ end
0
   end
0
 end
0
 
...
76
77
78
79
 
80
81
82
...
86
87
88
89
 
 
 
 
90
91
92
93
94
 
 
 
 
95
96
97
...
76
77
78
 
79
80
81
82
...
86
87
88
 
89
90
91
92
93
94
95
96
 
97
98
99
100
101
102
103
0
@@ -76,7 +76,7 @@ class AckInProject::Search
0
       gsub(/\e\[\d+m/,'</strong>')
0
   end
0
 
0
- def search_command
0
+ def prepare_search
0
     # TODO: bail if the search term is empty
0
     result = plist['result']
0
     
0
@@ -86,12 +86,18 @@ class AckInProject::Search
0
     options << '-Q' if result['literalMatch'] == 1
0
     options << '-C' if result['showContext'] == 1
0
     options << "--#{result['followSymLinks'] == 1 ? '' : 'no'}follow"
0
-
0
+ options << "--#{result['loadAckRC'] == 1 ? '' : 'no'}env"
0
+
0
+ AckInProject.update_search_history result['returnArgument']
0
+
0
     %{cd #{e_sh search_directory}; #{e_sh ack} #{options.join(' ')} #{e_sh result['returnArgument']}}
0
   end
0
   
0
   def search
0
- IO.popen(search_command) do |pipe|
0
+ # tell ack about potential .ackrc files in the project directory
0
+ ENV['ACKRC'] = File.join(project_directory, '.ackrc')
0
+
0
+ IO.popen(prepare_search) do |pipe|
0
       pipe.each do |line|
0
         case line
0
         when /^\s*$/
...
1
2
3
4
 
 
 
5
6
 
 
7
8
9
...
12
13
14
15
 
 
 
 
16
17
18
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
21
22
...
1
2
 
 
3
4
5
6
7
8
9
10
11
12
...
15
16
17
 
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
0
@@ -1,9 +1,12 @@
0
 class AckInProject::SearchDialog
0
   include AckInProject::Environment
0
-
0
- def show(params = {}, &block)
0
+ AckInProject::Environment.ghetto_include %w(web_preview), binding
0
+
0
+ def show(&block)
0
     raise ArgumentError, 'show_search_dialog requires a block' if block.nil?
0
 
0
+ verify_project_directory or return
0
+
0
     command = %Q{#{TM_DIALOG} -cm -p #{e_sh params.to_plist} -d #{e_sh defaults.to_plist} #{e_sh nib_file('AckInProjectSearch.nib')}}
0
     plist = OSX::PropertyList::load(%x{#{command}})
0
     if plist['result']
0
@@ -12,11 +15,33 @@ class AckInProject::SearchDialog
0
   end
0
   
0
   def defaults
0
- %w(ackMatchWholeWords ackIgnoreCase ackLiteralMatch ackShowContext ackFollowSymlinks).inject({}) do |hsh,v|
0
+ %w(
0
+ ackMatchWholeWords ackIgnoreCase ackLiteralMatch
0
+ ackShowContext ackFollowSymlinks ackLoadAckRC
0
+ ).inject({}) do |hsh,v|
0
       hsh[v] = false
0
       hsh
0
     end
0
   end
0
+
0
+ def params
0
+ history = AckInProject::search_history
0
+ {
0
+ #'contentHeight' => 168,
0
+ 'ackExpression' => history.first.to_s,
0
+ 'ackHistory' => history
0
+ }
0
+ end
0
+
0
+ def verify_project_directory
0
+ return true if project_directory
0
+
0
+ puts <<-HTML
0
+ <html><body>
0
+ <h1>Can't determine project directory (TM_PROJECT_DIR)</h1>
0
+ </body></html>
0
+ HTML
0
+ end
0
 end
0
 
0
 
...
3
4
5
6
 
 
 
 
 
 
7
8
9
...
3
4
5
 
6
7
8
9
10
11
12
13
14
0
@@ -3,7 +3,12 @@
0
 <plist version="1.0">
0
 <dict>
0
   <key>IBDocumentLocation</key>
0
- <string>612 105 356 240 0 0 1680 1028 </string>
0
+ <string>425 98 703 386 0 0 1680 1028 </string>
0
+ <key>IBEditorPositions</key>
0
+ <dict>
0
+ <key>185</key>
0
+ <string>761 638 214 136 0 0 1680 1028 </string>
0
+ </dict>
0
   <key>IBFramework Version</key>
0
   <string>443.0</string>
0
   <key>IBOpenObjects</key>

Comments

    No one has commented yet.