我想设置emacs,以便在输入缓冲区时输入打字机声音,以及在输入时输入回车声(类似于Windows上的Q10编辑器).有没有人对我如何解决这个问题有任何建议?我可以使用钩子吗?
我目前使用的是aquamacs和emacs 22,但我不反对升级.
编辑:如果有人有兴趣,这个问题的vim版本在这里被问到:当我写一封信时,如何使VIM播放打字机声音?
Joa*_*ora 11
首先,您必须建立一些播放声音的方法:
(defun play-typewriter-sound ()
(let ((data-directory "~/Dowloads/Sounds"))
(play-sound `(sound :file "key1.wav"))))
Run Code Online (Sandbox Code Playgroud)
...例如,在Mac OSX Emacs上不起作用,因为它没有声音支持编译.但是有一些解决方法,例如参见http://www.emacswiki.org/emacs/ErcSound
然后,您可以在任何Emacsen上使用建议
(defadvice self-insert-command (after play-a-sound activate)
(play-typewriter-sound))
Run Code Online (Sandbox Code Playgroud)
你也可以建议newline-and-indent.
在Emacs24上你现在有了 post-self-insert-hook
(add-hook 'post-self-insert-hook 'play-typewriter-sound)
Run Code Online (Sandbox Code Playgroud)如果您不喜欢defadvice,可以使用post-command-hook并检查this-command那里的名称:
(add-hook 'post-command-hook #'play-typewriter-sound-maybe)
(defun play-typewriter-sound-maybe ()
(if (eq this-command 'self-insert-command)
(play-typewriter-sound)))
Run Code Online (Sandbox Code Playgroud)