Use Conform for Java and Python formatting
This commit is contained in:
parent
9037b301ac
commit
a3a2eb2963
|
@ -1,17 +0,0 @@
|
||||||
local macchiato_line_length = 80
|
|
||||||
if (vim.o.textwidth or 0) > 0 then
|
|
||||||
macchiato_line_length = vim.o.textwidth
|
|
||||||
end
|
|
||||||
vim.opt_local.formatprg = 'black-macchiato -l ' .. macchiato_line_length
|
|
||||||
|
|
||||||
vim.keymap.set('n', '<leader>is', function()
|
|
||||||
local bufnr = vim.api.nvim_get_current_buf()
|
|
||||||
local modified = vim.api.nvim_get_option_value("modified", { buf = bufnr })
|
|
||||||
|
|
||||||
if modified then
|
|
||||||
print('*** Save your changes first! ***')
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local file_name = vim.api.nvim_buf_get_name(0) -- Get file name of file in current buffer
|
|
||||||
vim.cmd(":!isort -l 1000000 --wl 0 --sl " .. file_name)
|
|
||||||
end, { desc = 'Run isort on the current buffer' })
|
|
17
init.lua
17
init.lua
|
@ -646,6 +646,7 @@ require('lazy').setup({
|
||||||
|
|
||||||
{ -- Autoformat
|
{ -- Autoformat
|
||||||
'stevearc/conform.nvim',
|
'stevearc/conform.nvim',
|
||||||
|
|
||||||
event = { 'BufWritePre' },
|
event = { 'BufWritePre' },
|
||||||
cmd = { 'ConformInfo' },
|
cmd = { 'ConformInfo' },
|
||||||
keys = {
|
keys = {
|
||||||
|
@ -658,11 +659,25 @@ require('lazy').setup({
|
||||||
desc = '[F]ormat buffer',
|
desc = '[F]ormat buffer',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
-- This will provide type hinting with LuaLS
|
||||||
|
---@module "conform"
|
||||||
|
---@type conform.setupOpts
|
||||||
opts = {
|
opts = {
|
||||||
|
-- log_level = vim.log.levels.DEBUG,
|
||||||
notify_on_error = false,
|
notify_on_error = false,
|
||||||
format_on_save = false,
|
format_on_save = nil, -- Do NOT format when saving a buffer
|
||||||
|
formatters = {
|
||||||
|
isort = {
|
||||||
|
prepend_args = { "-l", "1000000", "--wl", "0", "--sl" }
|
||||||
|
},
|
||||||
|
black = {
|
||||||
|
prepend_args = { "-l", tostring(vim.o.textwidth) },
|
||||||
|
},
|
||||||
|
},
|
||||||
formatters_by_ft = {
|
formatters_by_ft = {
|
||||||
lua = { 'stylua' },
|
lua = { 'stylua' },
|
||||||
|
java = { "google-java-format" },
|
||||||
|
python = { "black", "isort" },
|
||||||
-- Conform can also run multiple formatters sequentially
|
-- Conform can also run multiple formatters sequentially
|
||||||
-- python = { "isort", "black" },
|
-- python = { "isort", "black" },
|
||||||
--
|
--
|
||||||
|
|
Loading…
Reference in New Issue