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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue May 4 02:44:48 CEST 2010


Author: prezez
Date: 2010-05-04 02:44:48 +0200 (Tue, 04 May 2010)
New Revision: 265

Modified:
   komodo/SciViews-K/content/js/commands.js
   komodo/SciViews-K/content/js/pref-R.js
   komodo/SciViews-K/content/js/prefs.js
   komodo/SciViews-K/content/js/sciviews.js
   komodo/SciViews-K/content/overlayMain.xul
Log:
sv.prefs.checkAll - new function to restore default preferences.
Lock file 00LOCK now removed before R is called from within startR.
Re-enabled command updating, but only for document/language changed events, should cause no more problems (I hope).
Local retrieval of CRAN_mirrors list was broken. Many other changes. Removed unused/old pieces of code.
R-application lookup still not always work. Tested only on Win7 and Ubuntu. Please check on Mac!



Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js	2010-05-03 13:35:33 UTC (rev 264)
+++ komodo/SciViews-K/content/js/commands.js	2010-05-04 00:44:48 UTC (rev 265)
@@ -3,9 +3,6 @@
 // Copyright (c) 2009, K. Barton & Ph. Grosjean (phgrosjean at sciviews.org)
 // License: MPL 1.1/GPL 2.0/LGPL 2.1
 ////////////////////////////////////////////////////////////////////////////////
-// sv.command.getRApp(event);  	// Select a preferred R application in the list
-// sv.command.setMenuRApp(el); 	// Set up 'R application' submenu (checked item
-								// and hide incompatible items.
 // sv.command.startR();			// Start the preferred R app and connect to it
 // TODO: sv.command.quitR(saveWorkspace)
 // sv.command.openPkgManager(); // Open the package manager window
@@ -76,7 +73,9 @@
 	}
 
 	function _isRRunning () {
-		return sv.r.running;
+		//TODO: temporary solution
+		return true;
+		//return sv.r.running;
 	}
 
 	function _RControl_supported () {
@@ -103,12 +102,33 @@
 	"sciviewsk at sciviews.org", "defaults");
 	var cmd = sv.prefs.getString("svRApplication");
 
+
+	// PhG: there is a bug in the way R starts: at the begining, a dummy '00LOCK'
+	// file is created that prevents to config another R process as SciViews socket
+	// server. Everytime svStart.R is run, it looks if this '00LOCK' file exists,
+	// and if it finds it, it refuses to configure R as a socket server.
+	// OK, but what happens if the config of the SciViews R server fails in the
+	// middle of the process? Well, '00LOCK' is not removed, and it is not possible
+	// any more to configure R (automatically) as a SciViews socket server.
+	// To cope with this problem, I make sure '00LOCK' is deleted everytime the
+	// SciViews-K plugin is loaded in Komodo Edit. That way, restarting Komodo
+	// solves the problem of the remaining '00LOCK' file, in case R failed...
+
+	// KB: The '00LOCK' semaphore is used mainly to prevent infinite loop when
+	// R restarts after installing missing libraries (as it is done in svStart).
+	// So, it should be ok to delete it everytime user chooses a command to
+	// start R from Komodo.
+	try {
+		var lockFile = sv.tools.file.getfile(cwd, "00LOCK");
+		if (lockFile.exists())	lockFile.remove(true);
+	} catch(e) { }
+
+
 	// trim just in case
 	var path = sv.tools.strings.trim(sv.prefs.getString("svRDefaultInterpreter"));
 
 	// PhG: on Mac OS X, R.app is not a file, but a dir!!!
-	//if (!path || (sv.tools.file.exists(path) != sv.tools.file.TYPE_FILE)) {
-	if (!path || (sv.tools.file.exists(path) < 1)) {
+	if (!path || (sv.tools.file.exists(path) == sv.tools.file.TYPE_NONE)) {
 	    if(ko.dialogs.okCancel(
 		sv.translate("Default R interpreter is not (correctly) set in " +
 			     "Preferences. Do you want to do it now?"),
@@ -124,8 +144,8 @@
 	//.getService(Components.interfaces.koIOs);
 	//path = os.path.dirname(path);
 	//if (path) path += os.sep;
-	var Quiet = " ";
-	if (sv.prefs.getString("svRQuiet")) Quiet = "--quiet ";
+	var Quiet = sv.prefs.getString("svRQuiet")? "--quiet " : " ";
+
 	cmd = cmd.replace("%Path%", path).replace("%cwd%", cwd)
 		.replace("%title%", "SciViews-R").replace("%quiet%", Quiet);
 
@@ -169,10 +189,15 @@
 			break;
 		default:
 	}
+	//sv.cmdout.append("Running '" + cmd + "' in " + runIn + " / preferredRApp is" + preferredRApp);
+	//return;
 
 	ko.run.runCommand(window, cmd, cwd, env.join("\n"), false,
 		false, false, runIn, false, false, false);
 
+
+
+
 	//return cmd + "\n" + runIn;
 
 	// Register observer of application termination.
@@ -244,94 +269,6 @@
 		}
 	}
 
-	// Selects the checkbox on selected element, while deselecting others
-	this.getRApp = function (event) {
-		var el = event.originalTarget;
-		var siblings = el.parentNode.childNodes;
-		for (var i = 0; i < siblings.length; i++) {
-			try {
-				siblings[i].setAttribute("checked", siblings[i] == el);
-			} catch(e) {}
-		}
-		// This will preserve the selection
-		el.parentNode.setAttribute('selected',  el.id);
-		// Set the preference string
-		sv.prefs.setString("sciviews.preferredRApp", el.id, true);
-
-		document.getElementById("cmd_sv_start_R").setAttribute("label",
-			sv.translate("Start R") + " (" + el.getAttribute('label') + ")");
-	}
-
-	// Selects checkbox on the 'preferred R application' menu on its first
-	// display and hides unsupported commands
-	// It is triggered on popupshowing event, onload would be better,
-	// but it is for compatibility with Komodo 4 which doesn't support onload()
-	this.setMenuRApp = function (el) {
-		var selected = el.getAttribute('selected');
-		var siblings =  el.childNodes;
-
-		var isLinux = navigator.platform.toLowerCase().indexOf("linux") > -1;
-		var isMac = navigator.platform.toLowerCase().indexOf("mac") > -1;
-		var isWin = navigator.platform.toLowerCase().indexOf("win") == 0;
-
-		var validPlatforms, showItem;
-		var platform = navigator.platform;
-		for (var i = 0; i < siblings.length; i++) {
-			try {
-				validPlatforms = siblings[i].getAttribute("platform").
-					split(/[,\s]+/);
-				showItem = false;
-				for (var j in validPlatforms) {
-					if (platform.indexOf(validPlatforms[j]) > -1) {
-						// On linux, try to determine which terminals are
-						// not available and remove these items from menu
-
-						var appName = siblings[i].getAttribute("app");
-						if (isLinux || isWin) {
-							appName = appName.split(/[, ]+/);
-							var res = true;
-							for (var k in appName)
-							    res = res && !!sv.tools.file.whereIs(appName[k]);
-
-
-							if (res) {
-								showItem = true;
-								break;
-							}
-						} else if (isMac) {
-							// Check that we find the application
-							if (appName == "R" || sv.tools.file.exists(appName)) {
-								showItem = true;
-								break;
-							}
-						}
-					}
-				}
-
-				siblings[i].setAttribute("hidden", !showItem);
-				if (showItem) {
-					sv.log.debug("R application supported: " +
-						siblings[i].getAttribute("app"));
-					siblings[i].setAttribute("checked",
-						siblings[i].id == selected);
-				}
-			} catch(e) {
-				sv.log.exception(e, "Error looking for R apps in setMenuRApp");
-			}
-		}
-
-		// Set the preference string
-		sv.prefs.setString("sciviews.preferredRApp", selected, false);
-
-		document.getElementById("cmd_sv_start_R").setAttribute("label",
-			sv.translate("Start R") + " (" + document.getElementById(selected).
-				getAttribute('label') + ")"
-		);
-
-		// We do not need to run it anymore
-		el.removeAttribute("onpopupshowing");
-	}
-
 	this.openPkgManager = function () {
 		var win = _getWindowRef("chrome://sciviewsk/content/RPkgManager.xul",
 					"RPkgMgr",
@@ -468,16 +405,17 @@
 
 // PhG: currently, all menu items remain enabled, because this feature
 //      does not work well, and menus are sometimes disabled when they shouldn't be!
+
+// KB: temporarily _isRRunning always == true so items are disabled only if current language is not R
+
 		//_setCommandCtrl1(cmdsIfRRunning, _isRRunning, "sv_");
 		//_setCommandCtrl1(cmdsIfRNotRunning, function() {
 		//	return !_isRRunning()}, "sv_");
-		//_setCommandCtrl1(cmdsIfIsRView, _RControl_supported, "sv_R");
-		//_setCommandCtrl1(cmdsIfIsRViewAndSelection,
-		//	_RControlSelection_supported, "sv_R");
+		_setCommandCtrl1(cmdsIfIsRView, _RControl_supported, "sv_R");
+		_setCommandCtrl1(cmdsIfIsRViewAndSelection,
+			_RControlSelection_supported, "sv_R");
 
-		vmProto.do_cmd_sv_quit_R = function () {
-			sv.r.quit();
-		};
+		vmProto.do_cmd_sv_quit_R = function () sv.r.quit();
 
 		vmProto.do_cmd_sv_update_charset = function () {
 			sv.socket.updateCharset(true);
@@ -491,60 +429,22 @@
 		//rather than continously
 		//_keepCheckingR();
 
-		// This is no longer needed:
-		// To run it with the same key as autocompletion with other languages
-		// command "cmd_triggerPrecedingCompletion" is replaced in XUL
-		// ko.commands.doCommandAsync('cmd_sv_RTriggerCompletion', event)
-		//vmProto.do_cmd_sv_RTriggerCompletion = function () {
-		//	sv.r.complete();
-		//};
 
-		vmProto.do_cmd_sv_RRunLine = function () {
-			sv.r.send("line");
-		};
-		vmProto.do_cmd_sv_RRunAll = function ()	{
-			sv.r.send("all");
-		};
-		vmProto.do_cmd_sv_RSourceAll = function () {
-			sv.r.source("all");
-		};
-		vmProto.do_cmd_sv_RSourcePara = function () {
-			sv.r.source("para");
-		};
-		vmProto.do_cmd_sv_RRunPara = function () {
-			sv.r.send("para");
-		};
-		vmProto.do_cmd_sv_RRunSelection = function () {
-			sv.r.send("sel");
-		};
-
-		vmProto.do_cmd_sv_RSourceSelection = function () {
-			sv.r.source("sel");
-		};
-
-		vmProto.do_cmd_sv_RRunLineOrSelection = function () {
-			sv.r.send("line/sel");
-		};
-
-		vmProto.do_cmd_sv_RSourceLineOrSelection = function () {
-			sv.r.source("line/sel");
-		};
-
-		vmProto.do_cmd_sv_RRunBlock = function () {
-			sv.r.send("block");
-		};
-		vmProto.do_cmd_sv_RSourceBlock = function () {
-			sv.r.source("block");
-		};
-		vmProto.do_cmd_sv_RRunFunction = function () {
-			sv.r.send("function");
-		};
-		vmProto.do_cmd_sv_RSourceFunction = function () {
-			sv.r.source("function");
-		};
-		vmProto.do_cmd_sv_start_R = function () {
-			sv.command.startR();
-		};
+		vmProto.do_cmd_sv_RRunLine = function() sv.r.send("line");
+		vmProto.do_cmd_sv_RRunAll = function()	sv.r.send("all");
+		vmProto.do_cmd_sv_RSourceAll = function() sv.r.source("all");
+		vmProto.do_cmd_sv_RSourcePara = function()	sv.r.source("para");
+		vmProto.do_cmd_sv_RRunPara = function() sv.r.send("para");
+		vmProto.do_cmd_sv_RRunSelection = function() sv.r.send("sel");
+		vmProto.do_cmd_sv_RSourceSelection = function() sv.r.source("sel");
+		vmProto.do_cmd_sv_RRunLineOrSelection = function() sv.r.send("line/sel");
+		vmProto.do_cmd_sv_RSourceLineOrSelection =
+			function() sv.r.source("line/sel");
+		vmProto.do_cmd_sv_RRunBlock = function() sv.r.send("block");
+		vmProto.do_cmd_sv_RSourceBlock = function() sv.r.source("block");
+		vmProto.do_cmd_sv_RRunFunction = function() sv.r.send("function");
+		vmProto.do_cmd_sv_RSourceFunction = function() sv.r.source("function");
+		vmProto.do_cmd_sv_start_R = function() sv.command.startR();
 	}
 
 // Code below is for extra items in editor context menu (eg. "run selection"),
@@ -585,15 +485,9 @@
 		//gKeybindingMgr.currentScheme.name
 		var currentSchemeName = sv.prefs.getString("keybinding-scheme");
 
-		// Perhaps this should be redone for each scheme?
-		//var currentSchemeName = "Default";
-		//var schemeNames = {};
-		//keybindingSvc.getSchemeNames(schemeNames, {});
-		//schemeNames = schemeNames.value;
 		var sch = keybindingSvc.getScheme(currentSchemeName);
 
 		//gKeybindingMgr.parseConfiguration
-
 		var bindingRx = /[\r\n]+(# *SciViews|binding cmd_sv_.*)/g;
 		if (clearOnly != true) {
 			function _getSvKeys (data, pattern) {
@@ -615,9 +509,8 @@
 			// Temporarily delete SciViews keybindings
 			sch.data = sch.data.replace(bindingRx, "");
 
-
-			//var usedbys = this.usedBy([keysequence]);
 			// Check for key conflicts
+			//var usedbys = this.usedBy([keysequence]);
 			var svKeysCurrentOther = _getSvKeys (sch.data, "");
 			var currKeyArr = [];
 			for (var k in svKeysCurrentOther)

Modified: komodo/SciViews-K/content/js/pref-R.js
===================================================================
--- komodo/SciViews-K/content/js/pref-R.js	2010-05-03 13:35:33 UTC (rev 264)
+++ komodo/SciViews-K/content/js/pref-R.js	2010-05-04 00:44:48 UTC (rev 265)
@@ -106,10 +106,10 @@
 	PrefR_menulistSetValue(document.getElementById("svRApplication"),
 		os.path.basename(prefExecutable), "app",  "R");
 	document.getElementById("svRDefaultInterpreter").value = prefExecutable;
-	
+
 	if (!PrefR_UpdateCranMirrors(true))
 		PrefR_UpdateCranMirrors(false);
-	
+
 	menuListSetValues();
 	PrefR_svRApplicationUpdate(null);
 	parent.hPrefWindow.onpageload();
@@ -140,7 +140,7 @@
 		sv.r.eval('options(OutDec = "' + outDec + '", ' +
 			'OutSep = "' + outSep + '")', true);
 	}
-	
+
 	menuListGetValues();
 	return true;
 }
@@ -156,7 +156,7 @@
 	//      switch from R in /usr/bin to R.app in /Applications and vice versa
 	// So, we must start with a reasonable default directory for the application
 	// as it can be defined automatically...
-	// And even, for some applications, one cannot change it (disable 'Browse')!	
+	// And even, for some applications, one cannot change it (disable 'Browse')!
 	//var os = Components.classes['@activestate.com/koOs;1']
 	//	.getService(Components.interfaces.koIOs);
 	//var path = os.path.normpath(os.path.dirname(
@@ -179,10 +179,10 @@
 	var sel = el.selectedItem;
 	var data = sel.getAttribute(prefattribute);
 	var cmdfield = document.getElementById('R_command');
-	
+
 	var svRDefaultInterpreter = document
 		.getElementById("svRDefaultInterpreter").value;
-	
+
 	// Check if svRDefaultInterpreter exists on disk
 	if (!sv.tools.file.exists(svRDefaultInterpreter)) {
 		// Indicate the problem in the command...
@@ -190,14 +190,14 @@
 			"' not found!";
 		return false;
 	}
-	
+
 	var Quiet = " ";
 	if (document.getElementById("svRQuiet")
 		.getAttribute("checked") == "true") Quiet = "--quiet ";
 
 	var cwd = sv.tools.file.path("ProfD", "extensions",
 		"sciviewsk at sciviews.org", "defaults");
-	
+
 	// PhG: note that the path here is now the full path, application included!
 	data = data.replace("%Path%", svRDefaultInterpreter)
 		.replace("%title%", "SciViews-R").replace("%cwd%", cwd)
@@ -215,7 +215,7 @@
 		path = document.getElementById("svRDefaultInterpreter").value;
 		// Special treatment for the .app items: open the parent directory!
 		var defpath = path;
-		if (path.match(/\.app$/) == ".app") defpath = os.path.dirname(path); 
+		if (path.match(/\.app$/) == ".app") defpath = os.path.dirname(path);
 		path = ko.filepicker.openExeFile(defpath);
 	}
 
@@ -232,7 +232,8 @@
 		return(appName);
 	}
 	// 2) Try to locate the application
-	var appPath = sv.tools.file.whereIs(appName)
+	//TODO: use basename here?
+	var appPath = sv.tools.file.whereIs(appName);
 	if (appPath != null) {
 		return(appPath);
 	}
@@ -243,7 +244,7 @@
 		return(appName);
 	} else {
 		// Not found? What else can I do?
-		return("?");
+		return(null);
 	}
 }
 
@@ -329,14 +330,16 @@
 			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", csvName));
+									   "../../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) {
-				if (sv_file.exists(localPaths[i])) {
-					csvContent = sv_file.read(localPaths[i]);
+				file = sv_file.getfile(localPaths[i], csvName);
+				if (file.exists()) {
+					csvContent = sv_file.read(file.path);
 					//sv.cmdout.append("Read from: " + localPaths[i]);
 					break;
 				}
@@ -356,10 +359,15 @@
 		var name, url, item;
 		for (i in arrData) {
 			item = arrData[i];
-			if (item[colOK] == "1") {
+			if (item[colOK] == "1"
+				// fix for broken entries:
+				&& (item[colURL].search(/^(f|ht)tp:\/\//) === 0)
+				) {
 				arrData[i] = [item[colName], item[colURL]];
 			}
 		}
+		// Add main server at the beginning:
+		arrData.unshift(["Main CRAN server", "http://cran.r-project.org/"]);
 	}
 	if (!arrData)	return false;
 

Modified: komodo/SciViews-K/content/js/prefs.js
===================================================================
--- komodo/SciViews-K/content/js/prefs.js	2010-05-03 13:35:33 UTC (rev 264)
+++ komodo/SciViews-K/content/js/prefs.js	2010-05-04 00:44:48 UTC (rev 265)
@@ -13,6 +13,61 @@
 
 if (typeof(sv.prefs) == 'undefined') sv.prefs = new Object();
 
+//This can be used in the Preferences page to set/restore missing values:
+//sv.prefs.checkAll()
+
+// sv.prefs.defaults[preferenceName] = preferenceValue
+sv.prefs.defaults = {
+	"sciviews.server.socket": "7052",
+	"sciviews.client.socket": "8888",
+	"sciviews.client.id": "SciViewsK",
+	"sciviews.server.host": "127.0.0.1",
+	svRDefaultInterpreter: "", //????
+	svRApplication: "", //????
+	svRApplicationId: "", //????
+	svRQuiet: "", //must be string, otherwise sv.prefs.getString will fail
+	"r.csv.dec.arg": ".",  // TODO: change name, it is not only "csv"
+	"r.csv.sep.arg": ",",
+	CRANMirror: "http://cran.r-project.org/",
+	RHelpCommand: "javascript:sv.r.help(\"%w\")"
+
+	//*Future preferences:*
+	//sciviews.rhelp.open_in = [tab, window]
+	//sciviews.r.auto-start
+};
+
+
+// Set default preferences:
+sv.prefs.checkAll = function(revert) {
+	var prefset = Components.classes['@activestate.com/koPrefService;1']
+		.getService(Components.interfaces.koIPrefService).prefs;
+	for (var i in sv.prefs.defaults) {
+		var el;
+		var p = sv.prefs.defaults[i];
+		switch(typeof(p)) {
+			case "number":
+				el = (parseInt(p) == p)? "Long" : "Double";
+				break;
+			case "boolean":
+				el = "Boolean";
+				break;
+			case "string":
+			default:
+				el = "String";
+				p = p.toString();
+		}
+		if (revert // take all
+			|| !prefset.hasPref(i) // if missing at all
+			|| (prefset["has" + el + "Pref"](i)    // has one of right type, but empty
+				&& !prefset["get" + el + "Pref"](i))
+		) {
+			prefset.deletePref(i); // To avoid _checkPrefType error
+			prefset["set" + el + "Pref"](i, p);
+		};
+	}
+}
+
+
 // Get a string preference, or default value
 sv.prefs.getString = function (pref, def) {
 	var prefsSvc = Components.classes["@activestate.com/koPrefService;1"].
@@ -70,18 +125,14 @@
 }
 
 //// Preferences (default values, or values reset on each start) ///////////////
+
 // Define default socket ports for the client and server, and other parameters
-sv.prefs.setString("sciviews.server.socket", "7052", false);
-sv.prefs.setString("sciviews.client.socket", "8888", false);
-sv.prefs.setString("sciviews.client.id", "SciViewsK", false);
-sv.prefs.setString("sciviews.server.host", "127.0.0.1", false);
+// R interpreter
+sv.prefs.checkAll(false);
 
-// R interpreter
-sv.prefs.setString("svRDefaultInterpreter", "", false);
-sv.prefs.setString("svRApplication", null, false);
-sv.prefs.setString("svRQuiet", false, false);
+
 var svRDefaultInterpreter = sv.prefs.getString("svRDefaultInterpreter", "");
-
+//TODO: Rework this with respect to Mac and R.app
 // Default R interpreter Id: use a reasonable default, given the platform
 if (navigator.platform.indexOf("Win") === 0) {
 	sv.prefs.setString("svRApplicationId", "r-gui", false);
@@ -95,9 +146,9 @@
 }
 sv.prefs.setString("svRDefaultInterpreter", svRDefaultInterpreter, false);
 
-sv.prefs.setString("CRANMirror", "http://cran.r-project.org/", false);
-sv.prefs.setString("RHelpCommand", "javascript:sv.r.help(\"%w\")", false);
 
+
+
 // This is required by sv.helpContext() for attaching help to snippets (hack!)
 // Create empty preference sets to be used with snippet help system hack
 // [[%pref:R-help:value]] which displays nothing when the snippet is used
@@ -148,6 +199,7 @@
 sv.prefs.mru("factor2", true, "");
 sv.prefs.mru("blockFactor", true, "");
 
+
 //// (re)initialize a series of MRU for snippets' %ask constructs //////////////
 // TODO: defaultMRU for ts, data, table, ...
 

Modified: komodo/SciViews-K/content/js/sciviews.js
===================================================================
--- komodo/SciViews-K/content/js/sciviews.js	2010-05-03 13:35:33 UTC (rev 264)
+++ komodo/SciViews-K/content/js/sciviews.js	2010-05-04 00:44:48 UTC (rev 265)
@@ -13,17 +13,17 @@
 // Various functions defined in the 'sv' namespace directly
 // sv.alert(header, text); // Own alert box; text is optional
 // sv.getTextRange(what, gotoend, select);  // Get a part of text in the buffer,
-                                            // but do not operate on selection
+// but do not operate on selection
 // sv.fileOpen(directory, filename, title, filter, multiple); // file open dlg,
-            // more customizable replacement for ko.filepicker.open()
+// more customizable replacement for ko.filepicker.open()
 
 // sv.browseURI(URI, internal); // Show URI in internal or external browser
 // sv.showFile(path, readonly); // Show a file in Komodo, possibly as read-only
 // sv.helpURL(URL); // Display URL help in the default browser
 // sv.helpContext(); // Get contextual help for selected word in buffer in R or
-                     // for active snippet in toolbox/project (see Help context)
+// for active snippet in toolbox/project (see Help context)
 // sv.translate(textId); // translate messages using data from
-						 // chrome://sciviewsk/locale/main.properties
+// chrome://sciviewsk/locale/main.properties
 //
 // SciViews-K Command Output management ('sv.cmdout' namespace) ////////////////
 // sv.cmdout.append(str, newline, scrollToStart); // Append to Command Output
@@ -33,8 +33,8 @@
 // SciViews-K logging feature ('sv.log' namespace) /////////////////////////////
 // sv.log.logger;           // The SciViews-K Komodo logger object
 // sv.log.exception(e, msg, showMsg); // Log an exception with error message
-                            // and stack. If showMsg == true, also display the
-                            // msg in an alert box (optional)
+// and stack. If showMsg == true, also display the
+// msg in an alert box (optional)
 // sv.log.critical(msg);    // Log a critical error
 // sv.log.error(msg);       // Log an error
 // sv.log.warn(msg);        // Log a warning
@@ -48,6 +48,19 @@
 // Not used any more?
 // sv.checkToolbox(); // Check that the correct SciViews-K toolbox is installed
 
+/*
+FIXME: A loose list:
+Key conflicts in toolbox: (to be removed/changed to unused combinations in SciViews toolbox)
+*Run function (Ctrl+Shift+F) conflicts with "Find in Files..."
+*Run paragraph (Ctrl+Shift+H) <--> "Replace in Files..."
+*Run line and hit enter (Ctrl+Return) <--> "Insert Newline (no favors)"
+*Working dir (current file): F7 <--> "Run marked block"
+*In toolbox: Ctrl+Shift+M (toolbox) and F7 (menu) both defined for "Run marked block"
+*Object structure (Ctrl+Shift+T) <--> Reopen the Last Closed Tab
+*Session in my documents... (Ctrl+Shift+S) <--> Save As... (This one is quite important!)
+
+*/
+
 ////////////////////////////////////////////////////////////////////////////////
 
 // This function is used to tag strings to be translated in projects/toolbox
@@ -62,13 +75,13 @@
 // IMPORTANT: now sv.version is a "X.X.X" string, and sv.checkVersion accepts only such format
 // please update all macros using sv.checkVersion
 sv.version = Components.classes["@mozilla.org/extensions/manager;1"]
-				.getService(Components.interfaces.nsIExtensionManager)
-				.getItemForID("sciviewsk at sciviews.org").version;
+	.getService(Components.interfaces.nsIExtensionManager)
+	.getItemForID("sciviewsk at sciviews.org").version;
 sv.showVersion = true;
 
 sv._compareVersion = function (a, b) {
-    if (!a)	return -1;
-    if (!b)	return 1;
+	if (!a)	return -1;
+	if (!b)	return 1;
 
 	// try is necessary only till I find where is that damn macro causing an error
 	// at startup (-;
@@ -81,14 +94,14 @@
 		for (k in a) {
 			if (k < b.length) {
 				if (a[k] > b[k])
-					return 1;
+				return 1;
 				else if (a[k] < b[k])
-					return -1;
+				return -1;
 			} else {
 				return 1;
 			}
 		}
-	   return (b.length > a.length)? -1 : 0;
+		return (b.length > a.length)? -1 : 0;
 	} catch(e) {
 		return 1;
 	}
@@ -97,18 +110,18 @@
 sv.checkVersion = function (version) {
 	if (sv._compareVersion(sv.version, version) < 0) {
 		var text = sv.translate(
-"One or more macros require the SciViews-K plugin %S, " +
-"but currently installed version is %S. You should update it." +
-"Would you like to open the extension manager and check for updates now?",
-version, this.version);
+		"One or more macros require the SciViews-K plugin %S, " +
+		"but currently installed version is %S. You should update it." +
+		"Would you like to open the extension manager and check for updates now?",
+		version, this.version);
 
 		var sYes = sv.translate("Yes");
 		var res = ko.dialogs.yesNo(sv.translate("Outdated SciViews-K extension"),
-			sYes, text, "SciViews-K");
+		sYes, text, "SciViews-K");
 		if (res == sYes) 	ko.launch.openAddonsMgr();
 		return(false);
 	} else
-		return(true);
+	return(true);
 }
 
 
@@ -146,29 +159,28 @@
 	// By default, we keep current selection
 
 	if (what == "line/sel")
-		what = (pStart == pEnd)? "line" : "sel";
+	what = (pStart == pEnd)? "line" : "sel";
 
 	switch(what) {
-	case "sel":
-	   // Simply retain current selection
-	   break;
-	case "word":
-	   if (pStart == pEnd) { // only return word if no selection
+		case "sel":
+		// Simply retain current selection
+		break;
+		case "word":
+		if (pStart == pEnd) { // only return word if no selection
 			if (!includeChars && currentView.languageObj.name == "R")
-				includeChars = ".";
+			includeChars = ".";
 
 			var wordChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_" + includeChars;
 
 			function wordCharTest(s) {
 				return (s.charCodeAt(0) > 0x80) ||
-					wordChars.indexOf(s) > -1;
+				wordChars.indexOf(s) > -1;
 			}
 
-
 			for (pStart = scimoz.positionBefore(curPos);
 				 (pStart > 0) && wordCharTest(scimoz.getWCharAt(pStart));
-				 pStart = scimoz.positionBefore(pStart)) {
-				};
+			pStart = scimoz.positionBefore(pStart)) {
+			};
 
 			// PhG: correction for infinite loop if the name is at the beginning
 			// of the document
@@ -178,27 +190,19 @@
 
 			for (pEnd = scimoz.currentPos;
 				 (pEnd < scimoz.length) && wordCharTest(scimoz.getWCharAt(pEnd));
-				 pEnd = scimoz.positionAfter(pEnd)) {
+			pEnd = scimoz.positionAfter(pEnd)) {
 			}
+		}
+		break;
+		case "function":
+		// tricky one: select an entire R function
+		// this should work even with extremely messy coded ones.
 
-			// TODO: this should be set for every R document by default. but how?
-			//if (includeChars) {
-			//	var wordChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + includeChars;
-			//	scimoz.setWordChars(wordChars);
-			//}
-			//pStart = scimoz.wordStartPosition(curPos, true);
-			//pEnd = scimoz.wordEndPosition(curPos, true);
-	   }
-	   break;
-	case "function":
-	   // tricky one: select an entire R function
-	   // this should work even with extremely messy coded ones.
-
 		// function declaration pattern:
 		var funcRegExStr = "\\S+\\s*(<-|=)\\s*function\\s*\\(";
 
 		var findSvc = Components.classes['@activestate.com/koFindService;1']
-			 .getService(Components.interfaces.koIFindService);
+		.getService(Components.interfaces.koIFindService);
 
 		// save previous find settings
 		var oldFindPref = {searchBackward: true, matchWord: false,
@@ -217,8 +221,8 @@
 			//  search for function pattern backwards:
 			findSvc.options.searchBackward = true;
 			findRes = findSvc.find("", // view.document.displayPath
-									scimoz.text, funcRegExStr,
-									scimoz.charPosAtPosition(pos0), 0); //start, end
+			scimoz.text, funcRegExStr,
+			scimoz.charPosAtPosition(pos0), 0); //start, end
 			if (!findRes) break;
 
 			// function declaration start:
@@ -231,9 +235,9 @@
 			// find first character following the closing brace
 			findSvc.options.searchBackward = false;
 			findRes = findSvc.find("",  //view.document.displayPath
-									scimoz.text, "\\S",
-									scimoz.charPosAtPosition(pos2) + 1,
-									scimoz.charPosAtPosition(scimoz.length));
+			scimoz.text, "\\S",
+			scimoz.charPosAtPosition(pos2) + 1,
+			scimoz.charPosAtPosition(scimoz.length));
 			if (!findRes) break;
 
 			//  beginning of the function body:
@@ -244,7 +248,7 @@
 
 			// get first line of the folding block:
 			firstLine = (scimoz.getFoldParent(lineBodyStart) != lineArgsStart)?
-				lineBodyStart : lineArgsStart;
+			lineBodyStart : lineArgsStart;
 
 			// get end of the function body
 			if (scimoz.getWCharAt(pos3 - 1) == "{") {
@@ -253,9 +257,9 @@
 				pos4 = scimoz.getLineEndPosition(lineBodyStart);
 			}
 
-		// repeat if selected function does not embrace cursor position and if
-		// there are possibly any functions enclosing it:
-		} while (pos4 < curPos && scimoz.getFoldParent(lineArgsStart) != -1);
+			// repeat if selected function does not embrace cursor position and if
+			// there are possibly any functions enclosing it:
+			} while (pos4 < curPos && scimoz.getFoldParent(lineArgsStart) != -1);
 
 		if (pos4 >= curPos) {
 			pStart = pos0;
@@ -265,8 +269,8 @@
 		// restore previous find settings
 		for (var i in oldFindPref) findSvc.options[i] = oldFindPref[i];
 
-	   break;
-	case "block":
+		break;
+		case "block":
 		// Select all content between two bookmarks
 		var Mark1, Mark2;
 		Mark1 = scimoz.markerPrevious(curLine, 64);
@@ -277,51 +281,51 @@
 		pStart = scimoz.positionFromLine(Mark1);
 		pEnd = scimoz.getLineEndPosition(Mark2);
 
-	   break;
-	case "para":
-	   // Select the entire paragraph
-	   // go up from curLine until
-	   for (var i = curLine; i >= 0
-			&& scimoz.lineLength(i) > 0
-			&& scimoz.getTextRange(
-			   pStart = scimoz.positionFromLine(i),
-			   scimoz.getLineEndPosition(i)).trim() != "";
-			i--) {		}
+		break;
+		case "para":
+		// Select the entire paragraph
+		// go up from curLine until
+		for (var i = curLine; i >= 0
+		&& scimoz.lineLength(i) > 0
+		&& scimoz.getTextRange(
+		pStart = scimoz.positionFromLine(i),
+		scimoz.getLineEndPosition(i)).trim() != "";
+		i--) {		}
 
-	   for (var i = curLine; i <= scimoz.lineCount
-			&& scimoz.lineLength(i) > 0
-			&& scimoz.getTextRange(scimoz.positionFromLine(i),
-			   pEnd = scimoz.getLineEndPosition(i)).trim() != "";
-			i++) {		}
+		for (var i = curLine; i <= scimoz.lineCount
+		&& scimoz.lineLength(i) > 0
+		&& scimoz.getTextRange(scimoz.positionFromLine(i),
+		pEnd = scimoz.getLineEndPosition(i)).trim() != "";
+		i++) {		}
 
-	   break;
-	case "line":
-		 // Select whole current line
+		break;
+		case "line":
+		// Select whole current line
 		pStart = scimoz.positionFromLine(curLine);
 		pEnd = scimoz.getLineEndPosition(curLine);
-	   break;
-	case "linetobegin":
-	   // Select line content from beginning to anchor
-	   pStart = scimoz.positionFromLine(curLine);
-	   break;
-	case "linetoend":
-	   // Select line from anchor to end of line
-	   pEnd = scimoz.getLineEndPosition(curLine);
-	   break;
-	case "end":
-	   // take text from current line to the end
-	   pStart = scimoz.positionFromLine(curLine);
-	   pEnd = scimoz.textLength;
-	   break;
-    case "codefrag":
+		break;
+		case "linetobegin":
+		// Select line content from beginning to anchor
+		pStart = scimoz.positionFromLine(curLine);
+		break;
+		case "linetoend":
+		// Select line from anchor to end of line
+		pEnd = scimoz.getLineEndPosition(curLine);
+		break;
+		case "end":
+		// take text from current line to the end
+		pStart = scimoz.positionFromLine(curLine);
+		pEnd = scimoz.textLength;
+		break;
+		case "codefrag":
         // This is used by calltip and completion. Returns all text backwards from current
 		// position to the beginning of the current folding level
         pStart = scimoz.positionFromLine(scimoz.getFoldParent(curLine));
-	case "all":
-	default:
-	   // Take everything
-	   text = scimoz.text;
-	}
+		case "all":
+		default:
+		// Take everything
+		text = scimoz.text;
+		}
 
 	if (what != "all") {
 		text = scimoz.getTextRange(pStart, pEnd).replace(/(^[\n\r]+|[\n\r]+$)/, "");
@@ -336,40 +340,40 @@
 		range.value = {start: pStart, end: pEnd};
 	}
 	return(text);
-}
+	}
 
 // file open dialog, more customizable replacement for ko.filepicker.open
 sv.fileOpen = function (directory, filename, title, filter, multiple, save,
-						filterIndex) {
+filterIndex) {
 	const nsIFilePicker = Components.interfaces.nsIFilePicker;
     var fp = Components.classes["@mozilla.org/filepicker;1"]
-        .createInstance(nsIFilePicker);
+	.createInstance(nsIFilePicker);
 
 	//Dialog should get default system title
     //if (!title) title = sv.translate(save? "Save file" : "Open file");
 
 	var mode;
 	if (!save)
-	    mode = multiple? nsIFilePicker.modeOpenMultiple : nsIFilePicker.modeOpen;
+	mode = multiple? nsIFilePicker.modeOpenMultiple : nsIFilePicker.modeOpen;
 	else
-		mode = nsIFilePicker.modeSave;
+	mode = nsIFilePicker.modeSave;
 
     fp.init(window, title, mode);
 
 	if (typeof filterIndex != "undefined")
-		fp.filterIndex = (typeof filterIndex == "object")?
-			filterIndex.value : filterIndex;
+	fp.filterIndex = (typeof filterIndex == "object")?
+	filterIndex.value : filterIndex;
 
 	var filters = [];
 
 	if (filter) {
         if (typeof(filter) == "string")
-            filter = filter.split(',');
+		filter = filter.split(',');
         var fi;
         for (var i = 0; i  < filter.length; i++) {
             fi = filter[i].split("|");
             if (fi.length == 1)
-                fi[1] = fi[0];
+			fi[1] = fi[0];
             fp.appendFilter(fi[0], fi[1]);
 			filters.push(fi[1]);
         }
@@ -379,12 +383,12 @@
 
     if (directory) {
         var lf = Components.classes["@mozilla.org/file/local;1"].
-            createInstance(Components.interfaces.nsILocalFile);
+		createInstance(Components.interfaces.nsILocalFile);
         lf.initWithPath(directory);
         fp.displayDirectory = lf;
     }
     if (filename)
-        fp.defaultString = filename;
+	fp.defaultString = filename;
 
     var rv = fp.show();
     if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
@@ -394,7 +398,7 @@
             path = new Array();
             while (files.hasMoreElements()) {
                 var file = files.getNext().
[TRUNCATED]

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


More information about the Sciviews-commits mailing list