summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS8
-rw-r--r--org-link-edit.el21
-rw-r--r--test-org-link-edit.el18
3 files changed, 39 insertions, 8 deletions
diff --git a/NEWS b/NEWS
index ac4cb25..159441f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,13 @@
Org Link Edit NEWS -- history of user-visible changes -*- mode: org; -*-
+* Unreleased
+
+** New features
+
+- If the target link already has a description,
+ ~org-link-edit-transport-next-link~ now asks whether to overwrite
+ the description rather than just aborting.
+
* v1.1.0
** New features
diff --git a/org-link-edit.el b/org-link-edit.el
index 00cc109..200ddb9 100644
--- a/org-link-edit.el
+++ b/org-link-edit.el
@@ -338,7 +338,7 @@ If N is negative, barf trailing blobs instead of leading blobs."
(user-error "No %s link found" (if previous "previous" "next")))))
;;;###autoload
-(defun org-link-edit-transport-next-link (&optional previous beg end)
+(defun org-link-edit-transport-next-link (&optional previous beg end overwrite)
"Move the next link to point.
If the region is active, use the selected text as the link's
@@ -349,10 +349,15 @@ the next link.
Non-interactively, use the text between BEG and END as the
description, moving the next (or previous) link relative to BEG
-and END."
- (interactive (cons current-prefix-arg
- (and (use-region-p)
- (list (region-beginning) (region-end)))))
+and END. By default, refuse to overwrite an existing
+description. If OVERWRITE is `ask', prompt for confirmation
+before overwriting; for any other non-nil value, overwrite
+without asking."
+ (interactive `(,current-prefix-arg
+ ,@(if (use-region-p)
+ (list (region-beginning) (region-end))
+ (list nil nil))
+ ask))
(let ((pt (point))
(desc-bounds (cond
((and beg end)
@@ -376,7 +381,11 @@ and END."
(goto-char (or (car desc-bounds) pt))
(cl-multiple-value-bind (link-beg link-end link orig-desc)
(org-link-edit--next-link-data previous)
- (unless (or (not desc-bounds) (= (length orig-desc) 0))
+ (unless (or (not desc-bounds)
+ (= (length orig-desc) 0)
+ (if (eq overwrite 'ask)
+ (y-or-n-p "Overwrite existing description?")
+ overwrite))
(user-error "Link already has a description"))
(delete-region link-beg link-end)
(insert (org-make-link-string
diff --git a/test-org-link-edit.el b/test-org-link-edit.el
index 0980aca..0f63306 100644
--- a/test-org-link-edit.el
+++ b/test-org-link-edit.el
@@ -578,12 +578,26 @@ website"
(org-link-edit-transport-next-link
nil (point-min) (point)))
:type 'user-error)
- ;; Fail if link already has a description.
+ ;; Fail if link already has a description, unless caller confirms
+ ;; the overwrite.
+ (should-error
+ (org-test-with-temp-text
+ "Here is <point>Org's website \[\[http://orgmode.org/\]\[description\]\]"
+ (cl-letf (((symbol-function 'y-or-n-p) (lambda (_) nil)))
+ (call-interactively #'org-link-edit-transport-next-link)))
+ :type 'user-error)
(should-error
(org-test-with-temp-text
"Here is <point>Org's website \[\[http://orgmode.org/\]\[description\]\]"
(org-link-edit-transport-next-link))
- :type 'user-error))
+ :type 'user-error)
+ (should
+ (string=
+ "Here is \[\[http://orgmode.org/\]\[Org's\]\] website "
+ (org-test-with-temp-text
+ "Here is <point>Org's website \[\[http://orgmode.org/\]\[description\]\]"
+ (org-link-edit-transport-next-link nil nil nil 'overwrite)
+ (buffer-string)))))
;;; Other