Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.3 KiB

  1. ;;; mode-line-bell.el --- Flash the mode line instead of ringing the bell -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2018 Steve Purcell
  3. ;; Author: Steve Purcell <steve@sanityinc.com>
  4. ;; Keywords: convenience
  5. ;; Package-Version: 0.2
  6. ;; Package-Commit: 4985ba42f5a19f46ddbf9b3622453a9694995ce5
  7. ;; This program is free software; you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; This program is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; Enable the global minor mode `mode-line-bell-mode' to set
  19. ;; `ring-bell-function' to a function that will briefly flash the mode
  20. ;; line when the bell is rung.
  21. ;;; Code:
  22. (defgroup mode-line-bell nil
  23. "Flash the mode line instead of ringing the bell."
  24. :group 'frames)
  25. (defcustom mode-line-bell-flash-time 0.05
  26. "Length of time to flash the mode line when the bell is rung."
  27. :type 'float
  28. :safe 'floatp)
  29. (defvar mode-line-bell--flashing nil
  30. "If non-nil, the mode line is currently flashing.")
  31. (defun mode-line-bell--begin-flash ()
  32. "Begin flashing the mode line."
  33. (unless mode-line-bell--flashing
  34. (invert-face 'mode-line)
  35. (setq mode-line-bell--flashing t)))
  36. (defun mode-line-bell--end-flash ()
  37. "Finish flashing the mode line."
  38. (when mode-line-bell--flashing
  39. (invert-face 'mode-line)
  40. (setq mode-line-bell--flashing nil)))
  41. ;;;###autoload
  42. (defun mode-line-bell-flash ()
  43. "Flash the mode line momentarily."
  44. (unless mode-line-bell--flashing
  45. (run-with-timer mode-line-bell-flash-time nil 'mode-line-bell--end-flash)
  46. (mode-line-bell--begin-flash)))
  47. ;;;###autoload
  48. (define-minor-mode mode-line-bell-mode
  49. "Flash the mode line instead of ringing the bell."
  50. :lighter nil
  51. :global t
  52. (setq-default ring-bell-function (when mode-line-bell-mode
  53. 'mode-line-bell-flash)))
  54. (provide 'mode-line-bell)
  55. ;;; mode-line-bell.el ends here