aboutsummaryrefslogtreecommitdiffstats
path: root/elpa/doom-themes-20220504.1557/doom-themes-ext-visual-bell.el
blob: 82e1af354b80f7592d21d8a88cf5420266b64e67 (plain) (blame)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
;;; doom-themes-ext-visual-bell.el --- flash mode-line on error -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2019-2022 Henrik Lissner
;;
;; Author: Henrik Lissner <contact@henrik.io>
;; Maintainer: Henrik Lissner <contact@henrik.io>
;; Created: July 29, 2019
;;
;;; Commentary:
;;; Code:

(require 'face-remap)

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

;;;###autoload
(defun doom-themes-visual-bell-fn ()
  "Blink the mode-line red briefly. Set `ring-bell-function' to this to use it."
  ;; Since emacs 29, the mode-line face is the parent of the new face
  ;; mode-line-active and mode-line-inactive.  For remapping purposes, the
  ;; mode-line-active face has to be used, see details at:
  ;; http://debbugs.gnu.org/cgi/bugreport.cgi?bug=53636
  (let* ((face (if (facep 'mode-line-active)
                   'mode-line-active
                 'mode-line))
         (buf (current-buffer))
         (cookie (face-remap-add-relative face 'doom-themes-visual-bell)))
    (force-mode-line-update)
    (run-with-timer 0.15 nil
                    (lambda ()
                      (with-current-buffer buf
                        (face-remap-remove-relative cookie)
                        (force-mode-line-update))))))

;;;###autoload
(defun doom-themes-visual-bell-config ()
  "Enable flashing the mode-line on error."
  (setq ring-bell-function #'doom-themes-visual-bell-fn
        visible-bell t))

(provide 'doom-themes-ext-visual-bell)
;;; doom-themes-ext-visual-bell.el ends here