diff options
author | Leah Neukirchen <leah@vuxu.org> | 2021-07-02 18:00:19 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2021-07-02 18:00:19 +0200 |
commit | 793b2a106b04aecea5521a06260d76deb70f3cf3 (patch) | |
tree | b22b65e1cc8b36cda91bbe7d357a4c420da90bae | |
parent | 237a10b0d399538c6b29be2c3ce4f482d46f0d9d (diff) | |
download | moar-793b2a106b04aecea5521a06260d76deb70f3cf3.tar.gz moar-793b2a106b04aecea5521a06260d76deb70f3cf3.tar.xz moar-793b2a106b04aecea5521a06260d76deb70f3cf3.zip |
moar-insert-link: wrap region if transient mark mode is active
-rw-r--r-- | moar.el | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/moar.el b/moar.el index eb71180..0e767f8 100644 --- a/moar.el +++ b/moar.el @@ -173,13 +173,21 @@ (defun moar-insert-link () (interactive) - (let* ((links (moar-all-links)) - (read (if (fboundp 'ivy-read) - #'ivy-read - #'completing-read)) - (target (funcall read "Link target? " links))) - (when target - (insert "[" target "]")))) + (if (use-region-p) + (save-excursion + (let ((start (region-beginning)) + (end (region-end))) + (goto-char end) + (insert "]") + (goto-char start) + (insert "["))) + (let* ((links (moar-all-links)) + (read (if (fboundp 'ivy-read) + #'ivy-read + #'completing-read)) + (target (funcall read "Link target? " links))) + (when target + (insert "[" target "]"))))) (defun moar-visit-link-interactive () (interactive) |