From 9f0209543318c331c5a4051750ea817370d234f6 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 24 Jan 2019 19:59:26 -0500 Subject: 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. --- org-link-edit.el | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'org-link-edit.el') 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 -- cgit v1.2.3