X-Git-Url: https://git.donarmstrong.com/?p=org-ref.git;a=blobdiff_plain;f=org-ref.org;h=c0529c1c5ae00f6c74131ad4623add2a718c8565;hp=3a908cad1d4b9dbd12711b2a2fa3366cc32bedc5;hb=83d8c28832965e96b26aa49f0b71fb33fa0efa88;hpb=cefe92516dfde2297eb0a7b0c65f3c68e63f052d diff --git a/org-ref.org b/org-ref.org index 3a908ca..c0529c1 100644 --- a/org-ref.org +++ b/org-ref.org @@ -123,14 +123,14 @@ There are some variables needed later to tell this library where you store your (defcustom org-ref-insert-cite-function - 'org-ref-insert-cite-link - "Function to call to insert citation links." + 'helm-bibtex + "Function to call to insert citation links. The default is `helm-bibtex'. org-ref modifies helm-bibtex a little bit to give org-mode citations, and to reorder default actions. You may use `org-ref-insert-cite-link' if you like the reftex interface." :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" + 'org-ref-cite-click-helm + "Function that runs when you click on a cite link. The function must take no arguments. You may also use `org-ref-cite-onclick-minibuffer-menu' if you do not like helm." :type 'function) #+END_SRC @@ -1477,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))))) @@ -2124,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)) @@ -2788,7 +2790,6 @@ I like convenience. Here are some aliases for faster typing. Now, let us define a function that inserts the cite links: #+BEGIN_SRC emacs-lisp :tangle org-ref.el - (defun helm-bibtex-format-org-ref (keys) "insert selected KEYS as cite link. Append KEYS if you are on a link." (let* ((object (org-element-context))) @@ -2820,30 +2821,144 @@ Now, let us define a function that inserts the cite links: (setq helm-bibtex-format-citation-functions '((org-mode . helm-bibtex-format-org-ref))) -(setq org-ref-insert-cite-function 'helm-bibtex) - (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 + ("Quit" . org-ref-citation-at-point) + ("Open bibtex entry" . org-ref-open-citation-at-point)))) -(setq org-ref-helm-cite-click-source - '((name . "org-ref actions") - (candidates . (("open" . org-ref-open-citation-at-point) - ("pdf" . org-ref-open-pdf-at-point) - ("notes" . org-ref-open-notes-at-point))) - (action . (lambda (f) (funcall f))))) -(defun org-ref-cite-click-helm () - (interactive) - (helm :sources '(org-ref-helm-cite-click-source))) + (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) -(setq org-ref-cite-onclick-function 'org-ref-cite-click-helm) + (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 bibtex entry and pdf" . (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))))) + + +(defvar org-ref-helm-user-candidates '() + "List of user-defined candidates to act when clicking on a cite link. +This is a list of cons cells '((\"description\" . action)). The action function should not take an argument, and should assume point is on the cite key of interest. +") + +;; example of adding your own function +(add-to-list + 'org-ref-helm-user-candidates + '("Example" . (lambda () (message-box "You did it!"))) + t) + +(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)))) + ((name . "User functions") + (candidates . ,org-ref-helm-user-candidates) + (action . (lambda (f) + (switch-to-buffer cb) + (funcall f)))) + )))) #+END_SRC +#+RESULTS: +: org-ref-cite-click-helm + * End of code #+BEGIN_SRC emacs-lisp :tangle org-ref.el (provide 'org-ref)