-
-
Save wiedzmin/017a8c410b45a69de871598470353ffd 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 lgm/is-link (text) | |
(let ((url-in-text (cl-search "https://" text))) | |
(if url-in-text | |
(= 0 url-in-text) | |
nil) | |
) | |
) | |
;; Copy Slack behavior of automatically creating link when pasting url with text selected | |
(defun lgm/org-yank-link () | |
(interactive) | |
(let ((yank-text (car kill-ring))) | |
(if (lgm/is-link yank-text) | |
(org-insert-link "https://" yank-text (buffer-substring-no-properties (mark) (point))) | |
(org-yank))) | |
) | |
(org-defkey org-mode-map (kbd "C-y") (lambda () | |
(interactive) | |
(lgm/org-yank-link))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment