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

Re: Hidden buffers

Expand Messages
  • LCD 47
    ... [...] Switching to the said buffer makes it unhidden, which is less than useful. :) ... [...] This was the first thing I tried, but it doesn t work
    Message 1 of 7 , Apr 7, 2013
    • 0 Attachment
      On 6 April 2013, tooth pik <toothpik6@...> wrote:
      > On Sat, Apr 06, 2013 at 10:48:37PM +0300, LCD 47 wrote:
      > > Given a buffer number, is it possible to find out (in Vimscript)
      > > whether the corresponding buffer is hidden or not?
      >
      > you can change to said buffer with the buffer command
      >
      > :buffer <bufno>
      [...]

      Switching to the said buffer makes it unhidden, which is less than
      useful. :)

      On 7 April 2013, Marcin Szamotulski <mszamot@...> wrote:
      > You can also get the value with
      >
      > let bufhidden = getbufvar(bufnr, '&bufhidden')
      [...]

      This was the first thing I tried, but it doesn't work reliably. If
      &hidden is set and the current window is :quit, the corresponding buffer
      becomes hidden, but &bufhidden is undefined. Both buflisted() and
      bufloaded() return true, but there is no bufhidden() function. So, is
      there a way to detect this situation?

      /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.
    • Marcin Szamotulski
      ... Actually this also will not work since bufhidden is not reset for hidden buffers - it works in a different way, it rather instructs vim what to do with
      Message 2 of 7 , Apr 7, 2013
      • 0 Attachment
        On 08:18 Sun 07 Apr , Marcin Szamotulski wrote:
        > On 19:23 Sat 06 Apr , tooth pik wrote:
        > > On Sat, Apr 06, 2013 at 10:48:37PM +0300, LCD 47 wrote:
        > > > Given a buffer number, is it possible to find out (in Vimscript)
        > > > whether the corresponding buffer is hidden or not?
        > >
        > > you can change to said buffer with the buffer command
        > >
        > > :buffer <bufno>
        > >
        > > then you can test &bufhidden for a null value or any of its other
        > > possibilities (anything other than null will mean it's hidden)
        > >
        > > if &bufhidden == ""
        > > do unhidden stuff
        > > else
        > > do hidden stuff
        > > endif
        > >
        > > this help at all?
        > >
        > > --
        > > --
        > > 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.
        > >
        >
        > You can also get the value with
        >
        > let bufhidden = getbufvar(bufnr, '&bufhidden')
        >
        > See
        > :help getbufvar
        > :help :let-&
        >
        > Best,
        > Marcin

        Actually this also will not work since bufhidden is not reset for hidden
        buffers - it works in a different way, it rather instructs vim what to
        do with buffers which become hidden.

        The solution might be a loop over tabpages and checking if a buffer is
        associated with one of them. The following function will test if bufnr
        is associated with one of tabpages:

        fun! BufInTab(bufnr)
        for tabnr in range(1,tabpaggenr('$'))
        if index(tabpagebuflist(tabnr), a:bufnr) != -1
        return 1
        endfi
        endfor
        return 0
        endfun

        If you just want to test if the buffer is not shown just in the current
        tab page you can use winbufnr(), it return -1 if the buffer has not
        associated window.

        Best,
        Marcin

        --
        --
        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.
      • Gary Johnson
        ... How about using :redir to capture the output of :ls and parsing the result? Regards, Gary -- -- You received this message from the vim_use maillist. Do
        Message 3 of 7 , Apr 7, 2013
        • 0 Attachment
          On 2013-04-06, LCD 47 wrote:
          > Given a buffer number, is it possible to find out (in Vimscript)
          > whether the corresponding buffer is hidden or not?

          How about using :redir to capture the output of :ls and parsing the
          result?

          Regards,
          Gary

          --
          --
          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.
        • LCD 47
          On 7 April 2013, Marcin Szamotulski wrote: [...] ... [...] ... Aha, this works fine, thank you! ... This works too, using bufwinnr()
          Message 4 of 7 , Apr 7, 2013
          • 0 Attachment
            On 7 April 2013, Marcin Szamotulski <mszamot@...> wrote:
            [...]
            > > > On Sat, Apr 06, 2013 at 10:48:37PM +0300, LCD 47 wrote:
            > > > > Given a buffer number, is it possible to find out (in Vimscript)
            > > > > whether the corresponding buffer is hidden or not?

            [...]
            > The solution might be a loop over tabpages and checking if a buffer is
            > associated with one of them. The following function will test if
            > bufnr is associated with one of tabpages:
            >
            > fun! BufInTab(bufnr)
            > for tabnr in range(1,tabpaggenr('$'))
            > if index(tabpagebuflist(tabnr), a:bufnr) != -1
            > return 1
            > endfi
            > endfor
            > return 0
            > endfun

            Aha, this works fine, thank you!

            > If you just want to test if the buffer is not shown just in the current
            > tab page you can use winbufnr(), it return -1 if the buffer has not
            > associated window.

            This works too, using bufwinnr() (winbufnr() returns the buffer in
            window, bufwinnr() gets the window of the buffer). It's exactly what I
            need.

            On 7 April 2013, Gary Johnson <garyjohn@...> wrote:
            > How about using :redir to capture the output of :ls and parsing the
            > result?

            That was the last resort option, it's really ugly, and I'm glad
            there's a better solution. :) But thank you for answering nonetheless.

            /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.
          Your message has been successfully submitted and would be delivered to recipients shortly.