# Encoding: UTF-8

[{beforeRunningCommand: "nop",
  command: 
   "# Evaluate the current seletion in our Scheme interpreter\n#\n# The interpreter you use should be set in the environment\n# variable TM_SCHEME_EVALUATOR \n\nINTERPRET=${TM_SCHEME_INTERPRETER:=csi}\nCMD=$(basename \"$INTERPRET\")\n\n# Run depending on the system are we on?\nif [ $CMD == \"mzscheme\" ] ; then\n\n\t# Check mzscheme version for decimal;\n\t# command-line behavior changed between\n\t# v372 and v4.0\n\n\tVER=$(\"$INTERPRET\" -v | sed -E 's/^Welcome to MzScheme v([^ ]+).*$/\\1/')\n\n\t# version 4.0 or later\n\tif (echo $VER | grep -q '\\.') ; then\n\t\t\"$INTERPRET\" -e \"$TM_SELECTED_TEXT\"\n\t# version 372 or earlier\n\telse\n\t\t\"$INTERPRET\" -vm -e \"$TM_SELECTED_TEXT\"\n\tfi\nelif [ $CMD == \"csi\" ] ; then\n\t\"$INTERPRET\" -q < /dev/stdin\nfi",
  fallbackInput: "line",
  input: "selection",
  keyEquivalent: "^E",
  name: "Evaluate Selection",
  output: "showAsTooltip",
  scope: "source.scheme",
  uuid: "B270255C-1AE7-47FA-B3A7-38E983402C36"},
 {beforeRunningCommand: "nop",
  command: 
   "#!/usr/bin/env ruby\n\nrequire ENV[\"TM_SUPPORT_PATH\"] + \"/lib/tm/executor\"\nrequire ENV[\"TM_SUPPORT_PATH\"] + \"/lib/tm/save_current_document\"\nrequire ENV[\"TM_SUPPORT_PATH\"] + \"/lib/escape\"\n\nTextMate.save_current_document\nTextMate::Executor.make_project_master_current_document\n\ninterpreters = [\"mzscheme\", \"csi\", \"guile\"]\nargs = []\nargs << (ENV[\"TM_SCHEME\"] || interpreters.select{|ii| ENV[\"PATH\"].split(\":\").any?{|dd| File.executable? File.join(dd, ii)}}.first)\n\ncase args[0]\nwhen \"mzscheme\"\n  args << \"-e\" << '(require (lib \"errortrace.ss\" \"errortrace\"))' << \"-r\"\nelse\n  args << \"-s\"\nend\n\nTextMate::Executor.run(args, ENV[\"TM_FILEPATH\"]) do |line,type|\n  if line =~ /(.*):([0-9]+):([0-9]+):(.*)/ then\n    unless ENV[\"TM_FILE_IS_UNTITLED\"] == \"true\"\n       \"<a href=\\\"txmt://open?url=file://\#{htmlize($1)}&line=\#{$2}&column=\#{$3}\\\">\#{htmlize($1)}:\#{$2}:\#{$3}</a>:\#{htmlize($4)}\"\n    else\n      \"<a href=\\\"txmt://open?line=\#{$2}&column=\#{$3}\\\">\#{htmlize($1)}:\#{$2}:\#{$3}</a>:\#{htmlize($4)}\"\n    end\n  end\nend\n    \n\n\n# def printheader(schemesystem, interpreter)\n#   print <<-ENDHTML\n#     <html>\n#     <head>\n#     <title>Scheme TextMate Runtime</title>\n#     <style type='text/css'>\n#       body { background-color: #e0e0ff;}\n#       .header,\n#       .output,\n#       .errors {\n#           margin: 10px 0px 10px 0px;\n#           padding: 10px;\n#           border: 1px dotted black;\n#           background-color: #ffffff;\n#       }\n#       .header { background-color: #a0a0ff;}\n#       .output { background-color: #ffffff;}\n#       .outputline { font-family: Monaco;\n#                     font-size: 8pt; }\n#       .errors { background-color: #f0f0f0;}\n#       .errorline {  font-family: Monaco;\n#                     font-size: 8pt;\n#                     color: #0000f0 }\n#       .errorinfo {  font-family: Monaco;\n#                     font-size: 8pt; }\n#       .errorexp {   font-family: Monaco;\n#                     font-size: 8pt;\n#                     color: #f00000 }\n#       a { color: #f00000;\n#           text-decoration: none; }\n#     </style>\n#     <body>\n#     <div class='header'>\n#     Executed Scheme file in \#{schemesystem} (<i>\#{interpreter}</i>)\n#     </div>\n#   ENDHTML\n# end\n# \n# def printend\n#   print <<-ENDHTML\n#     </body>\n#     </html>\n#   ENDHTML\n# end\n# \n# def printoutput(ioport)\n#   puts \"<div class='output'>\"\n#   ioport.each do |line| \n#     puts \"<div class='outputline'>\"\n#     puts line\n#     puts \"</div>\"\n#   end\n#   puts \"</div>\"\n# end\n# \n# def makeerrorlink(line, system)\n#   case system\n#   when \"mzscheme\"\n#     a = line.split(':', 4)\n#     file = a[0]\n#     line = a[1]\n#     column = a[2]\n#     exp = a[3]\n#     \"<tr><td width='50'></td><td><div class='errorinfo'>\" +\n#     File.basename(file) + \" line \#{line}, column \#{column}</div></td>\" +\n#     '<td width=\"30\"></td><td><div class=\"errorexp\"><a href=\"txmt://open?url=file://' + \n#     File.expand_path(a[0]) + '&line=' + line + '&column=' + column + '\">' + \n#     escape(exp) + \"</a></div></td></tr>\"\n#   end\n# end\n# \n# def printerrors(errorfile, system)\n#   puts \"<div class='errors'>\"\n#   puts \"<table>\"\n#   errors = 0\n#   f = File.new(errorfile)  \n#   f.each do |line|\n#       errors = 1\n#       case system\n#       when \"mzscheme\"\n#         if line =~ /:[0-9]+:[0-9]+:/ then\n#           puts makeerrorlink(line, system)\n#         else\n#           puts \"<div class='errorline'>\"\n#           puts line\n#           puts \"</div>\"\n#         end\n#       when \"csi\"\n#         if line =~ /^Error/ then\n#           puts \"<div class='errorline'>\"\n#           puts line\n#           puts \"</div>\"        \n#         else\n#           puts \"<div class='errorinfo'>\"\n#           puts line\n#           puts \"</div>\"\n#         end\n#       else\n#         puts \"<div class='errorline'>\"\n#         puts line\n#         puts \"</div>\"        \n#       end\n#   end\n#   if errors == 0\n#       puts \"Program exited normally.\"\n#   end\n#   puts \"</table></div>\"\n# end\n\n\n\n# error_fd ||= IO.for_fd(ENV[\"TM_ERROR_FD\"].to_i)\n# case type\n# when :err    # \n#   if str =~ /^([^\\:]+):(\\d+):(\\d+): (.*?): (.*) \\((-?\\d+)\\)$/ then\n#     filepath, start,  stop, err, msg, status = $1, $2.to_i, $3.to_i, $4, $5, $6\n#   \n#     err = err.gsub(/\\b\\w(?=\\w{3,})/) { |m| m.upcase }\n#     \n#     error_fd << \"<div id=\\\"exception_report\\\" class=\\\"framed\\\">\\n\"\n#     error_fd << \"<p id=\\\"exception\\\"><strong>\#{htmlize err}</strong>: \#{htmlize msg}</p>\\n\"\n#   \n#     from = document[0..start].rindex(/^/)\n#     to = start + document[start..-1].index(/$/)\n#     src =  document[from...to]\n#   \n#     line = document[0...start].count(\"\\n\") + 1\n#     column = start - from\n#   \n#     link = \"txmt://open?line=\#{line}&column=\#{column}\"\n#     error_fd << \"<pre>\#{src}\\n\"\n#     error_fd << \"\#{' ' * (column)}↑</pre>\"\n#     error_fd <<  \"<blockquote><a href=\\\"\#{link}\\\">line \#{line}, column \#{column}</a> in \#{ENV['TM_DISPLAYNAME']}\\n\"\n#   \n#     error_fd << \"<p>Error \#{status}.</p>\\n\"\n#     error_fd << \"</div>\\n\"\n#     \n#     error_fd.flush\n#     \"\"\n#   else\n#     \"<span class=\\\"err\\\" style=\\\"color:red;\\\">\#{htmlize(str)}</span><br/>\"\n#   end\n# when :out\n#   htmlize(str)\n# end\n\n\n# Run the current document in our Scheme interpreter.\n#\n# The interpreter you use should be set in the environment\n# variable TM_SCHEME_INTERPRETER.\n#\n\n# # Save file, use tmp-file if there's no filepath.\n# [[ -z \"$TM_FILEPATH\" ]] && TM_TMPFILE=$(mktemp -t pythonmate)\n# : \"${TM_FILEPATH:=$TM_TMPFILE}\"; cat >\"$TM_FILEPATH\"\n# \n# # set up variables\n# INTERPRET=${TM_SCHEME_INTERPRETER:=csi}\n# CMD=$(basename \"$INTERPRET\")\n# SHOWOUTPUT=\"$TM_BUNDLE_SUPPORT/showoutput.rb\"\n# TM_ERRORTEMP=$(mktemp -t scheme)\n# \n# # Run depending on the system are we on?\n# if [ $CMD == \"mzscheme\" ] ; then\n#   \"$INTERPRET\" -e '(require (lib \"errortrace.ss\" \"errortrace\"))' -r \"$TM_FILEPATH\" 2>\"$TM_ERRORTEMP\" | \"$SHOWOUTPUT\" \"$INTERPRET\" \"$TM_ERRORTEMP\"\n# elif [ $CMD == \"csi\" ] ; then\n#   \"$INTERPRET\" -s \"$TM_FILEPATH\" 2>\"$TM_ERRORTEMP\" | \"$SHOWOUTPUT\" \"$INTERPRET\" \"$TM_ERRORTEMP\"\n# elif [ $CMD = \"guile\" ] ; then\n#   \"$INTERPRET\" -s \"$TM_FILEPATH\" 2>\"$TM_ERRORTEMP\" | \"$SHOWOUTPUT\" \"$INTERPRET\" \"$TM_ERRORTEMP\"\n# fi\n# \n# # Delete tempfiles\n# rm -f \"$TM_TMPFILE\"\n# rm -f \"$TM_ERRORTEMP\" ",
  input: "document",
  keyEquivalent: "@r",
  name: "Run Script",
  output: "showAsHTML",
  scope: "source.scheme",
  uuid: "CBFEB6F9-D38C-4726-BD16-325E3FCC0C6B"},
 {beforeRunningCommand: "nop",
  command: 
   "osascript -e \"tell application \\\"Terminal\\\"\n   do script \\\"clear; ${TM_SCHEME_INTERPRETER:=csi}\\\"\n   activate\nend tell\"\n",
  input: "none",
  keyEquivalent: "^I",
  name: "Start Interpreter",
  output: "discard",
  scope: "source.scheme",
  uuid: "887AF89E-004D-42AC-B29E-D90B0147F6DC"}]
