Wednesday, March 4, 2015

Bug? (was Re: vimscripting problem w/tabs and expanding width w/numbering option)

Ben Fritz wrote:
> On Sunday, February 8, 2015 at 5:59:28 PM UTC-6, L. A. Walsh wrote:
>> It sorta looks like both tabs are being brought up at the same time and a race condition might be happening, but the fact that it
>> is very deterministic, leads me to believe something else is going on.
> ----
> It can't be a race condition. Vim is single-threaded and will be processing one whole function at a time.
----
Actually, it is a type of race condition, in that only the 1st
tab initialized/read in, gets the benefit of the function expanding
the columns. I'm not sure how to have the function called for
each tab as it is initialized (no ".vimtabrc" ;-)?)...

I tried using 'tab-specific' vars: i.e.:

func! SetNumberAndWidth()
set number
if (! exists("t:added_numwth")) | let t:added_numwth=0 | endif
if (t:added_numwth < &numberwidth)
let t:added_numwth = &numberwidth
let &columns = 2 + t:added_numwth + &columns
endif
endf
if !exists("t:autocommands_loaded")
let t:autocommands_loaded =1
au BufReadPost * let ln = line("'\"") | if
search("vim=:SetNumberAndWidth",'n') | call SetNumberAndWidth() | endif
endif


But same problem. As the code above only is called when gvim
starts -- not for each tab.

---------------
I figured this much out by using ":echo winwidth(0)"
(the 1st tab gets the enlarged value, the remaining tabs still have
the original width (of 80, usually).

I thought about trying to "loop" through the tabs, but when
the 1st file is opened and processed, it is likely they others
aren't opened or processed yet (as you said, vim is single threaded).


Is there a way to have the function executed once/tab (not once/
buffer -- as that would seem to 're-exec' the function with every
new buffer opened.


>> I thought g: vars were 'global across all buffs, but this seems
>> to be behaving like g:added_numwth (*or*) &columns are not in-sync
>> between the tabs? Is that what is happening or am I missing some
>> simpler explanation?
>
> g: vars are global across all buffers, tabs, and windows just as you expect. 'columns' is also a global option so it will always be in sync between tabs.
>
> I don't know of a simpler explanation for what you're seeing, but it's not due to you use of g: variables or tab pages, as far as I can tell.
----
I would need something like a ".vimtabrc", but realistically,
since &columns is a global then the problem seems to be
the 2nd tab isn't getting it's "winwidth" set correctly to the #
of columns as set in ".gvimrc".

NOTE: background tabs *DO* get their winwidth reset when one
resizes the 1st tab manually -- so the behavior is such that
background tabs' winwidth's == the current physical size when
it is reset. But that's not happening if the size is reset
via .gvimrc.

Horrible idea: (which probably wouldn't work anyway) due to
restrictions on init scripts -- but -- that would be to
do something like:

:!kill -SIGWINCH $PPID

in the column resizing function.... but that's just *evil*, even
by my standards! ;-)

FWIW -- same behavior in my linux 7.3.831 & windows 7.3.480





--
--
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

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

No comments: