While I'm at it, here's a followup to the "date" patch that adds a
little function to shorten author names, and uses it for the "plain"
entry output.

This is a simple function ATM; it only strips given names from
personal names, and is only used on the "plain" entry output.

But it should be easily extended to handle, for example, initializing
given names.

I'm still waiting to hear back from FSF, but I think the LOC should be
small enough?

Bruce

PS - I assume here it's better as a separate thread rather than
replying to the earlier one; is that correct?
From c1b634f5c8a31ad98f7453b77fd45ab9322f9cf2 Mon Sep 17 00:00:00 2001
From: Bruce D'Arcus <bdar...@gmail.com>
Date: Fri, 29 Oct 2021 08:42:27 -0400
Subject: [PATCH] oc-basic: Add function to shorten names

* lisp/oc-basic.el (org-cite-basic--shorten-names): new function to
shorten author names

* lisp/oc-basic.el (org-cite-basic--print-entry): shorten author name
list for the "plain" output style
---
 lisp/oc-basic.el | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/lisp/oc-basic.el b/lisp/oc-basic.el
index 1c5634341..2000dafeb 100644
--- a/lisp/oc-basic.el
+++ b/lisp/oc-basic.el
@@ -309,6 +309,19 @@ non-nil."
         (org-export-raw-string value)
       value)))
 
+(defun org-cite-basic--shorten-names (names)
+  "Return a list of family names from a list of full NAMES.
+
+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 ") ", ")))
+
 (defun org-cite-basic--number-to-suffix (n)
   "Compute suffix associated to number N.
 This is used for disambiguation."
@@ -384,7 +397,8 @@ Optional argument INFO is the export state, as a property list."
     (pcase style
       ("plain"
        (org-cite-concat
-        author ". " title (and from (list ", " from)) ", " year "."))
+        (org-cite-basic--shorten-names author)
+        ". " title (and from (list ", " from)) ", " year "."))
       ("numeric"
        (let ((n (org-cite-basic--key-number (cdr (assq 'id entry)) info)))
          (org-cite-concat
-- 
2.33.1

Reply via email to