[Sciviews-commits] r451 - in komodo: . SciViews-K/components SciViews-K/content SciViews-K/content/js SciViews-K/content/js/tools SciViews-K-dev/content/js

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Feb 27 07:18:16 CET 2012


Author: phgrosjean
Date: 2012-02-27 07:18:16 +0100 (Mon, 27 Feb 2012)
New Revision: 451

Modified:
   komodo/SciViews-K-dev/content/js/pref-R.js
   komodo/SciViews-K/components/koRLinter.py
   komodo/SciViews-K/components/koR_UDL_Language.py
   komodo/SciViews-K/content/RHelpWindow.xul
   komodo/SciViews-K/content/js/pref-R.js
   komodo/SciViews-K/content/js/socket.js
   komodo/SciViews-K/content/js/tools/file.js
   komodo/SciViews-K/content/pref-R.xul
   komodo/TODO
Log:
Incorporation of changes in SciViews-K-dev into SciViews-K (part III)

Modified: komodo/SciViews-K/components/koRLinter.py
===================================================================
--- komodo/SciViews-K/components/koRLinter.py	2012-02-26 22:58:05 UTC (rev 450)
+++ komodo/SciViews-K/components/koRLinter.py	2012-02-27 06:18:16 UTC (rev 451)
@@ -36,7 +36,7 @@
 # 
 # ***** END LICENSE BLOCK *****
 
-from xpcom import components, nsError, COMException
+from xpcom import components, nsError, COMException, ServerException
 from xpcom._xpcom import PROXY_SYNC, PROXY_ALWAYS, PROXY_ASYNC
 from koLintResult import *
 from koLintResults import koLintResults
@@ -45,7 +45,11 @@
 import string
 import process
 import koprocessutils
+import logging
 
+log = logging.getLogger('RLinter')
+#log.setLevel(logging.DEBUG)
+
 # R error line format with svTools:::koLint(..., type = "flat")
 # warning|error+++line+++column+++error message\n
 

Modified: komodo/SciViews-K/components/koR_UDL_Language.py
===================================================================
--- komodo/SciViews-K/components/koR_UDL_Language.py	2012-02-26 22:58:05 UTC (rev 450)
+++ komodo/SciViews-K/components/koR_UDL_Language.py	2012-02-27 06:18:16 UTC (rev 451)
@@ -36,6 +36,7 @@
 
 import logging
 from koUDLLanguageBase import KoUDLLanguage
+from xpcom import components #, nsError, COMException, ServerException
 
 
 log = logging.getLogger("koRLanguage")
@@ -53,8 +54,9 @@
     _reg_desc_ = "%s Language" % name
     _reg_contractid_ = "@activestate.com/koLanguage?language=%s;1" % name
     _reg_clsid_ = "{4cc23d3b-52e2-426d-8a22-6d7eb2ba81ae}"
+    _reg_categories_ = [("komodo-language", name)]
     defaultExtension = '.R'
-
+    primary = 1
     lang_from_udl_family = {
         'SSL': 'R'
     }

Modified: komodo/SciViews-K/content/RHelpWindow.xul
===================================================================
--- komodo/SciViews-K/content/RHelpWindow.xul	2012-02-26 22:58:05 UTC (rev 450)
+++ komodo/SciViews-K/content/RHelpWindow.xul	2012-02-27 06:18:16 UTC (rev 451)
@@ -33,7 +33,10 @@
  ***** END LICENSE BLOCK ***** -->
 
 <!DOCTYPE overlay PUBLIC "-//MOZILLA//DTD XUL V1.0//EN"
-"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+	"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" [
+	<!ENTITY % textcontext SYSTEM "chrome://global/locale/textcontext.dtd">
+	%textcontext;
+]>
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 <?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
@@ -50,10 +53,12 @@
 <window
   id="RHelpWindow" title="R Help"
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-  width="700" height="500"
+  width="700" height="500" screenX="20" screenY="20"
   persist="screenX screenY width height"
   style="min-height: 400px; min-width: 300px;">
 
+	<script type="application/javascript"
+		src="chrome://global/content/globalOverlay.js"/>
 	<script type="text/javascript">
 	<![CDATA[
 		var sv;
@@ -227,6 +232,7 @@
 			el.setAttribute("disabled", nothingSelected);
 			document.getElementById("cmd_run_r_code").setAttribute("disabled", nothingSelected);
 		
+			goUpdateCommand("cmd_copy");
 		}
 		
 		function runSelAsRCode () {
@@ -283,6 +289,7 @@
 			var cmd = "";
 			// Use only one type of connection for both client and server!
 			//if (sv.r.server == "http") {
+			// TODO: this is reworked in SciViews-K-dev => look what's there!!!
 			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";
@@ -340,6 +347,12 @@
 						break;
 					}
 				}
+				if (!sv) {
+					var wm = Components.classes['@mozilla.org/appshell/window-mediator;1']
+						.getService(Components.interfaces.nsIWindowMediator);
+					var win = wm.getMostRecentWindow("Komodo");
+					sv = win.sv;
+				}
 			}
 		
 			rHelpTopic = document.getElementById("rhelp-topic");
@@ -446,15 +459,26 @@
 			label="Run as R code" desc="Execute selected text in R" accesskey="r" />
 	  <command id="cmd_rsearch_for" oncommand="rHelpSearch(sv.tools.strings.trim(window._content.getSelection().toString()));"
 			label="Search R for selection" desc="Search R for selected text" accesskey="S" />
+		<command id="cmd_copy" oncommand="goDoCommand('cmd_copy')" disabled="true"/>
+		<command id="cmd_selectAll" oncommand="goDoCommand('cmd_selectAll')"/>
 	</commandset>
 
 	<popupset>
 		<menupopup id="rHelpBrowserContext"
 			onpopupshowing="rHelpBrowserContextOnShow(event);">
 			<menuitem id="menu_cmd_run_r_code"
-				command="cmd_run_r_code" acceltext="Ctrl+R"/>
+				command="cmd_run_r_code" acceltext="Ctrl+Shift+R"/>
 			<menuitem id="menu_cmd_rsearch_for"
 				command="cmd_rsearch_for"/>
+			
+			<menuseparator />
+		
+			<menuitem id="context-copy"
+				label="&copyCmd.label;" accesskey="&copyCmd.accesskey;"
+				command="cmd_copy" disabled="true"/>
+			<menuitem id="context-selectall"
+				label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;"
+				command="cmd_selectAll"/>
 		</menupopup>
 	</popupset>
 
@@ -483,6 +507,9 @@
 					<menuitem id="rhelp-menu-cran" label="CRAN"
 						accesskey="c"
 						oncommand="go('@CRAN@');"/>
+					<menuitem id="rhelp-menu-vignettes" label="Browse vignettes"
+						accesskey="v"
+						oncommand="sv.r.eval('browseVignettes()');"/>
 					<menuitem id="rhelp-menu-wiki" label="R wiki"
 						accesskey="w"
 						oncommand="go('http://wiki.r-project.org/');"/>

Modified: komodo/SciViews-K/content/js/pref-R.js
===================================================================
--- komodo/SciViews-K/content/js/pref-R.js	2012-02-26 22:58:05 UTC (rev 450)
+++ komodo/SciViews-K/content/js/pref-R.js	2012-02-27 06:18:16 UTC (rev 451)
@@ -13,7 +13,7 @@
 // PrefR_OnLoad();                        // R preference window loaded
 // PrefR_editMenulist(el, value);         // Edit a list for a menu
 // PrefR_svRDefaultInterpreterOnSelect(event); // R app selected in the list
-// PrefR_svRApplicationUpdate(event);     // Update list of application
+// PrefR_svRApplicationOnSelect(event);   // Update list of application
 // PrefR_updateCommandLine(update);       // Update the command line label
 // PrefR_setExecutable(path);             // Set the path to the R executable
 // PrefR_UpdateCranMirrors(localOnly);    // Update the list of CRAN mirrors
@@ -34,9 +34,9 @@
 // List of supported R applications
 var apps = [
 	{id:"r-terminal", label:"in default terminal",
-		path:"\"%Path%\" %args%",
+		path:"x-terminal-emulator -e '%Path% %args%'",
         app:"R",
-		required:"R",
+		required:"x-terminal-emulator,R",
 		platform:"Lin,Mac"},
 	{id:"r-terminal", label:"in console window",
 		path:"\"%Path%\" %args%",
@@ -121,6 +121,9 @@
 			values = [];
 			for (var k = 0; k < el.itemCount; k++)
 				values.push(escape(el.getItemAtIndex(k).value));
+			values = sv.tools.array.unique(values);
+			var nMax = parseInt(el.getAttribute('maxValues'));
+			if(nMax > 0) values = values.slice(0, nMax);
 			el.setAttribute(attribute, values.join(" "));
 		}
 	}
@@ -138,7 +141,8 @@
      case "nt":
         rs = rs.concat(sv.tools.file.whereIs("Rgui"));
         rs = rs.concat(sv.tools.file.whereIs("R"));
-        break;
+        rs.sort(); rs.reverse();
+		break;
      case "mac":
 	 case "posix": // On Mac OS X, os.name is posix!!!
         rs = ["/Applications/R.app", "/Applications/R64.app",
@@ -157,6 +161,10 @@
     }
 
     rs = sv.tools.array.unique(rs);
+	if (rs.indexOf(prefExecutable) == -1) {
+		prefset.setStringPref('svRDefaultInterpreter', '');
+		rs.unshift('');
+	}
     menu.removeAllItems();
     for (var i in rs)
         menu.appendItem(rs[i], rs[i], null);
@@ -235,7 +243,8 @@
 	}
     
 	var app = os.path.basename(menuInterpreters.value);
-    if (apps[menuApplication.value].app != app) {
+    if (!(menuApplication.value in apps) ||
+		apps[menuApplication.value].app != app) {
         var i;
         for (i in apps)
 			if (apps[i].app == app) break;
@@ -244,15 +253,18 @@
     PrefR_updateCommandLine(true);
 }
 
-function PrefR_svRApplicationUpdate (event) {
+function PrefR_svRApplicationOnSelect (event) {
 	var menuApplication = document.getElementById("svRApplication");
     var menuInterpreters = document.getElementById("svRDefaultInterpreter");
-    var app = apps[menuApplication.value].app;
-	var sel = menuApplication.selectedItem;
+    if (!(menuApplication.value in apps)) return;
+	var app = apps[menuApplication.value].app;
+	//var sel = menuApplication.selectedItem;
 	var os = Components.classes['@activestate.com/koOs;1']
 		.getService(Components.interfaces.koIOs);
     if (os.path.basename(menuInterpreters.value) != app) {
-        var item;
+        //TODO: modify to use with:
+        //PrefR_menulistSetValue(menuInterpreters, value, "value", null);
+		var item;
         for (var i = 0; i <= menuInterpreters.itemCount; i++) {
             item = menuInterpreters.getItemAtIndex(i);
             if (item) {
@@ -269,7 +281,8 @@
 function PrefR_updateCommandLine (update) {
     var appId = document.getElementById("svRApplication").value;
     var appPath = document.getElementById("svRDefaultInterpreter").value;
-    var cmdArgs = document.getElementById("svRArgs").value;
+    if (!appId || !appPath) return("");
+	var cmdArgs = document.getElementById("svRArgs").value;
 	var args1 = "";
 
 	if (document.getElementById("sciviews.pkgs.sciviews").checked)
@@ -364,6 +377,7 @@
 		}
 	}
 	if (!csvContent && !arrData) return(false);
+	// TODO: Add error message when mirrors list cannot be obtained
 
 	if (!arrData) {
 		// Convert CSV string to Array
@@ -376,7 +390,7 @@
 		for (i in arrData) {
 			item = arrData[i];
 			if (item[colOK] == "1"
-				// fix for broken entries
+				// Fix for broken entries
 				&& (item[colURL].search(/^(f|ht)tp:\/\//) === 0)) {
 				arrData[i] = [item[colName], item[colURL]];
 			}
@@ -432,11 +446,14 @@
 			"SciViews-K preferences");
         return(false);
     }
-	prefset.setStringPref("r.csv.sep", outSep);
-	prefset.setStringPref("r.csv.dec", outDec);
-	if (sv.r.running) {
-		sv.r.evalHidden('options(OutDec = "' + outDec + '", ' +
-		'OutSep = "' + outSep + '")', true);
+	if (outDec != prefset.getStringPref('r.csv.dec')
+		|| outSep != prefset.getStringPref('r.csv.sep')) {
+		prefset.setStringPref("r.csv.sep", outSep);
+		prefset.setStringPref("r.csv.dec", outDec);
+		if (sv.r.running) {
+			sv.r.evalHidden('options(OutDec = "' + outDec + '", ' +
+			'OutSep = "' + outSep + '")', true);
+		}
 	}
 	
 	// Set the client type

Modified: komodo/SciViews-K/content/js/socket.js
===================================================================
--- komodo/SciViews-K/content/js/socket.js	2012-02-26 22:58:05 UTC (rev 450)
+++ komodo/SciViews-K/content/js/socket.js	2012-02-27 06:18:16 UTC (rev 451)
@@ -4,15 +4,20 @@
 // License: MPL 1.1/GPL 2.0/LGPL 2.1
 ////////////////////////////////////////////////////////////////////////////////
 //
-/////// Socket client //////
+/////// Socket client //////////////////////////////////////////////////////////
 // sv.clientType				// A global variable with 'http' or 'socket'
 // sv.socket.svSocketMinVersion // Minimum version of svSocket package required
 // sv.socket.svHttpMinVersion   // Minimum version of svHttp package required
 // sv.socket.partial	// In case of multiline mode, current command is partial
+// sv.socket.lastCmd	// Last command issued
+// sv.socket.charset	// Character set used by R
+// sv.socket.fromUnicode(str, charset);	// String conversion from unicode
+// sv.socket.toUnicode(str, charset);	// String conversion to unicode
 // sv.socket.rClientSocket(host, port, cmd, listener, echo, procname);
 // sv.socket.rClientHttp(host, port, cmd, listener, echo, procname);
+// sv.socket.rClient(host, port, cmd, listener, echo, procname);
 // 		Main client fonction, SciViews socket server and SciViews HTTP server)
-
+// sv.socket.setSocketType(type); // Set the socket type to use
 // sv.socket.rCommand(cmd, echo, procfun, ...); 	 	// Send cmd to R
 // sv.socket.rProcess(rjson);	// Default RJSONp function called back
 // sv.socket.rCommandSync(cmd); // A synchronous communication that is also
@@ -21,12 +26,12 @@
 //      adjusted according to these results.
 // sv.socket.rUpdate();								  	// Update R options
 //
-/////// Socket server //////
+/////// Socket server //////////////////////////////////////////////////////////
 // sv.serverType				// A global variable with 'file' or 'socket'
 // sv.socket.debug              // Debugging mode (in Command Output)
 // sv.socket.serverIsLocal      // Is the socket servicing only localhost?
-//
-// sv.socket.serverStart();     // Start the SciViews-K socket server
+// sv.socket.checkFile();       // The file version of the server
+// sv.socket.serverStart(port); // Start the SciViews-K socket server
 // sv.socket.serverStop();      // Stop the SciViews-K socket server
 // sv.socket.serverIsStarted;   // (read-only) Is the socket server started?
 // sv.socket.serverConfig();    // Get a short description of server config
@@ -53,777 +58,772 @@
 if (typeof(sv.socket) == 'undefined') sv.socket = {};
 
 (function () {
-
-var _this = this;
-
-/////// Socket client //////////////////////////////////////////////////////
-// svSocketMinVersion, partial and _converter are global variables
-// defined in svRinterpreter.js
-this.svSocketMinVersion = "0.9-52";// Min version of svSocket package required
-this.svHttpMinVersion = "0.9-52";  // Minimum version of svHttp package required
-this.partial = false;			   // Is the last command send to R partial?
-this.lastCmd = "";				   // Last command issued
-
-// String converter used between Komodo and R (localeToCharset()[1] in R)
-// PhG: not used any more because the conversion is now done in R
-//      I leave code there until it is completely debugged!
-var _converter = Components
-	.classes["@mozilla.org/intl/scriptableunicodeconverter"]
-	.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
-
-// Accessors to set/get charset
-this.__defineGetter__ ('charset', function () _converter.charset);
-this.__defineSetter__ ('charset', function (charset) {
-	// PhG: I eliminate the 'if' because sometimes the converter stops
-	// working, and it is reactivated only when it is reset => this is
-	// a temorary workaround to recover from that situation
-	//if (charset != _converter.charset)
-		try { _converter.charset = charset; } catch (e) { }
-	return(_converter.charset);
-});
-// Select reasonable defaults: ISO8859-1 on Windows, UTF-8 elsewhere
-if (navigator.platform.search(/Win\d+$/) === 0) {
-	this.charset = "ISO8859-1";
-} else {
-	this.charset = "UTF-8";	
-}
-
-// The conversion functions
-function _fromUnicode (str, charset) {
-	if (charset !== undefined && _this.charset != charset)
-		_this.charset = charset;
-	try {
-		if (_converter.charset)
-			str = _converter.ConvertFromUnicode(str) + _converter.Finish();
-	} catch(e) {
-		sv.log.exception(e, "sv.socket is unable to convert from Unicode to " +
-			_converter.charset + ". The message was " + str);
+	var _this = this;
+	
+	/////// Socket client //////////////////////////////////////////////////////
+	// svSocketMinVersion, partial and _converter are global variables
+	// defined in svRinterpreter.js
+	this.svSocketMinVersion = "0.9-52";// Min version of svSocket package required
+	this.svHttpMinVersion = "0.9-52";  // Minimum version of svHttp package required
+	this.partial = false;			   // Is the last command send to R partial?
+	this.lastCmd = "";				   // Last command issued
+	
+	// String converter used between Komodo and R (localeToCharset()[1] in R)
+	// PhG: not used any more because the conversion is now done in R
+	//      I leave code there until it is completely debugged!
+	var _converter = Components
+		.classes["@mozilla.org/intl/scriptableunicodeconverter"]
+		.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
+	
+	// Accessors to set/get charset
+	this.__defineGetter__ ('charset', function () _converter.charset);
+	this.__defineSetter__ ('charset', function (charset) {
+		// PhG: I eliminate the 'if' because sometimes the converter stops
+		// working, and it is reactivated only when it is reset => this is
+		// a temorary workaround to recover from that situation
+		//if (charset != _converter.charset)
+			try { _converter.charset = charset; } catch (e) { }
+		return(_converter.charset);
+	});
+	// Select reasonable defaults: ISO8859-1 on Windows, UTF-8 elsewhere
+	if (navigator.platform.search(/Win\d+$/) === 0) {
+		this.charset = "ISO8859-1";
+	} else {
+		this.charset = "UTF-8";	
 	}
-	return(str);
-}
-
-this.fromUnicode = function (str, charset)
-	_fromUnicode(str, charset);
-
-function _toUnicode (str, charset) {
-	if (charset !== undefined && _this.charset != charset)
-		_this.charset = charset;
-	try {
-		if (_converter.charset)
-			str = _converter.ConvertToUnicode(str);
-	} catch(e) {
-		sv.log.exception(e, "sv.socket is unable to convert to Unicode from " +
-			_converter.charset + ". The message was " + str);
+	
+	// The conversion functions
+	function _fromUnicode (str, charset) {
+		if (charset !== undefined && _this.charset != charset)
+			_this.charset = charset;
+		try {
+			if (_converter.charset)
+				str = _converter.ConvertFromUnicode(str) + _converter.Finish();
+		} catch(e) {
+			sv.log.exception(e, "sv.socket is unable to convert from Unicode to " +
+				_converter.charset + ". The message was " + str);
+		}
+		return(str);
 	}
-	return(str);
-}
-
-this.toUnicode = function (str, charset)
-	_toUnicode(str, charset);
-
-// The main socket client function to connect to R socket server
-this.rClientSocket = function (host, port, cmd, listener, echo, procname) {
-	// Workaround for NS_ERROR_OFFLINE returned by 'createTransport' when
-	// there is no network connection (when network goes down). Based on
-	// toggleOfflineStatus() in chrome://browser/content/browser.js.
-	if (!navigator.onLine) Components
-		.classes["@mozilla.org/network/io-service;1"]
-		.getService(Components.interfaces.nsIIOService2).offline = false;
-
-	try {
-		var transport = Components
-			.classes["@mozilla.org/network/socket-transport-service;1"]
-			.getService(Components.interfaces.nsISocketTransportService)
-			.createTransport(null, 0, host, port, null);
-
-		var outstream = transport.openOutputStream(0, 0, 0);
-		cmd = _fromUnicode(cmd);
-		// TODO: if procname != null, instruct to return a RJsonP result!
-		outstream.write(cmd, cmd.length);
-
-		var stream = transport.openInputStream(0, 0, 0);
-		var instream = Components
-			.classes["@mozilla.org/scriptableinputstream;1"]
-			.createInstance(Components.interfaces.nsIScriptableInputStream);
-		instream.init(stream);
-
-		var dataListener = {
-			data: "",
-			onStartRequest: function(request, context) { _this.data = ""; },
-			onStopRequest: function(request, context, status) {
-				instream.close();
-				stream.close()
-				outstream.close();
-				_this.data = sv.tools.strings.removeLastCRLF(_this.data);
-				listener.finished(_this.data);
-			},
-			onDataAvailable: function (request, context, inputStream,
-				offset, count) {
-				var chunk = _toUnicode(instream.read(count));
-
-				// Do we need to close the connection
-				// (\f received, followed by \n, \r, or both)?
-				if (chunk.match("\n\f") == "\n\f") {
+	
+	this.fromUnicode = function (str, charset)
+		_fromUnicode(str, charset);
+	
+	function _toUnicode (str, charset) {
+		if (charset !== undefined && _this.charset != charset)
+			_this.charset = charset;
+		try {
+			if (_converter.charset)
+				str = _converter.ConvertToUnicode(str);
+		} catch(e) {
+			sv.log.exception(e, "sv.socket is unable to convert to Unicode from " +
+				_converter.charset + ". The message was " + str);
+		}
+		return(str);
+	}
+	
+	this.toUnicode = function (str, charset)
+		_toUnicode(str, charset);
+	
+	// The main socket client function to connect to R socket server
+	this.rClientSocket = function (host, port, cmd, listener, echo, procname) {
+		// Workaround for NS_ERROR_OFFLINE returned by 'createTransport' when
+		// there is no network connection (when network goes down). Based on
+		// toggleOfflineStatus() in chrome://browser/content/browser.js.
+		if (!navigator.onLine) Components
+			.classes["@mozilla.org/network/io-service;1"]
+			.getService(Components.interfaces.nsIIOService2).offline = false;
+	
+		try {
+			var transport = Components
+				.classes["@mozilla.org/network/socket-transport-service;1"]
+				.getService(Components.interfaces.nsISocketTransportService)
+				.createTransport(null, 0, host, port, null);
+	
+			var outstream = transport.openOutputStream(0, 0, 0);
+			cmd = _fromUnicode(cmd);
+			// TODO: if procname != null, instruct to return a RJsonP result!
+			outstream.write(cmd, cmd.length);
+		
+			var stream = transport.openInputStream(0, 0, 0);
+			var instream = Components
+				.classes["@mozilla.org/scriptableinputstream;1"]
+				.createInstance(Components.interfaces.nsIScriptableInputStream);
+			instream.init(stream);
+	
+			var dataListener = {
+				data: "",
+				onStartRequest: function(request, context) { _this.data = ""; },
+				onStopRequest: function(request, context, status) {
 					instream.close();
-					stream.close();
+					stream.close()
 					outstream.close();
-					// Eliminate trailing (\r)\n\f chars before the prompt
-					// Eliminate the last carriage return after the prompt
-					chunk = chunk.replace(/(\r?\n\f|\s+$)/, "");
+					_this.data = sv.tools.strings.removeLastCRLF(_this.data);
+					listener.finished(_this.data);
+				},
+				onDataAvailable: function (request, context, inputStream,
+					offset, count) {
+					var chunk = _toUnicode(instream.read(count));
+	
+					// Do we need to close the connection
+					// (\f received, followed by \n, \r, or both)?
+					if (chunk.match("\n\f") == "\n\f") {
+						instream.close();
+						stream.close();
+						outstream.close();
+						// Eliminate trailing (\r)\n\f chars before the prompt
+						// Eliminate the last carriage return after the prompt
+						chunk = chunk.replace(/(\r?\n\f|\s+$)/, "");
+					}
+	
+					// Determine if we have a prompt at the end
+					if (chunk.search(/\+\s+$/) > -1) {
+						// If we just shift in partial mode, prepend command
+						chunk = chunk.rtrim() + " ";
+						var cmd = chunk;
+						if (!_this.partial)
+							cmd = _this.lastCmd + "\n";
+						_this.partial = true;
+						if (echo) sv.r.print(cmd, false, true, true);
+					} else if (chunk.search(/>\s+$/) > -1) {
+						_this.partial = false;
+						if (echo) sv.r.print(chunk, false, false, false);
+					} else if (echo) sv.r.print(chunk, false, false, true);
+					_this.data += chunk;
 				}
-
-				// Determine if we have a prompt at the end
-				if (chunk.search(/\+\s+$/) > -1) {
-					// If we just shift in partial mode, prepend command
-					chunk = chunk.rtrim() + " ";
-					var cmd = chunk;
-					if (!_this.partial)
-						cmd = _this.lastCmd + "\n";
-					_this.partial = true;
-					if (echo) sv.r.print(cmd, false, true, true);
-				} else if (chunk.search(/>\s+$/) > -1) {
-					_this.partial = false;
-					if (echo) sv.r.print(chunk, false, false, false);
-				} else if (echo) sv.r.print(chunk, false, false, true);
-				_this.data += chunk;
 			}
+	
+			var pump = Components
+				.classes["@mozilla.org/network/input-stream-pump;1"]
+				.createInstance(Components.interfaces.nsIInputStreamPump);
+			pump.init(stream, -1, -1, 0, 0, false);
+			pump.asyncRead(dataListener, null);
+		} catch (e) {
+			sv.log.exception(e,
+				"sv.socket.rClientSocket() raises an unknown error");
+			return(e);
 		}
-
-		var pump = Components
-			.classes["@mozilla.org/network/input-stream-pump;1"]
-			.createInstance(Components.interfaces.nsIInputStreamPump);
-		pump.init(stream, -1, -1, 0, 0, false);
-		pump.asyncRead(dataListener, null);
-	} catch (e) {
-		sv.log.exception(e,
-			"sv.socket.rClientSocket() raises an unknown error");
-		return(e);
+		return(null);
 	}
-	return(null);
-}
-
-// The main http client function to connect to R socket server
-this.rClientHttp = function (host, port, cmd, listener, echo, procname) {
-	// Workaround for NS_ERROR_OFFLINE returned by 'createTransport' when
-	// there is no network connection (when network goes down). Based on
-	// toggleOfflineStatus() in chrome://browser/content/browser.js.
-	if (!navigator.onLine) Components
-		.classes["@mozilla.org/network/io-service;1"]
-		.getService(Components.interfaces.nsIIOService2).offline = false;
-
-	try {
-		var httpRequest, url;
-		httpRequest = new XMLHttpRequest();
-		httpRequest.onprogress = function () {
-			sv.r.print(httpRequest.responseText, false, false, false);
-		};
-		httpRequest.onreadystatechange = function () {
-			try {
-				if (httpRequest.readyState == 4) {
-					// For reasons I don't know, R HTTP server version 2.11.1
-					// returns 500 instead of 200 upon correct completion of
-					// the command...
-					if (httpRequest.status == 200 | httpRequest.status == 500) {
-						var res = _toUnicode(httpRequest.responseText);
-						if (res.match("\n\f") == "\n\f") {
-							// Eliminate trailing (\r)\n\f before the prompt
-							res = res.replace(/(\r?\n\f|\s+$)/, "");
+		
+	// The main http client function to connect to R socket server
+	this.rClientHttp = function (host, port, cmd, listener, echo, procname) {
+		// Workaround for NS_ERROR_OFFLINE returned by 'createTransport' when
+		// there is no network connection (when network goes down). Based on
+		// toggleOfflineStatus() in chrome://browser/content/browser.js.
+		if (!navigator.onLine) Components
+			.classes["@mozilla.org/network/io-service;1"]
+			.getService(Components.interfaces.nsIIOService2).offline = false;
+	
+		try {
+			var httpRequest, url;
+			httpRequest = new XMLHttpRequest();
+			httpRequest.onprogress = function () {
+				sv.r.print(httpRequest.responseText, false, false, false);
+			};
+			httpRequest.onreadystatechange = function () {
+				try {
+					if (httpRequest.readyState == 4) {
+						// For reasons I don't know, R HTTP server version 2.11.1
+						// returns 500 instead of 200 upon correct completion of
+						// the command...
+						if (httpRequest.status == 200 | httpRequest.status == 500) {
+							var res = _toUnicode(httpRequest.responseText);
+							if (res.match("\n\f") == "\n\f") {
+								// Eliminate trailing (\r)\n\f before the prompt
+								res = res.replace(/(\r?\n\f|\s+$)/, "");
+							}
+	
+							// Determine if we have a prompt at the end
+							if (res.search(/\+\s+$/) > -1) {
+								res = res.rtrim() + " ";
+								// If we just shift in partial mode, prepend command
+								if (!_this.partial)
+									res = _this.lastCmd + "\n";
+								_this.partial = true;
+								if (echo) sv.r.print(res, false, true, true);
+							} else if (res.search(/>\s+$/) > -1) {
+								_this.partial = false;
+								if (echo) sv.r.print(res, false, false, false);
+							} else if (echo) sv.r.print(res, false, false, true);
+							// Finish command in case there is a callback
+							listener.finished(sv.tools.strings.removeLastCRLF(res));
+						} else if (httpRequest.status > 0) {
+							sv.log.error(
+								"sv.http.rCallback() got a communication error. " +
+								"Status: " + httpRequest.status);
+							return(httpRequest.status);
 						}
-
-						// Determine if we have a prompt at the end
-						if (res.search(/\+\s+$/) > -1) {
-							res = res.rtrim() + " ";
-							// If we just shift in partial mode, prepend command
-							if (!_this.partial)
-								res = _this.lastCmd + "\n";
-							_this.partial = true;
-							if (echo) sv.r.print(res, false, true, true);
-						} else if (res.search(/>\s+$/) > -1) {
-							_this.partial = false;
-							if (echo) sv.r.print(res, false, false, false);
-						} else if (echo) sv.r.print(res, false, false, true);
-						// Finish command in case there is a callback
-						listener.finished(sv.tools.strings.removeLastCRLF(res));
-					} else if (httpRequest.status > 0) {
-						sv.log.error(
-							"sv.http.rCallback() got a communication error. " +
-							"Status: " + httpRequest.status);
-						return(httpRequest.status);
 					}
+				} catch(e) {
+					sv.log.exception(e,
+						"sv.http.rCallback() raises an unknown error");
+					return(e);
 				}
-			} catch(e) {
-				sv.log.exception(e,
-					"sv.http.rCallback() raises an unknown error");
-				return(e);
+				return(null);
+			};
+				
+			// Too long URIs are considered to be > 2083 characters
+			// With percent encoding, one can triple required space
+			// => set a maximum to 600 characters in non-encoded strings
+			// For too long instructions (> 600 characters), or instructions that
+			// contain something else than plain ASCII, we write them in a file
+			// and pass 'SOURCE=<filepath>' as cmd. The new HTTP server in the R
+			// package svHttp should be able to deal with this new process.
+			if (cmd.length > 600 || /^[\000-\177]/.test(cmd)) {
+				var filename = "svHttpFile" + Math.floor(Math.random() * 65536)
+					.toString(36);
+				var tempFile = sv.tools.file.temp(filename);
+				// It seems that a carriage return is needed at the end,
+				// or the last line is not collected
+				cmd = cmd + "\n";
+				sv.tools.file.write(tempFile, cmd, "UTF-8", false);
+				tempFile = tempFile.addslashes();
+				cmd = "SOURCE=" + tempFile;
 			}
-			return(null);
-		};
+			
+			//url is http://<host>:<port>/custom/SciViews?<cmd>&<callback>
+			url = "http://" + host + ":" + port + "/custom/SciViews?" +
+				encodeURIComponent(_fromUnicode(cmd))
+			if (procname != null) url = url + "&" + procname;
+			httpRequest.open('GET', url, true);
+			httpRequest.setRequestHeader('Host', 'SciViews-K-Komodo');
+			//httpRequest.setRequestHeader('Accept-Charset', 'UTF-8');
+			//httpRequest.setRequestHeader('Accept-Encoding', 'UTF-8');
+			//httpRequest.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');
+			//httpRequest.setRequestHeader('Content-Transfer-Encoding', 'UTF-8');
+			//httpRequest.setRequestHeader('Transfer-Encoding', 'UTF-8');
+			//httpRequest.setRequestHeader('Keep-Alive', 'true');
+			//httpRequest.setRequestHeader('Connection', 'close');
+			httpRequest.send(''); // Try sending data!	
+		} catch (e) {
+			sv.log.exception(e, "sv.socket.rClientHttp() raises an unknown error");
+			return(e);
+		}
+		return(null);
+	}
 		
-		// Too long URIs are considered to be > 2083 characters
-		// With percent encoding, one can triple required space
-		// => set a maximum to 600 characters in non-encoded strings
-		// For too long instructions (> 600 characters), or instructions that
-		// contain something else than plain ASCII, we write them in a file
-		// and pass 'SOURCE=<filepath>' as cmd. The new HTTP server in the R
-		// package svHttp should be able to deal with this new process.
-		if (cmd.length > 600 || /^[\000-\177]/.test(cmd)) {
-			var filename = "svHttpFile" + Math.floor(Math.random() * 65536)
-				.toString(36);
-			var tempFile = sv.tools.file.temp(filename);
-			// It seems that a carriage return is needed at the end,
-			// or the last line is not collected
-			cmd = cmd + "\n";
-			sv.tools.file.write(tempFile, cmd, "UTF-8", false);
-			tempFile = tempFile.addslashes();
-			cmd = "SOURCE=" + tempFile;
+	this.rClient = function (host, port, cmd, listener, echo, procname) {
+		if (sv.clientType == "socket") {
+			res = this.rClientSocket(host, port, cmd, listener, echo, procname);
+		} else {
+			res = this.rClientHttp(host, port, cmd, listener, echo, procname)
 		}
+		return(res);
+	}
 		
-		//url is http://<host>:<port>/custom/SciViews?<cmd>&<callback>
-		url = "http://" + host + ":" + port + "/custom/SciViews?" +
-			encodeURIComponent(_fromUnicode(cmd))
-		if (procname != null) url = url + "&" + procname;
-		httpRequest.open('GET', url, true);
-		httpRequest.setRequestHeader('Host', 'SciViews-K-Komodo');
-		//httpRequest.setRequestHeader('Accept-Charset', 'UTF-8');
-		//httpRequest.setRequestHeader('Accept-Encoding', 'UTF-8');
-		//httpRequest.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');
-		//httpRequest.setRequestHeader('Content-Transfer-Encoding', 'UTF-8');
-		//httpRequest.setRequestHeader('Transfer-Encoding', 'UTF-8');
-		//httpRequest.setRequestHeader('Keep-Alive', 'true');
-		//httpRequest.setRequestHeader('Connection', 'close');
-		httpRequest.send(''); // Try sending data!
-
-	} catch (e) {
-		sv.log.exception(e, "sv.socket.rClientHttp() raises an unknown error");
-		return(e);
-	}
-	return(null);
-}
-
-this.rClient = function (host, port, cmd, listener, echo, procname) {
-	if (sv.clientType == "socket") {
-		res = this.rClientSocket(host, port, cmd, listener, echo, procname);
-	} else {
-		res = this.rClientHttp(host, port, cmd, listener, echo, procname)
-	}
-	return(res);
-}
-
-this.setSocketType = function (type) {
-	switch(type) {
-		case "http":
+	this.setSocketType = function (type) {
+		switch(type) {
+		 case "http":
 			_this.rClient = this.rClientHttp;
 			// Make sure sv.clientType is correct
 			sv.clientType = "http";
 			// For calltip and complete, I have something different
 			sv.prefs.setString("sciviews.client.currentType", "http");
 			break;
-
-		case "socket":
-		default:
+		 case "socket":
+		 default:
 			_this.rClient = this.rClientSocket;
 			// Make sure sv.clientType is correct
 			sv.clientType = "socket";
 			// For calltip and complete, I have something different
[TRUNCATED]

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


More information about the Sciviews-commits mailing list