emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Bruce D'Arcus" <bdarcus@gmail.com>
To: org-mode-email <emacs-orgmode@gnu.org>
Subject: [PATCH] oc-basic: add shorten-name function
Date: Fri, 29 Oct 2021 08:55:23 -0400	[thread overview]
Message-ID: <CAF-FPGN72vSjY6SiXLssVi66oHC429_iT6jsPhN=s3JNVNmqrA@mail.gmail.com> (raw)

[-- 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?


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)
+(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
-        author ". " title (and from (list ", " from)) ", " year "."))
+        (org-cite-basic--shorten-names author)
+        ". " title (and from (list ", " from)) ", " year "."))
        (let ((n (org-cite-basic--key-number (cdr (assq 'id entry)) info)))

             reply	other threads:[~2021-10-29 12:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-29 12:55 Bruce D'Arcus [this message]
2021-11-20 18:41 ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAF-FPGN72vSjY6SiXLssVi66oHC429_iT6jsPhN=s3JNVNmqrA@mail.gmail.com' \
    --to=bdarcus@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: [PATCH] oc-basic: add shorten-name function' \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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


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).