diff options
Diffstat (limited to '.config/nvim/lua')
| -rw-r--r-- | .config/nvim/lua/plugins/telescope.lua | 97 | ||||
| -rw-r--r-- | .config/nvim/lua/user/keys.lua | 9 | ||||
| -rw-r--r-- | .config/nvim/lua/user/mods.lua | 15 |
3 files changed, 81 insertions, 40 deletions
diff --git a/.config/nvim/lua/plugins/telescope.lua b/.config/nvim/lua/plugins/telescope.lua index fb1b3ee..481cb7d 100644 --- a/.config/nvim/lua/plugins/telescope.lua +++ b/.config/nvim/lua/plugins/telescope.lua @@ -421,52 +421,77 @@ function M.find_books() local search_results = vim.fn.systemlist(search_cmd) local results = {} - local recent_books_section = {} -- To store recent books separately - for _, recent_book in ipairs(recent_books) do - table.insert(recent_books_section, 'Recent Books: ' .. recent_book) + -- Section for Recent Books + table.insert(results, ' Recent Books') + for _, recent_book_path in ipairs(recent_books) do + local formatted_path = vim.fn.fnameescape(recent_book_path) + table.insert(results, formatted_path) end + -- Section for All Books + table.insert(results, ' All Books') + local directories = {} + local files = {} + for _, search_result in ipairs(search_results) do - table.insert(results, search_result) + if vim.fn.isdirectory(search_result) == 1 then + table.insert(directories, search_result) + else + table.insert(files, search_result) + end end - -- Add the recent books section to the results - for _, recent_entry in ipairs(recent_books_section) do - table.insert(results, recent_entry) - end + table.sort(directories) + table.sort(files) - pickers - .new({}, { - prompt_title = 'Find Books', - finder = finders.new_table({ - results = results, - }), - previewer = require('telescope.previewers').vim_buffer_cat.new({}), - sorter = config.generic_sorter({}), - attach_mappings = function(prompt_bufnr, map) - actions_set.select:replace(function() - local entry = actions_state.get_selected_entry() - if entry ~= nil then - local path = entry.value + for _, dir in ipairs(directories) do + table.insert(results, dir) + end - actions.close(prompt_bufnr, false) - -- Determine whether it's a directory or a file - local is_directory = vim.fn.isdirectory(path) + for _, file in ipairs(files) do + table.insert(results, file) + end - if is_directory then - -- It's a directory, navigate to it in the current buffer - vim.cmd('e ' .. path) - else - -- It's a file, open it - vim.cmd('edit ' .. path) - end + local picker = pickers.new({}, { + prompt_title = 'Find Books', + finder = finders.new_table({ + results = results, + }), + file_ignore_patterns = { + '%.git', + }, + previewer = require('telescope.previewers').vim_buffer_cat.new({}), + sorter = config.generic_sorter({}), + attach_mappings = function(prompt_bufnr, map) + actions_set.select:replace(function() + local entry = actions_state.get_selected_entry() + if entry ~= nil then + local path = entry.value + + actions.close(prompt_bufnr, false) + + -- Check if it's under "Recent Books" + if path == ' Recent Books' or path == ' All Books' then + vim.notify("Cannot select 'All Books'/'Recent Books', please select a book or directory.", vim.log.levels.WARN, { title = 'Find Books' }) + else + -- Determine whether it's a directory or a file + local is_directory = vim.fn.isdirectory(path) + if is_directory then + -- It's a directory, navigate to it in the current buffer + vim.cmd('e ' .. path) + else + -- It's a file, open it + vim.cmd('e ' .. path) end - end) - return true - end, - }) - :find() + end + end + end) + return true + end, + }) + + picker:find() end function M.grep_current_dir() diff --git a/.config/nvim/lua/user/keys.lua b/.config/nvim/lua/user/keys.lua index a6be1e5..64e7cb0 100644 --- a/.config/nvim/lua/user/keys.lua +++ b/.config/nvim/lua/user/keys.lua @@ -59,8 +59,8 @@ map('n', '<Leader>m', ':marks<CR>') -- Messages map('n', '<Leader>M', ':messages<CR>') --- Clear messages or just refresh/redraw the screen -map('n', '<leader>u', ":echo '' | redraw<CR>") +--- Clear messages or just refresh/redraw the screen +map('n', '<leader>i', "<cmd>lua require('notify').dismiss()<CR>") -- Unsets the 'last search pattern' register by hitting return --map("n", "<CR>", "!silent :noh<CR><CR>") @@ -443,4 +443,7 @@ map('n', '<leader>H', '<CMD>lua require("plugins.hardtime").ToggleHardtime()<CR> map('n', '<leader>rr', '<CMD>lua require("user.mods").toggleCodeRunner()<CR>') -- Run executable file -map('n', '<leader>rc', ":lua require('user.mods').RunCurrentFile()<CR>:echom 'Running executable file...'<CR>:sl!<CR>:echo ''<CR>") +map('n', '<leader>rx', ":lua require('user.mods').RunCurrentFile()<CR>:echom 'Running executable file...'<CR>:sl!<CR>:echo ''<CR>") + +-- Close all floating windows +map('n', '<leader>cw', '<CMD>CloseFloatingWindows<CR>') diff --git a/.config/nvim/lua/user/mods.lua b/.config/nvim/lua/user/mods.lua index 49027da..c4431df 100644 --- a/.config/nvim/lua/user/mods.lua +++ b/.config/nvim/lua/user/mods.lua @@ -483,7 +483,7 @@ vim.api.nvim_create_autocmd({ 'VimLeave' }, { local modifiedBufs = function(bufs) -- nvim-tree is also there in modified buffers so this function filter it out local t = 0 for k, v in pairs(bufs) do - if v.name:match('NvimTree_') == nil then + if v.name:match('NvimTree_', 'NvimTree1') == nil then t = t + 1 end end @@ -1042,5 +1042,18 @@ end -------------------------------------------------- +-- Close all floating windows +vim.api.nvim_create_user_command('CloseFloatingWindows', function(opts) + for _, window_id in ipairs(vim.api.nvim_list_wins()) do + -- If window is floating + if vim.api.nvim_win_get_config(window_id).relative ~= '' then + -- Force close if called with ! + vim.api.nvim_win_close(window_id, opts.bang) + end + end +end, { bang = true, nargs = 0 }) + +-------------------------------------------------- + -- ... return M |
