From 772d0ff4583f272300cfd4270bcf18cc310642d2 Mon Sep 17 00:00:00 2001 From: kevinm6 <72861758+kevinm6@users.noreply.github.com> Date: Sat, 8 Feb 2025 11:27:22 +0100 Subject: [PATCH] chore: QOL improvements and some fixes --- after/ftplugin/pdf.lua | 14 ++++ after/ftplugin/qf.lua | 22 ++++++- after/ftplugin/sql.lua | 3 + after/syntax/freemarker.vim | 82 ----------------------- lazy-lock.json | 30 ++++----- lua/lib/compiler.lua | 17 ++--- lua/plugins/ui/dashboard.lua | 4 +- plugin/autocommands.lua | 123 ++++++++++++----------------------- 8 files changed, 104 insertions(+), 191 deletions(-) create mode 100644 after/ftplugin/pdf.lua delete mode 100644 after/syntax/freemarker.vim diff --git a/after/ftplugin/pdf.lua b/after/ftplugin/pdf.lua new file mode 100644 index 0000000..5cf0635 --- /dev/null +++ b/after/ftplugin/pdf.lua @@ -0,0 +1,14 @@ +------------------------------------- +-- File : pdf.lua +-- Description : PDF filetype extra config +-- Author : Kevin +-- Last Modified: 08/02/2025 - 09:43 +------------------------------------- + +vim.api.nvim_set_option_value("readonly", true, { buf = 0 }) +if not vim.fn.executable "pdftotext" then + vim.notify("vim-pdf: pdftotext is not found.\nStop converting...", vim.log.levels.ERROR) + return +end + +require("lib.pdf").load_pdf(vim.api.nvim_buf_get_name(0)) diff --git a/after/ftplugin/qf.lua b/after/ftplugin/qf.lua index d9c3096..438603e 100644 --- a/after/ftplugin/qf.lua +++ b/after/ftplugin/qf.lua @@ -1,10 +1,28 @@ +------------------------------------- +-- File : qf.lua +-- Description : filetype qf extra config +-- Author : Kevin +-- Last Modified: 20/10/2024 - 19:10 +------------------------------------- + local del_qf_item = function() local items = vim.fn.getqflist() - local line = vim.fn.line('.') + local line = vim.fn.line "." table.remove(items, line) vim.fn.setqflist(items, "r") vim.api.nvim_win_set_cursor(0, { line, 0 }) end +---Keymaps +vim.keymap.set("n", "", "cprev", { buffer = true, silent = true }) +vim.keymap.set("n", "", "cnext", { buffer = true, silent = true }) +vim.keymap.set("n", "", "", { buffer = true, silent = true }) +vim.keymap.set("n", "q", function() + vim.cmd.quit { bang = true } +end, { buffer = true, silent = true }) +vim.keymap.set("n", "", function() + vim.cmd.quit { bang = true } +end, { buffer = true, silent = true }) + vim.keymap.set("n", "dd", del_qf_item, { silent = true, buffer = true, desc = "Remove entry from QF" }) -vim.keymap.set("v", "D", del_qf_item, { silent = true, buffer = true, desc = "Remove entry from QF" }) \ No newline at end of file +vim.keymap.set("v", "D", del_qf_item, { silent = true, buffer = true, desc = "Remove entry from QF" }) diff --git a/after/ftplugin/sql.lua b/after/ftplugin/sql.lua index 72899bf..0cb6d15 100644 --- a/after/ftplugin/sql.lua +++ b/after/ftplugin/sql.lua @@ -15,3 +15,6 @@ vim.opt_local.autoindent = true vim.opt_local.commentstring = "-- %s" vim.opt.spell = false + +---Start postgresql service on sql files (Mac) +-- require("lib").run_brew_service("postgresql@14", false) diff --git a/after/syntax/freemarker.vim b/after/syntax/freemarker.vim deleted file mode 100644 index f1e942c..0000000 --- a/after/syntax/freemarker.vim +++ /dev/null @@ -1,82 +0,0 @@ -if exists("b:current_syntax") - finish -endif - -"Basic html syntax{{{ -syntax keyword freemarkerKeyword div p html body head title a href br b i form -syntax keyword freemarkerKeyword pre hr h1 h2 h3 tr td table thead th tbody type -syntax keyword freemarkerKeyword class caption style button input label script -syntax keyword freemarkerBoolean true false -"}}} - -"Functions, assignments{{{ -syntax match freemarkerFunction "\v\#function|\#return" -syntax match freemarkerFunction "\v\#return" -syntax match freemarkerFunction "\v\#assign" -syntax match freemarkerFunction "\v\#include" -syntax match freemarkerFunction "\v\#local" -"}}} - -"open and close tags {{{ -syntax match freemarkerFunction "<" -syntax match freemarkerFunction ">" -syntax match freemarkerFunction "(" -syntax match freemarkerFunction ")" -syntax match freemarkerFunction "\[" -syntax match freemarkerFunction "\]" -syntax match freemarkerFunction "\v/" -"}}} - -"variables {{{ -"variable type @s.example -syntax match freemarkerFunction "\v\@\S*" - -"External variables ${example.test} -syntax region freemarkerSpecialChar start=+${+ end=+}+ -"}}} - -"Conditionals and blocs {{{ -syntax match freemarkerConditional "\v\v\#if|\#else" -syntax match freemarkerConditional "\v\#elseif" -syntax match freemarkerConditional "\v\#attemp" -syntax match freemarkerConditional "\v\#recover" -syntax match freemarkerConditional "\v\#list" -syntax match freemarkerConditional "\v\#break" -syntax match freemarkerConditional "\v\#macro" -syntax match freemarkerConditional "\v\#nested" -syntax match freemarkerConditional "\v\#switch" -syntax match freemarkerConditional "\v\#case" -syntax match freemarkerConditional "\v\#default" -syntax match freemarkerConditional "\v\#items" -"}}} - -"Basic operators {{{ -syntax match freemarkerOperator "\v\*" -syntax match freemarkerOperator "\v/" -syntax match freemarkerOperator "\v\+" -syntax match freemarkerOperator "\v-" -syntax match freemarkerOperator "\v\?" -syntax match freemarkerOperator "\v\*\=" -syntax match freemarkerOperator "\v/\=" -syntax match freemarkerOperator "\v\+\=" -syntax match freemarkerOperator "\v-\=" -syntax match freemarkerOperator "\v\=" -"}}} - -"Strings and comments {{{ -syntax match freemarkerString '\v".*"' -syntax match freemarkerComment "\v\<#--.*--\>" -"}}} - -"highlighting groups {{{ -highlight link freemarkerConditional Conditional -highlight link freemarkerOperator Operator -highlight link freemarkerFunction Function -highlight link freemarkerSpecialChar SpecialChar -highlight link freemarkerString String -highlight link freemarkerComment Comment -highlight link freemarkerKeyword Keyword -highlight link freemarkerBoolean Boolean -"}}} - -let b:current_syntax = "freemarker" \ No newline at end of file diff --git a/lazy-lock.json b/lazy-lock.json index 3d3bc38..6a39fb1 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,47 +1,47 @@ { - "SchemaStore.nvim": { "branch": "main", "commit": "4244700eff0a9258b88f48b2b0d0339dea3338af" }, + "SchemaStore.nvim": { "branch": "main", "commit": "b265e7b68308c9b68581d57c3f79419ce5e8dca2" }, "alpha-nvim": { "branch": "main", "commit": "de72250e054e5e691b9736ee30db72c65d560771" }, "blink.cmp": { "branch": "main", "commit": "b6f11a0aa33e601c469a126e3ed6e35208fe3ea3" }, "color-picker.nvim": { "branch": "master", "commit": "06cb5f853535dea529a523e9a0e8884cdf9eba4d" }, "conform.nvim": { "branch": "master", "commit": "363243c03102a531a8203311d4f2ae704c620d9b" }, "data-viewer.nvim": { "branch": "main", "commit": "40ddf37bb7ab6c04ff9e820812d1539afe691668" }, - "gitsigns.nvim": { "branch": "main", "commit": "9b36d497495436c135659902054ee637e0ba6021" }, - "go.nvim": { "branch": "master", "commit": "79857f92433d18857167cdc18c417701778185bf" }, + "gitsigns.nvim": { "branch": "main", "commit": "c23bbd3ed2c7a3fdc3399e97e24f9e158f57612f" }, + "go.nvim": { "branch": "master", "commit": "9ecbd0950bac754d9c449ca79e883ab6b230bda2" }, "hererocks": { "branch": "master", "commit": "c9c5444dea1e07e005484014a8231aa667be30b6" }, "image.nvim": { "branch": "master", "commit": "6ffafab2e98b5bda46bf227055aa84b90add8cdc" }, "jupytext.nvim": { "branch": "main", "commit": "c8baf3ad344c59b3abd461ecc17fc16ec44d0f7b" }, - "lazy.nvim": { "branch": "main", "commit": "7527af40ddd4a93a02911be570b32609b9d4ea53" }, + "lazy.nvim": { "branch": "main", "commit": "f15a93907ddad3d9139aea465ae18336d87f5ce6" }, "lazydev.nvim": { "branch": "main", "commit": "a1b78b2ac6f978c72e76ea90ae92a94edf380cfc" }, - "markdown.nvim": { "branch": "main", "commit": "b9c98ff7d47dfe2a972f1b08340850c92e6ca9bc" }, + "markdown.nvim": { "branch": "main", "commit": "5c2440d932a4ba96840e5ce5a7bd40f0624bdaa2" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "f75e877f5266e87523eb5a18fcde2081820d087b" }, "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, "mini.icons": { "branch": "main", "commit": "ec61af6e606fc89ee3b1d8f2f20166a3ca917a36" }, "mini.pairs": { "branch": "main", "commit": "1a3e73649c0eaef2f6c48ce1e761c6f0a7c11918" }, - "mini.surround": { "branch": "main", "commit": "ceddea5fe862f13b279d9bbe81c3327a0e66d56b" }, + "mini.surround": { "branch": "main", "commit": "f40be56134835421061bf32c3702de9a29fb789c" }, "molten-nvim": { "branch": "main", "commit": "a286aa914d9a154bc359131aab788b5a077a5a99" }, "nui.nvim": { "branch": "main", "commit": "53e907ffe5eedebdca1cd503b00aa8692068ca46" }, "nvim-colorizer.lua": { "branch": "master", "commit": "a065833f35a3a7cc3ef137ac88b5381da2ba302e" }, - "nvim-dap": { "branch": "master", "commit": "b4f27d451c187de912fa8d3229025a952917eb9e" }, + "nvim-dap": { "branch": "master", "commit": "52302f02fea3a490e55475de52fa4deb8af2eb11" }, "nvim-dap-ui": { "branch": "master", "commit": "bc81f8d3440aede116f821114547a476b082b319" }, - "nvim-dbee": { "branch": "master", "commit": "495f6f718ccfb98eba51c7998e30f3f3ea6e95e1" }, - "nvim-jdtls": { "branch": "master", "commit": "3efcd0700a293efea9dada58f79c32a64850eb24" }, - "nvim-lint": { "branch": "master", "commit": "789b7ada1b4f00e08d026dffde410dcfa6a0ba87" }, - "nvim-lspconfig": { "branch": "master", "commit": "ead2fbc4893fdd062e1dd0842679a48bfb7bac5c" }, + "nvim-dbee": { "branch": "master", "commit": "f9aa10f113ae439ef20c6d8b91b27dab93274360" }, + "nvim-jdtls": { "branch": "master", "commit": "3cdd09f336ab7169476b936c0825213d86d32e41" }, + "nvim-lint": { "branch": "master", "commit": "6e9dd545a1af204c4022a8fcd99727ea41ffdcc8" }, + "nvim-lspconfig": { "branch": "master", "commit": "75edb91a3d2deabe76a9911cde2c13d411b3b097" }, "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, "nvim-notify": { "branch": "master", "commit": "22f29093eae7785773ee9d543f8750348b1a195c" }, - "nvim-treesitter": { "branch": "master", "commit": "bcd0b26607c1a4336c392285a9f13e31f514ccf2" }, + "nvim-treesitter": { "branch": "master", "commit": "62911c78a868bac24c8a86f2c1c412d0b799f885" }, "nvim-treesitter-refactor": { "branch": "master", "commit": "d8b74fa87afc6a1e97b18da23e762efb032dc270" }, "nvim-ufo": { "branch": "main", "commit": "81f5ffa6e8ba27c48403cf681d4b383d924e03e4" }, "obsidian.nvim": { "branch": "main", "commit": "ae1f76a75c7ce36866e1d9342a8f6f5b9c2caf9b" }, "oil.nvim": { "branch": "master", "commit": "add50252b5e9147c0a09d36480d418c7e2737472" }, - "otter.nvim": { "branch": "main", "commit": "3ff6c154d55528fbde475b2a722f91389421e873" }, + "otter.nvim": { "branch": "main", "commit": "0e42fa795c35c7190935e3beda3791189c41bb72" }, "plenary.nvim": { "branch": "master", "commit": "3707cdb1e43f5cea73afb6037e6494e7ce847a66" }, "promise-async": { "branch": "main", "commit": "119e8961014c9bfaf1487bf3c2a393d254f337e2" }, - "quarto-nvim": { "branch": "main", "commit": "1cb2d24d7793241bd43f38e3a6f99a6d11f84458" }, + "quarto-nvim": { "branch": "main", "commit": "abc417c7e7422033f1090c0da5f30ef3ecb0c7ca" }, "sqls.nvim": { "branch": "main", "commit": "a514379f5f89bf72955ed3bf5c1c31a40b8a1472" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "dae2eac9d91464448b584c7949a31df8faefec56" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope.nvim": { "branch": "master", "commit": "415af52339215926d705cccc08145f3782c4d132" }, - "vimtex": { "branch": "master", "commit": "3a9f47ce6e42c4a3c9a92a254f1f611a8d374fc9" }, + "vimtex": { "branch": "master", "commit": "dfaf26c2cafddf61963ebeff28437352002691ac" }, "which-key.nvim": { "branch": "main", "commit": "0e76a87ac51772569aec678dc74baa8e2a86100c" } } diff --git a/lua/lib/compiler.lua b/lua/lib/compiler.lua index 1b1bed7..56b2372 100644 --- a/lua/lib/compiler.lua +++ b/lua/lib/compiler.lua @@ -58,12 +58,13 @@ local function getCommand(command) local filepath = vim.fn.expand "%:p" local clean_cmd = command - command = command:gsub("$fileNameWithoutExt", vim.fn.fnamemodify(filepath, ":t:r")) - command = command:gsub("$fileName", vim.fn.fnamemodify(filepath, ":t")) - command = command:gsub("$file", filepath) - command = command:gsub("$dir", vim.fn.fnamemodify(filepath, ":p:h")) - command = command:gsub("$dName", vim.fn.fnamemodify(vim.uv.cwd() or vim.loop.cwd() or "", ":t")) - command = command:gsub("$end", "") + command = command + :gsub("$fileNameWithoutExt", vim.fn.fnamemodify(filepath, ":t:r")) + :gsub("$fileName", vim.fn.fnamemodify(filepath, ":t")) + :gsub("$file", filepath) + :gsub("$dir", vim.fn.fnamemodify(filepath, ":p:h")) + :gsub("$dName", vim.fn.fnamemodify(vim.uv.cwd() or vim.loop.cwd() or "", ":t")) + :gsub("$end", "") return (command == clean_cmd) and command or string.format("%s %s", command, filepath) end @@ -164,12 +165,12 @@ end ---In this way, only if user wants to compile/run the file, prompt the selection ---@param buf any bufId for which set keymap local function set_keymaps(buf) - local icons = require "lib.icons" + local icons = require "mini.icons" local function map(tbl) vim.keymap.set("n", tbl[1], tbl[2], { buffer = buf, desc = "Run❭ " .. tbl[3] }) end - vim.keymap.set({ "n", "v" }, "R", function() end, { buffer = buf, desc = icons.debug.run .. " Run" }) + vim.keymap.set({ "n", "v" }, "R", function() end, { buffer = buf, desc = icons.file.rerun .. " Run" }) local function run_file_cmd() if not compiler.compilers[vim.bo.filetype] then diff --git a/lua/plugins/ui/dashboard.lua b/lua/plugins/ui/dashboard.lua index 77fd29e..959cf86 100644 --- a/lua/plugins/ui/dashboard.lua +++ b/lua/plugins/ui/dashboard.lua @@ -85,7 +85,7 @@ return { db_btn("f", "󰾰 Find file", "lua require 'lib'.find_files()"), db_btn("r", " Recent files", "lua require 'lib'.recent_files()"), - db_btn("R", " Find project", "lua require 'lib'.projects()"), + db_btn("p", " Find project", "lua require 'lib'.projects()"), db_btn("d", "󰾰 Developer", [[lua require "lib".dev_folder()]]), db_btn("L", " Plugin Manager", "Lazy"), db_btn("m", " Package Manager", "Mason"), @@ -111,4 +111,4 @@ return { db.config.opts.noautocmd = true alpha.setup(db.opts) end, -} \ No newline at end of file +} diff --git a/plugin/autocommands.lua b/plugin/autocommands.lua index eeee189..166d3b1 100644 --- a/plugin/autocommands.lua +++ b/plugin/autocommands.lua @@ -98,23 +98,6 @@ autocmd("FileType", { end, }) ----QuickFixList keymaps -autocmd("FileType", { - group = augroup("_maps_qf_ft", { clear = true }), - pattern = "qf", - callback = function() - vim.keymap.set("n", "", "cprev", { buffer = true, silent = true }) - vim.keymap.set("n", "", "cnext", { buffer = true, silent = true }) - vim.keymap.set("n", "", "", { buffer = true, silent = true }) - vim.keymap.set("n", "q", function() - vim.cmd.quit { bang = true } - end, { buffer = true, silent = true }) - vim.keymap.set("n", "", function() - vim.cmd.quit { bang = true } - end, { buffer = true, silent = true }) - end, -}) - autocmd("FileType", { group = augroup("_autocmd_statuscolumn", { clear = true }), callback = function(ev) @@ -143,54 +126,54 @@ autocmd({ "BufNewFile", "BufRead" }, { ---Check if want to install Treesitter parser for current ---filetype if missing -autocmd("FileType", { - group = augroup("_check_ft_ts_parser", { clear = true }), - pattern = "*", - callback = function(ev) - if not filetypes_to_exclude[ev.match] then - local has_ts, ts_parsers = pcall(require, "nvim-treesitter.parsers") - if not has_ts then - return - end - - local lang = ts_parsers.get_buf_lang() - local donot_ask_install = vim.g.dont_ask_install or {} - if - ts_parsers.get_parser_configs()[lang] - and not ts_parsers.has_parser(lang) - and not donot_ask_install[lang] == true - then - vim.schedule_wrap(function() - local msg = string.format("Install missing TS parser for < %s >?", lang) - local choice = vim.fn.confirm(msg, "&Yes\n&No") - - if choice == 1 then - vim.cmd.TSInstall(lang) - else - donot_ask_install[lang] = true - vim.g.dont_ask_install = donot_ask_install - end - end)() - end - end - end, -}) - ----Set makeprg and keywordprg for filetype (using default compiler when available) -- autocmd("FileType", { --- group = augroup("_set_makefile", { clear = true }), +-- group = augroup("_check_ft_ts_parser", { clear = true }), -- pattern = "*", -- callback = function(ev) --- local lib_compiler = require "lib.compiler" --- if ev.match and lib_compiler.set_keywordprg(ev.match) then --- vim.opt_local.keywordprg = lib_compiler.set_keywordprg(ev.match) --- end --- if ev.match and not filetypes_to_exclude[ev.match] then --- lib_compiler.set_compiler(ev) +-- if not filetypes_to_exclude[ev.match] then +-- local has_ts, ts_parsers = pcall(require, "nvim-treesitter.parsers") +-- if not has_ts then +-- return +-- end +-- +-- local lang = ts_parsers.get_buf_lang() +-- local donot_ask_install = vim.g.dont_ask_install or {} +-- if +-- ts_parsers.get_parser_configs()[lang] +-- and not ts_parsers.has_parser(lang) +-- and not donot_ask_install[lang] == true +-- then +-- vim.schedule_wrap(function() +-- local msg = string.format("Install missing TS parser for < %s >?", lang) +-- local choice = vim.fn.confirm(msg, "&Yes\n&No") +-- +-- if choice == 1 then +-- vim.cmd.TSInstall(lang) +-- else +-- donot_ask_install[lang] = true +-- vim.g.dont_ask_install = donot_ask_install +-- end +-- end)() +-- end -- end -- end, -- }) +---Set makeprg and keywordprg for filetype (using default compiler when available) +--autocmd("FileType", { +-- group = augroup("_set_makefile", { clear = true }), +-- pattern = "*", +-- callback = function(ev) +-- local lib_compiler = require "lib.compiler" +-- if ev.match and lib_compiler.set_keywordprg(ev.match) then +-- vim.opt_local.keywordprg = lib_compiler.set_keywordprg(ev.match) +-- end +-- if ev.match and not filetypes_to_exclude[ev.match] then +-- lib_compiler.set_compiler(ev) +-- end +-- end, +--}) + ---Jump to last < cursor-pos > in file autocmd("BufRead", { group = augroup("_buf_last_cursor_pos", { clear = true }), @@ -258,30 +241,6 @@ autocmd({ "BufRead", "BufNewFile" }, { end, }) ----Start postgresql service on sql files --- autocmd("FileType", { --- group = augroup("_postres_service", { clear = true }), --- pattern = { "sql" }, --- once = true, -- don't run again on other sql files --- callback = function() --- require("lib").run_brew_service("postgresql@14", false) --- end, --- }) - ----Read PDF into neovim, using pdftotext binary -autocmd("FileType", { - group = augroup("_pdf_reader", { clear = true }), - pattern = { "pdf", "PDF" }, - callback = function(ev) - vim.api.nvim_set_option_value("readonly", true, { buf = ev.buf }) - if not vim.fn.executable "pdftotext" then - vim.notify("vim-pdf: pdftotext is not found.\nStop converting...", vim.log.levels.ERROR) - return - end - require("lib.pdf").load_pdf(ev.file) - end, -}) - ---Hex autocmd("FileType", { group = augroup("_hex_files", { clear = true }),