[Sciviews-commits] r177 - in komodo: . SciViews-K SciViews-K/components SciViews-K/content SciViews-K/content/js SciViews-K/content/js/tools SciViews-K/skin/images SciViews-K/udl
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Aug 14 12:55:58 CEST 2009
Author: phgrosjean
Date: 2009-08-14 12:55:55 +0200 (Fri, 14 Aug 2009)
New Revision: 177
Added:
komodo/SciViews-K/content/js/pref-R.js
komodo/SciViews-K/content/pref-Main.xul
komodo/SciViews-K/content/prefOverlay.xul
komodo/SciViews-K/sciviewsk-0.8.1-ko.xpi
komodo/SciViews-K/skin/images/appicon.png
Removed:
komodo/SciViews-K/content/pref-R.js
komodo/SciViews-K/content/prefsOverlay.xul
Modified:
komodo/SciViews-K/chrome.manifest
komodo/SciViews-K/components/koR_UDL_Language.py
komodo/SciViews-K/content/default-keybindings.kkf
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/robjects.js
komodo/SciViews-K/content/js/sciviews.js
komodo/SciViews-K/content/js/socket.js
komodo/SciViews-K/content/js/tools/io.js
komodo/SciViews-K/content/js/tools/strings.js
komodo/SciViews-K/content/overlay.xul
komodo/SciViews-K/content/overlayMain.xul
komodo/SciViews-K/content/pref-R.xul
komodo/SciViews-K/install.rdf
komodo/SciViews-K/udl/R-mainlex.udl
komodo/SciViews-K/udl/Rlex.udl
komodo/TODO
Log:
General rework of SciViews-K plugin
Modified: komodo/SciViews-K/chrome.manifest
===================================================================
--- komodo/SciViews-K/chrome.manifest 2009-08-11 13:08:31 UTC (rev 176)
+++ komodo/SciViews-K/chrome.manifest 2009-08-14 10:55:55 UTC (rev 177)
@@ -4,7 +4,7 @@
# Those two items are not finished yet, and are thus commented out
overlay chrome://komodo/content/komodo.xul chrome://sciviewsk/content/rconsole.xul
-overlay chrome://komodo/content/pref/pref.xul chrome://sciviewsk/content/prefsOverlay.xul
+overlay chrome://komodo/content/pref/pref.xul chrome://sciviewsk/content/prefOverlay.xul
locale sciviewsk en-GB jar:sciviewsk.jar!/locale/en-GB/
locale sciviewsk fr-FR jar:sciviewsk.jar!/locale/fr-FR/
Modified: komodo/SciViews-K/components/koR_UDL_Language.py
===================================================================
--- komodo/SciViews-K/components/koR_UDL_Language.py 2009-08-11 13:08:31 UTC (rev 176)
+++ komodo/SciViews-K/components/koR_UDL_Language.py 2009-08-14 10:55:55 UTC (rev 177)
@@ -11,13 +11,14 @@
# License for the specific language governing rights and limitations
# under the License.
#
-# The Original Code is SciViews-K by Philippe Grosjean & Romain Francois.
+# The Original Code is SciViews-K by Philippe Grosjean et al.
#
# Portions created by ActiveState Software Inc are Copyright (C) 2000-2008
# ActiveState Software Inc. All Rights Reserved.
#
# Contributor(s):
# Philippe Grosjean
+# Kamil Barton
# ActiveState Software Inc (code inspired from)
#
# Alternatively, the contents of this file may be used under the terms of
Modified: komodo/SciViews-K/content/default-keybindings.kkf
===================================================================
--- komodo/SciViews-K/content/default-keybindings.kkf 2009-08-11 13:08:31 UTC (rev 176)
+++ komodo/SciViews-K/content/default-keybindings.kkf 2009-08-14 10:55:55 UTC (rev 177)
@@ -1,10 +1,9 @@
version 15
-# Default keybindings for SciViews-K, will be applied if no other key has been
+# Default keybindings for SciViews-K, will be applied if no other key has been
# assigned by user, and if a key combination is not used.
# Commands' ids must start with "cmd_sv_" and be defined in the XUL overlay.
-
binding cmd_sv_RRunAll F5
binding cmd_sv_RSourceAll Shift+F5
binding cmd_sv_RRunSelection F6
Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js 2009-08-11 13:08:31 UTC (rev 176)
+++ komodo/SciViews-K/content/js/commands.js 2009-08-14 10:55:55 UTC (rev 177)
@@ -192,7 +192,7 @@
this.setControllers = function() {
//alert("this.setControllers");
- // allow some commands only whan R is running...
+ // allow some commands only when R is running...
// using this needs solving an issue of running R in some terminals on linux (mac?)
// that send terminate signal right after start.
@@ -429,7 +429,7 @@
}
vm.prototype.is_cmd_Test_enabled = function() { alert("is_cmd_Test_enabled?"); return false; }
-//commands sohuld be put in a commandset, so they can be enabled only if lang = R
+//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
Added: komodo/SciViews-K/content/js/pref-R.js
===================================================================
--- komodo/SciViews-K/content/js/pref-R.js (rev 0)
+++ komodo/SciViews-K/content/js/pref-R.js 2009-08-14 10:55:55 UTC (rev 177)
@@ -0,0 +1,91 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is SciViews-K by Philippe Grosjean & Romain Francois.
+ *
+ * Portions created by ActiveState Software Inc are Copyright (C) 2000-2008
+ * ActiveState Software Inc. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Philippe Grosjean
+ * ActiveState Software Inc (code inspired from)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+// TODO: use 'R' simply as default R interpreter (terminal on Win/Mac, or ? on Linux)
+
+//---- globals
+
+var RPrefLog = getLoggingMgr().getLogger("R");
+RPrefLog.setLevel(LOG_DEBUG);
+
+function OnPreferencePageOK(prefset) {
+ var ok = true;
+
+ // ensure that the interpreter is valid
+ var defaultInterp = prefset.getStringPref("RDefaultInterpreter");
+ if (defaultInterp != "") {
+ var koSysUtils = Components.classes["@activestate.com/koSysUtils;1"].
+ getService(Components.interfaces.koISysUtils);
+ // If the interpreter's name ends with '.app', it is a Mac application
+ // meaning it is a directory instead of a file!
+ if (! koSysUtils.IsFile(defaultInterp) & ! koSysUtils.IsDir(defaultInterp)) {
+ dialog_alert("No R interpreter could be found at '" + defaultInterp +
+ "'. You must make another selection for the default " +
+ "R interpreter.\n");
+ ok = false;
+ document.getElementById("R_interpreterPath").focus();
+ }
+ }
+ return ok;
+}
+
+function PrefR_OnLoad() {
+ var prefExecutable;
+ var prefName = 'RDefaultInterpreter';
+ // If there is no pref, create it, otherwise trying to save a new pref
+ // will fail, because it tries to get an existing one to see if the
+ // pref needs updating.
+ if (!parent.hPrefWindow.prefset.hasStringPref(prefName)) {
+ parent.hPrefWindow.prefset.setStringPref(prefName, "");
+ prefExecutable = '';
+ } else {
+ prefExecutable = parent.hPrefWindow.prefset.getStringPref(prefName);
+ if (prefExecutable == null) {
+ prefExecutable = '';
+ }
+ }
+ _finishSpecifyingExecutable(prefExecutable);
+}
+
+function loadRExecutable() {
+ _finishSpecifyingExecutable(filepicker_openExeFile());
+}
+
+function _finishSpecifyingExecutable(path) {
+ if (path != null) {
+ document.getElementById("R_interpreterPath").value = path;
+ }
+}
Modified: komodo/SciViews-K/content/js/prefs.js
===================================================================
--- komodo/SciViews-K/content/js/prefs.js 2009-08-11 13:08:31 UTC (rev 176)
+++ komodo/SciViews-K/content/js/prefs.js 2009-08-14 10:55:55 UTC (rev 177)
@@ -16,3 +16,104 @@
// This is the base path for the R Wiki context help feature of sv.helpContext()
sv.prefs.setString("sciviews.rwiki.help.base",
"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');
+if (sep == '\t') {
+ sv.prefs.setString("r.csv.sep.arg", '"\\t"', true);
+} else {
+ sv.prefs.setString("r.csv.sep.arg", '"' + sep + '"', true);
+}
+sv.prefs.setString("r.csv.dec", '.', false);
+sv.prefs.setString("r.csv.dec.arg", '"' + sv.prefs.getString("r.csv.dec", '.') +
+ '"', true);
+
+// 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);
+
+// (re)initialize a series of MRU for snippets' %ask constructs
+//// TODO: ts, data, table
+
+//// dec argument, like in read.table()
+sv.prefs.mru("dec", reset = true, '"."|","', sep = "|");
+
+//// sep argument, like in read.table()
+sv.prefs.mru("sep", reset = true, '" "|";"|","|"\\t"', sep = "|");
+
+//// header argument, like in read.table()
+sv.prefs.mru("header", reset = true, 'TRUE|FALSE', sep = "|");
+
+//// Various examples of pkgdata (indeed, data frames in datatasets 2.9.1)
+sv.prefs.mru("pkgdata", reset = false,
+ 'airquality|anscombe|attenu|attitude|beaver1|beaver2|BOD|cars|' +
+ 'ChickWeight|chickwts|CO2|DNase|esoph|faithful|Formaldehyde|freeny|' +
+ 'Indometh|infert|InsectSprays|iris|LifeCycleSavings|Loblolly|longley|' +
+ 'morley|mtcars|Orange|OrchardSprays|PlantGrowth|pressure|Puromycin|' +
+ 'quakes|randu|rock|sleep|stackloss|swiss|Theoph|ToothGrowth|trees|' +
+ 'USArrests|USJudgeRatings|warpbreaks|women', sep = "|");
+
+// TODO... Various examples of itemIndex, subset and expression
+// TODO... List of function, descfun and transfun
+
+//// Various examples of formulas
+sv.prefs.mru("formula", reset = false,
+ 'y ~ x,y ~ x + x2,y ~ x + I(x^2),y ~ x - 1,' +
+ 'y ~ factor,y ~ x | factor,y ~ factor + factor2,y ~ factor * factor2',
+ sep = ",");
+
+//// Various examples of quantiles and probs
+sv.prefs.mru("quantiles", reset = false, '1|c(1, 3)', sep = "|");
+sv.prefs.mru("probs", reset = false, '0.5|c(0.01, 0.25, 0.5, 0.75, 0.99)', sep = "|");
+sv.prefs.mru("lower.tail", reset = true, 'TRUE|FALSE', sep = "|");
+sv.prefs.mru("na.rm", reset = true, 'TRUE|FALSE', sep = "|");
+sv.prefs.mru("var.equal", reset = true, 'TRUE|FALSE', sep = "|");
+sv.prefs.mru("conf.level", reset = true, '0.90|0.95|0.99|0.999', sep = "|");
+sv.prefs.mru("alternative", reset = true, '"two.sided"|"less"|"greater"', sep = "|");
+sv.prefs.mru("breaks", reset = true, '"Sturges"|"Scott"|"Freedman-Diaconis"|10', sep = "|");
+sv.prefs.mru("corMethod", reset = true, '"pearson"|"kendall"|"spearman"', sep = "|");
+
+//// Various graph parameters
+// Colors
+sv.prefs.mru("col", reset = true,
+ '"black"|"red"|"blue"|"green"|"gray"|"darkred"|"darkblue"|"darkgreen"|' +
+ '"darkgray"|"lightblue"|"lightgreen"|"lightgray"|"gray10"|"gray20"|' +
+ '"gray30"|"gray40"|"gray50"|"gray60"|"gray70"|"gray80"|"gray90"|"white|"' +
+ '"transparent"|"wheat"|"cornsilk"|"yellow"|"orange"|"tan"|"tomato"|' +
+ '"firebrick"|"magenta"|"pink"|"salmon"|"violet"|"purple"|"plum"|"cyan"|' +
+ '"lavender"|"navy"|"azure"|"aquamarine"|"turquoise"|"khaki"|"gold"|' +
+ '"bisque"|"beige"|"brown"|"chocolate"', sep = "|");
+
+// Type
+sv.prefs.mru("type", reset = true, '"p"|"l"|"b"|"c"|"o"|"h"|"s"|"S"|"n"', sep = "|");
+ko.mru.reset("dialog-interpolationquery-typeMru");
+ko.mru.add("dialog-interpolationquery-typeMru", '"n"', true);
+ko.mru.add("dialog-interpolationquery-typeMru", '"S"', true);
+ko.mru.add("dialog-interpolationquery-typeMru", '"s"', true);
+ko.mru.add("dialog-interpolationquery-typeMru", '"h"', true);
+ko.mru.add("dialog-interpolationquery-typeMru", '"o"', true);
+ko.mru.add("dialog-interpolationquery-typeMru", '"c"', true);
+ko.mru.add("dialog-interpolationquery-typeMru", '"b"', true);
+ko.mru.add("dialog-interpolationquery-typeMru", '"l"', true);
+ko.mru.add("dialog-interpolationquery-typeMru", '"p"', true);
+
+// Pch
+sv.prefs.mru("type", reset = 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|' +
+ '"."|"+"|"-"|"*"', sep = "|");
+
+// Lty
+sv.prefs.mru("lty", reset = true,
+ '"solid"|"dashed"|"dotted"|"dotdash"|"longdash"|"twodash"|"blank"', sep = "|");
+
+// Lwd
+sv.prefs.mru("lwd", reset = true, '1|2|3', sep = "|");
+
+
+//// various mrus for 'car' graphs
+sv.prefs.mru("reg.line", reset = true, 'FALSE|lm', sep = "|");
+sv.prefs.mru("smooth", reset = true, 'TRUE|FALSE', sep = "|");
+sv.prefs.mru("diagonal", reset = true,
+ '"density"|"histogram"|"boxplot"|"qqplot"|"none"', sep = "|");
+sv.prefs.mru("envelope", reset = true, '0.90|0.95|0.99|0.999', sep = "|");
Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js 2009-08-11 13:08:31 UTC (rev 176)
+++ komodo/SciViews-K/content/js/r.js 2009-08-14 10:55:55 UTC (rev 177)
@@ -5,9 +5,10 @@
////////////////////////////////////////////////////////////////////////////////
// To cope with versions incompatibilities, we define this:
// alert(sv.r.RMinVersion); // Display minimum R version required
+// sv.r.sep; // ??? Defined as ";;", Kamil, what is this???
+// sv.r.running; // Is the linked R interpreter currently running?
+// sv.r.test(); // Check if an R interpreter is running and communicates with us
//
-// These functions are available if you trigger this macro on startup
-// Then, you can use them in other macros, menus, toolbars, ...
// 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'
@@ -17,9 +18,9 @@
// sv.r.runEnter(breakLine = false); // Run current line to pos in R and add a line feed
// sv.r.source(what); // Source various part of current buffer to R
// sv.r.send(what); // Send various part of current buffer to R
-// sv.r.addHistory(data, cmd); // Add current command to R's history, used as a procfun in sv.socket.rCommand call
// sv.r.calltip(code); // Get a calltip for a piece of code
// sv.r.calltip_show(tip); sv.r.calltip_trigget(event); // Companion functions for sv.r.calltip
+// sv.r.autoComplete(); // AutoComplete mechanism for R
// sv.r.display(topic, what); // Display 'topic' according to 'what' type
// sv.r.helpStart(); // Start R help in the default browser
// sv.r.help(topic, package); // Get help in R for 'topic', 'topic' is facultative
@@ -32,8 +33,11 @@
// sv.r.data(); // Select one dataset to load
// sv.r.data_select(data); // Callback function for sv.r.data()
// sv.r.browseVignettes(); // Open a web page listing all installed vignettes
-// sv.r.saveWorkspace(file, title); // Save data in a .Rdata file
-// sv.r.loadWorkspace(file, attach); // Load the content of a .RData file into the workspace, or attach it
+// sv.r.saveWorkspace(file, title); // Save data in a .Rdata file
+// sv.r.loadWorkspace(file, attach); // Load the content of a .RData file into
+ // the workspace, or attach it
+// sv.r.addHistory(data, cmd); // Add current command to R's history, used as
+ // a procfun in sv.socket.rCommand call
// sv.r.saveHistory(file, title); // Save the history in a file
// sv.r.loadHistory(file, title); // Load the history from a file
// sv.r.saveGraph(type, file, title, height, width, method);
@@ -42,27 +46,26 @@
//
// sv.r.pkg namespace: /////////////////////////////////////////////////////////
// sv.r.pkg.repositories(); // Select repositories for installing R packages
-// sv.r.pkg.CRANmirror(); // Select preferred CRAN mirror
-// sv.r.pkg.available(); // List available R packages on selected repositories
-// sv.r.pkg.installed(); // List installed R packages
-// sv.r.pkg.install(); // Install R package(s) from the repositories
-// sv.r.pkg.chooseCRANMirror(andInstall); // replacement for .CRANmirror, optionally calls .install after execution
-
-// sv.r.pkg.installLocal(); // Install one or more R packages from local files
-// sv.r.pkg.installSV(); // Install the Sciviews bundle from CRAN
-// sv.r.pkg.installSVrforge(); // Install development versions of SciViews
- // from R-Forge
+// sv.r.pkg.CRANmirror(); // Select preferred CRAN mirror
+// sv.r.pkg.chooseCRANMirror(andInstall); // replacement for .CRANmirror,
+ // optionally calls .install after execution
+// sv.r.pkg.available(); // List available R packages on selected repositories
+// sv.r.pkg.installed(); // List installed R packages
// sv.r.pkg.new(); // List new R packages available on CRAN
// sv.r.pkg.old(); // List older installed R packages than distributed versions
// sv.r.pkg.update(); // Update installed R packages from the repositories
// sv.r.pkg.status(); // Show status of installed R packages
// sv.r.pkg.loaded(); // Show which R packages are loaded
// sv.r.pkg.load(); // Load one R package
-// sv.r.pkg.load_select(pkgs); // Callback function for sv.r.pkg.load()
// sv.r.pkg.unload(); // Unload one r package
// sv.r.pkg.unload_select(pkgs); // Callback function for sv.r.pkg.unload()
// sv.r.pkg.remove(); // Remove one R package
// sv.r.pkg.remove_select(pkgs); // Callback function for sv.r.pkg.remove()
+// sv.r.pkg.install(isCRANMirrorSet); // Install R package(s) from the repositories
+// sv.r.pkg.installLocal(); // Install one or more R packages from local files
+// sv.r.pkg.installSV(); // Install the SciViews bundle from CRAN
+// sv.r.pkg.installSVrforge(); // Install development versions of SciViews
+ // from R-Forge
////////////////////////////////////////////////////////////////////////////////
// TODO: in overlay: add "source file" context menu item in the project tab
@@ -98,7 +101,6 @@
// Evaluate code in R
sv.r.eval = function(cmd) {
-
cmd = (new String(cmd)).trim();
// Store the current R command
if (sv.socket.prompt == ":> ") {
@@ -109,7 +111,7 @@
} else {
// We continue previous multiline command
//sv.socket.cmd += '\n' + cmd;
- sv.socket.cmd += '' + cmd;
+ sv.socket.cmd += '<<<n>>>' + cmd;
}
if (sv.socket.cmdout) {
if (sv.socket.prompt == ":> ") {
@@ -120,7 +122,7 @@
}
}
var res = sv.socket.rCommand('<<<e>>>' + cmd, sv.socket.cmdout, null,
- sv.r.addHistory, sv.socket.cmd);
+ sv.r.addHistory, sv.socket.cmd);
return(res);
}
@@ -133,8 +135,6 @@
var res = sv.socket.rCommand(preCode + cmd, false);
return(res);
}
-
-
// Tests:
//sv.r.evalHidden("Sys.sleep(5); cat('done\n')");
//sv.r.evalHidden("Sys.sleep(5); cat('done\n')", earlyExit = true);
@@ -188,19 +188,16 @@
break;
case "session":
getDirFromR = "getOption(\"R.initdir\")";
- //sv.r.eval(".odir <- setwd(getOption(\"R.initdir\"))");
break;
case "previous":
- //sv.r.eval("if (exists(\".odir\")) .odir <- setwd(.odir); getwd()");
getDirFromR = "if (exists(\".odir\")) .odir else getwd()";
break;
case "init":
- //sv.r.eval(".odir <- setwd(getOption(\"R.initdir\"))");
getDirFromR = "getOption(\"R.initdir\")";
break;
case "current":
getDirFromR = "getwd()";
- ask = true; // assume ask is always true in shis case
+ ask = true; // assume ask is always true in this case
break;
case "file":
var kv = ko.views.manager.currentView;
@@ -250,8 +247,10 @@
dir = ko.filepicker.getFolder(dir, sv.translate("Choose working directory"));
if (dir != null) {
- res = sv.r.evalHidden(".odir <- setwd(\"" + dir.addslashes() + "\")");
- sv.cmdout.message(sv.translate("Current R's working directory is: \"%S\"", dir), 10000);
+ // No, we want to make it a regular R command (should be included in a script)
+ //res = sv.r.evalHidden(".odir <- setwd(\"" + dir.addslashes() + "\")");
+ //sv.cmdout.message(sv.translate("Current R's working directory is: \"%S\"", dir), 10000);
+ sv.r.eval(".odir <- setwd(\"" + dir.addslashes() + "\")");
}
return res;
}
@@ -301,7 +300,6 @@
// get text from a line and move caret to the eol
// do we want to break line here or execute it to the end?
var text = sv.getTextRange(breakLine? "linetobegin" : "line", true);
-
ko.commands.doCommand('cmd_newlineExtra');
if (text != "") res = sv.r.eval(text);
}
@@ -363,7 +361,6 @@
// Send whole or a part of the current buffer to R
// place cursor at next line
sv.r.send = function(what) {
- //sv.cmdout.message("sv.r.send "+what, 3000);
//alert("sv.r.send "+what);
var res = false;
var kv = ko.views.manager.currentView;
@@ -391,49 +388,6 @@
return res;
}
-// Add current command to R's history,
-// used as a procfun in sv.socket.rCommand call
-sv.r.addHistory = function(data, cmd) {
- if (sv.socket.prompt == ":> ") {
- var quotedCmd = cmd.trim();
- quotedCmd = quotedCmd.replace(/([\\"'])/g, "\\$1").replace(/[\r\n]+/, "\\n").replace("\t", " ");
-
- sv.socket.rCommand("<<<H>>>" + ".sv.tmp <- strsplit(\"" + quotedCmd + "\", \"\\\\s*([\\r\\n]|<<<n>>>)+\\\\s*\", perl = T)[[1]]; .sv.tmp <- .sv.tmp[.sv.tmp != \"\"]; lapply(.sv.tmp, function(x) {.Internal(addhistory((x))) }); rm(.sv.tmp);", false);
- }
-}
-
-// Display R objects in different ways
-// TODO: allow custom methods + arguments + forcevisible + affect to var
-sv.r.display = function(topic, what) {
- var res = false;
- if (typeof(topic) == "undefined" | topic == "") topic = sv.getText();
- if (topic == "") {
- //alert("Nothing is selected!");
- } else {
- // Display data in different ways, depending on what
- switch(what) {
- case "names":
- res = sv.r.eval("names(" + topic + ")");
- break;
- case "structure":
- res = sv.r.eval("str(" + topic + ")");
- break;
- case "summary":
- res = sv.r.eval("summary(" + topic + ")");
- break;
- case "plot":
- res = sv.r.eval("plot(" + topic + ")");
- break;
- case "content":
- case "print":
- case "show":
- default:
- res = sv.r.eval(topic);
- }
- }
- return(res);
-}
-
// Get a calltip for a R function
sv.r.calltip = function(codestrip) {
var cmd = 'cat(CallTip("' + codestrip.replace(/(")/g, "\\$1") + '", location = TRUE))';
@@ -452,20 +406,33 @@
}
}
-//
+// The trigger for sv.r.calltip (when '(' is entered)
+sv.r.callTip_trigger = function(event) {
+ //sv.cmdout.append("keyCode " + event.keyCode);
+ if (ko.views.manager.currentView.languageObj.name != "R")
+ return;
+
+ try {
+ if (event.keyCode == 57) { // 57 is code for '('
+ var codestrip = sv.getTextRange("linetobegin");
+ var res = sv.r.calltip(codestrip);
+ }
+ } catch(e) { log.exception(e); }
+}
+// TODO: better way to trigger calltips - with the same mechanism as
+// for other languages
+//window.addEventListener("keyup", sv.r.callTip_trigger, true);
+
+// AutoComplete mechanism for R
sv.r.autoComplete = function() {
if (ko.views.manager.currentView.languageObj.name != "R")
return false;
var text = sv.getTextRange("linetobegin").replace(/(")/g, "\\$1");
var scimoz = ko.views.manager.currentView.scimoz;
- //var cmd = 'cat(Complete("' + text + '"))';
- //var cmd = 'scintillaCompletions("' + text + '", printit=TRUE, )';
- var cmd = 'Complete2("' + text + '", print = TRUE, types = svMisc:::.scintilla.completion.types)';
+ var cmd = 'Complete("' + text + '", print = TRUE, types = "scintilla")';
+ //alert(cmd);
- //Complete2("' + text + '", print=TRUE)';
- //sv.cmdout.append(cmd)
-
var res = sv.r.evalCallback(cmd, function(autoCstring) {
// these should be set only once?:
scimoz.autoCSeparator = 9;
@@ -482,38 +449,52 @@
// code below taken from "CodeIntelCompletionUIHandler"
var iface = Components.interfaces.koICodeIntelCompletionUIHandler;
scimoz.registerImage(iface.ACIID_FUNCTION,
- ko.markers.getPixmap("chrome://komodo/skin/images/ac_function.xpm"));
+ ko.markers.getPixmap("chrome://komodo/skin/images/ac_function.xpm"));
scimoz.registerImage(iface.ACIID_VARIABLE,
- ko.markers.getPixmap("chrome://komodo/skin/images/ac_variable.xpm"));
+ ko.markers.getPixmap("chrome://komodo/skin/images/ac_variable.xpm"));
scimoz.registerImage(iface.ACIID_XML_ATTRIBUTE,
- ko.markers.getPixmap("chrome://komodo/skin/images/ac_xml_attribute.xpm"));
+ ko.markers.getPixmap("chrome://komodo/skin/images/ac_xml_attribute.xpm"));
scimoz.registerImage(iface.ACIID_NAMESPACE,
- ko.markers.getPixmap("chrome://komodo/skin/images/ac_namespace.xpm"));
+ ko.markers.getPixmap("chrome://komodo/skin/images/ac_namespace.xpm"));
scimoz.registerImage(iface.ACIID_KEYWORD,
- ko.markers.getPixmap("chrome://komodo/skin/images/ac_interface.xpm"));
+ ko.markers.getPixmap("chrome://komodo/skin/images/ac_interface.xpm"));
scimoz.autoCChooseSingle = true;
scimoz.autoCShow(trigPos, autoCstring);
});
return res;
}
-
-// The trigger for sv.r.calltip (when '(' is entered)
-sv.r.callTip_trigger = function(event) {
- //sv.cmdout.append("keyCode " + event.keyCode);
- if (ko.views.manager.currentView.languageObj.name != "R")
- return;
-
- try {
- if (event.keyCode == 57) { // 57 is code for '('
- var codestrip = sv.getTextRange("linetobegin");
- var res = sv.r.calltip(codestrip);
+// Display R objects in different ways
+// TODO: allow custom methods + arguments + forcevisible + affect to var
+sv.r.display = function(topic, what) {
+ var res = false;
+ if (typeof(topic) == "undefined" | topic == "") topic = sv.getText();
+ if (topic == "") {
+ //alert("Nothing is selected!");
+ } else {
+ // Display data in different ways, depending on what
+ switch(what) {
+ case "names":
+ res = sv.r.eval("names(" + topic + ")");
+ break;
+ case "structure":
+ res = sv.r.eval("str(" + topic + ")");
+ break;
+ case "summary":
+ res = sv.r.eval("summary(" + topic + ")");
+ break;
+ case "plot":
+ res = sv.r.eval("plot(" + topic + ")");
+ break;
+ case "content":
+ case "print":
+ case "show":
+ default:
+ res = sv.r.eval(topic);
}
- } catch(e) { log.exception(e); }
+ }
+ return(res);
}
-// TODO: better way to trigger calltips - with the same mechanism as
-// for other languages
-//window.addEventListener("keyup", sv.r.callTip_trigger, true);
// Start R help in the default browser
sv.r.helpStart = function() {
@@ -529,12 +510,8 @@
if (typeof(topic) == "undefined" || topic == "")
topic = sv.getText();
- if (topic == "") {
- // let's not cry so much about an empty selection
+ if (topic == "")
ko.statusBar.AddMessage(sv.translate("Selection is empty..."), "R", 1000, false);
- //alert("Nothing is selected!");
- }
-
} else {
var cmd = '';
@@ -548,7 +525,6 @@
ko.statusBar.AddMessage(sv.translate("R help asked for \"%S\"", topic),
"R", 5000, true);
-
}
return(res);
}
@@ -558,7 +534,7 @@
var res = false;
if (typeof(topic) == "undefined" | topic == "") topic = sv.getText();
if (topic == "") {
- //alert("Nothing is selected!");
+ ko.statusBar.AddMessage(sv.translate("Selection is empty..."), "R", 1000, false);
} else {
res = sv.r.eval("example(" + topic + ")");
ko.statusBar.AddMessage(sv.translate("R example run for \"%S\"", topic),
@@ -613,7 +589,7 @@
var res = false;
if (typeof(topic) == "undefined" | topic == "") topic = sv.getText();
if (topic == "") {
- //alert("Nothing is selected!");
+ ko.statusBar.AddMessage(sv.translate("Selection is empty..."), "R", 1000, false);
} else {
res = sv.r.evalHidden('RSiteSearch("' + topic + '")', earlyExit = true);
ko.statusBar.AddMessage("R site search asked for '" + topic + "'",
@@ -677,19 +653,20 @@
// Save the content of the workspace in a file
sv.r.saveWorkspace = function(file, title) {
- // Ask for the filename if not provided
- if (typeof(file) == "undefined") {
- if (typeof(title) == "undefined") { title = 'Save the R workspace in a file'; }
- file = ko.filepicker.saveFile("", ".RData", title);
- if (file == null) return; // User clicked cancel
- }
- sv.r.eval('save.image("' + file + '")');
+ // Ask for the filename if not provided
+ if (typeof(file) == "undefined") {
+ if (typeof(title) == "undefined") {
+ title = 'Save the R workspace in a file';
+ }
+ file = ko.filepicker.saveFile("", ".RData", title);
+ if (file == null) return; // User clicked cancel
+ }
+ sv.r.eval('save.image("' + file + '")');
}
-
// Load the content of a .RData file into the workspace, or attach it
sv.r.loadWorkspace = function(file, attach, callback, param) {
- // Ask for the filename if not provided
+ // Ask for the filename if not provided
if (!file) {
file = sv.fileOpen("", ".RData", sv.translate("Browse for R workspace file"),
[sv.translate("R workspace") + " (*.RData)|*.RData"], true);
@@ -707,74 +684,141 @@
}
cmd = cmd.join("\n");
- if (callback)
+ if (callback) {
sv.r.evalCallback(cmd, callback, param);
- else
+ } else {
sv.r.eval(cmd);
+ }
+}
+// Add current command to R's history,
+// used as a procfun in sv.socket.rCommand call
+sv.r.addHistory = function(data, cmd) {
+ if (sv.socket.prompt == ":> ") {
+ var quotedCmd = cmd.trim();
+ quotedCmd = quotedCmd.replace(/([\\"'])/g, "\\$1").replace(/[\r\n]+/,
+ "\\n").replace("\t", " ");
+ sv.socket.rCommand("<<<H>>>" + ".sv.tmp <- strsplit(\"" + quotedCmd +
+ "\", \"\\\\s*([\\r\\n]|<<<n>>>)+\\\\s*\", perl = TRUE)[[1]]; " +
+ ".sv.tmp <- .sv.tmp[.sv.tmp != \"\"]; lapply(.sv.tmp, function(x) " +
+ "{.Internal(addhistory((x))) }); rm(.sv.tmp);", false);
+ }
}
// Save the history in a file
sv.r.saveHistory = function(file, title) {
- // Ask for the filename if not provided
- if (typeof(file) == "undefined") {
- if (typeof(title) == "undefined") { title = 'Save the command history in a file'; }
- file = ko.filepicker.saveFile("", ".Rhistory", title);
- if (file == null) return; // User clicked cancel
- }
- sv.r.eval('savehistory("' + file.addslashes() + '")');
+ // Ask for the filename if not provided
+ if (typeof(file) == "undefined") {
+ if (typeof(title) == "undefined")
+ title = 'Save the command history in a file';
+ file = ko.filepicker.saveFile("", ".Rhistory", title);
+ if (file == null) return; // User clicked cancel
+ }
+ sv.r.eval('savehistory("' + file.addslashes() + '")');
}
// Load the history from a file
sv.r.loadHistory = function(file, title) {
- // Ask for the filename if not provided
- if (typeof(file) == "undefined") {
- if (typeof(title) == "undefined") { title = 'Load the history from a file'; }
- file = ko.filepicker.openFile("", ".Rhistory", title);
- if (file == null) return; // User clicked cancel
- }
- sv.r.eval('loadhistory("' + file.addslashes() + '")');
+ // Ask for the filename if not provided
+ if (typeof(file) == "undefined") {
+ if (typeof(title) == "undefined")
+ title = 'Load the history from a file';
+ file = ko.filepicker.openFile("", ".Rhistory", title);
+ if (file == null) return; // User clicked cancel
+ }
+ sv.r.eval('loadhistory("' + file.addslashes() + '")');
}
// There is also dev.copy2pdf() copy2eps() + savePlot windows and X11(type = "Cairo")
sv.r.saveGraph = function(type, file, title, height, width, method) {
- if (typeof(type) == "undefined") { type = "png256"; }
- // Get the file extension according to type
- var ext = type.substring(0, 4);
- if (ext != "pgnm" & ext != "tiff" & ext != "jpeg") { ext = ext.substring(0, 3); }
- if (ext.substring(0, 2) == "ps") { ext = "ps"; }
- if (ext == "jpeg") { ext = "jpg" }
- if (typeof(height) == "undefined") { height = 'dev.size()[2]'; }
- if (typeof(width) == "undefined") { width = 'dev.size()[1]'; }
- if (typeof(method) == "undefined") { method = "pdf"; }
- // Ask for the filename if not provided
- if (typeof(file) == "undefined") {
- if (typeof(title) == "undefined") { title = 'Save the graph as "' + type + '"'; }
- file = ko.filepicker.saveFile("", "Rplot." + ext, title);
- if (file == null) return; // User clicked cancel
- }
- // Save the current device in R using dev2bitmap()... needs gostscript!
- sv.r.eval('dev2bitmap("' + file.addslashes() + '", type = "' + type + '", height = ' + height +
- ', width = ' + width + ', method = "' + method + '")');
+ if (typeof(type) == "undefined") { type = "png256"; }
+ // Get the file extension according to type
+ var ext = type.substring(0, 4);
+ if (ext != "pgnm" & ext != "tiff" & ext != "jpeg") { ext = ext.substring(0, 3); }
+ if (ext.substring(0, 2) == "ps") { ext = "ps"; }
+ if (ext == "jpeg") { ext = "jpg" }
+ if (typeof(height) == "undefined") { height = 'dev.size()[2]'; }
+ if (typeof(width) == "undefined") { width = 'dev.size()[1]'; }
+ if (typeof(method) == "undefined") { method = "pdf"; }
+ // Ask for the filename if not provided
+ if (typeof(file) == "undefined") {
+ if (typeof(title) == "undefined") { title = 'Save the graph as "' + type + '"'; }
+ file = ko.filepicker.saveFile("", "Rplot." + ext, title);
+ if (file == null) return; // User clicked cancel
+ }
+ // Save the current device in R using dev2bitmap()... needs gostscript!
+ sv.r.eval('dev2bitmap("' + file.addslashes() + '", type = "' + type +
+ '", height = ' + height + ', width = ' + width + ', method = "' + method + '")');
}
+// Quit R (ask to save in save in not defined)
sv.r.quit = function(save) {
- if (typeof(save) == "undefined") {
- // Ask for saving or not
- var response = ko.dialogs.customButtons("Do you want to save the workspace (.RData) " +
- "and the command history (.Rhistory) in the session directory first?",
- ["Yes", "No", "Cancel"], // buttons
- "No", // default response
- null, // text
- "Exiting R"); // title
- if (response == "Cancel") { return; }
- }
- sv.r.eval('q("' + response.toLowerCase() + '")');
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/sciviews -r 177
More information about the Sciviews-commits
mailing list