'switchbuf' "usetab" misbehaviour, incorrect title for the location list window

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

'switchbuf' "usetab" misbehaviour, incorrect title for the location list window

Lech Lorens
The attached patch fixes the misbehaviour of vim when 'switchbuf' is set
to "usetab". Also the location list window is not incorrectly described
as quickfix window any more.
To reproduce the problems perform the following steps:
Create a file "file.txt" containing the string "foo".
Open Vim: vim -p file.txt file.txt file.txt. Execute:
:autocmd TabEnter * call PrintTabNr()
:function! PrintTabNr()
:    echomsg "Entering tab number " . tabpagenr()
:endfunction
:set switchbuf=usetab
:lgrep foo file.txt
:lopen

At this moment observe that the location list window incorrectly has the
title "[Quickfix list]" instead of "[Location list]". Execute:
:wincmd k
:q

Press <Enter>. Observe that tab 3 becomes the current tab instead of
tab 2. Execute:
:messages

You see:
> Entering tab number 2
> Entering tab number 3
which means that both tabs were entered.

The reason for this behaviour: macro FOR_ALL_TAB_WINDOWS, which consists
of two nested loops, is used for iterating over each window. When the
correct window is found, a "break" is performed, which only breaks the
inner loop. Solution: break out of both loops.

--
Cheers,
Lech

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Index: src/buffer.c
===================================================================
--- src/buffer.c (revision 1356)
+++ src/buffer.c (working copy)
@@ -5098,7 +5098,8 @@
  */
  FOR_ALL_TAB_WINDOWS(tp, win)
     if (win->w_buffer == buf)
- break;
+ goto window_found;
+window_found:
  if (win != NULL && win->w_llist_ref != NULL)
     return _("[Location List]");
  else
Index: src/quickfix.c
===================================================================
--- src/quickfix.c (revision 1356)
+++ src/quickfix.c (working copy)
@@ -1610,11 +1610,12 @@
  {
     goto_tabpage_win(tp, wp);
     usable_win = 1;
-    break;
+    goto window_found;
  }
     }
  }
 
+window_found:
  /*
  * If there is only one window and it is the quickfix window, create a
  * new one above the quickfix window.
Index: src/screen.c
===================================================================
--- src/screen.c (revision 1356)
+++ src/screen.c (working copy)
@@ -7448,11 +7448,12 @@
  {
     outofmem = TRUE;
 #ifdef FEAT_WINDOWS
-    break;
+    goto try_no_more;
 #endif
  }
     }
 
+try_no_more:
 #ifdef FEAT_MBYTE
     for (i = 0; i < p_mco; ++i)
  if (new_ScreenLinesC[i] == NULL)