]> git.donarmstrong.com Git - org-ref.git/blobdiff - org-ref.org
added significant new helm integration for cite click.
[org-ref.git] / org-ref.org
index eb165b19900d6830841679f2fc0b555262cbe73b..8f5ff7c2792f634ec0af9f2b8362668399f4f77b 100644 (file)
@@ -127,6 +127,11 @@ There are some variables needed later to tell this library where you store your
   "Function to call to insert citation links."
  :type 'function)
 
+
+(defcustom org-ref-cite-onclick-function
+  'org-ref-cite-onclick-minibuffer-menu
+  "Function that runs when you click on a cite link. The function must take no arguments"
+ :type 'function)
 #+END_SRC
 
 This next variable determines the citation types that are available in org-ref. Links for each one are automatically generated, and completion functions are automatically generated. Users may add to this list in their own init files.
@@ -1472,12 +1477,13 @@ Prompt for NEW-FILE includes bib files in org-ref-default-bibliography, and bib
   (interactive)
   (let* ((results (org-ref-get-bibtex-key-and-file))
         (key (car results))
-        (bibfile (cdr results)))
+        (bibfile (cdr results))
+         doi)
     (save-excursion
       (with-temp-buffer
         (insert-file-contents bibfile)
         (bibtex-search-entry key)
-       (bibtex-autokey-get-field "doi")
+       (setq doi (bibtex-autokey-get-field "doi"))
        ;; in case doi is a url, remove the url part.
        (replace-regexp-in-string "^http://dx.doi.org/" "" doi)))))
 
@@ -1734,7 +1740,7 @@ and the completion function."
   (eval-expression
    `(org-add-link-type
      ,type
-     'org-ref-cite-onclick-minibuffer-menu
+     org-ref-cite-onclick-function
      (quote ,(intern (format "org-ref-format-%s" type)))))
 
   ;; create the completion function
@@ -2119,7 +2125,8 @@ And at the end of the document put \makeglossaries.
 
 #+BEGIN_SRC emacs-lisp :tangle org-ref.el
 (defun org-ref-bib-citation ()
-  "from a bibtex entry, create and return a simple citation string."
+  "From a bibtex entry, create and return a simple citation string.
+This assumes you are in an article."
 
   (bibtex-beginning-of-entry)
   (let* ((cb (current-buffer))
@@ -2820,6 +2827,129 @@ Now, let us define a function that inserts the cite links:
 (require 'helm-bibtex)
 #+END_SRC
 
+** A helm click menu
+
+#+BEGIN_SRC emacs-lisp :tangle org-ref.el
+(defun test ()
+  (interactive)
+  (let* ((results (org-ref-get-bibtex-key-and-file))
+        (key (car results))
+        (bibfile (cdr results)))
+    (save-excursion
+      (with-temp-buffer
+       (insert-file-contents bibfile)
+       (bibtex-search-entry key)
+       (org-ref-bib-citation)))))
+
+(defun org-ref-cite-candidates ()
+  "Generate the list of possible candidates.
+Check for pdf and doi, and add appropriate functions."
+  (interactive)
+  (let* ((results (org-ref-get-bibtex-key-and-file))
+        (key (car results))
+         (pdf-file (format (concat org-ref-pdf-directory "%s.pdf") key))
+         (bibfile (cdr results))
+        (url (save-excursion
+               (with-temp-buffer
+                 (insert-file-contents bibfile)
+                 (bibtex-search-entry key)
+                 (bibtex-autokey-get-field "url"))))
+        (doi (save-excursion
+               (with-temp-buffer
+                 (insert-file-contents bibfile)
+                 (bibtex-search-entry key)
+                 ;; I like this better than bibtex-url which does not always find
+                 ;; the urls
+                 (bibtex-autokey-get-field "doi"))))
+        (candidates `(                 ;;the first candidate is a brief summary
+                      (,(save-excursion
+                          (with-temp-buffer
+                            (insert-file-contents bibfile)
+                            (bibtex-search-entry key))
+                          (org-ref-bib-citation)) . org-ref-citation-at-point)
+                      ("Open bibtex entry" . org-ref-open-citation-at-point))))
+
+    (message-box "doi = \"%s\"" doi)
+    (when (file-exists-p pdf-file)
+      (add-to-list
+       'candidates
+       '("Open pdf" . org-ref-open-pdf-at-point)
+       t
+       ))
+
+    (add-to-list
+     'candidates
+     '("Open notes" . org-ref-open-notes-at-point)
+     t)
+
+    (when (or url doi)
+      (add-to-list
+       'candidates
+       '("Open in browser" . org-ref-open-url-at-point)
+       t))
+
+    (when doi
+      (mapc (lambda (x)
+             (add-to-list 'candidates x t))
+           `(("WOS" . org-ref-wos-at-point)
+             ("Related articles in WOS" . org-ref-wos-related-at-point)
+             ("Citing articles in WOS" . org-ref-wos-citing-at-point)
+             ("Google Scholar" . org-ref-google-scholar-at-point)
+             ("Pubmed" . org-ref-pubmed-at-point)
+             ("Crossref" . org-ref-crossref-at-point)
+             )))
+
+    (add-to-list
+     'candidates
+     '("Copy formatted citation to clipboard" . org-ref-copy-entry-as-summary)
+     t)
+
+    (add-to-list
+     'candidates
+     '("Copy key to clipboard" . (lambda ()
+                                 (kill-new
+                                  (car (org-ref-get-bibtex-key-and-file)))))
+     t)
+
+    (add-to-list
+     'candidates
+     '("Copy bibtex entry to file" . org-ref-copy-entry-at-point-to-file)
+     t)
+
+    (add-to-list
+     'candidates
+     '("Email" . (lambda ()
+                 (save-excursion
+                   (org-ref-open-citation-at-point)
+                   (email-bibtex-entry))))
+     t)
+  ;; finally return a numbered list of the candidates
+  (loop for i from 0
+       for cell in candidates
+       collect (cons (format "%2s. %s" i (car cell))
+                     (cdr cell)))))
+
+(defun org-ref-cite-click-helm (key)
+  "subtle points.
+1. get name and candidates before entering helm because we need the org-buffer.
+2. switch back to the org buffer before evaluating the action. most of them need the point and buffer."
+  (interactive)
+  (let ((name (test))
+       (candidates (org-ref-cite-candidates))
+       (cb (current-buffer)))
+
+    (helm :sources `(((name . ,name)
+                     (candidates . ,candidates)
+                     (action . (lambda (f)
+                                 (switch-to-buffer cb)
+                                 (funcall f))))
+                    ))))
+
+(setq  org-ref-cite-onclick-function 'org-ref-cite-click-helm)
+#+END_SRC
+
+#+RESULTS:
+: org-ref-cite-click-helm
 
 * End of code
 #+BEGIN_SRC emacs-lisp :tangle org-ref.el