Skip to content

Commit 4d141e4

Browse files
committed
Added functionality for Citar.el so that I can search the full name of
the authors rather than just surnames. Related: emacs-citar/citar#805
1 parent 5ecbec6 commit 4d141e4

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

emacs/config.org

+54
Original file line numberDiff line numberDiff line change
@@ -2728,13 +2728,67 @@ Example: ':/path/to/test.pdf:PDF'."
27282728
(push escaped filenames))))))
27292729
(nreverse filenames)))
27302730

2731+
;; Similar to `citar--shorten-name' and `citar--shorten-names'
2732+
;; but using the full name instead of just the last name.
2733+
(defun citar--full-name (name)
2734+
"Return full NAME in `family, given' string.
2735+
2736+
Otherwise, return as is."
2737+
(let ((split-names (split-string name ", ")))
2738+
(if (> (length split-names) 1)
2739+
(concat (cadr split-names) " " (car split-names))
2740+
name)))
2741+
2742+
(defun citar--full-names (namestr &optional truncate andstr)
2743+
"Return a list of full names from a list of full NAMESTR.
2744+
2745+
With an integer TRUNCATE, will shorten the list, and ANDSTR will
2746+
replace last comma."
2747+
(let* ((namelist (split-string (or namestr "") " and "))
2748+
(namelength (length namelist))
2749+
(tnamelist (seq-take namelist (or truncate namelength)))
2750+
(tnamelength (length tnamelist)))
2751+
(mapconcat
2752+
(lambda (n)
2753+
(let* ((shortname (citar--full-name n))
2754+
(pos (citar--shorten-name-position tnamelist n))
2755+
(suffix
2756+
(cond
2757+
;; if last name in the list and we're truncating add et al.; otherwise, no suffix
2758+
((equal pos tnamelength)
2759+
(if (< tnamelength namelength) " et al." ""))
2760+
;; if second to last in the list, and ANDSTR, use that
2761+
((and andstr (equal pos (- tnamelength 1)))
2762+
(concat " " andstr " "))
2763+
;; otherwise, use a comma
2764+
(t ", "))))
2765+
(concat shortname suffix)))
2766+
tnamelist "")))
2767+
27312768
(use-package citar
27322769
:custom
27332770
(citar-bibliography '("~/Dropbox/bibliography/references.bib"))
27342771
(citar-library-paths '("~/Dropbox/bibliography/pdfs/"))
27352772
;; FIXME: For some reason this doesn't work; it then complains that
27362773
;; it's not actually a list of functions. Instead we have to set it in `custom.el`.
27372774
;; (citar-file-parser-functions (my/citar--file-parser))
2775+
2776+
;; This has two changes vs. default:
2777+
;; 1. Wider author/editor field.
2778+
;; 2. Shows "raw" autor/editor field instead of just last names, thus allowing
2779+
;; us to search also by first names.
2780+
(citar-templates
2781+
'((main . "${author editor:50%fn} ${date year issued:4} ${title:48}")
2782+
(suffix . " ${=key= id:15} ${=type=:12} ${tags keywords:*}")
2783+
(preview . "${author editor:%etal} (${year issued date}) ${title}, ${journal journaltitle publisher container-title collection-title}.\n")
2784+
(note . "Notes on ${author editor:%etal}, ${title}")))
2785+
2786+
;; Add our own display transform function for full names `fn`.
2787+
(citar-display-transform-functions
2788+
`((sn . (citar--shorten-names))
2789+
(etal . (citar--shorten-names 3 "&"))
2790+
(fn . (citar--full-names))))
2791+
27382792
:bind
27392793
("C-c ]" . citar-open)
27402794
:hook

0 commit comments

Comments
 (0)