aboutsummaryrefslogtreecommitdiff
path: root/org-link-edit.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2017-03-03 00:10:00 -0500
committerKyle Meyer <kyle@kyleam.com>2017-03-03 00:29:36 -0500
commitae8e918c873febd58abfc332ebf8f59448e8fff4 (patch)
treed526f32083d7bc1aa1cf1681353ab2bbcd5c567d /org-link-edit.el
parent5dd5901cf6850f2bfdba64c896d10b017633600e (diff)
downloadorg-link-edit-ae8e918c873febd58abfc332ebf8f59448e8fff4.tar.gz
Add a separate function for testing if point is on a link
The slurping and barfing commands are interested in point being on a link, so it is sufficient for them to use org-link-edit--get-link-data and get a user-error when point is not on a link. But an upcoming command will want to know that point is _not_ in a link.
Diffstat (limited to 'org-link-edit.el')
-rw-r--r--org-link-edit.el14
1 files changed, 9 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))