summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2021-07-02 18:00:19 +0200
committerLeah Neukirchen <leah@vuxu.org>2021-07-02 18:00:19 +0200
commit793b2a106b04aecea5521a06260d76deb70f3cf3 (patch)
treeb22b65e1cc8b36cda91bbe7d357a4c420da90bae
parent237a10b0d399538c6b29be2c3ce4f482d46f0d9d (diff)
downloadmoar-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.el22
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)