Hello dear Vim developers and Dr Chip,

let me introduce my improvements to the great Dr Chip's StlShowFunc plugin:
Showing Current Function Name in Status Line
(http://www.drchip.org/astronaut/vim/index.html#STLSHOWFUNC).

It's about shell support:
- add POSIX-style shell functions definition support:
    func_name () { ... }
- optimized function name search algorithm which runs _much_ faster
    (I can share "profiling" method I used)
- overall cleanup

Your feedback is welcome!

Unfortunately, last time I tried to connect Dr Chip directly, I got no
response.
Dr Chip, if you read this, I would love to get reply from you.
Otherwise, I think I should publish this somewhere so my efforts didn't
lost.

Hope someone finds it useful!
Thanks


patch -p0 --ignore-whitespace --dry-run << 'HEAD'
--- .vim/ftplugin/sh/StlShowFunc_sh.vim.orig 2019-01-26 22:12:57.000000000 +0300
+++ .vim/ftplugin/sh/StlShowFunc_sh.vim      2019-02-07 23:24:25.500940209 +0300
@@ -18,69 +18,42 @@
 " StlShowFunc_sh: show function name associated with the line under the cursor 
{{{1
 "DechoTabOn
 fun! StlShowFunc_sh()
-"  call Dfunc("StlShowFunc_sh() line#".line(".")." mode=".mode())
-  if mode() != 'n'
-"   call Dret("StlShowFunc_sh")
-   return
-  endif
-
-  if !exists("b:shshowfunc_bgn")
-   let b:shshowfunc_bgn= -2
-   let b:shshowfunc_end= -2
-  endif
-
+"  call Dfunc("StlShowFunc_sh() line#" . line(".") . " mode=" . mode())
   let curlinenum = line(".")
-  let swp        = SaveWinPosn(0)
-  if getline(".") =~ '^\s*function\>'
-   let bgnfuncline = line(".")
-  else
-   sil! keepj let bgnfuncline= search('^\s*function\>','bW')
-  endif
-"  call Decho("preliminary bgnfuncline=".bgnfuncline)
-  if bgnfuncline > 0
-   sil! keepj let shfuncstart= search('^\s*{','W')
-   if shfuncstart != 0
-       sil! keepj let endfuncline= searchpair('{','','}',"Wn")
-       if endfuncline <= 0
-        let bgnfuncline= 0
-       endif
-   else
-       let bgnfuncline = 0
-       let endfuncline = 0
-   endif
-  else
-   let bgnfuncline= 0
-   let endfuncline= 0
-  endif
-  if curlinenum < bgnfuncline || endfuncline < curlinenum
-   let bgnfuncline= 0
-   let endfuncline= 0
-  endif
-  call RestoreWinPosn(swp)
-"  call Decho("previous bgn,end[".b:shshowfunc_bgn.",".b:shshowfunc_end."]")
-"  call Decho("current  bgn,end[".bgnfuncline.",".endfuncline."]")
 
-  if bgnfuncline == b:shshowfunc_bgn && endfuncline == b:shshowfunc_end
+  if   mode() != 'n'
+  \ || exists("b:bgn_range{winnr()}") && exists("b:end_range{winnr()}")
+  \ && b:bgn_range{winnr()} <= curlinenum && curlinenum <= b:end_range{winnr()}
    " looks like we're in the same region -- no change
 "   call Dret("StlShowFunc_sh : no change")
    return
   endif
 
-  let b:shshowfunc_bgn = bgnfuncline
-  let b:shshowfunc_end = endfuncline
-  let endprvfuncline     = search('^}$','Wbn')
-"  call Decho("endprvfuncline=".endprvfuncline)
-
-  if bgnfuncline < endprvfuncline || (endprvfuncline == 0 && bgnfuncline == 0)
-   call StlSetFunc("")
-  else
-   let funcline= getline(bgnfuncline)
-   if funcline =~ '^\s*function\s*\h\w*'
-       let funcname= 
substitute(funcline,'^\s*function\s*\(\h\w*\).\{-}$','\1','')
-"    call Decho("funcname<".funcname.">")
-    call StlSetFunc(funcname."()")
+  let swp = SaveWinPosn(0)
+  let bgnfuncline = search('^\s*\h\w*\s*()[[:blank:]\n]*{','bWc')
+  let b:bgn_range{winnr()} = bgnfuncline
+"  call Decho("preliminary bgnfuncline=" . bgnfuncline)
+  if bgnfuncline
+   call search('{','W')
+   let endfuncline = searchpair('{','','}',"Wn")
+   if endfuncline < curlinenum
+    let bgnfuncline = 0
+    if endfuncline
+     let b:bgn_range{winnr()} = endfuncline + 1
+    endif
+    let endfuncline = search('^\s*\h\w*\s*()[[:blank:]\n]*{','Wn')
+    let b:end_range{winnr()} = endfuncline ? endfuncline - 1 : line('$')
+   else
+    let b:end_range{winnr()} = endfuncline
    endif
+  else
+   let endfuncline = search('^\s*\h\w*\s*()[[:blank:]\n]*{','Wn')
+   let b:end_range{winnr()} = endfuncline ? endfuncline - 1 : line('$')
   endif
+  call RestoreWinPosn(swp)
+"  call Decho("current  bgn,end[" . b:bgn_range{winnr()} . "," . 
b:end_range{winnr()} . "]")
+
+  call StlSetFunc( bgnfuncline ? substitute(getline(bgnfuncline), 
'^\s*\(\h\w*\).*$', '\1', '') : '' )
 
   " set the status line and return
 "  call Dret("StlShowFunc_sh")

HEAD

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui