1

I'm trying to enable/disable visual-fill-column when there is one window/multiple windows.

Since I don't like trying it on my own before asking, here is the solution I came up with:

(defun my-visual-fill-one-window ()
  (global-visual-fill-column-mode -1)
  (if (one-window-p)
      (global-visual-fill-column-mode 1)
    (global-visual-fill-column-mode -1)
    )
  )

(add-hook 'window-state-change-hook 'my-visual-fill-one-window)

I have three problems (maybe more but these are the three I could identify):

  • Problem 1

    I need to disable the mode globally at the start of the function because if I don't and try to split one window horizontally I have the following error (strangely, I don't have it if I M-x visual-fill-column-mode manually and split the window without having this function hooked):

    split-window: Window #<window 3 on file> too small for splitting

  • Problem 2

    Treemacs stops working (I can't open its window) with the following error:

    treemacs--popup-window: Wrong type argument: window-live-p, nil

  • Problem 3

    I'm hooking it to window-state-changed-hook because it looked like the most suited one but maybe I could do better (the main problem being that if I use ivy-posframe it's considered as a second window, the mode is disabled, the text is instantly flushed to the left and as soon as the posframe is closed the mode is enabled again and the text centered)

Do you have a better solution (and possibly one that doesn't make treemacs fail miserabily)?

[EDIT]

There's actually another question: is it possible to enable this mode if there's more than one window but they're all split vertically?

2
  • Only one question per question, please. Please remove all but one problem/question. Pose the others separately. Thx. – Drew Jan 15 at 18:23
  • Done here here, here and here – Lhooq Jan 16 at 10:57

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.