reddit / emacs

What does `("C-p" . previous-line)` in `term-bind-key-alist` do?

brightlystar · 2022-08-09 16:01
I am using `multi-term` to manage multiple terminals. When I open a new term with `M-x multi-term RET`, the terminal is in `char` mode which is good. I execute a command in the terminal like this: echo hello world Then I type `C-p` but nothing happens. I check `C-h v term-bind-key-alist RET` and it has this info: term-bind-key-alist is a variable defined in ‘multi-term.el’. Its value is shown below. The key alist that will need to be bind. If you do not like default setup, modify it, with (KEY . COMMAND) format. You can customize this variable. Value: (("C-c C-c" . term-interrupt-subjob) ("C-c C-e" . term-send-esc) ("C-p" . previous-line) ("C-n" . next-line) ("C-s" . isearch-forward) ("C-r" . isearch-backward) ("C-m" . term-send-return) ("C-y" . term-paste) ("M-f" . term-send-forward-word) ("M-b" . term-send-backward-word) ("M-o" . term-send-backspace) ("M-p" . term-send-up) ("M-n" . term-send-down) ("M-M" . term-send-forward-kill-word) ("M-N" . term-send-backward-kill-word) ("<C-backspace>" . term-send-backward-kill-word) ("M-r" . term-send-reverse-search-history) ("M-d" . term-send-delete-word) ("M-," . term-send-raw) ("M-." . comint-dynamic-complete)) So by default `C-p` is bound to `previous-line`. So when I type `C-p` in terminal (which is in `char` mode), the cursor should move one line up? But nothing happens when I type `C-p` in the terminal. What good is the entry for `("C-p" . previous-line)` in `term-bind-key-alist` then if `C-p` does nothing? Anyone savvy can help me to understand what the use of this entry is?
Hamilton950B · 2022-08-09 17:52
Do the other bindings work? What does describe-key say?
brightlystar · 2022-08-09 20:21
Yes, other key bindings like `C-c C-c` (tested by cancelling commands), `C-c C-e` (tested by opening vim in Emacs ansi-terminal), `C-s`, `C-r`, etc. work. About describe-key, when I am in a terminal and then I run `C-h k C-p`, I get this info: C-p runs the command previous-line (found in term-raw-map), which is an interactive compiled Lisp function in ‘simple.el’. It is bound to C-p. (previous-line &optional ARG TRY-VSCROLL) Move cursor vertically up ARG lines. Interactively, vscroll tall lines if ‘auto-window-vscroll’ is enabled. Non-interactively, use TRY-VSCROLL to control whether to vscroll tall lines: if either ‘auto-window-vscroll’ or TRY-VSCROLL is nil, this function will not vscroll. ARG defaults to 1. If there is no character in the target line exactly over the current column, the cursor is positioned after the character in that line that spans this column, or at the end of the line if it is not long enough. If the variable ‘line-move-visual’ is non-nil, this command moves by display lines. Otherwise, it moves by buffer lines, without taking variable-width characters or continued lines into account. See M-x previous-logical-line for a command that always moves by buffer lines. The command C-x C-n can be used to create a semipermanent goal column for this command. Then instead of trying to move exactly vertically (or as close as possible), this command moves to the specified goal column (or as close as possible). The goal column is stored in the variable ‘goal-column’, which is nil when there is no goal column. Note that setting ‘goal-column’ overrides ‘line-move-visual’ and causes this command to move by buffer lines rather than by display lines. This function is for interactive use only; in Lisp code use `forward-line' with negative argument instead.