Last edit
Sammanfattning: Corrected a typo: of -> off "== Turn of alarms completely ==" -> "== Turn off alarms completely =="
Ändrad:
< == Turn of alarms completely ==
till
> == Turn off alarms completely ==
The bell rings whenever (ding) is called. What the bell does depends on the value of two variables:
Combinations of these two variables can create very interesting alert functions, as described in the following hacks.
The visible bell is great if Emacs is the only program you ever use. However, if you aren’t paying attention to Emacs, or it’s on another desktop, you won’t see the visible bell. In those cases, you probably want the bell to ring instead of blink. Use the following:
(defun unfoused-ding-blink ()
"Flash the screen when Emacs is focused, ring the bell (ding) if not." (setq ring-bell-function `(lambda ()
(setq visible-bell (fsm-frame-x-active-window-p (selected-frame)))
(ding))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Frame-related functions ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; All from http://www.emacswiki.org/emacs-pt/rcircDbusNotification(require 'dbus)
(defun fsm-x-active-window ()
"Return the window ID of the current active window in X, as
given by the _NET_ACTIVE_WINDOW of the root window set by the
window-manager, or nil if not able to"
(if (eq (window-system) 'x)
(let ((x-active-window (x-window-property "_NET_ACTIVE_WINDOW" nil "WINDOW" 0 nil t)))
(string-to-number (format "%x00%x" (car x-active-window) (cdr x-active-window)) 16))
nil)) (defun fsm-frame-outer-window-id (frame)
"Return the frame outer-window-id property, or nil if FRAME not of the correct type"
(if (framep frame)
(string-to-number
(frame-parameter frame 'outer-window-id))
nil)) (defun fsm-frame-x-active-window-p (frame)
"Check if FRAME is is the X active windows
Returns t if frame has focus or nil if"
(if (framep frame)
(progn
(if (eq (fsm-frame-outer-window-id frame)
(fsm-x-active-window))
t
nil))
nil)))(unfoused-ding-blink)
During a normal editing session Emacs gives a warning signal quite often. Every time you type Ctrl-G, to stop searching, or stop what you were typing and do something else, and so on… you will get the bell. Some people find all the beeping annoying. To get a visual signal instead, put the following in your .emacs:
(setq visible-bell 1)
Now some people find the flashing annoying. To turn the alarm totally off, you can use this:
(setq ring-bell-function 'ignore)
For XEmacs you can set the visible bell not to flash the whole screen (as is default in XEmacs) but only the top and bottom line (default in GnuEmacs) by setting the visible-bell to anything other than t or nil:
(setq visible-bell 'top-bottom)
In some cases, you’d like to reduce the number of warnings or eliminate warnings in certain conditions. The following turns off the alarm bell when you hit ‘C-g’ in the minibuffer or during an ‘isearch’.
(setq ring-bell-function
(lambda ()
(unless (memq this-command
'(isearch-abort abort-recursive-edit exit-minibuffer keyboard-quit))
(ding))))Instead of beeping or flashing, Emacs could play a cool sound file, whenever an error occurs:
(setq ring-bell-function (lambda () (call-process "audioplay" nil 0 nil "/this/is/my/errorsound.au")))
You might have to replace “audioplay” by “wavplay” or whatever application you have for playing audio files.
XEmacs offers an option to set the variable bell-volume. The following turns off the bell absolutely:
(setq bell-volume 0)
I use the following to make the Scroll Lock LED blink:
(setq ring-bell-function (lambda () (call-process-shell-command "xset led 3; xset -led 3" nil 0 nil)))
Seems like the Scroll Lock LED may be useful after all ;) – mina86
I have a younger sister and the bell wakes her up, so I’ve wrote this predicate to control the beeping. – PiotrMieszkowski
(defvar night-start 22
"The hour that people go to sleep.")
(defvar night-end 8
"The hour that people wake up.")
(defun nightp ()
"Check if it is night."
(let ((hr (nth 2 (decode-time (current-time)))))
(or (< hr night-end)
(> hr night-start))))When I use (setq visible-bell t) I see nothing. So I use this as a visual indicator:
;; quiet, please! No dinging!
(setq visible-bell nil)
(setq ring-bell-function `(lambda ()
(set-face-background 'default "DodgerBlue")
(set-face-background 'default "black")))