aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/org/oc-basic.el
diff options
context:
space:
mode:
authorKyle Meyer2021-11-06 14:10:47 -0400
committerKyle Meyer2021-11-06 14:10:47 -0400
commitf05b8a939b7ad57e9526510d510ff24484dcb520 (patch)
tree1b4498a64600e22ef1e265038d00deb50ce795f4 /lisp/org/oc-basic.el
parent5e9b4e70ab433fe2eb33c20a02b045c83e70d074 (diff)
downloademacs-f05b8a939b7ad57e9526510d510ff24484dcb520.tar.gz
emacs-f05b8a939b7ad57e9526510d510ff24484dcb520.zip
Update to Org 9.5-68-g77e2ec
Diffstat (limited to 'lisp/org/oc-basic.el')
-rw-r--r--lisp/org/oc-basic.el58
1 files changed, 33 insertions, 25 deletions
diff --git a/lisp/org/oc-basic.el b/lisp/org/oc-basic.el
index c51c7d301e4..7b09db5f8b4 100644
--- a/lisp/org/oc-basic.el
+++ b/lisp/org/oc-basic.el
@@ -325,15 +325,19 @@ This is used for disambiguation."
325 ((= n 27) (throw :complete (cons 0 (cons 0 result)))) 325 ((= n 27) (throw :complete (cons 0 (cons 0 result))))
326 (t nil)))))))) 326 (t nil))))))))
327 327
328(defun org-cite-basic--get-year (entry-or-key info) 328(defun org-cite-basic--get-year (entry-or-key info &optional no-suffix)
329 "Return year associated to ENTRY-OR-KEY. 329 "Return year associated to ENTRY-OR-KEY.
330 330
331ENTRY-OR-KEY is either an association list, as returned by 331ENTRY-OR-KEY is either an association list, as returned by
332`org-cite-basic--get-entry', or a string representing a citation key. INFO is 332`org-cite-basic--get-entry', or a string representing a citation
333the export state, as a property list. 333key. INFO is the export state, as a property list.
334 334
335Unlike `org-cite-basic--get-field', this function disambiguates author-year 335Year is obtained from the \"year\" field, if available, or from
336patterns." 336the \"date\" field if it starts with a year pattern.
337
338Unlike `org-cite-basic--get-field', this function disambiguates
339author-year patterns by adding a letter suffix to the year when
340necessary, unless optional argument NO-SUFFIX is non-nil."
337 ;; The cache is an association list with the following structure: 341 ;; The cache is an association list with the following structure:
338 ;; 342 ;;
339 ;; (AUTHOR-YEAR . KEY-SUFFIX-ALIST). 343 ;; (AUTHOR-YEAR . KEY-SUFFIX-ALIST).
@@ -345,7 +349,16 @@ patterns."
345 ;; the cite key, as a string, and SUFFIX is the generated suffix 349 ;; the cite key, as a string, and SUFFIX is the generated suffix
346 ;; string, or the empty string. 350 ;; string, or the empty string.
347 (let* ((author (org-cite-basic--get-field 'author entry-or-key info 'raw)) 351 (let* ((author (org-cite-basic--get-field 'author entry-or-key info 'raw))
348 (year (org-cite-basic--get-field 'year entry-or-key info 'raw)) 352 (year
353 (or (org-cite-basic--get-field 'year entry-or-key info 'raw)
354 (let ((date
355 (org-cite-basic--get-field 'date entry-or-key info t)))
356 (and (stringp date)
357 (string-match (rx string-start
358 (group (= 4 digit))
359 (or string-end (not digit)))
360 date)
361 (match-string 1 date)))))
349 (cache-key (cons author year)) 362 (cache-key (cons author year))
350 (key 363 (key
351 (pcase entry-or-key 364 (pcase entry-or-key
@@ -359,11 +372,13 @@ patterns."
359 (plist-put info :cite-basic/author-date-cache (cons value cache)) 372 (plist-put info :cite-basic/author-date-cache (cons value cache))
360 year)) 373 year))
361 (`(,_ . ,alist) 374 (`(,_ . ,alist)
362 (concat year 375 (let ((suffix
363 (or (cdr (assoc key alist)) 376 (or (cdr (assoc key alist))
364 (let ((new (org-cite-basic--number-to-suffix (1- (length alist))))) 377 (let ((new (org-cite-basic--number-to-suffix
365 (push (cons key new) alist) 378 (1- (length alist)))))
366 new))))))) 379 (push (cons key new) alist)
380 new))))
381 (if no-suffix year (concat year suffix)))))))
367 382
368(defun org-cite-basic--print-entry (entry style &optional info) 383(defun org-cite-basic--print-entry (entry style &optional info)
369 "Format ENTRY according to STYLE string. 384 "Format ENTRY according to STYLE string.
@@ -371,7 +386,6 @@ ENTRY is an alist, as returned by `org-cite-basic--get-entry'.
371Optional argument INFO is the export state, as a property list." 386Optional argument INFO is the export state, as a property list."
372 (let ((author (org-cite-basic--get-field 'author entry info)) 387 (let ((author (org-cite-basic--get-field 'author entry info))
373 (title (org-cite-basic--get-field 'title entry info)) 388 (title (org-cite-basic--get-field 'title entry info))
374 (year (org-cite-basic--get-field 'year entry info))
375 (from 389 (from
376 (or (org-cite-basic--get-field 'publisher entry info) 390 (or (org-cite-basic--get-field 'publisher entry info)
377 (org-cite-basic--get-field 'journal entry info) 391 (org-cite-basic--get-field 'journal entry info)
@@ -379,10 +393,12 @@ Optional argument INFO is the export state, as a property list."
379 (org-cite-basic--get-field 'school entry info)))) 393 (org-cite-basic--get-field 'school entry info))))
380 (pcase style 394 (pcase style
381 ("plain" 395 ("plain"
382 (org-cite-concat 396 (let ((year (org-cite-basic--get-year entry info 'no-suffix)))
383 author ". " title (and from (list ", " from)) ", " year ".")) 397 (org-cite-concat
398 author ". " title (and from (list ", " from)) ", " year ".")))
384 ("numeric" 399 ("numeric"
385 (let ((n (org-cite-basic--key-number (cdr (assq 'id entry)) info))) 400 (let ((n (org-cite-basic--key-number (cdr (assq 'id entry)) info))
401 (year (org-cite-basic--get-year entry info 'no-suffix)))
386 (org-cite-concat 402 (org-cite-concat
387 (format "[%d] " n) author ", " 403 (format "[%d] " n) author ", "
388 (org-cite-emphasize 'italic title) 404 (org-cite-emphasize 'italic title)
@@ -603,15 +619,7 @@ export communication channel, as a property list."
603 ;; When using this style on citations with multiple references, 619 ;; When using this style on citations with multiple references,
604 ;; use global affixes and ignore local ones. 620 ;; use global affixes and ignore local ones.
605 (`(,(or "numeric" "nb") . ,_) 621 (`(,(or "numeric" "nb") . ,_)
606 (let* ((references (org-cite-get-references citation)) 622 (pcase-let ((`(,prefix . ,suffix) (org-cite-main-affixes citation)))
607 (prefix
608 (or (org-element-property :prefix citation)
609 (and (= 1 (length references))
610 (org-element-property :prefix (car references)))))
611 (suffix
612 (or (org-element-property :suffix citation)
613 (and (= 1 (length references))
614 (org-element-property :suffix (car references))))))
615 (org-export-data 623 (org-export-data
616 (org-cite-concat 624 (org-cite-concat
617 "(" prefix (org-cite-basic--citation-numbers citation info) suffix ")") 625 "(" prefix (org-cite-basic--citation-numbers citation info) suffix ")")
@@ -712,7 +720,7 @@ reference. Values are the cite key."
712 org-cite-basic-author-column-end nil ?\s) 720 org-cite-basic-author-column-end nil ?\s)
713 (make-string org-cite-basic-author-column-end ?\s))) 721 (make-string org-cite-basic-author-column-end ?\s)))
714 org-cite-basic-column-separator 722 org-cite-basic-column-separator
715 (let ((date (org-cite-basic--get-field 'year key nil t))) 723 (let ((date (org-cite-basic--get-year key nil 'no-suffix)))
716 (format "%4s" (or date ""))) 724 (format "%4s" (or date "")))
717 org-cite-basic-column-separator 725 org-cite-basic-column-separator
718 (org-cite-basic--get-field 'title key nil t)))) 726 (org-cite-basic--get-field 'title key nil t))))