[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org 23378177c2 2/2: lisp/oc-basic.el: Consider that aut
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org 23378177c2 2/2: lisp/oc-basic.el: Consider that author/title fields may be raw string objects |
Date: |
Tue, 5 Dec 2023 06:58:17 -0500 (EST) |
branch: externals/org
commit 23378177c2ead82f6bc6e05e6b1ad6d4478109e3
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>
lisp/oc-basic.el: Consider that author/title fields may be raw string
objects
* lisp/oc-basic.el (org-cite-basic--get-field): Clarify that raw
string object may be returned.
(org-cite-basic--shorten-names): Clarify NAMES type. Allow NAMES to
be a raw string object.
(org-cite-basic--get-year):
(org-cite-basic--key-completion-table): Use a more clear RAW argument
value in the call to make it explicit that we request raw return value.
(org-cite-basic-export-citation): Allow AUTHOR to be raw string object.
* lisp/oc.el (org-cite-capitalize): New function to capitalize string
or raw string object.
Reported-by: William Denton <wtd@pobox.com>
Link:
https://orgmode.org/list/alpine.DEB.2.22.394.2311230124110.19367@shell3.miskatonic.org
---
lisp/oc-basic.el | 42 ++++++++++++++++++++++++++----------------
lisp/oc.el | 9 +++++++++
2 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/lisp/oc-basic.el b/lisp/oc-basic.el
index 2b78d85d0d..e22bff237a 100644
--- a/lisp/oc-basic.el
+++ b/lisp/oc-basic.el
@@ -334,8 +334,8 @@ FIELD is a symbol. ENTRY-OR-KEY is either an association
list, as returned by
Optional argument INFO is the export state, as a property list.
Return value may be nil or a string. If current export backend is derived
-from `latex', return a raw string instead, unless optional argument RAW is
-non-nil.
+from `latex', return a raw string object instead, unless optional
+argument RAW is non-nil.
Throw an error if the field value is non-string and non-nil."
(let ((value
@@ -358,17 +358,27 @@ Throw an error if the field value is non-string and
non-nil."
(defun org-cite-basic--shorten-names (names)
"Return a list of family names from a list of full NAMES.
+NAMES can be a string or raw string object.
To better accomomodate corporate names, this will only shorten
personal names of the form \"family, given\"."
- (when (stringp names)
- (mapconcat
- (lambda (name)
- (if (eq 1 (length name))
- (cdr (split-string name))
- (car (split-string name ", "))))
- (split-string names " and ")
- ", ")))
+ (let (names-string raw-p)
+ (cond
+ ((stringp names) (setq names-string names))
+ ((org-element-type-p names 'raw)
+ (setq names-string (org-element-contents names)
+ raw-p t)))
+ (when names-string
+ (setq names-string
+ (mapconcat
+ (lambda (name)
+ (if (eq 1 (length name))
+ (cdr (split-string name))
+ (car (split-string name ", "))))
+ (split-string names " and ")
+ ", "))
+ (if raw-p (org-export-raw-string names-string)
+ names-string))))
(defun org-cite-basic--number-to-suffix (n)
"Compute suffix associated to number N.
@@ -424,7 +434,7 @@ necessary, unless optional argument NO-SUFFIX is non-nil."
(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)))
+ (org-cite-basic--get-field 'date entry-or-key info 'raw)))
(and (stringp date)
(string-match (rx string-start
(group (= 4 digit))
@@ -657,11 +667,11 @@ export communication channel, as a property list."
(`(,(or "author" "a") . ,variant)
(let ((caps (member variant '("caps" "c"))))
(org-export-data
- (mapconcat
+ (org-cite-mapconcat
(lambda (key)
(or
(let ((author (org-cite-basic--get-author key info)))
- (if caps (capitalize author) author))
+ (if caps (org-cite-capitalize author) author))
"??"))
(org-cite-get-references citation t)
org-cite-basic-author-year-separator)
@@ -687,7 +697,7 @@ export communication channel, as a property list."
(lambda (p c s) (org-cite-concat p c s))
(lambda (p a y s)
(org-cite-concat p
- (if caps (capitalize a) a)
+ (if caps (org-cite-capitalize a) a)
(if bare " " " (")
y s
(and (not bare) ")")))
@@ -711,7 +721,7 @@ export communication channel, as a property list."
(lambda (p c s)
(org-cite-concat (and (not bare) "(") p c s (and (not bare) ")")))
(lambda (p a y s)
- (org-cite-concat p (if caps (capitalize a) a) ", " y s))
+ (org-cite-concat p (if caps (org-cite-capitalize a) a) ", " y s))
info)))
;; This should not happen.
(_ (error "Invalid style: %S" style)))))
@@ -815,7 +825,7 @@ Return nil if there are no bibliography files or no
entries."
(let ((date (org-cite-basic--get-year entry nil 'no-suffix)))
(format "%4s" (or date "")))
org-cite-basic-column-separator
- (org-cite-basic--get-field 'title entry nil t))))
+ (org-cite-basic--get-field 'title entry nil 'raw))))
(puthash completion key org-cite-basic--completion-cache)))
(unless (map-empty-p org-cite-basic--completion-cache) ;no key
(puthash entries t org-cite-basic--completion-cache)
diff --git a/lisp/oc.el b/lisp/oc.el
index f69e2734e4..72e1779e24 100644
--- a/lisp/oc.el
+++ b/lisp/oc.el
@@ -1235,6 +1235,15 @@ and must return either a string, an object, or a
secondary string."
(org-cite-concat result separator (funcall function datum))))
result)))
+(defun org-cite-capitalize (str)
+ "Capitalize string of raw string object STR."
+ (cond
+ ((stringp str) (capitalize str))
+ ((org-element-type-p str 'raw)
+ (org-export-raw-string
+ (upcase (org-element-contents str))))
+ (t (error "%S must be either a string or raw string object" str))))
+
;;; Internal interface with fontification (activate capability)
(defun org-cite-fontify-default (cite)