How to send <C-left> to the term Emacs?

I use this function to send raw commands to the terminal:

(defun raw (str)
  (interactive "sKey: ")
  (term-send-raw-string (read-kbd-macro str)))

But read-kbd-macrofor <C-left>return [C-left], which is not a string.

I also tried:

(term-send-raw-string "\C-\eOD")

and

(define-key term-raw-map (kbd "<C-left>") 'term-send-raw)

But they also do not work.

How can I send C-left then?

+3
source share
1 answer

I have the following snippet in my installation file for the same purpose as you: move the words at the bash prompt using C-<arrows>

(defun term-send-Cright () (interactive) (term-send-raw-string "\e[1;5C"))
(defun term-send-Cleft  () (interactive) (term-send-raw-string "\e[1;5D"))
(define-key term-raw-map (kbd "C-<right>") 'term-send-Cright)
(define-key term-raw-map (kbd "C-<left>")  'term-send-Cleft)

I found the codes \e[1;5Cand \e[1;5Dusing the following trick:

  • run cat >/dev/nullin terminal
  • type C-<left>and C-<right>and see that the echo returns to the terminal
  • exit with C-dorC-c

Another way to find them would be to enter a terminal: C-v C-<left>

+3
source

All Articles