From a49f3c1981b7872ce0a3b6ad4dbb37405ca21dc4 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Thu, 14 Apr 2022 09:31:47 -0400 Subject: [PATCH] Additional vterm improvements: fix consult-yank and add find-file --- emacs/.emacs.d/config/init-vterm.el | 15 +++++++++++++++ zsh/.zshrc | 6 +++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/emacs/.emacs.d/config/init-vterm.el b/emacs/.emacs.d/config/init-vterm.el index 9604f2a..a5e35d2 100644 --- a/emacs/.emacs.d/config/init-vterm.el +++ b/emacs/.emacs.d/config/init-vterm.el @@ -22,6 +22,21 @@ (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)) :general (leader-map "v" #'project-vterm) :custom diff --git a/zsh/.zshrc b/zsh/.zshrc index daf92a7..ede52b5 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -152,13 +152,17 @@ vterm_cmd() { vterm_printf "51;E$vterm_elisp" } +find_file() { + vterm_cmd find-file "$(realpath "${@:-.}")" +} + if [[ "$INSIDE_EMACS" = 'vterm' ]]; then # Completely clear the buffer. With this, everything that is not on screen # is erased. alias clear='vterm_printf "51;Evterm-clear-scrollback";tput clear' alias man='vterm_cmd man' alias ediff='vterm_cmd ediff' - alias ff='vterm_cmd find-file' + alias ff='find_file' fi # This is to change the title of the buffer based on information provided by the