Autocommand script

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Autocommand script

A. Wik
Hi all,

I was wondering (a) if there is a better way to do it than this
script, and (b) whether all the backslashes and pipe characters (|)
are really necessary and why.

if has("autocmd")
  au BufLeave * let x=0 | while x<=bufnr('$') |
\   if bufexists(x) |
\     set buflisted hidden bufhidden=hide |
\   endif |
\   let x = x+1 |
\ endwhile
endif  " has("autocmd")

Regards,
Albert.

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CALPW7mT1Tzv7P5z7w93%2B7cYm7EsMPVDrPq28HAC2YYDYGxaXTg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Autocommand script

Tom Ryder
On Sat, Aug 22, 2020 at 09:01:56AM +0000, A. Wik wrote:
>if has("autocmd")
>  au BufLeave * let x=0 | while x<=bufnr('$') |
>\   if bufexists(x) |
>\     set buflisted hidden bufhidden=hide |
>\   endif |
>\   let x = x+1 |
>\ endwhile
>endif  " has("autocmd")

>I was wondering...
>(a) if there is a better way to do it than this script...

Can you explain what you're trying to do?

>(b) whether all the backslashes and pipe characters (|) are really
>necessary and why.

The pipe characters are necessary to define a concatenated list of
commands to :autocmd.  The backslashes are line-continuation characters
to break up what would otherwise be a long line.

The easiest way to avoid both in this context is to define a function to
group the commands:

     function! MyFunction() abort
         ...
     endfunction

     if has('autocmd')
         autocmd BufLeave * call MyFunction()
     endif

--
Tom Ryder <https://sanctum.geek.nz/>
Maybe we can bring back the light.

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200822145524.GG16492%40arjuna.sanctum.geek.nz.
Reply | Threaded
Open this post in threaded view
|

Re: Autocommand script

A. Wik
On Sat, 22 Aug 2020 at 14:55, Tom Ryder <[hidden email]> wrote:

>
> On Sat, Aug 22, 2020 at 09:01:56AM +0000, A. Wik wrote:
> >if has("autocmd")
> >  au BufLeave * let x=0 | while x<=bufnr('$') |
> >\   if bufexists(x) |
> >\     set buflisted hidden bufhidden=hide |
> >\   endif |
> >\   let x = x+1 |
> >\ endwhile
> >endif  " has("autocmd")
>
> >I was wondering...
> >(a) if there is a better way to do it than this script...
>
> Can you explain what you're trying to do?

I'm trying to undo the "nobuflisted" status that some scripts set on
some buffers.  In practice, the main thing is to keep the Vim help
buffers from disappearing from ":ls".

I suppose there is no need to iterate through all buffers.  Maybe
"bufnr('%') would work to determine the exact buffer to apply the
options to, ie. only the buffer currently being left?

> >(b) whether all the backslashes and pipe characters (|) are really
> >necessary and why.
>
> The pipe characters are necessary to define a concatenated list of
> commands to :autocmd.  The backslashes are line-continuation characters
> to break up what would otherwise be a long line.

I know what they do.  I was just wondering, because this is not
normally necessary, but I think I understand now -- it is necessary
for concatenation of what would otherwise be limited to a single
command.

> The easiest way to avoid both in this context is to define a function to
> group the commands:
>
>      function! MyFunction() abort
>          ...
>      endfunction

Why the "!" and "abort"?

-aw

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CALPW7mTBgGbXvPzbrA9TudHPE2zAaebOE2oSHc19MvCtq9oGWw%40mail.gmail.com.