Quantcast

detect QuickFix window list or LocationList

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

detect QuickFix window list or LocationList

chris-2
I want to bind key Alt-n/p to next/previous LocationList or next/previous QuickFix list.
So I need to detect which List in current buffer. then bind Alt-n/p to them.
like this.
    if (detect Location or QuickFix)
        map <A-n> :cnext<CR>
        map <A-n> :cprevious<CR>
    elseif
        map <A-n> :lnext<CR>
        map <A-n> :lprevious<CR>
    endif

--
stardiviner GPG: 5D9F64D8 Twitter: @numbchild
http://stardiviner.dyndns-blog.com/author.html

signature.asc (501 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect QuickFix window list or LocationList

Tim Chase
On 10/31/11 06:14, stardiviner wrote:

> I want to bind key Alt-n/p to next/previous LocationList or next/previous QuickFix list.
> So I need to detect which List in current buffer. then bind Alt-n/p to them.
> like this.
>      if (detect Location or QuickFix)
>          map<A-n>  :cnext<CR>
>          map<A-n>  :cprevious<CR>
>      elseif
>          map<A-n>  :lnext<CR>
>          map<A-n>  :lprevious<CR>
>      endif

(I presume those 2nd mappings should be <A-p> to prevent
overwriting the previous mapping...)

A rough (untested) pair of mappings might look something like

  :nnoremap <expr> <A-n> (&buftype=='quickfix'?':cn':':lnext')."\n"

  :nnoremap <expr> <A-p> (&buftype=='quickfix'?':cp':':lprev')."\n"


Adjust accordingly for your intent regarding the logic.  It might
end up looking something like

 
':'.((&buftype=='quickfix'?'cn':(&buftype=='location'?'lnext':'n'))."\n"

to treat all 3 cases (qf, loc, and other).

-tim


--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect QuickFix window list or LocationList

Andy Wokula
In reply to this post by chris-2
Am 31.10.2011 12:14, schrieb stardiviner:

> I want to bind key Alt-n/p to next/previous LocationList or next/previous QuickFix list.
> So I need to detect which List in current buffer. then bind Alt-n/p to them.
> like this.
>      if (detect Location or QuickFix)
>          map<A-n>  :cnext<CR>
>          map<A-n>  :cprevious<CR>
>      elseif
>          map<A-n>  :lnext<CR>
>          map<A-n>  :lprevious<CR>
>      endif

You could check for
     empty(getloclist(0))


" Second approach: always do :lnext and if that fails, try :cnext

nnoremap <A-n>  :NextError<CR>
nnoremap <A-p>  :PrevError<CR>

com! -bar NextError  call s:GoForError("next")
com! -bar PrevError  call s:GoForError("previous")

func! s:GoForError(partcmd)
     try
         try
             exec "l". a:partcmd
         catch /:E776:/
             " No location list
             exec "c". a:partcmd
         endtry
     catch
         echohl ErrorMsg
         echomsg matchstr(v:exception, ':\zs.*')
         echohl None
     endtry
endfunc

--
Andy

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect QuickFix window list or LocationList

chris-2
Thanks to upper two guys hints. empty(getloclist(0)) is more simple.

Andy Wokula, which one is for QuickFix like getloclist(0), I can not find it even I use many times
Tab.

=> On [2011-10-31 13:50:49 +0100]:
 Andy Wokula Said:

> Am 31.10.2011 12:14, schrieb stardiviner:
> >I want to bind key Alt-n/p to next/previous LocationList or next/previous QuickFix list.
> >So I need to detect which List in current buffer. then bind Alt-n/p to them.
> >like this.
> >     if (detect Location or QuickFix)
> >         map<A-n>  :cnext<CR>
> >         map<A-n>  :cprevious<CR>
> >     elseif
> >         map<A-n>  :lnext<CR>
> >         map<A-n>  :lprevious<CR>
> >     endif
>
> You could check for
>     empty(getloclist(0))
>
>
> " Second approach: always do :lnext and if that fails, try :cnext
>
> nnoremap <A-n>  :NextError<CR>
> nnoremap <A-p>  :PrevError<CR>
>
> com! -bar NextError  call s:GoForError("next")
> com! -bar PrevError  call s:GoForError("previous")
>
> func! s:GoForError(partcmd)
>     try
>         try
>             exec "l". a:partcmd
>         catch /:E776:/
>             " No location list
>             exec "c". a:partcmd
>         endtry
>     catch
>         echohl ErrorMsg
>         echomsg matchstr(v:exception, ':\zs.*')
>         echohl None
>     endtry
> endfunc
>
> --
> Andy
>
> --
> 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
--
stardiviner GPG: 5D9F64D8 Twitter: @numbchild
http://stardiviner.dyndns-blog.com/author.html

signature.asc (501 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: detect QuickFix window list or LocationList

Andy Wokula
Am 01.11.2011 04:30, schrieb stardiviner:
> Thanks to upper two guys hints. empty(getloclist(0)) is more simple.
>
> Andy Wokula, which one is for QuickFix like getloclist(0), I can not find it even I use many times
> Tab.

     :h getqflist()

Hints on searching:

Look for general terms:
     :h quickfix
the function is mentioned in the 2nd paragraph.

Find functions that have to do with quickfix:
     :h eval.txt|/quickfix
-> first hit

--
Andy

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