I'm a fan. More bandwidth from vim to me is always good. But people wanting to turn off beeps from vim are very vocal, those wanting to turn them on are not.
I got used to relying on beeps using vi on dumb terminals for many years, and using vim with GTK with random DEs getting any kind of beep with vim proved very hit or miss, and losing the beep after some kind of upgrade happened a lot. So I learned about libcanberra, and my vim gives me a 100 ms cowbell. It's only about 15 lines of C. Managing (choosing, distributing) the sound files would be a far larger task than the code I imagine.
I've no idea about libcanberra on MS Windows.
Regards, John Little
At file scope:
#ifdef CANBERRA
# include <canberra.h>
static ca_context *canberra = 0;
#endif
In gui_mch_beep:
#ifdef CANBERRA
int ca_error;
if (!canberra) // static, initialize on first use
ca_context_create (&canberra);
ca_error = ca_context_play (canberra, 0,
CA_PROP_EVENT_ID, "bell",
CA_PROP_EVENT_DESCRIPTION, "vim beep",
CA_PROP_CANBERRA_CACHE_CONTROL, "volatile",
NULL);
if (ca_error)
fprintf(stderr, "%d error, %s\n", ca_error, ca_strerror(ca_error));
#else
...
But also, in misc1.c, in vim_beep:
#ifdef CANBERRA
// john I use a 100 ms beep, which plays asynchronously anyway
// so let's use 50 instead of 500
if (!did_init || ELAPSED_FUNC(start_tv) > 50)
#else
if (!did_init || ELAPSED_FUNC(start_tv) > 500)
#endif
Because libcanberra plays the sound in another thread, or something like that, it doesn't block, and it handles playing multiple sounds. My keyboard repeat rate is 50 Hz, and if I hold down the escape key I get 10 sounds a second, because the sound is 100 ms (thanks to audacity). Having a very fast (that is, a short attack stage) sound saves me a good fraction of second every time.
Thinking while typing, please excuse me...
The sound themes typically available for the xdg desktop standard have sounds that are one or 2 seconds long, and usually start slowly. For me that wouldn't suit vim.
I'd like a general scheme where a different sound could be set for at least each auto command event. Maybe via an ex command, say "play". F.ex. one could make vim like a smartphone with key sounds on with InsertCharPre. But I'd like other events, too, with fine-grained control possible for errors and every circumstance where vim presently issues a beep.
Python can play sounds, so I suppose I could make a call to python in auto commands. Maybe all we need is an event for the bell, and for errors, maybe passing or setting up some context via v:event. (It was a struggle for me to get all the packages I needed to get my python to use GSound; documentation I found was not quite up to date. )
So, my conclusion is that there could be an event for all the circumstances where vim presently may beep, and the relevant item at :h 'belloff' could be set in v:event. If an error has occurred then v:errmsg gives information. Then some heroic plugin author can put together the python bits and pieces with an appropriate sound theme. The large majority who want nothing to do with sound can continue in their silence, or maybe flash their RGB, or send a command to an odour generator ;).
Regards, John Little
don’t use system commands, it’s a waste of resources and likely too slow;
I have also been searching for small, portable audio libraries, to make the plugin self-contained, and I recall having found one that seemed apt, although I haven’t tried it. As soon as I find what it was I’ll post the link here.
It appears libcanberra is widely available. My system also has the -dev
package installed (I didn't do that, perhaps because of a gtk
dependency). I could not find something for autoconf though. But I
expect it to be simple.I've no idea about libcanberra on MS Windows.
It needs a completely different solution. And again I hope it's a
simple thing, since we don't want this to be adding much code to Vim.