From 90a049ccbd48184af95b865f6a1f75eec064f350 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sat, 23 Nov 2024 13:14:04 +0100 Subject: refactor(modules/nvim/files): Move to their respective plugin --- modules/by-name/nv/nvim/files/default.nix | 15 ------ modules/by-name/nv/nvim/files/ftplugin/tex.lua | 60 ---------------------- modules/by-name/nv/nvim/module.nix | 1 - .../plgs/telescope/extensions/bibtex/default.nix | 10 +++- .../nvim/plgs/telescope/extensions/bibtex/tex.lua | 60 ++++++++++++++++++++++ 5 files changed, 69 insertions(+), 77 deletions(-) delete mode 100644 modules/by-name/nv/nvim/files/default.nix delete mode 100644 modules/by-name/nv/nvim/files/ftplugin/tex.lua create mode 100644 modules/by-name/nv/nvim/plgs/telescope/extensions/bibtex/tex.lua (limited to 'modules/by-name') diff --git a/modules/by-name/nv/nvim/files/default.nix b/modules/by-name/nv/nvim/files/default.nix deleted file mode 100644 index ef8afa1a..00000000 --- a/modules/by-name/nv/nvim/files/default.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ - config, - lib, - ... -}: let - cfg = config.soispha.programs.nvim; -in { - home-manager.users.soispha.programs.nixvim = lib.mkIf cfg.enable { - extraFiles = { - "ftplugin/tex.lua".text = '' - ${lib.strings.fileContents ./ftplugin/tex.lua} - ''; - }; - }; -} diff --git a/modules/by-name/nv/nvim/files/ftplugin/tex.lua b/modules/by-name/nv/nvim/files/ftplugin/tex.lua deleted file mode 100644 index 4107a7c5..00000000 --- a/modules/by-name/nv/nvim/files/ftplugin/tex.lua +++ /dev/null @@ -1,60 +0,0 @@ --- local used = false; --- vim.keymap.set('n', 't', function() --- used = not used; --- if used then --- require('nvim-treesitter.configs').setup { --- highlight = { --- additional_vim_regex_highlighting = { "latex", "markdown" }, --- }, --- } --- else --- require('nvim-treesitter.configs').setup { --- highlight = { --- additional_vim_regex_highlighting = { "" }, --- }, --- } --- end --- end --- ); --- --- - --- Set tex specific telescope extension -require("telescope").setup({ - extensions = { - bibtex = { - -- Depth for the *.bib file - depth = 1, - -- Path to global bibliographies (placed outside of the project) - global_files = {}, - -- Define the search keys to use in the picker - search_keys = { "author", "year", "title" }, - -- Template for the formatted citation - citation_format = "{{author}} ({{year}}), {{title}}.", - -- Only use initials for the authors first name - citation_trim_firstname = true, - -- Max number of authors to write in the formatted citation - -- following authors will be replaced by "et al." - citation_max_auth = 2, - -- Wrapping in the preview window is disabled by default - wrap = false, - -- Custom format for citation label - custom_formats = { - { id = "tex_autocite", cite_marker = "\\autocite{%s}" }, - }, - format = "tex_autocite", - -- Use context awareness - context = true, - -- Fallback to global/directory .bib files if context not found - -- This setting has no effect if context = false - context_fallback = true, - }, - }, -}) -require("telescope").load_extension("bibtex") -vim.keymap.set( - "n", - "ib", - function() require("telescope").extensions.bibtex.bibtex() end, - { noremap = true, silent = true, desc = "list bibtex entries in telescope" } -) diff --git a/modules/by-name/nv/nvim/module.nix b/modules/by-name/nv/nvim/module.nix index 829a9c2b..69e417bb 100644 --- a/modules/by-name/nv/nvim/module.nix +++ b/modules/by-name/nv/nvim/module.nix @@ -9,7 +9,6 @@ in { imports = [ ./autocmds ./clipboard - ./files ./mappings ./options ./plgs 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 index e263cfdc..818aa18e 100644 --- a/modules/by-name/nv/nvim/plgs/telescope/extensions/bibtex/default.nix +++ b/modules/by-name/nv/nvim/plgs/telescope/extensions/bibtex/default.nix @@ -6,11 +6,19 @@ }: 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 ]; + + # Only activate this in tex files. + # TODO: Why? <2024-11-23> + extraFiles = { + "ftplugin/tex.lua".text = '' + ${lib.strings.fileContents ./tex.lua} + ''; + }; + keymaps = [ { key = "ib"; diff --git a/modules/by-name/nv/nvim/plgs/telescope/extensions/bibtex/tex.lua b/modules/by-name/nv/nvim/plgs/telescope/extensions/bibtex/tex.lua new file mode 100644 index 00000000..4107a7c5 --- /dev/null +++ b/modules/by-name/nv/nvim/plgs/telescope/extensions/bibtex/tex.lua @@ -0,0 +1,60 @@ +-- local used = false; +-- vim.keymap.set('n', 't', function() +-- used = not used; +-- if used then +-- require('nvim-treesitter.configs').setup { +-- highlight = { +-- additional_vim_regex_highlighting = { "latex", "markdown" }, +-- }, +-- } +-- else +-- require('nvim-treesitter.configs').setup { +-- highlight = { +-- additional_vim_regex_highlighting = { "" }, +-- }, +-- } +-- end +-- end +-- ); +-- +-- + +-- Set tex specific telescope extension +require("telescope").setup({ + extensions = { + bibtex = { + -- Depth for the *.bib file + depth = 1, + -- Path to global bibliographies (placed outside of the project) + global_files = {}, + -- Define the search keys to use in the picker + search_keys = { "author", "year", "title" }, + -- Template for the formatted citation + citation_format = "{{author}} ({{year}}), {{title}}.", + -- Only use initials for the authors first name + citation_trim_firstname = true, + -- Max number of authors to write in the formatted citation + -- following authors will be replaced by "et al." + citation_max_auth = 2, + -- Wrapping in the preview window is disabled by default + wrap = false, + -- Custom format for citation label + custom_formats = { + { id = "tex_autocite", cite_marker = "\\autocite{%s}" }, + }, + format = "tex_autocite", + -- Use context awareness + context = true, + -- Fallback to global/directory .bib files if context not found + -- This setting has no effect if context = false + context_fallback = true, + }, + }, +}) +require("telescope").load_extension("bibtex") +vim.keymap.set( + "n", + "ib", + function() require("telescope").extensions.bibtex.bibtex() end, + { noremap = true, silent = true, desc = "list bibtex entries in telescope" } +) -- cgit 1.4.1