Is there any way to add my own completion to an (interactive)
elisp function? Ideally, I'd like to pass it a list of strings that it would tab-complete from. I know that using (interactive "D")
, (interactive "F")
or (interactive "b")
give you completion for directories, files and buffer-names respectively, but what about more general inputs?
Asked
Active
Viewed 2,728 times
20

Inaimathi
- 13,853
- 9
- 49
- 93
1 Answers
38
The argument to interactive
need not be a string; if it isn't, it's evaluated to get the list of arguments to pass to the function. Therefore, you can do something like this:
(defun insert-foo-bar-or-baz (arg)
(interactive
(list
(completing-read "Choose one: " '("foo" "bar" "baz"))))
(insert arg))

Sean
- 29,130
- 4
- 80
- 105
-
1/facepalm Now that I've seen an example, that comment in the `M-x apropos` entry for `interactive` makes perfect sense. – Inaimathi Mar 04 '10 at 21:29
-
Don't work @lnaimathi you are not alone in the facepalming :) LOL – Shane Aug 31 '18 at 20:57