Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treemacs unwanted resizing #376

Closed
Compro-Prasad opened this issue Mar 6, 2019 · 14 comments
Closed

Treemacs unwanted resizing #376

Compro-Prasad opened this issue Mar 6, 2019 · 14 comments

Comments

@Compro-Prasad
Copy link
Contributor

Compro-Prasad commented Mar 6, 2019

Treemacs automatically increases the width of its own window after a which key popup. My which-key popup is shown on the right side.

@Compro-Prasad
Copy link
Contributor Author

Isn't there a hook when a window is resized? We could use that instead.

@Alexander-Miller
Copy link
Owner

Reopening on account of #41

@bk138
Copy link

bk138 commented Aug 7, 2019

My config is affected as well, though the symptoms really are what #41 covers.

@Alexander-Miller
Copy link
Owner

Does this help:

(with-eval-after-load 'which-key

  (defun treemacs--fix-width-after-which-key (func &rest args)
    "Advice to sure treemacs' window size stays put when which-key is active.
Wraps original FUNC + ARGS."
    (let* ((window (treemacs-get-local-window))
           (should-toggle (when window
                            (not (buffer-local-value 'treemacs--width-is-locked
                                                     (window-buffer window))))))
      (when should-toggle
        (with-selected-window window
          (treemacs-toggle-fixed-width)))
      (apply func args)
      (when should-toggle
        (with-selected-window window
          (treemacs-toggle-fixed-width)))))

  (advice-add 'which-key--update :around 'treemacs--fix-width-after-which-key)
  (advice-add 'which-key--hide-popup :around 'treemacs--fix-width-after-which-key))

@bk138
Copy link

bk138 commented Aug 12, 2019

Nope. When unlocking fixed-width and trying to drag the window border, I get:

Error during redisplay: (which-key--hide-popup-on-frame-size-change #<frame emacs@denkpad 0x1203c30>) signaled (wrong-number-of-arguments (lambda (func &rest args) "Advice to sure treemacs' window size stays put when which-key is active.
Wraps original FUNC + ARGS." (let* ((window (treemacs-get-local-window)) (should-toggle (if window (progn (not (buffer-local-value (quote treemacs--width-is-locked) (window-buffer window))))))) (if should-toggle (progn (let ((save-selected-window--state (internal--before-with-selected-window window))) (save-current-buffer (unwind-protect (progn (select-window (car save-selected-window--state) (quote norecord)) (treemacs-toggle-fixed-width)) (internal--after-with-selected-window save-selected-window--state)))))) (apply func args) (if should-toggle (progn (let ((save-selected-window--state (internal--before-with-selected-window window))) (save-current-buffer (unwind-protect (progn (select-window (car save-selected-window--state) (quote norecord)) (treemacs-toggle-fixed-width)) (internal--after-with-selected-window save-selected-window--state)))))))) 0)
Error in pre-command-hook (which-key--hide-popup): (wrong-number-of-arguments (lambda (func &rest args) "Advice to sure treemacs' window size stays put when which-key is active.
Wraps original FUNC + ARGS." (let* ((window (treemacs-get-local-window)) (should-toggle (if window (progn (not (buffer-local-value (quote treemacs--width-is-locked) (window-buffer window))))))) (if should-toggle (progn (let ((save-selected-window--state (internal--before-with-selected-window window))) (save-current-buffer (unwind-protect (progn (select-window (car save-selected-window--state) (quote norecord)) (treemacs-toggle-fixed-width)) (internal--after-with-selected-window save-selected-window--state)))))) (apply func args) (if should-toggle (progn (let ((save-selected-window--state (internal--before-with-selected-window window))) (save-current-buffer (unwind-protect (progn (select-window (car save-selected-window--state) (quote norecord)) (treemacs-toggle-fixed-width)) (internal--after-with-selected-window save-selected-window--state)))))))) 0)
LSP :: Connected to [clangd:24750 status:starting].
[Treemacs] Window width has been unlocked.
user-error: No resizable window on the left of this one [4 times]

This is on GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.4) of 2019-02-03, modified by Debian.

Please let me know what kind of additional info I can provide.

@Alexander-Miller
Copy link
Owner

wrong-number-of-arguments

Weird stuff. My advice for which-key's functions calls them with the very same arguments they'd be called with anyway.

Let's try again. My guess is that the previously defined advice was interfering, so we'll remove that first.

(with-eval-after-load 'which-key

  (advice-remove 'which-key--update 'treemacs--fix-width-after-which-key)
  (advice-remove 'which-key--hide-buffer-side-window 'treemacs--fix-width-after-which-key)

  (defun treemacs--fix-width-after-which-key (func &rest args)
    "Advice to sure treemacs' window size stays put when which-key is active.
  Wraps original FUNC + ARGS."
    (let* ((window (treemacs-get-local-window))
           (should-toggle (and (with-no-warnings (which-key--popup-showing-p))
                               (when window
                                 (not (buffer-local-value 'treemacs--width-is-locked
                                                          (window-buffer window))))))
           (treemacs--no-messages t))
      (when should-toggle
        (with-selected-window window
          (treemacs-toggle-fixed-width)))
      (apply func args)
      (when should-toggle
        (with-selected-window window
          (treemacs-toggle-fixed-width))))

    (advice-add 'which-key--update :around 'treemacs--fix-width-after-which-key)
    (advice-add 'which-key--hide-buffer-side-window :around 'treemacs--fix-width-after-which-key)))

@bk138
Copy link

bk138 commented Aug 13, 2019

No error anymore, but no resize either:

For information about GNU Emacs and the GNU system, type C-h C-a.
[Treemacs] Window width has been unlocked.
LSP :: Connected to [clangd:29301 status:starting].
user-error: No resizable window on the left of this one [54 times]
Mark set

Are you able to repro with my config: https://github.com/bk138/dotfiles/blob/master/.emacs ?

Update:

Your snippet does fix interaction with which-key. I have another package 'dashboard' (https://github.com/emacs-dashboard/emacs-dashboard) which seems to forbid window resizing as well. Shall I open an issue with treemacs or with them?

@Alexander-Miller
Copy link
Owner

All I'm getting up to is setting a single variable that determines whether the width of the treemacs window should be fixed or not. If dashboard.el interferes with that then I think it's on them to look into this.

@bestlem
Copy link

bestlem commented Nov 15, 2019

On Aquamacs this bug with treemacs getting larger with which-key seems to have come back after the 20190814.459 elpa version now on 20191106.2038

I don't remeber seeing this size increase before

@Alexander-Miller
Copy link
Owner

Let's have a look. What do your which-key and treemacs settings look like?

@bestlem
Copy link

bestlem commented Dec 4, 2019

The wonders of HTML cut and past of elisp here removes all < and > to the viewer but they are visible in the edit
I will edit (remove the lines as it failed before without them as they were key bindings) but might have missed some


(use-package which-key
  :ensure t
  :defer 5
  :config (which-key-setup-side-window-right-bottom)
  (setq which-key-sort-order 'which-key-key-order-alpha
        which-key-side-window-max-width 0.33
        which-key-idle-delay 0.05)
  (which-key-mode)
  :diminish which-key-mode)

(use-package treemacs
  :ensure t
  :defer t
  :init
  (with-eval-after-load 'winum
    (define-key winum-keymap (kbd "M-0") #'treemacs-select-window))
  :config
  (progn
    (setq hydra-key-regex "\\[\\|]\\|[-\\[:alnum:] ~.,;:/|?<>={}*+#%@!&^⇧⌘⌥↑↓←→⌫⌦⏎'`()\"$]+?") ; add Mac key symbols

    (setq treemacs-silent-refresh t
          treemacs-persist-file (mwb-user-emacs-file "data/treemacs-persist"))
    (with-eval-after-load 'treemacs
      (add-to-list 'treemacs-pre-file-insert-predicates #'treemacs-is-file-git-ignored?))

    ;; The default width and height of the icons is 22 pixels. If you are
    ;; using a Hi-DPI display, uncomment this to double the icon size.
    ;;(treemacs-resize-icons 44)

    (treemacs-follow-mode t)
    (treemacs-filewatch-mode t)
    (treemacs-fringe-indicator-mode t)
    (pcase (cons (not (null (executable-find "git")))
                 (not (null treemacs-python-executable )))
      (`(t . t)
       (treemacs-git-mode 'deferred))
      (`(t . _)
       (treemacs-git-mode 'simple))))
  :hydra (mwb/hydra-treemacs-mode
          (:color teal)
          ("p" matcha-projectile/body "Projectile")
          ("c" treemacs-add-project-to-workspace "Create Project")
          ("d" treemacs-remove-project-from-workspace "Delete Project")
          ("q" nil "Quit"))
  (mwb/hydra-treemacs-global
   (:color blue)
   ("t" treemacs "Treemacs toggle" :column "Project")
   ("p" mwb/hydra-treemacs-mode/body "Projectile")
   ("0" treemacs-select-window "Select" :column "Other Window")
   ("1" treemacs-delete-other-windows "Delete")
   ("B" treemacs-bookmark "Bookmark" :column "Rest")
   ("f" treemacs-find-file "Find File")
   ("T" treemacs-find-tag "Find Tag"))
  :bind (("H-t" . mwb/hydra-treemacs-global/body)
         ))

@fjl
Copy link

fjl commented May 12, 2020

One thing that tripped me up when trying out treemacs for the first time is that it still honors window-min-width. If this is set, setting the treemacs window size doesn't really work and you can't resize it below this value.

The workaround is to use window-resize with the right ignore parameter in treemacs--set-width.

@Alexander-Miller
Copy link
Owner

Hmm, I had integrated the which-key glue code a long time ago, but forgot about this ticket. And based on #674 the resizing no longer even happens. I think we can safely close this.

@fjl Why shouldn't it honor window-min-width? The default is only 10 columns, if you want less than that you're probably better off just closing treemacs.

@fjl
Copy link

fjl commented May 24, 2020

I added this comment because my window-min-width used to be 80, and that broke treemacs. I've since restructured my config to avoid relying on window-min-width, but still don't see a reason why treemacs should care about it. If you want to avoid crashing emacs with a window that's too small, consider using window-safe-min-width instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants