TextMate bundle commands: Eval, Help, Infer, Run, See

db4
Joe Groff 2008-01-12 23:00:52 -08:00
parent e0caf654e6
commit 606b0be95b
10 changed files with 220 additions and 5 deletions

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env ruby
require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor"
puts factor_eval(STDIN.read)</string>
<key>fallbackInput</key>
<string>line</string>
<key>input</key>
<string>selection</string>
<key>keyEquivalent</key>
<string>^E</string>
<key>name</key>
<string>Eval Selection/Line</string>
<key>output</key>
<string>replaceSelectedText</string>
<key>scope</key>
<string>source.factor</string>
<key>uuid</key>
<string>8E01DDAF-959B-4237-ADB9-C133A4ACCE90</string>
</dict>
</plist>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env ruby
require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor"
doc = STDIN.read
word = line_current_word(ENV["TM_CURRENT_LINE"], ENV["TM_LINE_INDEX"].to_i)
factor_run(%Q(#{doc_using_statements(doc)} \\ #{word} help))</string>
<key>fallbackInput</key>
<string>word</string>
<key>input</key>
<string>document</string>
<key>keyEquivalent</key>
<string>^H</string>
<key>name</key>
<string>Help for Word</string>
<key>output</key>
<string>showAsTooltip</string>
<key>scope</key>
<string>source.factor</string>
<key>uuid</key>
<string>BC5BE120-734B-40DF-8B6B-5D3243614B27</string>
</dict>
</plist>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env ruby
require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor"
doc = STDIN.read
puts factor_eval(%Q(#{doc_using_statements(doc)} USE: inference\n [ #{ENV["TM_SELECTED_TEXT"]} ] infer.))</string>
<key>fallbackInput</key>
<string>word</string>
<key>input</key>
<string>document</string>
<key>name</key>
<string>Infer Effect of Selection</string>
<key>output</key>
<string>showAsTooltip</string>
<key>scope</key>
<string>source.factor</string>
<key>uuid</key>
<string>B619FCC0-2DF2-4657-82A8-0E5676A10254</string>
</dict>
</plist>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env ruby
require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor"
factor_run(%Q("#{ENV["TM_FILEPATH"]}" run-file))</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
<string>@r</string>
<key>name</key>
<string>Run File in Listener</string>
<key>output</key>
<string>discard</string>
<key>scope</key>
<string>source.factor</string>
<key>uuid</key>
<string>CAD3BB10-C480-4C0E-9518-94D61F7A0C0B</string>
</dict>
</plist>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env ruby
require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor"
factor_run(STDIN.read)</string>
<key>fallbackInput</key>
<string>line</string>
<key>input</key>
<string>selection</string>
<key>keyEquivalent</key>
<string>^~e</string>
<key>name</key>
<string>Run Selection/Line in Listener</string>
<key>output</key>
<string>discard</string>
<key>scope</key>
<string>source.factor</string>
<key>uuid</key>
<string>15A984BD-BC65-43E8-878A-267788C8DA70</string>
</dict>
</plist>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env ruby
require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor"
doc = STDIN.read
word = line_current_word(ENV["TM_CURRENT_LINE"], ENV["TM_LINE_INDEX"].to_i)
puts factor_eval(%Q(#{doc_using_statements(doc)} \\ #{word} see))</string>
<key>fallbackInput</key>
<string>word</string>
<key>input</key>
<string>document</string>
<key>keyEquivalent</key>
<string>^h</string>
<key>name</key>
<string>See Word</string>
<key>output</key>
<string>showAsTooltip</string>
<key>scope</key>
<string>source.factor</string>
<key>uuid</key>
<string>35484754-DBF9-4381-BB25-00CAB64DF4A1</string>
</dict>
</plist>

View File

@ -0,0 +1,38 @@
require 'osx/cocoa'
def _wait_for_return_value(pb)
origCount = pb.changeCount
sleep 0.125 while pb.changeCount == origCount
end
def perform_service(service, in_string, wait_for_return_value=false)
p = OSX::NSPasteboard.pasteboardWithUniqueName
p.declareTypes_owner([OSX::NSStringPboardType], nil)
p.setString_forType(in_string, OSX::NSStringPboardType)
raise "Unable to call service #{service}" unless OSX::NSPerformService(service, p)
_wait_for_return_value(p) if wait_for_return_value
p.stringForType(OSX::NSStringPboardType)
end
def textmate_front()
system %Q{osascript -e 'tell app "TextMate" to activate'};
end
def factor_run(code)
perform_service("Factor/Evaluate in Listener", code)
end
def factor_eval(code)
r = perform_service("Factor/Evaluate Selection", code, true)
textmate_front
r
end
def doc_using_statements(document)
document.scan(/\b(USING:\s[^;]*\s;|USE:\s+\S+|IN:\s\S+)/).join("\n") << "\n"
end
def line_current_word(line, point)
left = line.rindex(/\s|^/, point - 1) + 1; right = line.index(/\s|$/, point) - 1
line[left..right]
end

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>fileTypes</key> <key>fileTypes</key>
@ -254,9 +254,9 @@
</dict> </dict>
<dict> <dict>
<key>begin</key> <key>begin</key>
<string>\(\s</string> <string>\((?=\s)</string>
<key>end</key> <key>end</key>
<string>\s\)</string> <string>(^|(?&lt;=\s))\)</string>
<key>name</key> <key>name</key>
<string>comment.parens.factor</string> <string>comment.parens.factor</string>
</dict> </dict>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>fileTypes</key> <key>fileTypes</key>

View File

@ -1,9 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>name</key> <key>name</key>
<string>Factor</string> <string>Factor</string>
<key>ordering</key>
<array>
<string>3C9C9C2A-314A-475B-A4E4-A68BAAF3F36E</string>
<string>141517D7-73E0-4475-A481-71102575A175</string>
<string>CAD3BB10-C480-4C0E-9518-94D61F7A0C0B</string>
<string>15A984BD-BC65-43E8-878A-267788C8DA70</string>
<string>8E01DDAF-959B-4237-ADB9-C133A4ACCE90</string>
<string>35484754-DBF9-4381-BB25-00CAB64DF4A1</string>
<string>BC5BE120-734B-40DF-8B6B-5D3243614B27</string>
<string>B619FCC0-2DF2-4657-82A8-0E5676A10254</string>
</array>
<key>uuid</key> <key>uuid</key>
<string>8061D2F3-B603-411D-AFFE-61784A07906D</string> <string>8061D2F3-B603-411D-AFFE-61784A07906D</string>
</dict> </dict>