summaryrefslogtreecommitdiffstats
path: root/lua/snippet
diff options
context:
space:
mode:
authorSquibid <me@zacharyscheiman.com>2024-08-09 02:45:31 -0400
committerSquibid <me@zacharyscheiman.com>2024-08-09 02:45:31 -0400
commitc489d393695e90d424f9ae51e35c4d42358e6a71 (patch)
tree12ea97ec4684fd82cd6b73dd127d0137b115837b /lua/snippet
parentad76983d969c318e6e234bc82384b4b025d70447 (diff)
downloadnvim-c489d393695e90d424f9ae51e35c4d42358e6a71.tar.gz
nvim-c489d393695e90d424f9ae51e35c4d42358e6a71.tar.bz2
nvim-c489d393695e90d424f9ae51e35c4d42358e6a71.zip
yes there's a bit of java in my nvim config why do you ask?
Diffstat (limited to '')
-rw-r--r--lua/snippet/c.lua79
-rw-r--r--lua/snippet/lua.lua14
-rw-r--r--lua/snippet/makefile.lua41
-rw-r--r--lua/snippet/shorthands.lua31
-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
10 files changed, 282 insertions, 165 deletions
diff --git a/lua/snippet/c.lua b/lua/snippet/c.lua
deleted file mode 100644
index 7ef2e51..0000000
--- a/lua/snippet/c.lua
+++ /dev/null
@@ -1,79 +0,0 @@
-ls.add_snippets('c', {
- s('trip', {
- -- cond ? then : else statment
- i(1, 'cond'), t(' ? '), i(2, 'then'), t(' : '), i(3, 'else')
- }),
-
- s('stdlibs', {
- -- the normal stuff
- t('#include <stdio.h>'),
- t({'', '#include <stdlib.h>'})
- }),
-
- s('die', {
- -- message provieder when program is exiting
- t({
- 'void die(const char *fmt, ...) {', '',
- 'va_list ap;',
- '',
- 'va_start(ap, fmt);',
- 'vfprintf(stderr, fmt, ap);',
- 'va_end(ap);',
- '',
- [[if (fmt[0] && fmt[strlen(fmt)-1] == ':') {]],
- [[ fputc(' ', stderr);]],
- ' perror(NULL);',
- '} else',
- [[ fputc('\n', stderr);]],
- ' exit(1);',
- '}',
- })
- }),
-
- s({
- name = 'get them opts!',
- trig = 'getopt',
- dscr = 'standard argument parser',
- },
- fmta(
- [[
- int c;
-
- while ((c = getopt(argc, argv, "<OPTS>")) != -1) {
- switch (c) {
- case '<OPT1>': <OPT1RUN> break;
- default: <DEFRUN> break;
- }
- }
- ]],
- {
- OPTS = i(1, 'h'),
- OPT1 = i(2, 'h'),
- OPT1RUN = i(3, 'printf("help text\\n");'),
- DEFRUN = i(4, 'printf("run %s -h for help\\n", argv[0]); return 1;'),
- }
- )
- ),
- s({
- name = 'Variadic function parser',
- trig = 'infinite vars',
- dscr = 'Parse an infinite number of arguments passed to a function',
- },
- {
- t({
- "/*",
- " * NOTE: the function must have a int before the ... argument",
- " * and you need to include <stdarg.h> for this to work",
- " */",
- "va_list ptr;",
- "va_start(ptr, ", i(1, "n"),
- ");",
- "for (int i = 0; i < ", ri(1),
- "; i++) {",
- i(2),
- "}",
- "va_end(ptr);",
- }),
- }
- )
-})
diff --git a/lua/snippet/lua.lua b/lua/snippet/lua.lua
deleted file mode 100644
index c5466ff..0000000
--- a/lua/snippet/lua.lua
+++ /dev/null
@@ -1,14 +0,0 @@
-ls.add_snippets('lua', {
- s({
- name = "local require",
- trig = "req",
- dscr = "simple lua require"
- },
- fmt("local {} = require('{}')",
- {
- i(1, "default"),
- ri(1),
- }
- )
- )
-})
diff --git a/lua/snippet/makefile.lua b/lua/snippet/makefile.lua
deleted file mode 100644
index d15ef8d..0000000
--- a/lua/snippet/makefile.lua
+++ /dev/null
@@ -1,41 +0,0 @@
-ls.add_snippets('make', {
- s({
- name = "Start Makefile",
- trig = "make",
- dscr = "simple starter make file"
- },
- fmta(
- [[
- # flags and incs
- CFLAGS = <FLAGS>
- INCS = <MAIN>.c
-
- PREFIX = <PREFIX>
-
- # compiler and linker
- CC = cc
-
- all: <MAINA>
- <MAINA>: <MAINA>.o
- $(CC) <MAINA>.o $(CFLAGS) -o $@
- <MAINA>.o: $(INCS)
-
- clean:
- rm -f <MAINA> *.o
-
- install: <MAINA>
- mkdir -p $(PREFIX)/bin
- cp -f <MAINA> $(PREFIX)/bin
- chmod 755 $(PREFIX)/bin/<MAINA>
- uninstall: <MAINA>
- rm -f $(PREFIX)/bin/<MAINA>
- ]],
- {
- FLAGS = i(1, "-Wall"),
- MAIN = i(2, "main"),
- PREFIX = i(3, "/usr/local"),
- MAINA = ri(2),
- }
- )
- ),
-})
diff --git a/lua/snippet/shorthands.lua b/lua/snippet/shorthands.lua
deleted file mode 100644
index 05453bd..0000000
--- a/lua/snippet/shorthands.lua
+++ /dev/null
@@ -1,31 +0,0 @@
-ls = require("luasnip")
-s = ls.snippet
-sn = ls.snippet_node
-isn = ls.indent_snippet_node
-t = ls.text_node
-i = ls.insert_node
-f = ls.function_node
-c = ls.choice_node
-d = ls.dynamic_node
-r = ls.restore_node
-events = require("luasnip.util.events")
-ai = require("luasnip.nodes.absolute_indexer")
-extras = require("luasnip.extras")
-l = extras.lambda
-rep = extras.rep
-p = extras.partial
-m = extras.match
-n = extras.nonempty
-dl = extras.dynamic_lambda
-fmt = require("luasnip.extras.fmt").fmt
-fmta = require("luasnip.extras.fmt").fmta
-conds = require("luasnip.extras.expand_conditions")
-postfix = require("luasnip.extras.postfix").postfix
-types = require("luasnip.util.types")
-parse = require("luasnip.util.parser").parse_snippet
-
--- Repeat Insernode text
--- @param insert_node_id The id of the insert node to repeat (the first line from)
-ri = function (insert_node_id)
- return f(function (args) return args[1][1] end, insert_node_id)
-end
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({ "", "?>" })
+ })
+}