# Encoding: UTF-8

[{beforeRunningCommand: "nop",
  command: 
   "ruby -e '\nrequire ENV[\"TM_BUNDLE_SUPPORT\"] + \"/lib/historyList.rb\"\nprint HistoryList.new(STDIN.read + \"\\n> \").list.join(\"\\n\")\n' | pbcopy\n\necho \"Commands from selection/document placed into pasteboard\"",
  fallbackInput: "document",
  input: "selection",
  keyEquivalent: "^@r",
  name: "Copy Commands into Clipboard",
  output: "showAsTooltip",
  scope: "source.rapp-console",
  uuid: "48E1CB3A-8349-46E4-86B0-671663712005"},
 {beforeRunningCommand: "nop",
  command: 
   "echo\ntest=`tail -c+2`\nosascript <<-APPLESCRIPT | tail -n +2 | perl -pe 'BEGIN {$/=undef} s/\\n\\z//'\ntell application \"System Events\"\n    -- Get a reference to the text field\n    set text_area to (process \"R\")'s (window \"R Console\")'s (scroll area 1)'s text area 1\n    \n    -- Get text before and after our command\n    set oldtext to text_area's value\n    tell application \"R\" to cmd \"${test//\\\"/\\\"}\" \n    set newtext to text_area's value\n\n    -- Find the difference between old and new\n    text from (oldtext's length + 1) to -1 of newtext\nend tell\nAPPLESCRIPT",
  fallbackInput: "line",
  input: "selection",
  keyEquivalent: "\n",
  name: "Execute Line / Selection",
  output: "afterSelectedText",
  scope: "source.rapp-console",
  uuid: "7AF6ADAA-E6F0-4B9D-B146-A62BDE600D74"},
 {beforeRunningCommand: "nop",
  command: 
   ". \"$TM_SUPPORT_PATH/lib/webpreview.sh\"\nhtml_header \"R Console (R.app) Bundle Help\" \"R\"\n\"$TM_SUPPORT_PATH/lib/markdown_to_help.rb\" <<'MARKDOWN'\n\n# Introduction\n\nThe \"R Console (R.app)\" bundle provides some commands to remote the Mac OSX GUI R.app using AppleScript.\n       \n# Commands\n\n-   __Send Selection / Document to R.app__\n\n    Executes the current document or selection in R.app and switches to R.app's Console.\n\n-   __Show Line Output as Tool Tip__\n\n    Executes the current line or selection in R.app and shows only the result as tooltip.\n    \n-   __Execute Line / Selection__\n\n    Executes the current line or selection in R.app and inserts the result into the current document.\n    \n-   __Copy Commands into Clipboard__\n\n    Parses the current document or selection for lines beginning with \"> \" and pastes all found commands into the clipboard.\n    \n-   __Show History List__\n\n    Shows as inline menu all commands entered in the current document.\n\n-   __Next/Previous History Item__\n\n    Inserts the next/previous command found in the current document.\n\n   ***Notes***\n    <blockquote>\n    All commands specified within the \"R\" bundle can be used.\n    </blockquote>\n    <blockquote>\n    If the \"Rdaemon\" also runs in the background and the library \"CarbonEL\" (R 2.6.x) or RQuartz (R 2.7.x) is loaded the communication between TextMate and R.app wont't work caused by the issue that the event loop handler (R 2.6.x) resp. the RQuartz window handler (R 2.7.x) has the same name \"R\".\n    </blockquote>\n\n\n# Main Bundle Maintainer\n\n***Date: Mai 20 2008***\n\n<pre>\n-  Charilaos Skiadas&nbsp;<a href=\"mailto:cskiadas@gmail.com\">cskiadas@gmail.com</a>\n-  Hans-Jörg Bibiko&nbsp;&nbsp;<a href=\"mailto:bibiko@eva.mpg.de\">bibiko@eva.mpg.de</a>\n</pre>\n\nMARKDOWN\nhtml_footer",
  input: "none",
  keyEquivalent: "",
  name: "Help",
  output: "showAsHTML",
  scope: "source.rapp-console",
  uuid: "CAEB703B-1D79-4D3A-90BB-2A2C2BD846F7"},
 {beforeRunningCommand: "nop",
  command: 
   "#!/usr/bin/ruby\nrequire ENV['TM_BUNDLE_SUPPORT'] + \"/lib/historyList.rb\"\nrequire ENV['TM_SUPPORT_PATH'] + \"/lib/exit_codes.rb\"\nrequire ENV['TM_SUPPORT_PATH'] + \"/lib/escape.rb\"\ndoc = STDIN.read\nnew_doc = HistoryList.move_down(doc)\nTextMate.exit_discard if new_doc == doc\nprint e_sn(new_doc)",
  fallbackInput: "document",
  input: "selection",
  keyEquivalent: "",
  name: "Next History Item",
  output: "insertAsSnippet",
  scope: "source.rapp-console",
  uuid: "C1302FC5-FDC8-4560-8DFF-2CEC85EFCD19"},
 {beforeRunningCommand: "nop",
  command: 
   "#!/usr/bin/ruby\nrequire ENV['TM_BUNDLE_SUPPORT'] + \"/lib/historyList.rb\"\nrequire ENV['TM_SUPPORT_PATH'] + \"/lib/exit_codes.rb\"\nrequire ENV['TM_SUPPORT_PATH'] + \"/lib/escape.rb\"\ndoc = STDIN.read\nnew_doc = HistoryList.move_up(doc)\nTextMate.exit_discard if new_doc == doc\nprint e_sn(new_doc)",
  fallbackInput: "document",
  input: "selection",
  keyEquivalent: "",
  name: "Previous History Item",
  output: "insertAsSnippet",
  scope: "source.rapp-console",
  uuid: "2CE460A3-ADAE-47B6-8A89-EE142C714CC2"},
 {beforeRunningCommand: "nop",
  command: 
   "# input is selection or document\nrawText=\"`cat`\"\n\ncurDir=''\nif [[ ${#TM_DIRECTORY} -gt 0 ]]; then\n\tcurDir=\"$TM_DIRECTORY\"\nfi\n\nosascript -e 'on run(theCode)' \\\n\t\t  -e 'tell application \"R\" to activate' \\\n\t\t  -e 'if (item 2 of theCode) is not \"\" then tell application \"R\" to cmd \"setwd('\\''\" & (item 2 of theCode) & \"'\\'')\"' \\\n\t\t  -e 'tell application \"R\" to cmd (item 1 of theCode)' \\\n\t\t  -e 'end run' -- \"$rawText\" \"$curDir\"\n",
  input: "selection",
  keyEquivalent: "@R",
  name: "Send Document / Selection to R.app",
  output: "showAsTooltip",
  scope: "source.rapp-console",
  uuid: "B2E62E8B-6E70-11D9-A369-000D93B3A10E"},
 {beforeRunningCommand: "nop",
  command: 
   "#!/usr/bin/ruby\nrequire ENV['TM_BUNDLE_SUPPORT'] + \"/lib/historyList.rb\"\nrequire ENV['TM_SUPPORT_PATH'] + \"/lib/ui.rb\"\nrequire ENV['TM_SUPPORT_PATH'] + \"/lib/exit_codes.rb\"\nrequire ENV['TM_SUPPORT_PATH'] + \"/lib/escape.rb\"\ndoc = STDIN.read\nlist = HistoryList.new(doc)\nchoice = TextMate::UI.menu(list.list)\nTextMate.exit_discard if choice.nil?\nprint e_sn(list.add_line(list.list[choice]))",
  fallbackInput: "document",
  input: "selection",
  keyEquivalent: "^~",
  name: "Show History List",
  output: "insertAsSnippet",
  scope: "source.rapp-console",
  uuid: "613CDD87-1F8B-484E-B741-74B95F3C878B"},
 {beforeRunningCommand: "nop",
  command: 
   "echo\n#test=`tail -c+2`\ntest=$(cat)\nosascript <<-APPLESCRIPT | tail -n +2  | perl -pe 'BEGIN {$/=undef} s/> $//;s/\\n\\z//'\ntell application \"System Events\"\n    -- Get a reference to the text field\n    set text_area to (process \"R\")'s (window \"R Console\")'s (scroll area 1)'s text area 1\n    \n    -- Get text before and after our command\n    set oldtext to text_area's value\n    tell application \"R\" to cmd \"${test//\\\"/\\\"}\" \n    set newtext to text_area's value\n\n    -- Find the difference between old and new\n    text from (oldtext's length + 1) to -1 of newtext\nend tell\nAPPLESCRIPT",
  fallbackInput: "line",
  input: "selection",
  keyEquivalent: "^@r",
  name: "Show Line Output as Tool Tip",
  output: "showAsTooltip",
  scope: "source.rapp-console",
  uuid: "1A8EC6F7-D254-4888-9095-75C9DBA519F7"}]
