Skip to content
Browse files

Run command no longer overwrites document

Previously the run command would take care of saving the document rather than rely on TextMate to do this. The reason for this was to allow executing untitled documents as scripts (without asking the user to first save the script).

With TextMate 2 we no longer ask for a file name when using the “Save: Modified Documents” option, so the run command now only takes care of saving, if the document is untitled (in which case, it writes it to a temporary file and executes that).
  • Loading branch information...
1 parent 7dc7d6c commit e7f78683144a53e7bb3e14f0f4a90437624664f4 @sorbits sorbits committed Jan 5, 2013
Showing with 18 additions and 6 deletions.
  1. +1 −1 Commands/Run.tmCommand
  2. +17 −5 Support/RubyMate/run_script.rb
View
2 Commands/Run.tmCommand
@@ -5,7 +5,7 @@
<key>autoScrollOutput</key>
<true/>
<key>beforeRunningCommand</key>
- <string>nop</string>
+ <string>saveModifiedFiles</string>
<key>command</key>
<string>#!/bin/sh
View
22 Support/RubyMate/run_script.rb
@@ -1,9 +1,21 @@
-require ENV["TM_SUPPORT_PATH"] + "/lib/tm/executor"
-require ENV["TM_SUPPORT_PATH"] + "/lib/tm/save_current_document"
+require "#{ENV["TM_SUPPORT_PATH"]}/lib/tm/executor"
+require "#{ENV["TM_SUPPORT_PATH"]}/lib/tm/tempfile"
+require "pathname"
-require 'pathname'
+def save_untitled_document
+ ENV['TM_FILEPATH'] = TextMate::IO.tempfile('rb').path
+ ENV['TM_FILENAME'] = File.basename(ENV['TM_FILEPATH'])
+ ENV['TM_FILE_IS_UNTITLED'] = 'true'
-TextMate.save_current_document
+ begin
+ Dir.chdir(File.dirname(ENV["TM_FILEPATH"]))
+ open(ENV['TM_FILEPATH'], 'w') { |io| io << STDIN.read }
+ rescue e
+ abort "Failed to save document as ‘#{ENV['TM_FILEPATH']}’: #{e}"
+ end
+end
+
+save_untitled_document if ENV['TM_FILEPATH'].nil?
# For Run focused unit test, find the name of the test the user wishes to run.
args = [ ]
@@ -41,7 +53,7 @@
cmd = [ENV['TM_RUBY'] || 'ruby', '-KU', '-rcatch_exception']
if is_test_script and not ENV['TM_FILE_IS_UNTITLED']
- path_ary = (ENV['TM_ORIG_FILEPATH'] || ENV['TM_FILEPATH']).split("/")
+ path_ary = ENV['TM_FILEPATH'].split("/")
if index = path_ary.rindex("test")
test_path = "#{File.join(*path_ary[0..index])}:#{File.join(*path_ary[0..-2])}"
lib_path = File.join( *( path_ary[0..-2] +

0 comments on commit e7f7868

Please sign in to comment.
Something went wrong with that request. Please try again.