forked from forgejo/forgejo
Update CodeMirror to version 5.49.0 (#8381)
* Update CodeMirror to version 5.49.0 * Update CodeMirror versions in librejs and VERSIONS
This commit is contained in:
parent
6fa14ac3c8
commit
1e9b330525
352 changed files with 14625 additions and 2451 deletions
|
@ -15,7 +15,7 @@
|
|||
.cm-s-default span.cm-arg-is { color: brown; }
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
|
||||
<a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../../index.html">Home</a>
|
||||
|
@ -31,47 +31,50 @@
|
|||
<article>
|
||||
<h2>R mode</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
# Code from http://www.mayin.org/ajayshah/KB/R/
|
||||
X <- list(height = 5.4, weight = 54)
|
||||
cat("Printing objects: "); print(X)
|
||||
print("Accessing individual elements:")
|
||||
cat(sprintf("Your height is %s and your weight is %s\n", X$height, X$weight))
|
||||
|
||||
# FIRST LEARN ABOUT LISTS --
|
||||
X = list(height=5.4, weight=54)
|
||||
print("Use default printing --")
|
||||
print(X)
|
||||
print("Accessing individual elements --")
|
||||
cat("Your height is ", X$height, " and your weight is ", X$weight, "\n")
|
||||
|
||||
# FUNCTIONS --
|
||||
# Functions:
|
||||
square <- function(x) {
|
||||
return(x*x)
|
||||
return(x * x)
|
||||
}
|
||||
cat("The square of 3 is ", square(3), "\n")
|
||||
|
||||
# default value of the arg is set to 5.
|
||||
cube <- function(x=5) {
|
||||
return(x*x*x);
|
||||
}
|
||||
cat("Calling cube with 2 : ", cube(2), "\n") # will give 2^3
|
||||
cat("Calling cube : ", cube(), "\n") # will default to 5^3.
|
||||
|
||||
# LEARN ABOUT FUNCTIONS THAT RETURN MULTIPLE OBJECTS --
|
||||
powers <- function(x) {
|
||||
parcel = list(x2=x*x, x3=x*x*x, x4=x*x*x*x);
|
||||
return(parcel);
|
||||
}
|
||||
|
||||
X = powers(3);
|
||||
print("Showing powers of 3 --"); print(X);
|
||||
|
||||
# WRITING THIS COMPACTLY (4 lines instead of 7)
|
||||
|
||||
powerful <- function(x) {
|
||||
return(list(x2=x*x, x3=x*x*x, x4=x*x*x*x));
|
||||
}
|
||||
print("Showing powers of 3 --"); print(powerful(3));
|
||||
cat(sprintf("The square of 3 is %s\n", square(3)))
|
||||
|
||||
# In R, the last expression in a function is, by default, what is
|
||||
# returned. So you could equally just say:
|
||||
powerful <- function(x) {list(x2=x*x, x3=x*x*x, x4=x*x*x*x)}
|
||||
# returned. The idiomatic way to write the function is:
|
||||
square <- function(x) {
|
||||
x * x
|
||||
}
|
||||
# or, for functions with short content:
|
||||
square <- function(x) x * x
|
||||
|
||||
# Function arguments with default values:
|
||||
cube <- function(x = 5) x * x * x
|
||||
cat(sprintf("Calling cube with 2 : %s\n", cube(2)) # will give 2^3
|
||||
cat(sprintf("Calling cube : %s\n", cube()) # will default to 5^3.
|
||||
|
||||
powers <- function(x) list(x2 = x*x, x3 = x*x*x, x4 = x*x*x*x)
|
||||
|
||||
cat("Powers of 3: "); print(powers(3))
|
||||
|
||||
# Data frames
|
||||
df <- data.frame(letters = letters[1:5], '#letter' = 1:5)
|
||||
print(df$letters)
|
||||
print(df$`#letter`)
|
||||
|
||||
# Operators:
|
||||
m1 <- matrix(1:6, 2, 3)
|
||||
m2 <- m1 %*% t(m1)
|
||||
cat("Matrix product: "); print(m2)
|
||||
|
||||
# Assignments:
|
||||
a <- 1
|
||||
b <<- 2
|
||||
c = 3
|
||||
4 -> d
|
||||
5 ->> e
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
|
||||
|
|
64
public/vendor/plugins/codemirror/mode/r/r.js
vendored
64
public/vendor/plugins/codemirror/mode/r/r.js
vendored
|
@ -1,5 +1,5 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
|
@ -14,15 +14,22 @@
|
|||
CodeMirror.registerHelper("wordChars", "r", /[\w.]/);
|
||||
|
||||
CodeMirror.defineMode("r", function(config) {
|
||||
function wordObj(str) {
|
||||
var words = str.split(" "), res = {};
|
||||
function wordObj(words) {
|
||||
var res = {};
|
||||
for (var i = 0; i < words.length; ++i) res[words[i]] = true;
|
||||
return res;
|
||||
}
|
||||
var atoms = wordObj("NULL NA Inf NaN NA_integer_ NA_real_ NA_complex_ NA_character_");
|
||||
var builtins = wordObj("list quote bquote eval return call parse deparse");
|
||||
var keywords = wordObj("if else repeat while function for in next break");
|
||||
var blockkeywords = wordObj("if else repeat while function for");
|
||||
var commonAtoms = ["NULL", "NA", "Inf", "NaN", "NA_integer_", "NA_real_", "NA_complex_", "NA_character_", "TRUE", "FALSE"];
|
||||
var commonBuiltins = ["list", "quote", "bquote", "eval", "return", "call", "parse", "deparse"];
|
||||
var commonKeywords = ["if", "else", "repeat", "while", "function", "for", "in", "next", "break"];
|
||||
var commonBlockKeywords = ["if", "else", "repeat", "while", "function", "for"];
|
||||
|
||||
CodeMirror.registerHelper("hintWords", "r", commonAtoms.concat(commonBuiltins, commonKeywords));
|
||||
|
||||
var atoms = wordObj(commonAtoms);
|
||||
var builtins = wordObj(commonBuiltins);
|
||||
var keywords = wordObj(commonKeywords);
|
||||
var blockkeywords = wordObj(commonBlockKeywords);
|
||||
var opChars = /[+\-*\/^<>=!&|~$:]/;
|
||||
var curPunc;
|
||||
|
||||
|
@ -44,6 +51,9 @@ CodeMirror.defineMode("r", function(config) {
|
|||
} else if (ch == "'" || ch == '"') {
|
||||
state.tokenize = tokenString(ch);
|
||||
return "string";
|
||||
} else if (ch == "`") {
|
||||
stream.match(/[^`]+`/);
|
||||
return "variable-3";
|
||||
} else if (ch == "." && stream.match(/.[.\d]+/)) {
|
||||
return "keyword";
|
||||
} else if (/[\w\.]/.test(ch) && ch != "_") {
|
||||
|
@ -62,13 +72,17 @@ CodeMirror.defineMode("r", function(config) {
|
|||
return "variable";
|
||||
} else if (ch == "%") {
|
||||
if (stream.skipTo("%")) stream.next();
|
||||
return "variable-2";
|
||||
} else if (ch == "<" && stream.eat("-")) {
|
||||
return "arrow";
|
||||
return "operator variable-2";
|
||||
} else if (
|
||||
(ch == "<" && stream.eat("-")) ||
|
||||
(ch == "<" && stream.match("<-")) ||
|
||||
(ch == "-" && stream.match(/>>?/))
|
||||
) {
|
||||
return "operator arrow";
|
||||
} else if (ch == "=" && state.ctx.argList) {
|
||||
return "arg-is";
|
||||
} else if (opChars.test(ch)) {
|
||||
if (ch == "$") return "dollar";
|
||||
if (ch == "$") return "operator dollar";
|
||||
stream.eatWhile(opChars);
|
||||
return "operator";
|
||||
} else if (/[\(\){}\[\];]/.test(ch)) {
|
||||
|
@ -101,13 +115,23 @@ CodeMirror.defineMode("r", function(config) {
|
|||
};
|
||||
}
|
||||
|
||||
var ALIGN_YES = 1, ALIGN_NO = 2, BRACELESS = 4
|
||||
|
||||
function push(state, type, stream) {
|
||||
state.ctx = {type: type,
|
||||
indent: state.indent,
|
||||
align: null,
|
||||
flags: 0,
|
||||
column: stream.column(),
|
||||
prev: state.ctx};
|
||||
}
|
||||
function setFlag(state, flag) {
|
||||
var ctx = state.ctx
|
||||
state.ctx = {type: ctx.type,
|
||||
indent: ctx.indent,
|
||||
flags: ctx.flags | flag,
|
||||
column: ctx.column,
|
||||
prev: ctx.prev}
|
||||
}
|
||||
function pop(state) {
|
||||
state.indent = state.ctx.indent;
|
||||
state.ctx = state.ctx.prev;
|
||||
|
@ -118,22 +142,22 @@ CodeMirror.defineMode("r", function(config) {
|
|||
return {tokenize: tokenBase,
|
||||
ctx: {type: "top",
|
||||
indent: -config.indentUnit,
|
||||
align: false},
|
||||
flags: ALIGN_NO},
|
||||
indent: 0,
|
||||
afterIdent: false};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (stream.sol()) {
|
||||
if (state.ctx.align == null) state.ctx.align = false;
|
||||
if ((state.ctx.flags & 3) == 0) state.ctx.flags |= ALIGN_NO
|
||||
if (state.ctx.flags & BRACELESS) pop(state)
|
||||
state.indent = stream.indentation();
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
var style = state.tokenize(stream, state);
|
||||
if (style != "comment" && state.ctx.align == null) state.ctx.align = true;
|
||||
if (style != "comment" && (state.ctx.flags & ALIGN_NO) == 0) setFlag(state, ALIGN_YES)
|
||||
|
||||
var ctype = state.ctx.type;
|
||||
if ((curPunc == ";" || curPunc == "{" || curPunc == "}") && ctype == "block") pop(state);
|
||||
if ((curPunc == ";" || curPunc == "{" || curPunc == "}") && state.ctx.type == "block") pop(state);
|
||||
if (curPunc == "{") push(state, "}", stream);
|
||||
else if (curPunc == "(") {
|
||||
push(state, ")", stream);
|
||||
|
@ -141,7 +165,8 @@ CodeMirror.defineMode("r", function(config) {
|
|||
}
|
||||
else if (curPunc == "[") push(state, "]", stream);
|
||||
else if (curPunc == "block") push(state, "block", stream);
|
||||
else if (curPunc == ctype) pop(state);
|
||||
else if (curPunc == state.ctx.type) pop(state);
|
||||
else if (state.ctx.type == "block" && style != "comment") setFlag(state, BRACELESS)
|
||||
state.afterIdent = style == "variable" || style == "keyword";
|
||||
return style;
|
||||
},
|
||||
|
@ -150,8 +175,9 @@ CodeMirror.defineMode("r", function(config) {
|
|||
if (state.tokenize != tokenBase) return 0;
|
||||
var firstChar = textAfter && textAfter.charAt(0), ctx = state.ctx,
|
||||
closing = firstChar == ctx.type;
|
||||
if (ctx.flags & BRACELESS) ctx = ctx.prev
|
||||
if (ctx.type == "block") return ctx.indent + (firstChar == "{" ? 0 : config.indentUnit);
|
||||
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
||||
else if (ctx.flags & ALIGN_YES) return ctx.column + (closing ? 0 : 1);
|
||||
else return ctx.indent + (closing ? 0 : config.indentUnit);
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue