Skip to content

Commit

Permalink
Run command no longer overwrites document
Browse files Browse the repository at this point in the history
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
sorbits committed Jan 5, 2013
1 parent 7dc7d6c commit e7f7868
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Commands/Run.tmCommand
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>autoScrollOutput</key>
<true/>
<key>beforeRunningCommand</key>
<string>nop</string>
<string>saveModifiedFiles</string>
<key>command</key>
<string>#!/bin/sh
Expand Down
22 changes: 17 additions & 5 deletions Support/RubyMate/run_script.rb
Original file line number Diff line number Diff line change
@@ -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 = [ ]
Expand Down Expand Up @@ -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] +
Expand Down

0 comments on commit e7f7868

Please sign in to comment.