emacs-lsp / lsp-ui

UI integrations for lsp-mode
https://emacs-lsp.github.io/lsp-ui
GNU General Public License v3.0
1.03k stars 139 forks source link

Lock lsp-ui-imenu window width #543

Closed indigoviolet closed 2 years ago

indigoviolet commented 3 years ago

I wanted to exclude the lsp-ui imenu window from balance-windows etc, so I tried adding a hook to lsp-ui-imenu-mode-hook with (window-preserve (get-buffer-window lsp-ui-imenu-buffer-name) t t), but that didn't work. I had to create a new function like

(defun my/lsp-ui-imenu ()
 (interactive)
 (lsp-ui-imenu)
 (window-preserve (get-buffer-window lsp-ui-imenu-buffer-name) t t)
)

Is this expected? Can it be fixed or made configurable?

yyoncho commented 3 years ago

given the nature of emacs, imho creating such functions when the user wants a particular behaviour is acceptable.

indigoviolet commented 3 years ago

@yyoncho Of course, but my question was really about the hook: why do you think that didn't work? Is it because of when the lsp-ui-imenu-mode is set up, and should that be delayed to the last minute so that the hook would work as expected?

jcs090218 commented 3 years ago

Sorry for the late reply.

Are you using any plugin that may effect the window configuration when you start lsp-ui-imenu? I don't see the balancing behaviour with the default lsp-ui's imenu module. 😕

indigoviolet commented 3 years ago

to be clear, i want to exclude the imenu window from being balanced when i call balance-windows myself, it isn't happening automatically. my question is about why the imenu mode hook is being fired in a way that i can't call window-preserve in the hook.

On Fri, Dec 25, 2020, 10:56 PM Jen-Chieh Shen notifications@github.com wrote:

Sorry for the late reply.

Are you using any plugin that may effect the window configuration when you start lsp-ui-imenu? I don't see the balancing behaviour with the default lsp-ui's imenu module. 😕

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/emacs-lsp/lsp-ui/issues/543#issuecomment-751327262, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA32WVMXJKIPANUX2TUTVDSWWCKPANCNFSM4VIU6H3Q .

jcs090218 commented 3 years ago

Can you tell me where you bind for balance-windows? The hook should work because the hook itself is called after window is created. 😕

DivvyCr commented 2 years ago

I think I'm currently looking into this exact issue - I want to implement some of the treemacs behaviour into the imenu window, which includes making it 'invisible' during balance-windows (alongside making it persistent under delete-other-windows). Hence, my current 'fix' is identical to treemacs' implementation, relying on window-size-fixed:

Set window-size-fixed in the imenu buffer via the major-mode:

(define-derived-mode lsp-ui-imenu-mode special-mode "lsp-ui-imenu"
  "Mode showing imenu entries."
+  ;; The `lsp-ui-imenu' may need to be refreshed to take effect:
+  (setq window-size-fixed (if lsp-ui-imenu-persistent-buffer 'width nil)))

Wrap the resizing logic (on buffer initialisation) in a let statement that temporarily sets window-size-fixed to nil:

+ (let ((window-size-fixed)) ;; Temporarily set `window-size-fixed' to nil.
    ;; When `lsp-ui-imenu-window-width' is 0, fit window to buffer:
    (if (= lsp-ui-imenu-window-width 0)
            (let ((fit-window-to-buffer-horizontally 'only))
              (fit-window-to-buffer win)
              (window-resize win 3 t))
          (let ((x (- lsp-ui-imenu-window-width (window-width))))
            (window-resize (selected-window) x t))))

Note the new variable lsp-ui-imenu-persistent-buffer, which is a boolean that would toggle this behaviour.

This approach also works with lsp-ui-imenu-window-width (ie. apply the specified width, and make it 'permanent'). It may even be worthwhile to make the two inter-dependent.

brotzeit commented 2 years ago

@DivvyCr let's give it a try :+1:

brotzeit commented 2 years ago

Please reopen if it still doesn't work.