[Sciviews-commits] r183 - in komodo/SciViews-K: . components content content/js pylib templates
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Sep 7 01:51:25 CEST 2009
Author: phgrosjean
Date: 2009-09-07 01:51:23 +0200 (Mon, 07 Sep 2009)
New Revision: 183
Added:
komodo/SciViews-K/content/js/misc.js
Modified:
komodo/SciViews-K/components/svRinterpreter.js
komodo/SciViews-K/content/js/commands.js
komodo/SciViews-K/content/js/prefs.js
komodo/SciViews-K/content/js/r.js
komodo/SciViews-K/content/js/sciviews.js
komodo/SciViews-K/content/js/socket.js
komodo/SciViews-K/content/overlayMain.xul
komodo/SciViews-K/pylib/lang_r.py
komodo/SciViews-K/sciviewsk-0.8.1-ko.xpi
komodo/SciViews-K/templates/.Rprofile
Log:
Various enhancements for better session support in R
Modified: komodo/SciViews-K/components/svRinterpreter.js
===================================================================
--- komodo/SciViews-K/components/svRinterpreter.js 2009-08-29 10:42:13 UTC (rev 182)
+++ komodo/SciViews-K/components/svRinterpreter.js 2009-09-06 23:51:23 UTC (rev 183)
@@ -85,7 +85,7 @@
// Send an <<<esc>>> sequence that breaks multiline mode
cmd = "";
prompt == ":> ";
- // TODO: change this! if (cmdout) { sv.cmdout.clear(); }
+ // TODO: put this only in sv.r.escape()! if (cmdout) { sv.cmdout.clear(); }
var listener = { finished: function(data) {} }
var res = rCommand('<<<esc>>>', false);
return(res);
Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js 2009-08-29 10:42:13 UTC (rev 182)
+++ komodo/SciViews-K/content/js/commands.js 2009-09-06 23:51:23 UTC (rev 183)
@@ -296,7 +296,7 @@
"SciViewsK"),
"koHost=localhost",
"koActivate=FALSE",
- "Rinitdir=" + sv.io.makePath(isWin? "Pers" : "Home"),
+ "Rinitdir=" + sv.prefs.getString("sciviews.session.dir", "~"),
"koServe=" + sv.prefs.getString("sciviews.client.socket", "8888"),
"koPort=" + sv.prefs.getString("sciviews.server.socket", "7052"),
"koAppFile=" + sv.io.makePath("CurProcD", ["komodo" + (isWin? ".exe" : "")])
@@ -339,6 +339,10 @@
env.push("Rid=R.app");
command = "open -a /Applications/R.app \"" + cwd + "\"";
break;
+ case "r64-app":
+ env.push("Rid=R64.app");
+ command = "open -a /Applications/R64.app \"" + cwd + "\"";
+ break;
default:
env.push("Rid=R");
command = "R --quiet";
@@ -357,7 +361,7 @@
ko.run.runCommand(window, command, cwd, env.join("\n"), false,
false, false, runIn, false, false, false);
-
+
// register observer of application termination.
this.rObserver = new AppTerminateObserver(command);
};
Added: komodo/SciViews-K/content/js/misc.js
===================================================================
--- komodo/SciViews-K/content/js/misc.js (rev 0)
+++ komodo/SciViews-K/content/js/misc.js 2009-09-06 23:51:23 UTC (rev 183)
@@ -0,0 +1,281 @@
+// SciViews-K miscellaneous functions
+// Define the 'sv.misc' namespace
+// Copyright (c) 2008-2009, Ph. Grosjean (phgrosjean at sciviews.org)
+// License: MPL 1.1/GPL 2.0/LGPL 2.1
+////////////////////////////////////////////////////////////////////////////////
+// sv.misc.closeAllOthers(); // Close all buffer except current one
+// sv.misc.colorPicker(); // Invoke a color picker dialog box
+// sv.misc.moveLineDown(); // Move current line down
+// sv.misc.moveLineUp(); // Move current line up
+// sv.misc.searchBySel(); // Search next using current selection
+// sv.misc.showConfig(); // Show Komodo configuration page
+// sv.misc.swapQuotes(); // Swap single and double quotes in selection
+// sv.misc.pathToClipboard(); // Copy file path to clipboard
+// sv.misc.unixPathToClipboard(); // Copy file path in UNIX format to clipboard
+// sv.misc.timeStamp(); // Stamp text with current date/time
+// sv.misc.delLine(); // Delete current line in buffer
+////////////////////////////////////////////////////////////////////////////////
+
+// Define the 'sv.misc' namespace
+if (typeof(sv.misc) == 'undefined')
+ sv.misc = {};
+
+// Close all buffers except current one (an start page)
+sv.misc.closeAllOthers = function () {
+ try {
+ var view = ko.views.manager.currentView;
+ if (view) {
+ var curr_uri = view.document.file.URI;
+ var views = ko.views.manager.topView.getDocumentViews(true);
+ for (var i = views.length - 1; i >= 0; i--) {
+ // Exclude the Start Page from "Close All".
+ var thisView = views[i];
+ if (thisView.getAttribute("type") != "startpage"
+ && thisView.document.file
+ && thisView.document.file.URI != curr_uri) {
+ if (! thisView.close()) {
+ return false;
+ }
+ }
+ }
+ }
+ } catch(e) {
+ sv.log.exception(e, "sv.misc.closeAllOthers() error");
+ }
+}
+
+/*
+ * JavaScript macro to provide a basic color picker for hexadecimal colors.
+ * Assign a useful keybinding to this macro and ka-zam, funky color picking!
+ *
+ * Version: 1.0
+ *
+ * Authored by: David Ascher
+ * Modified by: Shane Caraveo
+ * Todd Whiteman
+ * Philippe Grosjean
+ */
+sv.misc.colorPicker_system = function (color) {
+ var sysUtils = Components.classes['@activestate.com/koSysUtils;1'].
+ getService(Components.interfaces.koISysUtils);
+ if (!color)
+ color = "#000000";
+ newcolor = sysUtils.pickColor(color);
+ if (newcolor) {
+ var scimoz = ko.views.manager.currentView.scimoz;
+ scimoz.replaceSel(newcolor);
+ scimoz.anchor = scimoz.currentPos;
+ }
+}
+
+sv.misc.colorPicker_onchange = function (event, cp) {
+ var scimoz = ko.views.manager.currentView.scimoz;
+ scimoz.insertText(scimoz.currentPos, cp.color);
+ // Move cursor position to end of the inserted color
+ // Note: currentPos is a byte offset, so we need to correct the length
+ var newCurrentPos = scimoz.currentPos + ko.stringutils.bytelength(cp.color);
+ scimoz.currentPos = newCurrentPos;
+ // Move the anchor as well, so we don't have a selection
+ scimoz.anchor = newCurrentPos;
+ // for some reason we get the event twice, removing
+ // onselect fixes the problem. Tried to solve it
+ // by canceling the event below, but it went on anyway
+ cp.removeAttribute('onselect');
+ cp.parentNode.hidePopup();
+
+ event.preventDefault();
+ event.stopPropagation();
+ event.cancelBubble = true;
+ sv.misc.colorPicker_remove();
+}
+
+sv.misc.colorPicker_remove = function () {
+ // remove the popup from the document. This cleans up so
+ // we can change the macro code if needed
+ var p = document.getElementById('popup_colorpicker');
+ if (p)
+ p.parentNode.removeChild(p);
+}
+
+sv.misc.colorPicker_init = function () {
+ sv.misc.colorPicker_remove();
+ var p = document.createElement('popup');
+ p.setAttribute('id', 'popup_colorpicker');
+ var cp = document.createElement('colorpicker');
+ cp.colorChanged = sv.misc.colorPicker_onchange;
+ cp.setAttribute('onselect', 'this.colorChanged(event, this);');
+ p.appendChild(cp);
+ document.documentElement.appendChild(p);
+}
+
+sv.misc.colorPicker = function () {
+ var currentView = ko.views.manager.currentView;
+ if (currentView) {
+ currentView.scintilla.focus();
+ var os_prefix = window.navigator.platform.substring(0, 3).toLowerCase();
+ if ((os_prefix == "win") || (os_prefix == "mac")) {
+ var color = null;
+ try {
+ color = ko.interpolate.interpolate(window, ["%s"], [])[0];
+ } catch(e) {
+ // No selection, ignore this error.
+ }
+ sv.misc.colorPicker_system(color);
+ } else {
+ init_colorpicker();
+ var scimoz = currentView.scimoz;
+ var pos = scimoz.currentPos;
+ var x = scimoz.pointXFromPosition(pos);
+ var y = scimoz.pointYFromPosition(pos);
+ var boxObject = currentView.boxObject;
+ var cp = document.getElementById('popup_colorpicker');
+ cp.showPopup(currentView.scintilla,
+ x + boxObject.x, y + boxObject.y,
+ 'colorpicker',"topleft","topleft");
+ }
+ }
+}
+
+// Move Line Down, adapted by Ph. Grosjean from code by "mircho"
+sv.misc.moveLineDown = function () {
+ var currentView = ko.views.manager.currentView;
+ if (currentView) {
+ currentView.scintilla.focus();
+ var ke = currentView.scimoz;
+ var currentLine = ke.lineFromPosition(ke.currentPos);
+ // Check if we are not at the last line
+ if( currentLine < (ke.lineCount - 1)) {
+ ke.lineDown();
+ ke.lineTranspose();
+ }
+ }
+}
+
+// Move Line Up, adapted by Ph. Grosjean from code by "mircho"
+sv.misc.moveLineUp = function () {
+ var currentView = ko.views.manager.currentView;
+ if (currentView) {
+ currentView.scintilla.focus();
+ var ke = currentView.scimoz;
+ var currentLine = ke.lineFromPosition(ke.currentPos);
+ // Check if we are not at the first line
+ if (currentLine > 0) {
+ ke.lineTranspose();
+ ke.lineUp();
+ }
+ }
+}
+
+// Search next using current selection
+sv.misc.searchBySel = function () {
+ var currentView = ko.views.manager.currentView;
+ if (currentView) {
+ currentView.scintilla.focus();
+ var ke = currentView.scimoz;
+ var searchText = ke.selText;
+ if (!searchText.length) {
+ // use last pattern used
+ searchText = ko.mru.get("find-patternMru");
+ }
+
+ // Search with last user find preferences
+ var findSvc = Components.classes["@activestate.com/koFindService;1"]
+ .getService(Components.interfaces.koIFindService);
+ var context = Components.classes["@activestate.com/koFindContext;1"]
+ .createInstance(Components.interfaces.koIFindContext);
+ context.type = findSvc.options.preferredContextType;
+ Find_FindNext(window, context, searchText);
+ }
+}
+
+// Show current Komodo configuration page
+sv.misc.showConfig = function () {
+ try {
+ ko.open.URI('about:config','browser');
+ } catch(e) {
+ sv.log.exception(e, "sv.misc.showConfig() error");
+ }
+}
+
+// Swap quotes by 'Nicto', adapted in SciViews-K by Ph. Grosjean
+sv.misc.swapQuotes = function() {
+ try {
+ var currentView = ko.views.manager.currentView;
+ if (currentView) {
+ currentView.scintilla.focus();
+ var scimoz = currentView.scimoz;
+ scimoz.beginUndoAction();
+
+ // Retain these so we can reset the selection after the replacement
+ var curAnchor = scimoz.anchor;
+ var curPos = scimoz.currentPos;
+
+ // Replace the currently selected text
+ scimoz.replaceSel(
+ // Find all single and double quote characters
+ scimoz.selText.replace( /[\'\"]/g, function (value) {
+ // Return whatever the value isn't
+ return value == '"'?"'":'"';
+ })
+ );
+
+ // Reset the selection
+ scimoz.setSel(curAnchor, curPos);
+ }
+ } catch (e) {
+ sv.log.exception(e, "sv.misc.showConfig() error");
+ } finally {
+ ko.views.manager.currentView.scimoz.endUndoAction();
+ }
+}
+
+// Copy the path of current file to the clipboard
+sv.misc.pathToClipboard = function () {
+ var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"].
+ getService(Components.interfaces.nsIClipboardHelper);
+ try {
+ ch.copyString(ko.views.manager.currentView.document.file.path);
+ } catch(e) {
+ sv.alert("Copy path to clipboard",
+ "Unable to copy file path to clipboard (unsaved file?)")
+ }
+}
+
+// Copy the UNIX version (using '/' as sep) path of current file to the clipboard
+sv.misc.unixPathToClipboard = function () {
+ var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"].
+ getService(Components.interfaces.nsIClipboardHelper);
+ try {
+ ch.copyString(ko.views.manager.currentView.document.file.path.
+ replace(/\\/g, "/"));
+ } catch(e) {
+ sv.alert("Copy path to clipboard",
+ "Unable to copy file path to clipboard (unsaved file?)")
+ }
+}
+
+// Stamp the current text with date - time
+// Use preferences -> Internationalization -> Date & Time format to change it!
+sv.misc.timeStamp = function () {
+ try {
+ var ke = ko.views.manager.currentView.scimoz;
+ var strTime = ko.interpolate.interpolateStrings('%date');
+ ke.replaceSel(strTime);
+ } catch(e) {
+ sv.log.exception(e, "sv.misc.timeStamp() error");
+ }
+}
+
+// Delete current line
+sv.misc.delLine = function () {
+ try {
+ ko.views.manager.currentView.setFocus();
+ var scimoz = ko.views.manager.currentView.scimoz;
+ scimoz.home();
+ scimoz.delLineRight();
+ scimoz.deleteBack();
+ scimoz.charRight();
+ } catch(e) {
+ sv.log.exception(e, "sv.misc.delLine() error");
+ }
+}
\ No newline at end of file
Modified: komodo/SciViews-K/content/js/prefs.js
===================================================================
--- komodo/SciViews-K/content/js/prefs.js 2009-08-29 10:42:13 UTC (rev 182)
+++ komodo/SciViews-K/content/js/prefs.js 2009-09-06 23:51:23 UTC (rev 183)
@@ -22,8 +22,11 @@
// Help page on the R Wiki
sv.prefs.setString("RWiki-help", "", true);
-// Default working directory for R
+// Default working directory for R and default subdirs the first time SciViews-K
+// is used
sv.prefs.setString("sciviews.session.dir", "~", false);
+// ... and other default values for directories used in snippets
+sv.prefs.setSession();
// Where do we want to display R help? In internal browser or not?
sv.prefs.setString("sciviews.r.help", "internal", false);
@@ -33,8 +36,8 @@
"http:/wiki.r-project.org/rwiki/doku.php?id=", false);
// Record default field and decimal separators for CSV files
-sv.prefs.setString("r.csv.sep", '\t', false);
-var sep = sv.prefs.getString("r.csv.sep", '\t');
+sv.prefs.setString("r.csv.sep", ',', false);
+var sep = sv.prefs.getString("r.csv.sep", ',');
if (sep == '\t') {
sv.prefs.setString("r.csv.sep.arg", '"\\t"', true);
} else {
@@ -46,7 +49,7 @@
// Set default dataset to 'df'
// Should be reset to a more useful value during first use of R
-sv.prefs.setString("R.active.data.frame", "df", false);
+sv.prefs.setString("r.active.data.frame", "df", false);
//// (re)initialize a series of MRU for snippets' %ask constructs //////////////
@@ -104,7 +107,7 @@
sv.prefs.mru("type", true, '"p"|"l"|"b"|"c"|"o"|"h"|"s"|"S"|"n"', "|");
// Pch
-sv.prefs.mru("type", true,
+sv.prefs.mru("pch", true,
'0|1|2|3|3|4|5|6|7|8|9|10|11|12|13|14|15|15|17|18|19|20|21|22|23|24|25|' +
'"."|"+"|"-"|"*"', "|");
Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js 2009-08-29 10:42:13 UTC (rev 182)
+++ komodo/SciViews-K/content/js/r.js 2009-09-06 23:51:23 UTC (rev 183)
@@ -12,7 +12,7 @@
// 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(); // Escape R calculation or multiline mode
+// 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
@@ -152,13 +152,17 @@
}
// Escape R calculation
-sv.r.escape = function () {
+sv.r.escape = function (cmd) {
// Send an <<<esc>>> sequence that breaks multiline mode
sv.socket.cmd = "";
sv.socket.prompt == ":> ";
if (sv.socket.cmdout) { sv.cmdout.clear(); }
var listener = { finished: function(data) {} }
- var res = sv.socket.rCommand('<<<esc>>>', false);
+ if (typeof(cmd) == "undefined") {
+ var res = sv.socket.rCommand('<<<esc>>>', false);
+ } else {
+ var res = sv.socket.rCommand('<<<esc>>>' + cmd, false);
+ }
return(res);
}
Modified: komodo/SciViews-K/content/js/sciviews.js
===================================================================
--- komodo/SciViews-K/content/js/sciviews.js 2009-08-29 10:42:13 UTC (rev 182)
+++ komodo/SciViews-K/content/js/sciviews.js 2009-09-06 23:51:23 UTC (rev 183)
@@ -33,6 +33,11 @@
// sv.prefs.setString(pref, value, overwrite); // Set a preference string
// sv.prefs.askString(pref, defvalue); // Ask for the value of a preference
// sv.prefs.mru(mru, reset, items, sep); //Simplify update of MRU lists
+// sv.prefs.setSession(dir, datadir, scriptdir, reportdir, saveOld, loadNew);
+ // Initialize R session with corresponding directories
+ // 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?
//
// SciViews-K Command Output management ('sv.cmdout' namespace) ////////////////
// sv.cmdout.append(str, newline, scrollToStart); // Append to Command Output
@@ -588,7 +593,174 @@
}
}
+// Set a R session dir and corresponding directories preferences
+sv.prefs.setSession = function (dir, datadir, scriptdir, reportdir,
+ saveOld, loadNew) {
+ // Set defaults for saveOld and loadNew
+ if (typeof(saveOld) == "undefined") saveOld = true;
+ if (typeof(loadNew) == "undefined") loadNew = true;
+
+ // cmd is the command executed in R to switch session (done asynchronously)
+ var cmd = "";
+
+ // If dir is the same as current session dir, do nothing
+ if (typeof(dir) != "undefined" &
+ dir == sv.prefs.getString("sciviews.session.dir", "")) {
+ return(false);
+ }
+
+ // Before switching to the new session directory, close current one
+ // if R is running
+ if (saveOld) {
+ // Save .RData & .Rhistory in the the session directory and clean WS
+ // We need also to restore .required and .SciViewsReady variables
+ cmd = 'assignTemp(".required", .required)\nTempEnv()$.Last.sys()\n' +
+ 'save.image()\nsavehistory()\nrm(list = ls())\n' +
+ '.required <- getTemp(".required")\n.SciViewsReady <- TRUE\n';
+
+ } else {
+ // Clear workspace (hint, we don't clear hidden objects!)
+ cmd = 'rm(list = ls())\n'
+ }
+ // TODO: possibly close the associated Komodo project
+
+ // Initialize the various arguments
+ if (typeof(dir) == "undefined")
+ dir = sv.prefs.getString("sciviews.session.dir", "~");
+ if (typeof(datadir) == "undefined")
+ datadir = sv.prefs.getString("sciviews.session.data", "");
+ if (typeof(scriptdir) == "undefined")
+ scriptdir = sv.prefs.getString("sciviews.session.scripts", "");
+ if (typeof(reportdir) == "undefined")
+ reportdir = sv.prefs.getString("sciviews.session.reports", "");
+ var os = Components.classes['@activestate.com/koOs;1'].
+ getService(Components.interfaces.koIOs);
+ var ossep = os.sep;
+
+ var localdir = dir;
+ // If dir starts with ~, get what's considered as '~' by R:
+ // '~' in Linux/Mac, but '~\My Documents' in Windows
+ if (dir.substring(0, 1) == "~") {
+ if (ossep == "/") {
+ // This is Linux or Mac OS X
+ // Instead of using '~', we get the actual home directory
+ var home = Components.
+ classes["@mozilla.org/file/directory_service;1"].
+ getService(Components.interfaces.nsIProperties).
+ get("Home", Components.interfaces.nsIFile).path;
+ } else {
+ // This is probably Windows
+ ossep = "\\";
+ // This is the way we got "My Documents" under Windows
+ var wrk = Components.classes["@mozilla.org/windows-registry-key;1"]
+ .createInstance(Components.interfaces.nsIWindowsRegKey);
+ wrk.open(wrk.ROOT_KEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft",
+ wrk.ACCESS_READ);
+ var subkey = wrk.
+ openChild("Windows\\CurrentVersion\\Explorer\\Shell Folders",
+ wrk.ACCESS_READ);
+ var key = subkey.readStringValue("Personal");
+ subkey.close();
+ wrk.close();
+ // Possibly eliminate trailing backslash
+ var home = key.replace(/\\$/, "");
+ }
+ // Construct localdir using home found here
+ localdir = home + dir.substring(1);
+ }
+
+ // Refresh preferences
+ sv.prefs.setString("sciviews.session.dir", dir, true);
+ sv.prefs.setString("sciviews.session.localdir", localdir, true);
+ // Subdirectories for data, reports and scripts
+ sv.prefs.setString("sciviews.session.data", datadir, true);
+ sv.prefs.setString("sciviews.session.scripts", scriptdir, true);
+ sv.prefs.setString("sciviews.session.reports", reportdir, true);
+ // Combination of these to give access to respective dirs
+ if (datadir == "") {
+ sv.prefs.setString("sciviews.data.dir", dir, true);
+ sv.prefs.setString("sciviews.data.localdir", localdir, true);
+ } else {
+ sv.prefs.setString("sciviews.data.dir", dir + "/" + datadir, true);
+ sv.prefs.setString("sciviews.data.localdir",
+ localdir + ossep + datadir, true);
+ }
+ if (scriptdir == "") {
+ sv.prefs.setString("sciviews.scripts.dir", dir, true);
+ sv.prefs.setString("sciviews.scripts.localdir", localdir, true);
+ } else {
+ sv.prefs.setString("sciviews.scripts.dir", dir + "/" + scriptdir, true);
+ sv.prefs.setString("sciviews.scripts.localdir",
+ localdir + ossep + scriptdir, true);
+ }
+ if (reportdir == "") {
+ sv.prefs.setString("sciviews.reports.dir", dir, true);
+ sv.prefs.setString("sciviews.reports.localdir", localdir, true);
+ } else {
+ sv.prefs.setString("sciviews.reports.dir", dir + "/" + reportdir, true);
+ sv.prefs.setString("sciviews.reports.localdir",
+ localdir + ossep + reportdir, true);
+ }
+
+ // Look if the session directory exists, or create it
+ var file = Components.classes["@mozilla.org/file/local;1"]
+ .createInstance(Components.interfaces.nsILocalFile);
+ file.initWithPath(localdir);
+ if (file.exists() == false) {
+ sv.log.debug( "Creating session directory... " );
+ file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 511);
+ }
+ // ... also make sure that /Data, /Script and /Report subdirs exist
+ if (datadir != "") {
+ file.initWithPath(localdir + ossep + datadir);
+ if (file.exists() == false) {
+ file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 511);
+ }
+ }
+ if (scriptdir != "") {
+ file.initWithPath(localdir + ossep + scriptdir);
+ if (file.exists() == false) {
+ file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 511);
+ }
+ }
+ if (reportdir != "") {
+ file.initWithPath(localdir + ossep + reportdir);
+ if (file.exists() == false) {
+ file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 511);
+ }
+ }
+
+ // Switch to the new session directory in R
+ cmd = cmd + 'setwd("' + dir + '")\noptions(R.initdir = "' + dir + '")\n';
+
+ // Do we load .RData and .Rhistory?
+ if (loadNew) {
+ cmd = cmd + 'if (file.exists(".RData")) load(".RData")\n' +
+ 'if (file.exists(".Rhistory")) loadhistory()\n';
+ }
+
+ // Execute the command in R (TODO: check for possible error here!)
+ // TODO: run first in R; make dirs in R; then change in Komodo!
+ sv.r.evalCallback(cmd, function(data) {
+ // Indicate everything is fine
+ ko.statusBar.AddMessage("R session directory set to '" + localdir + "'",
+ "R", 20000, true);
+ // Break possible partial multiline command in R from previous session
+ // and indicate that we are in a new session now in the R console
+ // TODO: report if we load something or not
+ sv.r.escape('cat("Session directory is now ' + dir +
+ '\n", file = stderr())');
+ // We most probably need to update the R Objects browser
+ rObjectsTree.getPackageList(true);
+ });
+
+ // TODO: possibly open the Komodo project associated with this session
+
+ return(true);
+}
+
+
//// Control the command output tab ////////////////////////////////////////////
if (typeof(sv.cmdout) == 'undefined') sv.cmdout = {};
@@ -717,7 +889,7 @@
var os = Components.classes['@activestate.com/koOs;1'].
getService(Components.interfaces.koIOs);
try {
- appdir = komodo.interpolate('%(path:hostUserDataDir)');
+ var appdir = ko.interpolate.interpolateStrings('%(path:hostUserDataDir)');
var logFile = os.path.join(appdir, 'pystderr.log');
var winOpts = "centerscreen,chrome,resizable,scrollbars,dialog=no,close";
window.openDialog('chrome://komodo/content/tail/tail.xul',"_blank",
Modified: komodo/SciViews-K/content/js/socket.js
===================================================================
--- komodo/SciViews-K/content/js/socket.js 2009-08-29 10:42:13 UTC (rev 182)
+++ komodo/SciViews-K/content/js/socket.js 2009-09-06 23:51:23 UTC (rev 183)
@@ -137,7 +137,8 @@
pump.init(stream, -1, -1, 0, 0, false);
pump.asyncRead(dataListener, null);
} catch (e) {
- sv.log.exception(e, "sv.socket.rClient() raises an unknown error");
+ sv.log.error("sv.socket.rClient() raises an unknown error\n");
+ //sv.log.exception(e, "sv.socket.rClient() raises an unknown error");
return(e);
}
return(null);
@@ -380,11 +381,18 @@
if (!force && _charsetUpdated) return;
//if (this.debug) sv.log.debug("charsetUpdate");
_charsetUpdated = true;
- _this.rCommand("<<<h>>>cat(localeToCharset()[1])", false, null,
+ // We also make sure that dec and sep are synched in R
+ _this.rCommand('<<<h>>>options(OutDec = ' +
+ sv.prefs.getString("r.csv.dec.arg", ".") +
+ '); options(OutSep = ' +
+ sv.prefs.getString("r.csv.sep.arg", ",") +
+ '); cat(localeToCharset()[1])', false, null,
function (s) {
_this.charset = s;
if (this.debug) sv.log.debug(s);
});
+ // Update also the R Object browser
+ rObjectsTree.getPackageList(true);
}
// [PhG] The following command raises an error on my Mac
Modified: komodo/SciViews-K/content/overlayMain.xul
===================================================================
--- komodo/SciViews-K/content/overlayMain.xul 2009-08-29 10:42:13 UTC (rev 182)
+++ komodo/SciViews-K/content/overlayMain.xul 2009-09-06 23:51:23 UTC (rev 183)
@@ -65,6 +65,7 @@
<script type="application/x-javascript" src="chrome://sciviewsk/content/js/robjects.js"/>
<script type="application/x-javascript" src="chrome://sciviewsk/content/js/commands.js"/>
<script type="application/x-javascript" src="chrome://sciviewsk/content/js/r-help.js"/>
+ <script type="application/x-javascript" src="chrome://sciviewsk/content/js/misc.js"/>
<commandset id="allcommands">
<command id="Tasks:svAbout"
@@ -159,6 +160,8 @@
onpopupshowing="sv.command.setMenuRApp(this);" >
<menuitem id="r-app" type="checkbox" checked="false" label="R app"
app="/Applications/R.app" platform="Mac" />
+ <menuitem id="r64-app" type="checkbox" checked="false" label="R64 app"
+ app="/Applications/R64.app" platform="Mac" />
<menuitem id="r-gnome-term" type="checkbox" checked="false" label="R Gnome terminal"
app="gnome-terminal" platform="Linux" />
<menuitem id="r-kde-term" type="checkbox" checked="false" label="R KDE terminal"
Modified: komodo/SciViews-K/pylib/lang_r.py
===================================================================
--- komodo/SciViews-K/pylib/lang_r.py 2009-08-29 10:42:13 UTC (rev 182)
+++ komodo/SciViews-K/pylib/lang_r.py 2009-09-06 23:51:23 UTC (rev 183)
@@ -2873,6 +2873,26 @@
return
if trg.id == (self.lang, TRG_FORM_CPLN, "identifiers"):
+ # First, check if there is an abbreviation
+
+# var ke = ko.views.manager.currentView.scimoz;
+# var sel = ke.selText;
+# if (sv.abbrev.callTipActive & ke.callTipActive()) { ke.callTipCancel(); }
+# // Only activate tip if current selection is empty!
+# if (sel == "") {
+# var trig = ko.interpolate.getWordUnderCursor(ke);
+# var snip = sv.abbrev.findAbbrevSnippet(trig);
+# if(snip) {
+# var tip = snip.value;
+# tip = tip.replace("!@#_anchor", "");
+# tip = tip.replace("!@#_currentPos", "");
+# ke.callTipShow(ke.anchor, "Meta+T expands:\n" + tip);
+# sv.abbrev.callTipActive = true;
+# }
+# }
+# } catch(e) { log.exception(e); }
+
+
# Return all known keywords and builtins.
#ctlr.set_cplns(self._get_all_known_identifiers(buf))
start, end = buf.accessor.contiguous_style_range_from_pos(pos)
Modified: komodo/SciViews-K/sciviewsk-0.8.1-ko.xpi
===================================================================
(Binary files differ)
Modified: komodo/SciViews-K/templates/.Rprofile
===================================================================
--- komodo/SciViews-K/templates/.Rprofile 2009-08-29 10:42:13 UTC (rev 182)
+++ komodo/SciViews-K/templates/.Rprofile 2009-09-06 23:51:23 UTC (rev 183)
@@ -1,6 +1,6 @@
### SciViews install begin ###
# SciViews-R installation and startup for running R with Komodo/SciViews-K
-# Version 0.7.0, 2009-01-23 Ph. Grosjean (phgrosjean at sciviews.org)
+# Version 0.8.1, 2009-09-06 Ph. Grosjean (phgrosjean at sciviews.org)
# Make sure we don't process this twice in case of duplicate items in .Rprofile
if (!exists(".SciViewsReady", envir = .GlobalEnv)) {
@@ -302,7 +302,6 @@
rm(Ret, Path)
}
-
owarn <- getOption("warn")
options(warn = -1)
# Try to run Komodo now
@@ -345,13 +344,20 @@
try(setwd(getOption("R.initdir")), silent = TRUE)
})
+ msg <- paste("Session directory is", getOption("R.initdir"))
# Do we load .RData and .Rhistory now?
if (!"--vanilla" %in% args && !"--no-restore" %in% args &&
- !"--no.restore-data" %in% args)
- if (file.exists(".RData")) load(".RData")
- if (!"--vanilla" %in% args && !"--no-restore" %in% args &&
- !"--no.restore-history" %in% args)
- if (file.exists(".Rhistory")) loadhistory()
+ !"--no.restore-data" %in% args) {
+ if (file.exists(".RData")) {
+ load(".RData")
+ msg <- paste(msg, "[data loaded")
+ } else msg <- paste(msg, "[no data")
+ if (file.exists(".Rhistory")) {
+ loadhistory()
+ msg <- paste(msg, ... = "/history loaded]", sep = "")
+ } else msg <- paste(msg, "/no history]", sep = "")
+ } else msg <- paste(msg, "[data/history not loaded]")
+ cat(msg, "\n", sep = "", file = stderr())
# Do we reactivate Komodo now?
koact <- getOption("ko.activate")
@@ -367,10 +373,10 @@
# And test also communication from R to Komodo!
koCmd('ko.statusBar.AddMessage("<<<data>>>", "R", 10000, true);',
data = paste("'", getOption("R.id"), "' (R ", R.Version()$major, ".",
- R.Version()$minor, ") connected. Initial dir: ",
+ R.Version()$minor, ") connected. Session dir: ",
path.expand(getOption("R.initdir")), sep = ""))
}
- rm(koact, Komodo, args)
+ rm(koact, Komodo, args, msg)
}
}
### SciViews install end ###
More information about the Sciviews-commits
mailing list