1

I have this function in my .emacs file that I thought used to work properly but now doesn't:

(defun insert-date ()
  (interactive "i")
  (insert (format-time-string "%Y-%m-%d")))

Emacs gives the error when I issue M-x insert-date:

call-interactively: Wrong number of arguments: (lambda nil (interactive "i") (insert (format-time-string "%Y-%m-%d"))), 1

I thought the i argument to interactive tells Emacs to ignore any arguments because none are expected. What is wrong with the command that prevents me from using it like I think it should be used?

1 Answer 1

3

The texinfo documentation says:

Just `(interactive)' means pass no args when calling interactively.

You are perhaps confusing an argument that is always nil with no arguments at all. The parameter i would be useful in cases where you want to ignore a particular parameter interactively, passing nil in that case.

There is also more information in the emacs manual: 20.2.1 Using interactive

Sign up to request clarification or add additional context in comments.

2 Comments

IOW, "i" expects an argument, and the function does not expect/provide one.
If you had a function that took three arguments but you only wanted to prompt for two interactively, it would be one way of ignoring the third argument wherever is was in the parameter list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.