Subject: Re: bug#64921: 13.2.1; Infinite loop in LaTeX-arg-biblatex-cites with RefTeX

From: Ikumi Keita <[email-masked]>
Date: Tue, 15 Aug 2023 15:18:22 +0900

Hi Gustavo,

>>>>> Gustavo Barros <[email-masked]> writes:
> Also, I respectfully disagree with the assessment that "it doesn't
> actually harm users". Indeed, `reftex-citation' is very convenient,
> and also my favorite, but it is not a full replacement for
> `TeX-insert-macro' for citation commands. `biblatex' has over 50
> citation commands, and `reftex-citation's dispatcher would become
> impractical if we actually tried to have them all available there. It
> is great for our most used ones, but for those odd birds, we still
> need `TeX-insert-macro'.

Hmm. I know almost nothing about biblatex, so I didn't know that.
Thanks.

> Regarding what to do, I see two ways to handle it. Either make
> "q"/"C-g" not delete the citation when leaving, or simply not loop,
> handling just the first bibkey. Perhaps there's good reason why
> "q"/"C-g" reverts the whole operation. But it cannot be too difficult
> simply not to loop at `LaTeX-arg-biblatex-cites'. And that is actually
> how `reftex-citation' works for citation lists, it only inserts the
> first argument.

Thank you for suggestion. Does the attached patch give you good results?

(By the way, the reason that "q"/"C-g" deletes the trace of the previous
input is that `TeX-insert-macro' introduced `atomic-change-group' a year
ago[1].)

[1] Thread beginning with
https://lists.gnu.org/r/auctex-devel/2022-08/msg00057.html

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine

diff --git a/style/biblatex.el b/style/biblatex.el
index 3254ce85..3160e074 100644
--- a/style/biblatex.el
+++ b/style/biblatex.el
@@ -203,8 +203,8 @@ for citation keys."
          (TeX-argument-insert
           (TeX-read-string (TeX-argument-prompt t nil "Global postnote"))
           (equal prenote ""))))
-  (let ((items t) (noinsert nil))
-    (while items
+  (let ((items t) (noinsert nil) (reftex--done nil))
+    (while (and items (not reftex--done))
       ;; Prompt for prenote and postnote of the current keys.
       (and TeX-arg-cite-note-p (not current-prefix-arg)
            (let ((TeX-arg-opening-brace "[")
@@ -221,7 +221,9 @@ for citation keys."
                            (fboundp 'reftex-plug-flag)
                            (reftex-plug-flag 3))
                       ;; Use RefTeX when enabled.
-                      (reftex-citation t)
+		      (prog1
+			  (reftex-citation t)
+			(setq reftex--done t))
                     ;; Multiple citation keys in each argument are allowed.
                     (TeX-completing-read-multiple
                      (TeX-argument-prompt optional prompt "Key(s)")