在所有 运行 个 emacs 实例中执行命令

Executing a command in all running emacs instances

我有两个访问相同项目的 VNC 会话。 我为多个项目打开了多个 emacs 会话。 保存我在 VNC1 上的工作后,当使用 VNC2 时,我需要一种方法来 运行 每个 emacs 中的命令 "update all opened files" 在 VNC2 上 运行ning 以便它与发生的更改同步VNC1.

我已经绑定 F10 来执行 "revert-all-buffers" 所以我需要这个脚本进入每个 emacs 并进行更新。 因此,我希望脚本这样做,而不是我去每个打开的 emacs 并按 "F10"。

关于如何处理这个问题的任何指示?

您可以从这段代码开始并自定义 'synchronize-on-this 函数来执行您想要的任何操作(现在它只打印一条消息)。

(defvar synchronize-file "~/.synchronize" )
(defun synchronize-on-this ()
  (when (string-equal (file-truename synchronize-file) 
                     (file-truename (buffer-file-name)))
    (message "Have synchronized!")))

(find-file-noselect synchronize-file)
(global-auto-revert-mode 1)

(add-hook 'after-revert-hook 'synchronize-on-this)

只需将您的 F10 绑定到一个写入 synchronize-file 的函数,您就可以开始了。您可以将信息存储在同步期间使用的那个文件中 - 或者不使用。