-**** 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
-