X-Git-Url: https://git.donarmstrong.com/?p=org-ref.git;a=blobdiff_plain;f=org-ref.org;h=c59d8d10b60b79c78f03b16d84479a6a6767af02;hp=ae39ab90db19d312ce8300a99a63dfab005434f9;hb=1640b223fedc30e829bea58d949881d27894b572;hpb=9afe00c1615fd24ee658620990ac03448279f04a diff --git a/org-ref.org b/org-ref.org index ae39ab9..c59d8d1 100644 --- a/org-ref.org +++ b/org-ref.org @@ -218,11 +218,35 @@ We setup reftex here. We use a custom insert cite link function defined here: [[ ;; I do not remember why I put this next line in. It doesn't ;; work for org-files. Nothing very bad happens, but it gives ;; an annoying error. Commenting it out for now. - ;(reftex-parse-all) + ;(reftex-parse-all ) (make-local-variable 'reftex-cite-format) - (setq reftex-cite-format 'org) - (define-key org-mode-map (kbd org-ref-insert-cite-key) org-ref-insert-cite-function)) + (setq reftex-cite-format 'org)) + +;; define key for inserting citations +(define-key org-mode-map + (kbd org-ref-insert-cite-key) + org-ref-insert-cite-function) + +(when org-ref-show-citation-on-enter + (setq org-ref-message-timer + (run-with-idle-timer 0.5 t 'org-ref-link-message))) + +(defun org-ref-show-link-messages () + "Turn on link messages. You will see a message in the +minibuffer when on a cite, ref or label link." + (interactive) + (setq org-ref-message-timer + (run-with-idle-timer 0.5 t 'org-ref-link-message)) + ) +(defun org-ref-cancel-link-messages () + "Stop showing messages in minibuffer when on a link." + (interactive) + (cancel-timer org-ref-message-timer)) + +;; this approach caused the selected region to not be highlighted any more. +; (add-hook 'post-command-hook 'org-ref-link-message)) +; (remove-hook 'post-command-hook 'org-ref-link-message)) (add-hook 'org-mode-hook 'org-mode-reftex-setup) @@ -2023,7 +2047,6 @@ And at the end of the document put \makeglossaries. #+END_SRC - * Utilities ** create simple text citation from bibtex entry @@ -2652,11 +2675,8 @@ Sometimes it may be helpful to manually change the order of citations. These fun (add-hook 'org-shiftleft-hook (lambda () (org-ref-swap-citation-link -1))) #+END_SRC - ** Lightweight messages about links -To get a lighter weight message about the label, ref and cite links, 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. - -ref:test citep:test label:rett +To get a lighter weight message about the label, ref and cite links, we define a function that gives us the minibuffer message, without the menu. We run this in an idle timer. #+BEGIN_SRC emacs-lisp :tangle org-ref.el (defun org-ref-get-label-context (label) @@ -2666,17 +2686,38 @@ ref:test citep:test label:rett (goto-char (point-min)) (when (re-search-forward (format "label:%s\\b" label) nil t) - (throw 'result (thing-at-point 'paragraph))) + (throw 'result (buffer-substring + (progn + (previous-line) + (beginning-of-line) + (point)) + (progn + (forward-line 4) + (point))))) (goto-char (point-min)) (when (re-search-forward (format "\\label{%s}" label) nil t) - (throw 'result (thing-at-point 'paragraph))) + (throw 'result (buffer-substring + (progn + (previous-line) + (beginning-of-line) + (point)) + (progn + (forward-line 4) + (point))))) (goto-char (point-min)) (when (re-search-forward (format "^#\\+label:\\s-*\\(%s\\)\\b" label) nil t) - (throw 'result (thing-at-point 'paragraph))) + (throw 'result (buffer-substring + (progn + (previous-line) + (beginning-of-line) + (point)) + (progn + (forward-line 4) + (point))))) (goto-char (point-min)) (when (re-search-forward @@ -2690,36 +2731,39 @@ ref:test citep:test label:rett (forward-line 4) (point)))))))) + (defun org-ref-link-message () "Print a minibuffer message about the link that point is on." (interactive) - (let* ((object (org-element-context)) - (type (org-element-property :type object))) + (when (eq major-mode 'org-mode) + (let* ((object (org-element-context)) + (type (org-element-property :type object))) + (save-excursion + (cond + ;; cite links + ((-contains? org-ref-cite-types type) + (message (org-ref-get-citation-string-at-point))) - (cond - ;; cite links - ((-contains? org-ref-cite-types type) - (message (org-ref-get-citation-string-at-point))) - - ;; message some context about the label we are referring to - ((string= type "ref") -;; (message-box "%s" (org-element-property :path object)) - (message (org-ref-get-label-context - (org-element-property :path object)))) - - ;; message the count - ((string= type "label") - (let ((count (org-ref-count-labels + ;; message some context about the label we are referring to + ((string= type "ref") + (message (org-ref-get-label-context (org-element-property :path object)))) - (message (concat - (number-to-string count) - " occurence" - (when (or (= count 0) - (> count 1)) - "s")))))))) -(when org-ref-show-citation-on-enter - (add-hook 'post-command-hook 'org-ref-link-message)) + ((string= type "eqref") + (message (org-ref-get-label-context + (org-element-property :path object)))) + + ;; message the count + ((string= type "label") + (let ((count (org-ref-count-labels + (org-element-property :path object)))) + ;; get plurality on occurrence correct + (message (concat + (number-to-string count) + " occurence" + (when (or (= count 0) + (> count 1)) + "s")))))))))) #+END_SRC * Aliases @@ -2775,6 +2819,7 @@ Technically, this function should return a string that is inserted by helm. This (-contains? org-ref-cite-types (org-element-property :type object))) + ;;(message-box "in a link") (goto-char (org-element-property :end object)) ;; sometimes there are spaces at the end of the link ;; this code moves point pack until no spaces are there @@ -2782,26 +2827,31 @@ Technically, this function should return a string that is inserted by helm. This (insert (concat "," (mapconcat 'identity keys ",")))) ;; We are next to a link, and we want to append + ;; next to a link means one character back is on a link. ((save-excursion (backward-char) (and (equal (org-element-type (org-element-context)) 'link) (-contains? org-ref-cite-types (org-element-property :type (org-element-context))))) - (goto-char (org-element-property :end object)) + ;;(message-box "at end of a link") + ;; (goto-char (org-element-property :end object)) (while (looking-back " ") (backward-char)) (insert (concat "," (mapconcat 'identity keys ",")))) ;; insert fresh link (t + ;;(message-box "fresh link") (insert (concat (if helm-current-prefix-arg - (ido-completing-read "Type: " org-ref-cite-types) + (helm :sources `((name . "link types") + (candidates . ,org-ref-cite-types) + (action . (lambda (x) x)))) org-ref-default-citation-link) ":" (s-join "," keys)))))) -;; return empty string for helm -"") + ;; return empty string for helm + "") (setq helm-bibtex-format-citation-functions '((org-mode . helm-bibtex-format-org-ref))) @@ -2813,6 +2863,11 @@ Technically, this function should return a string that is inserted by helm. This (helm-bibtex))) (require 'helm-bibtex) + +(mapc (lambda (x) (add-to-list 'helm-bibtex-fallback-options x t)) + '(("Crossref" . "http://search.crossref.org/?q=%s") + ("Scopus" . "http://www.scopus.com/scopus/search/submit/xadvanced.url?searchfield=TITLE-ABS-KEY(%s)") + ("Open Web of Science" . (lambda () (browse-url "http://apps.webofknowledge.com"))))) #+END_SRC ** A helm click menu @@ -2852,20 +2907,33 @@ Checks for pdf and doi, and add appropriate functions." (bibtex-autokey-get-field "doi")))) (candidates `(("Quit" . org-ref-citation-at-point) ("Open bibtex entry" . org-ref-open-citation-at-point)))) + ;; for some reason, when there is no doi or url, they are returned as "". I + ;; prefer nil so we correct this here. + (when (string= doi "") (setq doi nil)) + (when (string= url "") (setq url nil)) - - (when (file-exists-p pdf-file) + ;; Conditional pdf functions + (if (file-exists-p pdf-file) + (add-to-list + 'candidates + '("Open pdf" . org-ref-open-pdf-at-point) + t) (add-to-list 'candidates - '("Open pdf" . org-ref-open-pdf-at-point) - t - )) + '("Try to get pdf" . (lambda () + (save-window-excursion + (org-ref-open-citation-at-point) + (bibtex-beginning-of-entry) + (doi-utils-get-bibtex-entry-pdf)))) + t)) + (add-to-list 'candidates '("Open notes" . org-ref-open-notes-at-point) t) + ;; conditional url and doi functions (when (or url doi) (add-to-list 'candidates