E77: Too many files

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

E77: Too many files

Manfred Lotz-2
I have a simple scratch buffer functionity in scratch.vim like follows

if exists('g:loaded_scratch')
    finish
endif
let g:loaded_scratch = 1

let g:scratchbuf_no = 1

function! ScratchEdit(cmd)
    exe a:cmd '[Scratch' . g:scratchbuf_no . ']'
    let g:scratchbuf_no += 1

    setlocal buflisted
    setlocal noswapfile
    setlocal buftype=nofile
    setlocal bufhidden=hide
    setlocal foldcolumn=0
    setlocal nonumber
endfunction

command! -bar -nargs=* Scratch call ScratchEdit('edit')

(if above could/should be improved any advice is welcome)


Sometimes when issueing :Scratch I get

E77: Too many files

Then after some minutes when switching buffers (but not having closed
any buffer) I can do :Scratch without any errors.

Any ideas how to find out what the cause is?

--
Thanks, Manfred

--
--
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/20201218101659.7b48f32c%40hogwart.
Reply | Threaded
Open this post in threaded view
|

Re: E77: Too many files

Jürgen Krämer-4
Hi,

Manfred Lotz schrieb am 18.12.2020 um 10:16:

> I have a simple scratch buffer functionity in scratch.vim like follows
>
> if exists('g:loaded_scratch')
>     finish
> endif
> let g:loaded_scratch = 1
>
> let g:scratchbuf_no = 1
>
> function! ScratchEdit(cmd)
>     exe a:cmd '[Scratch' . g:scratchbuf_no . ']'
>     let g:scratchbuf_no += 1
>
>     setlocal buflisted
>     setlocal noswapfile
>     setlocal buftype=nofile
>     setlocal bufhidden=hide
>     setlocal foldcolumn=0
>     setlocal nonumber
> endfunction
>
> command! -bar -nargs=* Scratch call ScratchEdit('edit')
>
> (if above could/should be improved any advice is welcome)
>
>
> Sometimes when issueing :Scratch I get
>
> E77: Too many files
>
> Then after some minutes when switching buffers (but not having closed
> any buffer) I can do :Scratch without any errors.
>
> Any ideas how to find out what the cause is?
>

your constructed file name "[ScratchNNN]" is also a valid wildcard. If a
file named 'S' or 'c' or 'a' or so on, Vim will load this file into a
buffer.

My guess is that while the scratchbuf_no increases there will be both a
one-letter file name and a one-digit file name that Vim wants to load or
two one-digit file names. But because you use ":edit" to create the
scratch buffer and ":edit" only allows one single file name you get the
E77 error message.

If it happens again execute ":echo g:scratchbuf_no" and check what files
exist in your current directory.

Regards,
Jürgen

--
--
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/f564e8fa-3d30-8e83-35cb-ddb325075ff6%40googlemail.com.
Reply | Threaded
Open this post in threaded view
|

Re: E77: Too many files

Gary Johnson-4
In reply to this post by Manfred Lotz-2
On 2020-12-18, Manfred Lotz wrote:

> I have a simple scratch buffer functionity in scratch.vim like follows
>
> if exists('g:loaded_scratch')
>     finish
> endif
> let g:loaded_scratch = 1
>
> let g:scratchbuf_no = 1
>
> function! ScratchEdit(cmd)
>     exe a:cmd '[Scratch' . g:scratchbuf_no . ']'
>     let g:scratchbuf_no += 1
>
>     setlocal buflisted
>     setlocal noswapfile
>     setlocal buftype=nofile
>     setlocal bufhidden=hide
>     setlocal foldcolumn=0
>     setlocal nonumber
> endfunction
>
> command! -bar -nargs=* Scratch call ScratchEdit('edit')
>
> (if above could/should be improved any advice is welcome)
>
>
> Sometimes when issueing :Scratch I get
>
> E77: Too many files
>
> Then after some minutes when switching buffers (but not having closed
> any buffer) I can do :Scratch without any errors.
>
> Any ideas how to find out what the cause is?

The problem is that your edit command,

    exe a:cmd '[Scratch' . g:scratchbuf_no . ']'

expands to this, when g:scratchbuf_no is 1, for example:

    edit [Scratch1]

Vim looks for a file matching the glob "[Scratch1]", which is
a single character in the set "S c r a t c h 1".  If the glob
doesn't match any files, the buffer name "[Scratch1]" is used.  If
the glob matches one file, that file is opened.  If you happen to
have more than one file with a single-character name from that set,
then that glob will match more that one file and you will get E77.

You can fix that problem by escaping the brackets like this:

    exe a:cmd '\[Scratch' . g:scratchbuf_no . '\]'

Some years ago I wrote a similar function to create a scratchpad
buffer with a name enclosed in brackets with results similar to
yours.  I was very confused until the "Aha!" moment.

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

Re: E77: Too many files

Manfred Lotz-2
Thanks a lot (also to Jürgen)

On Fri, 18 Dec 2020 02:06:18 -0800
Gary Johnson <[hidden email]> wrote:

> On 2020-12-18, Manfred Lotz wrote:
> > I have a simple scratch buffer functionity in scratch.vim like
> > follows
> >
> > if exists('g:loaded_scratch')
> >     finish
> > endif
> > let g:loaded_scratch = 1
> >
> > let g:scratchbuf_no = 1
> >
> > function! ScratchEdit(cmd)
> >     exe a:cmd '[Scratch' . g:scratchbuf_no . ']'
> >     let g:scratchbuf_no += 1
> >
> >     setlocal buflisted
> >     setlocal noswapfile
> >     setlocal buftype=nofile
> >     setlocal bufhidden=hide
> >     setlocal foldcolumn=0
> >     setlocal nonumber
> > endfunction
> >
> > command! -bar -nargs=* Scratch call ScratchEdit('edit')
> >
> > (if above could/should be improved any advice is welcome)
> >
> >
> > Sometimes when issueing :Scratch I get
> >
> > E77: Too many files
> >
> > Then after some minutes when switching buffers (but not having
> > closed any buffer) I can do :Scratch without any errors.
> >
> > Any ideas how to find out what the cause is?  
>
> The problem is that your edit command,
>
>     exe a:cmd '[Scratch' . g:scratchbuf_no . ']'
>
> expands to this, when g:scratchbuf_no is 1, for example:
>
>     edit [Scratch1]
>
> Vim looks for a file matching the glob "[Scratch1]", which is
> a single character in the set "S c r a t c h 1".  If the glob
> doesn't match any files, the buffer name "[Scratch1]" is used.  If
> the glob matches one file, that file is opened.  If you happen to
> have more than one file with a single-character name from that set,
> then that glob will match more that one file and you will get E77.
>
> You can fix that problem by escaping the brackets like this:
>
>     exe a:cmd '\[Scratch' . g:scratchbuf_no . '\]'
>
> Some years ago I wrote a similar function to create a scratchpad
> buffer with a name enclosed in brackets with results similar to
> yours.  I was very confused until the "Aha!" moment.
>

Your explanations hit the nail on the head.

I tested it by creating two files S and r and E77 showed up! Your
suggestion (no surprise) fixed it.

Thanks again.


--
Best, Manfred

--
--
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/20201218192448.16cb67cf%40hogwart.