Merge branch 'master' of git://factorcode.org/git/factor
[factor/jcg.git] / misc / Factor.tmbundle / Support / lib / tm_factor.rb
blob2775a12ae9f621af1272a8a5bad41c186c4b1bbb
1 require 'osx/cocoa'
3 def _wait_for_return_value(pb)
4     origCount = pb.changeCount
5     sleep 0.125 while pb.changeCount == origCount
6 end
8 def perform_service(service, in_string, wait_for_return_value=false)
9     p = OSX::NSPasteboard.pasteboardWithUniqueName
10     p.declareTypes_owner([OSX::NSStringPboardType], nil)
11     p.setString_forType(in_string, OSX::NSStringPboardType)
12     raise "Unable to call service #{service}" unless OSX::NSPerformService(service, p)
13     _wait_for_return_value(p) if wait_for_return_value
14     p.stringForType(OSX::NSStringPboardType)
15 end
17 def textmate_front()
18     system %Q{osascript -e 'tell app "TextMate" to activate'};
19 end
21 def factor_run(code)
22     perform_service("Factor/Evaluate in Listener", code)
23 end
25 def factor_eval(code)
26     r = perform_service("Factor/Evaluate Selection", code, true)
27     textmate_front
28     r
29 end
31 def doc_using_statements(document)
32     document.scan(/\b(USING:\s[^;]*\s;|USE:\s+\S+|IN:\s\S+)/).join("\n") << "\n"
33 end
35 def line_current_word(line, point)
36     left = line.rindex(/\s/, point - 1) || 0; right = line.index(/\s/, point) || line.length
37     line[left..right]
38 end