[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals-release/org 18d77ac 2/2: oc-basic: Fix completion cache
From: |
ELPA Syncer |
Subject: |
[elpa] externals-release/org 18d77ac 2/2: oc-basic: Fix completion cache |
Date: |
Tue, 7 Dec 2021 16:57:47 -0500 (EST) |
branch: externals-release/org
commit 18d77ac253fec2bf7035275d5177bbfb045931e1
Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Commit: Nicolas Goaziou <mail@nicolasgoaziou.fr>
oc-basic: Fix completion cache
* lisp/oc-basic.el (org-cite-basic--key-completion-table): Cache
completions per document. Return nil when no completion is available
so insertion mechanism can properly report the problem.
---
lisp/oc-basic.el | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/lisp/oc-basic.el b/lisp/oc-basic.el
index 6b07ea1..7c83bdc 100644
--- a/lisp/oc-basic.el
+++ b/lisp/oc-basic.el
@@ -68,6 +68,7 @@
(require 'bibtex)
(require 'json)
+(require 'map)
(require 'oc)
(require 'seq)
@@ -704,11 +705,18 @@ Return chosen style as a string."
(defun org-cite-basic--key-completion-table ()
"Return completion table for cite keys, as a hash table.
-In this hash table, keys are a strings with author, date, and title of the
-reference. Values are the cite key."
- (let ((cache-key (mapcar #'car org-cite-basic--bibliography-cache)))
- (if (gethash cache-key org-cite-basic--completion-cache)
- org-cite-basic--completion-cache
+
+In this hash table, keys are a strings with author, date, and
+title of the reference. Values are the cite keys.
+
+Return nil if there are no bibliography files or no entries."
+ ;; Populate bibliography cache.
+ (let ((entries (org-cite-basic--parse-bibliography)))
+ (cond
+ ((null entries) nil) ;no bibliography files
+ ((gethash entries org-cite-basic--completion-cache)
+ org-cite-basic--completion-cache)
+ (t
(clrhash org-cite-basic--completion-cache)
(dolist (key (org-cite-basic--all-keys))
(let ((completion
@@ -725,8 +733,9 @@ reference. Values are the cite key."
org-cite-basic-column-separator
(org-cite-basic--get-field 'title key nil t))))
(puthash completion key org-cite-basic--completion-cache)))
- (puthash cache-key t org-cite-basic--completion-cache)
- org-cite-basic--completion-cache)))
+ (unless (map-empty-p org-cite-basic--completion-cache) ;no key
+ (puthash entries t org-cite-basic--completion-cache)
+ org-cite-basic--completion-cache)))))
(defun org-cite-basic--complete-key (&optional multiple)
"Prompt for a reference key and return a citation reference string.