dotfiles/emacs/.emacs.d/config/init-vterm.el

65 lines
2.6 KiB
EmacsLisp
Raw Normal View History

2021-04-05 14:46:49 +00:00
;; -*- lexical-binding: t; -*-
2021-02-21 13:20:05 +00:00
(use-package vterm
:commands vterm
2021-02-21 21:09:28 +00:00
:config
2021-03-08 22:35:03 +00:00
(general-def 'insert vterm-mode-map "C-<escape>" #'vterm-send-escape)
2021-02-22 14:43:04 +00:00
;; Add a hook when vterm changes the directory
(defvar vterm-directory-change-hook nil
"Hooks to be run after vterm changes the directory")
(defun vterm--set-directory (path)
"Set `default-directory' to PATH."
(let ((dir (vterm--get-directory path)))
(when (and dir (eq major-mode 'vterm-mode))
2021-02-22 14:43:04 +00:00
(setq default-directory dir)
(run-hooks 'vterm-directory-change-hook))))
(add-hook 'vterm-mode-hook #'hack-dir-local-variables-non-file-buffer)
(add-hook 'vterm-directory-change-hook #'hack-dir-local-variables-non-file-buffer)
(with-eval-after-load 'consult
(defun vterm-consult-yank-from-kill-ring-action (orig-fun &rest args)
(if (equal major-mode 'vterm-mode)
(let ((inhibit-read-only t)
(yank-undo-function (lambda (_start _end) (vterm-undo))))
(cl-letf (((symbol-function 'insert-for-yank)
(lambda (str) (vterm-send-string str t))))
(apply orig-fun args)))
(apply orig-fun args)))
(defun vterm-disable-consult-preview (orig-fun &rest args)
"Disable Consult previews in vterm buffers. Meant to advise consult--insertion-preview."
(unless (equal major-mode 'vterm-mode)
(apply orig-fun args)))
(advice-add 'consult-yank-from-kill-ring :around #'vterm-consult-yank-from-kill-ring-action)
(advice-add 'consult--insertion-preview :around #'vterm-disable-consult-preview))
(defun vterm-send-password ()
(interactive)
(comint-send-invisible "Enter password: ")
(vterm-send-string "\n")
(clear-this-command-keys))
(defun vterm-edit-zsh-command-line ()
"Edit the current command line in a temp buffer."
(interactive)
2024-03-20 16:03:47 +00:00
(vterm-send "C-x")
(vterm-send "C-e"))
(defun vterm-send-C-g ()
(interactive)
(vterm-send "C-g"))
2021-02-21 13:20:05 +00:00
:general
(leader-map "v" #'vterm)
2024-03-20 16:03:47 +00:00
(vterm-mode-map "C-x C-e" #'vterm-edit-zsh-command-line
"C-c C-g" #'vterm-send-C-g)
((normal motion insert) vterm-mode-map
"C-q" #'vterm-send-next-key)
2021-02-21 21:09:28 +00:00
:custom
2021-03-19 18:29:13 +00:00
(vterm-max-scrollback 10000)
2021-02-21 21:09:28 +00:00
(vterm-environment '("TYPEWRITTEN_CURSOR=terminal"))
(vterm-ignore-blink-cursor t)
2022-04-14 13:18:00 +00:00
(vterm-clear-scrollback-when-clearing t)
(vterm-eval-cmds '(("find-file" find-file)
("ff" find-file)
("message" message)
("vterm-clear-scrollback" vterm-clear-scrollback)
("man" man)
("ediff" ediff))))
2021-02-21 13:20:05 +00:00
(provide 'init-vterm)