Skip to content

Commit 8d7c8c5

Browse files
amygrinnSbozzolo
authored andcommitted
Add send-next-key function
Read next input event and send it to the libvterm. This is useful for controlling an emacs session within emacs-libvterm.
1 parent dccb6b2 commit 8d7c8c5

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,18 @@ or remove it from `vterm-mode-map`. By default, `vterm.el` binds most of the
455455
like `<backspace>` and `<return>`. Sending a keyboard interrupt is bound to `C-c
456456
C-c`.
457457
458+
In order to send a keypress that is already recognized by Emacs, such as `C-g`,
459+
use the interactive function `vterm-send-next-key`. This can be bound to a key
460+
in the `vterm-mode-map` like `C-q`, in which case pressing `C-q C-g` will send a
461+
`C-g` key to the terminal, and so on for other modified keys:
462+
463+
``` emacs
464+
(define-key vterm-mode-map (kbd "C-q") #'vterm-send-next-key)
465+
```
466+
467+
This can be useful for controlling an application running in the terminal, such
468+
as Emacs or Nano.
469+
458470
## Fonts
459471
460472
You can change the font (the _face_) used in a vterm with the following code:

vterm.el

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,23 @@ will invert `vterm-copy-exclude-prompt' for that call."
922922
(memq 'meta modifiers)
923923
(memq 'control modifiers))))
924924

925+
(defun vterm-send-next-key ()
926+
"Read next input event and send it to the libvterm.
927+
928+
With this you can directly send modified keys to applications
929+
running in the terminal (like Emacs or Nano)."
930+
(interactive)
931+
(let* ((inhibit-quit t)
932+
(event (read-event))
933+
(inhibit-quit nil)
934+
(modifiers (event-modifiers event))
935+
(basic (event-basic-type event)))
936+
(if (characterp basic)
937+
(vterm-send-key (string basic)
938+
(memq 'shift modifiers)
939+
(memq 'meta modifiers)
940+
(memq 'control modifiers)))))
941+
925942
(defun vterm-send-start ()
926943
"Output from the system is started when the system receives START."
927944
(interactive)

0 commit comments

Comments
 (0)