Allow term-mode to send function keys to the underlying shell
* lisp/term.el (term-bind-function-keys): New user option. (term-raw-map): Bind f keys. (term-send-function-key): Send the function key to the underlying shell (bug#29920).
This commit is contained in:
parent
4b20ae908b
commit
33141b51c3
2 changed files with 36 additions and 0 deletions
5
etc/NEWS
5
etc/NEWS
|
@ -1137,6 +1137,11 @@ filters and displayed with the specified color.
|
|||
|
||||
** term-mode
|
||||
|
||||
---
|
||||
*** New user option 'term-bind-function-keys'.
|
||||
If non-nil, 'term-mode' will pass the function keys on to the
|
||||
underlying shell instead of using the normal Emacs bindings.
|
||||
|
||||
---
|
||||
*** Support for ANSI 256-color and 24-bit colors, italic and other fonts.
|
||||
Term-mode can now display 256-color and 24-bit color codes. It can
|
||||
|
|
31
lisp/term.el
31
lisp/term.el
|
@ -918,6 +918,13 @@ is buffer-local."
|
|||
:type 'integer
|
||||
:version "27.1")
|
||||
|
||||
(defcustom term-bind-function-keys nil
|
||||
"If nil, don't alter <f1>, <f2> and so on.
|
||||
If non-nil, bind these keys in `term-mode' and send them to the
|
||||
underlying shell."
|
||||
:type 'boolean
|
||||
:version "29.1")
|
||||
|
||||
|
||||
;; Set up term-raw-map, etc.
|
||||
|
||||
|
@ -958,6 +965,10 @@ is buffer-local."
|
|||
(define-key map [next] 'term-send-next)
|
||||
(define-key map [xterm-paste] #'term--xterm-paste)
|
||||
(define-key map [?\C-/] #'term-send-C-_)
|
||||
|
||||
(when term-bind-function-keys
|
||||
(dotimes (key 21)
|
||||
(keymap-set map (format "<f%d>" key) #'term-send-function-key)))
|
||||
map)
|
||||
"Keyboard map for sending characters directly to the inferior process.")
|
||||
|
||||
|
@ -1411,6 +1422,26 @@ Entry to this mode runs the hooks on `term-mode-hook'."
|
|||
(defun term-send-del () (interactive) (term-send-raw-string "\e[3~"))
|
||||
(defun term-send-backspace () (interactive) (term-send-raw-string "\C-?"))
|
||||
(defun term-send-C-_ () (interactive) (term-send-raw-string "\C-_"))
|
||||
|
||||
(defun term-send-function-key ()
|
||||
"If bound to a function key, this will send that key to the underlying shell."
|
||||
(interactive)
|
||||
(let ((key (this-command-keys-vector)))
|
||||
(when (and (= (length key) 1)
|
||||
(symbolp (elt key 0)))
|
||||
(let ((name (symbol-name (elt key 0))))
|
||||
(when (string-match "\\`f\\([0-9]++\\)\\'" name)
|
||||
(let* ((num (string-to-number (match-string 1 name)))
|
||||
(ansi
|
||||
(cond
|
||||
((<= num 5) (+ num 10))
|
||||
((<= num 10) (+ num 11))
|
||||
((<= num 14) (+ num 12))
|
||||
((<= num 16) (+ num 13))
|
||||
((<= num 20) (+ num 14)))))
|
||||
(when ansi
|
||||
(term-send-raw-string (format "\e[%d~" ansi)))))))))
|
||||
|
||||
|
||||
(defun term-char-mode ()
|
||||
"Switch to char (\"raw\") sub-mode of term mode.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue