I've read the documentation on how to make interactive calls from within Elisp, but I still can't figure out how to pass the universal argument when using call-interactively on a command that recognizes the universal argument.

More specifically, I want to implement a function that, under certain conditions, should call the shell command interactively with the universal argument, so that, as a result, the prompt

Shell buffer (default *shell*): 

will be visible in the minibuffer, and, once this prompt gets a response, the specified buffer will be created (if it doesn't exist already), and made the current buffer.

FWIW, I tried the following:

(call-interactively 'shell)


(setq prefix-arg (list 4))
(call-interactively 'shell)

...but I never saw the prompt Shell buffer (default *shell*):; instead, in all cases, the shell command ran exactly as if it had been called without the universal argument. (I really don't know what I'm doing here, so my blind attempts above were made with conscious disregard of the documentation's prescient advice.)

  • 3
    Try (let ((current-prefix-arg 4)) (call-interactively 'shell))
    – xuchunyang
    Commented Apr 15, 2016 at 13:20
  • Thank you! I'll gladly accept this as the answer if you care to post it as such.
    – kjo
    Commented Apr 15, 2016 at 14:01

1 Answer 1


According to shell's interactive form, as long as current-prefix-arg is non-nil, shell will ask user a buffer to use, so you can set current-prefix-arg to non-nil (4 is used in following as an example):

(let ((current-prefix-arg 4))
  (call-interactively 'shell))

or simulate executing shell with a prefix 4 (M-4 M-x shell):

(execute-extended-command 4 "shell")
  • Just a tiny quibble: if one is going to use a truthy value other than plain old t, shouldn't that be (list 4) (or '(4) if you prefer)? I realize that the current version of shell does not care about the difference between 4 and (list 4) (it cares only that the value is non-nil), but future versions might.
    – kjo
    Commented Apr 15, 2016 at 14:57
  • 2
    4 simulates M-4 M-x shell, '(4) simulates C-u M-x shell
    – npostavs
    Commented Apr 15, 2016 at 15:08

Your Answer

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

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