emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ob-tangle: Tangle BibTeX files with the standard .bib file extension
@ 2025-01-05 10:20 Rudolf Adamkovič
  2025-01-05 13:15 ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Rudolf Adamkovič @ 2025-01-05 10:20 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Rudolf Adamkovič

---
 etc/ORG-NEWS                   |  7 +++++++
 lisp/ob-tangle.el              |  3 ++-
 testing/lisp/test-ob-tangle.el | 24 ++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 8f266c560..097550805 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -484,6 +484,13 @@ ignored by ~org-babel-tangle-collect-blocks~. Now, if it inherits a
 filename), a source block without =language= will get tangled to that
 file.
 
+*** BibTeX is tangled with the standard =.bib= file extension
+
+Previously, =bibtex= source blocks located in a file named =NAME.org=
+were tangled into a file named =NAME.bibtex=.  Now, they are tangled
+into a file named =FILE.bib=, using the standard extension =.bib=,
+matching the rest of the ecosystem, including BibTeX and LaTeX.
+
 * Version 9.7
 
 ** Important announcements and breaking changes
diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index 1f5de9250..38cad78ab 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -58,7 +58,8 @@
 
 (defcustom org-babel-tangle-lang-exts
   '(("emacs-lisp" . "el")
-    ("elisp" . "el"))
+    ("elisp" . "el")
+    ("bibtex" . "bib"))
   "Alist mapping languages to their file extensions.
 The key is the language name, the value is the string that should
 be inserted as the extension commonly used to identify files
diff --git a/testing/lisp/test-ob-tangle.el b/testing/lisp/test-ob-tangle.el
index 6e95c4c91..4a197f76b 100644
--- a/testing/lisp/test-ob-tangle.el
+++ b/testing/lisp/test-ob-tangle.el
@@ -715,6 +715,30 @@ another block
                    (funcall count-blocks-in-target-files
                             (org-babel-tangle-collect-blocks)))))))))
 
+(ert-deftest ob-tangle/bibtex ()
+  "Tangle BibTeX into a `.bib' file."
+  (let ((file (make-temp-file "org-tangle-" nil ".org"))
+        (bib "@Misc{example,
+  author = {Richard Stallman and {contributors}},
+  title = {{GNU} {Emacs}},
+  publisher = {Free Software Foundation},
+  url = {https://www.emacs.org/},
+}"))
+    (unwind-protect
+        (with-current-buffer (find-file-noselect file)
+          (insert (format "#+begin_src bibtex :tangle yes
+%s
+#+end_src"
+                          bib))
+          (org-babel-tangle)
+          (let ((bib-file (file-name-with-extension file "bib")))
+            (should (file-exists-p bib-file))
+            (should (string= (string-trim (org-file-contents bib-file))
+                             bib))))
+      (delete-file file))))
+
+(delete-file file)
+
 (provide 'test-ob-tangle)
 
 ;;; test-ob-tangle.el ends here
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-01-05 16:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-05 10:20 [PATCH] ob-tangle: Tangle BibTeX files with the standard .bib file extension Rudolf Adamkovič
2025-01-05 13:15 ` Ihor Radchenko
2025-01-05 16:32   ` Rudolf Adamkovič
2025-01-05 16:48     ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).