xterm conviniently beeps on a failed unit test (pytest):


(start-process "" nil "/usr/bin/xterm" "-e" "python3" "-B" "-m" "pytest_watch" "--clear" "--" "-s" "--last-failed")

Now I need this beep in term or ansi-term. How can can I do this?

Not yet beeping:

(switch-to-buffer (make-term "test-term" "/bin/bash" nil "-c" "python3 -B -m pytest_watch --clear -- -s --last-failed"))
(switch-to-buffer (term-ansi-make-term "test-ansi" "/bin/bash" nil "-c" "python3 -B -m pytest_watch --clear -- -s --last-failed"))
  • You might be able to use the Emacs function ding...
    – Drew
    May 15, 2022 at 15:26

1 Answer 1


pytest tells the terminal to beep by printing a BEL character, ascii 0x07. Emacs term looks for the same character and calls ding to ring the bell.

The way ding works is by looking at the variable ring-bell-function. If it is non–nil, it calls this function. However, the default value for this variable is ignore. This is a function that doesn’t do much, so generally Emacs is silent. If the variable is nil, then it falls back to an OS–specific hook which may or may not do anything. On Linux, with X Windows, this is done by calling XkbBell (or XBell, in the unlikley case that you built Emacs without Xkb). Very likely that will be handled by your desktop environment, which should allow you to customize the sound that plays.

Or you could set it to a function of your own that plays a sound by some other means, such as by running an appropriate sound–playing program on a sound file of your choosing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.