diff options
author | Kyle Meyer <kyle@kyleam.com> | 2019-01-24 19:59:26 -0500 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2019-01-24 20:01:42 -0500 |
commit | 9f0209543318c331c5a4051750ea817370d234f6 (patch) | |
tree | aacc6eafc5442388bc11a4565666bcfcf8230da6 | |
parent | d6019ec351d123b4b4f499d18068b72a187fafe6 (diff) | |
download | org-link-edit-9f0209543318c331c5a4051750ea817370d234f6.tar.gz |
transport: Let caller overwrite previous description
The existing description may not be of interest to the caller,
especially if it was automatically generated by org-store-link.
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | org-link-edit.el | 21 | ||||
-rw-r--r-- | test-org-link-edit.el | 18 |
3 files changed, 39 insertions, 8 deletions
@@ -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 |