fix(vterm): +vterm/toggle creating duplicates

If vterm-buffer-name-string is set to non-nil, then vterm will rename
the buffer after it is initialized. Since +vterm/toggle looks up buffers
by name, it will lose track of them, causing it to create a new one on
each invocation. With this, it will no longer lose track of them.

Fix: #6651
This commit is contained in:
Henrik Lissner 2022-08-09 17:18:35 +02:00
parent 4cf5ae8be1
commit a0a4aa81c1
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -1,5 +1,7 @@
;;; term/vterm/autoload.el -*- lexical-binding: t; -*-
(defvar +vterm--id nil)
;;;###autoload
(defun +vterm/toggle (arg)
"Toggles a terminal popup window at project root.
@ -27,8 +29,13 @@ Returns the vterm buffer."
(delete-window window))))
(if-let (win (get-buffer-window buffer-name))
(delete-window win)
(let ((buffer (get-buffer-create buffer-name)))
(let ((buffer (or (cl-loop for buf in (doom-buffers-in-mode 'vterm-mode)
if (equal (buffer-local-value '+vterm--id buf)
buffer-name)
return buf)
(get-buffer-create buffer-name))))
(with-current-buffer buffer
(setq-local +vterm--id buffer-name)
(unless (eq major-mode 'vterm-mode)
(vterm-mode)))
(pop-to-buffer buffer)))