대문 최근에 바뀐 글 새소식 찾기 하우투 문제 제안

AlarmBell

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.

Ring the Bell when Emacs is Out of Focus

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)

Get visual indication of an exception

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)

Turn off alarms completely

Now some people find the flashing annoying. To turn the alarm totally off, you can use this:

 (setq ring-bell-function 'ignore)

XEmacs: Flash top and bottom line only

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)

Reduce the number of warnings

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))))

Play a different sound

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: set the bell volume

XEmacs offers an option to set the variable bell-volume. The following turns off the bell absolutely:

    (setq bell-volume 0)

Use the Scroll-lock LED as an alarm indicator

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

A predicate for suppressing the bell at night

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))))

Flash the screen

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")))

CategoryDotEmacs