Let me first give all the names of the commands/functions/processes involved (it is what you ask for). They are:
read-key-sequence
( built-in function in ‘C source code’ )
a procedure called in the documentation "shift-translation" which is setting this-command-keys-shift-translated
and shift-select-mode
handle-shift-selection
(a byte-compiled Lisp function in ‘simple.el’.)
Executing next-char
results in prior run of handle-shift-selection
because of the specification of the directive (interactive "^p")
in the next-char
command where "^p"
specifies that if the string begins with ‘^’ and shift-select-mode is non-nil Emacs first calls the function handle-shift-selection
:
(defun right-char (&optional n)
...
(interactive "^p")
To give such detailed answer it is necessary to put together many pieces of information spread over multiple places in the documentation texts.
Below excerpts from https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Sequence-Input.html with included own remarks to address the specific case in your question:
The command loop reads input a key sequence at a time, by calling read-key-sequence
This above means that before the finally executed command right-char
is triggered by a user key sequence input, there will be also a kind of pre-processing of the keyboard input involved.
The consequence of this fact is that this pre-processing triggers another commands/functions along with the final one.
If an input character is upper-case (or has the shift modifier) and has no key binding, but its lower-case equivalent has one, (this is the case for the combination S-<right>
) then read-key-sequence
converts the character to lower case by invoking what is called "shift-translation" resulting in setting the variable this-command-keys-shift-translated
(defined in ‘C source code’) to a non-nil value.
In the further pre-processing taking place before the final call of right-char
:
Lisp examines this variable. For example, the function handle-shift-selection
will examine the value of this variable to determine how to activate or deactivate the region (see handle-shift-selection).
The missing piece of information not in the documentation seems to be that the pre-processing must set also the appropriate value of shift-select-mode
along with setting of this-command-keys-shift-translated
.
To arrive at this conclusion it was necessary to put together the information provided in both of the other answers by @Drew and by @Shynur .