diff --git a/vim/.vim/lua/config/fig.lua b/vim/.vim/lua/config/fig.lua index 7aebd86..c1694e9 100644 --- a/vim/.vim/lua/config/fig.lua +++ b/vim/.vim/lua/config/fig.lua @@ -2,8 +2,6 @@ local map = require("utils").map local use_google = require("utils").use_google if use_google() then - map("n", "tm", ":Telescope citc modified") - -- [F]ig [S]tatus map("n", "fs", [[lua require('telescope').extensions.fig.status{}]]) diff --git a/vim/.vim/lua/plugins/base.lua b/vim/.vim/lua/plugins/base.lua index 6892ab4..ed833e1 100644 --- a/vim/.vim/lua/plugins/base.lua +++ b/vim/.vim/lua/plugins/base.lua @@ -1,7 +1,28 @@ local use_google = require("utils").use_google +local buf_too_large = require("utils").buf_too_large return { - "RRethy/vim-illuminate", + { + "RRethy/vim-illuminate", + config = function() + local aug = vim.api.nvim_create_augroup("buf_large", { clear = true }) + vim.api.nvim_create_autocmd({ "BufReadPre" }, { + callback = function() + if buf_too_large() then + vim.b.large_buf = true + vim.cmd("syntax off") + vim.cmd("IlluminatePauseBuf") -- disable vim-illuminate + vim.opt_local.foldmethod = "manual" + vim.opt_local.spell = false + else + vim.b.large_buf = false + end + end, + group = aug, + pattern = "*", + }) + end, + }, "kdheepak/lazygit.nvim", "flwyd/vim-conjoin", "rafcamlet/nvim-luapad", @@ -21,6 +42,9 @@ return { opts = { -- add any custom options here }, + keys = { + { "s", [[lua require("persistence").load()]] }, + }, }, { "johmsalas/text-case.nvim", diff --git a/vim/.vim/lua/plugins/nvim-treesitter.lua b/vim/.vim/lua/plugins/nvim-treesitter.lua index 67fbeab..98299ac 100644 --- a/vim/.vim/lua/plugins/nvim-treesitter.lua +++ b/vim/.vim/lua/plugins/nvim-treesitter.lua @@ -48,11 +48,11 @@ return { if lang == "gdrama" then return true end + local file_too_large = require("utils").file_too_large - local max_filesize = 100 * 1024 -- 100 KB local fname = vim.api.nvim_buf_get_name(buf) - local ok, stats = pcall(vim.loop.fs_stat, fname) - if ok and stats and stats.size > max_filesize then + + if file_too_large(fname) then vim.schedule(function() vim.notify( string.format( @@ -63,6 +63,7 @@ return { end) return true end + return false end, -- Setting this to true will run `:h syntax` and tree-sitter at the same time. diff --git a/vim/.vim/lua/plugins/telescope.lua b/vim/.vim/lua/plugins/telescope.lua index e1dcc02..3b7f9d2 100644 --- a/vim/.vim/lua/plugins/telescope.lua +++ b/vim/.vim/lua/plugins/telescope.lua @@ -1,4 +1,5 @@ local use_google = require("utils").use_google +local exec = require("utils").exec local TableConcat = require("utils").TableConcat local scopes = require("neoscopes") @@ -20,12 +21,17 @@ _G.search_cwd = function() builtin.find_files({ cwd = utils.buffer_dir() }) end -_G.live_grep = function() +_G.live_grep = function(search_dirs) require("telescope.builtin").live_grep({ - search_dirs = scopes.get_current_dirs(), + search_dirs = search_dirs, + -- search_dirs = , }) end +local function exe(cmd) + return vim.split(vim.fn.system(cmd), "\n") +end + local function get_visual_selection() -- Yank current visual selection into the 'v' register -- @@ -35,16 +41,21 @@ local function get_visual_selection() return vim.fn.getreg("v") end +function fig_modified() + return exe("hg pstatus -ma -n --no-status --template=") +end +function fig_all_modified() + return exe("hg status -ma -n --rev p4base --no-status --template=") +end + local keys = { - { "", ":lua find_files()", desc = "Find Files in CWD" }, + { "", ":lua find_files(scopes.get_current_dirs())", desc = "Find Files in CWD" }, { "e", ":lua search_cwd()", desc = "Find Files in Buffer Directory" }, { "tc", ":Telescope textcase", desc = "Text case" }, { "t.", ":lua find_dotfiles()", desc = "Find Dotfiles" }, { "tdc", ":Telescope dap commands" }, { "tdc", ":Telescope dap configurations" }, { "td", ":lua find_dotfiles()", desc = "Find Dotfiles" }, - { "tf", ":lua find_files()", desc = "Find Files in CWD" }, - { "tf.", ":lua vim.error('use e')", desc = "Find Files in Buffer Directory" }, { "tg", ":Telescope git_files", desc = "Git Files" }, { "th", ":lua require('telescope.builtin').help_tags{}", desc = "[T]elescope [H]elp" }, { "tk", ":Telescope keymaps", desc = "Keymaps" }, @@ -52,11 +63,15 @@ local keys = { { "tn", ":Telescope notify", desc = "Notifications" }, { "to", ":Telescope oldfiles", desc = "Recent(oldfiles) Files" }, { "tr", ":Telescope resume", desc = "Telescope Resume" }, - { "ts", ":lua live_grep()", desc = "Search in CWD" }, + { "ts", ":lua live_grep(scopes.get_current_dirs())", desc = "Search in CWD" }, } if use_google() then TableConcat(keys, { + { "tm", ":lua find_files(fig_modified())" }, + { "tM", ":lua find_files(fig_all_modified())" }, + { "tF", ":lua live_grep(fig_all_modified())", desc = "Search in *all* modified Fig files." }, + { "tf", ":lua live_grep(fig_modified())", desc = "Search in modified Fig files." }, { "", [[lua require('telescope').extensions.codesearch.find_files{}]], "n" }, { "cs", [[lua require('telescope').extensions.codesearch.find_query{}]] }, { "cs", [[lua require('telescope').extensions.codesearch.find_query{}]], mode = "v" }, diff --git a/vim/.vim/lua/utils.lua b/vim/.vim/lua/utils.lua index 21862bb..5e8c61f 100644 --- a/vim/.vim/lua/utils.lua +++ b/vim/.vim/lua/utils.lua @@ -2,6 +2,17 @@ local M = { use_google_cache = nil, } +function M.exec(command, args) + local Job = require("plenary.job") + local job = Job:new({ + command = command, + args = args, + }) + job:sync() + job:wait() + return job:result() +end + function M.map(mode, lhs, rhs, opts) local options = { noremap = true } if opts then @@ -11,6 +22,19 @@ function M.map(mode, lhs, rhs, opts) vim.keymap.set(mode, lhs, rhs, options) end +function M.file_too_large(filename) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(vim.loop.fs_stat, filename) + if ok and stats and stats.size > max_filesize then + return true + end + return false +end + +function M.buf_too_large() + return M.file_too_large(vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf())) +end + function M.use_google() if M.use_google_cache == nil then M.use_google_cache = M.file_exists(os.getenv("HOME") .. "/use_google")