How to disable the beep in emacs on Windows
Asked Answered
D

3

62

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.

Dollop answered 11/5, 2012 at 4:26 Comment(0)
P
115

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

Patchy answered 11/5, 2012 at 5:36 Comment(5)
This is such an thorough answer. Thank you so much. I learned much more than my question asked for. As for the .emacs file name and location, mine is located at 'c:/users/my_name/AppData/Roaming/.emacs'. I didn't look into the '~/AppData/Roaming/' and that's why I didn't find it. Again, your answer helped me a lot to get started with emacs.Dollop
This is one of the best I have seen on Emacs tag. if any Emacs new user come across to this answer he/she would be thrilled. Thank you very much phils.Th
Just started using Emacs. Thank you so much for the help! For new users to Emacs, visible-bell isn't the only variable you have to change anymore, but the page does tell you the right place to go: ring-bell-functionThoracotomy
Some Emacsen truncate the value shown so you'd see something like user-init-file is a variable defined in ‘lread.c’. Its value is "c:/users/m..." which is not very helpful. Try M-: user-init-file RET to see the whole name.Congressional
@devon If Emacs is abbreviating strings as short as a filename, then I think something somewhere is misconfigured. Certainly that shouldn't happen by default! I would be inclined to work out why it's happening, because that's surely going to be an ongoing irritation.Patchy
M
36

To completely turn off alarms use:

(setq ring-bell-function 'ignore)

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

Mede answered 2/7, 2014 at 8:33 Comment(2)
Where in the .emacs file should I add this line? At the end of the file?Scapegoat
Doesn't matter, but yes I would put it at the end of the file.Mede
S
0

Add line below to your .emacs.d/init.cl file or any other startup file:

(set-message-beep 'silent)

For more information on this topic look at help docs for set-message-beep via command C-h f followed by set-message-beep

This question are addresses in Emacs W32 FAQ > Display Settings > Beep Sound

Shalne answered 12/8, 2023 at 22:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.