summaryrefslogtreecommitdiffstats
path: root/lua/core/snippets/c.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lua/core/snippets/c.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/lua/core/snippets/c.lua b/lua/core/snippets/c.lua
new file mode 100644
index 0000000..c45f556
--- /dev/null
+++ b/lua/core/snippets/c.lua
@@ -0,0 +1,29 @@
+ls.add_snippets('c', {
+ s('trip', {
+ -- cond ? then : else statment
+ i(1, 'cond'), t(' ? '), i(2, 'then'), t(' : '), i(3, 'else')
+ }),
+ s('stdlibs', {
+ -- cond ? then : else statment
+ t('#include <stdio.h>'),
+ t({'', '#include <stdlib.h>'})
+ }),
+ s('die', {
+ 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);',
+ '}',
+ })
+ })
+})