Here is the latest patch attached which fixes syntax highlighting with
bufhidden=delete and autocommands for BufDelete that can temporarily unload
current buffer (like in plugin dbext).
I added a new field b_p_bkl ('keep loaded') in struct file_buffer to be
used in set_curbuf() to flag close_buffer(prevbuf) not to 'del_buf' or
'wipe_buf' and not to syntax_clear() in buf_freeall().
Cheers, Alexey.
2011/11/18 Alexey Radkov <[email protected]>
> There is no issue with '#' in
>
>
> autocmd BufReadPost * if &modeline == 1 | call dbext#DB_checkModeline() |
> endif
>
> This '#' just triggers further loading of
>
> autocmd BufDelete * if exists('g:loaded_dbext_auto') != 0 | exec 'call
> dbext#DB_auBufDelete( expand("<abuf>") )' | endif
>
> (due to setting g:loaded_dbext_auto drom autoload/dbext.vim). So the
> problem of syntax highlighting disappearance still exists in unloading
> buffer algorithm.
>
> Anyway the latest patch fixes unexpected buffer unloading, and also syntax
> highlighting when closing quickfix window from normal buffer.
>
> Cheers, Alexey.
>
>
> 2011/11/16 Alexey Radkov <[email protected]>
>
>> Here is the latest patch attached where i fixed those segfaults: this was
>> really stupid to me to change first character in a static buffer, i just
>> did not know how b_p_bh was using memory.
>>
>> Syntax also works fine. Except.... You won't believe!
>>
>> I said that i used plugin dbext. It has autogroup commands:
>>
>> augroup dbext
>> au!
>> autocmd BufEnter * if exists('g:loaded_dbext_auto') != 0 | exec
>> "call dbext#DB_setTitle()" | endif
>> autocmd BufReadPost * if &modeline == 1 | call
>> dbext#DB_checkModeline() | endif
>> autocmd BufDelete * if exists('g:loaded_dbext_auto') != 0 | exec
>> 'call dbext#DB_auBufDelete( expand("<abuf>") )' | endif
>> autocmd VimLeavePre * if exists('g:loaded_dbext_auto') != 0 | exec
>> 'call dbext#DB_auVimLeavePre()' | endif
>> augroup END
>>
>> Syntax highlight when switching back from last window in tabpage won't
>> work in this original state. It will work if i remove autocmd BufReadPost.
>> I made some investigations and found that if i use modeline == 0, in which
>> case function dbext#DB_checkModeline() won't be called syntax hl won't work
>> either. Of course i thought that there was something in the vim code that
>> prevented normal work of the syntax when any BufReadPost autocmd had been
>> just declared. But occasionally i found that something like
>>
>> autocmd BufReadPost * if &modeline == 1 | echo "AAA" | endif
>>
>> worked perfectly (e.g. highlighted reverted buffer). Eventually i found
>> that symbol '#' in
>>
>> autocmd BufReadPost * if &modeline == 1 | call
>> dbext#DB_checkModeline() | endif
>>
>> prevents normal loading of the syntax. This is extremely weird. And i
>> even do not want to search what could be the cause of the issue. But of
>> course this smells like a bug.
>>
>> In my dbext plugin i fixed this by simply moving dbext#DB_checkModeline()
>> from autoload to plugin/dbext.vim and renaming it to DB_checkModeline().
>> Now the autocmd is
>>
>> autocmd BufReadPost * if &modeline == 1 | call DB_checkModeline() |
>> endif
>>
>> and all works perfectly, i.e. syntax highlighting is OK and buffer is not
>> unloaded. Also i checked that folds are kept and all the same for quitting
>> from quickfix window.
>>
>>
>> Cheers, Alexey.
>>
>>
>>
>> 2011/11/15 Alexey Radkov <[email protected]>
>>
>>> Thank you all, guys, for response.
>>>
>>> Actually the patch i attached is not perfect: it may lead to segfaults
>>> if bufhidden is empty. Currently i am working on another patch which fixes
>>> the issue, and i am struggling with syntax issue which is not working if
>>> dbext plugin is used because dbext uses additional BufReadPost autocmd
>>> which somehow prevents syntax in buffer where we return from highlighting.
>>> If i remove this single autocmd then syntax works fine. Surprisingly it
>>> does not matter which content of this autocmd is, it only matters the fact
>>> of presence of autocmd itself. Looks weird.
>>>
>>>
>>> 2011/11/15 Thilo Six <[email protected]>
>>>
>>>> Alexey Radkov wrote the following on 14.11.2011 20:41
>>>>
>>>> Hello Alexey,
>>>>
>>>> -- <snip> --
>>>> > You will be returned to the original file, but... Now there is no
>>>> > syntax highlight and ':ls' will show that there is no current buffer!
>>>> > ':ls!' will show that the current buffer is unloaded. Same behaviour
>>>> > can be found when using quickfix window instead tabpage.
>>>> -- <snip> --
>>>>
>>>>
>>>> Thank you for the detailed analysis and the patch. I assume that your
>>>> foundings
>>>> are also related to an issue that i had myself recently without being
>>>> able to
>>>> come to any useful solution.
>>>> http://thread.gmane.org/gmane.editors.vim
>>>> /100772<http://thread.gmane.org/gmane.editors.vim/100772>
>>>>
>>>> --
>>>> Regards,
>>>> Thilo
>>>>
>>>> 4096R/0xC70B1A8F
>>>> 721B 1BA0 095C 1ABA 3FC6 7C18 89A4 A2A0 C70B 1A8F
>>>>
>>>>
>>>> --
>>>> 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 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
diff -r 379a6398d462 src/buffer.c
--- a/src/buffer.c Wed Oct 26 23:48:21 2011 +0200
+++ b/src/buffer.c Fri Nov 18 19:29:47 2011 +0300
@@ -337,19 +337,22 @@
* The caller must take care of NOT deleting/freeing when 'bufhidden' is
* "hide" (otherwise we could never free or delete a buffer).
*/
- if (buf->b_p_bh[0] == 'd') /* 'bufhidden' == "delete" */
+ if (!buf->b_p_bkl)
{
- del_buf = TRUE;
- unload_buf = TRUE;
+ if (buf->b_p_bh[0] == 'd') /* 'bufhidden' == "delete" */
+ {
+ del_buf = TRUE;
+ unload_buf = TRUE;
+ }
+ else if (buf->b_p_bh[0] == 'w') /* 'bufhidden' == "wipe" */
+ {
+ del_buf = TRUE;
+ unload_buf = TRUE;
+ wipe_buf = TRUE;
+ }
+ else if (buf->b_p_bh[0] == 'u') /* 'bufhidden' == "unload" */
+ unload_buf = TRUE;
}
- else if (buf->b_p_bh[0] == 'w') /* 'bufhidden' == "wipe" */
- {
- del_buf = TRUE;
- unload_buf = TRUE;
- wipe_buf = TRUE;
- }
- else if (buf->b_p_bh[0] == 'u') /* 'bufhidden' == "unload" */
- unload_buf = TRUE;
#endif
if (win != NULL)
@@ -599,7 +602,8 @@
u_clearall(buf); /* reset all undo information */
}
#ifdef FEAT_SYN_HL
- syntax_clear(&buf->b_s); /* reset syntax info */
+ if (!buf->b_p_bkl)
+ syntax_clear(&buf->b_s); /* reset syntax info */
#endif
buf->b_flags &= ~BF_READERR; /* a read error is no longer relevant */
}
@@ -1372,10 +1376,13 @@
{
if (prevbuf == curbuf)
u_sync(FALSE);
+ prevbuf->b_p_bkl = TRUE;
close_buffer(prevbuf == curwin->w_buffer ? curwin : NULL, prevbuf,
unload ? action : (action == DOBUF_GOTO
&& !P_HID(prevbuf)
&& !bufIsChanged(prevbuf)) ? DOBUF_UNLOAD : 0);
+ if (buf_valid(prevbuf))
+ prevbuf->b_p_bkl = FALSE;
}
}
#ifdef FEAT_AUTOCMD
@@ -1730,6 +1737,7 @@
clrallmarks(buf); /* clear marks */
fmarks_check_names(buf); /* check file marks for this file */
buf->b_p_bl = (flags & BLN_LISTED) ? TRUE : FALSE; /* init 'buflisted' */
+ buf->b_p_bkl = FALSE;
#ifdef FEAT_AUTOCMD
if (!(flags & BLN_DUMMY))
{
diff -r 379a6398d462 src/structs.h
--- a/src/structs.h Wed Oct 26 23:48:21 2011 +0200
+++ b/src/structs.h Fri Nov 18 19:29:47 2011 +0300
@@ -1466,6 +1466,8 @@
char_u *b_p_bt; /* 'buftype' */
#endif
int b_p_bl; /* 'buflisted' */
+ int b_p_bkl; /* flag to keep some buffer data loaded when
+ * switching to another buffer */
#ifdef FEAT_CINDENT
int b_p_cin; /* 'cindent' */
char_u *b_p_cino; /* 'cinoptions' */
diff -r 379a6398d462 src/window.c
--- a/src/window.c Wed Oct 26 23:48:21 2011 +0200
+++ b/src/window.c Fri Nov 18 19:29:47 2011 +0300
@@ -2309,7 +2309,7 @@
/*
* Close window "win" in tab page "tp", which is not the current tab page.
- * This may be the last window ih that tab page and result in closing the tab,
+ * This may be the last window in that tab page and result in closing the tab,
* thus "tp" may become invalid!
* Caller must check if buffer is hidden and whether the tabline needs to be
* updated.