]> git.eshelyaron.com Git - emacs.git/commitdiff
Recognize multicite macros from biblatex
authorArash Esbati <arash@gnu.org>
Sat, 13 Apr 2024 20:31:25 +0000 (22:31 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sun, 14 Apr 2024 17:11:32 +0000 (19:11 +0200)
* 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.

(cherry picked from commit 845246093f8ae88db1061a9beaff04184685f8f4)

lisp/textmodes/reftex-cite.el
test/lisp/textmodes/reftex-tests.el

index f7b155874de1281cce052867b466545284cf84ab..34f40ba689ffe250b0eb308bdc51ed5a8e57dbe5 100644 (file)
@@ -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))
 
index 7f7c99a40a46ed5106036a24233a40541053fa32..456ee45886572243cc416f16579c04bc803157b9 100644 (file)
@@ -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)))))