Skip to content

Commit b7571df

Browse files
languages/typst: Add inline preview via typst-concealer (#588)
* add typst-concealer * Update modules/plugins/languages/typst.nix Co-authored-by: raf <[email protected]> * 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 <[email protected]>
1 parent 1bd9fc1 commit b7571df

File tree

4 files changed

+87
-1
lines changed

4 files changed

+87
-1
lines changed

.github/typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ default.extend-ignore-words-re = [
55
"befores",
66
"annote",
77
"viw",
8+
"typ",
89
"BA", # somehow "BANanaD3V" is valid, but BA is not...
910
]
1011

docs/release-notes/rl-0.8.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,10 @@
499499

500500
- Add [nvim-highlight-colors] plugin in `vim.ui.nvim-highlight-colors` with
501501
`enable` and `setupOpts`
502+
503+
[PartyWumpus](https://github.com/PartyWumpus):
504+
505+
[typst-concealer]: https://github.com/PartyWumpus/typst-concealer
506+
507+
- Add inline typst concealing support under `vim.languages.typst` using
508+
[typst-concealer].

modules/plugins/languages/typst.nix

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
inherit (lib.options) mkEnableOption mkOption;
88
inherit (lib.modules) mkIf mkMerge;
99
inherit (lib.lists) isList;
10-
inherit (lib.types) nullOr enum either attrsOf listOf package str;
10+
inherit (lib.types) nullOr enum either attrsOf listOf package str bool int;
1111
inherit (lib.attrsets) attrNames;
1212
inherit (lib.meta) getExe;
13+
inherit (lib.nvim.binds) mkMappingOption mkKeymap;
1314
inherit (lib.nvim.lua) expToLua toLuaObject;
1415
inherit (lib.nvim.types) mkGrammarOption mkPluginSetupOption;
1516
inherit (lib.nvim.dag) entryAnywhere;
@@ -150,6 +151,57 @@ in {
150151
};
151152
};
152153
};
154+
typst-concealer = {
155+
enable = mkEnableOption ''
156+
[typst-concealer]: https://github.com/PartyWumpus/typst-concealer
157+
158+
Inline typst preview for Neovim via [typst-concealer]
159+
'';
160+
161+
mappings = {
162+
toggleConcealing = mkMappingOption "Enable typst-concealer in buffer" "<leader>TT";
163+
};
164+
165+
setupOpts = mkPluginSetupOption "typst-concealer" {
166+
do_diagnostics = mkOption {
167+
type = nullOr bool;
168+
default = !cfg.lsp.enable;
169+
description = "Should typst-concealer provide diagnostics on error?";
170+
};
171+
color = mkOption {
172+
type = nullOr str;
173+
default = null;
174+
example = "rgb(\"#f012be\")";
175+
description = "What color should typst-concealer render text/stroke with? (only applies when styling_type is 'colorscheme')";
176+
};
177+
enabled_by_default = mkOption {
178+
type = nullOr bool;
179+
default = null;
180+
description = "Should typst-concealer conceal newly opened buffers by default?";
181+
};
182+
styling_type = mkOption {
183+
type = nullOr (enum ["simple" "none" "colorscheme"]);
184+
default = null;
185+
description = "What kind of styling should typst-concealer apply to your typst?";
186+
};
187+
ppi = mkOption {
188+
type = nullOr int;
189+
default = null;
190+
description = "What PPI should typst render at. Plugin default is 300, typst's normal default is 144.";
191+
};
192+
typst_location = mkOption {
193+
type = str;
194+
default = getExe pkgs.typst;
195+
description = "Where should typst-concealer look for your typst binary?";
196+
example = ''lib.getExe pkgs.typst'';
197+
};
198+
conceal_in_normal = mkOption {
199+
type = nullOr bool;
200+
default = null;
201+
description = "Should typst-concealer still conceal when the normal mode cursor goes over a line.";
202+
};
203+
};
204+
};
153205
};
154206
};
155207
config = mkIf cfg.enable (mkMerge [
@@ -180,5 +232,18 @@ in {
180232
require("typst-preview").setup(${toLuaObject cfg.extensions.typst-preview-nvim.setupOpts})
181233
'';
182234
})
235+
236+
(mkIf cfg.extensions.typst-concealer.enable {
237+
vim.lazy.plugins.typst-concealer = {
238+
event = "BufRead *.typ";
239+
package = "typst-concealer";
240+
setupModule = "typst-concealer";
241+
setupOpts = cfg.extensions.typst-concealer.setupOpts;
242+
243+
keys = [
244+
(mkKeymap "n" cfg.extensions.typst-concealer.mappings.toggleConcealing "<cmd>lua require('typst-concealer').toggle_buf()<CR>" {desc = "Toggle typst-concealer in buffer";})
245+
];
246+
};
247+
})
183248
]);
184249
}

npins/sources.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,6 +2526,19 @@
25262526
"url": "https://github.com/dmmulroy/ts-error-translator.nvim/archive/47e5ba89f71b9e6c72eaaaaa519dd59bd6897df4.tar.gz",
25272527
"hash": "08whn7l75qv5n74cifmnxc0s7n7ja1g7589pjnbbsk2djn6bqbky"
25282528
},
2529+
"typst-concealer": {
2530+
"type": "Git",
2531+
"repository": {
2532+
"type": "GitHub",
2533+
"owner": "PartyWumpus",
2534+
"repo": "typst-concealer"
2535+
},
2536+
"branch": "main",
2537+
"submodules": false,
2538+
"revision": "3d2e72ce7fc06bd0db0dafbdd1e17d3c9e343d53",
2539+
"url": "https://github.com/PartyWumpus/typst-concealer/archive/3d2e72ce7fc06bd0db0dafbdd1e17d3c9e343d53.tar.gz",
2540+
"hash": "16j3q3hk1wzgcz6snn9997vclhkanplyn0cp1dm9lk034jd8v9nh"
2541+
},
25292542
"typst-preview-nvim": {
25302543
"type": "Git",
25312544
"repository": {

0 commit comments

Comments
 (0)