]> git.donarmstrong.com Git - org-ref.git/blobdiff - org-ref.org
remove custom_id. we cannot ref these.
[org-ref.git] / org-ref.org
index 73562e9f990125bc4d2f1d65bf160947b6cc2cea..db0e205a640c15f9b5c004c4bcf59adf8a33d4fc 100644 (file)
@@ -1144,14 +1144,35 @@ If you are on a label link, replace it."
                     ;; no matching selection creates a new label
                     ((name . "Create new label")
                      (dummy)
-                     ;; default action creates a new label
+                     ;; default action creates a new label, or replaces old one
                      (action .  (lambda (label)
                                   (switch-to-buffer ,cb)
-                                  (insert
-                                   (concat
-                                    "label:"
-                                    (or label
-                                        helm-pattern))))))))))
+                                  (let* ((object (org-element-context))
+                                         (last-char (save-excursion
+                                                      (goto-char (org-element-property :end object))
+                                                      (backward-char)
+                                                      (if (looking-at " ")
+                                                          " "
+                                                        ""))))
+                                    (if (-contains? '("label")
+                                                    (org-element-property :type object))
+                                        ;; we are on a link, so replace it.
+                                        (setf
+                                         (buffer-substring
+                                          (org-element-property :begin object)
+                                          (org-element-property :end object))
+                                         (concat
+                                          (replace-regexp-in-string
+                                           (org-element-property :path object)
+                                           helm-pattern
+                                           (org-element-property :raw-link object))
+                                          last-char))
+                                      ;; new link
+                                      (insert
+                                       (concat
+                                        "label:"
+                                        (or label
+                                            helm-pattern))))))))))))
 #+END_SRC
 
 Now we create the completion function. This works from the org-machinery, e.g. if you type C-c C-l to insert a link, and use completion by pressing tab.
@@ -3048,13 +3069,6 @@ To get a lighter weight message about the label, ref and cite links, we define a
                        (progn
                          (forward-line 4)
                          (point)))))
-
-      ;; maybe we have a CUSTOM-ID
-      (org-map-entries
-       (lambda () (when (string=
-                        label
-                        (org-entry-get (point) "CUSTOM_ID"))
-                   (throw 'result (org-get-heading)))))
       (beep)
       (throw 'result "!!! NO CONTEXT FOUND !!!"))))
 
@@ -3101,24 +3115,26 @@ To get a lighter weight message about the label, ref and cite links, we define a
                 (link-string (org-element-property :path object))
                 (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)))
 
+            ;; make sure we are in link and not before the :
+           (when (> link-string-beginning (point))
+             (goto-char link-string-beginning))
+
            ;; now if we have comma separated bibliographies
            ;; we find the one clicked on. we want to
            ;; search forward to next comma from point
            (save-excursion
-              (goto-char link-string-beginning)
              (if (search-forward "," link-string-end 1 1)
                  (setq key-end (- (match-end 0) 1)) ; we found a match
                (setq key-end (point)))) ; no comma found so take the point
+
            ;; and backward to previous comma from point
            (save-excursion
-              (goto-char link-string-beginning)
              (if (search-backward "," link-string-beginning 1 1)
                  (setq key-beginning (+ (match-beginning 0) 1)) ; we found a match
                (setq key-beginning (point)))) ; no match found