enc: lua format custem

This commit is contained in:
asep.komarudin 2024-06-14 08:40:35 +07:00
parent 65857a4226
commit 384c0b5768
68 changed files with 1450 additions and 1450 deletions

View file

@ -1,44 +1,44 @@
local M = {}
function M.bufremove(buf)
buf = buf or 0
buf = buf == 0 and vim.api.nvim_get_current_buf() or buf
buf = buf or 0
buf = buf == 0 and vim.api.nvim_get_current_buf() or buf
if vim.bo.modified then
local choice = vim.fn.confirm(("Save changes to %q?"):format(vim.fn.bufname()), "&Yes\n&No\n&Cancel")
if choice == 0 then -- Cancel
return
end
if choice == 1 then -- Yes
vim.cmd.write()
end
end
if vim.bo.modified then
local choice = vim.fn.confirm(("Save changes to %q?"):format(vim.fn.bufname()), "&Yes\n&No\n&Cancel")
if choice == 0 then -- Cancel
return
end
if choice == 1 then -- Yes
vim.cmd.write()
end
end
for _, win in ipairs(vim.fn.win_findbuf(buf)) do
vim.api.nvim_win_call(win, function()
if not vim.api.nvim_win_is_valid(win) or vim.api.nvim_win_get_buf(win) ~= buf then
return
end
-- Try using alternate buffer
local alt = vim.fn.bufnr("#")
if alt ~= buf and vim.fn.buflisted(alt) == 1 then
vim.api.nvim_win_set_buf(win, alt)
return
end
for _, win in ipairs(vim.fn.win_findbuf(buf)) do
vim.api.nvim_win_call(win, function()
if not vim.api.nvim_win_is_valid(win) or vim.api.nvim_win_get_buf(win) ~= buf then
return
end
-- Try using alternate buffer
local alt = vim.fn.bufnr("#")
if alt ~= buf and vim.fn.buflisted(alt) == 1 then
vim.api.nvim_win_set_buf(win, alt)
return
end
-- Try using previous buffer
local has_previous = pcall(vim.cmd, "bprevious")
if has_previous and buf ~= vim.api.nvim_win_get_buf(win) then
return
end
-- Try using previous buffer
local has_previous = pcall(vim.cmd, "bprevious")
if has_previous and buf ~= vim.api.nvim_win_get_buf(win) then
return
end
-- Create new listed buffer
local new_buf = vim.api.nvim_create_buf(true, false)
vim.api.nvim_win_set_buf(win, new_buf)
end)
end
if vim.api.nvim_buf_is_valid(buf) then
pcall(vim.cmd, "bdelete! " .. buf)
end
-- Create new listed buffer
local new_buf = vim.api.nvim_create_buf(true, false)
vim.api.nvim_win_set_buf(win, new_buf)
end)
end
if vim.api.nvim_buf_is_valid(buf) then
pcall(vim.cmd, "bdelete! " .. buf)
end
end
return M

View file

@ -2,9 +2,9 @@ local null_ls = require("null-ls")
local M = {}
M.list_registered = function(filetype)
local method = null_ls.methods.FORMATTING
local registered_providers = require("user.utils.lsp").list_registered_providers_names(filetype)
return registered_providers[method] or {}
local method = null_ls.methods.FORMATTING
local registered_providers = require("user.utils.lsp").list_registered_providers_names(filetype)
return registered_providers[method] or {}
end
return M

View file

@ -2,18 +2,18 @@ local null_ls = require("null-ls")
local M = {}
M.alternative_methods = {
null_ls.methods.DIAGNOSTICS,
null_ls.methods.DIAGNOSTICS_ON_OPEN,
null_ls.methods.DIAGNOSTICS_ON_SAVE,
null_ls.methods.DIAGNOSTICS,
null_ls.methods.DIAGNOSTICS_ON_OPEN,
null_ls.methods.DIAGNOSTICS_ON_SAVE,
}
M.linter_list_registered = function(filetype)
local registered_providers = require("user.utils.lsp").list_registered_providers_names(filetype)
local providers_for_methods = vim.iter(vim.tbl_map(function(m)
return registered_providers[m] or {}
end, M.alternative_methods))
local registered_providers = require("user.utils.lsp").list_registered_providers_names(filetype)
local providers_for_methods = vim.iter(vim.tbl_map(function(m)
return registered_providers[m] or {}
end, M.alternative_methods))
return providers_for_methods
return providers_for_methods
end
return M

View file

@ -1,16 +1,16 @@
local M = {}
M.list_registered_providers_names = function(filetype)
local s = require("null-ls.sources")
local available_sources = s.get_available(filetype)
local registered = {}
for _, source in ipairs(available_sources) do
for method in pairs(source.methods) do
registered[method] = registered[method] or {}
table.insert(registered[method], source.name)
end
end
return registered
local s = require("null-ls.sources")
local available_sources = s.get_available(filetype)
local registered = {}
for _, source in ipairs(available_sources) do
for method in pairs(source.methods) do
registered[method] = registered[method] or {}
table.insert(registered[method], source.name)
end
end
return registered
end
return M

View file

@ -1,9 +1,9 @@
local hide_in_width = function()
return vim.fn.winwidth(0) > 75
end
local icons = require "user.icons"
local formatter = require "user.utils.formatter"
local linter = require "user.utils.linter"
local icons = require("user.icons")
local formatter = require("user.utils.formatter")
local linter = require("user.utils.linter")
local getLeftSubstring = function(word, length)
if #word > length then
@ -86,7 +86,7 @@ return {
local buf_ft = vim.bo.filetype
-- start register
local buf_clients = {}
buf_clients = vim.lsp.get_clients { bufnr = 0 }
buf_clients = vim.lsp.get_clients({ bufnr = 0 })
local buf_client_names = {}
if next(buf_clients) == nil then
-- TODO: clean up this if statement

View file

@ -1,6 +1,6 @@
local M = {}
local component = require "user.utils.lualine_component"
local component = require("user.utils.lualine_component")
local treesitter = component.treesitter
local lsp_info = component.lsp_info
local diagnostics = component.diagnostics

View file

@ -3,7 +3,7 @@ local M = {}
-- for debug
local debug_key = {}
if vim.fn.has "win32" == 0 then
if vim.fn.has("win32") == 0 then
debug_key = {
name = "  Debug",
t = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Toggle Breakpoint" },
@ -26,47 +26,47 @@ end
function M._LAZYGIT_TOGGLE()
local Terminal = require("toggleterm.terminal").Terminal
local lazygit = Terminal:new { cmd = "lazygit", hidden = true }
local lazygit = Terminal:new({ cmd = "lazygit", hidden = true })
lazygit:toggle()
end
function M._NODE_TOGGLE()
local Terminal = require("toggleterm.terminal").Terminal
local node = Terminal:new { cmd = "node", hidden = true }
local node = Terminal:new({ cmd = "node", hidden = true })
node:toggle()
end
function M._BTOP_TOGGLE()
local Terminal = require("toggleterm.terminal").Terminal
local htop = Terminal:new { cmd = "btop", hidden = true }
local htop = Terminal:new({ cmd = "btop", hidden = true })
htop:toggle()
end
function M._PYTHON_TOGGLE()
local Terminal = require("toggleterm.terminal").Terminal
local python = Terminal:new { cmd = "python", hidden = true }
local python = Terminal:new({ cmd = "python", hidden = true })
python:toggle()
end
function M._NEWTAB_TOGGLE()
local Terminal = require("toggleterm.terminal").Terminal
local pwsh = Terminal:new { cmd = "pwsh", hidden = true, direction = "tab" }
local pwsh = Terminal:new({ cmd = "pwsh", hidden = true, direction = "tab" })
pwsh:toggle()
end
function M._OPEN_EXPLORER()
local Terminal = require("toggleterm.terminal").Terminal
local pwsh = Terminal:new { cmd = "explorer .", hidden = true, direction = "tab" }
local pwsh = Terminal:new({ cmd = "explorer .", hidden = true, direction = "tab" })
pwsh:toggle()
end
function M._LIVE_SERVER()
local Terminal = require("toggleterm.terminal").Terminal
local live_server = Terminal:new {
local live_server = Terminal:new({
cmd = "live-server",
hidden = true,
direction = "tab",
}
})
live_server:toggle()
end