From 00009a92dac4cee2ce1583474cbcaa5c6750a286 Mon Sep 17 00:00:00 2001 From: Vu Quoc Huy <5112602+vqhuy@users.noreply.github.com> Date: Mon, 8 Apr 2024 01:36:16 +0200 Subject: [PATCH] Add support for bibtex-mode --- apheleia-formatters.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apheleia-formatters.el b/apheleia-formatters.el index 0a35876..ddecfdf 100644 --- a/apheleia-formatters.el +++ b/apheleia-formatters.el @@ -29,6 +29,7 @@ (apheleia-formatters-indent "--tab" "--indent-size" 'sh-basic-offset) "-")) + (bibtex-format . apheleia-reformat-bibtex-buffer) (black . ("black" (when (apheleia-formatters-extension-p "pyi") "--pyi") (apheleia-formatters-fill-column "--line-length") @@ -290,6 +291,7 @@ rather than using this system." (bash-ts-mode . shfmt) (bazel-mode . buildifier) (beancount-mode . bean-format) + (bibtex-mode . bibtex-format) (c++-ts-mode . clang-format) (caddyfile-mode . caddyfmt) (cc-mode . clang-format) @@ -1123,6 +1125,19 @@ For more implementation detail, see (indent-region (point-min) (point-max))) (funcall callback))) +(cl-defun apheleia-reformat-bibtex-buffer + (&key buffer scratch callback &allow-other-keys) + "Format a Bibtex BUFFER. +Use SCRATCH as a temporary buffer and CALLBACK to apply the +transformation. + +For more implementation detail, see +`apheleia--run-formatter-function'." + (with-current-buffer scratch + (funcall (with-current-buffer buffer major-mode)) + (bibtex-reformat) + (funcall callback))) + (defun apheleia--run-formatters (formatters buffer remote callback &optional stdin) "Run one or more code formatters on the current buffer.