[TxMt] Re: Ask the TextMate List – a suggestion

Hans-Jörg Bibiko bibiko at eva.mpg.de
Wed Aug 20 17:08:26 UTC 2008


On 20.08.2008, at 17:47, Piero D'Ancona wrote:

> Hans-Jörg Bibiko <bibiko at ...> writes:
>
>> (Ask the TextMate List.tmCommand): application/octet-stream, 2398  
>> bytes
>>
>
> Hans, as usual you have crazy and weirdly useful ideas.
> But... where's the script? I get a Not Found when
> I click on it

??

I've just opened my mail on an other Mac. I clicked at the  
attachment, TextMate opened, and installed the tmCommand. Normally it  
will be installed into your personal Bundle folder. Within that  
tmCommand you will find the Ruby script.
The Ruby script runs with the latest ui.rb and progress.rb

If that doesn't work, here the script:

Input: nothing
Output: Show as Tool Tip
Scope: no scope
Key binding: whatever

Command:
#!/usr/bin/env ruby -wKU

SUPPORT = ENV['TM_SUPPORT_PATH']
require SUPPORT + '/lib/ui.rb'
require SUPPORT + '/lib/progress.rb'
require 'net/http'
require 'uri'

url = "http://www.nabble.com/forum/Search.jtp?local=y&forum=18157&"
page = 0
isHeaderSet = false

query = TextMate::UI.request_string(:title => 'Ask the TextMate  
List', :prompt => 'Search for:')
exit 200 if query.nil?
query.gsub!('"','%22')
query.gsub!(/ +/, '+')

answer = ""
answer += "<base href='http://www.nabble.com'>"
TextMate.call_with_progress(:title => 'Ask the TextMate  
List', :summary => 'Searching…', :indeterminate => true) do |dlg|
   begin
     while true
       result = Net::HTTP.get( URI.parse("#{url}page=#{page}&query=# 
{query}") )
       if ! isHeaderSet
         m = result.match(/(?m)(Found \d+ matching posts for .*?  
thread.?\.)/)
         answer += "<div style='padding:1mm;background- 
color:lightgray;font-size:0.8em'>#{m[1]}</div>"
         isHeaderSet = true
         dlg.parameters = {'summary' => 'Preparing HTML page…',  
'details' => m[1].gsub(/<[^>]*?>/, '') }
       end
       result.gsub!(/(?m)<div class="nabble" id="nabble".*?<table  
cellspacing=2 cellpadding=2 border=0 width="100%">/, '')
       result.gsub!(/(?m)style="font-size:0.9em;"/,  
'style="display:none;"')
       result.gsub!(/(?m)<p>[^<]*?<div class="search-wrapper shaded- 
bg-color">.*?<\/html>/, '')
       answer += result
       page += 1
       break if ! result.include?("Next 10 ")
     end
   rescue
     print "Error"
     exit 200
   end
end
f = File.open("/tmp/TM_askList.html", "w")
f.puts "#{answer}</table></body></html>"
f.close
`open "/tmp/TM_askList.html"`
`sleep 2;rm -f "/tmp/TM_askList.html" &`


--Hans




More information about the textmate mailing list