From 4d5547b660194c45bcb5c9803123441a21810ab2 Mon Sep 17 00:00:00 2001 From: dalu Date: Fri, 16 Aug 2024 14:43:14 +0800 Subject: [PATCH] Add support for typstyle --- CHANGELOG.md | 7 +++++++ apheleia-formatters.el | 3 +++ test/formatters/installers/typstyle.bash | 4 ++++ test/formatters/samplecode/typstyle/in.typ | 10 ++++++++++ test/formatters/samplecode/typstyle/out.typ | 9 +++++++++ 5 files changed, 33 insertions(+) create mode 100644 test/formatters/installers/typstyle.bash create mode 100644 test/formatters/samplecode/typstyle/in.typ create mode 100644 test/formatters/samplecode/typstyle/out.typ diff --git a/CHANGELOG.md b/CHANGELOG.md index 213d04f..fc2b89c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog]. +## Unreleased +### Formatters +* [`typstyle`](https://github.com/Enter-tainer/typstyle) for + [typst](https://typst.app/) ([#313]). + +[#313]: https://github.com/radian-software/apheleia/pull/313 + ## 4.2 (released 2024-08-03) ### Changes * Custom Emacs Lisp formatting functions have the option to report an diff --git a/apheleia-formatters.el b/apheleia-formatters.el index 6257e09..3e37b4f 100644 --- a/apheleia-formatters.el +++ b/apheleia-formatters.el @@ -194,6 +194,7 @@ (rustfmt . ("rustfmt" "--quiet" "--emit" "stdout")) (terraform . ("terraform" "fmt" "-")) (treefmt . ("treefmt" "--stdin" filepath)) + (typstyle . ("typstyle")) (xmllint . ("xmllint" "--format" "-")) (yapf . ("yapf")) (yq-csv . ("yq" "--prettyPrint" "--no-colors" @@ -364,6 +365,8 @@ rather than using this system." (tuareg-mode . ocamlformat) (typescript-mode . prettier-typescript) (typescript-ts-mode . prettier-typescript) + (typst-mode . typstyle) + (typst-ts-mode . typstyle) (web-mode . prettier) (yaml-mode . prettier-yaml) (yaml-ts-mode . prettier-yaml) diff --git a/test/formatters/installers/typstyle.bash b/test/formatters/installers/typstyle.bash new file mode 100644 index 0000000..8779815 --- /dev/null +++ b/test/formatters/installers/typstyle.bash @@ -0,0 +1,4 @@ +ver="$(latest_release Enter-tainer/typstyle)" + +wget "https://github.com/Enter-tainer/typstyle/releases/download/${ver}/typstyle-x86_64-unknown-linux-gnu " -O /usr/local/bin/typstyle +chmod +x /usr/local/bin/typstyle diff --git a/test/formatters/samplecode/typstyle/in.typ b/test/formatters/samplecode/typstyle/in.typ new file mode 100644 index 0000000..7efdeb1 --- /dev/null +++ b/test/formatters/samplecode/typstyle/in.typ @@ -0,0 +1,10 @@ +#{ + let (title, + _) = query(heading.where(level: + 1)).map(e => ( + e.body, + e.location() + .page(), + )).rev().find(((_, v)) => v + <= page) +} diff --git a/test/formatters/samplecode/typstyle/out.typ b/test/formatters/samplecode/typstyle/out.typ new file mode 100644 index 0000000..0d6c08d --- /dev/null +++ b/test/formatters/samplecode/typstyle/out.typ @@ -0,0 +1,9 @@ +#{ + let (title, _) = query(heading.where(level: 1)) + .map(e => ( + e.body, + e.location().page(), + )) + .rev() + .find(((_, v)) => v <= page) +}