From 4e31578c1e4b9e989cec824e3e832ac2aa66efcd Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Mon, 17 Mar 2025 15:43:07 +0100 Subject: checkpoint --- after/ftplugin/c.lua | 6 ++++-- init.lua | 1 + lua/config/lsp.lua | 12 +++++++----- lua/config/map.lua | 3 +++ lua/config/projects.lua | 24 ++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 lua/config/projects.lua diff --git a/after/ftplugin/c.lua b/after/ftplugin/c.lua index af85156..df01cb4 100644 --- a/after/ftplugin/c.lua +++ b/after/ftplugin/c.lua @@ -16,13 +16,15 @@ map("n", ",i", function() vim.cmd("normal ''") end, { desc = "Include header for word under cursor" }) map("n", ",f", mapcmd("CF"), { desc = "Toggle formatting" }) -map("n", "", mapcmd("make"), { desc = "Make" }) map("i", "", "#if 1#endifO", { desc = "Insert `#if 1` block" }) vim.opt.commentstring = "// %s" -- disable indent in switch statement vim.opt.cinoptions = "l1" -vim.bo.makeprg = "./build.sh" +local projects = require("config.projects") +if projects and not projects.InProject then + vim.bo.makeprg = "./build.sh" +end vim.cmd("TSDisable indent") diff --git a/init.lua b/init.lua index 320638f..5185f90 100644 --- a/init.lua +++ b/init.lua @@ -3,3 +3,4 @@ require("config.set") require("config.map") require("config.lsp") require("config.autocmds") +require("config.projects") diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 49f415f..10235bf 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -143,14 +143,16 @@ ls.add_snippets("c", { parse_snippet( "uints", [[#include -typedef uint8_t u8; +typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; -typedef int8_t s8; -typedef int16_t s16; -typedef int32_t s32; -typedef int64_t s64; +typedef int8_t i8; +typedef int16_t i16; +typedef int32_t i32; +typedef int64_t i64; +typedef float f32; +typedef double f64; ]] ), }) diff --git a/lua/config/map.lua b/lua/config/map.lua index 7dcf82a..a39f362 100644 --- a/lua/config/map.lua +++ b/lua/config/map.lua @@ -4,6 +4,7 @@ local map = vim.keymap.set vim.g.mapleader = " " vim.g.maplocalleader = "," + -- open config map("n", " c", function() vim.cmd("cd ~/.config/nvim") @@ -13,6 +14,8 @@ end, { desc = "Open neovim config file" }) map("v", "J", ":m '>+1gv=gv", { desc = "Move selected text up" }) map("v", "K", ":m '<-2gv=gv", { desc = "Move selected text down" }) +map("n", "", "make", { desc = "Make" }) + -- better find next and previous map("n", "n", "nzzzv", { desc = "Keep cursor in middle with search" }) map("n", "N", "Nzzzv", { desc = "Keep cursor in middle with search" }) diff --git a/lua/config/projects.lua b/lua/config/projects.lua new file mode 100644 index 0000000..0b81def --- /dev/null +++ b/lua/config/projects.lua @@ -0,0 +1,24 @@ +local M = {} + +local HOME = os.getenv("HOME") +local CWD = vim.fn.getcwd() + +M.Projects = { + MetaC = { + Path = HOME .. "/proj/metac", + Options = function() + vim.o.makeprg = M.Projects.MetaC.Path .. "/misc/build.sh" + end, + }, +} + +M.InProject = false + +for At, Project in pairs(M.Projects) do + if string.find(CWD, Project.Path) then + M.InProject = true + Project.Options() + end +end + +return M -- cgit v1.2.3