From 4ddf25b19c40a5652a08e51f854851a8a551ac9b Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Wed, 3 Mar 2021 09:26:58 -0500 Subject: [PATCH] Vterm ediff integration and ability to send ESC sequences --- emacs/.emacs.d/config/init-built-ins.el | 15 ++++++++++++++- emacs/.emacs.d/config/init-vterm.el | 10 ++++++++-- zsh/.zshrc | 14 ++++++++------ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/emacs/.emacs.d/config/init-built-ins.el b/emacs/.emacs.d/config/init-built-ins.el index be73aa2..db9de17 100644 --- a/emacs/.emacs.d/config/init-built-ins.el +++ b/emacs/.emacs.d/config/init-built-ins.el @@ -35,7 +35,20 @@ :defer t :straight (:type built-in) :config - (setq ediff-window-setup-function #'ediff-setup-windows-plain)) + (setq ediff-window-setup-function #'ediff-setup-windows-plain) + (evil-collection-ediff-setup) + + ;; Restore window configuration after an ediff session + (defvar ediff-last-windows nil) + + (defun store-pre-ediff-winconfig () + (setq ediff-last-windows (current-window-configuration))) + + (defun restore-pre-ediff-winconfig () + (set-window-configuration ediff-last-windows)) + + (add-hook 'ediff-before-setup-hook #'store-pre-ediff-winconfig) + (add-hook 'ediff-quit-hook #'restore-pre-ediff-winconfig)) (use-package replace :defer t diff --git a/emacs/.emacs.d/config/init-vterm.el b/emacs/.emacs.d/config/init-vterm.el index 77adafa..927850d 100644 --- a/emacs/.emacs.d/config/init-vterm.el +++ b/emacs/.emacs.d/config/init-vterm.el @@ -8,13 +8,14 @@ (call-interactively #'vterm))) :config (evil-collection-vterm-setup) + (general-def 'insert vterm-mode-map "C-" #'vterm-send-escape) ;; 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 dir + (when (and dir (eq major-mode 'vterm-mode)) (setq default-directory dir) (run-hooks 'vterm-directory-change-hook)))) (add-hook 'vterm-mode-hook #'hack-dir-local-variables-non-file-buffer) @@ -23,6 +24,11 @@ (leader-map "v" #'project-vterm) :custom (vterm-environment '("TYPEWRITTEN_CURSOR=terminal")) - (vterm-ignore-blink-cursor t)) + (vterm-ignore-blink-cursor t) + (vterm-eval-cmds '(("find-file" find-file) + ("message" message) + ("vterm-clear-scrollback" vterm-clear-scrollback) + ("man" man) + ("ediff" ediff)))) (provide 'init-vterm) diff --git a/zsh/.zshrc b/zsh/.zshrc index 1bdd7b9..1ea1601 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -122,12 +122,6 @@ function vterm_printf(){ fi } -# Completely clear the buffer. With this, everything that is not on screen -# is erased. -if [[ "$INSIDE_EMACS" = 'vterm' ]]; then - alias clear='vterm_printf "51;Evterm-clear-scrollback";tput clear' -fi - # With vterm_cmd you can execute Emacs commands directly from the shell. # For example, vterm_cmd message "HI" will print "HI". # To enable new commands, you have to customize Emacs's variable @@ -142,6 +136,14 @@ vterm_cmd() { vterm_printf "51;E$vterm_elisp" } +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' +fi + # This is to change the title of the buffer based on information provided by the # shell. See, http://tldp.org/HOWTO/Xterm-Title-4.html, for the meaning of the # various symbols.