9

So, I want to do (ispell-change-dictionary) inside a function I'm writing, but doing a test throws this error:

(wrong-number-of-arguments #[(dict &optional arg)

I was told that M-x calls the function without arguments. Well, I did the same but for me an error happens. Weird.

I just want to allow the user to select a dictionary without hard-coding the list of dictionaries, showing what's available just as M-x ispell-change-dictionary RET does.

Drew
  • 75,699
  • 9
  • 109
  • 225
shackra
  • 2,702
  • 18
  • 47
  • Using `M-x` calls the function *interactively*, and the function's `interactive` form is then used to gather the necessary argument values (possibly prompting the user for some of the values). – phils May 13 '17 at 01:18

1 Answers1

14

If you want to call an interactive function from within elisp, but call it as if you invoked it interactively (e.g., via M-x some-command), you can wrap it in the call-interactively function.

The first part of the docstring reads:

(call-interactively FUNCTION &optional RECORD-FLAG KEYS)

Call FUNCTION, providing args according to its interactive calling specs. Return the value FUNCTION returns. The function contains a specification of how to do the argument reading. In the case of user-defined functions, this is specified by placing a call to the function interactive at the top level of the function body. See interactive.

So, in your case, you can use (call-interactively #'ispell-change-dictionary) within the body of your function.

Dan
  • 32,584
  • 6
  • 98
  • 168