]> git.donarmstrong.com Git - org-ref.git/blobdiff - org-ref.org
add function to give message when on a cite link.
[org-ref.git] / org-ref.org
index 8f5ff7c2792f634ec0af9f2b8362668399f4f77b..0908cd4aeed87971cda7770d3a37ca6eafaebbe5 100644 (file)
@@ -38,11 +38,11 @@ This document is an experiment at creating a literate program to provide similar
 
 ;;; Commentary:
 ;;
-;; Lisp code to setup bibliography cite, ref and label org-mode links.
-;; also sets up reftex for org-mode. The links are clickable and do
-;; things that are useful. You should really read org-ref.org for details.
+;; Lisp code to setup bibliography cite, ref and label org-mode links.  also
+;; sets up reftex and helm for org-mode citations. The links are clickable and
+;; do things that are useful. You should really read org-ref.org for details.
 ;;
-;; Package-Requires: ((dash))
+;; Package-Requires: ((dash) (helm) (helm-bibtex))
 #+END_SRC
 
 ** requires
@@ -51,6 +51,8 @@ The only external require is reftex-cite
 #+BEGIN_SRC emacs-lisp  :tangle org-ref.el
 (require 'reftex-cite)
 (require 'dash)
+(require 'helm)
+(require 'helm-bibtex
 #+END_SRC
 
 ** Custom variables
@@ -113,25 +115,36 @@ There are some variables needed later to tell this library where you store your
     ;;(org-tree-to-indirect-buffer)
     (outline-previous-visible-heading 1)
     (recenter-top-bottom 0))
-  "User-defined way to open a notes entry. This is excecuted after the entry is found, with the cursor at the beginning of the headline. The default setting fully expands the notes, and moves the headline to the top of the buffer")
+  "User-defined way to open a notes entry. This is excecuted after the entry is found, with the cursor at the beginning of the headline. The default setting fully expands the notes, and moves the headline to the top of the buffer"
+:type 'function
+:group 'org-ref)
 
 
 (defcustom org-ref-open-pdf-function
    'org-ref-open-pdf-at-point
 "User-defined function to open a pdf from a link. The function must get the key at point, and derive a path to the pdf file, then open it. The default function is `org-ref-open-pdf-at-point'."
-  :type 'function)
+  :type 'function
+  :group 'org-ref)
 
 
 (defcustom org-ref-insert-cite-function
-  'org-ref-insert-cite-link
-  "Function to call to insert citation links."
- :type 'function)
+  '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
+ :group 'org-ref)
 
 
 (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)
+  '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
+ :group 'org-ref)
+
+(defcustom org-ref-show-citation-on-enter t
+  "If non-nil add a hook function to show the citation summary in
+  the minibuffer just by putting the cursor in a link"
+ :group 'org-ref)
+
 #+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.
@@ -2790,7 +2803,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)))
@@ -2822,15 +2834,13 @@ 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 ()
+(defun org-ref-get-citation-string-at-point ()
   (interactive)
   (let* ((results (org-ref-get-bibtex-key-and-file))
         (key (car results))
@@ -2862,14 +2872,10 @@ Check for pdf and doi, and add appropriate functions."
                  ;; 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)
+                      ("Quit" . 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
@@ -2918,7 +2924,7 @@ Check for pdf and doi, and add appropriate functions."
 
     (add-to-list
      'candidates
-     '("Email" . (lambda ()
+     '("Email bibtex entry and pdf" . (lambda ()
                  (save-excursion
                    (org-ref-open-citation-at-point)
                    (email-bibtex-entry))))
@@ -2929,12 +2935,24 @@ Check for pdf and doi, and add appropriate functions."
        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))
+  (let ((name (org-ref-get-citation-string-at-point))
        (candidates (org-ref-cite-candidates))
        (cb (current-buffer)))
 
@@ -2943,14 +2961,31 @@ Check for pdf and doi, and add appropriate functions."
                      (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))))
                     ))))
-
-(setq  org-ref-cite-onclick-function 'org-ref-cite-click-helm)
 #+END_SRC
 
 #+RESULTS:
 : org-ref-cite-click-helm
 
+To get a lighter weight message about the cite link, we define a function that gives us the minibuffer message, without the menu. We add it to a hook that updates after every command, including cursor movements.
+
+#+BEGIN_SRC emacs-lisp :tangle org-ref.el
+(defun org-ref-cite-link-p () (interactive)
+       (let* ((object (org-element-context))
+             (type (org-element-property :type object)))
+        ;;   We only want this to work on citation links
+        (when (-contains? org-ref-cite-types type)
+          (message (org-ref-get-citation-string-at-point)))))
+
+(when org-ref-show-citation-on-enter
+ (add-hook 'post-command-hook 'org-ref-cite-link-p))
+#+END_SRC
+
 * End of code
 #+BEGIN_SRC emacs-lisp :tangle org-ref.el
 (provide 'org-ref)