make typst live editing and preview a thing

This commit is contained in:
Schrottkatze 2024-02-28 17:06:04 +01:00
parent 65039f4f17
commit 4f01412843
Signed by: schrottkatze
SSH key fingerprint: SHA256:hXb3t1vINBFCiDCmhRABHX5ocdbLiKyCdKI4HK2Rbbc
3 changed files with 104 additions and 30 deletions

View file

@ -183,6 +183,9 @@ in
oneko oneko
plover.dev plover.dev
mupdf
inotify-tools
]; ];
xsession = { xsession = {
enable = true; enable = true;

View file

@ -1,5 +1,12 @@
{config, ...}: { {config, ...}: {
home-manager.users.jade = {pkgs, ...}: { home-manager.users.jade = {pkgs, ...}: let
typstGrammar = pkgs.fetchFromGitHub {
owner = "uben0";
repo = "tree-sitter-typst";
rev = "baddc325e858afff90501dbefa00ecfa28528931";
sha256 = "sha256-XZAgnpb1B8EZ2WXPj/JYSZGsmpKsnDiBFCDF0XjunOM";
};
in {
home = { home = {
sessionVariables.EDITOR = "hx"; sessionVariables.EDITOR = "hx";
packages = [ packages = [
@ -7,15 +14,28 @@
pkgs.vscode-langservers-extracted pkgs.vscode-langservers-extracted
pkgs.nodePackages.typescript-language-server pkgs.nodePackages.typescript-language-server
pkgs.emmet-language-server pkgs.emmet-language-server
pkgs.typst-lsp
]; ];
}; };
home.file = {
".config/helix/runtime/queries" = {
source = "${typstGrammar}/queries";
};
};
programs.helix = { programs.helix = {
enable = true; enable = true;
settings = { settings = {
theme = "gruvbox"; theme = "gruvbox";
editor = { editor = {
line-number = "relative"; line-number = "relative";
lsp.display-messages = true; bufferline = "multiple";
color-modes = true;
lsp = {
display-messages = true;
display-inlay-hints = true;
};
shell = ["nu" "-c"];
idle-timeout = 0;
indent-guides = { indent-guides = {
render = true; render = true;
character = ""; character = "";
@ -38,32 +58,86 @@
}; };
}; };
languages = { languages = {
language-server."nu-builtin-lsp" = { language-server = {
command = "${config.users.defaultUserShell}/bin/nu"; "nu-builtin-lsp" = {
args = ["--lsp"]; command = "${config.users.defaultUserShell}/bin/nu";
}; args = ["--lsp"];
language-server."rust-analyzer" = { };
config = { "rust-analyzer" = {
check.command = "clippy"; config = {
check.command = "clippy";
completion.snippets.custom = {
"pub fn" = {
prefix = ["pfn" "pubfn"];
postfix = ["pfn"];
body = [
"pub fn $\{receiver\}() {"
"\\t$1"
"}"
];
scope = "type";
};
};
};
};
"emmet-language-server" = {
command = "emmet-language-server";
args = ["--stdio"];
};
# "php" = {
# name = "php";
# file-types = [ "php" ];
# language-server = {
# command = "psalm";
# args = ["--language-server"];
# };
# };
"typst-lsp" = {
command = "typst-lsp";
config = {
exportPdf = "onType";
};
}; };
}; };
language-server."emmet-language-server" = { grammar = [
command = "emmet-language-server"; {
args = ["--stdio"]; name = "typst";
}; source = {
# "php" = { git = "https://github.com/uben0/tree-sitter-typst";
# name = "php"; rev = "baddc325e858afff90501dbefa00ecfa28528931";
# file-types = [ "php" ]; # path = "${typstGrammar}";
# language-server = { };
# command = "psalm"; }
# args = ["--language-server"]; ];
# };
# };
language = [ language = [
{ {
name = "nu"; name = "nu";
language-servers = ["nu-builtin-lsp"]; language-servers = ["nu-builtin-lsp"];
} }
{
name = "typst";
scope = "source.typst";
file-types = ["typ" "typst"];
injection-regex = "typ(st)?";
comment-token = "//";
indent = {
tab-width = 2;
unit = " ";
};
roots = ["typst.toml"];
formatter = {
command = "${pkgs.typstfmt}/bin/typstfmt";
};
auto-format = true;
language-servers = ["typst-lsp"];
auto-pairs = {
"(" = ")";
"{" = "}";
"[" = "]";
"$" = "$";
"\"" = "\"";
};
}
{ {
name = "nix"; name = "nix";
formatter = { formatter = {

View file

@ -803,18 +803,15 @@ def glog [
] { ] {
git log --pretty=%h»¦«%s»¦«%aN»¦«%aE»¦«%aD -n $amount git log --pretty=%h»¦«%s»¦«%aN»¦«%aE»¦«%aD -n $amount
| lines | lines
| split column "»¦«" commit subject name email date | split column "»¦«u commit subject name email date"
} }
def ed [ def typed [
file: path name: string
...cmdargs: string
] { ] {
let ext = $file | path parse | get extension; touch $"($name).typ"
match $ext { typst compile $"($name).typ"
"typ" => {|| zellij run --direction down -- typst watch $file ($cmdargs | prepend '--open' | str join ' ') } mprocs --names Editor,Viewer,Notify $"hx '($name).typ'" $"mupdf-x11 '($name).pdf'" $"while inotifywait -e modify '($name).pdf' ; do pkill -HUP mupdf; done"
};
hx $file
} }
alias gnix = cd ~/nix-configs; alias gnix = cd ~/nix-configs;