From 37810df232453ada330fb67447208523dd951851 Mon Sep 17 00:00:00 2001 From: Andras Simonyi Date: Fri, 21 Jun 2024 15:36:30 +0200 Subject: [PATCH] Reorganize and add missing requires to fix compilation warnings --- citeproc-biblatex.el | 4 +++- citeproc-bibtex.el | 3 ++- citeproc-context.el | 16 +++++++++++++++- citeproc-date.el | 3 ++- citeproc-formatters.el | 13 ++++++++----- citeproc-generic-elements.el | 2 +- citeproc-lib.el | 14 -------------- citeproc-prange.el | 2 ++ citeproc-proc.el | 8 ++++++++ citeproc-rt.el | 9 ++------- citeproc-s.el | 8 ++------ citeproc-sort.el | 1 + citeproc-style.el | 2 +- citeproc.el | 2 +- 14 files changed, 48 insertions(+), 39 deletions(-) diff --git a/citeproc-biblatex.el b/citeproc-biblatex.el index decb145..0cb218d 100644 --- a/citeproc-biblatex.el +++ b/citeproc-biblatex.el @@ -26,6 +26,8 @@ ;;; Code: (require 'parse-time) +(require 'compat) + (require 'citeproc-bibtex) (defvar citeproc-blt-to-csl-types-alist @@ -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)) diff --git a/citeproc-bibtex.el b/citeproc-bibtex.el index 41092cc..aeb17d9 100644 --- a/citeproc-bibtex.el +++ b/citeproc-bibtex.el @@ -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) @@ -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. diff --git a/citeproc-context.el b/citeproc-context.el index 4a14619..7af136d 100644 --- a/citeproc-context.el +++ b/citeproc-context.el @@ -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. @@ -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 diff --git a/citeproc-date.el b/citeproc-date.el index abf166f..e514909 100644 --- a/citeproc-date.el +++ b/citeproc-date.el @@ -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. @@ -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." diff --git a/citeproc-formatters.el b/citeproc-formatters.el index e2708f9..6168a75 100644 --- a/citeproc-formatters.el +++ b/citeproc-formatters.el @@ -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 @@ -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. diff --git a/citeproc-generic-elements.el b/citeproc-generic-elements.el index 2d1a339..306a367 100644 --- a/citeproc-generic-elements.el +++ b/citeproc-generic-elements.el @@ -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) diff --git a/citeproc-lib.el b/citeproc-lib.el index 1d626c2..2803b2f 100644 --- a/citeproc-lib.el +++ b/citeproc-lib.el @@ -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 diff --git a/citeproc-prange.el b/citeproc-prange.el index 52a5fb3..9db65f0 100644 --- a/citeproc-prange.el +++ b/citeproc-prange.el @@ -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 diff --git a/citeproc-proc.el b/citeproc-proc.el index 9fd635b..001e734 100644 --- a/citeproc-proc.el +++ b/citeproc-proc.el @@ -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 diff --git a/citeproc-rt.el b/citeproc-rt.el index 9e36268..26d0622 100644 --- a/citeproc-rt.el +++ b/citeproc-rt.el @@ -36,6 +36,7 @@ (require 'cl-lib) (require 'let-alist) (require 's) +(require 'compat) (require 'citeproc-s) (require 'citeproc-lib) @@ -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." @@ -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 diff --git a/citeproc-s.el b/citeproc-s.el index b68bd7f..88d5866 100644 --- a/citeproc-s.el +++ b/citeproc-s.el @@ -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." @@ -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) diff --git a/citeproc-sort.el b/citeproc-sort.el index 5c60ee8..4de98d9 100644 --- a/citeproc-sort.el +++ b/citeproc-sort.el @@ -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." diff --git a/citeproc-style.el b/citeproc-style.el index bd51497..32f6c30 100644 --- a/citeproc-style.el +++ b/citeproc-style.el @@ -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." diff --git a/citeproc.el b/citeproc.el index 192b044..44f26f5 100644 --- a/citeproc.el +++ b/citeproc.el @@ -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)))