Loading ...
Sorry, an error occurred while loading the content.
 

detect QuickFix window list or LocationList

Expand Messages
  • 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
    Message 1 of 5 , Oct 31, 2011
      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
    • Tim Chase
      ... (I presume those 2nd mappings should be to prevent overwriting the previous mapping...) A rough (untested) pair of mappings might look something like
      Message 2 of 5 , Oct 31, 2011
        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
      • Andy Wokula
        ... You could check for empty(getloclist(0)) Second approach: always do :lnext and if that fails, try :cnext nnoremap :NextError nnoremap
        Message 3 of 5 , Oct 31, 2011
          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
          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
          Message 4 of 5 , Oct 31, 2011
            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
          • Andy Wokula
            ... Hints on searching: ... the function is mentioned in the 2nd paragraph. ... - first hit -- Andy -- You received this message from the vim_use maillist.
            Message 5 of 5 , Nov 1, 2011
              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
            Your message has been successfully submitted and would be delivered to recipients shortly.