Skip to content

Commit

Permalink
Save marker and use it in callback for insert
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Miciah committed May 27, 2021
1 parent ab4816e commit 8c66bd5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions org-cliplink.el
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,18 @@ TITLE-REGEXP does not match TITLE, return the original TITLE."
"Takes the URL, asynchronously retrieves the title and applies
a custom TRANSFORMER which transforms the url and title and insert
the required text to the current buffer."
(org-cliplink-retrieve-title
url
(lambda (url title)
(insert (funcall transformer url title)))))
(let ((m (point-marker)))
(org-cliplink-retrieve-title
url
(lambda (url title)
(let ((save-and-restore-position (/= (point) m))
(link (funcall transformer url title)))
(if save-and-restore-position
(save-excursion
(goto-char m)
(insert link))
(insert link))
(set-marker m nil))))))

;;;###autoload
(defun org-cliplink-retrieve-title-synchronously (url)
Expand Down

0 comments on commit 8c66bd5

Please sign in to comment.