Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add bundle from Hans-Jörg Bibiko.

git-svn-id: http://svn.textmate.org/trunk/Review/Bundles/R Console (R_app).tmbundle@9103 dfb7d73b-c2ec-0310-8fea-fb051d288c6d
  • Loading branch information...
commit 16fda51026b90c61e1a4ae47eb097e5aa6a0cbc9 0 parents
@infininight infininight authored
29 Commands/Copy Commands into Clipboard.tmCommand
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>ruby -e '
+require ENV["TM_BUNDLE_SUPPORT"] + "/lib/historyList.rb"
+print HistoryList.new(STDIN.read + "\n&gt; ").list.join("\n")
+' | pbcopy
+
+echo "Commands from selection/document placed into pasteboard"</string>
+ <key>fallbackInput</key>
+ <string>document</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>@C</string>
+ <key>name</key>
+ <string>Copy Commands into Clipboard</string>
+ <key>output</key>
+ <string>showAsTooltip</string>
+ <key>scope</key>
+ <string>source.rapp-console</string>
+ <key>uuid</key>
+ <string>48E1CB3A-8349-46E4-86B0-671663712005</string>
+</dict>
+</plist>
39 Commands/Execute Line : Selection.tmCommand
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>echo
+test=`tail -c+2`
+osascript &lt;&lt;-APPLESCRIPT | tail -n +2 | perl -pe 'BEGIN {$/=undef} s/\n\z//'
+tell application "System Events"
+ -- Get a reference to the text field
+ set text_area to (process "R")'s (window "R Console")'s (scroll area 1)'s text area 1
+
+ -- Get text before and after our command
+ set oldtext to text_area's value
+ tell application "R" to cmd "${test//\"/\"}"
+ set newtext to text_area's value
+
+ -- Find the difference between old and new
+ text from (oldtext's length + 1) to -1 of newtext
+end tell
+APPLESCRIPT</string>
+ <key>fallbackInput</key>
+ <string>line</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>
+</string>
+ <key>name</key>
+ <string>Execute Line / Selection</string>
+ <key>output</key>
+ <string>afterSelectedText</string>
+ <key>scope</key>
+ <string>source.rapp-console</string>
+ <key>uuid</key>
+ <string>7AF6ADAA-E6F0-4B9D-B146-A62BDE600D74</string>
+</dict>
75 Commands/Help.tmCommand
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>. "$TM_SUPPORT_PATH/lib/webpreview.sh"
+html_header "R Console (R.app) Bundle Help" "R"
+"$TM_SUPPORT_PATH/lib/markdown_to_help.rb" &lt;&lt;'MARKDOWN'
+
+# Introduction
+
+The "R Console (R.app)" bundle provides some commands to remote the Mac OSX GUI R.app using AppleScript.
+
+# Commands
+
+- __Send Selection / Document to R.app__
+
+ Executes the current document or selection in R.app and switches to R.app's Console.
+
+- __Show Line Output as Tool Tip__
+
+ Executes the current line or selection in R.app and shows only the result as tooltip.
+
+- __Execute Line / Selection__
+
+ Executes the current line or selection in R.app and inserts the result into the current document.
+
+- __Copy Commands into Clipboard__
+
+ Parses the current document or selection for lines beginning with "&gt; " and pastes all found commands into the clipboard.
+
+- __Show History List__
+
+ Shows as inline menu all commands entered in the current document.
+
+- __Next/Previous History Item__
+
+ Inserts the next/previous command found in the current document.
+
+ ***Notes***
+ &lt;blockquote&gt;
+ All commands specified within the "R" bundle can be used.
+ &lt;/blockquote&gt;
+ &lt;blockquote&gt;
+ If the "Rdaemon" also runs in the background and the library "CarbonEL" is loaded the communication between TextMate and R.app wont't work.
+ &lt;/blockquote&gt;
+
+
+# Main Bundle Maintainer
+
+***Date: Jan 09 2008***
+
+&lt;pre&gt;
+- Charilaos Skiadas&amp;nbsp;&lt;a href="mailto:cskiadas@gmail.com"&gt;cskiadas@gmail.com&lt;/a&gt;
+- Hans-Jörg Bibiko&amp;nbsp;&amp;nbsp;&lt;a href="mailto:bibiko@eva.mpg.de"&gt;bibiko@eva.mpg.de&lt;/a&gt;
+&lt;/pre&gt;
+
+MARKDOWN
+html_footer</string>
+ <key>input</key>
+ <string>none</string>
+ <key>keyEquivalent</key>
+ <string></string>
+ <key>name</key>
+ <string>Help</string>
+ <key>output</key>
+ <string>showAsHTML</string>
+ <key>scope</key>
+ <string>source.rapp-console</string>
+ <key>uuid</key>
+ <string>CAEB703B-1D79-4D3A-90BB-2A2C2BD846F7</string>
+</dict>
+</plist>
31 Commands/Next History Item.tmCommand
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/ruby
+require ENV['TM_BUNDLE_SUPPORT'] + "/lib/historyList.rb"
+require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"
+require ENV['TM_SUPPORT_PATH'] + "/lib/escape.rb"
+doc = STDIN.read
+new_doc = HistoryList.move_down(doc)
+TextMate.exit_discard if new_doc == doc
+print e_sn(new_doc)</string>
+ <key>fallbackInput</key>
+ <string>document</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string></string>
+ <key>name</key>
+ <string>Next History Item</string>
+ <key>output</key>
+ <string>insertAsSnippet</string>
+ <key>scope</key>
+ <string>source.rapp-console</string>
+ <key>uuid</key>
+ <string>C1302FC5-FDC8-4560-8DFF-2CEC85EFCD19</string>
+</dict>
+</plist>
31 Commands/Previous History Item.tmCommand
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/ruby
+require ENV['TM_BUNDLE_SUPPORT'] + "/lib/historyList.rb"
+require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"
+require ENV['TM_SUPPORT_PATH'] + "/lib/escape.rb"
+doc = STDIN.read
+new_doc = HistoryList.move_up(doc)
+TextMate.exit_discard if new_doc == doc
+print e_sn(new_doc)</string>
+ <key>fallbackInput</key>
+ <string>document</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string></string>
+ <key>name</key>
+ <string>Previous History Item</string>
+ <key>output</key>
+ <string>insertAsSnippet</string>
+ <key>scope</key>
+ <string>source.rapp-console</string>
+ <key>uuid</key>
+ <string>2CE460A3-ADAE-47B6-8A89-EE142C714CC2</string>
+</dict>
+</plist>
35 Commands/Send Selection : Document to R_app.tmCommand
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string># input is selection or document
+rawText="`cat`"
+
+curDir=''
+if [[ ${#TM_DIRECTORY} -gt 0 ]]; then
+ curDir="$TM_DIRECTORY"
+fi
+
+osascript -e 'on run(theCode)' \
+ -e 'tell application "R" to activate' \
+ -e 'if (item 2 of theCode) is not "" then tell application "R" to cmd "setwd('\''" &amp; (item 2 of theCode) &amp; "'\'')"' \
+ -e 'tell application "R" to cmd (item 1 of theCode)' \
+ -e 'end run' -- "$rawText" "$curDir"
+</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>@R</string>
+ <key>name</key>
+ <string>Send Selection / Document to R.app</string>
+ <key>output</key>
+ <string>showAsTooltip</string>
+ <key>scope</key>
+ <string>source.rapp-console</string>
+ <key>uuid</key>
+ <string>B2E62E8B-6E70-11D9-A369-000D93B3A10E</string>
+</dict>
+</plist>
33 Commands/Show History List.tmCommand
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/ruby
+require ENV['TM_BUNDLE_SUPPORT'] + "/lib/historyList.rb"
+require ENV['TM_SUPPORT_PATH'] + "/lib/ui.rb"
+require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"
+require ENV['TM_SUPPORT_PATH'] + "/lib/escape.rb"
+doc = STDIN.read
+list = HistoryList.new(doc)
+choice = TextMate::UI.menu(list.list)
+TextMate.exit_discard if choice.nil?
+print e_sn(list.add_line(list.list[choice]))</string>
+ <key>fallbackInput</key>
+ <string>document</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>^~</string>
+ <key>name</key>
+ <string>Show History List</string>
+ <key>output</key>
+ <string>insertAsSnippet</string>
+ <key>scope</key>
+ <string>source.rapp-console</string>
+ <key>uuid</key>
+ <string>613CDD87-1F8B-484E-B741-74B95F3C878B</string>
+</dict>
+</plist>
40 Commands/Show Line Output as Tool Tip.tmCommand
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>echo
+#test=`tail -c+2`
+test=$(cat)
+osascript &lt;&lt;-APPLESCRIPT | tail -n +2 | perl -pe 'BEGIN {$/=undef} s/&gt; $//;s/\n\z//'
+tell application "System Events"
+ -- Get a reference to the text field
+ set text_area to (process "R")'s (window "R Console")'s (scroll area 1)'s text area 1
+
+ -- Get text before and after our command
+ set oldtext to text_area's value
+ tell application "R" to cmd "${test//\"/\"}"
+ set newtext to text_area's value
+
+ -- Find the difference between old and new
+ text from (oldtext's length + 1) to -1 of newtext
+end tell
+APPLESCRIPT</string>
+ <key>fallbackInput</key>
+ <string>line</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>@T</string>
+ <key>name</key>
+ <string>Show Line Output as Tool Tip</string>
+ <key>output</key>
+ <string>showAsTooltip</string>
+ <key>scope</key>
+ <string>source.rapp-console</string>
+ <key>uuid</key>
+ <string>1A8EC6F7-D254-4888-9095-75C9DBA519F7</string>
+</dict>
+</plist>
47 Support/lib/historyList.rb
@@ -0,0 +1,47 @@
+def extract_command(string)
+ return "" if string.nil?
+ return string.gsub(/^>\s*|\s*\z/,"")
+end
+class HistoryList
+ attr_reader :list, :last_line, :text
+ def initialize(text)
+ @text = text.split("\n")
+ @last_line = @text.pop
+ @list = @text.grep(/^>(.*)$/).map{|m| extract_command(m)}.grep(/./)
+ @list = @list.reverse.uniq.reverse
+ end
+ def next_item(command)
+ cmd = extract_command(command)
+ return @list[0] if cmd.empty?
+ if i=@list.index(cmd) and i<=@list.length then
+ return @list[i+1]
+ end
+ return nil
+ end
+ def previous_item(command)
+ cmd = extract_command(command)
+ return @list.last if cmd.empty?
+ if i=@list.index(cmd) and i>=1 then
+ return @list[i-1]
+ end
+ return nil
+ end
+ def text
+ @text.join("\n") + "\n"
+ end
+ def add_line(line)
+ self.text + "> #{extract_command(line)}"
+ end
+ def move_up
+ add_line(previous_item(@last_line))
+ end
+ def move_down
+ add_line(next_item(@last_line))
+ end
+ def self.move_up(text)
+ self.new(text).move_up
+ end
+ def self.move_down(text)
+ self.new(text).move_down
+ end
+end
90 Support/lib/parsing.rb
@@ -0,0 +1,90 @@
+require ENV['TM_SUPPORT_PATH'] + "/lib/escape.rb"
+class Lexer
+ Token = Struct.new(:name, :pattern)
+
+ def initialize
+ @tokens = Array.new
+ end
+
+ def add_token(*args)
+ @tokens << Token.new(*args)
+ end
+
+ def lex(data)
+ copy, result = data.dup, Array.new
+ until copy.empty?
+ @tokens.find { |t|
+ copy.sub!(t.pattern, "") && (t.name.nil? || result << [t.name, $&])
+ } || raise(ArgumentError, "Malformed data could not be lexed correctly: #{data.inspect}. Copy is: #{copy.inspect.inspect}. Parsed is: #{result.inspect}")
+ end
+ result
+ end
+end
+class CommandParser
+ def self.snippet(str)
+ self.parse(self.lex(str))
+ end
+ def self.lex(str)
+ lexer = Lexer.new
+ [ [ :fun_begin, /\A(?:\w|\.)*\(/ ],
+ [ :assignment, /\A[\w.]+\s*<?=(?!=)\s*/ ],
+ [ :term, /\A[$\w.]+(?=,|)/ ],
+ [ :term, /\A\.\.\./ ],
+ [ :comma, /\A,\s*/ ],
+ [ :fun_end, /\A\)/ ],
+ [ :quoted, /\A"(?:\\.|[^\\"]+)*"/ ],
+ [ :quoted, /\A'(?:\\.|[^\\']+)*'/ ],
+ [ :operator, /\A\s*([\+\-\*\/^]|&&|\|\||!=?|<=?|>=?|==|~|%|;)\s*/ ],
+ [ :number, /\A\d+(\.\d+)?/ ],
+ [ :brace_begin, /\A\{/ ],
+ [ :brace_end, /\A\}/ ],
+ [ :bracket_begin, /\A\[/ ],
+ [ :bracket_end, /\A\]/ ],
+ [ :list_separator, /\A:/ ],
+ [ nil, /\A\s+/ ] ].each do |name, regex|
+ lexer.add_token(name, regex)
+ end
+ lexer.lex(str)
+ end
+ def self.parse(data)
+ snippet = ""
+ snippet_counter = -1
+ stack = []
+ until data.empty?
+ type,match = data.shift
+ if !stack.empty? && stack.last == :assignment && type.to_s =~ /comma|end$/ then
+ snippet << "}"
+ stack.pop
+ end
+ case type
+ when :fun_begin, :brace_begin, :bracket_begin
+ stack << :group
+ snippet << "${#{snippet_counter+=1}:#{e_sn match}${#{snippet_counter+=1}:"
+ when :assignment
+ stack << :assignment
+ snippet << "#{e_sn match}${#{snippet_counter+=1}:"
+ when :comma
+ snippet << ("}${#{snippet_counter+=1}:" + e_sn(match))
+ when :brace_end, :bracket_end, :fun_end
+ snippet << "}#{e_sn match}}"
+ stack.pop
+ when :quoted
+ snippet << "${#{snippet_counter+=1}:#{match[0..0]}${#{snippet_counter+=1}:#{e_sn match[1..-2].gsub("}","\\}")}}#{match[-1..-1]}}"
+ else
+ snippet << e_sn(match)
+ end
+ end
+ (pp stack;raise "Too many levels: #{snippet}. ") unless stack.length == 0
+ snippet[4..-2]
+ end
+end
+# This is for testing
+# require 'pp'
+# data=DATA.read.split("\n")
+# 5.times do
+# d = data[rand(2834)]
+# # i=0
+# # data.each do |d|
+# pp [d,CommandParser.snippet(d)]
+# # puts "Checking command no: #{i+=1}"
+# end
24 Support/lib/popen3.rb
@@ -0,0 +1,24 @@
+# Open a sub-process and return 3 IO objects: stdin, stdout, stderr
+# Unlike Open3::popen3, it produces a child, not a grandchild
+def popen3(*args)
+ stdin, stdout, stderr = [IO.pipe, IO.pipe, IO.pipe]
+ fork do
+ stdin[1].close
+ STDIN.reopen(stdin[0])
+ stdin[0].close
+
+ stdout[0].close
+ STDOUT.reopen(stdout[1])
+ stdout[1].close
+
+ stderr[0].close
+ STDERR.reopen(stderr[1])
+ stderr[1].close
+
+ exec(*args)
+ end
+ stdin[0].close
+ stdout[1].close
+ stderr[1].close
+ [stdin[1], stdout[0], stderr[0]]
+end
42 Syntaxes/R Console (R_app).tmLanguage
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>fileTypes</key>
+ <array/>
+ <key>keyEquivalent</key>
+ <string>^~R</string>
+ <key>name</key>
+ <string>R Console (R.app)</string>
+ <key>patterns</key>
+ <array>
+ <dict>
+ <key>begin</key>
+ <string>^&gt; </string>
+ <key>beginCaptures</key>
+ <dict>
+ <key>0</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.section.embedded.rapp-console</string>
+ </dict>
+ </dict>
+ <key>end</key>
+ <string>\n|\z</string>
+ <key>name</key>
+ <string>source.r.embedded.rapp-console</string>
+ <key>patterns</key>
+ <array>
+ <dict>
+ <key>include</key>
+ <string>source.r</string>
+ </dict>
+ </array>
+ </dict>
+ </array>
+ <key>scopeName</key>
+ <string>source.rapp-console</string>
+ <key>uuid</key>
+ <string>F629C7F3-823B-4A4C-8EEE-9971490C5710</string>
+</dict>
+</plist>
46 info.plist
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>contactEmailRot13</key>
+ <string>ovovxb@rin.zct.qr</string>
+ <key>contactName</key>
+ <string>Hans-Jörg Bibiko</string>
+ <key>deleted</key>
+ <array/>
+ <key>description</key>
+ <string>Extension to the R.bundle to remote the Mac's R GUI R.app</string>
+ <key>mainMenu</key>
+ <dict>
+ <key>items</key>
+ <array>
+ <string>B2E62E8B-6E70-11D9-A369-000D93B3A10E</string>
+ <string>7AF6ADAA-E6F0-4B9D-B146-A62BDE600D74</string>
+ <string>1A8EC6F7-D254-4888-9095-75C9DBA519F7</string>
+ <string>48E1CB3A-8349-46E4-86B0-671663712005</string>
+ <string>------------------------------------</string>
+ <string>613CDD87-1F8B-484E-B741-74B95F3C878B</string>
+ <string>2CE460A3-ADAE-47B6-8A89-EE142C714CC2</string>
+ <string>C1302FC5-FDC8-4560-8DFF-2CEC85EFCD19</string>
+ </array>
+ <key>submenus</key>
+ <dict/>
+ </dict>
+ <key>name</key>
+ <string>R Console (R.app)</string>
+ <key>ordering</key>
+ <array>
+ <string>B2E62E8B-6E70-11D9-A369-000D93B3A10E</string>
+ <string>1A8EC6F7-D254-4888-9095-75C9DBA519F7</string>
+ <string>7AF6ADAA-E6F0-4B9D-B146-A62BDE600D74</string>
+ <string>48E1CB3A-8349-46E4-86B0-671663712005</string>
+ <string>613CDD87-1F8B-484E-B741-74B95F3C878B</string>
+ <string>2CE460A3-ADAE-47B6-8A89-EE142C714CC2</string>
+ <string>C1302FC5-FDC8-4560-8DFF-2CEC85EFCD19</string>
+ <string>F629C7F3-823B-4A4C-8EEE-9971490C5710</string>
+ <string>CAEB703B-1D79-4D3A-90BB-2A2C2BD846F7</string>
+ </array>
+ <key>uuid</key>
+ <string>B24F6AAD-1722-494A-A0AB-B8E7AB587966</string>
+</dict>
+</plist>
Please sign in to comment.
Something went wrong with that request. Please try again.