emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] oc-basic: add shorten-name function
@ 2021-10-29 12:55 Bruce D'Arcus
  2021-11-20 18:41 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: Bruce D'Arcus @ 2021-10-29 12:55 UTC (permalink / raw)
  To: org-mode-email

[-- Attachment #1: Type: text/plain, Size: 564 bytes --]

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?

[-- Attachment #2: 0001-oc-basic-Add-function-to-shorten-names.patch --]
[-- Type: text/x-patch, Size: 1739 bytes --]

From c1b634f5c8a31ad98f7453b77fd45ab9322f9cf2 Mon Sep 17 00:00:00 2001
From: Bruce D'Arcus <bdarcus@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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] oc-basic: add shorten-name function
  2021-10-29 12:55 [PATCH] oc-basic: add shorten-name function Bruce D'Arcus
@ 2021-11-20 18:41 ` Nicolas Goaziou
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2021-11-20 18:41 UTC (permalink / raw)
  To: Bruce D'Arcus; +Cc: org-mode-email

Hello,

"Bruce D'Arcus" <bdarcus@gmail.com> writes:

> Subject: [PATCH] oc-basic: Add function to shorten names
>
> * lisp/oc-basic.el (org-cite-basic--shorten-names): new function to
> shorten author names

Applied. Thank you.

Regards,
-- 
Nicolas Goaziou


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-20 18:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-29 12:55 [PATCH] oc-basic: add shorten-name function Bruce D'Arcus
2021-11-20 18:41 ` Nicolas Goaziou

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).