willys5000 / vim

Automatically exported from code.google.com/p/vim
0 stars 0 forks source link

New option to not beep with 'showmatch' #319

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The 'showmatch' option is useful, but it's distracting that it beeps, if no 
matching pair is found, e.g. when typing a smiley: :)

I think a new option like 'showmatch_silent' would be nice.

Original issue reported on code.google.com by dhahler@gmail.com on 19 Jan 2015 at 1:26

GoogleCodeExporter commented 9 years ago
For reference, here is some question/answer about this on StackOverflow: 
http://stackoverflow.com/a/24242434/15690

Original comment by dhahler@gmail.com on 19 Jan 2015 at 1:36

GoogleCodeExporter commented 9 years ago
Is there a problem to disable the bell altogether?

Original comment by chrisbr...@googlemail.com on 20 Jan 2015 at 9:57

GoogleCodeExporter commented 9 years ago
The bell serves its purpose in general and disabling it altogether because of
this seems to be overkill.

I have it disabled in my terminal (but mostly because it does not work with
pulseaudio-module-x11 there), and got confused when gvim rang it on a smiley.

For my local setup it's ok to just comment it, but it appears to be a common 
issue.

For reference, here's a patch to disable it:

    diff --git i/src/search.c w/src/search.c
    index 3276a77..881382c 100644
    --- i/src/search.c
    +++ w/src/search.c
    @@ -2454,7 +2454,7 @@ showmatch(c)
         }

         if ((lpos = findmatch(NULL, NUL)) == NULL)     /* no match, so beep */
    -       vim_beep();
    +       /* vim_beep(); */ ;
         else if (lpos->lnum >= curwin->w_topline && lpos->lnum < curwin->w_botline)
         {
            if (!curwin->w_p_wrap)

There's a setting 'errorbells' already, maybe the new setting should be named
'showmatchbells' then?

Original comment by dhahler@gmail.com on 21 Jan 2015 at 4:38

GoogleCodeExporter commented 9 years ago
Anything wrong with this approach? Simply reset the bell setting when Entering 
Insert mode and reset it when returning. I don't think, we want to add another 
setting for that...

augroup NoError
    au!
    au InsertEnter * :call SetBell(1)
    au InsertLeave * :call SetBell(0)
augroup END

func! SetBell(disable)
    if a:disable
    let s:mybell = [&eb, &vb, &t_vb]
    " need to set visualbell, else bell will still be called.
    set noeb vb t_vb=
    else
    let [&eb, &vb, &t_vb] = s:mybell
    endif
endfu

Original comment by chrisbr...@googlemail.com on 21 Jan 2015 at 6:56

GoogleCodeExporter commented 9 years ago
Thanks for your example config!

Maybe it could be added to the documentation for 'showmatch'?

Feel free to close the issue if a new option is not wanted (which I can 
understand).

Original comment by dhahler@gmail.com on 24 Jan 2015 at 12:32

GoogleCodeExporter commented 9 years ago
Some drawbacks of this approach:
 - there are other bell events during insert mode, e.g. pressing '<del>' at the end of a line
 - it adds some overhead to entering/leaving insert mode

Original comment by dhahler@gmail.com on 24 Jan 2015 at 12:41

GoogleCodeExporter commented 9 years ago
I agree that a native option would have advantages over this rather crude 
workaround.

BTW, the beep also happens when the first candidate of a custom insert-mode 
completion contains an unmatched parenthesis. Since once hasn't explicitly 
types this, this is very unexpected and annoying.

Original comment by sw...@ingo-karkat.de on 24 Jan 2015 at 1:16

GoogleCodeExporter commented 9 years ago
Well, perhaps we can have an option like 'beepon' that takes a list of flags to 
specify when to beep. That would allow us to selectively turn off the bell for 
e.g. showmatch.

Original comment by chrisbr...@googlemail.com on 25 Jan 2015 at 12:35

GoogleCodeExporter commented 9 years ago
Perhaps instead of InsertEnter/InsertLeave to disable the beep, one could use 
InsertCharPre to disable specifically when entering a few choice characters, 
and InsertLeave to re-enable? Oddly enough I've never noticed a beep or flash 
with showmatch set.

Original comment by benjamin...@rockwellcollins.com on 26 Jan 2015 at 4:38

GoogleCodeExporter commented 9 years ago
Here is a patch, that implements the 'bellon' option. If anybody has a better 
name, I am all ear ;)
Anyway, Documentation like this:
                        *'bellon'* *'bo'*
'bellon' 'bo'       string  (default "bCceEghiLmoqrsSwy<")
            global
            {not in Vi}
    This option lets you finetune, whenn a bell (visual or accustic) will
    occur.

    It is a list of flags, when the flag is set, on those occasions a bell
    will b rung.
     flag   meaning when present    ~
      b error when pressing <BS> or <Del> in insert mode and the char
        can't be deleted.
      c Error occured when using |i_CTRL-X_CTRL-K| or |i_CTRL-X_CTRL-T|
      C Fail to move around using the cursor keys or
        <PageUp>/<PageDown> in insert mode.
      e     other Error occured (e.g. try to join last line)
      E hitting <Esc> in normal mode
      g unknown Char after <C-G> in insert mode
      h error occued when using hangul input
      i pressing <Esc> in 'insertmode'
      L calling the beep module for Lua/Mzschem/TCL
      m 'showmatch' error
      o empty region error |cpo-E|
      q In Visual mode, Hitting |Q|
      r Unknown register after <C-R> in insert mode.
      s Bell from shell output |:!|
      S Error on spell suggest
      w More matches in wild mode available
      y can't copy char from insert mode using i_CTRL-Y or i_CTRL-E
      < can't |g<|

    This is most usefule, to finetune when in insert mode the bell should
    be rung. For normal mode and ex commands, the bell is often rung to
    indicate that an error occured. It can be silenced by removing the 'E'
    flag then.

Build passed: https://travis-ci.org/chrisbra/vim-ci/builds/48553540

Original comment by chrisbr...@googlemail.com on 27 Jan 2015 at 10:57

Attachments:

GoogleCodeExporter commented 9 years ago
For reference, there's an updated patch on the vim_dev mailinglist:
https://groups.google.com/d/msg/vim_dev/-jN4_nsSls0/Nbjbrh4jXYEJ

Original comment by dhahler@gmail.com on 5 Feb 2015 at 9:03