From 57f3a6110d7386cb71b01b8251aa7d3b11be5b8e Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 5 May 2017 19:38:34 -0400 Subject: transport-next-link: Fix error on whitespace When point is on whitespace, there are no description bounds because there is no text to use for the description. Avoid a type error in this case by navigating to the initial location of point rather than the left description bound. --- org-link-edit.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'org-link-edit.el') diff --git a/org-link-edit.el b/org-link-edit.el index 6fa105a..636d191 100644 --- a/org-link-edit.el +++ b/org-link-edit.el @@ -373,7 +373,7 @@ END." (progn (goto-char pt) (org-link-edit--on-link-p))) (user-error "Cannot transport next link with point on a link")) - (goto-char (car desc-bounds)) + (goto-char (or (car desc-bounds) pt)) (cl-multiple-value-bind (link-beg link-end link desc) (org-link-edit--next-link-data previous) (unless (or (not desc-bounds) (= (length desc) 0)) -- cgit v1.2.3 From 36508630d7b8a2c7941f01104e0a0581a464d8cc Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 5 May 2017 19:44:18 -0400 Subject: transport-next-link: Rename a variable for clarity Make it more obvious that this variable corresponds to the original link's description, not the new description specified by the word at point or the selected text. --- org-link-edit.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'org-link-edit.el') diff --git a/org-link-edit.el b/org-link-edit.el index 636d191..6e58155 100644 --- a/org-link-edit.el +++ b/org-link-edit.el @@ -374,9 +374,9 @@ END." (org-link-edit--on-link-p))) (user-error "Cannot transport next link with point on a link")) (goto-char (or (car desc-bounds) pt)) - (cl-multiple-value-bind (link-beg link-end link desc) + (cl-multiple-value-bind (link-beg link-end link orig-desc) (org-link-edit--next-link-data previous) - (unless (or (not desc-bounds) (= (length desc) 0)) + (unless (or (not desc-bounds) (= (length orig-desc) 0)) (user-error "Link already has a description")) (delete-region link-beg link-end) (insert (org-make-link-string -- cgit v1.2.3 From 5c5fef32b4690092bbc9e86a8cf6718288053596 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 5 May 2017 19:54:18 -0400 Subject: transport-next-link: Keep original description when on whitespace A to-be-transported link is allowed to have a description if a new description isn't specified by the word at point or the selected text. In this case, don't drop the original description during transport. --- org-link-edit.el | 7 ++++--- test-org-link-edit.el | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'org-link-edit.el') diff --git a/org-link-edit.el b/org-link-edit.el index 6e58155..193f8fa 100644 --- a/org-link-edit.el +++ b/org-link-edit.el @@ -381,9 +381,10 @@ END." (delete-region link-beg link-end) (insert (org-make-link-string link - (and desc-bounds - (delete-and-extract-region (car desc-bounds) - (cdr desc-bounds)))))))) + (if desc-bounds + (delete-and-extract-region (car desc-bounds) + (cdr desc-bounds)) + orig-desc)))))) (provide 'org-link-edit) ;;; org-link-edit.el ends here diff --git a/test-org-link-edit.el b/test-org-link-edit.el index a5fecef..b88592d 100644 --- a/test-org-link-edit.el +++ b/test-org-link-edit.el @@ -552,6 +552,14 @@ website" "Here is Org's website http://orgmode.org/" (org-link-edit-transport-next-link) (buffer-string)))) + ;; Transported links are allow to have an existing description when + ;; point is on whitespace. + (should + (string= "Here is\[\[http://orgmode.org/\]\[descrption\]\] Org's website " + (org-test-with-temp-text + "Here is Org's website \[\[http://orgmode.org/\]\[descrption\]\]" + (org-link-edit-transport-next-link) + (buffer-string)))) ;; Fail if point is on a link. (should-error (org-test-with-temp-text -- cgit v1.2.3