From what I understand, in Emacs I can run commands such as M-x (which by the way I believe stands for execute-extended-command). This command M-x itself is used to run things like customize_face e.g. by typing M-x customize-face in the minibuffer.
My questions are:
Q.1. Is customize-face a command? or is it a function? And do we say that customize-face is passed to the command M-x as an argument?
Q.2 Do all Emacs commands have an associated Emacs function? (i.e. when I enter M-x customize-face I presume a defined function is called). If so, how can I look up the function name from the command name? (and viceversa)
Yes, all Emacs commands are functions, but not all functions are Emacs commands. You can make an arbitrary elisp function a command accessible via
M-xusing(interactive):Now that you’ve defined
my-commandas interactive, you can immediately access it withM-x my-command. Emacs does all the bookkeeping with the name for you automatically.This is all you have to do to add a new command! You can then bind it to a key with something like:
Moreover, every key-binding is associated with an interactive function like this. You can find which function is called by which key using
C-h kand entering your key sequence. This will give you the documentation for the function that would be called on that key sequence. If you ran the code I gave you, doingC-h k C-c fwould give you a buffer containing (among other things) your doc-string:So: all Emacs commands are just functions defined with
(interactive). (Actually, there are also some primitive functions from Emacs’s C core, but that isn’t super important.)This simple and elegant relationship between commands and functions–which is easy to follow in either direction–is part of what makes Emacs so easy to customize. If you ever wonder what functions your normal actions called, you can easily look them up, and if you want to add more commands, you just have one extra line in your function.