aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVu Quoc Huy <5112602+vqhuy@users.noreply.github.com>2025-11-28 20:51:35 +0100
committerGitHub <noreply@github.com>2025-11-28 11:51:35 -0800
commit436cd94b3e01c8c4314645417ce40b1acdb5d2cb (patch)
tree0cc47b4f5de73f9479f3194b0234d8c6018ba023
parent1fac3a885d13680d60f161ed29cae1b2b3281f5d (diff)
Add support for bibtex-mode (#294)
Add support for `bibtex-mode` using emacs native function `bibtex-reformat`.
-rw-r--r--CHANGELOG.md1
-rw-r--r--apheleia-formatters.el16
-rw-r--r--test/formatters/installers/bibtex.bash1
-rw-r--r--test/formatters/samplecode/bibtex/in.bib5
-rw-r--r--test/formatters/samplecode/bibtex/out.bib5
5 files changed, 28 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2df4c32..1d0c41f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog].
## Unreleased
### Formatters
* Use clang-format for formatting Objective-C/C++ files ([#378]).
+* `bibtex-reformat` for BibTeX files.
## 4.4.2 (released 2025-11-21)
### Bugs fixed
diff --git a/apheleia-formatters.el b/apheleia-formatters.el
index 65c0b15..928dcbb 100644
--- a/apheleia-formatters.el
+++ b/apheleia-formatters.el
@@ -29,6 +29,7 @@
(apheleia-formatters-indent
"--tab" "--indent-size" 'sh-basic-offset)
"-"))
+ (bibtex . apheleia-reformat-bibtex-buffer)
(black . ("black"
(when (apheleia-formatters-extension-p "pyi") "--pyi")
(apheleia-formatters-fill-column "--line-length")
@@ -318,6 +319,7 @@ rather than using this system."
(bash-ts-mode . shfmt)
(bazel-mode . buildifier)
(beancount-mode . bean-format)
+ (bibtex-mode . bibtex)
(c++-ts-mode . clang-format)
(caddyfile-mode . caddyfmt)
(cc-mode . clang-format)
@@ -1223,6 +1225,20 @@ 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))
+ (when (fboundp 'bibtex-reformat)
+ (bibtex-reformat))
+ (funcall callback)))
+
(cl-defun apheleia--run-formatters
(formatters buffer remote callback &optional stdin)
"Run one or more code formatters on the current buffer.
diff --git a/test/formatters/installers/bibtex.bash b/test/formatters/installers/bibtex.bash
new file mode 100644
index 0000000..97dbfb0
--- /dev/null
+++ b/test/formatters/installers/bibtex.bash
@@ -0,0 +1 @@
+# Nothing to do here, this formatter is pure Emacs!
diff --git a/test/formatters/samplecode/bibtex/in.bib b/test/formatters/samplecode/bibtex/in.bib
new file mode 100644
index 0000000..fcfbd6f
--- /dev/null
+++ b/test/formatters/samplecode/bibtex/in.bib
@@ -0,0 +1,5 @@
+@article{key,
+ title={An Article},
+ author = {John Doe},
+year=2020
+}
diff --git a/test/formatters/samplecode/bibtex/out.bib b/test/formatters/samplecode/bibtex/out.bib
new file mode 100644
index 0000000..36da836
--- /dev/null
+++ b/test/formatters/samplecode/bibtex/out.bib
@@ -0,0 +1,5 @@
+@article{key,
+ title = {An Article},
+ author = {John Doe},
+ year = 2020
+}