[Sciviews-commits] r345 - in komodo/SciViews-K/content: . js js/tools

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Dec 20 22:06:38 CET 2010


Author: prezez
Date: 2010-12-20 22:06:38 +0100 (Mon, 20 Dec 2010)
New Revision: 345

Modified:
   komodo/SciViews-K/content/RHelpWindow.xul
   komodo/SciViews-K/content/js/commands.js
   komodo/SciViews-K/content/js/pref-R.js
   komodo/SciViews-K/content/js/r.js
   komodo/SciViews-K/content/js/robjects.js
   komodo/SciViews-K/content/js/sciviews.js
   komodo/SciViews-K/content/js/socket.js
   komodo/SciViews-K/content/js/tools/file.js
Log:
Changed the default connection back to 'socket', until the http transport is fixed (problems with long strings. Isn't it due to the limitation in the http GET query length?).
Tried to directly use the preference value 'sciviews.client.type' everywhere instead of sv.r.server and sv.socketType, to make the configuration possible.
A load of other small changes.

Modified: komodo/SciViews-K/content/RHelpWindow.xul
===================================================================
--- komodo/SciViews-K/content/RHelpWindow.xul	2010-11-26 15:22:54 UTC (rev 344)
+++ komodo/SciViews-K/content/RHelpWindow.xul	2010-12-20 21:06:38 UTC (rev 345)
@@ -269,12 +269,14 @@
 	//var cmd = 'suppressMessages(make.packages.html()); ';
 	//cmd += 'options(htmlhelp = TRUE); ';
 	//cmd += "cat(" + (isWin? "R.home()" : "tempdir()") + ");";
-    
+
 	// If it is the http server, we know that the help server is launched
 	// (it is the same), and we also know the port!
 	var res = false;
 	var cmd = "";
-	if (sv.r.server == "http") {
+	// Use only one type of connection for both client and server!
+	//if (sv.r.server == "http") {
+	if (sv.prefs.getString("sciviews.client.type", "socket") == "http") {
         var port = sv.prefs.getString("sciviews.client.socket", "8888");
 		var path = "http://127.0.0.1:" + port + "/doc/html/index.html";
 		browser.homePage = sv.helpStartURI = path;

Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js	2010-11-26 15:22:54 UTC (rev 344)
+++ komodo/SciViews-K/content/js/commands.js	2010-12-20 21:06:38 UTC (rev 345)
@@ -34,13 +34,13 @@
 		return(null);
 	}
 
-	// Get reference to a window, opening it if is closed
-	function _getWindowRef(uri, name, features, focus) { //, ...
+	//Get reference to a window, opening it if is closed
+	function _getWindowRef(uri, name, features, focus) {//, ...
 		var win = _getWindowByURI(uri);
 		if (!win || win.closed) {
 			try {
 				var args = Array.apply(null, arguments);
-				args = args.slice(0, 3).concat(args.slice(4));
+				args = args.slice(0,3).concat(args.slice(4));
 				if (!features) args[2] = "chrome,modal,titlebar";
 				win = window.openDialog.apply(null, args);
 			} catch (e) {
@@ -110,14 +110,14 @@
 				}
 			return;
 		}
-	
-		var isWin = navigator.platform.indexOf("Win") === 0;
-		var id = sv.prefs.getString("svRApplication",
-			isWin ? "r-gui" : "r-terminal");
 
-		// runIn = "command-output-window", "new-console",
-		// env strings: "ENV1=fooJ\nENV2=bar"
-		// gPrefSvc.prefs.getStringPref("runEnv");
+	var isWin = navigator.platform.indexOf("Win") === 0;
+	var id = sv.prefs.getString("svRApplication",
+                                isWin? "r-gui" : "r-terminal");
+
+	// runIn = "command-output-window", "new-console",
+	// env strings: "ENV1=fooJ\nENV2=bar"
+	// gPrefSvc.prefs.getStringPref("runEnv");
 		var env = ["koId=" + sv.prefs.getString("sciviews.client.id",
 			"SciViewsK"),
 			"koHost=localhost",
@@ -127,33 +127,33 @@
 			"koServe=" + sv.prefs.getString("sciviews.client.socket", "8888"),
 			"koPort=" + sv.prefs.getString("sciviews.server.socket", "7052"),
 			"koDebug=" + String(sv.socket.debug).toUpperCase(),
-			"koAppFile=" + sv.tools.file.path("binDir", "komodo" + (isWin ? ".exe" : ""))
-		];
-		var runIn = "no-console";
-		env.push("Rid=" + id);
-	
-		switch (id) {
-		 case "r-tk":
+		"koAppFile=" + sv.tools.file.path("binDir", "komodo" + (isWin? ".exe" : ""))
+	];
+	var runIn = "no-console";
+	env.push("Rid=" + id);
+
+	switch (id) {
+		case "r-tk":
 			env.push("Rid=R-tk");
 			// Set DISPLAY only when not set:
 			var XEnv = Components.classes["@activestate.com/koEnviron;1"]
 				.createInstance(Components.interfaces.koIEnviron);
-			if (!XEnv.has("DISPLAY")) env.push("DISPLAY=:0");
+			if (!XEnv.has("DISPLAY"))	env.push("DISPLAY=:0");
 			delete(XEnv);
 			break;
-		 case "r-terminal":
+		case "r-terminal":
 			runIn = "new-console";
 			break;
-		 default:
-		}
-	
-		ko.run.runCommand(window, cmd, cwd, env.join("\n"), false,
-			false, false, runIn, false, false, false);
-	
-		// Register observer of application termination.
-		this.rObserver = new AppTerminateObserver(cmd);
+		default:
 	}
 
+	ko.run.runCommand(window, cmd, cwd, env.join("\n"), false,
+		false, false, runIn, false, false, false);
+
+	// Register observer of application termination.
+	this.rObserver = new AppTerminateObserver(cmd);
+}
+
 	// This will observe status message notification to be informed about
 	// application being terminated. A more straightforward way would be to use
 	// runService.RunAndNotify but this wouldn't allow to start app in a console
@@ -208,20 +208,21 @@
 
 	this.updateRStatus = function (running) {
 		running = !!running;
-		// Toggle status if no argument
+        // Toggle status if no argument
 		if (running === undefined) {
-			running = !sv.r.runnig;
+            running = !sv.r.running;
 		} else {
 			running = true;
 		}
-		if (running != sv.r.running) {
-			sv.r.running = !!running;
+       // if (running != sv.r.running) {
+			//sv.r.running = running;
+			//sv.r.running = running;
 			//xtk.domutils.fireEvent(window, 'r_app_started_closed');
 			// PhG: these events are disabled for now, because menus are
 			//      sometimes disabled when they shouldn't be!!! Very ennoying!
 			//window.updateCommands('r_app_started_closed');
-			sv.log.debug("R status updated: " + (running ? "" : "not ") + "running");
-		}
+			//sv.cmdout.message("R status: " + (running? "" : "not ") + "running" );
+		//}
 	}
 
 	this.openPkgManager = function () {
@@ -237,8 +238,8 @@
 		return(win);
 	}
 
-	// sv.command.openHelp - returns reference to the RHelpWindow
-	//FIXME: help in tab still buggy
+// sv.command.openHelp - returns reference to the RHelpWindow
+//FIXME: help in tab still buggy
 	this.openHelp = function (uri) {
 		var RHelpWin = _this.RHelpWin;
 
@@ -270,7 +271,7 @@
 
 		// Open R-help in a right tab
 		if (rhelpTabbed) {
-			// make sure tab is visible and select it
+			// Make sure tab is visible and select it
 			var tabPanel = document.getElementById("rhelpviewbox");
 			var tab = document.getElementById("rhelp_tab");
 			var tabBox = tabPanel.parentNode.parentNode;
@@ -309,7 +310,7 @@
 	}
 
 	// Close r-help tab
-	this.closeHelp = function () {
+	this.closeHelp = function() {
 		var tabPanel = document.getElementById("rhelpviewbox");
 		var tab = document.getElementById("rhelp_tab");
 		var tabBox = tabPanel.parentNode.parentNode;
@@ -333,63 +334,60 @@
 
         const XRRunning = 1, XRStopped = 2, XisRDoc = 4, XHasSelection = 8;
         var handlers = {
-                'cmd_svOpenPkgManager': ["sv.command.openPkgManager();", XRRunning],
-                'cmd_svBrowseWD': ['sv.r.setwd(\'current\', true);', XRRunning],
-                'cmd_svQuitR': ['sv.r.quit();', XRRunning],
-                'cmd_svOpenHelp': ["sv.command.openHelp();", XRRunning],
-                'cmd_svSessionMgr': ["sv.command.openSessionMgr();", XRRunning],
+                'cmd_svOpenPkgManager': [ "sv.command.openPkgManager();", XRRunning ],
+                'cmd_svBrowseWD': [ 'sv.r.setwd(\'current\', true);', XRRunning ],
+                'cmd_svQuitR': [ 'sv.r.quit();', XRRunning ],
+                'cmd_svOpenHelp': [ "sv.command.openHelp();", XRRunning ],
+                'cmd_svSessionMgr': [ "sv.command.openSessionMgr();", XRRunning ],
                 'cmd_svStartR': ['sv.command.startR();', 0], // XRStopped],
-				'cmd_svREscape': ['sv.r.escape();', XRRunning],
+                'cmd_svREscape': [ 'sv.r.escape();', XRRunning ],
                 // 'cmd_svUpdateRInfo': ['sv.socket.rUpdate();', XRRunning],
-                'cmd_svRRunAll': ['sv.r.send("all");', XisRDoc | XRRunning],
-                'cmd_svRSourceAll': ['sv.r.source("all");', XisRDoc | XRRunning],
-                'cmd_svRRunBlock': ['sv.r.send("block");', XisRDoc | XRRunning],
-                'cmd_svRRunFunction': ['sv.r.send("function");', XisRDoc | XRRunning],
-                'cmd_svRRunLine': ['sv.r.send("line");', XisRDoc | XRRunning],
-                'cmd_svRRunPara': ['sv.r.send("para");', XisRDoc | XRRunning],
-                'cmd_svRSourceBlock': ['sv.r.source("block");', XisRDoc | XRRunning],
-                'cmd_svRSourceFunction': ['sv.r.source("function");', XisRDoc | XRRunning],
-                'cmd_svRSourcePara': ['sv.r.source("para");', XisRDoc | XRRunning],
-				'cmd_svRRunLineOrSelection': ['sv.r.run();', XisRDoc | XRRunning],
-                'cmd_svRSourceLineOrSelection': ['sv.r.source("line/sel");', XisRDoc | XRRunning],
-                'cmd_svRRunSelection': ['sv.r.send("sel");', XisRDoc | XRRunning | XHasSelection],
-                'cmd_svRSourceSelection': ['sv.r.source("sel");', XisRDoc | XRRunning | XHasSelection],
-				'cmd_viewrtoolbar': ['ko.uilayout.toggleToolbarVisibility(\'RToolbar\')', 0]
+                'cmd_svRRunAll': [ 'sv.r.send("all");',XisRDoc | XRRunning ],
+                'cmd_svRSourceAll': [ 'sv.r.source("all");',XisRDoc | XRRunning ],
+                'cmd_svRRunBlock': [ 'sv.r.send("block");',XisRDoc | XRRunning ],
+                'cmd_svRRunFunction': [ 'sv.r.send("function");',XisRDoc | XRRunning ],
+                'cmd_svRRunLine': [ 'sv.r.send("line");',XisRDoc | XRRunning ],
+                'cmd_svRRunPara': [ 'sv.r.send("para");',XisRDoc | XRRunning ],
+                'cmd_svRSourceBlock': [ 'sv.r.source("block");',XisRDoc | XRRunning ],
+                'cmd_svRSourceFunction': [ 'sv.r.source("function");',XisRDoc | XRRunning ],
+                'cmd_svRSourcePara': [ 'sv.r.source("para");',XisRDoc | XRRunning ],
+				'cmd_svRRunLineOrSelection': [ 'sv.r.run();', XisRDoc | XRRunning ],
+                'cmd_svRSourceLineOrSelection': [ 'sv.r.source("line/sel");', XisRDoc | XRRunning ],
+                'cmd_svRRunSelection': [ 'sv.r.send("sel");',XisRDoc | XRRunning | XHasSelection ],
+                'cmd_svRSourceSelection': [ 'sv.r.source("sel");', XisRDoc | XRRunning | XHasSelection ],
+                'cmd_viewrtoolbar': [ 'ko.uilayout.toggleToolbarVisibility(\'RToolbar\')', 0 ]
         }
 
         // Temporary
         function _isRRunning () {
             return(true);
         }
-		
+
         function _isRCurLanguage () {
             var view = ko.views.manager.currentView;
             if (!view || !view.document) return(false);
             return(view.document.language == "R");
         }
-		
+
         function _hasSelection () {
             var view = ko.views.manager.currentView;
             if (!view || !view.scimoz) return(false);
-            return((view.scimoz.selectionEnd - view.scimoz.selectionStart) != 0);
+            return ((view.scimoz.selectionEnd - view.scimoz.selectionStart) != 0);
         }
 
         function svController() {}
-        
+
 		svController.prototype = new Controller();
         
 		svController.prototype.constructor = svController;
         
 		svController.prototype.destructor = function () { }
         
-		svController.prototype.isCommandEnabled = function (command) {
-            // PhG: without a try, it reases an error => must look more in details
-			// later on this stuff!
-			try {
-				if (!command in handlers) return(false);
-			} catch(e) { return(true) }
-			
-            var test = handlers[command][1];
+        svController.prototype.isCommandEnabled = function(command) {
+            if(!(command in handlers)) return(false);
+			return(true);
+		}
+            //var test = handlers[command][1];
             // PhG: since _isRRunning() returns always true, we are currently
 			// NOT able to start R!
 			// KB: Yes, but startR is enabled by on Komodo load and event
@@ -410,18 +408,14 @@
         svController.prototype.supportsCommand = svController.prototype
 			.isCommandEnabled;
 
-        svController.prototype.doCommand = function (command) {
-            // TODO: I got a series of errors with this and start to get tired
-			// from it => put in a try... and will look at this more closely later!
-			try {
-				if (command in handlers) return(eval(handlers[command][0]));
-			} catch(e) { }
-			return(false);
+        svController.prototype.doCommand = function(command) {
+            if (command in handlers) return(eval(handlers[command][0]));
+            return (false);
         }
 
         window.controllers.appendController(new svController());
         //sv.log.debug("Controllers has been set.");
-	}
+}
 
 // Code below is for extra items in editor context menu (eg. "run selection"),
 // Commented out because it is still buggy
@@ -431,12 +425,12 @@
 //		var ids = ["editor-context-sep-sv", "editor-context-sv-r-send-line-sel"];
 //
 //		var langNotR = ko.views.manager.currentView.koDoc.language != "R";
-//		var visibility = langNotR ? "collapse" : "visible";
+//		var visibility = langNotR? "collapse" : "visible";
 ///*
 //		for (i in ids)
 //			document.getElementById(ids[i]).style.visibility = visibility;
 //*/
-//		//} catch(e) { }
+//		//} catch(e) {}
 //
 //	}
 //var editorContextMenu = document.getElementById("editorContextMenu");
@@ -450,7 +444,7 @@
 			.classes["@activestate.com/koKeybindingSchemeService;1"]
 			.getService(Components.interfaces.koIKeybindingSchemeService);
 
-		//TODO: use of gKeybindingMgr could simplify this code
+//TODO: use of gKeybindingMgr could simplify this code
 		//gKeybindingMgr.keybindingSchemeService
 
 		var svSchemeDefault = sv.tools.file
@@ -507,14 +501,14 @@
 				newSchemeData += "binding " + k + " " + key + "\n";
 			}
 			sch.data += "\n\n# SciViews\n" + newSchemeData;
-			sv.log.debug(updatedKeys.length +
-				"SciViews keybindings have been updated in \"" +
+			sv.log.debug(" SciViews keybindings (" + updatedKeys.length +
+				") have been updated in \"" +
 				currentSchemeName + "\" scheme.");
 		} else {
 			//gKeybindingMgr.removeCommandsWithPrefix("cmd_sv");
 			sch.data = sch.data.replace(bindingRx, "");
-			sv.log.debug("SciViews keybindings have been cleared in \"" +
-				currentSchemeName + "\" scheme.");
+			sv.log.debug("SciViews keybindings (" + updatedKeys.length +
+				") have been cleared in \"" + currentSchemeName + "\" scheme.");
 		}
 		sch.save();
 		//gKeybindingMgr.saveAndApply();
@@ -530,10 +524,9 @@
 		//	"ko.commands.doCommandAsync('cmd_svRTriggerCompletion',
 		//  event);"].join(";"));
         //sv.log.debug("Keybindings has been applied.");
-
 	}
 
-    addEventListener("load", _setControllers, false);
-    addEventListener("load", _setKeybindings, false);
+	addEventListener("load", function() setTimeout(_setControllers, 600), false);
+	addEventListener("load", _setKeybindings, false);
 
 }).apply(sv.command);

Modified: komodo/SciViews-K/content/js/pref-R.js
===================================================================
--- komodo/SciViews-K/content/js/pref-R.js	2010-11-26 15:22:54 UTC (rev 344)
+++ komodo/SciViews-K/content/js/pref-R.js	2010-12-20 21:06:38 UTC (rev 345)
@@ -6,9 +6,8 @@
 // PrefR_OnLoad();                            	// R preference widow loaded
 // TODO: update this list...
 //////////////////////////////////////////////////////////////////////////////
-//
-// TODO: use 'R' simply as default R (terminal on Win/Mac, or on Linux)
 
+
 /* TODO: prefs to include:
 * address for remote R (sv.socket.host)? (if not localhost - disable source* commands)
 * R help: show in tab (sidebar - another TODO) or in separate window
@@ -216,13 +215,13 @@
 
 function OnPreferencePageOK(prefset) {
 	prefset = parent.hPrefWindow.prefset;
-    prefset.setStringPref("svRDefaultInterpreter",
-    document.getElementById("svRDefaultInterpreter").value);
-    prefset.setStringPref("svRApplication",
-    document.getElementById('svRApplication')
+	prefset.setStringPref("svRDefaultInterpreter",
+	document.getElementById("svRDefaultInterpreter").value);
+	prefset.setStringPref("svRApplication",
+	document.getElementById('svRApplication')
 		.selectedItem.getAttribute("value"));
 	prefset.setStringPref("svRApplicationId",
-    document.getElementById('svRApplication').selectedItem.id);
+	document.getElementById('svRApplication').selectedItem.id);
 
 
 	var outDec = document.getElementById('r.csv.dec').value;
@@ -245,7 +244,7 @@
 
 	if (sv.r.running) {
 		sv.r.eval('options(OutDec="' + outDec + '", ' +
-        'OutSep="' + outSep + '")', true);
+		'OutSep="' + outSep + '")', true);
 	}
 
 	// Set the client type
@@ -258,13 +257,13 @@
 
 	menuListGetValues();
 
-    // Restart socket server if running and port changed
-    var serverPort = document.getElementById('sciviews.server.socket').value;
-    if(sv.socket.serverIsStarted &&
-       serverPort != prefset.getStringPref("sciviews.server.socket")){
-        prefset.setStringPref("sciviews.server.socket", serverPort);
-        sv.socket.serverStart();
-    }
+	// Restart socket server if running and port changed
+	var serverPort = document.getElementById('sciviews.server.socket').value;
+	if(sv.socket.serverIsStarted &&
+		serverPort != prefset.getStringPref("sciviews.server.socket")){
+		prefset.setStringPref("sciviews.server.socket", serverPort);
+		sv.socket.serverStart();
+	}
 	return(true);
 }
 
@@ -275,6 +274,11 @@
 	var menuApplication = document.getElementById("svRApplication");
     var menuInterpreters = document.getElementById("svRDefaultInterpreter");
 
+	// Just in case
+	if(sv.tools.file.exists(menuInterpreters.value) == sv.tools.file.TYPE_NONE) {
+		ko.dialogs.alert("Cannot find file: " + menuInterpreters.value, null, "SciViews-K preferences");
+	}
+
     var app = os.path.basename(menuInterpreters.value);
 
     if (apps[menuApplication.value].app != app) {
@@ -379,47 +383,47 @@
 
 // Get CRAN mirrors list - independently of R
 function PrefR_UpdateCranMirrors(localOnly) {
-	var sv_file = sv.tools.file;
+	var svFile = sv.tools.file;
 
 	// Get data in as CSV:
 	var csvName = "CRAN_mirrors.csv";
-	var localDir = sv_file.path("PrefD", "extensions", "sciviewsk at sciviews.org");
+	var localDir = svFile.path("PrefD", "extensions", "sciviewsk at sciviews.org");
 	var path, csvContent;
 	var arrData;
 	if (!localOnly) {
 		try {
-			csvContent = sv_file.readURI("http://cran.r-project.org/" + csvName);
-			//sv_file.write(localCopy, csvContent, 'utf-8');
+			csvContent = svFile.readURI("http://cran.r-project.org/" + csvName);
+			//svFile.write(localCopy, csvContent, 'utf-8');
 		} catch(e) {}
 	}
 
 	var nativeJSON = Components.classes["@mozilla.org/dom/json;1"]
     .createInstance(Components.interfaces.nsIJSON);
 
-	var jsonFile = sv_file.path(localDir, "CRAN_mirrors.json");
+	var jsonFile = svFile.path(localDir, "CRAN_mirrors.json");
 	var alreadyCached = false;
 	if (!csvContent) {
 		// First, check if there is serialized version:
-		alreadyCached = sv_file.exists(jsonFile);
+		alreadyCached = svFile.exists(jsonFile);
 		if (alreadyCached) {
-			arrData = nativeJSON.decode(sv_file.read(jsonFile));
+			arrData = nativeJSON.decode(svFile.read(jsonFile));
 			//sv.cmdout.append("Read from: JSON");
 		} else {
 			var localPaths = [ ];
 
 			var platform = navigator.platform.toLowerCase().substr(0,3);
-			if (platform == "win") // TODO: what is the pref is not set??
-            localPaths.push(sv_file.path(sv.prefs.getString("svRDefaultInterpreter"),
-            "../../doc"));
+			if (platform == "win") // TODO: what if the pref is not set??
+				localPaths.push(svFile.path(sv.prefs.getString("svRDefaultInterpreter"),
+					"../../doc"));
 			else { // if (platform == "lin")
 				localPaths.push('/usr/share/R/doc'); 	// try other paths: // mac: ????
 				localPaths.push('/usr/local/share/R/doc');
 			}
 			var file;
 			for (i in localPaths) {
-				file = sv_file.getfile(localPaths[i], csvName);
+				file = svFile.getfile(localPaths[i], csvName);
 				if (file.exists()) {
-					csvContent = sv_file.read(file.path);
+					csvContent = svFile.read(file.path);
 					//sv.cmdout.append("Read from: " + localPaths[i]);
 					break;
 				}
@@ -453,7 +457,7 @@
 	if (!localOnly || !alreadyCached) {
 		// If updated from web, or not cached yet,
 		// serialize and save to file for faster later use:
-		sv_file.write(jsonFile, nativeJSON.encode(arrData), 'utf-8');
+		svFile.write(jsonFile, nativeJSON.encode(arrData), 'utf-8');
 	}
 
 	// Put arrData into MenuList

Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js	2010-11-26 15:22:54 UTC (rev 344)
+++ komodo/SciViews-K/content/js/r.js	2010-12-20 21:06:38 UTC (rev 345)
@@ -1,1890 +1,1918 @@
-// SciViews-K R functions
-// Define functions to pilot R from Komodo Edit 'sv.r' & 'sv.r.pkg'
-// Copyright (c) 2008-2009, Ph. Grosjean (phgrosjean at sciviews.org) & K. Barton
-// License: MPL 1.1/GPL 2.0/LGPL 2.1
-////////////////////////////////////////////////////////////////////////////////
-// To cope with versions incompatibilities, we define this:
-// sv.alert(sv.r.RMinVersion); // Display minimum R version required
-// sv.r.server; // Which kind of R server is used? Either 'http' or 'socket'
-// sv.r.sep; // Item separator that R should use returning data.
-// sv.r.running; // Is the linked R interpreter currently running?
-// sv.r.test();  // Check if an R interpreter is communicating with us
-//
-// sv.r.print(text, newline, command, partial); // Print to local R console
-// sv.r.eval(cmd); // Evaluate 'cmd' in R
-// sv.r.evalHidden(cmd, earlyExit); // Evaluate 'cmd' in R in a hidden way
-// sv.r.evalCallback(cmd, procfun, ...); // Evaluate 'cmd' in R and call 'procfun'
-// sv.r.escape(cmd); // Escape R multiline mode, 'cmd' to run then
-// sv.r.setwd(); // Set the working dir (choose or set to current buffer)
-// sv.r.run(); // Run current selection or line in R and goto next line
-// sv.r.runEnter(breakLine = false); // Run current line to pos in R
-									 // and add a line feed
-// sv.r.source(what); // Source various part of current buffer to R
-// sv.r.send(what); // Send various part of current buffer to R
-// sv.r.calltip(code); // Get a calltip for a piece of code (current code if "")
-// sv.r.calltip_show(tip);		// Companion functions for sv.r.calltip
-// sv.r.complete(code); // AutoComplete mechanism for R
-// sv.r.display(topic, what); // Display 'topic' according to 'what' type
-// sv.r.help(topic, package); // Get help in R for 'topic', 'package' is optional
-// sv.r.example(topic); // Run example in R for 'topic', 'topic' is optional
-// sv.r.search(topic); // Search R help for 'topic'
-// sv.r.search_select(topics); // Callback function: display a list of
-                               // choices to select help page from
-// sv.r.siteSearch(topic); // Search R web sites for 'topic'
-// sv.r.dataList(loaded); // List R datasets in "loaded" or "all" packages
-// sv.r.data(); // Select one dataset to load
-// sv.r.data_select(data); // Callback function for sv.r.data()
-// sv.r.browseVignettes(); // Open a web page listing all installed vignettes
-// sv.r.saveWorkspace(file, title);  // Save data in a .Rdata file
-// sv.r.loadWorkspace(file, attach); // Load the content of a .RData file into
-									 // the workspace, or attach it
-// sv.r.saveHistory(file, title); // Save the history in a file
-// sv.r.loadHistory(file, title); // Load the history from a file
-// sv.r.saveGraph(type, file, title, height, width, method);
-//                  // Save the current R graph in different formats
-// sv.r.obj(objClass); // Set active object for objClass (data.frame if omitted)
-// sv.r.obj_select(data); // The callback for sv.r.obj() to select an object
-// sv.r.obj_select_dataframe(objname); // Select one data frame to activate
-// sv.r.obj_select_lm(objname);		   // Select one lm object to activate
-// sv.r.obj_refresh_dataframe(data);   // Refresh active data frame's MRUs
-// sv.r.obj_refresh_lm(data); 		   // Refresh active 'lm' object
-// sv.r.obj_message(); // Refresh statusbar message about active df and lm
-// sv.r.refreshSession(); // Refresh MRU lists associated with current session
-// sv.r.initSession(dir, datadir, scriptdir, reportdir);
-// sv.r.setSession(dir, datadir, scriptdir, reportdir, saveOld, loadNew);
-                    // Initialize R session with corresponding directories
-					// setSession() also do the change in R and is to be used
-					// preferably, except at Komodo startup!
-                    // dir: session directory, xxxdir: xxx subdirectory,
-                    // saveOld (default true): do we save old session data?
-                    // loadNew (default true): do we load data from new session?
-// sv.r.switchSession(inDoc); // Switch to another R session (possibly create it)
-// sv.r.exploreSession(); // Explore the session dirs in default file browser
-// sv.r.clearSession();   // Clear session's .RData and .Rhistory files
-// sv.r.reloadSession();  // Reload .RData nd .Rhistory files from session dir
-// sv.r.quit(save); // Quit R (ask to save in save in not defined)
-// sv.r.kpf2pot(kpfFile); // Create a translation (.pot) file for a project
-// sv.r.kpz2pot(kpzFile); // Create a translation (.pot) file for a package
-// sv.r.kpfTranslate(kpfFile); // Translate a project
-// sv.r.kpzTranslate(kpzFile); // Translate a package
-//
-// Note: sv.r.objects is implemented in robjects.js
-//       sv.r.console functions are implemented in rconsole.js
-//
-// sv.r.pkg namespace: /////////////////////////////////////////////////////////
-// sv.r.pkg.repositories(); // Select repositories for installing R packages
-// sv.r.pkg.chooseCRANMirror(andInstall); // replacement for .CRANmirror,
-							// optionally calls .install after execution
-// sv.r.pkg.available();    // List available R packages on selected repository
-// sv.r.pkg.installed();    // List installed R packages
-// sv.r.pkg.new(); // List new R packages available on CRAN
-// sv.r.pkg.old(); // List older installed R packages than distributed versions
-// sv.r.pkg.update(); // Update installed R packages from the repositories
-// sv.r.pkg.status(); // Show status of installed R packages
-// sv.r.pkg.loaded(); // Show which R packages are loaded
-// sv.r.pkg.load(); // Load one R package
-// sv.r.pkg.unload(); // Unload one R package
-// sv.r.pkg.unload_select(pkgs); // Callback function for sv.r.pkg.unload()
-// sv.r.pkg.remove(); // Remove one R package
-// sv.r.pkg.remove_select(pkgs); // Callback function for sv.r.pkg.remove()
-// sv.r.pkg.install(pkgs, repos); // Install R package(s) from local files or repositories
-
-
-/// REMOVED! replaced by sv.r.pkg.install
-// sv.r.pkg.installLocal(); // Install one or more R packages from local files
-// sv.r.pkg.installSV(); // Install the SciViews-R packages from CRAN
-// sv.r.pkg.installSVrforge(); // Install development versions of SciViews-R
-                               // from R-Forge
-// sv.r.pkg.CRANmirror();   // Select preferred CRAN mirror
-
-/// REMOVED! use sv.command.openHelp instead
-// sv.r.helpStart(start); // Start R help in the browser, unless start is false
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// TODO:
-// * In overlay: add "source file" context menu item in the project tab
-
-// Define the 'sv.r' namespace
-if (typeof(sv.r) == 'undefined')
-	sv.r = {
-		RMinVersion: "2.11.0",	// Minimum version of R required
-		server: "http", 		// Currently, either 'http' or 'socket'
-		sep: ";;",				// Separator used for items
-		running: true			// Indicate if R is currently running
-								// FIXME: before we solve the issue of updating R status
-	};
-
-// Check where the R executable can be found
-sv.r.application = function (warn) {
-	if (warn === undefined) warn = false;
-	
-	// Look for R executable for batch processes
-	var R = sv.tools.file.whereIs("R")
-	if (R == null & warn)
-		sv.alert("R is not found", "You should install or reinstall R" +
-			" on this machine (see http://cran.r-project.org). Under Windows" +
-			" you could also run RSetReg.exe from the /bin subdirectory of R" +
-			" install in case R is installed, but not recognized by SciViews).");
-	// Save the path in r.application prefs
-	if (R == null) R = "";
-	sv.prefs.setString("r.application", R, true);
-	return(R);
-}
-
-// Test if R is running
-sv.r.test = function sv_RTest () {
-	var res = "";
-	res = sv.socket.rCommand("<<<h>>>cat('ok!');", false,
-		sv_RTest_callback);
-	return res;
-}
-
-sv.r.test_callback = function sv_RTest_callback (response) {
-	var wasRRunning = sv.r.running;
-	// In the case of http server, we got a more complex object!
-	if (response.result !== undefined) response = response.result;
-	var isRRunning = (response == "ok!");
-
-	sv.r.running = isRRunning;
-	if (wasRRunning != isRRunning) {
-		if (isRRunning) {
-			// Remove message in the statusbar
-			ko.statusBar.AddMessage("", "SciViews-K");
-			sv.socket.rUpdate();
-			// Possibly refresh the GUI by running SciViews-specific
-			// R task callbacks and make sure R Objects pane is updated
-			sv.r.evalCallback("try(guiRefresh(force = TRUE), silent = TRUE)",
-				function () { sv.r.objects.getPackageList(true); });
-		}
-		//xtk.domutils.fireEvent(window, 'r_app_started_closed');
-		// PhG: currently disabled: all menus enabled all the time!
-		//window.updateCommands('r_app_started_closed');
-		sv.log.debug("R state changed: " + wasRRunning + "->" + isRRunning);
-	}
-}
-
-//// Print some text (command or results) in the local R console
-sv.r.print = function (text, newline, command, partial) {
-	// Default values for optional arguments
-	if (newline === undefined) newline = true;
-	if (command === undefined) command = false;
-	if (partial === undefined) partial = false;
-	
-	// For now, use the command output pane
-	if (command) { // This is a R command
-		if (partial) {
-			sv.cmdout.message("R waits for more input...", 0, true);
-		} else { // This is a new command
-			sv.cmdout.clear();
-			sv.cmdout.message("R is calculating... " +
-				"(if it takes too long, switch to the R console:" +
-				" it could be waiting for some input)!", 0, true);
-			text = ":> " + text;	
-		}
-	} else { // This is some data returned by R
-		if (!partial) sv.cmdout.message("R is ready!", 0, false);
-	}
-	sv.cmdout.append(text, newline);
-}
-
-// Evaluate code in R
-sv.r.eval = function (cmd) {
-	// If R is not running, start it now
-	if (!sv.r.running) {
-		// Indicate R should be started
-		ko.statusBar.AddMessage(
-			sv.translate("R must be started for this command (R -> Start R)"),
-			"SciViews-K", 5000, true);
-		return(null);
-	}
-	cmd = cmd.rtrim();
-	// Special case for q() and quit() => use sv.r.quit() instead
-	if (cmd.search(/^(?:base::)?q(?:uit)?\s*\(\s*\)$/) > -1)
-		return(sv.r.quit());
-	// TODO: special cases for ? and ??
-	var res = "";
-	sv.r.print(cmd, true, true, sv.socket.partial);
-	res = sv.socket.rCommand('<<<e>>>' + cmd);
-	return(res);
-}
-// Test: sv.r.eval("ls()");
-
-// Evaluate code in R in a hidden way
-sv.r.evalHidden = function (cmd, earlyExit) {
-	// If R is not running, do nothing
-	if (!sv.r.running) return(null);
-	var preCode = "<<<h>>>";
-	if (earlyExit) preCode = "<<<H>>>";
-	// Evaluate a command in hidden mode (contextual help, calltip, etc.)
-	var res = sv.socket.rCommand(preCode + cmd, false);
-	return(res);
-}
-// Tests:
-//sv.r.evalHidden("Sys.sleep(5); cat('done\n')");
-//sv.r.evalHidden("Sys.sleep(5); cat('done\n')", earlyExit = true);
-//sv.r.evalHidden("Sys.sleep(3); cat('done\n');" +
-//   " koCmd('alert(\"koCmd is back\");')", earlyExit = true);
-
-// Evaluate R expression and call procfun in Komodo with the result as argument
-// all additional arguments will be passed to procfun,
-// result will be stored in procfun.value
-sv.r.evalCallback = function (cmd, procfun) {
-	// If R is not running, do nothing
-	if (!sv.r.running) {
-		// Indicate R should be started
-		ko.statusBar.AddMessage(
-			sv.translate("R must be started for this command (R -> Start R)"),
-			"SciViews-K", 5000, true);
-		return(null);
-	}
-	var res = "";
-	// Evaluate a command in hidden mode (contextual help, calltip, etc.)
-	// and call 'procfun' at the end of the evaluation
-	// Note: with http using RJSONp protocol, this is done automatically!
-	// Note2: sv.r.evalCallback now needs a named function for the http
-	// version to work!
-	// Treatment is different if we use http or socket
-	var args = Array.apply(null, arguments);
-	args.splice(0, 1, "<<<h>>>" + cmd, false);
-	res = sv.socket.rCommand.apply(sv.socket, args);
-	return(res);
-}
-
-// Escape R calculation
-sv.r.escape = function (cmd) {
-	if (cmd === undefined) cmd = "";
-	
-	// If R is not running, do nothing
-	if (!sv.r.running) return(null);
-	
-	// Send an <<<esc>>> sequence that breaks multiline mode
-	sv.r.print("<command cancelled!>", false, false, false);
-	var res = "";
-	sv.socket.partial = false; // Reset this
-	res = sv.socket.rCommand('<<<esc>>>' + cmd, false);
-	return(res);
-}
-
-// Set the current working directory (to current buffer dir, or ask for it)
-sv.r.setwd = function (dir, ask, type) {
-	// TODO: simplify this:
-	// for compatibility with previous versions
-	switch (arguments.length) {
-	 case 1:
-		type = dir;
-		dir = null;
-		ask = false;
-		break;
-	 case 2:
-		type = dir;
-		dir = null;
-		break;
-	 default:
-	}
-
-	var getDirFromR = "";
-
-	if (!dir || (sv.tools.file.exists(dir) == 2)) { // Not there or unspecified
-		//sv.log.debug(dir + ":" + type)
-		checkType:
-		switch (type) {
-		 case "this":
-			break;
-		 case "session":
-			getDirFromR = "getOption(\"R.initdir\")";
-			break;
-		 case "previous":
-			getDirFromR = "if (exists(\".odir\")) .odir else getwd()";
-			break;
-		 case "init":
-			getDirFromR = "getOption(\"R.initdir\")";
-			break;
-		 case "current":
-			getDirFromR = "getwd()";
-			ask = true;	// Assume ask is always true in this case
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/sciviews -r 345


More information about the Sciviews-commits mailing list