I have just (yesterday) installed emacs and am in the process of learning the very basics of its usage (I have never used emacs before, but I am maybe on the way to switch from SciTE and lua to emacs and elisp).
In between I mean to have already gained some basic understanding how emacs works under the hood and if I got it right there must be a lisp function there which is taking all keystrokes from user in order to dispatch them to other functions if the keystrokes are representing a keyboard shortcut or to the buffer if not, but was not able to find any information which one it is yet.
Is my understanding of how emacs handles user input the right one?
Or are the user input events (keystrokes, mouse action) sent by the OS to the emacs window dispatched by the emacs binary to the commands after being in a first stage internally evaluated by the binary, so there is no elisp script there which receives them all?
UPDATE responding to comment by Drew:
I have started to read the recommended documentation https://www.gnu.org/software/emacs/manual/html_node/elisp/Command-Overview.html but if I understand it right there should be somewhere an elisp function
read-key-sequence so I should be able to find it using:
~ $ locate read-key-sequence
or if this fails
~ $ grep "defun read-key-sequence" $(locate -b *.el)
but both of the above commands fail to find something.
Is this a hint that the
read-key-sequence is hard coded in the emacs binary and not available as elisp code which with appropriate modification would be able to trigger an own elisp script receiving all the user input as it comes in?
C-h f self-insert-command: that's the command that's bound to most keys. Its effect is to insert the character corresponding to that key into the buffer. The basic notion is that of a keymap: a keymap maps a key (which may actually be a key sequence) to a command, so what Emacs does is figure out what key was pressed, look it up in a keymap and call the command that corresponds to it. There are all sorts of complications, but that's a decent high level view and a good approximation to the truth.
C-h bis a great help to get an overview of key bindings. What I don't understand is why M-p is not mentioned in that list? Where I can find the description what M-p does? Calling C-h k -> M-p results in the response that M-p is not defined ... but I can get the last command retrieved using it, so it is defined ... Hmmm ...
Fundamentalmode e.g. and the keymap for that mode does not have a binding for
M-p. But if you try to do
M-x something, you end up in the minibuffer which has its own keymap and in that keymap there is a binding for
C-h t) and read the manual (
C-h i g(emacs)) in tandem. There is no royal road to Emacs...