summaryrefslogtreecommitdiff
path: root/lua/lvim/core
diff options
context:
space:
mode:
Diffstat (limited to 'lua/lvim/core')
-rw-r--r--lua/lvim/core/alpha.lua28
-rw-r--r--lua/lvim/core/alpha/dashboard.lua13
-rw-r--r--lua/lvim/core/autocmds.lua167
-rw-r--r--lua/lvim/core/bufferline.lua6
-rw-r--r--lua/lvim/core/commands.lua78
-rw-r--r--lua/lvim/core/dap.lua2
-rw-r--r--lua/lvim/core/log.lua17
-rw-r--r--lua/lvim/core/telescope.lua8
-rw-r--r--lua/lvim/core/treesitter.lua7
-rw-r--r--lua/lvim/core/which-key.lua3
10 files changed, 209 insertions, 120 deletions
diff --git a/lua/lvim/core/alpha.lua b/lua/lvim/core/alpha.lua
index 7612854b..fd637818 100644
--- a/lua/lvim/core/alpha.lua
+++ b/lua/lvim/core/alpha.lua
@@ -47,23 +47,21 @@ local function resolve_config(theme_name)
end
local function configure_additional_autocmds()
- local aucmds = {
- {
- "FileType",
- "alpha",
- "set showtabline=0 | autocmd BufLeave <buffer> set showtabline=" .. vim.opt.showtabline._value,
- },
- }
+ local group = "_dashboard_settings"
+ vim.api.nvim_create_augroup(group, {})
+ vim.api.nvim_create_autocmd("FileType", {
+ group = group,
+ pattern = "alpha",
+ command = "set showtabline=0 | autocmd BufLeave <buffer> set showtabline=" .. vim.opt.showtabline._value,
+ })
if not lvim.builtin.lualine.options.globalstatus then
- aucmds[#aucmds + 1] =
- -- https://github.com/goolord/alpha-nvim/issues/42
- {
- "FileType",
- "alpha",
- "set laststatus=0 | autocmd BufUnload <buffer> set laststatus=" .. vim.opt.laststatus._value,
- }
+ -- https://github.com/goolord/alpha-nvim/issues/42
+ vim.api.nvim_create_autocmd("FileType", {
+ group = group,
+ pattern = "alpha",
+ command = "set laststatus=0 | autocmd BufUnload <buffer> set laststatus=" .. vim.opt.laststatus._value,
+ })
end
- require("lvim.core.autocmds").define_augroups { _alpha = aucmds }
end
function M.setup()
diff --git a/lua/lvim/core/alpha/dashboard.lua b/lua/lvim/core/alpha/dashboard.lua
index 010d8c1a..d65980fb 100644
--- a/lua/lvim/core/alpha/dashboard.lua
+++ b/lua/lvim/core/alpha/dashboard.lua
@@ -34,16 +34,7 @@ function M.get_sections()
}
local text = require "lvim.interface.text"
- local git_utils = require "lvim.utils.git"
-
- local current_branch = git_utils.get_lvim_branch()
-
- local lvim_version
- if current_branch ~= "HEAD" or "" then
- lvim_version = current_branch .. "-" .. git_utils.get_lvim_current_sha()
- else
- lvim_version = "v" .. git_utils.get_lvim_tag()
- end
+ local lvim_version = require("lvim.utils.git").get_lvim_version()
local footer = {
type = "text",
@@ -68,7 +59,7 @@ function M.get_sections()
{
"SPC L c",
" Configuration",
- "<CMD>edit " .. require("lvim.config").get_user_config_path() .. " <CR>",
+ "<CMD>edit " .. require("lvim.config"):get_user_config_path() .. " <CR>",
},
},
}
diff --git a/lua/lvim/core/autocmds.lua b/lua/lvim/core/autocmds.lua
index 64b0a9b9..0ca21439 100644
--- a/lua/lvim/core/autocmds.lua
+++ b/lua/lvim/core/autocmds.lua
@@ -2,7 +2,7 @@ local M = {}
local Log = require "lvim.core.log"
--- Load the default set of autogroups and autocommands.
-function M.load_augroups()
+function M.load_defaults()
local user_config_file = require("lvim.config"):get_user_config_path()
if vim.loop.os_uname().version:match "Windows" then
@@ -10,51 +10,72 @@ function M.load_augroups()
user_config_file = user_config_file:gsub("\\", "/")
end
- return {
- _general_settings = {
- { "FileType", "qf,help,man", "nnoremap <silent> <buffer> q :close<CR>" },
+ local definitions = {
+ {
+ "TextYankPost",
{
- "TextYankPost",
- "*",
- "lua require('vim.highlight').on_yank({higroup = 'Search', timeout = 200})",
+ group = "_general_settings",
+ pattern = "*",
+ desc = "Highlight text on yank",
+ callback = function()
+ require("vim.highlight").on_yank { higroup = "Search", timeout = 200 }
+ end,
},
+ },
+ {
+ "BufWritePost",
{
- "BufWinEnter",
- "dashboard",
- "setlocal cursorline signcolumn=yes cursorcolumn number",
+ group = "_general_settings",
+ pattern = user_config_file,
+ desc = "Trigger LvimReload on saving " .. vim.fn.expand "%:~",
+ callback = function()
+ require("lvim.config"):reload()
+ end,
},
- { "BufWritePost", user_config_file, "lua require('lvim.config'):reload()" },
- { "FileType", "qf", "set nobuflisted" },
- -- { "VimLeavePre", "*", "set title set titleold=" },
},
- _formatoptions = {
+ {
+ "FileType",
{
- "BufWinEnter,BufRead,BufNewFile",
- "*",
- "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
+ group = "_filetype_settings",
+ pattern = "qf",
+ command = "set nobuflisted",
},
},
- _filetypechanges = {},
- _git = {
- { "FileType", "gitcommit", "setlocal wrap" },
- { "FileType", "gitcommit", "setlocal spell" },
- },
- _markdown = {
- { "FileType", "markdown", "setlocal wrap" },
- { "FileType", "markdown", "setlocal spell" },
+ {
+ "FileType",
+ {
+ group = "_filetype_settings",
+ pattern = { "gitcommit", "markdown" },
+ command = "setlocal wrap spell",
+ },
},
- _buffer_bindings = {
- { "FileType", "floaterm", "nnoremap <silent> <buffer> q :q<CR>" },
+ {
+ "FileType",
+ {
+ group = "_buffer_mappings",
+ pattern = { "qf", "help", "man", "floaterm", "lspinfo", "lsp-installer", "null-ls-info" },
+ command = "nnoremap <silent> <buffer> q :close<CR>",
+ },
},
- _auto_resize = {
- -- will cause split windows to be resized evenly if main window is resized
- { "VimResized", "*", "tabdo wincmd =" },
+ {
+ { "BufWinEnter", "BufRead", "BufNewFile" },
+ {
+ group = "_format_options",
+ pattern = "*",
+ command = "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
+ },
},
- _general_lsp = {
- { "FileType", "lspinfo,lsp-installer,null-ls-info", "nnoremap <silent> <buffer> q :close<CR>" },
+ {
+ "VimResized",
+ {
+ group = "_auto_resize",
+ pattern = "*",
+ command = "tabdo wincmd =",
+ },
},
- custom_groups = {},
}
+
+ M.define_autocmds(definitions)
end
local get_format_on_save_opts = function()
@@ -84,7 +105,7 @@ function M.enable_format_on_save()
end
function M.disable_format_on_save()
- pcall(vim.api.nvim_del_augroup_by_name, "lsp_format_on_save")
+ M.clear_augroup "lsp_format_on_save"
Log:debug "disabled format-on-save"
end
@@ -97,11 +118,11 @@ function M.configure_format_on_save()
end
function M.toggle_format_on_save()
- local status, _ = pcall(vim.api.nvim_get_autocmds, {
+ local exists, _ = pcall(vim.api.nvim_get_autocmds, {
group = "lsp_format_on_save",
event = "BufWritePre",
})
- if not status then
+ if not exists then
M.enable_format_on_save()
else
M.disable_format_on_save()
@@ -109,47 +130,61 @@ function M.toggle_format_on_save()
end
function M.enable_transparent_mode()
- vim.cmd "au ColorScheme * hi Normal ctermbg=none guibg=none"
- vim.cmd "au ColorScheme * hi SignColumn ctermbg=none guibg=none"
- vim.cmd "au ColorScheme * hi NormalNC ctermbg=none guibg=none"
- vim.cmd "au ColorScheme * hi MsgArea ctermbg=none guibg=none"
- vim.cmd "au ColorScheme * hi TelescopeBorder ctermbg=none guibg=none"
- vim.cmd "au ColorScheme * hi NvimTreeNormal ctermbg=none guibg=none"
- vim.cmd "au ColorScheme * hi EndOfBuffer ctermbg=none guibg=none"
- vim.cmd "let &fcs='eob: '"
+ vim.api.nvim_create_autocmd("ColorScheme", {
+ pattern = "*",
+ callback = function()
+ local hl_groups = {
+ "Normal",
+ "SignColumn",
+ "NormalNC",
+ "TelescopeBorder",
+ "NvimTreeNormal",
+ "EndOfBuffer",
+ "MsgArea",
+ }
+ for _, name in ipairs(hl_groups) do
+ vim.cmd(string.format("highlight %s ctermbg=none guibg=none", name))
+ end
+ end,
+ })
+ vim.opt.fillchars = "eob: "
end
---- Disable autocommand groups if it exists
---- This is more reliable than trying to delete the augroup itself
+--- Clean autocommand in a group if it exists
+--- This is safer than trying to delete the augroup itself
---@param name string the augroup name
-function M.disable_augroup(name)
+function M.clear_augroup(name)
-- defer the function in case the autocommand is still in-use
+ local exists, _ = pcall(vim.api.nvim_get_autocmds, { group = name })
+ if not exists then
+ Log:debug("ignoring request to clear autocmds from non-existent group " .. name)
+ return
+ end
vim.schedule(function()
- if vim.fn.exists("#" .. name) == 1 then
- vim.cmd("augroup " .. name)
- vim.cmd "autocmd!"
- vim.cmd "augroup END"
+ local status_ok, _ = xpcall(function()
+ vim.api.nvim_clear_autocmds { group = name }
+ end, debug.traceback)
+ if not status_ok then
+ Log:warn("problems detected while clearing autocmds from " .. name)
+ Log:debug(debug.traceback())
end
end)
end
--- Create autocommand groups based on the passed definitions
----@param definitions table contains trigger, pattern and text. The key will be used as a group name
-function M.define_augroups(definitions, buffer)
- for group_name, definition in pairs(definitions) do
- vim.cmd("augroup " .. group_name)
- if buffer then
- vim.cmd [[autocmd! * <buffer>]]
- else
- vim.cmd [[autocmd!]]
- end
-
- for _, def in pairs(definition) do
- local command = table.concat(vim.tbl_flatten { "autocmd", def }, " ")
- vim.cmd(command)
+--- Also creates the augroup automatically if it doesn't exist
+---@param definitions table contains a tuple of event, opts, see `:h nvim_create_autocmd`
+function M.define_autocmds(definitions)
+ for _, entry in ipairs(definitions) do
+ local event = entry[1]
+ local opts = entry[2]
+ if type(opts.group) == "string" and opts.group ~= "" then
+ local exists, _ = pcall(vim.api.nvim_get_autocmds, { group = opts.group })
+ if not exists then
+ vim.api.nvim_create_augroup(opts.group, {})
+ end
end
-
- vim.cmd "augroup END"
+ vim.api.nvim_create_autocmd(event, opts)
end
end
diff --git a/lua/lvim/core/bufferline.lua b/lua/lvim/core/bufferline.lua
index cb322032..2df1e514 100644
--- a/lua/lvim/core/bufferline.lua
+++ b/lua/lvim/core/bufferline.lua
@@ -144,9 +144,9 @@ end
-- Common kill function for bdelete and bwipeout
-- credits: based on bbye and nvim-bufdel
----@param kill_command String defaults to "bd"
----@param bufnr Number defaults to the current buffer
----@param force Boolean defaults to false
+---@param kill_command string defaults to "bd"
+---@param bufnr? number defaults to the current buffer
+---@param force? boolean defaults to false
function M.buf_kill(kill_command, bufnr, force)
local bo = vim.bo
local api = vim.api
diff --git a/lua/lvim/core/commands.lua b/lua/lvim/core/commands.lua
index 4ddbfcf0..80c5bb03 100644
--- a/lua/lvim/core/commands.lua
+++ b/lua/lvim/core/commands.lua
@@ -1,7 +1,6 @@
local M = {}
-M.defaults = {
- [[
+vim.cmd [[
function! QuickFixToggle()
if empty(filter(getwininfo(), 'v:val.quickfix'))
copen
@@ -9,21 +8,70 @@ M.defaults = {
cclose
endif
endfunction
- ]],
- [[ command! BufferKill lua require('lvim.core.bufferline').buf_kill('bd') ]],
- -- :LvimInfo
- [[ command! LvimInfo lua require('lvim.core.info').toggle_popup(vim.bo.filetype) ]],
- [[ command! LvimCacheReset lua require('lvim.utils.hooks').reset_cache() ]],
- [[ command! LvimUpdate lua require('lvim.bootstrap').update() ]],
- [[ command! LvimSyncCorePlugins lua require('lvim.plugin-loader'):sync_core_plugins() ]],
- [[ command! LvimReload lua require('lvim.config'):reload() ]],
- [[ command! LvimToggleFormatOnSave lua require('lvim.core.autocmds').toggle_format_on_save() ]],
- [[ command! LvimVersion lua require('lvim.core.telescope.custom-finders').view_lunarvim_changelog() ]],
+]]
+
+M.defaults = {
+ {
+ name = "BufferKill",
+ fn = function()
+ require("lvim.core.bufferline").buf_kill "bd"
+ end,
+ },
+ {
+ name = "LvimToggleFormatOnSave",
+ fn = function()
+ require("lvim.core.autocmds").toggle_format_on_save()
+ end,
+ },
+ {
+ name = "LvimInfo",
+ fn = function()
+ require("lvim.core.info").toggle_popup(vim.bo.filetype)
+ end,
+ },
+ {
+ name = "LvimCacheReset",
+ fn = function()
+ require("lvim.utils.hooks").reset_cache()
+ end,
+ },
+ {
+ name = "LvimReload",
+ fn = function()
+ require("lvim.config"):reload()
+ end,
+ },
+ {
+ name = "LvimUpdate",
+ fn = function()
+ require("lvim.bootstrap"):update()
+ end,
+ },
+ {
+ name = "LvimSyncCorePlugins",
+ fn = function()
+ require("lvim.plugin-loader").sync_core_plugins()
+ end,
+ },
+ {
+ name = "LvimChangelog",
+ fn = function()
+ require("lvim.core.telescope.custom-finders").view_lunarvim_changelog()
+ end,
+ },
+ {
+ name = "LvimVersion",
+ fn = function()
+ print(require("lvim.utils.git").get_lvim_version())
+ end,
+ },
}
-M.load = function(commands)
- for _, command in ipairs(commands) do
- vim.cmd(command)
+function M.load(collection)
+ local common_opts = { force = true }
+ for _, cmd in pairs(collection) do
+ local opts = vim.tbl_deep_extend("force", common_opts, cmd.opts or {})
+ vim.api.nvim_create_user_command(cmd.name, cmd.fn, opts)
end
end
diff --git a/lua/lvim/core/dap.lua b/lua/lvim/core/dap.lua
index 8f7eb294..727e238f 100644
--- a/lua/lvim/core/dap.lua
+++ b/lua/lvim/core/dap.lua
@@ -47,7 +47,7 @@ M.setup = function()
i = { "<cmd>lua require'dap'.step_into()<cr>", "Step Into" },
o = { "<cmd>lua require'dap'.step_over()<cr>", "Step Over" },
u = { "<cmd>lua require'dap'.step_out()<cr>", "Step Out" },
- p = { "<cmd>lua require'dap'.pause.toggle()<cr>", "Pause" },
+ p = { "<cmd>lua require'dap'.pause()<cr>", "Pause" },
r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Toggle Repl" },
s = { "<cmd>lua require'dap'.continue()<cr>", "Start" },
q = { "<cmd>lua require'dap'.close()<cr>", "Quit" },
diff --git a/lua/lvim/core/log.lua b/lua/lvim/core/log.lua
index 15ccb11c..bc05d72b 100644
--- a/lua/lvim/core/log.lua
+++ b/lua/lvim/core/log.lua
@@ -11,15 +11,26 @@ vim.tbl_add_reverse_lookup(Log.levels)
local notify_opts = {}
+function Log:set_level(level)
+ -- package.loaded["lvim.core.log"] = nil
+ local log_level = Log.levels[level:upper()]
+ local status_ok, logger = pcall(require("structlog").get_logger, "lvim")
+ if status_ok then
+ for _, s in ipairs(logger.sinks) do
+ s.level = log_level
+ end
+ end
+
+ package.loaded["packer.log"] = nil
+ require("packer.log").new { level = lvim.log.level }
+end
+
function Log:init()
local status_ok, structlog = pcall(require, "structlog")
if not status_ok then
return nil
end
- package.loaded["packer.log"] = nil
- require("packer.log").new { level = lvim.log.level }
-
local log_level = Log.levels[(lvim.log.level):upper() or "WARN"]
local lvim_log = {
lvim = {
diff --git a/lua/lvim/core/telescope.lua b/lua/lvim/core/telescope.lua
index 5b55bdc3..6a04a866 100644
--- a/lua/lvim/core/telescope.lua
+++ b/lua/lvim/core/telescope.lua
@@ -72,7 +72,7 @@ function M.config()
set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil,
pickers = {
find_files = {
- find_command = { "fd", "--type=file", "--hidden", "--smart-case" },
+ hidden = true,
},
live_grep = {
--@usage don't include the filename in the search results
@@ -130,6 +130,12 @@ function M.setup()
end)
end
+ if lvim.builtin.notify.active then
+ pcall(function()
+ require("telescope").load_extension "notify"
+ end)
+ end
+
if lvim.builtin.telescope.on_config_done then
lvim.builtin.telescope.on_config_done(telescope)
end
diff --git a/lua/lvim/core/treesitter.lua b/lua/lvim/core/treesitter.lua
index d8b0c136..fcada24f 100644
--- a/lua/lvim/core/treesitter.lua
+++ b/lua/lvim/core/treesitter.lua
@@ -12,11 +12,12 @@ M.config = function()
},
highlight = {
enable = true, -- false will disable the whole extension
- additional_vim_regex_highlighting = true,
+ additional_vim_regex_highlighting = false,
disable = { "latex" },
},
context_commentstring = {
enable = true,
+ enable_autocmd = false,
config = {
-- Languages that have a single comment style
typescript = "// %s",
@@ -28,9 +29,7 @@ M.config = function()
json = "",
},
},
- -- indent = {enable = true, disable = {"python", "html", "javascript"}},
- -- TODO seems to be broken
- indent = { enable = true, disable = { "yaml" } },
+ indent = { enable = true, disable = { "yaml", "python" } },
autotag = { enable = false },
textobjects = {
swap = {
diff --git a/lua/lvim/core/which-key.lua b/lua/lvim/core/which-key.lua
index 3c3cc66b..b1ae6f87 100644
--- a/lua/lvim/core/which-key.lua
+++ b/lua/lvim/core/which-key.lua
@@ -82,7 +82,7 @@ M.config = function()
mappings = {
[";"] = { "<cmd>Alpha<CR>", "Dashboard" },
["w"] = { "<cmd>w!<CR>", "Save" },
- ["q"] = { "<cmd>q!<CR>", "Quit" },
+ ["q"] = { "<cmd>lua require('lvim.utils.functions').smart_quit()<CR>", "Quit" },
["/"] = { "<cmd>lua require('Comment.api').toggle_current_linewise()<CR>", "Comment" },
["c"] = { "<cmd>BufferKill<CR>", "Close Buffer" },
["f"] = { require("lvim.core.telescope.custom-finders").find_project_files, "Find File" },
@@ -234,6 +234,7 @@ M.config = function()
},
P = { "<cmd>edit $LUNARVIM_CACHE_DIR/packer.nvim.log<cr>", "Open the Packer logfile" },
},
+ n = { "<cmd>Telescope notify<cr>", "View Notifications" },
r = { "<cmd>LvimReload<cr>", "Reload LunarVim's configuration" },
u = { "<cmd>LvimUpdate<cr>", "Update LunarVim" },
},