emacs - emacs 的打字机声音

标签 emacs elisp

我想设置emacs,以便在将文本输入缓冲区时播放打字机声音,以及在按Enter键时播放回车声音(类似于Windows上的Q10编辑器)。有人对我如何解决这个问题有任何建议吗?有没有我可以使用的钩子(Hook)?

我目前使用 aquamacs 和 emacs 22,但不反对升级。

编辑:如果有人感兴趣,这里问了这个问题的 vim 版本:How can I make VIM play typewriter sound when I write a letter?

最佳答案

首先,您必须建立一些播放声音的方式:

    (defun play-typewriter-sound ()
      (let ((data-directory "~/Dowloads/Sounds"))
        (play-sound `(sound :file "key1.wav"))))

...例如在 Mac OSX Emacs 上不起作用,因为它没有在编译时提供声音支持。有一些变通方法,例如见 http://www.emacswiki.org/emacs/ErcSound
  • 然后,您可以在任何 Emacsen 上使用建议
    (defadvice self-insert-command (after play-a-sound activate)
      (play-typewriter-sound))
    

    你也可以建议newline-and-indent .
  • 在 Emacs24 上,您现在拥有 post-self-insert-hook
    (add-hook 'post-self-insert-hook 'play-typewriter-sound)
    
  • 如果你不喜欢 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)))
    
  • 关于emacs - emacs 的打字机声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11206140/

    相关文章:

    emacs - 为两种情况配置 Yasnippet - (1) 区域处于事件状态; (2) 区域不活跃

    emacs - 编写包含 Emacs Lisp 代码的片段时出现问题

    emacs - 如何回到 Emacs Lisp 中先前定义的函数?

    emacs - 为包含参数的函数创建缩写

    emacs - 在 Emacs org-mode 中折叠当前大纲

    emacs - 如何配置 Emacs 使用可变字体来显示 LaTeX 公式的预览?

    用于检测事件缓冲区变化的 Emacs-lisp 钩子(Hook)?

    regex - Emacs lisp 正则表达式从缓冲区文件名中提取当前相对路径

    涉及正斜杠的 Emacs 键绑定(bind)

    Emacs -- 如何删除覆盖(列表形式)