Open
Description
Is your feature request related to a problem? Please describe.
I often find myself wanting to search through my bibliographies using the first name. This might just be because I remember the first name but not the last name, or there are too many authors with the same last name.
Describe the solution you'd like
I'm thinking something like (basically just a copy-paste of citar--shorten-names
):
;; Similar to `citar--shorten-name' and `citar--shorten-names'
;; but using the full name instead of just the last name.
(defun citar--full-name (name)
"Return full NAME, i.e. `given family`, from `family, given' string.
Otherwise, return as is."
(let (split-names (split-string name ", "))
(if (> (length split-names) 1)
(concat (cadr split-names) " " (car split-names))
name)))
(defun citar--full-names (namestr &optional truncate andstr)
"Return a list of full names from a list of full NAMESTR.
With an integer TRUNCATE, will shorten the list, and ANDSTR will
replace last comma."
(let* ((namelist (split-string (or namestr "") " and "))
(namelength (length namelist))
(tnamelist (seq-take namelist (or truncate namelength)))
(tnamelength (length tnamelist)))
(mapconcat
(lambda (n)
(let* ((shortname (citar--full-name n))
(pos (citar--shorten-name-position tnamelist n))
(suffix
(cond
;; if last name in the list and we're truncating add et al.; otherwise, no suffix
((equal pos tnamelength)
(if (< tnamelength namelength) " et al." ""))
;; if second to last in the list, and ANDSTR, use that
((and andstr (equal pos (- tnamelength 1)))
(concat " " andstr " "))
;; otherwise, use a comma
(t ", "))))
(concat shortname suffix)))
tnamelist "")))
in combination with
(setq citar-display-transform-functions
`((sn . (citar--shorten-names))
(etal . (citar--shorten-names 3 "&"))
(fn . (citar--full-names))))
so I can use this in templates with the transform key fn
.
Describe alternatives you've considered
One alternative is to "maintain" the usage of "and" in the author list, but IMO this becomes quite cluttered when searching, and so I prefer the "given1 family1, given2 family2, ..." instead of `given1 family1 and given2 family2 and ...".