0

I'm creating a window at the bottom of the frame with display-buffer-in-side-window and it displays a given buffer, I would like to have another buffer created but re-use that exact same window.

How do I do that? I'm keeping track of the value yield by (get-buffer-window (current-buffer)).

(defvar tortuga-first-open-window nil
  "Track the window of the first shell opened.")


(defun tortuga-shell ()
  "Open the first terminal at the bottom of the frame."
  (interactive)
  (if tortuga-first-open-window
      (set-window-buffer tortuga-first-open-window (tortuga-shell--create-new))
    (select-window
     (display-buffer-in-side-window
      (save-window-excursion
        (tortuga-shell--create-new))
      `((side . bottom)
        (window-height . ,tortuga-first-open-window-height)))))
  (setq tortuga-first-open-window (get-buffer-window (current-buffer))))

(defun tortuga-shell--create-new ()
  "Create a new eshell."
  (interactive)
  (let* ((count (+ 1 (length tortuga-shell-buffer-list)))
         (new-eshell-buffer (get-buffer-create (format "%s<%d>" eshell-buffer-name count))))
    (tortuga-shell-setup new-eshell-buffer)
    (add-to-list 'tortuga-shell-buffer-list new-eshell-buffer)
    new-eshell-buffer))

(defun tortuga-shell-setup (buffer)
  "Setup new buffer BUFFER as eshell buffer."
  (with-current-buffer buffer
    (eshell-mode)
    (add-hook 'kill-buffer-hook #'tortuga-after-kill-buffer nil :local)
    (local-set-key (kbd tortuga-hydra-start-key) 'tortuga-hydra/body)))
4
  • 1
    How about using set-window-buffer? If you create a new buffer, do so in a way that does not display it; and, then use set-window-buffer. – lawlist Mar 27 '20 at 4:58
  • @lawlist I modified my code to use set-window-buffer but is not working, the buffer remains and the new one is created and not displayed in the side window. – shackra Mar 27 '20 at 17:26
  • 1
    Due to the complexity of the display-buffer family of functions, a minimal working example that we can all work with would be very helpful. – lawlist Mar 28 '20 at 4:11
  • @lawlist I have updated my question with the actual code I'm trying. – shackra Mar 28 '20 at 5:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.