From 504543e1482bf7564464502ede9b1d266ceb8161 Mon Sep 17 00:00:00 2001 From: T Date: Sun, 6 Apr 2025 13:57:45 -0400 Subject: [PATCH] add formatters --- init.lua | 14 +++++++++++++- resources/clang-format | 12 ++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 resources/clang-format diff --git a/init.lua b/init.lua index 79ace422..88843ef1 100644 --- a/init.lua +++ b/init.lua @@ -128,6 +128,8 @@ vim.api.nvim_create_autocmd('TextYankPost', { end, }) +-- ~/.local/share/nvim +-- This is the location that nvim installs all the plugins -- [[ Install `lazy.nvim` plugin manager ]] -- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' @@ -640,6 +642,8 @@ require('lazy').setup({ local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { 'stylua', -- Used to format Lua code + 'clang-format', -- Need to install venv via `sudo apt install python3.12-venv` + 'black', }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } @@ -680,7 +684,8 @@ require('lazy').setup({ -- Disable "format_on_save lsp_fallback" for languages that don't -- have a well standardized coding style. You can add additional -- languages here or re-enable it for the disabled ones. - local disable_filetypes = { c = true, cpp = true } + -- local disable_filetypes = { c = true, cpp = true } + local disable_filetypes = {} if disable_filetypes[vim.bo[bufnr].filetype] then return nil else @@ -692,12 +697,19 @@ require('lazy').setup({ end, formatters_by_ft = { lua = { 'stylua' }, + c = { 'clang-format' }, + python = { 'black' }, -- Conform can also run multiple formatters sequentially -- python = { "isort", "black" }, -- -- You can use 'stop_after_first' to run the first available formatter from the list -- javascript = { "prettierd", "prettier", stop_after_first = true }, }, + formatters = { + ['clang-format'] = { + prepend_args = { '--style=file', '--fallback-style=LLVM' }, + }, + }, }, }, diff --git a/resources/clang-format b/resources/clang-format new file mode 100644 index 00000000..b8e705b0 --- /dev/null +++ b/resources/clang-format @@ -0,0 +1,12 @@ +--- +# We'll use defaults from the LLVM style, but with 4 columns indentation. +BasedOnStyle: LLVM +IndentWidth: 4 +TabWidth: 4 +UseTab: Never +ColumnLimit: 100 +--- +Language: C +PointerAlignment: Left +BreakBeforeBraces: Attach +AlignAfterOpenBracket: BlockIndent