summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ftdetect/json.lua3
-rw-r--r--ftdetect/plaintex.lua1
-rw-r--r--ftdetect/zig.lua3
-rw-r--r--ftplugin/lua.lua88
-rw-r--r--lua/lvim/config/settings.lua10
-rw-r--r--lua/lvim/core/autocmds.lua56
6 files changed, 42 insertions, 119 deletions
diff --git a/ftdetect/json.lua b/ftdetect/json.lua
deleted file mode 100644
index 9824e3e4..00000000
--- a/ftdetect/json.lua
+++ /dev/null
@@ -1,3 +0,0 @@
-vim.cmd [[
- au BufRead,BufNewFile tsconfig.json set filetype=jsonc
-]]
diff --git a/ftdetect/plaintex.lua b/ftdetect/plaintex.lua
deleted file mode 100644
index aa01dec8..00000000
--- a/ftdetect/plaintex.lua
+++ /dev/null
@@ -1 +0,0 @@
-vim.cmd [[ au BufRead,BufNewFile *.tex set filetype=tex ]]
diff --git a/ftdetect/zig.lua b/ftdetect/zig.lua
deleted file mode 100644
index 343c56c0..00000000
--- a/ftdetect/zig.lua
+++ /dev/null
@@ -1,3 +0,0 @@
-vim.cmd [[
- au BufRead,BufNewFile *.zir set filetype=zir
-]]
diff --git a/ftplugin/lua.lua b/ftplugin/lua.lua
deleted file mode 100644
index 138332e9..00000000
--- a/ftplugin/lua.lua
+++ /dev/null
@@ -1,88 +0,0 @@
-local fmt = string.format
--- luacheck: ignore
--- TODO: fix lint violations
-
--- Iterator that splits a string o a given delimiter
-local function split(str, delim)
- delim = delim or "%s"
- return string.gmatch(str, fmt("[^%s]+", delim))
-end
-
--- Find the proper directory separator depending
--- on lua installation or OS.
-local function dir_separator()
- -- Look at package.config for directory separator string (it's the first line)
- if package.config then
- return string.match(package.config, "^[^\n]")
- elseif vim.fn.has "win32" == 1 then
- return "\\"
- else
- return "/"
- end
-end
-
--- Search for lua traditional include paths.
--- This mimics how require internally works.
-local function include_paths(fname, ext)
- ext = ext or "lua"
- local sep = dir_separator()
- local paths = string.gsub(package.path, "%?", fname)
- for path in split(paths, "%;") do
- if vim.fn.filereadable(path) == 1 then
- return path
- end
- end
-end
-
--- Search for nvim lua include paths
-local function include_rtpaths(fname, ext)
- ext = ext or "lua"
- local sep = dir_separator()
- local rtpaths = vim.api.nvim_list_runtime_paths()
- local modfile, initfile = fmt("%s.%s", fname, ext), fmt("init.%s", ext)
- for _, path in ipairs(rtpaths) do
- -- Look on runtime path for 'lua/*.lua' files
- local path1 = table.concat({ path, ext, modfile }, sep)
- if vim.fn.filereadable(path1) == 1 then
- return path1
- end
- -- Look on runtime path for 'lua/*/init.lua' files
- local path2 = table.concat({ path, ext, fname, initfile }, sep)
- if vim.fn.filereadable(path2) == 1 then
- return path2
- end
- end
-end
-
--- Global function that searches the path for the required file
-function find_required_path(module)
- -- Look at package.config for directory separator string (it's the first line)
- local sep = string.match(package.config, "^[^\n]")
- -- Properly change '.' to separator (probably '/' on *nix and '\' on Windows)
- local fname = vim.fn.substitute(module, "\\.", sep, "g")
- local f
- ---- First search for lua modules
- f = include_paths(fname, "lua")
- if f then
- return f
- end
- -- This part is just for nvim modules
- f = include_rtpaths(fname, "lua")
- if f then
- return f
- end
- ---- Now search for Fennel modules
- f = include_paths(fname, "fnl")
- if f then
- return f
- end
- -- This part is just for nvim modules
- f = include_rtpaths(fname, "fnl")
- if f then
- return f
- end
-end
-
--- Set options to open require with gf
-vim.opt_local.include = [=[\v<((do|load)file|require)\s*\(?['"]\zs[^'"]+\ze['"]]=]
-vim.opt_local.includeexpr = "v:lua.find_required_path(v:fname)"
diff --git a/lua/lvim/config/settings.lua b/lua/lvim/config/settings.lua
index 5724406a..5b818034 100644
--- a/lua/lvim/config/settings.lua
+++ b/lua/lvim/config/settings.lua
@@ -64,6 +64,16 @@ M.load_default_options = function()
for k, v in pairs(default_options) do
vim.opt[k] = v
end
+
+ vim.filetype.add {
+ extension = {
+ tex = "tex",
+ zir = "zir",
+ },
+ pattern = {
+ ["[jt]sconfig.*.json"] = "jsonc",
+ },
+ }
end
M.load_headless_options = function()
diff --git a/lua/lvim/core/autocmds.lua b/lua/lvim/core/autocmds.lua
index 79c9089b..6d1cc6cd 100644
--- a/lua/lvim/core/autocmds.lua
+++ b/lua/lvim/core/autocmds.lua
@@ -3,25 +3,6 @@ local Log = require "lvim.core.log"
--- Load the default set of autogroups and autocommands.
function M.load_defaults()
- vim.api.nvim_create_autocmd({ "FileType" }, {
- pattern = {
- "Jaq",
- "qf",
- "help",
- "man",
- "lspinfo",
- "spectre_panel",
- "lir",
- "DressingSelect",
- "tsplayground",
- },
- callback = function()
- vim.cmd [[
- nnoremap <silent> <buffer> q :close<CR>
- set nobuflisted
- ]]
- end,
- })
local definitions = {
{
"TextYankPost",
@@ -30,7 +11,7 @@ function M.load_defaults()
pattern = "*",
desc = "Highlight text on yank",
callback = function()
- require("vim.highlight").on_yank { higroup = "Search", timeout = 100 }
+ vim.highlight.on_yank { higroup = "Search", timeout = 100 }
end,
},
},
@@ -46,16 +27,43 @@ function M.load_defaults()
"FileType",
{
group = "_filetype_settings",
- pattern = "qf",
- command = "set nobuflisted",
+ pattern = { "lua" },
+ desc = "fix gf functionality inside .lua files",
+ callback = function()
+ ---@diagnostic disable: assign-type-mismatch
+ -- credit: https://github.com/sam4llis/nvim-lua-gf
+ vim.opt_local.include = [[\v<((do|load)file|require|reload)[^''"]*[''"]\zs[^''"]+]]
+ vim.opt_local.includeexpr = "substitute(v:fname,'\\.','/','g')"
+ vim.opt_local.suffixesadd:prepend ".lua"
+ vim.opt_local.suffixesadd:prepend "init.lua"
+
+ for _, path in pairs(vim.api.nvim_list_runtime_paths()) do
+ vim.opt_local.path:append(path .. "/lua")
+ end
+ end,
},
},
{
"FileType",
{
group = "_buffer_mappings",
- pattern = { "qf", "help", "man", "floaterm", "lspinfo", "lsp-installer", "null-ls-info" },
- command = "nnoremap <silent> <buffer> q :close<CR>",
+ pattern = {
+ "qf",
+ "help",
+ "man",
+ "floaterm",
+ "lspinfo",
+ "lir",
+ "lsp-installer",
+ "null-ls-info",
+ "tsplayground",
+ "DressingSelect",
+ "Jaq",
+ },
+ callback = function()
+ vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = true })
+ vim.opt_local.buflisted = false
+ end,
},
},
{