From ca932c83df8a52da1a7bbe19cf663c9442e4e27c Mon Sep 17 00:00:00 2001 From: Frizzus Date: Tue, 7 Jan 2025 23:35:16 +0100 Subject: [PATCH] nouveau truc --- init.lua | 24 ++---- lua/custom/plugins/custom_init.lua | 15 ++++ lua/custom/plugins/init.lua | 5 -- lua/custom/plugins/snippets.lua | 122 +++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 21 deletions(-) create mode 100644 lua/custom/plugins/custom_init.lua delete mode 100644 lua/custom/plugins/init.lua create mode 100644 lua/custom/plugins/snippets.lua diff --git a/init.lua b/init.lua index f79e3969..471a502f 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,4 @@ --[[ - ===================================================================== ==================== READ THIS BEFORE CONTINUING ==================== ===================================================================== @@ -91,7 +90,7 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false +vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.opt` @@ -157,20 +156,6 @@ vim.opt.cursorline = true -- Minimal number of screen lines to keep above and below the cursor. vim.opt.scrolloff = 10 --- custom settings --- function Test() --- print 'test' --- end --- vim.api.nvim_create_user_command('Test', Test(), {}) -vim.cmd.colorscheme 'retrobox' - -vim.cmd.set 'tabline=no' -vim.cmd.set 'nonumber' -vim.o.tabstop = 4 -vim.o.shiftwidth = 4 -vim.o.expandtab = true --- - -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` @@ -967,3 +952,10 @@ require('lazy').setup({ -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et +local ls = require 'luasnip' +local snippets = require 'custom.plugins.snippets' +require('custom.plugins.custom_init').setup() +ls.add_snippets('tcl', snippets.tcl) +ls.add_snippets('typst', snippets.typst) +ls.add_snippets('c', snippets.c) +ls.add_snippets('cpp', snippets.c_header) diff --git a/lua/custom/plugins/custom_init.lua b/lua/custom/plugins/custom_init.lua new file mode 100644 index 00000000..a1873f8b --- /dev/null +++ b/lua/custom/plugins/custom_init.lua @@ -0,0 +1,15 @@ +return { + setup = function() + -- You can add your own plugins here or in other files in this directory! + -- I promise not to create any merge conflicts in this directory :) + -- + -- See the kickstart.nvim README for more information + vim.cmd.colorscheme 'retrobox' + + vim.cmd.set 'tabline=no' + vim.cmd.set 'nonumber' + vim.o.tabstop = 4 + vim.o.shiftwidth = 4 + vim.o.expandtab = true + end, +} diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua deleted file mode 100644 index be0eb9d8..00000000 --- a/lua/custom/plugins/init.lua +++ /dev/null @@ -1,5 +0,0 @@ --- You can add your own plugins here or in other files in this directory! --- I promise not to create any merge conflicts in this directory :) --- --- See the kickstart.nvim README for more information -return {} diff --git a/lua/custom/plugins/snippets.lua b/lua/custom/plugins/snippets.lua new file mode 100644 index 00000000..3d3ad19e --- /dev/null +++ b/lua/custom/plugins/snippets.lua @@ -0,0 +1,122 @@ +local ls = require 'luasnip' +local s = ls.snippet +local t = ls.text_node +local i = ls.insert_node +local rep = require('luasnip.extras').rep + +return { + -- Snippet pour la déclaration de fonction Tcl + tcl = { + s('proc', { + t 'proc ', -- Texte fixe : "proc " + i(1, 'func'), -- Point d'insertion pour le nom de la fonction, valeur par défaut : "func" + t ' {} {', -- Texte fixe : " {} {" + t { '', '\t' }, -- Nouvelle ligne et indentation + i(2, '# body'), -- Point d'insertion pour le corps de la fonction + t { '', '}' }, -- Nouvelle ligne pour fermer les accolades + }), + s('for', { + t 'for {set i ', -- Texte fixe : "for {set i " + i(1, '0'), -- Point d'insertion pour la valeur initiale (par défaut '0') + t '} {', -- Texte fixe : '} {' + i(2, '$i < 10'), -- Point d'insertion pour la condition (par défaut '$i < 10') + t { '} {incr i} {', '' }, -- Texte fixe : '} {incr i} {' + i(3, '\t# body'), -- Point d'insertion pour le corps de la boucle + t { '', '}' }, -- Texte fixe pour fermer la boucle + }), + s('if', { -- Nom du trigger : "if" + t 'if {', -- Texte statique pour commencer le `if` + i(1, 'cond'), -- Premier champ éditable pour la condition + t '} {', -- Texte statique pour l'ouverture du bloc + t { '', ' ' }, -- Nouvelle ligne avec indentation + i(2, '#body'), -- Deuxième champ éditable pour le corps + t { '', '}' }, -- Nouvelle ligne avec fermeture du bloc + }), + s('foreach', { -- Nom du trigger : "foreach" + t 'foreach {', -- Texte statique pour commencer + i(1, 'var'), -- Premier champ éditable pour la variable + t '} $', -- Espace statique + i(2, 'list'), -- Deuxième champ éditable pour la liste + t ' {', -- Début du bloc + t { '', ' ' }, -- Nouvelle ligne avec indentation + i(3, '#body'), -- Troisième champ éditable pour le corps + t { '', '}' }, -- Nouvelle ligne avec fermeture du bloc + }), + s('unit_test', { + t 'set res ', + i(1, '@'), + t { '', 'set expected ' }, + i(2, '@'), + t { '', 'set name ' }, + i(3, '@'), + t { '', 'if {$res == $expected } {', '' }, + t { '\tputs "test \\#[incr counter] \\"$name\\" passed"} else {', '' }, + t { '\tputs "test \\#[incr counter] \\"$name\\" not passed\\nres : $res\\nexpected : $expected"', '' }, + t '}', + }), + }, + -- Déclaration de snippet typst + typst = { + s('images', { + t { '#figure(caption: "' }, + i(1, 'caption'), + t { '")[', '' }, + t { ' #image("' }, + i(2, 'path'), + t { '")', '' }, + t { ']' }, + }), + }, + c = { + s('main', { + t { '#include ', '', 'int main(int argc, char *argv[]) {' }, + t { '', ' ' }, + i(1, '// Votre code ici'), + t { '', '', ' return 0;', '}' }, + }), + s('if', { + t { 'if (' }, + i(1, 'condition'), + t { ') {', ' ' }, + i(2, '// Code'), + t { '', '}' }, + }), + s('for', { + t { 'for (int ' }, + i(1, 'i = 0'), + t { '; ' }, + i(2, 'i < n'), + t { '; ' }, + i(3, 'i++'), + t { ') {', ' ' }, + i(4, '// Code'), + t { '', '}' }, + }), + s('while', { + t { 'while (' }, + i(1, 'condition'), + t { ') {', ' ' }, + i(2, '// Code'), + t { '', '}' }, + }), + s('func', { + i(1, 'type'), + t { ' ' }, + i(2, 'function_name'), + t { '(' }, + i(3, 'parameters'), + t { ') {', ' ' }, + i(4, '// Code'), + t { '', '}' }, + }), + }, + c_header = { + s('header', { + t { '#ifndef ' }, + i(1, 'FOO'), + t { '', '#define ' }, + rep(1), + t { '', 'int foo(int x); /* An example function declaration */', '', '#endif' }, + }), + }, +}