Skip to content

Commit

Permalink
Added semicolon-separated commands execution from R editor
Browse files Browse the repository at this point in the history
Filtered out comments and empty lines from the R editor content;
  • Loading branch information
Valentin Georgiev committed Aug 25, 2011
1 parent 68dbce0 commit 1cf343a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
Expand Up @@ -52,5 +52,5 @@ public interface IRBusinessManager extends IBioclipseManager {
@PublishedMethod(
methodSummary = "Passes the selection to eval"
)
public void evalSnippet(String seltext);
public String evalSnippet(String seltext);
}
Expand Up @@ -395,19 +395,20 @@ public String eval(String command) {
return returnVal;
}

public void evalSnippet(String seltext) {
public String evalSnippet(String seltext) {
//split up newlines
String[] rcmds = seltext.split("\n");

String msg = NEWLINE + "You selected text: " + NEWLINE;

//Run commands as individual R commands line by line
for (String cmd : rcmds){
msg += cmd + NEWLINE;
if(!cmd.startsWith("#"))
eval(cmd);
String retVal = null;
//Run commands as individual R commands line by line; split line on ";"
for (String line : rcmds){
String[] cmds = line.split(";");
for (String cmd : cmds) {
if(!cmd.startsWith("#") && cmd.length() != 0)
retVal = eval(cmd);
}
}
logger.debug(msg);
return retVal;

}

public String ls() {
Expand Down
Expand Up @@ -30,7 +30,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
IDocument doc = reditor.getDocumentProvider().getDocument(reditor.getEditorInput());
String contents = doc.get();

System.out.println("Editor contents: " + contents);
System.out.println("Editor content: \n" + contents);

IRBusinessManager r = Activator.getDefault().getJavaRBusinessManager();
r.evalSnippet(contents);
Expand Down
Expand Up @@ -26,7 +26,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
if (!(selection instanceof ITextSelection)) return null;

ITextSelection textsel = (ITextSelection) selection;
System.out.println("You selected text: " + textsel.getText());
System.out.println("You selected text: \n" + textsel.getText());

IRBusinessManager r = Activator.getDefault().getJavaRBusinessManager();
r.evalSnippet(textsel.getText());
Expand Down

0 comments on commit 1cf343a

Please sign in to comment.