On Fri, Mar 16, 2012 at 01:16, Benjamin R. Haskell <[email protected]> wrote:
> There are at least two things going on:
>
> 1. items in an 'stl' %{} group are expanded. So, if you ever return a line
> that contains a '%', you'll have trouble. I worked around this by renaming
> your function from WhatFunctionAreWeIn to RawWhatFunctionAreWeIn, then
> creating:
>
> fun! WhatFunctionAreWeIn()
> let stl=RawWhatFunctionAreWeIn()
> let stl=substitute(stl, '\t', ' ', 'g') " tabs don't show up right
> let stl=substitute(stl, '%', '%%', 'g') " need to escape %'s
> return stl
> endfun
>
Thanks. I suppose that actually wrapping the function to escape the
output is preferable to escaping on the return of the function, as it
will allow the reuse of the function for other places (such as GVIM
might provide the titlebar).
> 2. The :help for 'stl' states that you shouldn't change text or jump to
> another window. (See :help textlock).
>
Thanks. My major issue right now is knowing where in the fine manual
to poke around.
> But, even more strongly, you *probably* shouldn't move the cursor in a
> function called from 'stl'. When your function calls [{ to find the prior
> block, it moves the displayed text. That's what causes the jump. The
> problem is that the sequence of events for updating the displayed text seems
> to vary for different types of movement. I was unable to trigger the bug
> with <C-d> and <C-u> movement, for example. But, I could pretty
> consistently trigger it (when viewing Vim help files) by rapidly using 'k'
> to move up a single line.
>
I see. thanks.
> Here's a much simpler function for what you're trying to do (also more
> naïve, but it's a trade-off):
>
> " still used in the same way:
> " e.g.: set statusline+=%{WhatFunctionAreWeIn()}
>
> fun! StatusLineSafe(txt)
> let stl = a:txt
> let stl = substitute(stl, '\t', ' ', 'g') " tabs don't show up right
> let stl = substitute(stl, '%', '%%', 'g') " need to escape %'s
> return stl
> endfun
>
> fun! WhatFunctionAreWeIn()
> let strList = ['function', 'class']
> let lnum = line('.') - 1
> while lnum > 0
> let line = getline(lnum)
> let lnum -= 1
> if line =~ '^\s*#' " simple improvement to skip comments
> continue
> endif
> for item in strList
> let position = match(line, '\<'.item.'\>')
> if position >= 0
> break
> endif
> endfor
> if position >= 0
> return StatusLineSafe("[line ".(lnum+1)."] ".line)
> endif
> endwhile
> return '' " return empty string if it's unknown
> endfun
>
Thank you Ben! There is much in there that I have to examine in more
detail. I do have a working solution that was concocted in the linked
StackOverflow page, but there certainly is much in your code that I
can learn from. I will spend some time pouring over it. I appreciate
your help and your willingness to teach.
Have a peaceful night. Thank you.
--
Dotan Cohen
http://gibberish.co.il
http://what-is-what.com
--
You received this message from the "vim_use" 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