Insert link: use selection as title if region active

Here is a small snippet that I find useful - when inserting an org-roam link:

  1. if region is active, use the selection as default suggestion to a link
  2. if region is not active, just do the usual org-roam-insert

This way you can quickly enrich an existing text with links.

I bind it to key instead of org-roam-insert.

(defun org-roam-insert-dwim ()
"Insert an org-roam link. If there is a region active, use it as name."
(push (if (region-active-p)
          (capitalize-dwim '(buffer-substring-no-properties
        (thing-at-point 'symbol))
(call-interactively 'org-roam-insert))

Isn’t that a vanilla behaviour?


Ah… I’ve just checked and it is… I’ve been using this before org-roam had the capability and did not notice that it is default by now…