Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Elisp dynamic interactive prompt

Tags:

emacs

elisp

I am trying to have a dynamic prompt from my elisp function. I want something like replace-regexp where it will show you the last regexp entered. I tried (interactive (concat "sab" "bab"))) that doesnt work!

I also tried message like format (interactive "s %s" last-used-regexp)

and that doesn't work! Anyone know how to do this?

Thank you!

like image 845
jacob Avatar asked Apr 16 '09 00:04

jacob


1 Answers

M-x find-function is your friend. It will tell you how anything in emacs works by showing you the source code. Using it, I find that query-regexp-replace calls query-replace-read-args which calls query-replace-read-from which calls read-from-minibuffer using a prompt created from the last used regexp, which is saved in the dotted pair query-replace-defaults.

So:

(defun my-func ()
  "Do stuff..."
  (interactive)
  (read-from-minibuffer "Regexp? " (first query-replace-defaults)))

is a command that throws up a prompt with the last entered regexp as the default.

like image 182
andrewdotn Avatar answered Nov 05 '22 04:11

andrewdotn