]> gitweb.fluxo.info Git - rhatto/dotfiles/vim.git/commitdiff
Fix: additional session workarounds
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 28 Jul 2024 14:35:27 +0000 (11:35 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 28 Jul 2024 14:35:27 +0000 (11:35 -0300)
vim.dot.link/plugin/nerdtree_workarounds.vim

index a78ed0c38ca7918723157f06ff2e1ee9be564c59..60e4a1c5c4888376c4211f340e57d323454ac975 100644 (file)
@@ -3,15 +3,6 @@
 " Author: Silvio Rhatto <rhatto@riseup.net>
 "
 
-" Ensure the window has maximized height
-"
-" This helps restoring the window size after reopening sessions after
-" switching monitors (like from laptop screen to external HDMI monitor).
-"
-" https://superuser.com/questions/140419/how-to-start-gvim-maximized
-" https://vim.fandom.com/wiki/Maximize_or_set_initial_window_size
-set lines=999
-
 " Fix NERDTree width
 "
 " Useful after restoring sessions between screen size changes (such
@@ -51,11 +42,49 @@ function FixAllNERDTreeWidths()
   let dir_fixed_nerdtree_widths=1
 endfunction
 
-" Fix all NERDTree widths afert session load
+" Ensure the window has maximized height
+"
+" This helps restoring the window size after reopening sessions after
+" switching monitors (like from laptop screen to external HDMI monitor).
+"
+" We just want to quickly maximize the window and then restore it to
+" it's original size, to ensure all windows are refreshed.
+"
+" Maybe this is not a NERDTree workaround itself, but more like a
+" session workaround.
+"
+" https://superuser.com/questions/140419/how-to-start-gvim-maximized
+" https://vim.fandom.com/wiki/Maximize_or_set_initial_window_size
+"let lines_initial=&l:lines
+function FixWindowHeights()
+    " Set the maximum available height
+    set lines=999
+
+    " Set the lines depending on the LINES environment variable
+    " or through tput.
+    if $LINES != ""
+        execute ':set lines=' . $LINES
+    else
+        let available_lines = system('tput lines')
+        execute ':set lines=' . available_lines
+    " Old, and not working approach that tries to reuse the initial height
+    "else
+    "    execute ':set lines=' . lines_initial
+    "    set lines=999
+    "    execute ':set lines=' . winheight(0) - 3
+    endif
+endfunction
+
+function RestoreWindowSizes()
+  call FixWindowHeights()
+  call FixAllNERDTreeWidths()
+endfunction
+
+" Fix all window sizes
 augroup workaround
   autocmd!
   " This tends to fire for every buffer
-  autocmd workaround SessionLoadPost * call FixAllNERDTreeWidths()
+  autocmd workaround SessionLoadPost * call RestoreWindowSizes()
 
   " This seems to fire only once, but even when there's no session to be
   " restored.