]> git.donarmstrong.com Git - org-ref.git/blobdiff - org-ref.org
make message function only run in org-mode
[org-ref.git] / org-ref.org
index 1e03bdfb64fddae469e20ef88c1c759abdfd7da4..92b3252565bffcc34074ed2bd222c2d188fc93c4 100644 (file)
@@ -2679,8 +2679,6 @@ Sometimes it may be helpful to manually change the order of citations. These fun
 ** 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
-
 #+BEGIN_SRC emacs-lisp :tangle org-ref.el
 (defun org-ref-get-label-context (label)
   "Return a string of context around a label."
@@ -2738,34 +2736,35 @@ ref:test citep:test  label:rett
 (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)))
-    (save-excursion
-      (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 (org-ref-get-label-context
-               (org-element-property :path object))))
-
-     ((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
+  (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)))
+
+        ;; message some context about the label we are referring to
+        ((string= type "ref")
+         (message (org-ref-get-label-context
+                   (org-element-property :path object))))
+
+        ((string= type "eqref")
+         (message (org-ref-get-label-context
                    (org-element-property :path object))))
-        ;; get plurality on occurrence correct
-       (message (concat
-                 (number-to-string count)
-                 " occurence"
-                 (when (or (= count 0)
-                           (> count 1))
-                   "s")))))))))
+
+        ;; 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
@@ -2821,6 +2820,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
@@ -2828,18 +2828,21 @@ 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
                   (helm :sources `((name . "link types")