changeset 145:78176bdfe0be

Add `lawrencium_status_win_maxheight` setting.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 03 Nov 2018 19:01:22 -0700
parents 62af332fbf4a
children 33cc4af93b44
files autoload/lawrencium/status.vim doc/lawrencium.txt plugin/lawrencium.vim
diffstat 3 files changed, 38 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/autoload/lawrencium/status.vim	Sat Nov 03 18:57:53 2018 -0700
+++ b/autoload/lawrencium/status.vim	Sat Nov 03 19:01:22 2018 -0700
@@ -48,11 +48,11 @@
 
     " Open the Lawrencium buffer in a new split window of the right size.
     if g:lawrencium_status_win_split_above
-      execute "keepalt leftabove split " . fnameescape(l:status_path)
+        execute "keepalt leftabove split " . fnameescape(l:status_path)
     else
-      execute "keepalt rightbelow split " . fnameescape(l:status_path)
+        execute "keepalt rightbelow split " . fnameescape(l:status_path)
     endif
-    
+
     if (line('$') == 1 && getline(1) == '')
         " Buffer is empty, which means there are not changes...
         " Quit and display a message.
@@ -65,8 +65,14 @@
 
     execute "setlocal winfixheight"
     if !g:lawrencium_status_win_split_even
-      execute "setlocal winheight=" . (line('$') + 1)
-      execute "resize " . (line('$') + 1)
+        let l:status_win_height = (line('$') + 1)
+        if g:lawrencium_status_win_maxheight > 0
+            let l:status_win_height = min([
+                        \l:status_win_height,
+                        \&lines * g:lawrencium_status_win_maxheight / 100
+                        \])
+        endif
+        execute "resize " . l:status_win_height
     endif
 
     let b:lawrencium_status_type = a:status_type
@@ -137,6 +143,21 @@
     " Just re-edit the buffer, it will reload the contents by calling
     " the matching Mercurial command.
     edit
+
+    " The window might have been resize if something happened (like, say, we
+    " opened a commit message window, and closed it).
+    if g:lawrencium_status_win_split_even
+        execute "resize " . (&lines / 2)
+    else
+        let l:status_win_height = (line('$') + 1)
+        if g:lawrencium_status_win_maxheight > 0
+            let l:status_win_height = min([
+                        \l:status_win_height,
+                        \&lines * g:lawrencium_status_win_maxheight / 100
+                        \])
+        endif
+        execute "resize " . l:status_win_height
+    endif
 endfunction
 
 function! s:HgStatus_Refresh() abort
--- a/doc/lawrencium.txt	Sat Nov 03 18:57:53 2018 -0700
+++ b/doc/lawrencium.txt	Sat Nov 03 19:01:22 2018 -0700
@@ -573,6 +573,14 @@
                         show all modified files.
                         Defaults to `0`.
 
+                                                *lawrencium_status_win_maxheight*
+g:lawrencium_status_win_maxheight
+                        The maxiumum height, in percentage of the Vim window
+                        height, that the |Hgstatus| window is allowed to take.
+                        It will take as much room as needed to show its
+                        contents, up to this limit.
+                        Defaults to `50`.
+
                                                 *lawrencium_record_start_in_working_buffer*
 g:lawrencium_record_start_in_working_buffer
                         If set to 1, |Hgrecord| will leave focus in the
--- a/plugin/lawrencium.vim	Sat Nov 03 18:57:53 2018 -0700
+++ b/plugin/lawrencium.vim	Sat Nov 03 19:01:22 2018 -0700
@@ -49,6 +49,10 @@
     let g:lawrencium_status_win_split_even = 0
 endif
 
+if !exists('g:lawrencium_status_win_maxheight')
+    let g:lawrencium_status_win_maxheight = 50
+endif
+
 if !exists('g:lawrencium_record_start_in_working_buffer')
     let g:lawrencium_record_start_in_working_buffer = 0
 endif