From 6e16a81d2cffff74a71bfbd39862c84a2356d2e3 Mon Sep 17 00:00:00 2001 From: foozzi Date: Sun, 28 Jul 2024 17:48:16 +0200 Subject: [PATCH] 28072024 --- global/.config/nvim/lazy-lock.json | 6 +- global/.config/nvim/lua/plugins/lsp.lua | 3 +- .../.config/nvim/lua/plugins/lualine-nvim.lua | 5 +- .../nvim/lua/utils/telescope_addons.lua | 175 +++++++++--------- 4 files changed, 98 insertions(+), 91 deletions(-) diff --git a/global/.config/nvim/lazy-lock.json b/global/.config/nvim/lazy-lock.json index 6cbd259..6c0273f 100644 --- a/global/.config/nvim/lazy-lock.json +++ b/global/.config/nvim/lazy-lock.json @@ -28,12 +28,12 @@ "nvim-lint": { "branch": "master", "commit": "efc6fc83f0772283e064c53a8f9fb5645bde0bc0" }, "nvim-lspconfig": { "branch": "master", "commit": "f95d371c1a274f60392edfd8ea5121b42dca736e" }, "nvim-surround": { "branch": "main", "commit": "ec2dc7671067e0086cdf29c2f5df2dd909d5f71f" }, - "nvim-tree.lua": { "branch": "master", "commit": "82ba116bbd0cc5f0482783d67ea969595e2b381b" }, - "nvim-treesitter": { "branch": "master", "commit": "f97e0de0053df1cb3b9f74b9b1239acced1b7d9a" }, + "nvim-tree.lua": { "branch": "master", "commit": "48d0e82f9434691cc50d970898142a8c084a49d6" }, + "nvim-treesitter": { "branch": "master", "commit": "2d5133f67429f82547ea5fad33a0b1e7d4f78a1c" }, "nvim-treesitter-context": { "branch": "master", "commit": "2aba92ceb1479485953007f4d5adf34d0b66917e" }, "nvim-ts-autotag": { "branch": "main", "commit": "dc5e1687ab76ee02e0f11c5ce137f530b36e98b3" }, "nvim-ts-context-commentstring": { "branch": "main", "commit": "6b5f95aa4d24f2c629a74f2c935c702b08dbde62" }, - "nvim-web-devicons": { "branch": "master", "commit": "a2af6aa13a2ad3ad361d562a319a91bcd68c43a4" }, + "nvim-web-devicons": { "branch": "master", "commit": "5be6c4e685618b99c3210a69375b38a1202369b4" }, "peek.nvim": { "branch": "master", "commit": "5820d937d5414baea5f586dc2a3d912a74636e5b" }, "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" }, "tabular": { "branch": "master", "commit": "12437cd1b53488e24936ec4b091c9324cafee311" }, diff --git a/global/.config/nvim/lua/plugins/lsp.lua b/global/.config/nvim/lua/plugins/lsp.lua index 1555fd4..4dbd595 100644 --- a/global/.config/nvim/lua/plugins/lsp.lua +++ b/global/.config/nvim/lua/plugins/lsp.lua @@ -13,8 +13,7 @@ local config = function() focusable = true, style = "minimal", border = "rounded", - source = "always", - + source = true, header = "", prefix = "", }, diff --git a/global/.config/nvim/lua/plugins/lualine-nvim.lua b/global/.config/nvim/lua/plugins/lualine-nvim.lua index 241e72b..2e42edd 100644 --- a/global/.config/nvim/lua/plugins/lualine-nvim.lua +++ b/global/.config/nvim/lua/plugins/lualine-nvim.lua @@ -42,8 +42,9 @@ ins_right({ -- Lsp server name . function() local msg = "No Active Lsp" - local buf_ft = vim.api.nvim_buf_get_option(0, "filetype") - local clients = vim.lsp.get_active_clients() + -- local buf_ft = vim.api.nvim_buf_get_option(0, "filetype") + local buf_ft = vim.bo.filetype + local clients = vim.lsp.get_clients() if next(clients) == nil then return msg end diff --git a/global/.config/nvim/lua/utils/telescope_addons.lua b/global/.config/nvim/lua/utils/telescope_addons.lua index 38061cb..59a3e28 100644 --- a/global/.config/nvim/lua/utils/telescope_addons.lua +++ b/global/.config/nvim/lua/utils/telescope_addons.lua @@ -1,50 +1,44 @@ -local finders = require('telescope.finders') -local previewers = require('telescope.previewers') -local action_state = require('telescope.actions.state') -local conf = require('telescope.config').values -local pickers = require('telescope.pickers') +local finders = require("telescope.finders") +local previewers = require("telescope.previewers") +local action_state = require("telescope.actions.state") +local conf = require("telescope.config").values +local pickers = require("telescope.pickers") local actions = require("telescope.actions") local mapvimkey = require("utils.keymapper").mapvimkey local M = {} --- local function paste_titled_link() --- return function(prompt_bufnr) --- actions.close(prompt_bufnr) --- local selection = action_state.get_selected_entry() --- local parts = vim.split(selection.value, ":") --- local filename_part = parts[1] --- local title = parts[#parts]:match("^%s*(.-)%s*$") --- local link = "[" .. title .. "](../" .. filename_part .. ")" --- vim.api.nvim_put({ link }, "", true, true) --- end --- end +local function paste_titled_link() + return function(prompt_bufnr) + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + local parts = vim.split(selection.value, ":") + local filename_part = parts[1] + local filename_and_category = vim.split(filename_part, "/") + local title = parts[#parts]:match("^%s*(.-)%s*$") + local link = "[" + .. title + .. "](../" + .. filename_and_category[#filename_and_category - 1] + .. "/" + .. filename_and_category[#filename_and_category] + .. ")" + vim.api.nvim_put({ link }, "", true, true) + end +end + -- -- local function paste_link() -- return function(prompt_bufnr) -- actions.close(prompt_bufnr) -- local selection = action_state.get_selected_entry() +-- print(selection.value) -- local filename_part = vim.split(selection.value, ":")[1] -- local link = "[[../" .. filename_part .. "]]" -- vim.api.nvim_put({ link }, "", true, true) -- end -- end -- --- M.search_title = function() --- require("telescope.builtin").live_grep({ --- cwd = "~/Dropbox/TextSync/NOTES/", --- prompt_title = "Search by zettel title", --- default_text = "^raw_title: ", --- attach_mappings = function(_, map) --- map("n", "", paste_titled_link()) --- map("i", "", paste_titled_link()) --- map("n", "", paste_link()) --- map("i", "", paste_link()) --- return true --- end, --- }) --- end --- -- M.copy_filename_to_clipboard = function(prompt_bufnr) -- local selection = action_state.get_selected_entry() -- local filename_part = vim.split(selection.value, ":")[1] @@ -55,66 +49,79 @@ local M = {} -- end M.search_raw_title = function(opts) - opts = opts or {} - local search_dir = opts.search_dir or "." + opts = opts or {} + local search_dir = opts.search_dir or "." - pickers.new(opts, { - prompt_title = "Search ETON", - finder = finders.new_job(function(prompt) - if not prompt then - return nil - end + pickers + .new(opts, { + prompt_title = "Search ETON", + finder = finders.new_job(function(prompt) + if not prompt then + return nil + end - -- Adjust the rg command to search for raw_title in all files - local cmd = { "rg", "--no-heading", "--color=never", "--with-filename", "--line-number", "-i", "raw_title:.*" .. prompt, search_dir } - return cmd - end, opts.entry_maker or function(entry) - local filename, lnum, raw_title = entry:match("([^:]+):(%d+):raw_title:(.*)") - if not filename then return nil end + -- Adjust the rg command to search for raw_title in all files + local cmd = { + "rg", + "--no-heading", + "--color=never", + "--with-filename", + "--line-number", + "-i", + "raw_title:.*" .. prompt, + search_dir, + } + return cmd + end, opts.entry_maker or function(entry) + local filename, lnum, raw_title = entry:match("([^:]+):(%d+):raw_title:(.*)") + if not filename then + return nil + end - -- Получаем только базовое имя файла - local basename = filename:match("^.+/(.+)$") or filename + -- Получаем только базовое имя файла + local basename = filename:match("^.+/(.+)$") or filename - return { - value = entry, - ordinal = basename .. " " .. (raw_title or ""), - display = basename .. " - " .. (raw_title or ""), - filename = filename, - lnum = tonumber(lnum), - } - end), - previewer = previewers.new_buffer_previewer({ - define_preview = function(self, entry, status) - conf.buffer_previewer_maker(entry.filename, self.state.bufnr, { - bufname = self.state.bufname, - winid = self.state.winid, - preview = self.state.preview - }) - vim.api.nvim_buf_call(self.state.bufnr, function() - vim.fn.cursor(entry.lnum, 0) - vim.cmd("normal! zz") - end) - end - }), - sorter = conf.generic_sorter(opts), - attach_mappings = function(_, map) - actions.select_default:replace(function() - local selection = action_state.get_selected_entry() - actions.close(_) - vim.cmd('edit ' .. selection.filename) - vim.fn.cursor(selection.lnum, 0) - end) - return true - end, - }):find() + return { + value = entry, + ordinal = basename .. " " .. (raw_title or ""), + display = basename .. " - " .. (raw_title or ""), + filename = filename, + lnum = tonumber(lnum), + } + end), + previewer = previewers.new_buffer_previewer({ + define_preview = function(self, entry, status) + conf.buffer_previewer_maker(entry.filename, self.state.bufnr, { + bufname = self.state.bufname, + winid = self.state.winid, + preview = self.state.preview, + }) + -- vim.api.nvim_buf_call(self.state.bufnr, function() + -- vim.fn.cursor(entry.lnum, 0) + -- vim.cmd("normal! zz") + -- end) + end, + }), + sorter = conf.generic_sorter(opts), + attach_mappings = function(_, map) + -- map("n", "", paste_titled_link()) + -- map("i", "", paste_titled_link()) + map("n", "", paste_titled_link()) + map("i", "", paste_titled_link()) + actions.select_default:replace(function() + local selection = action_state.get_selected_entry() + actions.close(_) + vim.cmd("vsplit " .. selection.filename) + vim.fn.cursor(selection.lnum, 0) + end) + return true + end, + }) + :find() end --- vim.api.nvim_create_user_command("SearchZettelTitle", M.search_title, {}) --- mapvimkey("fm", "SearchZettelTitle", "Search by zettel title") - --- vim.api.nvim_create_user_command("SearchZettelTitle", M.search_raw_title({search_dir='/Users/fz0x1/Dropbox/TextSync/NOTES/01-zettel/'}), {}) vim.api.nvim_create_user_command("SearchZettelTitle", function() - M.search_raw_title({ search_dir = '/Users/fz0x1/Dropbox/TextSync/NOTES/01-zettel/' }) + M.search_raw_title({ search_dir = "/Users/fz0x1/Dropbox/TextSync/NOTES/01-zettel/" }) end, {}) mapvimkey("fm", "SearchZettelTitle", "Search by zettel title")