summary refs log tree commit diff
path: root/moar.el
diff options
context:
space:
mode:
Diffstat (limited to 'moar.el')
-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)