X-Git-Url: https://git.donarmstrong.com/?p=org-ref.git;a=blobdiff_plain;f=org-ref.org;h=fbff15988d49a5c3d1f0898bba2f56bfba24ff0f;hp=c0529c1c5ae00f6c74131ad4623add2a718c8565;hb=0a6ff51e6124ba2546c16c36269db80804b534dc;hpb=83d8c28832965e96b26aa49f0b71fb33fa0efa88 diff --git a/org-ref.org b/org-ref.org index c0529c1..fbff159 100644 --- a/org-ref.org +++ b/org-ref.org @@ -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 '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) + :type 'function + :group 'org-ref) (defcustom org-ref-cite-onclick-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) + :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. @@ -2006,118 +2019,6 @@ And at the end of the document put \makeglossaries. (format "\\Glspl{%s}" path))))) #+END_SRC -#+RESULTS: -| Glspl | nil | (lambda (path desc format) (cond ((eq format (quote latex)) (format \Glspl{%s} path)))) | -| Gls | nil | (lambda (path desc format) (cond ((eq format (quote latex)) (format \Gls{%s} path)))) | -| glspl | nil | (lambda (path desc format) (cond ((eq format (quote latex)) (format \glspl{%s} path)))) | -| gls | nil | (lambda (path desc format) (cond ((eq format (quote latex)) (format \gls{%s} path)))) | -| newglossaryentry | nil | (lambda (path desc format) (cond ((eq format (quote latex)) (format \newglossaryentry{%s}{%s} path desc)))) | -| google | (lambda (link-string) (browse-url (format http://www.google.com/search?q=%s (url-hexify-string link-string)))) | nil | -| ResearcherID | (lambda (link-string) (browse-url (format http://www.researcherid.com/rid/%s link-string))) | nil | -| orcid | (lambda (link-string) (browse-url (format http://orcid.org/%s link-string))) | nil | -| message | org-mac-message-open | nil | -| mac-outlook | org-mac-outlook-message-open | nil | -| skim | org-mac-skim-open | nil | -| addressbook | org-mac-addressbook-item-open | nil | -| x-together-item | org-mac-together-item-open | nil | -| ans | (lambda (path) (let* ((fields (split-string path ::)) (label (nth 0 fields)) (data (nth 1 fields)) (data-file (format %s-%s.dat tq-userid label))) (let ((temp-file data-file) (temp-buffer (get-buffer-create (generate-new-buffer-name *temp file*)))) (unwind-protect (prog1 (save-current-buffer (set-buffer temp-buffer) (insert data)) (save-current-buffer (set-buffer temp-buffer) (write-region nil nil temp-file nil 0))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (mygit (format git add %s data-file)) (mygit (format git commit -m "%s" data-file)) (mygit git push origin master))) | nil | -| mc | (lambda (link) (org-entry-put (point) ANSWER link) (save-restriction (save-excursion (org-narrow-to-subtree) (goto-char (point-max)) (if (bolp) nil (insert \n)) (insert (format # you chose %s link))))) | nil | -| exercise | (lambda (arg) (tq-check-internet) (tq-get-assignment arg)) | nil | -| solution | (lambda (label) (tq-check-internet) (let ((default-directory (file-name-as-directory (expand-file-name tq-root-directory)))) (if (file-exists-p solutions) nil (make-directory solutions)) (let ((default-directory (file-name-as-directory (expand-file-name solutions)))) (if (file-exists-p label) (progn (find-file (concat label / label .org)) (tq-update)) (mygit (format git clone %s@%s:solutions/%s tq-current-course tq-git-server label)) (find-file (concat label / label .org)))))) | nil | -| assignment | (lambda (arg) (tq-check-internet) (tq-get-assignment arg)) | nil | -| doi | doi-link-menu | nil | -| bibentry | org-ref-cite-onclick-minibuffer-menu | org-ref-format-bibentry | -| Autocites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Autocites | -| autocites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-autocites | -| supercites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-supercites | -| Textcites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Textcites | -| textcites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-textcites | -| Smartcites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Smartcites | -| smartcites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-smartcites | -| footcitetexts | org-ref-cite-onclick-minibuffer-menu | org-ref-format-footcitetexts | -| footcites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-footcites | -| Parencites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Parencites | -| parencites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-parencites | -| Cites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Cites | -| cites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-cites | -| fnotecite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-fnotecite | -| Pnotecite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Pnotecite | -| pnotecite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-pnotecite | -| Notecite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Notecite | -| notecite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-notecite | -| footfullcite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-footfullcite | -| fullcite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-fullcite | -| citeurl | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citeurl | -| citedate* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citedate* | -| citedate | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citedate | -| citetitle* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citetitle* | -| citetitle | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citetitle | -| Citeauthor* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Citeauthor* | -| Autocite* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Autocite* | -| autocite* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-autocite* | -| Autocite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Autocite | -| autocite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-autocite | -| supercite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-supercite | -| parencite* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-parencite* | -| cite* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-cite* | -| Smartcite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Smartcite | -| smartcite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-smartcite | -| Textcite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Textcite | -| textcite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-textcite | -| footcitetext | org-ref-cite-onclick-minibuffer-menu | org-ref-format-footcitetext | -| footcite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-footcite | -| Parencite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Parencite | -| parencite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-parencite | -| Cite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Cite | -| Citeauthor | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Citeauthor | -| Citealp | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Citealp | -| Citealt | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Citealt | -| Citep | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Citep | -| Citet | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Citet | -| citeyear* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citeyear* | -| citeyear | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citeyear | -| citeauthor* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citeauthor* | -| citeauthor | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citeauthor | -| citetext | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citetext | -| citenum | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citenum | -| citealp* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citealp* | -| citealp | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citealp | -| citealt* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citealt* | -| citealt | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citealt | -| citep* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citep* | -| citep | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citep | -| citet* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citet* | -| citet | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citet | -| nocite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-nocite | -| cite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-cite | -| eqref | (lambda (label) on clicking goto the label. Navigate back with C-c & (org-mark-ring-push) (widen) (goto-char (point-min)) (if (or (re-search-forward (format label:%s label) nil t) (re-search-forward (format \label{%s} label) nil t) (re-search-forward (format ^#\+label:\s-*\(%s\)\b label) nil t)) nil (org-mark-ring-goto) (error %s not found label)) (message go back with (org-mark-ring-goto) `C-c &`)) | (lambda (keyword desc format) (cond ((eq format (quote html)) (format (%s) path)) ((eq format (quote latex)) (format \eqref{%s} keyword)))) | -| nameref | (lambda (label) on clicking goto the label. Navigate back with C-c & (org-mark-ring-push) (widen) (if (or (progn (goto-char (point-min)) (re-search-forward (format \label{%s} label) nil t))) nil (org-mark-ring-goto) (error %s not found label)) (message go back with (org-mark-ring-goto) `C-c &`)) | (lambda (keyword desc format) (cond ((eq format (quote html)) (format (%s) path)) ((eq format (quote latex)) (format \nameref{%s} keyword)))) | -| pageref | (lambda (label) on clicking goto the label. Navigate back with C-c & (org-mark-ring-push) (widen) (if (or (progn (goto-char (point-min)) (re-search-forward (format label:%s\b label) nil t)) (progn (goto-char (point-min)) (re-search-forward (format \label{%s} label) nil t)) (progn (goto-char (point-min)) (re-search-forward (format ^#\+label:\s-*\(%s\)\b label) nil t)) (progn (goto-char (point-min)) (re-search-forward (format ^#\+tblname:\s-*\(%s\)\b label) nil t))) nil (org-mark-ring-goto) (error %s not found label)) (message go back with (org-mark-ring-goto) `C-c &`)) | (lambda (keyword desc format) (cond ((eq format (quote html)) (format (%s) path)) ((eq format (quote latex)) (format \pageref{%s} keyword)))) | -| ref | (lambda (label) on clicking goto the label. Navigate back with C-c & (org-mark-ring-push) (widen) (if (or (progn (goto-char (point-min)) (re-search-forward (format label:%s\b label) nil t)) (progn (goto-char (point-min)) (re-search-forward (format \label{%s} label) nil t)) (progn (goto-char (point-min)) (re-search-forward (format ^#\+label:\s-*\(%s\)\b label) nil t)) (progn (goto-char (point-min)) (re-search-forward (format ^#\+tblname:\s-*\(%s\)\b label) nil t))) nil (org-mark-ring-goto) (error %s not found label)) (org-show-entry) (message go back with (org-mark-ring-goto) `C-c &`)) | (lambda (keyword desc format) (cond ((eq format (quote html)) (format (%s) path)) ((eq format (quote latex)) (format \ref{%s} keyword)))) | -| label | (lambda (label) on clicking count the number of label tags used in the buffer. A number greater than one means multiple labels! (message (format %s occurences (+ (count-matches (format label:%s\b[^-:] label) (point-min) (point-max) t) (count-matches (format ^#\+tblname:\s-*%s\b[^-:] label) (point-min) (point-max) t) (count-matches (format \label{%s}\b label) (point-min) (point-max) t) (count-matches (format ^#\+label:\s-*%s\b[^-:] label) (point-min) (point-max) t))))) | (lambda (keyword desc format) (cond ((eq format (quote html)) (format () path)) ((eq format (quote latex)) (format \label{%s} keyword)))) | -| list-of-tables | org-ref-list-of-tables | (lambda (keyword desc format) (cond ((eq format (quote latex)) (format \listoftables)))) | -| list-of-figures | org-ref-list-of-figures | (lambda (keyword desc format) (cond ((eq format (quote latex)) (format \listoffigures)))) | -| addbibresource | (lambda (link-string) (let* ((bibfile) (object (org-element-context)) (link-string-beginning) (link-string-end)) (save-excursion (goto-char (org-element-property :begin object)) (search-forward link-string nil nil 1) (setq link-string-beginning (match-beginning 0)) (setq link-string-end (match-end 0))) (set (make-local-variable (quote reftex-default-addbibresource)) (split-string (org-element-property :path object) ,)) (save-excursion (if (search-forward , link-string-end 1 1) (setq key-end (- (match-end 0) 1)) (setq key-end (point)))) (save-excursion (if (search-backward , link-string-beginning 1 1) (setq key-beginning (+ (match-beginning 0) 1)) (setq key-beginning (point)))) (setq bibfile (org-ref-strip-string (buffer-substring key-beginning key-end))) (find-file bibfile))) | (lambda (keyword desc format) (cond ((eq format (quote html)) (format )) ((eq format (quote latex)) (format \addbibresource{%s} keyword)))) | -| bibliographystyle | (lambda (arg) (message Nothing implemented for clicking here.)) | (lambda (keyword desc format) (cond ((eq format (quote latex)) (format \bibliographystyle{%s} keyword)))) | -| printbibliography | (lambda (arg) (message Nothing implemented for clicking here.)) | (lambda (keyword desc format) (cond ((eq format (quote org)) (org-ref-get-org-bibliography)) ((eq format (quote html)) (org-ref-get-html-bibliography)) ((eq format (quote latex)) \printbibliography))) | -| nobibliography | (lambda (link-string) (let* ((bibfile) (object (org-element-context)) (link-string-beginning) (link-string-end)) (save-excursion (goto-char (org-element-property :begin object)) (search-forward link-string nil nil 1) (setq link-string-beginning (match-beginning 0)) (setq link-string-end (match-end 0))) (set (make-local-variable (quote reftex-default-bibliography)) (split-string (org-element-property :path object) ,)) (save-excursion (if (search-forward , link-string-end 1 1) (setq key-end (- (match-end 0) 1)) (setq key-end (point)))) (save-excursion (if (search-backward , link-string-beginning 1 1) (setq key-beginning (+ (match-beginning 0) 1)) (setq key-beginning (point)))) (setq bibfile (org-ref-strip-string (buffer-substring key-beginning key-end))) (find-file bibfile))) | (lambda (keyword desc format) (cond ((eq format (quote org)) (org-ref-get-org-bibliography)) ((eq format (quote ascii)) (org-ref-get-ascii-bibliography)) ((eq format (quote html)) (org-ref-get-html-bibliography)) ((eq format (quote latex)) (format \nobibliography{%s} (replace-regexp-in-string \.bib (mapconcat (quote identity) (mapcar (quote expand-file-name) (split-string keyword ,)) ,)))))) | -| bibliography | (lambda (link-string) (let* ((bibfile) (object (org-element-context)) (link-string-beginning) (link-string-end)) (save-excursion (goto-char (org-element-property :begin object)) (search-forward link-string nil nil 1) (setq link-string-beginning (match-beginning 0)) (setq link-string-end (match-end 0))) (set (make-local-variable (quote reftex-default-bibliography)) (split-string (org-element-property :path object) ,)) (save-excursion (if (search-forward , link-string-end 1 1) (setq key-end (- (match-end 0) 1)) (setq key-end (point)))) (save-excursion (if (search-backward , link-string-beginning 1 1) (setq key-beginning (+ (match-beginning 0) 1)) (setq key-beginning (point)))) (setq bibfile (org-ref-strip-string (buffer-substring key-beginning key-end))) (find-file bibfile))) | (lambda (keyword desc format) (cond ((eq format (quote org)) (org-ref-get-org-bibliography)) ((eq format (quote ascii)) (org-ref-get-ascii-bibliography)) ((eq format (quote html)) (org-ref-get-html-bibliography)) ((eq format (quote latex)) (format \bibliography{%s} (replace-regexp-in-string \.bib (mapconcat (quote identity) (mapcar (quote expand-file-name) (split-string keyword ,)) ,)))))) | -| rmail | org-rmail-open | nil | -| mhe | org-mhe-open | nil | -| irc | org-irc-visit | nil | -| info | org-info-open | nil | -| gnus | org-gnus-open | nil | -| docview | org-docview-open | org-docview-export | -| bibtex | org-bibtex-open | nil | -| bbdb | org-bbdb-open | org-bbdb-export | -| pydoc | (lambda (link-string) (shell-command (format python -m pydoc %s link-string))) | nil | -| index | (lambda (path) (tq-index) (occur path)) | nil | -| attachfile | (lambda (link-string) (org-open-file link-string)) | (lambda (keyword desc format) (cond ((eq format (quote html)) (format )) ((eq format (quote latex)) (format \attachfile{%s} keyword)))) | -| msx | org-msx-open | nil | -| id | org-id-open | nil | -| file+emacs | org-open-file-with-emacs | nil | -| file+sys | org-open-file-with-system | nil | - * Utilities @@ -2827,7 +2728,7 @@ Now, let us define a function that inserts the cite links: ** 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)) @@ -2939,7 +2840,7 @@ This is a list of cons cells '((\"description\" . action)). The action function 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))) @@ -2959,6 +2860,20 @@ This is a list of cons cells '((\"description\" . action)). The action function #+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)