Skip to content

Commit f7b213c

Browse files
committed
feat: add support for full name rendering in completion
Add new display transform function for full names. Generalize existing `citar--shorten-names` to `citar--render-names` to allow code-sharing between completion rendering of family names and full names. Refs: emacs-citar#805
1 parent ac91ec3 commit f7b213c

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

citar.el

+39-13
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ references as a string."
191191
(defcustom citar-display-transform-functions
192192
;; TODO change this name, as it might be confusing?
193193
`((sn . (citar--shorten-names))
194+
(fn . (citar--full-names))
194195
(etal . (citar--shorten-names 3 "&")))
195196
"Configure transformation of field display values from raw values.
196197
@@ -1416,20 +1417,14 @@ See the documentation for `citar-add-file-sources' for more details."
14161417

14171418
;;; Format and display field values
14181419

1419-
(defun citar--shorten-name-position (namelist name)
1420+
(defun citar--render-name-position (namelist name)
14201421
"Return NAME position in a NAMELIST."
14211422
(+ (seq-position namelist name) 1))
14221423

1423-
(defun citar--shorten-name (name)
1424-
"Return family NAME in `family, given' string.
1424+
(defun citar--render-names (namestr name-func &optional truncate andstr)
1425+
"Return a list of names from a list of full NAMESTR.
14251426
1426-
Otherwise, return as is."
1427-
(car (split-string name ", ")))
1428-
1429-
(defun citar--shorten-names (namestr &optional truncate andstr)
1430-
"Return a list of family names from a list of full NAMESTR.
1431-
To better accommodate corporate names, this will only shorten
1432-
personal names of the form \"family, given\".
1427+
Each name will be processed by NAME-FUNC.
14331428
14341429
With an integer TRUNCATE, will shorten the list, and ANDSTR will
14351430
replace last comma."
@@ -1439,8 +1434,8 @@ replace last comma."
14391434
(tnamelength (length tnamelist)))
14401435
(mapconcat
14411436
(lambda (n)
1442-
(let* ((shortname (citar--shorten-name n))
1443-
(pos (citar--shorten-name-position tnamelist n))
1437+
(let* ((name (funcall name-func n))
1438+
(pos (citar--render-name-position tnamelist n))
14441439
(suffix
14451440
(cond
14461441
;; if last name in the list and we're truncating add et al.; otherwise, no suffix
@@ -1451,9 +1446,40 @@ replace last comma."
14511446
(concat " " andstr " "))
14521447
;; otherwise, use a comma
14531448
(t ", "))))
1454-
(concat shortname suffix)))
1449+
(concat name suffix)))
14551450
tnamelist "")))
14561451

1452+
(defun citar--shorten-name (name)
1453+
"Return family NAME in `family, given' string.
1454+
1455+
Otherwise, return as is."
1456+
(car (split-string name ", ")))
1457+
1458+
(defun citar--shorten-names (namestr &optional truncate andstr)
1459+
"Return a list of family names from a list of full NAMESTR.
1460+
To better accommodate corporate names, this will only shorten
1461+
personal names of the form \"family, given\".
1462+
1463+
With an integer TRUNCATE, will shorten the list, and ANDSTR will
1464+
replace last comma."
1465+
(citar--render-names namestr #'citar--shorten-name truncate andstr))
1466+
1467+
(defun citar--full-name (name)
1468+
"Return `given family' in `family, given' string NAME.
1469+
1470+
Otherwise, return as is."
1471+
(let ((split-names (split-string name ", ")))
1472+
(if (> (length split-names) 1)
1473+
(concat (cadr split-names) " " (car split-names))
1474+
name)))
1475+
1476+
(defun citar--full-names (namestr &optional truncate andstr)
1477+
"Return a list of full names from a list of full NAMESTR.
1478+
1479+
With an integer TRUNCATE, will shorten the list, and ANDSTR will
1480+
replace last comma."
1481+
(citar--render-names namestr #'citar--full-name truncate andstr))
1482+
14571483
(defun citar--fields-for-format (template)
14581484
"Return list of fields for TEMPLATE."
14591485
(mapcan (lambda (fieldspec) (when (consp fieldspec) (cdr fieldspec)))

0 commit comments

Comments
 (0)