Skip to content

Commit 5fb11d1

Browse files
committed
fit lsp-ui-imenu to longest line in buffer
Previously, in buffers with many nested levels of imenu, the long lines would trail off past the width of the window. Now, we properly enlarge the window to fit the longest line.
1 parent 8aa8b17 commit 5fb11d1

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lsp-ui-imenu.el

+16-6
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,22 @@ ITEMS are used when the kind position is `left."
323323
(let ((window-size-fixed)) ;; Temporarily set `window-size-fixed' to nil for resizing.
324324
;; When `lsp-ui-imenu-window-width' is 0, fit window to buffer:
325325
(if (= lsp-ui-imenu-window-width 0)
326-
(let ((fit-window-to-buffer-horizontally 'only))
327-
(fit-window-to-buffer win)
328-
(window-resize win 3 t))
329-
(let ((x (- lsp-ui-imenu-window-width (window-width))))
330-
(window-resize (selected-window) x t))))
331-
)))
326+
(let ((actual-width (if (fboundp 'buffer-line-statistics)
327+
;; since Emacs-28
328+
(cadr (buffer-line-statistics))
329+
(save-excursion
330+
(goto-char (point-min))
331+
(let ((max 0)
332+
(to (point-max)))
333+
(while (< (point) to)
334+
(end-of-line)
335+
(setq max (max max (current-column)))
336+
(forward-line))
337+
max)))))
338+
(enlarge-window-horizontally
339+
(- (1+ actual-width) (window-width win))))
340+
(let ((x (- lsp-ui-imenu-window-width (window-width))))
341+
(window-resize (selected-window) x t)))))))
332342

333343
(defun lsp-ui-imenu--kill nil
334344
"Kill imenu window."

0 commit comments

Comments
 (0)