]> git.donarmstrong.com Git - org-ref.git/blobdiff - org-ref.org
added docs
[org-ref.git] / org-ref.org
index 098dc5760eae7513282a0206fa34e881127f2857..2047859e6d264b340e32f087f374c5570213d9c9 100644 (file)
@@ -1322,66 +1322,6 @@ Finally, we want to know which file the key is in.
    (cons key file)))
 #+END_SRC
 
-**** Creating the menu for when we click on a key
-     :PROPERTIES:
-     :ID:       d7b7530b-802f-42b1-b61e-1e77da33e278
-     :END:
-When we click on a cite link, we want to get a menu in the minibuffer. We need to create a string for this. We want a citation, and some options that depend on the key. We want to know if the key is found, if there is a pdf, if etc... Here we create that string.
-
-#+BEGIN_SRC emacs-lisp  :tangle org-ref.el
-(defun org-ref-get-menu-options ()
-  "returns a dynamically determined string of options for the citation under point.
-
-we check to see if there is pdf, and if the key actually exists in the bibliography"
-  (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))
-        m1 m2 m3 m4 m5 menu-string)
-    (setq m1 (if bibfile                
-                "(o)pen"
-              "(No key found)"))
-
-    (setq m3 (if (file-exists-p pdf-file)
-                "(p)df"
-                    "(No pdf found)"))
-
-    (setq m4 (if (not
-                  (and bibfile
-                       (string= (catch 'url
-                                  (progn
-
-                                    (with-temp-buffer
-                                      (insert-file-contents bibfile)
-                                      (bibtex-search-entry key)
-                                      (when (not
-                                             (string= (setq url (bibtex-autokey-get-field "url")) ""))
-                                        (throw 'url url))
-
-                                      (when (not
-                                             (string= (setq url (bibtex-autokey-get-field "doi")) ""))
-                                        (throw 'url url))))) "")))
-               "(u)rl" "(no url found)"))
-    (setq m5 "(n)otes")
-    (setq m2 (if bibfile
-                (progn
-                   (setq citation (progn
-                                    (with-temp-buffer
-                                      (insert-file-contents bibfile)
-                                      (bibtex-search-entry key)
-                                      (concat
-                                      (org-ref-bib-citation)
-                                      "\n"
-                                      "in: " bibfile)
-                                     )))
-                   citation)
-              "no key found"))
-
-    (setq menu-string (mapconcat 'identity (list m2 "\n" m1 m3 m4 m5 "(m)enu" "(q)uit") "  "))
-    menu-string))
-#+END_SRC
-
 **** convenience functions to act on citation at point
      :PROPERTIES:
      :ID:       af0b2a82-a7c9-4c08-9dac-09f93abc4a92
@@ -1465,60 +1405,169 @@ We need some convenience functions to open act on the citation at point. These w
 #+END_SRC
 
 **** the actual minibuffer menu
-Now, we create the menu.
+Now, we create the menu. This is a rewrite of the cite action. This makes the function extendable by users.
+#+BEGIN_SRC emacs-lisp  :tangle org-ref.el
+(defvar org-ref-cite-menu-funcs '()
+ "Functions to run on cite click menu. Each entry is a list of (key menu-name function). 
+The function must take no arguments and work on the key at point. Do not modify this variable, it is set to empty in the menu click function, and functions are conditionally added to it.")
+
+
+(defvar org-ref-user-cite-menu-funcs
+  '(("C" "rossref" org-ref-crossref-at-point))
+  "user-defined functions to run on bibtex key at point.")
 
-#+BEGIN_SRC emacs-lisp :tangle org-ref.el
-(defun org-ref-cite-onclick-minibuffer-menu (&optional link-string)
-  "use a minibuffer to select options for the citation under point.
 
-you select your option with a single key press."
+(defun org-ref-get-doi-at-point ()
+  "Get doi for key at point."
   (interactive)
-  (let* ((choice (read-char (org-ref-get-menu-options)))
-        (results (org-ref-get-bibtex-key-and-file))
+  (let* ((results (org-ref-get-bibtex-key-and-file))
         (key (car results))
-        (cb (current-buffer))
-         (pdf-file (format (concat org-ref-pdf-directory "%s.pdf") key))
-         (bibfile (cdr results)))
+        (bibfile (cdr results)))
+    (save-excursion
+      (with-temp-buffer
+        (insert-file-contents bibfile)
+        (bibtex-search-entry key)
+          (bibtex-autokey-get-field "doi")))))
+  
 
-    (cond
-     ;; open
-     ((= choice ?o)
-      (find-file bibfile)
-       (bibtex-search-entry key))
-
-     ;; cite
-     ((= choice ?c)
-      (org-ref-citation-at-point))      
-
-     ;; quit
-     ((or 
-      (= choice ?q) ; q
-      (= choice ?\ )) ; space
-      ;; this clears the minibuffer
-      (message ""))
-
-     ;; pdf
-     ((= choice ?p)
-      (org-ref-open-pdf-at-point))
-
-     ;; notes
-     ((= choice ?n)
-      (org-ref-open-notes-at-point))
-
-     ;; url
-     ((= choice ?u)
-      (org-ref-open-url-at-point))
-
-     ;; jmax-bibtex menu
-     ((= choice ?m)
-      (save-window-excursion
-        (set-buffer (find-file-noselect bibfile))
-       ;; get to bibtex entry and use menu there
-       (bibtex-search-entry key)
-       (jmax-bibtex)))
-
-     ;; anything else we just quit.
-     (t (message "")))))    
+;; functions that operate on key at point for click menu
+(defun org-ref-wos-at-point ()
+  "open the doi in wos for bibtex key under point."
+  (interactive)
+  (doi-utils-wos (org-ref-get-doi-at-point)))
+
+
+(defun org-ref-wos-citing-at-point ()
+  "open the doi in wos citing articles for bibtex key under point."
+  (interactive)
+  (doi-utils-wos-citing (org-ref-get-doi-at-point)))
+
+
+(defun org-ref-wos-related-at-point ()
+  "open the doi in wos related articles for bibtex key under point."
+  (interactive)
+  (doi-utils-wos-related (org-ref-get-doi-at-point)))
+
+
+(defun org-ref-google-scholar-at-point ()
+  "open the doi in google scholar for bibtex key under point."
+  (interactive)
+  (doi-utils-google-scholar (org-ref-get-doi-at-point)))
+
+
+(defun org-ref-pubmed-at-point ()
+  "open the doi in pubmed for bibtex key under point."
+  (interactive)
+  (doi-utils-pubmed (org-ref-get-doi-at-point)))
+
+
+(defun org-ref-crossref-at-point ()
+  "open the doi in crossref for bibtex key under point."
+  (interactive)
+  (doi-utils-crossref (org-ref-get-doi-at-point)))
+
+
+(defun org-ref-cite-onclick-minibuffer-menu (&optional link-string)
+  "action when a cite link is clicked on.
+Provides a menu of context sensitive actions. If the bibtex entry has a pdf, you get an option to open it. If there is a doi, you get a lot of options."
+  (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")))))
+
+    (when (string= "" doi) (setq doi nil))
+    (when (string= "" url) (setq url nil))
+    (setq org-ref-cite-menu-funcs '())
+        
+    ;; open action
+    (when
+       bibfile
+      (add-to-list 
+       'org-ref-cite-menu-funcs
+       '("o" "pen" org-ref-open-citation-at-point)))
+
+    ;; pdf
+    (when (file-exists-p pdf-file)
+      (add-to-list
+       'org-ref-cite-menu-funcs
+       '("p" "df" org-ref-open-pdf-at-point) t))
+
+    ;; notes
+    (add-to-list
+     'org-ref-cite-menu-funcs
+     '("n" "otes" org-ref-open-notes-at-point) t)
+
+    ;; url
+    (when (or url doi)
+      (add-to-list
+       'org-ref-cite-menu-funcs
+       '("u" "rl" org-ref-open-url-at-point) t))
+
+    ;; doi funcs
+    (when doi
+      (add-to-list
+       'org-ref-cite-menu-funcs
+       '("w" "os" org-ref-wos-at-point) t)
+
+      (add-to-list
+       'org-ref-cite-menu-funcs
+       '("c" "iting" org-ref-wos-citing-at-point) t)
+
+      (add-to-list
+       'org-ref-cite-menu-funcs
+       '("r" "elated" org-ref-wos-related-at-point) t)
+      
+      (add-to-list
+       'org-ref-cite-menu-funcs
+       '("g" "oogle scholar" org-ref-google-scholar-at-point) t)
+
+      (add-to-list
+       'org-ref-cite-menu-funcs
+       '("P" "ubmed" org-ref-pubmed-at-point) t))
+
+    (add-to-list
+     'org-ref-cite-menu-funcs
+     '("q" "uit" (lambda ())) t)
+
+    ;; add user functions
+    (dolist (tup org-ref-user-cite-menu-funcs)
+      (add-to-list
+       'org-ref-cite-menu-funcs
+       tup t))
+      
+    ;; now we make a menu
+    ;; construct menu string as a message
+    (message
+     (concat
+      (mapconcat
+       (lambda (tup)
+        (concat "[" (elt tup 0) "]"
+                (elt tup 1) " "))
+       org-ref-cite-menu-funcs "") ": "))
+    ;; get the input
+    (let* ((input (read-char-exclusive))
+          (choice (assoc
+                   (char-to-string input) org-ref-cite-menu-funcs)))
+      ;; now run the function (2nd element in choice)
+      (when choice
+       (funcall
+        (elt 
+         choice
+         2))))))
 #+END_SRC
 
 *** A function to format a cite link