emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 845246093f8: Recognize multicite macros from biblatex


From: Arash Esbati
Subject: master 845246093f8: Recognize multicite macros from biblatex
Date: Sat, 13 Apr 2024 16:34:30 -0400 (EDT)

branch: master
commit 845246093f8ae88db1061a9beaff04184685f8f4
Author: Arash Esbati <arash@gnu.org>
Commit: Arash Esbati <arash@gnu.org>

    Recognize multicite macros from biblatex
    
    * lisp/textmodes/reftex-cite.el (reftex-all-used-citation-keys):
    Match the citation keys used with multicite macros provided by
    biblatex.  (bug#38249)
    
    * test/lisp/textmodes/reftex-tests.el
    (reftex-all-used-citation-keys): Adjust test accordingly.
---
 lisp/textmodes/reftex-cite.el       | 45 ++++++++++++++++++++++++++++++++++---
 test/lisp/textmodes/reftex-tests.el | 22 ++++++++++++++++++
 2 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/lisp/textmodes/reftex-cite.el b/lisp/textmodes/reftex-cite.el
index f7b155874de..34f40ba689f 100644
--- a/lisp/textmodes/reftex-cite.el
+++ b/lisp/textmodes/reftex-cite.el
@@ -1144,8 +1144,6 @@ recommended for follow mode.  It works OK for individual 
lookups."
 (defun reftex-all-used-citation-keys ()
   "Return a list of all citation keys used in document."
   (reftex-access-scan-info)
-  ;; FIXME: multicites macros provided by biblatex
-  ;; are not covered in this function.
   (let ((files (reftex-all-document-files))
         (re (concat "\\\\"
                     "\\(?:"
@@ -1170,6 +1168,25 @@ recommended for follow mode.  It works OK for individual 
lookups."
                     "\\)"
                     ;; Now match the key:
                     "{\\([^}]+\\)}"))
+        ;; Multicites: Match \MACRONAME(Global Pre)(Global Post)
+        (re2 (concat "\\\\"
+                     (regexp-opt '("cites"       "Cites"
+                                   "parencites"  "Parencites"
+                                   "footcites"   "footcitetexts"
+                                   "smartcites"  "Smartcites"
+                                   "textcites"   "Textcites"
+                                   "supercites"
+                                   "autocites"   "Autocites"
+                                   "volcites"    "Volcites"
+                                   "pvolcites"   "Pvolcites"
+                                   "fvolcites"   "Fvolcites"
+                                   "svolcites"   "Svolcites"
+                                   "tvolcites"   "Tvolcites"
+                                   "avolcites"   "Avolcites"))
+                     "\\(?:([^)]*)\\)\\{0,2\\}"))
+        ;; For each key in list [prenote][postnote]{key}
+        (re3 (concat "\\(?:\\[[^]]*\\]\\)\\{0,2\\}"
+                     "{\\([^}]+\\)}"))
         file keys kk k)
     (save-current-buffer
       (while (setq file (pop files))
@@ -1188,7 +1205,29 @@ recommended for follow mode.  It works OK for individual 
lookups."
                 (setq kk (split-string kk "[, \t\r\n]+"))
                 (while (setq k (pop kk))
                   (or (member k keys)
-                      (setq keys (cons k keys))))))))))
+                      (setq keys (cons k keys))))))
+            ;; And now search for citation lists:
+            (goto-char (point-min))
+            (while (re-search-forward re2 nil t)
+              ;; Make sure we're not inside a comment:
+              (unless (save-match-data
+                        (nth 4 (syntax-ppss)))
+                (while (progn
+                         ;; Ignore the value of
+                         ;; `reftex-allow-detached-macro-args' since we
+                         ;; expect a bigger number of args and detaching
+                         ;; them seems natural for line breaks:
+                         (while (looking-at "[ \t\r\n]+\\|%.*\n")
+                           (goto-char (match-end 0)))
+                         (and (looking-at re3)
+                              (goto-char (match-end 0))))
+                  (setq kk (match-string-no-properties 1))
+                  (while (string-match "%.*\n?" kk)
+                    (setq kk (replace-match "" t t kk)))
+                  (setq kk (split-string kk "[, \t\r\n]+"))
+                  (while (setq k (pop kk))
+                    (or (member k keys)
+                        (setq keys (cons k keys)))))))))))
     (reftex-kill-temporary-buffers)
     keys))
 
diff --git a/test/lisp/textmodes/reftex-tests.el 
b/test/lisp/textmodes/reftex-tests.el
index 7f7c99a40a4..456ee458865 100644
--- a/test/lisp/textmodes/reftex-tests.el
+++ b/test/lisp/textmodes/reftex-tests.el
@@ -285,6 +285,20 @@ Natbib compatibility commands:
 \\Citep[pre][pos]{Citep:2022}
 \\Citep*[pre][pos]{Citep*:2022}
 
+Qualified Citation Lists:
+\\cites(Global Prenote)(Global 
Postnote)[pre][post]{cites:1}[pre][post]{cites:2}
+\\Cites(Global Prenote)(Global 
Postnote)[pre][post]{Cites:1}[pre][post]{Cites:2}
+\\parencites(Global Prenote)(Global Postnote)[pre][post]{parencites:1}
+  [pre][post]{parencites:2}
+\\Parencites(Global Prenote)(Global 
Postnote)[pre][post]{Parencites:1}{Parencites:2}
+\\footcites[pre][post]{footcites:1}[pre][post]{footcites:2}
+\\footcitetexts{footcitetexts:1}{footcitetexts:2}
+\\smartcites{smartcites:1}
+% This is comment about \\smartcites{smartcites:2}
+[pre][post]{smartcites:2}
+% And this should be ignored \\smartcites{smartcites:3}{smartcites:4}
+
+
 Test for bug#56655:
 There was a few \\% of increase in budget \\Citep*{bug:56655}.
 
@@ -331,6 +345,14 @@ And this should be % \\cite{ignored}.
                              "citealp:2022" "citealp*:2022"
                              "Citet:2022"   "Citet*:2022"
                              "Citep:2022"   "Citep*:2022"
+                             ;; Qualified Citation Lists
+                             "cites:1"         "cites:2"
+                             "Cites:1"         "Cites:2"
+                             "parencites:1"    "parencites:2"
+                             "Parencites:1"    "Parencites:2"
+                             "footcites:1"     "footcites:2"
+                             "footcitetexts:1" "footcitetexts:2"
+                             "smartcites:1"    "smartcites:2"
                              "bug:56655")
                            #'string<)))
       (kill-buffer (file-name-nondirectory tex-file)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]