about summary refs log tree commit diff stats
path: root/lisp/acdw-bell.el
blob: 514be1fca6485c2dc8f43cc825b8b5326951fbac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
;;; acdw-bell.el --- flash mode-line on error -*- lexical-binding: t; -*-

;; cribbed pretty heavily from doom-themes-ext-visual-bell.el ...

(require 'face-remap)

(defface acdw-bell '((t (:inherit mode-line-highlight)))
  "Face to use for the mode-line when `doom-themes-visual-bell-config' is used."
  :group 'mode-line)

;;;###autoload
(defun acdw-bell/flash-mode-line (&optional beep-p)
  "Blink the mode-line red briefly. Set `ring-bell-function' to this to use it.
If BEEP-P is non-nil, beep too."
  (let ((acdw-bell//cookie
         (face-remap-add-relative 'mode-line 'acdw-bell)))
    (force-mode-line-update)
    (when beep-p (beep))
    (run-with-timer 0.15 nil
                    (lambda (cookie buf)
                      (with-current-buffer buf
                        (face-remap-remove-relative cookie)
                        (force-mode-line-update)))
                    acdw-bell//cookie
                    (current-buffer))))

(provide 'acdw-bell)
;;; acdw-bell.el ends here