jixiuf / vterm-toggle

toggles between the vterm buffer and whatever buffer you are editing.
GNU General Public License v3.0
188 stars 12 forks source link

Vterm not opening on the bottom. #33

Closed apoorv569 closed 2 years ago

apoorv569 commented 3 years ago

I added the code from the README for showing vterm buffer in bottom side, but whenever I run vterm-toggle it always opens on the right.

Here is my vterm configuration,

  (use-package vterm
    :straight t
    :commands vterm
    :config
    (setq vterm-max-scrollback 10000))
  (use-package vterm-toggle
    :straight t
    :custom
    (vterm-toggle-reset-window-configration-after-exit t))
  (setq vterm-toggle-fullscreen-p nil)
  (add-to-list 'display-buffer-alist
               '((lambda(bufname _) (with-current-buffer bufname (equal major-mode 'vterm-mode)))
                 (display-buffer-reuse-window display-buffer-at-bottom)
                 ;;(display-buffer-reuse-window display-buffer-in-direction)
                 ;;display-buffer-in-direction/direction/dedicated is added in emacs27
                 ;;(direction . bottom)
                 ;;(dedicated . t) ;dedicated is supported in emacs27
                 (reusable-frames . visible)
                 (window-height . 0.3)))

What am I doing wrong here?

Ergus commented 3 years ago

This is somehow related:

From the Help I get:

(display-buffer-reuse-window BUFFER ALIST) it received 3 arguments, not 2.

I have observed that it does not open at bottom when the windows is to wide; in small screens it behaves as expected.

apoorv569 commented 3 years ago

This is somehow related:

From the Help I get:

(display-buffer-reuse-window BUFFER ALIST) it received 3 arguments, not 2.

I have observed that it does not open at bottom when the windows is to wide; in small screens it behaves as expected.

I see, I do have an ultrawide monitor, maybe this is the issue. I also have the configuration on my laptop, and it always open vterm on bottom.

So there is no fix for this?

luiznux commented 2 years ago

Before the last commit, vterm-toggle was working well for me(I also have a big monitor). With the recent version, vterm-toggle simply cant stay at bottom but in small window it works fine. Anyone have some suggestions to fix that ?

ianyepan commented 2 years ago

I am also getting this issue. Except it opens on the right "only" when it's the first time. If I toggle it hidden and shown again, it'll be at the bottom (as I wanted).

kriansa commented 2 years ago

That happens because at the first time the vterm buffer is created, its major mode is still 'fundamental-mode, and your display-buffer-alist is set to act only when major mode is 'vterm-mode, so it won't run at the first time because vterm-toggle hasn't turned it into a vterm yet.

On the later runs that callback will run and set your window to the right specs.

A quick fix is relying on bufname instead of major-mode:

(add-to-list 'display-buffer-alist
    '((lambda (bufname _) (equal bufname vterm-buffer-name))
       (display-buffer-reuse-window display-buffer-in-direction)
       (direction . bottom)
       (dedicated . t)
       (reusable-frames . visible)
       (window-height . 0.3)))
Ergus commented 2 years ago

At the end I made it simpler... not fully functional yet, but good enough

(add-to-list 'display-buffer-alist `(,vterm-buffer-name display-buffer-at-bottom))

But this should also work:

(add-to-list 'display-buffer-alist `(,vterm-buffer-name
                       (display-buffer-reuse-window display-buffer-at-bottom)
                       (dedicated . t)
                       (reusable-frames . visible)
                       (window-height . 0.3)))
kriansa commented 2 years ago

@jixiuf thanks for updating the readme! It works flawlessly most of the time, however, if you happen to use vterm-toggle-scope 'project then you might end up with multiple vterm buffers, and they are named sequentially like Term<1>, Term<2> and so on.

Another quickfix for that is simply comparing the bufname prefix with vterm-buffer-name instead, like so:

(lambda (bufname _) (with-current-buffer bufname
                            (or (equal major-mode 'vterm-mode)
                              (string-prefix-p vterm-buffer-name bufname))))

I'm not sure if that's the best alternative to avoid any false positives, but for me it works fine at least.