[Sciviews-commits] r180 - komodo/SciViews-K/content/js pkg/svMisc/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 26 12:18:47 CEST 2009


Author: prezez
Date: 2009-08-26 12:18:41 +0200 (Wed, 26 Aug 2009)
New Revision: 180

Modified:
   komodo/SciViews-K/content/js/commands.js
   komodo/SciViews-K/content/js/sciviews.js
   pkg/svMisc/R/Complete.R
Log:
Small mods to svMisc::Complete, sv.getTextRange("codefrag") and sv.command.

Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js	2009-08-23 15:14:29 UTC (rev 179)
+++ komodo/SciViews-K/content/js/commands.js	2009-08-26 10:18:41 UTC (rev 180)
@@ -34,8 +34,6 @@
 	clearInterval(sv.r.testInterval);
 	if (!stopMe) {
 		sv.r.testInterval = window.setInterval(sv.r.test, 10000);
-	} else {
-		clearInterval(sv.r.testInterval);
 	}
 	setTimeout(window.updateCommands, 1000, 'r_app_started_closed');
 }
@@ -183,7 +181,7 @@
 		var observerSvc = Components.classes["@mozilla.org/observer-service;1"]
 			.getService(Components.interfaces.nsIObserverService);
 		observerSvc.removeObserver(this, 'status_message');
-		
+
 		sv.log.debug("R has been closed. Command was: " + this.command);
 
 		sv.r.running = false;
@@ -198,7 +196,7 @@
 	// using this needs solving an issue of running R in some terminals on linux
 	// (mac?) that send terminate signal right after start.
 
-	var viewManager = ko.views.viewManager;
+	var vmProto = ko.views.viewManager.prototype;
 
 	var cmdsIfRRunning = ['OpenPkgManager', 'BrowseWD', 'quit_R', 'update_charset'];
 	var cmdsIfRNotRunning = ['start_R'];
@@ -212,9 +210,9 @@
 
 	function _setCommandCtrl1 (arr, fun, pfx) {
 		pfx = "is_cmd_" + pfx;
-		for (var i in cmdsIfRRunning) {
-			viewManager.prototype[pfx + arr[i] + "_supported"] = fun;
-			viewManager.prototype[pfx + arr[i] + "_enabled"] = fun;
+		for (var i in arr) {
+			vmProto[pfx + arr[i] + "_supported"] = fun;
+			vmProto[pfx + arr[i] + "_enabled"] = fun;
 		}
 	}
 
@@ -225,70 +223,67 @@
 	_setCommandCtrl1(cmdsIfIsRViewAndSelection, _RControlSelection_supported,
 		"sv_R");
 
-	viewManager.prototype.do_cmd_sv_quit_R = function () {
-		sv.r.quit();
-	};
+	vmProto.do_cmd_sv_quit_R = function () {
+		sv.r.quit(); };
 
-	viewManager.prototype.do_cmd_sv_update_charset = function () {
+	vmProto.do_cmd_sv_update_charset = function () {
 		sv.socket.updateCharset(true);
-		sv.log.info(sv.translate("R uses \"%S\" encoding.",
+		window.setTimeout(function() {
+			sv.log.info(sv.translate("R uses \"%S\" encoding.",
 			sv.socket.charset));
+		}, 100);
 	};
 
 	_keepCheckingR();
 
+	// This is no longer necessary:
 	// 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)
-	viewManager.prototype.do_cmd_sv_RTriggerCompletion = function () {
-		sv.r.autoComplete();
-	};
+	//vmProto.do_cmd_sv_RTriggerCompletion = function () {
+	//	sv.r.complete();
+	//};
 
-	viewManager.prototype.do_cmd_sv_RRunLine = function () {
+	vmProto.do_cmd_sv_RRunLine = function () 	{
 		sv.r.send("line");
 	};
-
-	viewManager.prototype.do_cmd_sv_RRunAll = function () {
+	vmProto.do_cmd_sv_RRunAll = function ()		{
 		sv.r.send("all");
 	};
-	
-	viewManager.prototype.do_cmd_sv_RSourceAll = function () {
+	vmProto.do_cmd_sv_RSourceAll = function () 	{
 		sv.r.source("all");
 	};
-
-	viewManager.prototype.do_cmd_sv_RSourcePara = function () {
+	vmProto.do_cmd_sv_RSourcePara = function () {
 		sv.r.source("para");
 	};
-	
-	viewManager.prototype.do_cmd_sv_RRunPara = function () {
+
+	vmProto.do_cmd_sv_RRunPara = function () {
 		sv.r.send("para");
 	};
 
-	viewManager.prototype.do_cmd_sv_RRunSelection = function ()	{
+	vmProto.do_cmd_sv_RRunSelection = function ()	{
 		sv.r.send("sel");
 	};
-	
-	viewManager.prototype.do_cmd_sv_RSourceSelection = function () {
+
+	vmProto.do_cmd_sv_RSourceSelection = function () {
 		sv.r.source("sel");
 	};
-
-	viewManager.prototype.do_cmd_sv_RRunBlock = function ()	{
+	vmProto.do_cmd_sv_RRunBlock = function ()	{
 		sv.r.send("block");
 	};
-	
-	viewManager.prototype.do_cmd_sv_RSourceBlock = function () {
+
+	vmProto.do_cmd_sv_RSourceBlock = function () {
 		sv.r.source("block");
 	};
-
-	viewManager.prototype.do_cmd_sv_RRunFunction = function () {
+	vmProto.do_cmd_sv_RRunFunction = function () {
 		sv.r.send("function");
 	};
-	
-	viewManager.prototype.do_cmd_sv_RSourceFunction = function () {
+
+	vmProto.do_cmd_sv_RSourceFunction = function () {
 		sv.r.source("function");
 	};
 
-	viewManager.prototype.do_cmd_sv_start_R = function () {
+	vmProto.do_cmd_sv_start_R = function () {
 		// runIn = "command-output-window", "new-console",
 		// env strings: "ENV1=fooJ\nENV2=bar"
 		// gPrefSvc.prefs.getStringPref("runEnv");
@@ -359,7 +354,7 @@
 			//.getService(Components.interfaces.koIRunService);
 		//var Rapp = runSvc.RunAndNotify(command, cwd, env.join("\n"), null);
 		//ko.run.runCommand(window, command, cwd, env.join("\n"), false,
-		
+
 		ko.run.runCommand(window, command, cwd, env.join("\n"), false,
 			false, false, runIn, false, false, false);
 
@@ -387,6 +382,7 @@
 	//schemeNames = schemeNames.value;
 	var sch = keybindingSvc.getScheme(currentSchemeName);
 
+	var bindingRx = /[\r\n]+(# *SciViews|binding cmd_sv_.*)/g;
 	if (clearOnly != true) {
 		function _getSvKeys (data, pattern) {
 			if (!pattern) pattern = "";
@@ -404,7 +400,7 @@
 		var svKeysCurrent = _getSvKeys (sch.data, svCmdPattern);
 
 		// Temporarily delete sciviews keybindings
-		sch.data = sch.data.replace(/[\r\n]+(# *SciViews|binding cmd_sv_.*)/g, "");
+		sch.data = sch.data.replace(bindingRx, "");
 
 		// Check for key conflicts:
 		var svKeysCurrentOther = _getSvKeys (sch.data, "");
@@ -434,47 +430,23 @@
 			"SciViews keybindings have been updated in \"" +
 			currentSchemeName + "\" scheme.");
 	} else {
-		sch.data = sch.data.replace(/[\r\n]+(# *SciViews|binding cmd_sv_.*)/g, "");
+		sch.data = sch.data.replace(bindingRx, "");
 		sv.log.debug("SciViews keybindings have been cleared in \"" +
 			currentSchemeName + "\" scheme.");
 
 	}
 	sch.save();
 	sv.log.debug("You may need to restart Komodo.");
+
+	// A (temporary) hack to allow for R autocompletion/calltips to be triggered with the same key-shortcut
+	// as for other languages. cmd_sv_RTriggerCompletion will exit for files other than R
+	//var tpc_cmd = document.getElementById("cmd_triggerPrecedingCompletion");
+	//tpc_cmd.setAttribute("oncommand", [tpc_cmd.getAttribute("oncommand"),
+	//	"ko.commands.doCommandAsync('cmd_sv_RTriggerCompletion', event);"].join(";"));
+
 }
 
 }).apply(sv.command);
 
 addEventListener("load", sv.command.setControllers, false);
 addEventListener("load", sv.command.setKeybindings, false);
-
-/*
-
-//Useful garbage. delete it later.
-// command controllers template:
-vm.prototype.is_cmd_Test_supported
-vm.prototype.do_cmd_Test = function () { sv.alert("do_cmd_Test!"); }
-vm.prototype.is_cmd_Test_supported = function () {
-	sv.alert("is_cmd_Test_supported?:" +
-		ko.views.manager.currentView.document.language);
-	return(ko.views.manager.currentView.document.language == "R");
-}
-vm.prototype.is_cmd_Test_enabled = function () {
-	sv.alert("is_cmd_Test_enabled?");
-	return false;
-}
-
-// Commands should be put in a commandset, so they can be enabled only if lang = R
-document.getElementById("cmdset_view_or_language_changed")
-
-select,current_view_changed,language_changed
-var x = document.getElementById("cmdset_r_control")
-x.oncommandupdate = function oncommandupdate (event) {
-	ko.commands.updateCommandset(this);
-	sv.cmdout.append(ko.views.manager.currentView.document.language)
-}
-
-id="cmdset_r_control"
-current_view_language_changed
-
-*/

Modified: komodo/SciViews-K/content/js/sciviews.js
===================================================================
--- komodo/SciViews-K/content/js/sciviews.js	2009-08-23 15:14:29 UTC (rev 179)
+++ komodo/SciViews-K/content/js/sciviews.js	2009-08-26 10:18:41 UTC (rev 180)
@@ -49,10 +49,10 @@
 // sv.log.warn(msg);        // Log a warning
 // sv.log.warnStack(msg);   // Log a warning and print the calling stack
 // sv.log.info(msg);        // Log an info message (if sv.log.isAll() == true)
-// sv.log.debug(msg);       // Log a debug message (if sv.log.isAll() == true) 
+// sv.log.debug(msg);       // Log a debug message (if sv.log.isAll() == true)
 // sv.log.all(debug);       // Toggle logging of debug/info messages on/off
 // sv.log.isAll();          // Do we currently log all messages?
-// sv.log.show();           // Show the Komodo log file 
+// sv.log.show();           // Show the Komodo log file
 //
 // Not used any more?
 // sv.checkToolbox(); // Check that the correct SciViews-K toolbox is installed
@@ -296,11 +296,10 @@
 	   pEnd = ke.textLength;
 	   break;
     case "codefrag":
-        // This is used by calltip and completion. It takes 10 lines up from
-        // the current position (should be enough for this purpose)
-        var lineUp = curLine - 10;
-        if (lineUp < 0) lineUp = 0;
-        pStart = ke.positionFromLine(lineUp);
+        // This is used by calltip and completion. Returns all text backwards from current
+		// position to the beginning of the current folding level
+        pStart = ke.positionFromLine(ke.getFoldParent(curLine));
+
 	case "all":
 	default:
 	   // Take everything
@@ -698,7 +697,7 @@
     this.logger.info(msg);
 }
 
-sv.log.debug = function (msg) { 
+sv.log.debug = function (msg) {
     this.logger.debug(msg);
 }
 
@@ -706,7 +705,7 @@
     if (typeof(debug) == "undefined" || debug == false) {
         this.logger.setLevel(false);
     } else {
-        this.logger.setLevel(true); 
+        this.logger.setLevel(true);
     }
 }
 
@@ -732,7 +731,7 @@
 //sv.log.all(false);
 //alert(sv.log.isAll());
 //try {
-//   test = nonexistingvar; 
+//   test = nonexistingvar;
 //} catch(e) {sv.log.exception(e, "Test it exception"); }
 //sv.log.critical("Test it critical");
 //sv.log.error("Test it error");
@@ -808,4 +807,4 @@
 
 // Ensure we check the toolbox is installed once the extension is loaded
 //addEventListener("load", function() {setTimeout (sv.checkToolbox, 5000) }, false);
-//addEventListener("load", sv.checkToolbox, false);
\ No newline at end of file
+//addEventListener("load", sv.checkToolbox, false);

Modified: pkg/svMisc/R/Complete.R
===================================================================
--- pkg/svMisc/R/Complete.R	2009-08-23 15:14:29 UTC (rev 179)
+++ pkg/svMisc/R/Complete.R	2009-08-26 10:18:41 UTC (rev 180)
@@ -111,7 +111,12 @@
 	if (!length(completions)) return(invisible(""))
 
 	# remove weird object names (useful when the token starts with ".")
-    completions <- completions[!grepl("^[.]__[[:alpha:]]__", completions)]
+    # line below causes error on ubuntu: could not find function "grepl". older R version?
+	#completions <- completions[!grepl("^[.]__[[:alpha:]]__", completions)]
+    i <- grep("^[.]__[[:alpha:]]__", completions)
+	if (length(i) > 0)
+		completions <- completions[-i]
+
     if (!length(completions)) return(invisible(""))
 
 	fguess <- ComplEnv$fguess
@@ -120,9 +125,9 @@
 		completions <- completions[!(completions %in% ComplEnv$funargs)]
 	if (!length(completions)) return(invisible(""))
 
-	i <- -grep("<-.+$", completions)
+	i <- grep("<-.+$", completions)
 	if (length(i) > 0)
-		completions <- completions[-grep("<-.+$", completions)]
+		completions <- completions[-i]
 
 	if (addition && triggerPos > 0L)
 		completions <- substring(completions, triggerPos + 1)
@@ -188,17 +193,17 @@
 
 			# This is the code added to utils:::inFunction()
 			wp2 <- rev(cumsum(temp$c[-(wp[1L]:nrow(temp))]))
+			suffix <- sub("^\\s+", "", suffix, perl = TRUE)
 			# TODO: simplify this:
 			if (length(wp2)) {
-				funargs <- strsplit(sub("^\\s+", "", suffix, perl = TRUE),
-					"\\s*[\\(\\)][\\s,]*", perl = TRUE)[[1]]
+				funargs <- strsplit(suffix,	"\\s*[\\(\\)][\\s,]*", perl = TRUE)[[1]]
 				funargs <- paste(funargs[wp2 == 0], collapse = ",")
 			} else {
 				funargs <- suffix
 			}
-			funargs <- strsplit(funargs, " *, *")[[1]]
-			funargs <- unname(sapply(funargs, sub, pattern = " *=.*$",
-				replacement = utils:::.CompletionEnv$options$funarg.suffix))
+			funargs <- strsplit(funargs, "\\s*,\\s*", perl=TRUE)[[1]]
+			funargs <- unname(sapply(funargs, sub, pattern = "\\s*=.*$",
+				replacement = utils:::.CompletionEnv$options$funarg.suffix, perl=TRUE))
 			assign("funargs", funargs, utils:::.CompletionEnv)
 			# ... addition ends here
 



More information about the Sciviews-commits mailing list