I have been suffering from two problems with the quickfix functionality. 
The first one is a bug, the second one I would call a usability issue.

1st problem:
- I have a location list with entries relating each to a different file: 
  foo.txt, bar.txt, baz.txt, quux.txt, etc.
- it is possible to get a situation where foo.txt is opened while the 
  location list will highlight baz.txt,
- when I execute ":lnext", bar.txt is opened but the highlighting in the 
  location list will move to quux.txt


2nd problem:
- I have a window with a loaded buffer, this window has its location 
  list window opened,
- I move to the location list window, move to an entry corresponding to 
  another buffer, press enter and the new buffer will open in a new 
  window instead of reusing the one to which the location list is 
  corresponding,
- each of the entries in the location list corresponding to to different 
  buffers will have its own new window opened.

I have a problem with this approach. While normally using ":lnext" is 
the equivalent of entering the location list window, moving the cursor 
to the next line and pressing enter, in this case the behaviour is 
different. What is enough to make this happen is for the buffers to have 
their 'bt' set.
My proposed change here is to always try to reuse the window to which 
the location list window corresponds and only if it is impossible, to 
find another window or to open a new one.

Find attached:
- quickfix1.patch – fixes the 1st problem,
- quickfix2.patch – fixes the 2nd problem,
- problem1.vim – source it to reproduce the 1st problem,
- problem2.vim – source it to reproduce the 2nd problem,
- base.vim – used by problem1.vim and problem2.vim to set up the 
  location list and loading buffer contents.

I will prepare test for quickfix1.patch ASAP.

Before I prepare test for quickfix2.patch I would know if the change 
will be accepted – I don't want to spend my time on something that will 
never be used.

-- 
Lech Lorens

-- 
-- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


" Get the output of ":scriptnames" in the scriptnames_output variable.
let scriptnames_output = ''
redir => scriptnames_output
    silent scriptnames
redir END

" Split the output into lines and parse each line.      Add an entry to the
" "scripts" dictionary.
let scripts = {}
let thisScriptName = substitute(split(scriptnames_output, "\n")[-1],
            \ '\v^.+:\s*', '', '')
let baseScript = substitute(thisScriptName, '\v^(.*)/.*', '\1/base.vim', '')
exe "source " . baseScript



lopen

lnext
lnext
lnext
lnext

vert split
wincmd L
lopen
wincmd p
lnext

" FIXME: why does the location list indicate we're in test://spam.txt but the
" buffer shown in the window is test://bar.txt?!
diff --git a/src/quickfix.c b/src/quickfix.c
index 3ac534d..f3cf9f5 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -1180,7 +1180,10 @@ copy_loclist(from, to)
 	/* When no valid entries are present in the list, qf_ptr points to
 	 * the first item in the list */
 	if (to_qfl->qf_nonevalid)
-	    to_qfl->qf_ptr = to_qfl->qf_start;
+	{
+	    to_qfl->qf_ptr   = to_qfl->qf_start;
+	    to_qfl->qf_index = 1;
+	}
     }
 
     to->w_llist->qf_curlist = qi->qf_curlist;	/* current list */
diff --git a/src/quickfix.c b/src/quickfix.c
index 3ac534d..f3cf9f5 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -1613,6 +1616,8 @@ qf_jump(qi, dir, errornr, forceit)
      */
     if (bt_quickfix(curbuf) && !opened_window)
     {
+	win_T *usable_win_ptr = NULL;
+
 	/*
 	 * If there is no file specified, we don't know where to go.
 	 * But do advance, otherwise ":cn" gets stuck.
@@ -1620,14 +1625,29 @@ qf_jump(qi, dir, errornr, forceit)
 	if (qf_ptr->qf_fnum == 0)
 	    goto theend;
 
-	/* Locate a window showing a normal buffer */
 	usable_win = 0;
-	FOR_ALL_WINDOWS(win)
-	    if (win->w_buffer->b_p_bt[0] == NUL)
-	    {
+	if (curwin->w_llist_ref != NULL)
+	{
+	    /* In a location window - try to find the window with the same
+	     * location list */
+	    ll_ref = curwin->w_llist_ref;
+	    FOR_ALL_WINDOWS(usable_win_ptr)
+		if (usable_win_ptr->w_llist == ll_ref)
+		    break;
+	    if (usable_win_ptr != NULL)
 		usable_win = 1;
-		break;
-	    }
+	}
+
+	if (!usable_win)
+	{
+	    /* Locate a window showing a normal buffer */
+	    FOR_ALL_WINDOWS(win)
+		if (win->w_buffer->b_p_bt[0] == NUL)
+		{
+		    usable_win = 1;
+		    break;
+		}
+	}
 
 	/*
 	 * If no usable window is found and 'switchbuf' contains "usetab"
@@ -1680,12 +1700,8 @@ win_found:
 	    if (curwin->w_llist_ref != NULL)
 	    {
 		/* In a location window */
-		ll_ref = curwin->w_llist_ref;
+		win = usable_win_ptr;
 
-		/* Find the window with the same location list */
-		FOR_ALL_WINDOWS(win)
-		    if (win->w_llist == ll_ref)
-			break;
 		if (win == NULL)
 		{
 		    /* Find the window showing the selected file */
" Get the output of ":scriptnames" in the scriptnames_output variable.
let scriptnames_output = ''
redir => scriptnames_output
    silent scriptnames
redir END

" Split the output into lines and parse each line.      Add an entry to the
" "scripts" dictionary.
let scripts = {}
let thisScriptName = substitute(split(scriptnames_output, "\n")[-1],
            \ '\v^.+:\s*', '', '')
let baseScript = substitute(thisScriptName, '\v^(.*)/.*', '\1/base.vim', '')
exe "source " . baseScript



lopen
finish

exe "normal \<CR>"
wincmd j
2
exe "normal \<CR>"
wincmd j
3
exe "normal \<CR>"
wincmd j
4
exe "normal \<CR>"

" FIXME: why do we have each of the test://*.txt buffers in a separate window?!
function! ReadTestProtocol(name)
        let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
        let word = substitute(base, '\v(.*)\..*', '\1', '')

        setl modifiable
        setl noreadonly
        setl noswapfile
        setl bufhidden=delete
        %del _
        " NOTE: problem 1:
        " 'buftype' has to be set to reproduce the constant opening of new 
windows
        setl buftype=nofile

        call setline(1, word)

        setl nomodified
        setl nomodifiable
        setl readonly
        exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', 
'')
endfunction

augroup testgroup
        au!
        autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
augroup END

let words = [ "foo",
            \ "bar",
            \ "baz",
            \ "quux",
            \ "shmoo",
            \ "spam",
            \ "eggs",
            \ ]

wincmd n
wincmd o


let qflist = []
for word in words
        call add(qflist,
        \        {'filename': 'test://' . word . '.txt',
        \         'text': 'file ' . word . '.txt',
        \        })
        " NOTE: problem 2:
        " intentionally not setting 'lnum' so that the quickfix entries are not
        " valid
        call setloclist(0, qflist, ' ')
endfor

Raspunde prin e-mail lui