21.14 禁止交互

有时将 Emacs 作为无头服务器进程运行、 通过网络连接响应命令会很有用。 然而,Emacs 主要是一个交互式使用平台, 因此许多命令在异常情况下会向用户提示以获取反馈。 这会让这种使用场景变得困难,因为服务器进程会挂起等待用户输入。

将变量 inhibit-interaction 绑定为非 nil 值, 会让 Emacs 触发一个 inhibited-interaction 错误, 而不是弹出提示,服务器进程可以利用这一点来处理这些情况。

典型使用示例:

(let ((inhibit-interaction t))
  (respond-to-client
   (condition-case err
       (my-client-handling-function)
     (inhibited-interaction err))))

如果 my-client-handling-function 最终调用了 需要向用户询问信息的函数(通过 y-or-n-pread-from-minibuffer 等), 则会触发 inhibited-interaction 错误。 服务器代码可以捕获该错误并将其报告给客户端。

emacs

Emacs

org-mode

Orgmode

Donations

打赏

Copyright

© Jasper Hsu

Creative Commons

Creative Commons

Attribute

Attribute

Noncommercial

Noncommercial

Share Alike

Share Alike