forked from andras-simonyi/citeproc-el
-
Notifications
You must be signed in to change notification settings - Fork 0
/
citeproc-itemdata.el
101 lines (81 loc) · 3.75 KB
/
citeproc-itemdata.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
;;; citeproc-itemdata.el --- represent and access bibliography items -*- lexical-binding: t; -*-
;; Copyright (C) 2017 András Simonyi
;; Author: András Simonyi <[email protected]>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;; This file is not part of GNU Emacs.
;;; Commentary:
;; Structure type and functions to handle data about bibliography items.
;;; Code:
(require 'citeproc-rt)
(require 'citeproc-context)
(cl-defstruct (citeproc-itemdata (:constructor citeproc-itemdata-create))
"Struct for storing bibliography item data.
VARVALS is an alist containg variable-name symbols as keys and
their values for the item as values,
RAWCITE is the cached cite of the item in internal rich-text
format,
RC-UPTODATE is t iff the RAWCITE field is up-to-date,
RAWBIBITEM is the cached bibliograhy item in internal rich-text
format.
SORT-KEY is the bibliography sort-key of the item,
OCCURRED-BEFORE is used during bibliography generation to
indicate whether the item was referred to earlier. If the first
occurrence is in a note then the actual value is the
note-number,
DISAMB-POS contains the position on which cite disambiguation is
based. Possible values are 'first, 'ibid and 'subsequent,
SUBBIB-NOS is a list of numeric indexes of sub-bibliographies
in which the item occurs."
varvals rawcite rawbibitem rc-uptodate sort-key occurred-before
disamb-pos subbib-nos)
(defun citeproc-itd-getvar (itd var)
"Return itemdata ITD's value for VAR ."
(alist-get var (citeproc-itemdata-varvals itd)))
(defun citeproc-itd-setvar (itd var val)
"Set itemdata ITD's value for VAR to VAL."
(setf (alist-get var (citeproc-itemdata-varvals itd) nil t) val
(citeproc-itemdata-rc-uptodate itd) nil))
(defun citeproc-itd-rt-cite (itd style)
"Return the rich-text cite of itemdata ITD using STYLE."
(if (citeproc-itemdata-rc-uptodate itd)
(citeproc-itemdata-rawcite itd)
(let ((rc (citeproc-render-varlist-in-rt
(cons (cons 'position (citeproc-itemdata-disamb-pos itd))
(citeproc-itemdata-varvals itd))
style
'cite 'display 'no-links t)))
(setf (citeproc-itemdata-rawcite itd) rc
(citeproc-itemdata-rc-uptodate itd) t)
rc)))
(defun citeproc-itd-plain-cite (itd style)
"Return the plain text cite of itemdata ITD using STYLE."
(citeproc-rt-to-plain (citeproc-itd-rt-cite itd style)))
(defun citeproc-itd-namevars (itd style)
"Rendered namevars in the cite of itemdata ITD using STYLE."
(citeproc-rt-rendered-name-vars (citeproc-itd-rt-cite itd style)))
(defun citeproc-itd-nameids (itd style)
"Rendered name ids in the cite of itemdata ITD using STYLE."
(citeproc-rt-rendered-name-ids (citeproc-itd-rt-cite itd style)))
(defun citeproc-itd-update-disamb-pos (itd pos)
"Update the highest position of ITD with position POS."
(let ((old (citeproc-itemdata-disamb-pos itd)))
(unless (eq old 'subsequent)
(let ((new (pcase pos
('first 'first)
((or 'ibid 'ibid-with-locator) 'ibid)
(_ 'subsequent))))
(setf (citeproc-itemdata-disamb-pos itd)
(cond ((memq old '(nil first)) new)
((eq new 'subsequent) 'subsequent)
(t 'ibid)))))))
(provide 'citeproc-itemdata)
;;; citeproc-itemdata.el ends here