Skip to content

Instantly share code, notes, and snippets.

@rytswd
Created November 16, 2023 23:55
Show Gist options
  • Save rytswd/20cd6995d2de05bdc64b9235d0d0d19e to your computer and use it in GitHub Desktop.
Save rytswd/20cd6995d2de05bdc64b9235d0d0d19e to your computer and use it in GitHub Desktop.
Emacs: Send text or region to vterm
(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