Function: org-cite-basic--get-year
org-cite-basic--get-year is a byte-compiled function defined in
oc-basic.el.gz.
Signature
(org-cite-basic--get-year ENTRY-OR-KEY INFO &optional NO-SUFFIX)
Documentation
Return year associated to ENTRY-OR-KEY.
ENTRY-OR-KEY is either an association list, as returned by
org-cite-basic--get-entry, or a string representing a citation
key. INFO is the export state, as a property list.
Year is obtained from the "year" field, if available, or from the "date" field if it starts with a year pattern.
Unlike org-cite-basic--get-field, this function disambiguates
author-year patterns by adding a letter suffix to the year when
necessary, unless optional argument NO-SUFFIX is non-nil.
Source Code
;; Defined in /usr/src/emacs/lisp/org/oc-basic.el.gz
(defun org-cite-basic--get-year (entry-or-key info &optional no-suffix)
"Return year associated to ENTRY-OR-KEY.
ENTRY-OR-KEY is either an association list, as returned by
`org-cite-basic--get-entry', or a string representing a citation
key. INFO is the export state, as a property list.
Year is obtained from the \"year\" field, if available, or from
the \"date\" field if it starts with a year pattern.
Unlike `org-cite-basic--get-field', this function disambiguates
author-year patterns by adding a letter suffix to the year when
necessary, unless optional argument NO-SUFFIX is non-nil."
;; The cache is an association list with the following structure:
;;
;; (AUTHOR-YEAR . KEY-SUFFIX-ALIST).
;;
;; AUTHOR-YEAR is the author year pair associated to current entry
;; or key.
;;
;; KEY-SUFFIX-ALIST is an association (KEY . SUFFIX), where KEY is
;; the cite key, as a string, and SUFFIX is the generated suffix
;; string, or the empty string.
(let* ((author (org-cite-basic--get-author entry-or-key info 'raw))
(year
(or (org-cite-basic--get-field 'year entry-or-key info 'raw)
(let ((date
(org-cite-basic--get-field 'date entry-or-key info t)))
(and (stringp date)
(string-match (rx string-start
(group (= 4 digit))
(or string-end (not digit)))
date)
(match-string 1 date)))))
(cache-key (cons author year))
(key
(pcase entry-or-key
((pred stringp) entry-or-key)
((pred consp) (cdr (assq 'id entry-or-key)))
(_ (error "Wrong value for ENTRY-OR-KEY: %S" entry-or-key))))
(cache (plist-get info :cite-basic/author-date-cache)))
(pcase (assoc cache-key cache)
('nil
(let ((value (cons cache-key (list (cons key "")))))
(plist-put info :cite-basic/author-date-cache (cons value cache))
year))
(`(,_ . ,alist)
(let ((suffix
(or (cdr (assoc key alist))
(let ((new (org-cite-basic--number-to-suffix
(1- (length alist)))))
(push (cons key new) alist)
new))))
(if no-suffix year (concat year suffix)))))))