[education/rkward] rkward: Initial support for papaja package

Stefan Rödiger null at kde.org
Mon Jul 4 12:25:57 BST 2022


Git commit e37d0c22abfda64951c3fd1e647418da7174ff3e by Stefan Rödiger.
Committed on 25/06/2022 at 11:07.
Pushed by srodiger into branch 'master'.

Initial support for papaja package

A  +35   -0    rkward/RKWardpapaja.xml

https://invent.kde.org/education/rkward/commit/e37d0c22abfda64951c3fd1e647418da7174ff3e

diff --git a/rkward/RKWardpapaja.xml b/rkward/RKWardpapaja.xml
new file mode 100644
index 00000000..7571e2db
--- /dev/null
+++ b/rkward/RKWardpapaja.xml
@@ -0,0 +1,35 @@
+<snippets name="papaja (RKWard)" filetypes="R Markdown" authors="RKWard Team" namespace="Snippetspapaja" 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>apa_print (papaja)</match>
+  <fillin>${rangeCommand("papaja::apa_print(%%1)", "\"A model object\"")}</fillin>
+ </item>
+</snippets>



More information about the rkward-tracker mailing list