From b7571df4d6e9ac08506a738ddceeec0b141751b0 Mon Sep 17 00:00:00 2001 From: Party Wumpus <48649272+PartyWumpus@users.noreply.github.com> Date: Fri, 19 Sep 2025 09:47:41 +0100 Subject: [PATCH] languages/typst: Add inline preview via typst-concealer (#588) * add typst-concealer * Update modules/plugins/languages/typst.nix Co-authored-by: raf * add keybinds, resolve review etc * add changes back (it was easier than a rebase here) * add the newer conceal_in_normal option * run deno fmt * add "typ" to typos --------- Co-authored-by: raf --- .github/typos.toml | 1 + docs/release-notes/rl-0.8.md | 7 +++ modules/plugins/languages/typst.nix | 67 ++++++++++++++++++++++++++++- npins/sources.json | 13 ++++++ 4 files changed, 87 insertions(+), 1 deletion(-) diff --git a/.github/typos.toml b/.github/typos.toml index 2cd18dde..26be7d9b 100644 --- a/.github/typos.toml +++ b/.github/typos.toml @@ -5,6 +5,7 @@ default.extend-ignore-words-re = [ "befores", "annote", "viw", + "typ", "BA", # somehow "BANanaD3V" is valid, but BA is not... ] diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index 74a94b9c..82b3c77e 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -499,3 +499,10 @@ - Add [nvim-highlight-colors] plugin in `vim.ui.nvim-highlight-colors` with `enable` and `setupOpts` + +[PartyWumpus](https://github.com/PartyWumpus): + +[typst-concealer]: https://github.com/PartyWumpus/typst-concealer + +- Add inline typst concealing support under `vim.languages.typst` using + [typst-concealer]. diff --git a/modules/plugins/languages/typst.nix b/modules/plugins/languages/typst.nix index 08a2252b..32bce676 100644 --- a/modules/plugins/languages/typst.nix +++ b/modules/plugins/languages/typst.nix @@ -7,9 +7,10 @@ inherit (lib.options) mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; inherit (lib.lists) isList; - inherit (lib.types) nullOr enum either attrsOf listOf package str; + inherit (lib.types) nullOr enum either attrsOf listOf package str bool int; inherit (lib.attrsets) attrNames; inherit (lib.meta) getExe; + inherit (lib.nvim.binds) mkMappingOption mkKeymap; inherit (lib.nvim.lua) expToLua toLuaObject; inherit (lib.nvim.types) mkGrammarOption mkPluginSetupOption; inherit (lib.nvim.dag) entryAnywhere; @@ -150,6 +151,57 @@ in { }; }; }; + typst-concealer = { + enable = mkEnableOption '' + [typst-concealer]: https://github.com/PartyWumpus/typst-concealer + + Inline typst preview for Neovim via [typst-concealer] + ''; + + mappings = { + toggleConcealing = mkMappingOption "Enable typst-concealer in buffer" "TT"; + }; + + setupOpts = mkPluginSetupOption "typst-concealer" { + do_diagnostics = mkOption { + type = nullOr bool; + default = !cfg.lsp.enable; + description = "Should typst-concealer provide diagnostics on error?"; + }; + color = mkOption { + type = nullOr str; + default = null; + example = "rgb(\"#f012be\")"; + description = "What color should typst-concealer render text/stroke with? (only applies when styling_type is 'colorscheme')"; + }; + enabled_by_default = mkOption { + type = nullOr bool; + default = null; + description = "Should typst-concealer conceal newly opened buffers by default?"; + }; + styling_type = mkOption { + type = nullOr (enum ["simple" "none" "colorscheme"]); + default = null; + description = "What kind of styling should typst-concealer apply to your typst?"; + }; + ppi = mkOption { + type = nullOr int; + default = null; + description = "What PPI should typst render at. Plugin default is 300, typst's normal default is 144."; + }; + typst_location = mkOption { + type = str; + default = getExe pkgs.typst; + description = "Where should typst-concealer look for your typst binary?"; + example = ''lib.getExe pkgs.typst''; + }; + conceal_in_normal = mkOption { + type = nullOr bool; + default = null; + description = "Should typst-concealer still conceal when the normal mode cursor goes over a line."; + }; + }; + }; }; }; config = mkIf cfg.enable (mkMerge [ @@ -180,5 +232,18 @@ in { require("typst-preview").setup(${toLuaObject cfg.extensions.typst-preview-nvim.setupOpts}) ''; }) + + (mkIf cfg.extensions.typst-concealer.enable { + vim.lazy.plugins.typst-concealer = { + event = "BufRead *.typ"; + package = "typst-concealer"; + setupModule = "typst-concealer"; + setupOpts = cfg.extensions.typst-concealer.setupOpts; + + keys = [ + (mkKeymap "n" cfg.extensions.typst-concealer.mappings.toggleConcealing "lua require('typst-concealer').toggle_buf()" {desc = "Toggle typst-concealer in buffer";}) + ]; + }; + }) ]); } diff --git a/npins/sources.json b/npins/sources.json index cf4bb564..ff8662f3 100644 --- a/npins/sources.json +++ b/npins/sources.json @@ -2526,6 +2526,19 @@ "url": "https://github.com/dmmulroy/ts-error-translator.nvim/archive/47e5ba89f71b9e6c72eaaaaa519dd59bd6897df4.tar.gz", "hash": "08whn7l75qv5n74cifmnxc0s7n7ja1g7589pjnbbsk2djn6bqbky" }, + "typst-concealer": { + "type": "Git", + "repository": { + "type": "GitHub", + "owner": "PartyWumpus", + "repo": "typst-concealer" + }, + "branch": "main", + "submodules": false, + "revision": "3d2e72ce7fc06bd0db0dafbdd1e17d3c9e343d53", + "url": "https://github.com/PartyWumpus/typst-concealer/archive/3d2e72ce7fc06bd0db0dafbdd1e17d3c9e343d53.tar.gz", + "hash": "16j3q3hk1wzgcz6snn9997vclhkanplyn0cp1dm9lk034jd8v9nh" + }, "typst-preview-nvim": { "type": "Git", "repository": {