Skip to content
This repository has been archived by the owner on May 18, 2020. It is now read-only.

Commit

Permalink
Merge branch 'km/transport-whitespace'
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleam committed May 6, 2017
2 parents e0be9b9 + 5c5fef3 commit 1f8c200
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
13 changes: 7 additions & 6 deletions org-link-edit.el
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,18 @@ 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))
(cl-multiple-value-bind (link-beg link-end link desc)
(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 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
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
15 changes: 15 additions & 0 deletions test-org-link-edit.el
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,21 @@ website"
(org-link-edit-transport-next-link
'previous (point) (point-max))
(buffer-string))))
;; Transport next link with point on whitespace.
(should
(string= "Here is\[\[http://orgmode.org/\]\] Org's website "
(org-test-with-temp-text
"Here is<point> 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<point> 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
Expand Down

0 comments on commit 1f8c200

Please sign in to comment.