diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index b4e4b250..e0d649e5 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -235,6 +235,9 @@ `languages/haskell.nix` - Made the haskell LSP and formatter configurable +- Added [csvview.nvim](https://github.com/hat0uma/csvview.nvim) support under + `vim.utility.csvview` for rendering CSV/TSV files as aligned tables. + [alfarel](https://github.com/alfarelcynthesis): [obsidian.nvim]: https://github.com/obsidian-nvim/obsidian.nvim diff --git a/modules/plugins/utility/csvview/config.nix b/modules/plugins/utility/csvview/config.nix new file mode 100644 index 00000000..2fcb2866 --- /dev/null +++ b/modules/plugins/utility/csvview/config.nix @@ -0,0 +1,50 @@ +{ + options, + config, + lib, + ... +}: let + inherit (lib.generators) mkLuaInline; + inherit (lib.modules) mkIf; + inherit (lib.nvim.binds) mkKeymap; + + cfg = config.vim.utility.csvview; + + keys = cfg.mappings; + inherit (options.vim.utility.csvview) mappings; +in { + config = mkIf cfg.enable { + vim = { + lazy.plugins.csvview-nvim = { + package = "csvview-nvim"; + setupModule = "csvview"; + inherit (cfg) setupOpts; + + cmd = ["CsvViewEnable" "CsvViewDisable" "CsvViewToggle" "CsvViewInfo"]; + + keys = [ + (mkKeymap "n" keys.toggle "CsvViewToggle" {desc = mappings.toggle.description;}) + ]; + }; + + # csvview.nvim has no built-in auto-enable, so drive it with a FileType + # autocommand. The `is_enabled` guard keeps this idempotent so + # re-firing FileType (e.g. `:e!`, `:set ft=csv`) doesn't warn about an + # already-attached buffer. + autocmds = mkIf cfg.autoEnable [ + { + event = ["FileType"]; + pattern = ["csv" "tsv"]; + callback = mkLuaInline '' + function(args) + if not require("csvview").is_enabled(args.buf) then + require("csvview").enable() + end + end + ''; + desc = "Automatically enable CSV view for CSV/TSV files"; + } + ]; + }; + }; +} diff --git a/modules/plugins/utility/csvview/csvview.nix b/modules/plugins/utility/csvview/csvview.nix new file mode 100644 index 00000000..167a8efe --- /dev/null +++ b/modules/plugins/utility/csvview/csvview.nix @@ -0,0 +1,80 @@ +{ + config, + lib, + ... +}: let + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) bool int str listOf enum; + inherit (lib.nvim.types) mkPluginSetupOption; + inherit (config.vim.lib) mkMappingOption; +in { + options.vim.utility.csvview = { + enable = mkEnableOption "View CSV/TSV files as aligned tables [csvview.nvim]"; + + autoEnable = + mkEnableOption '' + Automatically enable the CSV view when opening CSV/TSV files. + '' + // {default = true;}; + + mappings = { + toggle = mkMappingOption "Toggle CSV view [csvview]" "tc"; + }; + + # Note: These defaults are a subset of the csvview default configuration, as defined in + # [https://github.com/hat0uma/csvview.nvim/blob/5c22774c3ecc7f8883af5d143b366e45b1f0875d/README.md?plain=1#L97] + # which I think users would most likely want to modify + setupOpts = mkPluginSetupOption "csvview.nvim" { + parser = { + async_chunksize = mkOption { + type = int; + default = 50; + description = "Number of lines processed per asynchronous parsing cycle. If the UI freezes, try reducing this value."; + }; + + comments = mkOption { + type = listOf str; + default = []; + description = '' + List of comment prefixes. Lines starting with one of these are + treated as comments and excluded from table rendering, e.g. + `["#" "//"]`. + ''; + }; + }; + + view = { + min_column_width = mkOption { + type = int; + default = 5; + description = "Minimum width of a column"; + }; + + spacing = mkOption { + type = int; + default = 2; + description = "Spacing between columns"; + }; + + display_mode = mkOption { + type = enum ["highlight" "border"]; + default = "highlight"; + description = '' + Display method for the column delimiter. + + - `highlight`: highlight the delimiter character. + - `border`: render the delimiter as a vertical border. + ''; + }; + + sticky_header = { + enabled = mkOption { + type = bool; + default = true; + description = "Keep the header row visible at the top while scrolling"; + }; + }; + }; + }; + }; +} diff --git a/modules/plugins/utility/csvview/default.nix b/modules/plugins/utility/csvview/default.nix new file mode 100644 index 00000000..d9252771 --- /dev/null +++ b/modules/plugins/utility/csvview/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./csvview.nix + ./config.nix + ]; +} diff --git a/modules/plugins/utility/default.nix b/modules/plugins/utility/default.nix index a2a3d870..46ea4303 100644 --- a/modules/plugins/utility/default.nix +++ b/modules/plugins/utility/default.nix @@ -2,6 +2,7 @@ imports = [ ./binds ./ccc + ./csvview ./diffview ./direnv ./fzf-lua diff --git a/npins/sources.json b/npins/sources.json index f526937d..d05045c5 100644 --- a/npins/sources.json +++ b/npins/sources.json @@ -423,6 +423,19 @@ "url": "https://github.com/Decodetalkers/csharpls-extended-lsp.nvim/archive/be8093d19af1538aad9ee77dc5589e55b083967a.tar.gz", "hash": "sha256-MDr3n9LaQ/YTHD7egDohQ7YmT2+itWXNoMLigmZp3KQ=" }, + "csvview-nvim": { + "type": "Git", + "repository": { + "type": "GitHub", + "owner": "hat0uma", + "repo": "csvview.nvim" + }, + "branch": "main", + "submodules": false, + "revision": "5c22774c3ecc7f8883af5d143b366e45b1f0875d", + "url": "https://github.com/hat0uma/csvview.nvim/archive/5c22774c3ecc7f8883af5d143b366e45b1f0875d.tar.gz", + "hash": "sha256-JJZCrLhUzausIs61UfsE4472B1KzgZyI+BlbZH+gUn0=" + }, "dashboard-nvim": { "type": "Git", "repository": {