summaryrefslogtreecommitdiffstats
path: root/lua/snippets
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lua/snippets/c.lua48
-rw-r--r--lua/snippets/java.lua110
-rw-r--r--lua/snippets/make.lua47
-rw-r--r--lua/snippets/norg.lua28
-rw-r--r--lua/snippets/openscad.lua40
-rw-r--r--lua/snippets/php.lua9
6 files changed, 282 insertions, 0 deletions
diff --git a/lua/snippets/c.lua b/lua/snippets/c.lua
new file mode 100644
index 0000000..b1ca713
--- /dev/null
+++ b/lua/snippets/c.lua
@@ -0,0 +1,48 @@
+require('core.snippets.shorthands')
+
+return {
+ -- method snippet
+ s("main", {
+ c(1, {
+ t(""),
+ t("static "),
+ }),
+ t("int "),
+ t("main"),
+ t("("),
+ c(2, {
+ t("int argc, char *argv[]"),
+ i(1, "void"),
+ }),
+ t(")"),
+ t({ " {", "\t" }),
+ i(0),
+ t({ "", "}" }),
+ }),
+
+ -- function snippet
+ s("fn", {
+ c(1, {
+ t("void"),
+ t("char"),
+ t("int"),
+ t("short"),
+ t("long"),
+ t("double"),
+ t("float"),
+ i(nil, "myType"),
+ }),
+ t({ "", "" }),
+ c(2, {
+ t(""),
+ t("*")
+ }),
+ i(3, "myFunc");
+ t("("),
+ i(4),
+ t(")"),
+ t({ "", "{", "\t" }),
+ i(0),
+ t({ "", "}" }),
+})
+}
diff --git a/lua/snippets/java.lua b/lua/snippets/java.lua
new file mode 100644
index 0000000..8424628
--- /dev/null
+++ b/lua/snippets/java.lua
@@ -0,0 +1,110 @@
+require('core.snippets.shorthands')
+
+local function file_name(args, parent, user_args)
+ return vim.fn.expand("%:t:r")
+end
+
+return {
+ -- method snippet
+ s("fn", {
+ c(1, {
+ t("public "),
+ t("private "),
+ }),
+ c(2, {
+ t("void"),
+ t("String"),
+ t("char"),
+ t("int"),
+ t("double"),
+ t("boolean"),
+ i(nil, "myType"),
+ }),
+ t(" "),
+ i(3, "myFunc"),
+ t("("),
+ i(4),
+ t(")"),
+ c(5, {
+ t(""),
+ sn(nil, {t({ "", " throws " }), i(1)}),
+ }),
+ t({ " {", "\t" }),
+ i(0),
+ t({ "", "}" }),
+ }),
+
+ -- constructor snippet
+ s("constr", {
+ c(1, {
+ t("public "),
+ t("private "),
+ t("protected ")
+ }),
+ f(file_name, {}),
+ t("("),
+ i(2),
+ t(")"),
+ c(3, {
+ t(""),
+ sn(nil, {t({ "", " throws " }), i(1)}),
+ }),
+ t({ " {", "\t" }),
+ i(0),
+ t({ "", "}" }),
+ }),
+
+ -- class snippet
+ s("class", {
+ c(1, {
+ t("public "),
+ t("private "),
+ t("protected ")
+ }),
+ c(2, {
+ t("class "),
+ t("interface ")
+ }),
+ f(file_name, {}),
+ c(3, {
+ t(" "),
+ sn(nil, { t({" implements "}), i(1), t(" ") }),
+ sn(nil, { t({" extends "}), i(1), t(" ") }),
+ }),
+ t({ "{", "\t" }),
+ i(0),
+ t({ "", "}" }),
+ }),
+
+ -- pacakge snippet
+ s("package", {
+ t("package "),
+ f(function(args, parent, user_args)
+ -- get path
+ local dir = vim.fn.expand("%:h")
+ -- remove prefix
+ dir = dir:gsub("src/main/java/", "")
+ -- convert to package path
+ dir = dir:gsub("/", ".")
+
+ return dir
+ end, {}),
+ t(";"),
+ t({ "", "", "" })
+ }),
+
+ -- try, catch, finally snippet
+ s("try", {
+ t({"try {", "\t"}),
+ i(1),
+ t({"", "} catch ("}),
+ i(2, "Error e"),
+ t({") {", "\t"}),
+ i(3),
+ t({"", "}"}),
+ c(4, {
+ t(""),
+ sn(nil, { t({" finally {", "\t"}), i(1), t({"", "}"}) })
+ })
+ })
+}
diff --git a/lua/snippets/make.lua b/lua/snippets/make.lua
new file mode 100644
index 0000000..fefdf92
--- /dev/null
+++ b/lua/snippets/make.lua
@@ -0,0 +1,47 @@
+require('core.snippets.shorthands')
+
+return {
+ -- basic make template snippet
+ s("make", {
+ t({ "PKG_CONFIG = pkg-config", "CC = cc", "VERSION = " }),
+ i(1, "0.1"),
+ t({ "", "", "# flags and incs", "PKGS = " }),
+ i(2),
+ t({ "", "CFLAGS = -DVERSION=\\\"$(VERSION)\\\" -Wall" }),
+ i(3),
+ t({ "", "LIBS = `$(PKG_CONFIG) --libs --cflags $(PKGS)`" }),
+ i(4),
+ t({ "", "", "PREFIX = " }),
+ i(5, "/usr/local"),
+ t({ "", "MANDIR = $(PREFIX)/share/man" }),
+ t({ "", "", "all: " }),
+ i(6, "main"),
+ t({ "", "" }),
+ rep(6),
+ t(": "),
+ rep(6),
+ t({ ".o", "\t$(CC) *.o $(CFLAGS) $(LIBS) -o $@", "" }),
+ rep(6),
+ t(".o: "),
+ rep(6),
+ t({ ".c", "", "clean:", "\trm -f " }),
+ rep(6),
+ t({ " *.o", "", "install: " }),
+ rep(6),
+ t({ "", "\tmkdir -p $(PREFIX)/bin", "\tcp -f " }),
+ rep(6),
+ t({ " $(PREFIX)/bin", "\tchmod 755 $(PREFIX)/bin/" }),
+ rep(6),
+ t({ "", "\tmkdir -p $(MANDIR)/man1", "\tcp -f " }),
+ rep(6),
+ t({ ".1 $(MANDIR)/man1", "\tchmod 644 $(MANDIR)/man1/" }),
+ rep(6),
+ t({ ".1", "", "uninstall: " }),
+ rep(6),
+ t({ "", "\trm -f $(PREFIX)/bin/" }),
+ rep(6),
+ t(" $(MANDIR)/man1/"),
+ rep(6),
+ t(".1")
+ })
+}
diff --git a/lua/snippets/norg.lua b/lua/snippets/norg.lua
new file mode 100644
index 0000000..d96a471
--- /dev/null
+++ b/lua/snippets/norg.lua
@@ -0,0 +1,28 @@
+require('core.snippets.shorthands')
+
+local function file_name(args, parent, user_args)
+ return vim.fn.expand("%:t:r")
+end
+
+return {
+ -- header level 1, usually this has the same name as the file
+ s("h1", {
+ t("* "),
+ c(1, {
+ f(file_name, {}),
+ i(1, "header")
+ })
+ }),
+
+ -- link snippet
+ s("link", {
+ t("{"),
+ c(1, {
+ sn(nil, { t({":$/"}), i(1, "path to file"), t(":") }),
+ i(1, "https://example.com")
+ }),
+ t("}["),
+ i(2, "description"),
+ t("]")
+ })
+}
diff --git a/lua/snippets/openscad.lua b/lua/snippets/openscad.lua
new file mode 100644
index 0000000..c430f2d
--- /dev/null
+++ b/lua/snippets/openscad.lua
@@ -0,0 +1,40 @@
+require('core.snippets.shorthands')
+
+return {
+ -- translate snippet
+ s("t", {
+ t("translate([ "),
+ i(1, "0"),
+ t(", "),
+ i(2, "0"),
+ t(", "),
+ i(3, "0"),
+ t({ " ]) {", "\t" }),
+ i(0),
+ t({ "", "}" })
+ }),
+
+ -- rotate snippet
+ s("r", {
+ t("rotate([ "),
+ i(1, "0"),
+ t(", "),
+ i(2, "0"),
+ t(", "),
+ i(3, "0"),
+ t({ " ]) {", "\t" }),
+ i(0),
+ t({ "", "}" })
+ }),
+
+ -- cube snippet
+ s("c", {
+ t("cube([ "),
+ i(1, "0"),
+ t(", "),
+ i(2, "0"),
+ t(", "),
+ i(3, "0"),
+ t(" ]);")
+ }),
+}
diff --git a/lua/snippets/php.lua b/lua/snippets/php.lua
new file mode 100644
index 0000000..93713a4
--- /dev/null
+++ b/lua/snippets/php.lua
@@ -0,0 +1,9 @@
+require('core.snippets.shorthands')
+
+return {
+ s("php", {
+ t({ "<?php", "\t" }),
+ i(1),
+ t({ "", "?>" })
+ })
+}