anler / centered-window-mode

Keep your text centered when there's only one window.
142 stars 12 forks source link

Splitting windows vertically doesn't work #12

Open sondr3 opened 8 years ago

sondr3 commented 8 years ago

Hello, this does everything I want for my purposes, however, it refuses to split up windows. I use Evil so I do C-w v to split my window vertically but get the following error message: split-window: Window #<window 3 on emacs.org> too small for splitting (2) [2 times]. However splitting horizontally works just fine. Any ideas why?

I'm using the Emacs 25.1 on OS X El Capitan.

anler commented 8 years ago

I'll take a look asap.

wagk commented 7 years ago

I'm facing the same problem, however, it appears that the issue does not affect M-x split-windows-horizontally

My current workaround until this is fixed is to put (evil-ex-define-cmd "vsp[lit]" 'split-window-horizontally) inside the evil config

An issue with this solution is that now the split windows are both centered. Toggling centered-window-mode does not fix this, but oddly does if the toggling is done in a frame where there are no splits.

anler commented 7 years ago

Hi, I pushed a new version that hopefully will fix this issue.

xiongtx commented 7 years ago

Issue doesn't seem to be fixed with latest build.

Backtrace

When calling split-window-right:

Debugger entered--Lisp error: (error "Window #<window 369 on centered-window-mode.el> too small for splitting")
  signal(error ("Window #<window 369 on centered-window-mode.el> too small for splitting"))
  error("Window %s too small for splitting" #<window 369 on centered-window-mode.el>)
  split-window(nil nil t)
  split-window-right(nil)
  funcall-interactively(split-window-right nil)
  call-interactively(split-window-right nil nil)
  command-execute(split-window-right)

Environment

anler commented 7 years ago

I'm working on it, thanks for reporting it!

xiongtx commented 7 years ago

@Wagk Are you sure you've having problems splitting windows vertically and not horizontally?

split-window-horizontally:

+---------------+     +-------+-------+
|               |     |       |       |
|               | --> |       |       |
|               |     |       |       |
+---------------+     +-------+-------+

split-window-vertically:

+---------------+     +---------------+
|               |     |               |
|               | --> +---------------+
|               |     |               |
+---------------+     +---------------+

Fringes are on the left and right, so the trouble should be with splitting horizontally, not vertically. That's what I'm experiencing.

wagk commented 7 years ago

@xiongtx Yes I believe split-window-horizontal was the one causing the issue. Apologies

xiongtx commented 7 years ago

@anler It may be worth taking a look at writeroom-mode /visual-fill-column, which also center the window but don't have this splitting problem, for ideas on how to deal with this issue.

I haven't dug too deeply into how they do things, but one thing I see is that they use margins instead of fringes to center the window.

anler commented 7 years ago

Hi all, I haven't forgotten about this, but I'm going to merge #21 first, I'm using it and haven't had this issue since, but still is not a definitive solution. Thanks!

wyuenho commented 7 years ago

I just tried out #21, I had to set cwm-frame-internal-border to 0 to avoid having the mode line and the minibuffer being rendered off screen. My window were also only able to be split horizontally once. C-x 3 C-x 1 C-x 3 will still get me the window too small warning.

wyuenho commented 6 years ago

@anler I think this is due to https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24193,

Olivetti had the same problem and they hacked around it. Maybe you can do something similar? I love this mode since this is the only lightroom mode clone that works with linum.

anler commented 6 years ago

I'll take a look later today, thanks!

wyuenho commented 6 years ago

So, using https://github.com/railwaycat/homebrew-emacsmacport, setting fullscreen frame parameter to maximized with (set-frame-parameter nil 'fullscreen 'maximized), C-x 3 RET C-x 1 RET C-x 3 doesn't work. But if I maximize the frame with (toggle-max-frame 'both), splitting windows now works. This is just weird.

cnngimenez commented 2 weeks ago

Hi!

It seems that the error is triggered at Line 5544 on window.el file. It seems that split-window make some calculations to check if the splitting is possible. If I understand the code right, it calculates the new window minimum size (it considers the frame divider size too) , and if this size is not available, it triggers the error message. Maybe the frame divider value is too high? 🤔

As a temporary solution I tried to advise the split-window function to disable and re-enable the centered-window-mode.

(defun my-cwm-turn-off (fnc &optional window size side pixelwise)
  "Deactivate the centered-window-mode before splitting."
  (if centered-window-mode
      (progn
        (centered-window-mode -1)
        (apply fnc window size side pixelwise)
        (centered-window-mode t))
    (apply fnc window size side pixelwise)))

(advice-add 'split-window :around #'my-cwm-turn-off)

This works in my Emacs... but maybe there is a better solution for this? 🤔

krisbalintona commented 1 week ago

As an FYI I think this is a more universal solution (i.e. one that works regardless of what function/command is doing the splitting):

(defun kb/window-splittable-p (window &optional horizontal)
    "Override for `window-splittable-p'.
Determine if WINDOW is splittable."
    (when (and (window-live-p window)
               (not (window-parameter window 'window-side)))
      (with-current-buffer (window-buffer window)
        (if horizontal
            (and (memq window-size-fixed '(nil height))
                 (numberp split-width-threshold)
                 (>= (if (bound-and-true-p centered-window-mode)
                         ;; Added this. Not sure if this is foolproof, since all
                         ;; it does is take into consideration the margins and
                         ;; fringes, but for now it's a sufficient approximation
                         (window-total-width window)
                       (window-width window))
                     (max split-width-threshold
                          (* 2 (max window-min-width 2)))))
          (and (memq window-size-fixed '(nil width))
               (numberp split-height-threshold)
               (>= (window-height window)
                   (max split-height-threshold
                        (* 2 (max window-min-height
                                  (if mode-line-format 2 1))))))))))
(advice-add 'window-splittable-p :override #'kb/window-splittable-p)