aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--org-link-edit.el14
-rw-r--r--test-org-link-edit.el22
2 files changed, 31 insertions, 5 deletions
diff --git a/org-link-edit.el b/org-link-edit.el
index 49e9aa0..833d620 100644
--- a/org-link-edit.el
+++ b/org-link-edit.el
@@ -61,6 +61,14 @@
(require 'org-element)
(require 'cl-lib)
+(defun org-link-edit--on-link-p (&optional element)
+ (let ((el (or element (org-element-context))))
+ ;; Don't use `org-element-lineage' because it isn't available
+ ;; until Org version 8.3.
+ (while (and el (not (memq (car el) '(link))))
+ (setq el (org-element-property :parent el)))
+ (eq (car el) 'link)))
+
(defun org-link-edit--link-data ()
"Return list with information about the link at point.
The list includes
@@ -69,11 +77,7 @@ The list includes
- the link text
- the link description (nil when on a plain link)"
(let ((el (org-element-context)))
- ;; Don't use `org-element-lineage' because it isn't available
- ;; until Org version 8.3.
- (while (and el (not (memq (car el) '(link))))
- (setq el (org-element-property :parent el)))
- (unless (eq (car el) 'link)
+ (unless (org-link-edit--on-link-p el)
(user-error "Point is not on a link"))
(save-excursion
(goto-char (org-element-property :begin el))
diff --git a/test-org-link-edit.el b/test-org-link-edit.el
index 893cec5..4f006e7 100644
--- a/test-org-link-edit.el
+++ b/test-org-link-edit.el
@@ -513,6 +513,28 @@ website"
;;; Other
+(ert-deftest test-org-link-edit/on-link-p ()
+ "Test `org-link-edit--on-link-p'."
+ ;; On plain link
+ (should
+ (org-test-with-temp-text "http://orgmode.org/"
+ (org-link-edit--on-link-p)))
+ ;; On bracket link
+ (should
+ (org-test-with-temp-text "\[\[http://orgmode.org/\]\[org\]\]"
+ (org-link-edit--on-link-p)))
+ ;; Point beyond link, but technically still within link element.
+ (should
+ (org-test-with-temp-text "\[\[http://orgmode.org/\]\[org\]\] <point>"
+ (org-link-edit--on-link-p)))
+ ;; Not on a link
+ (should-not
+ (org-test-with-temp-text " \[\[http://orgmode.org/\]\[org\]\]"
+ (org-link-edit--on-link-p)))
+ (should-not
+ (org-test-with-temp-text "not a link"
+ (org-link-edit--on-link-p))))
+
(ert-deftest test-org-link-edit/get-link-data ()
"Test `org-link-edit--link-data'."
;; Plain link