|
@@ -325,15 +325,19 @@ This is used for disambiguation."
|
|
((= n 27) (throw :complete (cons 0 (cons 0 result))))
|
|
((= n 27) (throw :complete (cons 0 (cons 0 result))))
|
|
(t nil))))))))
|
|
(t nil))))))))
|
|
|
|
|
|
-(defun org-cite-basic--get-year (entry-or-key info)
|
|
|
|
|
|
+(defun org-cite-basic--get-year (entry-or-key info &optional no-suffix)
|
|
"Return year associated to ENTRY-OR-KEY.
|
|
"Return year associated to ENTRY-OR-KEY.
|
|
|
|
|
|
ENTRY-OR-KEY is either an association list, as returned by
|
|
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.
|
|
|
|
|
|
+`org-cite-basic--get-entry', or a string representing a citation
|
|
|
|
+key. INFO is the export state, as a property list.
|
|
|
|
|
|
-Unlike `org-cite-basic--get-field', this function disambiguates author-year
|
|
|
|
-patterns."
|
|
|
|
|
|
+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:
|
|
;; The cache is an association list with the following structure:
|
|
;;
|
|
;;
|
|
;; (AUTHOR-YEAR . KEY-SUFFIX-ALIST).
|
|
;; (AUTHOR-YEAR . KEY-SUFFIX-ALIST).
|
|
@@ -345,7 +349,16 @@ patterns."
|
|
;; the cite key, as a string, and SUFFIX is the generated suffix
|
|
;; the cite key, as a string, and SUFFIX is the generated suffix
|
|
;; string, or the empty string.
|
|
;; string, or the empty string.
|
|
(let* ((author (org-cite-basic--get-field 'author entry-or-key info 'raw))
|
|
(let* ((author (org-cite-basic--get-field 'author entry-or-key info 'raw))
|
|
- (year (org-cite-basic--get-field 'year 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))
|
|
(cache-key (cons author year))
|
|
(key
|
|
(key
|
|
(pcase entry-or-key
|
|
(pcase entry-or-key
|
|
@@ -359,11 +372,13 @@ patterns."
|
|
(plist-put info :cite-basic/author-date-cache (cons value cache))
|
|
(plist-put info :cite-basic/author-date-cache (cons value cache))
|
|
year))
|
|
year))
|
|
(`(,_ . ,alist)
|
|
(`(,_ . ,alist)
|
|
- (concat year
|
|
|
|
- (or (cdr (assoc key alist))
|
|
|
|
- (let ((new (org-cite-basic--number-to-suffix (1- (length alist)))))
|
|
|
|
- (push (cons key new) alist)
|
|
|
|
- new)))))))
|
|
|
|
|
|
+ (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)))))))
|
|
|
|
|
|
(defun org-cite-basic--print-entry (entry style &optional info)
|
|
(defun org-cite-basic--print-entry (entry style &optional info)
|
|
"Format ENTRY according to STYLE string.
|
|
"Format ENTRY according to STYLE string.
|
|
@@ -371,7 +386,6 @@ ENTRY is an alist, as returned by `org-cite-basic--get-entry'.
|
|
Optional argument INFO is the export state, as a property list."
|
|
Optional argument INFO is the export state, as a property list."
|
|
(let ((author (org-cite-basic--get-field 'author entry info))
|
|
(let ((author (org-cite-basic--get-field 'author entry info))
|
|
(title (org-cite-basic--get-field 'title entry info))
|
|
(title (org-cite-basic--get-field 'title entry info))
|
|
- (year (org-cite-basic--get-field 'year entry info))
|
|
|
|
(from
|
|
(from
|
|
(or (org-cite-basic--get-field 'publisher entry info)
|
|
(or (org-cite-basic--get-field 'publisher entry info)
|
|
(org-cite-basic--get-field 'journal entry info)
|
|
(org-cite-basic--get-field 'journal entry info)
|
|
@@ -379,10 +393,12 @@ Optional argument INFO is the export state, as a property list."
|
|
(org-cite-basic--get-field 'school entry info))))
|
|
(org-cite-basic--get-field 'school entry info))))
|
|
(pcase style
|
|
(pcase style
|
|
("plain"
|
|
("plain"
|
|
- (org-cite-concat
|
|
|
|
- author ". " title (and from (list ", " from)) ", " year "."))
|
|
|
|
|
|
+ (let ((year (org-cite-basic--get-year entry info 'no-suffix)))
|
|
|
|
+ (org-cite-concat
|
|
|
|
+ author ". " title (and from (list ", " from)) ", " year ".")))
|
|
("numeric"
|
|
("numeric"
|
|
- (let ((n (org-cite-basic--key-number (cdr (assq 'id entry)) info)))
|
|
|
|
|
|
+ (let ((n (org-cite-basic--key-number (cdr (assq 'id entry)) info))
|
|
|
|
+ (year (org-cite-basic--get-year entry info 'no-suffix)))
|
|
(org-cite-concat
|
|
(org-cite-concat
|
|
(format "[%d] " n) author ", "
|
|
(format "[%d] " n) author ", "
|
|
(org-cite-emphasize 'italic title)
|
|
(org-cite-emphasize 'italic title)
|
|
@@ -712,7 +728,7 @@ reference. Values are the cite key."
|
|
org-cite-basic-author-column-end nil ?\s)
|
|
org-cite-basic-author-column-end nil ?\s)
|
|
(make-string org-cite-basic-author-column-end ?\s)))
|
|
(make-string org-cite-basic-author-column-end ?\s)))
|
|
org-cite-basic-column-separator
|
|
org-cite-basic-column-separator
|
|
- (let ((date (org-cite-basic--get-field 'year key nil t)))
|
|
|
|
|
|
+ (let ((date (org-cite-basic--get-year key nil 'no-suffix)))
|
|
(format "%4s" (or date "")))
|
|
(format "%4s" (or date "")))
|
|
org-cite-basic-column-separator
|
|
org-cite-basic-column-separator
|
|
(org-cite-basic--get-field 'title key nil t))))
|
|
(org-cite-basic--get-field 'title key nil t))))
|