Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to enable parsebib's replace-tex option #445

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions bibtex-completion.el
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ This should be a single character."
:group 'bibtex-completion
:type 'string)

(defcustom bibtex-completion-replace-tex nil
"Make use of parsebib's ability to parse TeX and replace it by unicode characters."
:group 'bibtex-completion
:type 'boolean)

(defcustom bibtex-completion-fallback-options
'(("CrossRef (biblio.el)"
. (lambda (search-expression) (biblio-lookup #'biblio-crossref-backend search-expression)))
Expand Down Expand Up @@ -676,25 +681,28 @@ Also do some preprocessing of the entries.

If HT-STRINGS is provided it is assumed to be a hash table."
(goto-char (point-min))
(cl-loop
with fields = (append '("title" "crossref")
(-map (lambda (it) (if (symbolp it) (symbol-name it) it))
bibtex-completion-additional-search-fields))
for entry-type = (parsebib-find-next-item)
while entry-type
unless (member-ignore-case entry-type '("preamble" "string" "comment"))
collect (let* ((entry (parsebib-read-entry entry-type (point) ht-strings))
(fields (append
(list (if (assoc-string "author" entry 'case-fold)
"author"
"editor")
(if (assoc-string "date" entry 'case-fold)
"date"
"year"))
fields)))
(-map (lambda (it)
(cons (downcase (car it)) (cdr it)))
(bibtex-completion-prepare-entry entry fields)))))
(cl-letf (((symbol-function 'parsebib--convert-tex-italics) (lambda (str) str))
((symbol-function 'parsebib--convert-tex-bold) (lambda (str) str)))
(cl-loop
with fields = (append '("title" "crossref")
(-map (lambda (it) (if (symbolp it) (symbol-name it) it))
bibtex-completion-additional-search-fields))
for entry-type = (parsebib-find-next-item)
while entry-type
unless (member-ignore-case entry-type '("preamble" "string" "comment"))
collect (let* ((entry (parsebib-read-entry entry-type (point) ht-strings nil
bibtex-completion-replace-tex))
(fields (append
(list (if (assoc-string "author" entry 'case-fold)
"author"
"editor")
(if (assoc-string "date" entry 'case-fold)
"date"
"year"))
fields)))
(-map (lambda (it)
(cons (downcase (car it)) (cdr it)))
(bibtex-completion-prepare-entry entry fields))))))

(defun bibtex-completion-get-entry (entry-key)
"Given a BibTeX key this function scans all bibliographies listed in `bibtex-completion-bibliography' and returns an alist of the record with that key.
Expand Down
6 changes: 6 additions & 0 deletions helm-bibtex.el
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,18 @@ comes out in the right buffer."

;; Helm sources:

(defcustom helm-bibtex-ignore-diacritics nil
"Ignore diacritics when searching."
:group 'bibtex-completion
:type 'boolean)

(defvar helm-source-bibtex
(helm-build-sync-source "BibTeX entries"
:header-name (lambda (name)
(format "%s%s: " name (if helm-bibtex-local-bib " (local)" "")))
:candidates 'helm-bibtex-candidates
:filtered-candidate-transformer 'helm-bibtex-candidates-formatter
:diacritics helm-bibtex-ignore-diacritics
:action (helm-make-actions
"Open PDF, URL or DOI" 'helm-bibtex-open-any
"Open URL or DOI in browser" 'helm-bibtex-open-url-or-doi
Expand Down