diff --git a/misc/Factor.tmbundle/Commands/Eval Selection:Line.tmCommand b/misc/Factor.tmbundle/Commands/Eval Selection:Line.tmCommand
new file mode 100644
index 0000000000..37867a2737
--- /dev/null
+++ b/misc/Factor.tmbundle/Commands/Eval Selection:Line.tmCommand
@@ -0,0 +1,27 @@
+
+
+
+
+ beforeRunningCommand
+ nop
+ command
+ #!/usr/bin/env ruby
+
+require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor"
+puts factor_eval(STDIN.read)
+ fallbackInput
+ line
+ input
+ selection
+ keyEquivalent
+ ^E
+ name
+ Eval Selection/Line
+ output
+ replaceSelectedText
+ scope
+ source.factor
+ uuid
+ 8E01DDAF-959B-4237-ADB9-C133A4ACCE90
+
+
diff --git a/misc/Factor.tmbundle/Commands/Help for Word.tmCommand b/misc/Factor.tmbundle/Commands/Help for Word.tmCommand
new file mode 100644
index 0000000000..a3d77d2f0c
--- /dev/null
+++ b/misc/Factor.tmbundle/Commands/Help for Word.tmCommand
@@ -0,0 +1,30 @@
+
+
+
+
+ beforeRunningCommand
+ nop
+ command
+ #!/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))
+ fallbackInput
+ word
+ input
+ document
+ keyEquivalent
+ ^H
+ name
+ Help for Word
+ output
+ showAsTooltip
+ scope
+ source.factor
+ uuid
+ BC5BE120-734B-40DF-8B6B-5D3243614B27
+
+
diff --git a/misc/Factor.tmbundle/Commands/Infer Effect of Selection.tmCommand b/misc/Factor.tmbundle/Commands/Infer Effect of Selection.tmCommand
new file mode 100644
index 0000000000..378294e6c1
--- /dev/null
+++ b/misc/Factor.tmbundle/Commands/Infer Effect of Selection.tmCommand
@@ -0,0 +1,27 @@
+
+
+
+
+ beforeRunningCommand
+ nop
+ command
+ #!/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.))
+ fallbackInput
+ word
+ input
+ document
+ name
+ Infer Effect of Selection
+ output
+ showAsTooltip
+ scope
+ source.factor
+ uuid
+ B619FCC0-2DF2-4657-82A8-0E5676A10254
+
+
diff --git a/misc/Factor.tmbundle/Commands/Run File in Listener.tmCommand b/misc/Factor.tmbundle/Commands/Run File in Listener.tmCommand
new file mode 100644
index 0000000000..bc8c84ec13
--- /dev/null
+++ b/misc/Factor.tmbundle/Commands/Run File in Listener.tmCommand
@@ -0,0 +1,25 @@
+
+
+
+
+ beforeRunningCommand
+ nop
+ command
+ #!/usr/bin/env ruby
+
+require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor"
+factor_run(%Q("#{ENV["TM_FILEPATH"]}" run-file))
+ input
+ none
+ keyEquivalent
+ @r
+ name
+ Run File in Listener
+ output
+ discard
+ scope
+ source.factor
+ uuid
+ CAD3BB10-C480-4C0E-9518-94D61F7A0C0B
+
+
diff --git a/misc/Factor.tmbundle/Commands/Run Selection:Line in Listener.tmCommand b/misc/Factor.tmbundle/Commands/Run Selection:Line in Listener.tmCommand
new file mode 100644
index 0000000000..5028bd8db3
--- /dev/null
+++ b/misc/Factor.tmbundle/Commands/Run Selection:Line in Listener.tmCommand
@@ -0,0 +1,27 @@
+
+
+
+
+ beforeRunningCommand
+ nop
+ command
+ #!/usr/bin/env ruby
+
+require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor"
+factor_run(STDIN.read)
+ fallbackInput
+ line
+ input
+ selection
+ keyEquivalent
+ ^~e
+ name
+ Run Selection/Line in Listener
+ output
+ discard
+ scope
+ source.factor
+ uuid
+ 15A984BD-BC65-43E8-878A-267788C8DA70
+
+
diff --git a/misc/Factor.tmbundle/Commands/See Word.tmCommand b/misc/Factor.tmbundle/Commands/See Word.tmCommand
new file mode 100644
index 0000000000..b9dd2e5e90
--- /dev/null
+++ b/misc/Factor.tmbundle/Commands/See Word.tmCommand
@@ -0,0 +1,30 @@
+
+
+
+
+ beforeRunningCommand
+ nop
+ command
+ #!/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))
+ fallbackInput
+ word
+ input
+ document
+ keyEquivalent
+ ^h
+ name
+ See Word
+ output
+ showAsTooltip
+ scope
+ source.factor
+ uuid
+ 35484754-DBF9-4381-BB25-00CAB64DF4A1
+
+
diff --git a/misc/Factor.tmbundle/Support/lib/tm_factor.rb b/misc/Factor.tmbundle/Support/lib/tm_factor.rb
new file mode 100644
index 0000000000..54272e5e36
--- /dev/null
+++ b/misc/Factor.tmbundle/Support/lib/tm_factor.rb
@@ -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
diff --git a/misc/Factor.tmbundle/Syntaxes/Factor.tmLanguage b/misc/Factor.tmbundle/Syntaxes/Factor.tmLanguage
index ec4961f312..304af129ce 100644
--- a/misc/Factor.tmbundle/Syntaxes/Factor.tmLanguage
+++ b/misc/Factor.tmbundle/Syntaxes/Factor.tmLanguage
@@ -1,5 +1,5 @@
-
+
fileTypes
@@ -254,9 +254,9 @@
begin
- \(\s
+ \((?=\s)
end
- \s\)
+ (^|(?<=\s))\)
name
comment.parens.factor
diff --git a/misc/Factor.tmbundle/Syntaxes/HTML (Factor).tmLanguage b/misc/Factor.tmbundle/Syntaxes/HTML (Factor).tmLanguage
index 89c0f191b9..03394b933c 100644
--- a/misc/Factor.tmbundle/Syntaxes/HTML (Factor).tmLanguage
+++ b/misc/Factor.tmbundle/Syntaxes/HTML (Factor).tmLanguage
@@ -1,5 +1,5 @@
-
+
fileTypes
diff --git a/misc/Factor.tmbundle/info.plist b/misc/Factor.tmbundle/info.plist
index 8def3807d7..1ea756a1a5 100644
--- a/misc/Factor.tmbundle/info.plist
+++ b/misc/Factor.tmbundle/info.plist
@@ -1,9 +1,20 @@
-
+
name
Factor
+ ordering
+
+ 3C9C9C2A-314A-475B-A4E4-A68BAAF3F36E
+ 141517D7-73E0-4475-A481-71102575A175
+ CAD3BB10-C480-4C0E-9518-94D61F7A0C0B
+ 15A984BD-BC65-43E8-878A-267788C8DA70
+ 8E01DDAF-959B-4237-ADB9-C133A4ACCE90
+ 35484754-DBF9-4381-BB25-00CAB64DF4A1
+ BC5BE120-734B-40DF-8B6B-5D3243614B27
+ B619FCC0-2DF2-4657-82A8-0E5676A10254
+
uuid
8061D2F3-B603-411D-AFFE-61784A07906D