;;;; jimb-sound.el --- some functions for dealing with sound, for beeps (defun js-file-bytes (filename) "Return the contents of FILENAME as a string of bytes." (save-excursion (let (b) (unwind-protect (progn (set-buffer (setq b (generate-new-buffer " *file-bytes*"))) (set-buffer-multibyte nil) (insert-file-contents-literally filename) (buffer-string)) (if b (kill-buffer b)))))) (defun js-read-sound-file (filename) "Return the contents of FILENAME as a sound." (let ((bytes (js-file-bytes filename))) `(sound :data ,bytes))) (defconst js-beep-sound nil "The sound 'js-beep' plays for beeps, or nil to do the default beep. If nil, js-beep respects 'visible-bell'.") (defun js-beep () "Play `js-beep-sound'. If that is nil, play the default sound." (let ((sound js-beep-sound)) (if (and (consp sound) (eq (car sound) 'sound)) (play-sound sound) (let ((ring-bell-function nil)) (beep t))))) (defun js-set-beep-sound-file (filename) "Make `beep' play the sound from FILENAME, if it exists. If FILENAME does not exist, fall back to the default terminal bell (respecting the value of `visible-bell'). Return nil if we're unable to read FILENAME, or a true value otherwise." (condition-case nil (progn (setq js-beep-sound (js-read-sound-file filename)) (setq ring-bell-function (function js-beep)) t) ((file-error) (setq js-beep-sound nil) (setq ring-bell-function nil)))) (provide 'jimb-sound)