netrw formatting bug and improvement and documentation improvement

9 views
Skip to first unread message

Mark Waggoner

unread,
Mar 21, 2022, 2:37:17 PM3/21/22
to vim_dev
I have a small patch, below, for the netrw plugin.
  • I found that the netrw plugin didn't properly recognize the difference between netrw_sizestyle values of "h" and "H" if ignorecase is turned on.  
  • I also prefer to have it format the size with a sometimes consistent width.  I didn't go the the effort to compute how wide it needed to be in the patch below, bit it will make it align better much of the time.   
  • Finally, I added a little bit to the netrw documentation to make the g:netrw_dynamic_maxfilenamelen setting easier to find.

 --- runtime/autoload/netrw.vim        2021-10-13 16:55:56.217948000 -0700
+++ local/share/vim/vim82/autoload/netrw.vim        2022-03-21 11:08:02.071576000 -0700
@@ -12174,34 +12174,34 @@
 fun! s:NetrwHumanReadable(sz)
 "  call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
 
-  if g:netrw_sizestyle == 'h'
+  if g:netrw_sizestyle ==# 'h'
    if a:sz >= 1000000000
-    let sz = printf("%.1f",a:sz/1000000000.0)."g"
+    let sz = printf("%4.1f",a:sz/1000000000.0)."g"
    elseif a:sz >= 10000000
-    let sz = printf("%d",a:sz/1000000)."m"
+    let sz = printf("%4d",a:sz/1000000)."m"
    elseif a:sz >= 1000000
-    let sz = printf("%.1f",a:sz/1000000.0)."m"
+    let sz = printf("%4.1f",a:sz/1000000.0)."m"
    elseif a:sz >= 10000
-    let sz = printf("%d",a:sz/1000)."k"
+    let sz = printf("%4d",a:sz/1000)."k"
    elseif a:sz >= 1000
-    let sz = printf("%.1f",a:sz/1000.0)."k"
+    let sz = printf("%4.1f",a:sz/1000.0)."k"
    else
-    let sz= a:sz
+    let sz= printf("%4d",a:sz) . " "
    endif
 
-  elseif g:netrw_sizestyle == 'H'
+  elseif g:netrw_sizestyle ==# 'H'
    if a:sz >= 1073741824
-    let sz = printf("%.1f",a:sz/1073741824.0)."G"
+    let sz = printf("%4.1f",a:sz/1073741824.0)."G"
    elseif a:sz >= 10485760
-    let sz = printf("%d",a:sz/1048576)."M"
+    let sz = printf("%4d",a:sz/1048576)."M"
    elseif a:sz >= 1048576
-    let sz = printf("%.1f",a:sz/1048576.0)."M"
+    let sz = printf("%4.1f",a:sz/1048576.0)."M"
    elseif a:sz >= 10240
-    let sz = printf("%d",a:sz/1024)."K"
+    let sz = printf("%4d",a:sz/1024)."K"
    elseif a:sz >= 1024
-    let sz = printf("%.1f",a:sz/1024.0)."K"
+    let sz = printf("%4.1f",a:sz/1024.0)."K"
    else
-    let sz= a:sz
+    let sz= printf("%4d",a:sz) . " "
    endif
 
   else
--- runtime/doc/pi_netrw.txt        2022-03-21 11:12:31.791377000 -0700
+++ local/share/vim/vim82/doc/pi_netrw.txt        2022-03-21 11:24:25.756314000 -0700
@@ -1401,6 +1401,7 @@
 <
 Associated setting variables: |g:netrw_liststyle| |g:netrw_maxfilenamelen|
                               |g:netrw_timefmt|   |g:netrw_list_cmd|
+                              |g:netrw_dynamic_maxfilenamelen|
 
 CHANGE FILE PERMISSION                                                *netrw-gp* {{{2
 
@@ -2880,7 +2881,8 @@
                                 If your screen is wider, and you have file
                                 or directory names longer than 32 bytes,
                                 you may set this option to keep listings
-                                columnar.
+                                columnar.
+                                Also see |g:netrw_dynamic_maxfilenamelen|
 
   *g:netrw_mkdir_cmd*                command for making a remote directory
                                 via ssh  (also see |g:netrw_remote_mkdir|)

Reply all
Reply to author
Forward
0 new messages