3

Emacs help shown using C-h k S-<right> states only:

<right> (translated from S-<right>) runs the command right-char (found
in global-map), which is an interactive byte-compiled Lisp function in
‘bindings.el’.
It is bound to <right>.

It doesn't also say how it comes that S-<right> not only moves the cursor one position to the right (or to beginning of next line if at end of a line) but also results in starting, extending or shrinking a highlighted selection.

This raises the question: Which commands/functions/processes are executed on keyboard input S-<right> along with command right-char?

Drew
  • 75,699
  • 9
  • 109
  • 225
Claudio
  • 410
  • 2
  • 11
  • You might consider editing the question to make it more *general*, because it's not just `S-` that has a similar property. (`C-p`, `C-e`, ...) – shynur Apr 15 '23 at 16:54
  • More general is not welcome here at emacs.stackexchage.com. So at least my up to now experience. The more the question down to a detail that can be solved/answered, the better. Maybe you consider to write such question along with giving an answer to it yourself sharing this way your knowledge? Making this way the first step to neovimacs (two days ago I have discovered kakoune modal editing available also for emacs and in my eyes worth to be the standard way of editing in neovimacs). Your *cursor* instead of *point* ... you are ready for the transition, right? – Claudio Apr 15 '23 at 17:43

3 Answers3

4
(defun right-char (&optional n)
  ...
  (interactive "^p")

describe-function interactive:

If the string begins with ‘^’ and shift-select-mode is non-nil, Emacs first calls the function handle-shift-selection.

shynur
  • 4,065
  • 1
  • 3
  • 23
  • The command is `right-char`. But I guess what you really want to ask is `handle-shift-selection`. – shynur Apr 15 '23 at 15:03
  • `handle-shift-selection` isn't a command. So whether that might or might not be what OP *really* wants, it's not what OP asked, which was *"Which **command(s)** is (are) run on keyboard input S-?"* (And in the title it's just *"Which command is run on keyboard input S-?"*) – Drew Apr 15 '23 at 17:08
  • 1
    @Drew: You are right; I will upvote your answer which really answered the question, to make more people notice it. But, still, I *think* that people who ask a question like that probably want to ask about `handle-shift-selection`, and people who know the answer won't ask a question like that, so your answer may not be what they're looking for. – shynur Apr 15 '23 at 17:39
  • @Drew : sorry for not stating my question clearly enough. I have updated my question to be more clear. I am still coping a bit with distinguishing between commands and functions. And there seems to be more than commands and functions there - I named it "processes" which might be wrong - but was the best term coming to my mind in this context. – Claudio Apr 15 '23 at 18:05
  • @Shynur : you are excellent at communicating your messages in a conflict-free way skillful giving and taking at the same time. Have you learned it somewhere or is it how you really are? – Claudio Apr 15 '23 at 18:14
  • @Shynur: I agree that my answer answered the question as posed originally, but that knowing about `handle-shift-selection` might help OP more. (An answer doesn't have to be the best answer to be helpful.) And I think my answer might also have helped OP learn to better ask Emacs (asking it about `shift selection`, for example). I also (mistakenly I guess) thought the question was about not only shift *selection* but also Shift *translation* (why `S-` acts like `` when `S-` isn't bound overtly). – Drew Apr 15 '23 at 20:58
2

No, that key description (in *Help*) does not raise the question "Which command (s) is (are) run on keyboard input S-?". It answers that question: the command right-char is run.

  • For information about how or why S-<right> is automatically translated to <right>, you need to consult the manual.

    In the Elisp manual, i shift TAB shows you shift translation as one choice. Choosing it takes you to node Key Sequence Input, where shift selection is defined and explained.

  • For information about how or why Shift can cause the selection (region) to be adjusted, you need to consult the manual.

    In the Emacs manual, i shift TAB gives you shift-selection, and RET then takes you to node Shift Selection.

Drew
  • 75,699
  • 9
  • 109
  • 225
1

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 .

Claudio
  • 410
  • 2
  • 11
  • *"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."* If you think something important is missing from the documentation, then `M-x report-emacs-bug`. – Drew Apr 15 '23 at 17:05
  • I am quite sure you will find it somewhere mentioned, but until it will be the case feel yourself challenged to prove me wrong and report it here, so I can add the appropriate documentation link to my answer replacing the (maybe wrong) statement. – Claudio Apr 15 '23 at 17:26