Saturday, August 22, 2020

Re: Autocommand script

On Sat, 22 Aug 2020 at 14:55, Tom Ryder <tom@sanctum.geek.nz> 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 vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CALPW7mTBgGbXvPzbrA9TudHPE2zAaebOE2oSHc19MvCtq9oGWw%40mail.gmail.com.

No comments: