Skip to content

Commit 8c66bd5

Browse files
committed
Save marker and use it in callback for insert
* org-cliplink.el (org-cliplink-insert-transformed-title): Save point as a marker, and use it in the callback so that it inserts the link at the position at which the `org-cliplink' command was executed.
1 parent ab4816e commit 8c66bd5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

org-cliplink.el

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,10 +559,18 @@ TITLE-REGEXP does not match TITLE, return the original TITLE."
559559
"Takes the URL, asynchronously retrieves the title and applies
560560
a custom TRANSFORMER which transforms the url and title and insert
561561
the required text to the current buffer."
562-
(org-cliplink-retrieve-title
563-
url
564-
(lambda (url title)
565-
(insert (funcall transformer url title)))))
562+
(let ((m (point-marker)))
563+
(org-cliplink-retrieve-title
564+
url
565+
(lambda (url title)
566+
(let ((save-and-restore-position (/= (point) m))
567+
(link (funcall transformer url title)))
568+
(if save-and-restore-position
569+
(save-excursion
570+
(goto-char m)
571+
(insert link))
572+
(insert link))
573+
(set-marker m nil))))))
566574

567575
;;;###autoload
568576
(defun org-cliplink-retrieve-title-synchronously (url)

0 commit comments

Comments
 (0)