[education/rkward/snippets] rkward: RKWardR.xml and fixes in RKWardRMd.xm
Stefan Rödiger
null at kde.org
Sun Jun 19 00:42:12 BST 2022
Git commit 14357f9b90b7c2ace894b1d35e9c0e47b1aeeeda by Stefan Rödiger.
Committed on 18/06/2022 at 23:41.
Pushed by srodiger into branch 'snippets'.
RKWardR.xml and fixes in RKWardRMd.xm
M +1 -0 rkward/CMakeLists.txt
A +87 -0 rkward/RKWardR.xml
M +34 -98 rkward/RKWardRMd.xml
https://invent.kde.org/education/rkward/commit/14357f9b90b7c2ace894b1d35e9c0e47b1aeeeda
diff --git a/rkward/CMakeLists.txt b/rkward/CMakeLists.txt
index a5f949c9..94694d84 100644
--- a/rkward/CMakeLists.txt
+++ b/rkward/CMakeLists.txt
@@ -127,3 +127,4 @@ ENDIF(SharedMimeInfo_FOUND)
INSTALL(FILES RKWardRMd.xml DESTINATION ${DATA_INSTALL_DIR}/ktexteditor_snippets/data)
INSTALL(FILES RKWardLaTeX.xml DESTINATION ${DATA_INSTALL_DIR}/ktexteditor_snippets/data)
INSTALL(FILES RKWardYAML.xml DESTINATION ${DATA_INSTALL_DIR}/ktexteditor_snippets/data)
+INSTALL(FILES RKWardR.xml DESTINATION ${DATA_INSTALL_DIR}/ktexteditor_snippets/data)
diff --git a/rkward/RKWardR.xml b/rkward/RKWardR.xml
new file mode 100644
index 00000000..54f23733
--- /dev/null
+++ b/rkward/RKWardR.xml
@@ -0,0 +1,87 @@
+<snippets name="LaTeX (RKWard)" filetypes="tex" authors="RKWard Team" namespace="SnippetsLaTeX" license="BSD">
+ <script>require("range.js")
+require("cursor.js")
+require("document.js")
+require("view.js")
+
+function fileName() { return document.fileName(); }
+function encoding() { return document.encoding(); }
+function year() { return new Date().getFullYear(); }
+function upper(x) { return x.toUpperCase(); }
+function lower(x) { return x.toLowerCase(); }
+function braces(text) { return "{" + text + "}"; }
+function lineCommand(command, replaces="", label_if_empty="Heading") {
+ let c = view.cursorPosition();
+ // NOTE: snippet scripts work by 1. inserting the raw snippet as a raw "template" 2. evaluating any commands inside the template 3. replacing the template with the evaluated template. As a result, when this function gets called, it contains the call to itself...
+ let line = document.line(c.line).replace(/\$\{lineCommand\s*\([^\}]*\}/g, "");
+ line = line.replace(new RegExp(replaces), "");
+ if (line == "") line = label_if_empty;
+ else document.removeLine(c.line);
+ return command + " " + line + "\n";
+}
+
+function rangeCommand(command, def) {
+ if (view.selectedText().length > 0) {
+ return command.replace("%%1", view.selectedText());
+ } else {
+ return command.replace("%%1", def);
+ }
+}
+</script>
+ <item>
+ <match>Newline</match>
+ <fillin>\newline</fillin>
+ </item>
+ <item>
+ <match>x=y</match>
+ <fillin>$x = y$</fillin>
+ </item>
+ <item>
+ <match>α Α</match>
+ <fillin>$\alpha A$</fillin>
+ </item>
+ <item>
+ <match>|A|</match>
+ <fillin>$|A|$</fillin>
+ </item>
+ <item>
+ <match>x∈A</match>
+ <fillin>$x \in A$</fillin>
+ </item>
+ <item>
+ <match>P(A∣B)</match>
+ <fillin>$P(A \mid B)$</fillin>
+ </item>
+ <item>
+ <match>Overlined</match>
+ <fillin>$\overline{x}$</fillin>
+ </item>
+ <item>
+ <match>Hat</match>
+ <fillin>$\hat{x}$</fillin>
+ </item>
+ <item>
+ <match>Tile</match>
+ <fillin>$\tilde{x}$</fillin>
+ </item>
+ <item>
+ <match>Subset</match>
+ <fillin>$x \subset B$</fillin>
+ </item>
+ <item>
+ <match>Subset equal</match>
+ <fillin>$x \subseteq B$</fillin>
+ </item>
+ <item>
+ <match>Or</match>
+ <fillin>$A \cup B$</fillin>
+ </item>
+ <item>
+ <match>And</match>
+ <fillin>$A \cap B$</fillin>
+ </item>
+ <item>
+ <match>And</match>
+ <fillin>$A \cap B$</fillin>
+ </item>
+</snippets>
diff --git a/rkward/RKWardRMd.xml b/rkward/RKWardRMd.xml
index 4e50221e..88fdfd5b 100644
--- a/rkward/RKWardRMd.xml
+++ b/rkward/RKWardRMd.xml
@@ -1,4 +1,4 @@
-<snippets name="R Markdown (RKWard)" filetypes="R Markdown" authors="RKWard Team" namespace="SnippetsRmd" license="BSD">
+<snippets name="R (RKWard)" filetypes="R" authors="RKWard Team" namespace="SnippetsR" license="BSD">
<script>require("range.js")
require("cursor.js")
require("document.js")
@@ -29,121 +29,57 @@ function rangeCommand(command, def) {
}
</script>
<item>
- <match>Heading1</match>
- <fillin>${lineCommand("#", "^#+ ", "Heading")}</fillin>
- </item>
- <item>
- <match>Heading2</match>
- <fillin>${lineCommand("##", "^#+ ", "Heading")}</fillin>
- </item>
- <item>
- <match>Heading3</match>
- <fillin>${lineCommand("###", "^#+ ", "Heading")}</fillin>
- </item>
- <item>
- <match>List (Unordered)</match>
- <fillin>${rangeCommand("\n- A\n- B\n- C\n\n")}</fillin>
- </item>
- <item>
- <match>List (Ordered)</match>
- <fillin>${rangeCommand("\n1. A\n2. B\n3. C\n\n")}</fillin>
- </item>
- <item>
- <match>List (Unordered & Nested)</match>
- <fillin>${rangeCommand("\n- A\n - a\n- B\n - b\n- C\n - c\n\n")}</fillin>
- </item>
- <item>
- <match>Bold</match>
- <fillin>${rangeCommand("**%%1**", "Bold")}</fillin>
- </item>
- <item>
- <match>Italics</match>
- <fillin>${rangeCommand("*%%1*", "Italics")}</fillin>
- </item>
- <item>
- <match>Superscript</match>
- <fillin>${rangeCommand("\n$A^2^$\n")}</fillin>
- </item>
- <item>
- <match>Subscript</match>
- <fillin>${rangeCommand("\n$H~2~O$\n")}</fillin>
- </item>
- <item>
- <match>En dash</match>
- <fillin>--</fillin>
- </item>
- <item>
- <match>Em dash</match>
- <fillin>---</fillin>
- </item>
- <item>
- <match>Equation (inline)</match>
+ <match>Figure as PDF</match>
<fillin>
-$e^${braces("i\\pi")} + 1$
-</fillin>
+pdf(filename="myplot.pdf", width=5, height=5)
+plot(rnorm(100))
+dev.off()
+ </fillin>
</item>
<item>
- <match>Equation (block)</match>
+ <match>Plotting area (3x3 array)</match>
<fillin>
-$$e^${braces("i\\pi")} + 1$$
-</fillin>
- </item>
- <item>
- <match>Strikethrough</match>
- <fillin>${rangeCommand("~~%%1~~", "Strikethrough")}</fillin>
- </item>
- <item>
- <match>Link</match>
- <fillin>${rangeCommand("(title)[%%1]", "URL")}</fillin>
- </item>
- <item>
- <match>rmarkdown::render()</match>
- <fillin>rmarkdown::render()</fillin>
- </item>
- <item>
- <match>Code (inline)</match>
- <fillin>${rangeCommand("`r %%1`", "paste(\"The sum of 1 to 1000 is\", sum(1L:1000))")}</fillin>
- </item>
- <item>
- <match>Code (simple chunk)</match>
- <fillin>${rangeCommand("\n```"+ braces("r") +" %%1```\n", "\nx <- 1\n\n")}</fillin>
+# Plotting area (3x3 array) with 3 rows and 3 columns
+par(mfrow=c(3,3))
+ </fillin>
</item>
<item>
- <match>Quote</match>
- <fillin>${rangeCommand("> %%1", "Text")}</fillin>
+ <match>Matrix multiplication</match>
+ <fillin>
+%*%
+ </fillin>
</item>
<item>
- <match>Code (chunk with defaults)</match>
- <fillin>${rangeCommand("\n```"+ braces("r, echo = FALSE, eval = FALSE, fig.show = \"hide\", include = FALSE, message = FALSE, results = \"hide\", warning = FALSE") +" %%1```\n", "\nx <- 1\n\n")}</fillin>
+ <match>Concatenate vectors after converting to character</match>
+ <fillin>
+paste(…, sep = " ", collapse = NULL)
+ </fillin>
</item>
<item>
- <match>Table</match>
+ <match>for loop</match>
<fillin>
-| Right | Left | Default | Center |
-|-------:|:------|-----------|:---------:|
-| 12 | 12 | 12 | 12 |
-| 123 | 123 | 123 | 123 |
-| 1 | 1 | 1 | 1 |
+# Print for 10 capital LETTERS
+for(i in 1:10){
+ print(LETTERS[i])
+}
</fillin>
</item>
<item>
- <match>Table with caption</match>
+ <match>while loop</match>
<fillin>
-| Right | Left | Default | Center |
-|-------:|:------|-----------|:---------:|
-| 12 | 12 | 12 | 12 |
-| 123 | 123 | 123 | 123 |
-| 1 | 1 | 1 | 1 |
-:Caption text
+while(condition){
+ Do something
+}
</fillin>
</item>
<item>
- <match>Table (kable)</match>
+ <match>ifelse statement</match>
<fillin>
-```{r}
-data <- iris[1:4, ]
-knitr::kable(data, caption = "Table caption text.")
-```
+if (condition){
+ Do something
+ } else {
+ Do something different
+ }
</fillin>
</item>
-</snippets>
+ </snippets>
More information about the rkward-tracker
mailing list