Created
November 16, 2023 23:55
-
-
Save rytswd/20cd6995d2de05bdc64b9235d0d0d19e to your computer and use it in GitHub Desktop.
Emacs: Send text or region to vterm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun rytswd/vterm-execute-current-line-or-region () | |
"Insert text of current line or region in vterm and execute." | |
(interactive) | |
(let* ((current-line (buffer-substring | |
(save-excursion | |
(beginning-of-line) | |
(point)) | |
(save-excursion | |
(end-of-line) | |
(point)))) | |
(buf (current-buffer)) | |
(command (string-trim | |
(if (use-region-p) | |
(buffer-substring (region-beginning) (region-end)) | |
current-line)))) | |
(unless (get-buffer vterm-buffer-name) | |
(vterm)) | |
(display-buffer vterm-buffer-name t) | |
(switch-to-buffer-other-window vterm-buffer-name) | |
(vterm--goto-line -1) | |
(vterm-send-string command t) | |
(vterm-send-return) | |
(switch-to-buffer-other-window buf) | |
(when (featurep 'beacon) | |
(beacon-blink)) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment