]> git.donarmstrong.com Git - org-ref.git/commitdiff
modify helm-bibtex to put keywords in the search, and provide a little function to...
authorJohn Kitchin <jkitchin@andrew.cmu.edu>
Tue, 3 Mar 2015 03:07:19 +0000 (22:07 -0500)
committerJohn Kitchin <jkitchin@andrew.cmu.edu>
Tue, 3 Mar 2015 03:07:19 +0000 (22:07 -0500)
org-ref.org

index e0ce7436c73dad8003305084649947cb302bab0a..e59f91df88044c9559454985759c418b2008d90c 100644 (file)
@@ -3393,9 +3393,52 @@ I like convenience. Here are some aliases for faster typing.
 * Helm interface
 [[https://github.com/tmalsburg/helm-bibtex][helm-bibtex]] is a very cool interface to bibtex files. Out of the box though, it is not super convenient for org-ref. Here, we modify it to make it fit our workflow and extend it where needed.
 
 * Helm interface
 [[https://github.com/tmalsburg/helm-bibtex][helm-bibtex]] is a very cool interface to bibtex files. Out of the box though, it is not super convenient for org-ref. Here, we modify it to make it fit our workflow and extend it where needed.
 
+Let us add keywords as a searchable field.
+#+BEGIN_SRC emacs-lisp
+(setq helm-bibtex-additional-search-fields '(keywords))
+#+END_SRC
+
+Next, we are going to add keywords to the helm interface.
+#+BEGIN_SRC emacs-lisp
+(defun helm-bibtex-candidates-formatter (candidates source)
+  "Formats BibTeX entries for display in results list."
+  (cl-loop
+    with width = (with-helm-window (window-width))
+    for entry in candidates
+    for entry = (cdr entry)
+    for entry-key = (helm-bibtex-get-value entry 'entry-key)
+    for fields = (--map (helm-bibtex-clean-string
+                          (helm-bibtex-get-value entry it " "))
+                        '(author title year has-pdf has-note entry-type))
+    for fields = (-update-at 0 'helm-bibtex-shorten-authors fields)
+    for fields = (append fields
+                        (list  (or (helm-bibtex-get-value entry 'keywords)
+                                   "" )))
+    collect
+    (cons (s-format "$0 $1 $2 $3 $4$5 $6" 'elt
+            (-zip-with (lambda (f w) (truncate-string-to-width f w 0 ?\s))
+                       fields (list 36 (- width 85) 4 1 1 7 7)))
+          entry-key)))
+
+#+END_SRC
+
 1. Make the default action to insert selected keys.
 2. Make open entry second action
 #+BEGIN_SRC emacs-lisp :tangle org-ref.el
 1. Make the default action to insert selected keys.
 2. Make open entry second action
 #+BEGIN_SRC emacs-lisp :tangle org-ref.el
+(defun org-ref-tag-entries (candidates)
+  "Set tags on selected entries."
+  (let ((keywords (read-input "Keywords (comma separated): ")))
+    (loop for key in (helm-marked-candidates)
+         do
+         (save-window-excursion
+           (helm-bibtex-show-entry key)
+           (bibtex-set-field
+            "keywords"
+            (concat
+             keywords
+             "," (bibtex-autokey-get-field "keywords")))
+           (save-buffer)))))
+
 (setq helm-source-bibtex
       '((name                                      . "BibTeX entries")
        (init                                      . helm-bibtex-init)
 (setq helm-source-bibtex
       '((name                                      . "BibTeX entries")
        (init                                      . helm-bibtex-init)
@@ -3405,11 +3448,12 @@ I like convenience. Here are some aliases for faster typing.
                   ("Show entry"                   . helm-bibtex-show-entry)
                   ("Open PDF file (if present)"   . helm-bibtex-open-pdf)
                   ("Open URL or DOI in browser"   . helm-bibtex-open-url-or-doi)
                   ("Show entry"                   . helm-bibtex-show-entry)
                   ("Open PDF file (if present)"   . helm-bibtex-open-pdf)
                   ("Open URL or DOI in browser"   . helm-bibtex-open-url-or-doi)
-                  ("Insert reference"             . helm-bibtex-insert-reference)
+                  ("Insert formatted reference"   . helm-bibtex-insert-reference)
                   ("Insert BibTeX key"            . helm-bibtex-insert-key)
                   ("Insert BibTeX entry"          . helm-bibtex-insert-bibtex)
                   ("Attach PDF to email"          . helm-bibtex-add-PDF-attachment)
                   ("Edit notes"                   . helm-bibtex-edit-notes)
                   ("Insert BibTeX key"            . helm-bibtex-insert-key)
                   ("Insert BibTeX entry"          . helm-bibtex-insert-bibtex)
                   ("Attach PDF to email"          . helm-bibtex-add-PDF-attachment)
                   ("Edit notes"                   . helm-bibtex-edit-notes)
+                   ("Tag entries"                  . org-ref-tag-entries)
                   ))))
 #+END_SRC
 
                   ))))
 #+END_SRC