Search code examples
emacsscrollbeep

Emacs: disable beep when trying to move beyond the end of the document


Is there a way to disable the beep in Emacs when trying to move the cursor beyond the beginning or end of a document? I normally wouldn't mind, but the momentum scrolling on my trackpad makes it so that it beeps a dozen times whenever I scroll to the top or bottom of a document.

I'd rather not disable the bell for other things, if that's possible.


Solution

  • This works pretty well for me to disable the bell just when scrolling to limits (add the following to your .emacs or other init file) :

    (defun my-bell-function ()
      (unless (memq this-command
            '(isearch-abort abort-recursive-edit exit-minibuffer
                  keyboard-quit mwheel-scroll down up next-line previous-line
                  backward-char forward-char))
        (ding)))
    (setq ring-bell-function 'my-bell-function)
    

    Source