Last active
April 10, 2023 23:24
-
-
Save lgmoneda/bc08cb3ebae106b005faea32afe6280d to your computer and use it in GitHub Desktop.
Copy Slack behavior of automatically creating link when pasting url with text selected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun my-org-make-link () | |
"Turn selected text into an Org mode link by replacing the selected | |
text with a link that uses the selected text as the link description | |
and the clipboard contents as the link URL." | |
(interactive) | |
(let ((link-description (if (use-region-p) | |
(buffer-substring-no-properties (region-beginning) (region-end)) | |
(read-string "Link description: "))) | |
(clipboard-contents (current-kill 0))) | |
(delete-region (region-beginning) (region-end)) | |
(insert (concat "[[" clipboard-contents "][" link-description "]]")))) | |
(define-key org-mode-map (kbd "s-v") 'my-org-make-link) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment