diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-11-09 12:35:44 +0100 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-11-09 12:54:51 +0100 |
commit | 2122a01f99c6da466b8f0f55c965c11a9043d117 (patch) | |
tree | 6c1697afc30a5bb72635bda7db9b5610386a5b71 /modules/by-name/nv/nvim/plgs/telescope | |
parent | fix(pkgs/stamp): Fallback to `dot-license` (diff) | |
download | nixos-config-2122a01f99c6da466b8f0f55c965c11a9043d117.tar.gz nixos-config-2122a01f99c6da466b8f0f55c965c11a9043d117.zip |
refactor(modules/legacy/conf/nvim): Move to `by-name`
Diffstat (limited to 'modules/by-name/nv/nvim/plgs/telescope')
10 files changed, 295 insertions, 0 deletions
diff --git a/modules/by-name/nv/nvim/plgs/telescope/default.nix b/modules/by-name/nv/nvim/plgs/telescope/default.nix new file mode 100644 index 00000000..193ee1ac --- /dev/null +++ b/modules/by-name/nv/nvim/plgs/telescope/default.nix @@ -0,0 +1,23 @@ +{ + config, + lib, + ... +}: let + cfg = config.soispha.programs.nvim; +in { + imports = [ + ./defaults + ./keymaps + ./extensions + ]; + home-manager.users.soispha.programs.nixvim.plugins = lib.mkIf cfg.enable { + telescope = { + enable = true; + }; + + # This is a dependency of telescope + web-devicons = { + enable = true; + }; + }; +} diff --git a/modules/by-name/nv/nvim/plgs/telescope/defaults/default.nix b/modules/by-name/nv/nvim/plgs/telescope/defaults/default.nix new file mode 100644 index 00000000..11d04304 --- /dev/null +++ b/modules/by-name/nv/nvim/plgs/telescope/defaults/default.nix @@ -0,0 +1,36 @@ +{ + config, + lib, + ... +}: let + cfg = config.soispha.programs.nvim; +in { + home-manager.users.soispha.programs.nixvim.plugins.telescope.settings.defaults = lib.mkIf cfg.enable { + mappings = let + insert_and_normal_mappings = { + # map actions.which_key to <c-h> (default: <c-/>) + # actions.which_key shows the mappings for your picker, + # e.g. git_{create, delete, ...}_branch for the git_branches picker + "<C-h>" = "which_key"; + }; + in { + i = + insert_and_normal_mappings; + n = + { + "t" = "move_selection_next"; + "n" = "move_selection_previous"; + "<Space>" = "toggle_all"; + + "<C-d>" = "preview_scrolling_up"; + "<C-u>" = "preview_scrolling_down"; + "<Left>" = "preview_scrolling_left"; + "<Right>" = "preview_scrolling_right"; + + "<Esc>" = "close"; + "q" = "close"; + } + // insert_and_normal_mappings; + }; + }; +} diff --git a/modules/by-name/nv/nvim/plgs/telescope/extensions/bibtex/default.nix b/modules/by-name/nv/nvim/plgs/telescope/extensions/bibtex/default.nix new file mode 100644 index 00000000..e263cfdc --- /dev/null +++ b/modules/by-name/nv/nvim/plgs/telescope/extensions/bibtex/default.nix @@ -0,0 +1,24 @@ +{ + pkgs, + config, + lib, + ... +}: let + cfg = config.soispha.programs.nvim; +in { + # WARNING: This is only activated in tex files via the ftplugin. + home-manager.users.soispha.programs.nixvim = lib.mkIf cfg.enable { + extraPlugins = [ + pkgs.vimExtraPlugins.telescope-bibtex-nvim + ]; + keymaps = [ + { + key = "<space>ib"; + # This is registered in the ftplugin file, so we set this to null here + action = "<Nop>"; + mode = "n"; + options.desc = "[i]nsert a [b]atex citation"; + } + ]; + }; +} diff --git a/modules/by-name/nv/nvim/plgs/telescope/extensions/default.nix b/modules/by-name/nv/nvim/plgs/telescope/extensions/default.nix new file mode 100644 index 00000000..0b1e033a --- /dev/null +++ b/modules/by-name/nv/nvim/plgs/telescope/extensions/default.nix @@ -0,0 +1,9 @@ +{...}: { + imports = [ + ./bibtex + ./frecency + ./fzy-native + ./rooter + ./symbols + ]; +} diff --git a/modules/by-name/nv/nvim/plgs/telescope/extensions/frecency/default.nix b/modules/by-name/nv/nvim/plgs/telescope/extensions/frecency/default.nix new file mode 100644 index 00000000..f4e3d116 --- /dev/null +++ b/modules/by-name/nv/nvim/plgs/telescope/extensions/frecency/default.nix @@ -0,0 +1,28 @@ +{ + lib, + config, + ... +}: let + cfg = config.soispha.programs.nvim; +in { + home-manager.users.soispha.programs.nixvim = lib.mkIf cfg.enable { + keymaps = [ + { + key = "gff"; + mode = "n"; + action.__raw = "function() require('telescope').extensions.frecency.frecency() end"; + options.desc = "activate the frecency file selection"; + } + ]; + plugins.telescope = { + extensions.frecency = { + enable = true; + settings = { + show_scores = true; + db_safe_mode = false; + default_workspace = "CWD"; # or 'LSP' + }; + }; + }; + }; +} diff --git a/modules/by-name/nv/nvim/plgs/telescope/extensions/fzy-native/default.nix b/modules/by-name/nv/nvim/plgs/telescope/extensions/fzy-native/default.nix new file mode 100644 index 00000000..4194e688 --- /dev/null +++ b/modules/by-name/nv/nvim/plgs/telescope/extensions/fzy-native/default.nix @@ -0,0 +1,11 @@ +{ + config, + lib, + ... +}: let + cfg = config.soispha.programs.nvim; +in { + home-manager.users.soispha.programs.nixvim.plugins.telescope.extensions.fzy-native = lib.mkIf cfg.enable { + enable = true; + }; +} diff --git a/modules/by-name/nv/nvim/plgs/telescope/extensions/rooter/default.nix b/modules/by-name/nv/nvim/plgs/telescope/extensions/rooter/default.nix new file mode 100644 index 00000000..6153b063 --- /dev/null +++ b/modules/by-name/nv/nvim/plgs/telescope/extensions/rooter/default.nix @@ -0,0 +1,13 @@ +{ + lib, + config, + ... +}: let + cfg = config.soispha.programs.nvim; +in { + home-manager.users.soispha.programs.nixvim = lib.mkIf cfg.enable { + extraConfigLuaPost = '' + ${lib.strings.fileContents ./lua/rooter.lua} + ''; + }; +} diff --git a/modules/by-name/nv/nvim/plgs/telescope/extensions/rooter/lua/rooter.lua b/modules/by-name/nv/nvim/plgs/telescope/extensions/rooter/lua/rooter.lua new file mode 100644 index 00000000..48a8588d --- /dev/null +++ b/modules/by-name/nv/nvim/plgs/telescope/extensions/rooter/lua/rooter.lua @@ -0,0 +1,76 @@ +-- Taken from: https://github.com/desdic/telescope-rooter.nvim/blob/69423216c75a5f1f1477bbf8faf6b0dc8af04099/lua/telescope/_extensions/rooter.lua +local has_telescope, telescope = pcall(require, "telescope") +if not has_telescope then + error("This extension requires telescope.nvim") + return +end + +local has_plenary, plenary = pcall(require, "plenary") +if not has_plenary then + error("This extension requires plenary") + return +end + +local log = plenary.log.new({ plugin = "telescope_rooter", level = "info" }) + +-- TODO: expose this function +local toggle = function(_) + vim.g["Telescope#rooter#enabled"] = not vim.g["Telescope#rooter#enabled"] + print("Telescope#rooter#enabled=" .. vim.inspect(vim.g["Telescope#rooter#enabled"])) +end + +local config = { patterns = { ".git" }, enable = true, debug = false } + +-- default enabled +vim.g["Telescope#rooter#enabled"] = vim.F.if_nil(config.enable, true) + +-- redefine log if debug enabled +if vim.F.if_nil(config.debug, false) then log = plenary.log.new({ plugin = "telescope_rooter", level = "debug" }) end + +local group = vim.api.nvim_create_augroup("TelescopeRooter", { clear = true }) + +vim.api.nvim_create_autocmd({ "DirChangedPre" }, { + callback = function() + if vim.g["Telescope#rooter#enabled"] ~= true then return end + + if vim.g["Telescope#rooter#oldpwd"] == nil then + vim.g["Telescope#rooter#oldpwd"] = vim.loop.cwd() + log.debug("before " .. vim.inspect(vim.loop.cwd())) + end + end, + group = group, +}) + +vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, { + callback = function() + if vim.g["Telescope#rooter#enabled"] ~= true then return end + + vim.schedule(function() + if vim.bo.filetype == "TelescopePrompt" then + local rootdir = vim.fs.dirname(vim.fs.find(config.patterns, { upward = true })[1]) + if rootdir ~= nil then + vim.api.nvim_set_current_dir(rootdir) + log.debug("changing dir to " .. rootdir) + end + end + end) + end, + group = group, +}) + +vim.api.nvim_create_autocmd({ "BufWinLeave" }, { + callback = function() + if vim.g["Telescope#rooter#enabled"] ~= true then return end + + vim.schedule(function() + if vim.bo.filetype ~= "TelescopePrompt" then + if vim.g["Telescope#rooter#oldpwd"] ~= nil then + log.debug("restoring " .. vim.g["Telescope#rooter#oldpwd"]) + vim.api.nvim_set_current_dir(vim.g["Telescope#rooter#oldpwd"]) + vim.g["Telescope#rooter#oldpwd"] = nil + end + end + end) + end, + group = group, +}) diff --git a/modules/by-name/nv/nvim/plgs/telescope/extensions/symbols/default.nix b/modules/by-name/nv/nvim/plgs/telescope/extensions/symbols/default.nix new file mode 100644 index 00000000..adbb466a --- /dev/null +++ b/modules/by-name/nv/nvim/plgs/telescope/extensions/symbols/default.nix @@ -0,0 +1,59 @@ +{ + pkgs, + config, + lib, + ... +}: let + cfg = config.soispha.programs.nvim; +in { + home-manager.users.soispha.programs.nixvim = lib.mkIf cfg.enable { + extraPlugins = [ + # Source of symbols for telescope symbols + pkgs.vimPlugins.telescope-symbols-nvim + ]; + keymaps = [ + { + key = "<space>il"; + mode = "n"; + action.__raw = '' + function() + require('telescope.builtin').symbols{ sources = { + 'latex' + }} + end + ''; + options.desc = "[i]nsert a [l]atex symbol"; + } + { + key = "<space>ie"; + mode = "n"; + action.__raw = '' + function() + require('telescope.builtin').symbols{ sources = { + 'emoji', + }} + end + ''; + options.desc = "[i]nsert a [e]moji"; + } + { + key = "<space>is"; + mode = "n"; + action.__raw = '' + function() + require('telescope.builtin').symbols{ sources = { + 'emoji', + 'gitmoji', + 'julia', + 'kaomoji', + 'latex', + 'math', + 'nerd', + }} + end + ''; + options.desc = "[i]nsert a [s]ymbol (like emojis)"; + } + ]; + }; +} diff --git a/modules/by-name/nv/nvim/plgs/telescope/keymaps/default.nix b/modules/by-name/nv/nvim/plgs/telescope/keymaps/default.nix new file mode 100644 index 00000000..a474f097 --- /dev/null +++ b/modules/by-name/nv/nvim/plgs/telescope/keymaps/default.nix @@ -0,0 +1,16 @@ +{ + config, + lib, + ... +}: let + cfg = config.soispha.programs.nvim; +in { + home-manager.users.soispha.programs.nixvim.plugins.telescope.keymaps = lib.mkIf cfg.enable { + "<space>rg" = { + action = "live_grep"; + options = { + desc = "[rg] in a live session"; + }; + }; + }; +} |