Skip to content

Commit

Permalink
Merge pull request #311 from Zaeph/find-entry-fn
Browse files Browse the repository at this point in the history
Isolate find-note-file lambda in prepare-entry
  • Loading branch information
tmalsburg authored Apr 16, 2020
2 parents b14b628 + 1083278 commit 72c6748
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions bibtex-completion.el
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,24 @@ Returns nil if no PDF is found."
(or (bibtex-completion-find-pdf-in-field key-or-entry)
(bibtex-completion-find-pdf-in-library key-or-entry find-additional)))

(defun bibtex-completion-find-note-file-default (entry-key)
"Find note file associated from BibTeX’s ENTRY-KEY in the default directory.
The default directory is `bibtex-completion-notes-path'. If the
note file doesn’t exist, return nil."
(and bibtex-completion-notes-path
(f-directory? bibtex-completion-notes-path)
(f-file? (f-join bibtex-completion-notes-path
(s-concat entry-key
bibtex-completion-notes-extension)))))

(defcustom bibtex-completion-find-note-file-fns
(list #'bibtex-completion-find-note-file-default)
"List of functions to use to find note files.
The functions should accept one argument: the entry-key of the
BibTeX entry."
:group 'bibtex-completion
:type 'list)

(defun bibtex-completion-prepare-entry (entry &optional fields do-not-find-pdf)
"Prepare ENTRY for display.
ENTRY is an alist representing an entry as returned by
Expand All @@ -781,11 +799,10 @@ find a PDF file."
; Check for notes:
(entry (if (or
;; One note file per entry:
(and bibtex-completion-notes-path
(f-directory? bibtex-completion-notes-path)
(f-file? (f-join bibtex-completion-notes-path
(s-concat entry-key
bibtex-completion-notes-extension))))
(cl-some #'identity
(mapcar (lambda (fn)
(funcall fn entry-key))
bibtex-completion-find-note-file-fns))
;; All notes in one file:
(and bibtex-completion-notes-path
(f-file? bibtex-completion-notes-path)
Expand All @@ -795,7 +812,7 @@ find a PDF file."
; Remove unwanted fields:
(entry (if fields
(--filter (member-ignore-case (car it) fields) entry)
entry)))
entry)))
;; Normalize case of entry type:
(setcdr (assoc "=type=" entry) (downcase (cdr (assoc "=type=" entry))))
;; Remove duplicated fields:
Expand Down

0 comments on commit 72c6748

Please sign in to comment.