[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org 5b45ad083c: oc-basic: Detect malformed bibtex bibli
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org 5b45ad083c: oc-basic: Detect malformed bibtex bibliographies |
Date: |
Sat, 9 Jul 2022 05:57:47 -0400 (EDT) |
branch: externals/org
commit 5b45ad083c92f24f0e8a859f1873edc0c6820d74
Author: Ihor Radchenko <yantar92@gmail.com>
Commit: Ihor Radchenko <yantar92@gmail.com>
oc-basic: Detect malformed bibtex bibliographies
* lisp/oc-basic.el (org-cite-basic--parse-bibtex): Validate the
bibliography before parsing. Display list of issues if any (via
`bibtex-validate`).
(org-cite-basic--parse-bibliography): Set buffer file name needed by
`bibtex-validate`. Empty the cache in case of error.
---
lisp/oc-basic.el | 37 +++++++++++++++++++++++--------------
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/lisp/oc-basic.el b/lisp/oc-basic.el
index f10b95b7f1..95d3832a98 100644
--- a/lisp/oc-basic.el
+++ b/lisp/oc-basic.el
@@ -221,6 +221,10 @@ Return a hash table with citation references as keys and
fields alist as values.
(let ((entries (make-hash-table :test #'equal))
(bibtex-sort-ignore-string-entries t))
(bibtex-set-dialect dialect t)
+ ;; Throw an error if bibliography is malformed.
+ (unless (bibtex-validate)
+ (user-error "Malformed bibliography at %S"
+ (or (buffer-file-name) (current-buffer))))
(bibtex-map-entries
(lambda (key &rest _)
;; Normalize entries: field names are turned into symbols
@@ -265,21 +269,26 @@ Optional argument INFO is the export state, as a property
list."
(when (or (org-file-has-changed-p file)
(not (gethash file org-cite-basic--file-id-cache)))
(insert-file-contents file)
+ (setf (buffer-file-name) file)
(puthash file (org-buffer-hash) org-cite-basic--file-id-cache))
- (let* ((file-id (cons file (gethash file
org-cite-basic--file-id-cache)))
- (entries
- (or (cdr (assoc file-id
org-cite-basic--bibliography-cache))
- (let ((table
- (pcase (file-name-extension file)
- ("json" (org-cite-basic--parse-json))
- ("bib" (org-cite-basic--parse-bibtex
'biblatex))
- ("bibtex" (org-cite-basic--parse-bibtex
'BibTeX))
- (ext
- (user-error "Unknown bibliography extension:
%S"
- ext)))))
- (push (cons file-id table)
org-cite-basic--bibliography-cache)
- table))))
- (push (cons file entries) results)))))
+ (condition-case nil
+ (unwind-protect
+ (let* ((file-id (cons file (gethash file
org-cite-basic--file-id-cache)))
+ (entries
+ (or (cdr (assoc file-id
org-cite-basic--bibliography-cache))
+ (let ((table
+ (pcase (file-name-extension file)
+ ("json" (org-cite-basic--parse-json))
+ ("bib" (org-cite-basic--parse-bibtex
'biblatex))
+ ("bibtex"
(org-cite-basic--parse-bibtex 'BibTeX))
+ (ext
+ (user-error "Unknown bibliography
extension: %S"
+ ext)))))
+ (push (cons file-id table)
org-cite-basic--bibliography-cache)
+ table))))
+ (push (cons file entries) results))
+ (setf (buffer-file-name) nil))
+ (error (setq org-cite-basic--file-id-cache nil))))))
(when info (plist-put info :cite-basic/bibliography results))
results)))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/org 5b45ad083c: oc-basic: Detect malformed bibtex bibliographies,
ELPA Syncer <=