C-c C-x C-v calls org-toggle-inline-images function. With prefix key it passes some arguments to this function (don't know which one).

How can I map the function with arguments to the F12 button so it does the same as C-u C-c C-x C-v?

2 Answers 2


C-u is the universal prefix argument. It is often used for commands that only have two states (with and without an argument), though it can also be interpreted as a numeric prefix (4).

In this case, looking at the source code for org-toggle-inline-images I see that it only checks whether the argument is set so the specific value you pass does not matter.

You can define a function that calls (org-toggle-inline-images t). To do it with a lambda:

(define-key org-mode-map  (kbd "<f12>")
    (lambda () (interactive) (org-toggle-inline-images t)))

This binds F12 in org-mode, leaving the global binding in place for other modes.

For more on key bindings, this is a good read: Mastering Key Bindings in Emacs. And of course there are lots of details in the Emacs Lisp manual.


The answer in general is to look at the code defining the command. In particular (but not necessarily only) the interactive spec.

What you look for is what the function does with a prefix arg. And then you define a command that does the same thing.

Typically, the prefix arg is used to define some value that is then passed in the code to another function. You then need only call that other function, passing it the argument that would have been provided via the prefix arg in the original command. IOW, you can typically use the same code, just passing a value in place of the value that would be determined from the prefix arg.

  • 3
    You can also emulate a C-u prefix with this: (let ((current-prefix-arg '(4))) (call-interactively #'whatever-command)). That might be useful if you cannot figure out what the command you are calling is doing with its argument.
    – glucas
    Aug 14, 2015 at 17:56
  • @glucas: That is appropriate only if the particular prefix arg used does not matter for the given command, or if the behavior you want from the command is that of plain C-u. It is not appropriate if the command has different behavior depending on whether plain C-u is used or not (e.g., distinction of C-- or C-3 or C-u C-u from just C-u. My advice is to always check how the command actually treats a prefix arg.
    – Drew
    Aug 14, 2015 at 18:02
  • True, good point. Just providing it as an option for the specific case of "call this as if I pressed C-u first."
    – glucas
    Aug 14, 2015 at 18:04
  • @glucas: What's more, in the case you cite you can typically (but not always) do without interactive use altogether, and just pass '(4) to the command (without bothering with call-interactively). (But that won't work, e.g., if the command does not have a parameter that corresponds to the prefix arg, but instead tests current-prefix-arg in the command body.)
    – Drew
    Aug 14, 2015 at 18:05
  • @glucas: Yes, it was good that you mentioned it.
    – Drew
    Aug 14, 2015 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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