@@ -2728,13 +2728,67 @@ Example: ':/path/to/test.pdf:PDF'."
2728
2728
(push escaped filenames))))))
2729
2729
(nreverse filenames)))
2730
2730
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
+
2731
2768
(use-package citar
2732
2769
:custom
2733
2770
(citar-bibliography '("~/Dropbox/bibliography/references.bib"))
2734
2771
(citar-library-paths '("~/Dropbox/bibliography/pdfs/"))
2735
2772
;; FIXME: For some reason this doesn't work; it then complains that
2736
2773
;; it's not actually a list of functions. Instead we have to set it in `custom.el`.
2737
2774
;; (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
+
2738
2792
:bind
2739
2793
("C-c ]" . citar-open)
2740
2794
:hook
0 commit comments