Created
March 13, 2014 07:03
-
-
Save dgutov/9523133 to your computer and use it in GitHub Desktop.
Make noises when typing
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-typer.el --- Make noises when typing -*- lexical-binding: t -*- | |
;; This file is not part of GNU Emacs. | |
;; This file is free software: you can redistribute it and/or modify | |
;; it under the terms of the GNU General Public License as published by | |
;; the Free Software Foundation, either version 3 of the License, or | |
;; (at your option) any later version. | |
;; This file is distributed in the hope that it will be useful, | |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
;; GNU General Public License for more details. | |
;; You should have received a copy of the GNU General Public License | |
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
;;; Commentary: | |
;; * Inspired by Bob Newell's `writer-make-noise' | |
;; (http://www.bobnewell.net/writer-typewriter.el) | |
;; * Sound files from Noisy Typer are recommended | |
;; (http://fffff.at/noisy-typer-a-typewriter-for-your-laptop/) | |
;; Download the sound files, extract to a directory of your choice | |
;; and customize `noisy-typer-sounds-alist'. | |
;; Then type `M-x noisy-typer-mode' to toggle it on or off. | |
;;; Code: | |
(defcustom noisy-typer-play-command "mpg123" | |
"Command to play noise files.") | |
(defcustom noisy-typer-margin-column 72 | |
"Column at which to emit the `marginbell' sound.") | |
(defcustom noisy-typer-sounds-alist | |
'((key-1 . "~/Downloads/typewriter/NoisyTyper/key-01.mp3") | |
(key-2 . "~/Downloads/typewriter/NoisyTyper/key-02.mp3") | |
(key-3 . "~/Downloads/typewriter/NoisyTyper/key-03.mp3") | |
(key-4 . "~/Downloads/typewriter/NoisyTyper/key-04.mp3") | |
(space . "~/Downloads/typewriter/NoisyTyper/space.mp3") | |
(marginbell . "~/Downloads/typewriter/NoisyTyper/return.mp3") | |
(linefeed . "~/Downloads/typewriter/NoisyTyper/return-new.mp3") | |
(backspace . "~/Downloads/typewriter/NoisyTyper/backspace.mp3") | |
(pageup . "~/Downloads/typewriter/NoisyTyper/scrollUp.mp3") | |
(pagedn . "~/Downloads/typewriter/NoisyTyper/scrollDown.mp3")) | |
"Associative list with (SYMBOL . FILE) pairs.") | |
;;;###autoload | |
(define-minor-mode noisy-typer-mode | |
"Make Emacs emit sounds when typing." | |
:lighter "" :global t | |
(if noisy-typer-mode | |
(add-hook 'post-command-hook 'noisy-typer-maybe-emit) | |
(remove-hook 'post-command-hook 'noisy-typer-maybe-emit))) | |
(defun noisy-typer-maybe-emit () | |
(cond | |
((= (current-column) noisy-typer-margin-column) | |
(noisy-typer-emit 'marginbell)) | |
((eq last-command-event 32) | |
(noisy-typer-emit 'space)) | |
((memq this-command '(self-insert-command org-self-insert-command)) | |
(noisy-typer-emit (intern (format "key-%d" (1+ (mod last-command-event 4)))))) | |
((memq last-command-event '(10 13 return)) | |
(noisy-typer-emit 'linefeed)) | |
((memq last-command-event '(127 M-backspace C-backspace backspace)) | |
(noisy-typer-emit 'backspace)) | |
((eq last-command-event 'prior) | |
(noisy-typer-emit 'pageup)) | |
((eq last-command-event 'next) | |
(noisy-typer-emit 'pagedn)))) | |
(defun noisy-typer-emit (noise) | |
(let ((file (cdr (assoc noise noisy-typer-sounds-alist)))) | |
(when file | |
(start-process "noisy-typer" nil noisy-typer-play-command | |
(expand-file-name file))))) | |
(provide 'noisy-typer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment