How to disable the beep in emacs on Windows

Hi I'm new to Emacs and I downloaded GNU emacs on my windows machine. I just finished the short tutorial but I found there's a beep sound whenever I hit the beginning/end of a file and in many other cases, which is a little disturbing to me.

I searched online and I found people saying putting this

(setq visible-bell 1)

in my .emacs file, but I don't know how to do that. First, where is my .emacs file and what is it? Or is there another way to do it? I mean in the emacs window menu there is Options -> Customize Emacs but I couldn't find where the setting is. I feel like it's kind of hard to find things in there unless you already know where it is.


You have a couple of options, one of which doesn't require you to know where the file is; however in due course you're almost certainly going to want to make changes to the file, so let's start there.

First, where is my .emacs file and what is it?

You also have some options for the name of that file. ~/.emacs is the default, but it could also be ~/.emacs.el or ~/.emacs.d/init.el. (Personally I prefer the latter, so as to keep all Emacs related files under that same .emacs.d directory, but we'll go with the default, and you can always rename the file later.)

So first, check to see if you have an existing file.

C-hv user-init-file RET

By default it will show you a file path ending in /.emacs (even if that file doesn't exist), but on the (unlikely, in your case) offchance that it ends in /.emacs.el or /.emacs.d/init.el then it would mean that you have an existing init file at that location.

Load that file with the appropriate one of the following:

  • C-xC-f ~/.emacs RET
  • C-xC-f ~/.emacs.el RET
  • C-xC-f ~/.emacs.d/init.el RET

Or you could load it regardless of where it was with:
M-: (find-file user-init-file) RET

Then you can simply add that line of code to the file:

(setq visible-bell 1)

Save the file:

C-xC-s

And the next time you start Emacs, it will use that setting.

You can also evaluate the setting immediately by typing C-xC-e with the cursor after the closing parenthesis.

Now that you know how to do that, the other approach is:

  • M-x customize-variable RET visible-bell RET
  • Click the "Toggle" button to turn the setting on.
  • Click the "Save for future sessions" button to save it to your init file.

If you then look at your init file, you will see that it has been added to the (custom-set-variables ...) section.

As for what your .emacs file is, it's a personal library of Emacs Lisp (elisp) code which is automatically loaded and evaluated when you start Emacs. All Emacs configuration and customization is written in this language (as indeed is the majority of the editor itself).

You can read more about the init file and customizing Emacs in the built-in manual, by typing:

M-: (info "(emacs) Customization") RET
or C-hig (emacs) Customization RET

You may need to learn how to use the info reader first. From the *info* buffer you can type h to start its tutorial, and d to return to the top level page (which has some useful notes at the top).

Or is there another way to do it? I mean in the emacs window menu there is Options -> Customize Emacs but I couldn't find where the setting is.

"Specific Option" -> "visible-bell" was the answer for that approach. But do take note that not everything is available through those menus, so that won't always be the answer, and lots of people disable the menu bar entirely, because everything can be accessed without it. (I'm more inclined to suggest browsing through the menus as a way of discovering some of the options which people thought were useful enough to put in there, but make sure you're not reliant on them.)

I feel like it's kind of hard to find things in there unless you already know where it is.

That's certainly true to an extent, but the self-documentation aspect of Emacs means that even if you don't know where to look, you can almost always find out if you know how to look.

Admittedly there's a definite learning curve even on doing that, but I recommend learning as much as you can about this aspect of Emacs as soon as possible. This will get you started:

http://emacswiki.org/emacs/SelfDocumentation


To completely turn off alarms use:

(setq ring-bell-function 'ignore)

in your .emacs File which is placed in your HOME Folder