1

I'm trying to create a simple plugin for Sublime Text 2 that will permit OS X users to send the selected text to R64.app for computation. So far I have the following:

import sublime, sublime_plugin, os
class send2rCommand(sublime_plugin.TextCommand):
    def run(self,blah):
        os.system("""osascript -e 'tell application "R64" to activate'""")
        for sel in self.view.sel():
            sel_text = self.view.substr(sel)
            os.system('''osascript -e 'on run(args)' -e 'tell application "R64" to cmd (item 1 of args)' -e 'end run' -- "'''+sel_text+'''"''')

However, this seems to fail when the selected text contains the $ character (a frequent occurrence in R). I also suspect that I've misunderstood something as I'm not sure why the run command fails (with an error in python) when I remove the ,blah part of the run function definition.

4

1 回答 1

0

解决方案似乎是在发送到 osascript 之前必须替换$字符:\$

import sublime, sublime_plugin, os
class send2rCommand(sublime_plugin.TextCommand):
    def run(self,blah):
        os.system("""osascript -e 'tell application "R64" to activate'""")
        for sel in self.view.sel():
            sel_text = self.view.substr(sel)
            sel_text = sel_text.replace('$','\$')
            os.system('''osascript -e 'on run(args)' -e 'tell application "R64" to cmd (item 1 of args)' -e 'end run' -- "'''+sel_text+'''"''')
于 2012-09-14T14:37:25.550 回答