0

I've written a regular expression to transform Markdown links into Org Mode links and I've stored it into a variable.

(defvar markdown-link-to-org-regexp "s/\[\(.+\)\](\(.+\))/[[\2][\1]]")

I'm using Doom and Evil mode so next time I type : so I go to the minibuffer I'd like to bring that string into the minibuffer. Is there an easy way to do it?

  • Copy the region and then yank it (C-y) into the minibuffer? – NickD Oct 6 at 18:06
  • The region as plain text won't be available when I need it. That regex will live in init.el and the usage will happen when editing some org file and pasting some content from the internet. So the request is to bring to the minibuffer a predefined string from a variable. – tonicebrian Oct 7 at 6:32
0

Define an interactive function (aka command), which inserts this string. Then put this function on a key binding.

(defun my-insert-regex ()
  (interactive)
  (insert (format "%S" markdown-link-to-org-regexp)))

(define-key global-map (kbd "C-c i") #'my-insert-regex)

When doing M-: you then just have to press C-c i to insert this string at the prompt.

Note, that your regex is eventualy wrong and needs more escape characters. re-builder can help you construct this regex.


Second option:

This M-: promt normaly supports a history. You just need to type or paste it once, then you can retrieve former inputs with <up> and <down> keys. C-r searches backwards in the history. (C-r maybe has a different keybinding in Doom, Evil).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.