Update to Org 9.5-68-g77e2ec

This commit is contained in:
Kyle Meyer 2021-11-06 14:10:47 -04:00
parent 5e9b4e70ab
commit f05b8a939b
6 changed files with 68 additions and 40 deletions

View file

@ -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 `org-cite-basic--get-entry', or a string representing a citation
the export state, as a property list. key. INFO is the export state, as a property list.
Unlike `org-cite-basic--get-field', this function disambiguates author-year Year is obtained from the \"year\" field, if available, or from
patterns." 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 (let ((suffix
(or (cdr (assoc key alist)) (or (cdr (assoc key alist))
(let ((new (org-cite-basic--number-to-suffix (1- (length alist))))) (let ((new (org-cite-basic--number-to-suffix
(push (cons key new) alist) (1- (length alist)))))
new))))))) (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 (let ((year (org-cite-basic--get-year entry info 'no-suffix)))
author ". " title (and from (list ", " from)) ", " year ".")) (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)
@ -603,15 +619,7 @@ export communication channel, as a property list."
;; When using this style on citations with multiple references, ;; When using this style on citations with multiple references,
;; use global affixes and ignore local ones. ;; use global affixes and ignore local ones.
(`(,(or "numeric" "nb") . ,_) (`(,(or "numeric" "nb") . ,_)
(let* ((references (org-cite-get-references citation)) (pcase-let ((`(,prefix . ,suffix) (org-cite-main-affixes citation)))
(prefix
(or (org-element-property :prefix citation)
(and (= 1 (length references))
(org-element-property :prefix (car references)))))
(suffix
(or (org-element-property :suffix citation)
(and (= 1 (length references))
(org-element-property :suffix (car references))))))
(org-export-data (org-export-data
(org-cite-concat (org-cite-concat
"(" prefix (org-cite-basic--citation-numbers citation info) suffix ")") "(" prefix (org-cite-basic--citation-numbers citation info) suffix ")")
@ -712,7 +720,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))))

View file

@ -487,21 +487,25 @@ INFO is the export state, as a property list."
(let ((global-prefix (org-element-property :prefix citation))) (let ((global-prefix (org-element-property :prefix citation)))
(when global-prefix (when global-prefix
(let* ((first (car cites)) (let* ((first (car cites))
(prefix (org-element-property :prefix first))) (prefix-item (assq 'prefix first)))
(org-element-put-property (setcdr prefix-item
first :prefix (org-cite-concat global-prefix prefix))))) (concat (org-element-interpret-data global-prefix)
" "
(cdr prefix-item))))))
;; Global suffix is appended to the suffix of the last reference. ;; Global suffix is appended to the suffix of the last reference.
(let ((global-suffix (org-element-property :suffix citation))) (let ((global-suffix (org-element-property :suffix citation)))
(when global-suffix (when global-suffix
(let* ((last (org-last cites)) (let* ((last (org-last cites))
(suffix (org-element-property :suffix last))) (suffix-item (assq 'suffix last)))
(org-element-put-property (setcdr suffix-item
last :suffix (org-cite-concat suffix global-suffix))))) (concat (cdr suffix-item)
" "
(org-element-interpret-data global-suffix))))))
;; Check if CITATION needs wrapping, i.e., it should be wrapped in ;; Check if CITATION needs wrapping, i.e., it should be wrapped in
;; a footnote, but isn't yet. ;; a footnote, but isn't yet.
(when (and (not footnote) (org-cite-csl--note-style-p info)) (when (and (not footnote) (org-cite-csl--note-style-p info))
(org-cite-adjust-note citation info) (org-cite-adjust-note citation info)
(org-cite-wrap-citation citation info)) (setq footnote (org-cite-wrap-citation citation info)))
;; Return structure. ;; Return structure.
(apply #'citeproc-citation-create (apply #'citeproc-citation-create
`(:note-index `(:note-index

View file

@ -119,11 +119,7 @@ If \"natbib\" package is already required in the document, e.g., through
(defun org-cite-natbib--build-optional-arguments (citation info) (defun org-cite-natbib--build-optional-arguments (citation info)
"Build optional arguments for citation command. "Build optional arguments for citation command.
CITATION is the citation object. INFO is the export state, as a property list." CITATION is the citation object. INFO is the export state, as a property list."
(let* ((origin (pcase (org-cite-get-references citation) (pcase-let ((`(,prefix . ,suffix) (org-cite-main-affixes citation)))
(`(,reference) reference)
(_ citation)))
(suffix (org-element-property :suffix origin))
(prefix (org-element-property :prefix origin)))
(concat (and prefix (format "[%s]" (org-trim (org-export-data prefix info)))) (concat (and prefix (format "[%s]" (org-trim (org-export-data prefix info))))
(cond (cond
(suffix (format "[%s]" (org-trim (org-export-data suffix info)))) (suffix (format "[%s]" (org-trim (org-export-data suffix info))))

View file

@ -638,6 +638,24 @@ in the current buffer. Positions include leading \"@\" character."
(re-search-forward org-element-citation-key-re end t) (re-search-forward org-element-citation-key-re end t)
(cons (match-beginning 0) (match-end 0))))) (cons (match-beginning 0) (match-end 0)))))
(defun org-cite-main-affixes (citation)
"Return main affixes for CITATION object.
Some export back-ends only support a single pair of affixes per
citation, even if it contains multiple keys. This function
decides what affixes are the most appropriate.
Return a pair (PREFIX . SUFFIX) where PREFIX and SUFFIX are
parsed data."
(let ((source
;; When there are multiple references, use global affixes.
;; Otherwise, local affixes have priority.
(pcase (org-cite-get-references citation)
(`(,reference) reference)
(_ citation))))
(cons (org-element-property :prefix source)
(org-element-property :suffix source))))
(defun org-cite-supported-styles (&optional processors) (defun org-cite-supported-styles (&optional processors)
"List of supported citation styles and variants. "List of supported citation styles and variants.
@ -872,7 +890,9 @@ When non-nil, the return value if the footnote container."
INFO is the export state, as a property list. INFO is the export state, as a property list.
White space before the citation, if any, are removed. The parse tree is White space before the citation, if any, are removed. The parse tree is
modified by side-effect." modified by side-effect.
Return newly created footnote object."
(let ((footnote (let ((footnote
(list 'footnote-reference (list 'footnote-reference
(list :label nil (list :label nil

View file

@ -173,7 +173,7 @@ a file, \"input-file\" and \"modification-time\"."
modtime)))))))) modtime))))))))
;; Install generic macros. ;; Install generic macros.
'(("keyword" . (lambda (arg1 &rest _) '(("keyword" . (lambda (arg1 &rest _)
(org-macro--find-keyword-value arg1))) (org-macro--find-keyword-value arg1 t)))
("n" . (lambda (&optional arg1 arg2 &rest _) ("n" . (lambda (&optional arg1 arg2 &rest _)
(org-macro--counter-increment arg1 arg2))) (org-macro--counter-increment arg1 arg2)))
("property" . (lambda (arg1 &optional arg2 &rest _) ("property" . (lambda (arg1 &optional arg2 &rest _)

View file

@ -11,7 +11,7 @@ Inserted by installing Org mode or when a release is made."
(defun org-git-version () (defun org-git-version ()
"The Git version of Org mode. "The Git version of Org mode.
Inserted by installing Org or when a release is made." Inserted by installing Org or when a release is made."
(let ((org-git-version "release_9.5-59-g52e6f1")) (let ((org-git-version "release_9.5-68-g77e2ec"))
org-git-version)) org-git-version))
(provide 'org-version) (provide 'org-version)