Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

168 Reorganize and add missing requires to fix compilation warnings #169

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion citeproc-biblatex.el
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
;;; Code:

(require 'parse-time)
(require 'compat)

(require 'citeproc-bibtex)

(defvar citeproc-blt-to-csl-types-alist
Expand Down Expand Up @@ -473,7 +475,7 @@ biblatex variables in B."
(citeproc-blt--get-standard 'address b)))
(push (cons csl-place-var ~location) result)))
;; url
(-when-let (url (or (let ((u (alist-get 'url b))) (and u (citeproc-s-replace "\\" "" u)))
(-when-let (url (or (let ((u (alist-get 'url b))) (and u (string-replace "\\" "" u)))
(when-let ((~eprinttype (or (alist-get 'eprinttype b)
(alist-get 'archiveprefix b)))
(~eprint (alist-get 'eprint b))
Expand Down
3 changes: 2 additions & 1 deletion citeproc-bibtex.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
(require 's)
(require 'org)
(require 'map)
(require 'compat)
;; Handle the fact that org-bibtex has been renamed to ol-bibtex -- for the time
;; being we support both feature names.
(or (require 'ol-bibtex nil t)
Expand Down Expand Up @@ -262,7 +263,7 @@ replacements."
(let ((wo-quotes (if (and (string= (substring s 0 1) "\"")
(string= (substring s -1) "\""))
(substring s 1 -1) s)))
(citeproc-s-replace "\\&" "&" wo-quotes)))
(string-replace "\\&" "&" wo-quotes)))

(defun citeproc-bt--to-csl (s &optional with-nocase)
"Convert a BibTeX field S to a CSL one.
Expand Down
16 changes: 15 additions & 1 deletion citeproc-context.el
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ no internal links should be produced."
;; Else link each cite to the corresponding bib item.
(if (eq mode 'cite) 'cited-item-no 'bib-item-no)))))

(defun citeproc-context-maybe-stop-rendering
(trigger context result &optional var)
"Stop rendering if a (`stop-rendering-at'. TRIGGER) pair is present in CONTEXT.
In case of stopping return with RESULT. If the optional VAR
symbol is non-nil then rendering is stopped only if VAR is eq to
TRIGGER."
(if (and (eq trigger (alist-get 'stop-rendering-at (citeproc-context-vars context)))
(or (not var) (eq var trigger))
(eq (cdr result) 'present-var))
(let ((rt-result (car result)))
(push '(stopped-rendering . t) (car rt-result))
(throw 'stop-rendering (citeproc-rt-render-affixes rt-result)))
result))

(defun citeproc-render-varlist-in-rt (var-alist style mode render-mode &optional
internal-links no-external-links)
"Render an item described by VAR-ALIST with STYLE in rich-text.
Expand Down Expand Up @@ -257,7 +271,7 @@ external links."
(citeproc-context-int-link-attrval
style internal-links mode (alist-get 'position var-alist)))
(cite-no-attr-val (cons cite-no-attr
(alist-get 'citation-number var-alist))))
(alist-get 'citation-number var-alist))))
(cond ((consp rendered) (setf (car rendered)
(-snoc (car rendered) cite-no-attr-val)))
((stringp rendered) (setq rendered
Expand Down
3 changes: 2 additions & 1 deletion citeproc-date.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
(require 'citeproc-lib)
(require 'citeproc-rt)
(require 'citeproc-context)
(require 'citeproc-number)

(cl-defstruct (citeproc-date (:constructor citeproc-date-create))
"Struct for representing dates.
Expand Down Expand Up @@ -94,7 +95,7 @@ Set the remaining slots to the values SEASON and CIRCA."
(cons nil 'empty-vars)))
(cons nil 'empty-vars))))
;; Handle `year' citation mode by stopping if needed
(citeproc-lib-maybe-stop-rendering 'issued context result var-sym)))
(citeproc-context-maybe-stop-rendering 'issued context result var-sym)))

(defun citeproc--date-part (attrs _context &rest _body)
"Function corresponding to the date-part CSL element."
Expand Down
13 changes: 8 additions & 5 deletions citeproc-formatters.el
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
(require 's)
(require 'cl-lib)

(cl-defstruct (citeproc-formatter (:constructor citeproc-formatter-create))
"Output formatter struct with slots RT, CITE, BIB-ITEM and BIB.
(require 'citeproc-s)
(require 'citeproc-rt)

(cl-defstruct (citeproc-formatter (:constructor citeproc-formatter-create))
"Output formatter struct with slots RT, CITE, BIB-ITEM and BIB.
RT is a one-argument function mapping a rich-text to its
formatted version,
CITE is a one-argument function mapping the output of RT for a
Expand All @@ -48,9 +51,9 @@ BIB is a two-argument function mapping a list of formatted
bibliography,
NO-EXTERNAL-LINKS is non-nil if the formatter doesn't support
external linking."
rt (cite #'identity) (bib-item (lambda (x _) x))
(bib (lambda (x _) (mapconcat #'identity x "\n\n")))
(no-external-links nil))
rt (cite #'identity) (bib-item (lambda (x _) x))
(bib (lambda (x _) (mapconcat #'identity x "\n\n")))
(no-external-links nil))

(defun citeproc-formatter-fun-create (fmt-alist)
"Return a rich-text formatter function based on FMT-ALIST.
Expand Down
2 changes: 1 addition & 1 deletion citeproc-generic-elements.el
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
(setq type (cdr macro-val)))))
;; We stop if only the title had to be rendered.
(let ((result (cons (citeproc-rt-format-single attrs content context) type)))
(citeproc-lib-maybe-stop-rendering
(citeproc-context-maybe-stop-rendering
'title context result (or (and .variable (intern .variable)) t))))))

(provide 'citeproc-generic-elements)
Expand Down
14 changes: 0 additions & 14 deletions citeproc-lib.el
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,6 @@ numeric content."
(s-matches-p "\\`[[:alpha:]]?[[:digit:]]+[[:alpha:]]*\\(\\( *\\([,&-]\\|--\\) *\\)?[[:alpha:]]?[[:digit:]]+[[:alpha:]]*\\)?\\'"
val))))

(defun citeproc-lib-maybe-stop-rendering
(trigger context result &optional var)
"Stop rendering if a (`stop-rendering-at'. TRIGGER) pair is present in CONTEXT.
In case of stopping return with RESULT. If the optional VAR
symbol is non-nil then rendering is stopped only if VAR is eq to
TRIGGER."
(if (and (eq trigger (alist-get 'stop-rendering-at (citeproc-context-vars context)))
(or (not var) (eq var trigger))
(eq (cdr result) 'present-var))
(let ((rt-result (car result)))
(push '(stopped-rendering . t) (car rt-result))
(throw 'stop-rendering (citeproc-rt-render-affixes rt-result)))
result))

(provide 'citeproc-lib)

;;; citeproc-lib.el ends here
2 changes: 2 additions & 0 deletions citeproc-prange.el
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

;;; Code:

(require 'citeproc-s)

(defun citeproc-prange--end-significant (start end len)
"Return the significant digits of the end in page range START END.
START and END are strings of equal length containing integers. If
Expand Down
8 changes: 8 additions & 0 deletions citeproc-proc.el
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ Return the PROC-internal representation of REP."
(let ((filters (citeproc-proc-bib-filters proc)))
(and filters (not (equal filters '(nil))))))

(defun citeproc-proc-max-offset (itds)
"Return the maximal first field width of bibitems in ITDS.
ITDS should be the value of the itemdata field of a citeproc-proc
structure."
(cl-loop for itd being the hash-values of itds
when (listp (citeproc-itemdata-rawbibitem itd)) maximize
(length (citeproc-rt-to-plain (cadr (citeproc-itemdata-rawbibitem itd))))))

(provide 'citeproc-proc)

;;; citeproc-proc.el ends here
9 changes: 2 additions & 7 deletions citeproc-rt.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
(require 'cl-lib)
(require 'let-alist)
(require 's)
(require 'compat)

(require 'citeproc-s)
(require 'citeproc-lib)
Expand Down Expand Up @@ -148,7 +149,7 @@ If optional SKIP-NOCASE is non-nil then skip spans with the

(defun citeproc-rt-strip-periods (rts)
"Remove all periods from rich-texts RTS."
(citeproc-rt-map-strings (lambda (x) (citeproc-s-replace "." "" x)) rts))
(citeproc-rt-map-strings (lambda (x) (string-replace "." "" x)) rts))

(defun citeproc-rt-length (rt)
"Return the length of rich-text RT as a string."
Expand Down Expand Up @@ -532,12 +533,6 @@ The values are ordered depth-first."

;;; Helpers for bibliography rendering

(defun citeproc-rt-max-offset (itemdata)
"Return the maximal first field width in rich-texts RTS."
(cl-loop for itd being the hash-values of itemdata
when (listp (citeproc-itemdata-rawbibitem itd)) maximize
(length (citeproc-rt-to-plain (cadr (citeproc-itemdata-rawbibitem itd))))))

(defun citeproc-rt-subsequent-author-substitute (bib s)
"Substitute S for subsequent author(s) in BIB.
BIB is a list of bib entries in rich-text format. Return the
Expand Down
8 changes: 2 additions & 6 deletions citeproc-s.el
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@

(require 'thingatpt)
(require 's)

;; Handle the unavailability of `string-replace' in early Emacs versions
(if (fboundp 'string-replace)
(defalias 'citeproc-s-replace #'string-replace)
(defalias 'citeproc-s-replace #'s-replace))
(require 'compat)

(defun citeproc-s-camelcase-p (s)
"Return whether string S is in camel case."
Expand Down Expand Up @@ -237,7 +233,7 @@ OQ is the opening quote, CQ is the closing quote to use."
REPLACEMENTS is an alist with (FROM . TO) elements."
(let ((result s))
(pcase-dolist (`(,from . ,to) replacements)
(setq result (citeproc-s-replace from to result)))
(setq result (string-replace from to result)))
result))

(defun citeproc-s-replace-all-sim (s regex replacements)
Expand Down
1 change: 1 addition & 0 deletions citeproc-sort.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
(require 'citeproc-macro)
(require 'citeproc-proc)
(require 'citeproc-name)
(require 'citeproc-number)

(defun citeproc--sort (_attrs _context &rest body)
"Placeholder function corresponding to the cs:sort element of CSL."
Expand Down
2 changes: 1 addition & 1 deletion citeproc-style.el
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ position and before the (possibly empty) body."
(cons str (cdr result)))
result)))
;; Handle `author' citation mode by stopping if needed
(citeproc-lib-maybe-stop-rendering 'names context final)))))
(citeproc-context-maybe-stop-rendering 'names context final)))))

(defun citeproc-style-cite-note (style)
"Return whether csl STYLE is a note style."
Expand Down
2 changes: 1 addition & 1 deletion citeproc.el
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ formatting parameters keyed to the parameter names as symbols:
;; could be handled way more efficiently.
(max-offset (if (and (alist-get 'second-field-align bib-opts)
(not (hash-table-empty-p itemdata)))
(citeproc-rt-max-offset itemdata)
(citeproc-proc-max-offset itemdata)
0))
(format-params (cons (cons 'max-offset max-offset)
(citeproc-style-bib-opts-to-formatting-params bib-opts)))
Expand Down
Loading