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

Re: What is the best way to distinguish the current buffer is location list or quickfix list?

Expand Messages
  • LCD 47
    ... There is no good way to do that. As a partial workaround, you might try calling getloclist(0), it should return [] if the current buffer is a quickfix
    Message 1 of 2 , Aug 30, 2013
    View Source
    • 0 Attachment
      On 30 August 2013, Kent <kent.yuan@...> wrote:
      > Hi all,
      >
      > I have an autocmd, if ft is qf, it is gonna call some functions to
      > modify the quickfix list by get/setqflist()
      >
      > I know there are another pair of functions get/setloclist(), to handle
      > the location list.
      >
      > My problem is, how to know if the current buffer is qf-list or
      > location-list (They both have filetype qf) so that I know which
      > functions should be called?

      There is no good way to do that. As a partial workaround, you might
      try calling getloclist(0), it should return [] if the current buffer is
      a quickfix list, and something non-empty if it's a loclist. But this
      may or may not work from an autocmd. Also, the filetype of the quickfix
      buffer may be empty at that point if the quickfix has just been created.

      [...]
      > Did I miss some function/flag/variable ?

      Not really. Working with loclists is one of the darker corners of
      Vim, using them for anything else than the built-in make, grep, and
      friends is a huge pain.

      [...]
      > one answer from @romainl suggested using the variable w:quickfix_title.
      > check if the command was beginning with ":l(L)"
      [...]

      That's even less reliable: if you create loclists with setloclist()
      w:quickfix_title can be empty, or ':setloclist()', or something entirely
      different.

      /lcd

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

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Ben Fritz
      ... The only reliable way I ve found, is to store the current window number, then issue a :copen command. If the active window number changes, you were in the
      Message 2 of 2 , Sep 3, 2013
      View Source
      • 0 Attachment
        On Friday, August 30, 2013 4:37:15 PM UTC-5, Kent wrote:
        > Hi all,
        >
        >
        >
        >
        > I have an autocmd, if ft is qf, it is gonna call some functions to modify the quickfix list by get/setqflist()
        >
        >
        > I know there are another pair of functions get/setloclist(), to handle the location list.
        >
        >
        >
        >
        > My problem is, how to know if the current buffer is qf-list or location-list (They both have filetype qf) so that I know which functions should be called?
        >
        >
        > so far what I can think of is, do some change on qf-list, and compare with current buffer, if the current buffer is changed too, it is qf-list, otherwise it should be location list. Finally roll back the changes. But I feel it is stupid... there should be better way to make the decision.
        >
        >
        >
        >
        > the location list and qf list both could be empty or both were filled with data.
        >
        >
        >
        >
        > Did I miss some function/flag/variable ?
        >
        >
        >
        >
        >
        >
        > In fact I've asked the question at SO:
        > http://stackoverflow.com/questions/18522086/what-is-the-best-way-to-distinguish-the-current-buffer-is-location-list-or-quick
        >
        >
        >
        >
        >
        > one answer from @romainl suggested using the variable w:quickfix_title. check if the command was beginning with ":l(L)" after I tested a little there are some cases need to be careful:
        >
        >
        >
        >
        > - the qf/loc list was filled by a script, (using setqflist()/setloclist()), the value of the variable would be the function name. so this could be checked too
        > - if user manually open an empty quickfixlist, e.g. :copen , reading the variable will throw exception. it could be ok too, because it seems that we cannot manually open an empty location list by :lopen.
        >
        >
        >
        >
        > - I don't know if there are other (corner) situations, will break the check.
        >
        >
        >
        >
        > what would be the best way to detect, which list window I am in?
        >
        >
        >
        >
        > thanx in advance
        >
        >
        >
        >
        > Kent

        The only reliable way I've found, is to store the current window number, then issue a :copen command. If the active window number changes, you were in the location list and not the quickfix list. If it doesn't change, you were already in the quickfix list.

        You also want to store the number of open windows, and compare that to the new number of open windows. Then you can close the quickfix window if it wasn't already open.

        Finally you can jump back to the location list (if needed) using the stored window number and "wincmd w".

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

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      Your message has been successfully submitted and would be delivered to recipients shortly.