(defface visible-bell-face `((t (:background "yellow"))) "") (defface visible-bell-cursor-face `((t (:background "red"))) "") (defvar visible-bell--cursor-background nil) (defvar visible-bell--face-remapping nil) (defun visible-bell () (unless visible-bell--cursor-background (setq visible-bell--cursor-background (face-attribute 'cursor :background))) (set-face-attribute 'cursor nil :background (face-attribute 'visible-bell-cursor-face :background)) (with-current-buffer " *Echo Area 0*" (setq-local visible-bell--face-remapping (face-remap-add-relative 'default 'visible-bell-face))) (sit-for 0.5) (set-face-attribute 'cursor nil :background visible-bell--cursor-background) (with-current-buffer " *Echo Area 0*" (face-remap-remove-relative visible-bell--face-remapping))) (setq ring-bell-function #'visible-bell) (setq visible-bell nil) ;; just in case