Last active
August 5, 2016 06:56
-
-
Save plaidfinch/04482acf77165bbb9a11e479aeffeadc to your computer and use it in GitHub Desktop.
Configure flycheck to make a "ding!" sound after it completes checking, only in certain modes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Noisy Flycheck (for slow syntax checkers, program verifiers, &c.) | |
(defvar flycheck-ding t) ;; Enable sounds? | |
(defvar flycheck-ding-path "~/.emacs.d/private/Ding.mp3") ;; Where's the "ding!" sound to make? | |
(defvar flycheck-buzz-path "~/.emacs.d/private/Basso.aiff") ;; Where's the "bzz!" sound to make? | |
(defvar flycheck-noisy-modes-list '(dafny-mode)) ;; Which modes should we make sounds in? | |
;; Below what number of seconds checking time should we be silent? | |
(defvar flycheck-ding-delay-threshold 2) | |
(defvar flycheck-buzz-delay-threshold 1) | |
(defun play-sound (sound-file) | |
(call-process-shell-command | |
(concat "afplay " sound-file " &> /dev/null") nil 0)) | |
(defun flycheck-ring-bell () | |
(if flycheck-ding | |
(if (member major-mode flycheck-noisy-modes-list) | |
(lexical-let* | |
((errors-exist (flycheck-has-current-errors-p 'error)) | |
(sound-file (if errors-exist | |
flycheck-buzz-path | |
flycheck-ding-path)) | |
(elapsed-time (- (float-time) flycheck-start-time))) | |
(progn | |
(setq flycheck-total-time (+ flycheck-total-time elapsed-time)) | |
(if (> flycheck-total-time | |
(if errors-exist | |
flycheck-buzz-delay-threshold | |
flycheck-ding-delay-threshold)) | |
(progn | |
(setq flycheck-now-running nil) | |
(run-with-timer | |
0.05 nil | |
(lambda () (if (not flycheck-now-running) | |
(progn | |
(setq flycheck-total-time 0) | |
(play-sound sound-file)))))))))))) | |
(defun flycheck-register-start-time () | |
(progn | |
(if (not (boundp 'flycheck-total-time)) | |
(defvar flycheck-total-time 0)) | |
(if (boundp 'flycheck-start-time) | |
(setq flycheck-start-time (float-time)) | |
(defvar flycheck-start-time (float-time))) | |
(if (boundp 'flycheck-now-running) | |
(setq flycheck-now-running t) | |
(defvar flycheck-now-running t)))) | |
(add-hook 'flycheck-before-syntax-check-hook 'flycheck-register-start-time) | |
(add-hook 'flycheck-after-syntax-check-hook 'flycheck-ring-bell) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment