Spawn new vterms in vc-root-dir

This commit is contained in:
larstvei 2023-07-29 21:42:29 -07:00
parent 470b6419b1
commit a58bb9c81b

View File

@ -1555,9 +1555,14 @@
** vterm ** vterm
Inspired by [[https://github.com/torenord/.emacs.d][torenord]], I maintain quick access to shell buffers with bindings vterm is a fully capable terminal emulator, and I use it exclusively.
~M-1~ to ~M-9~. In addition, the ~M-z~ toggles between the last visited
shell, and the last visited non-shell buffer. Inspired by [[https://github.com/torenord/.emacs.d][torenord]], I maintain quick access to vterm buffers with bindings
~M-1~ to ~M-9~. In addition, the ~C-z~ toggles between the last visited vterm, and
the last visited non-vterm buffer.
Fresh vterm buffers spawns with the directory given by ~vc-root-dir~ if it
exists and ~default-directory~ otherwise.
#+begin_src emacs-lisp #+begin_src emacs-lisp
@ -1570,11 +1575,12 @@
(defun toggle-vterm (&optional n) (defun toggle-vterm (&optional n)
(interactive) (interactive)
(setq vterms (seq-filter 'buffer-live-p vterms)) (setq vterms (seq-filter 'buffer-live-p vterms))
(cond ((numberp n) (push (vterm n) vterms)) (let ((default-directory (or (vc-root-dir) default-directory)))
((null vterms) (push (vterm 1) vterms)) (cond ((numberp n) (push (vterm n) vterms))
((seq-contains-p vterms (current-buffer)) ((null vterms) (push (vterm 1) vterms))
(switch-to-buffer (car (seq-difference (buffer-list) vterms)))) ((seq-contains-p vterms (current-buffer))
(t (switch-to-buffer (car (seq-intersection (buffer-list) vterms)))))) (switch-to-buffer (car (seq-difference (buffer-list) vterms))))
(t (switch-to-buffer (car (seq-intersection (buffer-list) vterms)))))))
:bind (:map custom-bindings-map :bind (:map custom-bindings-map
("C-z" . toggle-vterm) ("C-z" . toggle-vterm)