Emacs 协作缓冲区以错误的模式打开

发布于 2024-08-23 12:37:06 字数 272 浏览 5 评论 0原文

我正在使用 Emacs 和 Rudel 与远程程序员协作。 Rudel 有一个已发布缓冲区的概念。当我的合作伙伴发布缓冲区时,我可以订阅它,并且我们可以同时编辑它。

我的问题是,当他发布带有 *.py 扩展名的 Python 文件并且我订阅它时,我的缓冲区不会自动设置为 python 模式(它处于基本模式)。我怎样才能得到它,以便缓冲区以正确的语言模式打开?

I am using Emacs and Rudel to collaborate with a remote programmer. Rudel has a concept of published buffers. When my partner publishes a buffer, I can subscribe to it and the we can both edit it simultaneously.

My problem is that when he publishes a Python file with a *.py extension and I subscribe to it, my buffer is not set to python-mode automatically (it is in fundamental mode). How can I get it so that the buffer opens with the correct language mode?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长途伴 2024-08-30 12:37:06

我不太了解 Rudel,无法提供 100% 的解决方案,但您想要做的是这样的:

(add-hook 'rudel-document-attach-hook 'my-rudel-set-mode-appropriately)
(defun my-rudel-set-mode-appropriately (document buffer)
  "try to set the mode appropriately"
  (set-buffer buffer)
  (let ((buffer-file-name ...get-name-from-document...))
    (set-auto-mode)))

仅,您需要替换 ...get-name-from-document...< /code> 代码部分,其中包含计算结果为您想要的文件名的内容,例如,如果缓冲区名为 myfile.py,那么您可以将其更改为 (buffer-名称)。但是,如果缓冲区的名称很奇怪,也许您需要从文档对象中提取名称(Rudel 内部使用文档对象来表示您正在共享的内容)。因此,如果 (buffer-name) 不起作用,您可以尝试 (rudel-suggested-buffer-name document)

即尝试上面的代码,但使用以下行之一:

  (let ((buffer-file-name (buffer-name)))

并且

  (let ((buffer-file-name (rudel-suggested-buffer-name document)))

set-auto-mode 将使用 buffer-file-name 的值来确定主要模式,使用 < a href="http://www.gnu.org/s/emacs/manual/html_node/elisp/Auto-Major-Mode.html" rel="nofollow noreferrer">一般 Emacs 机制。

I don't know Rudel well enough to give a 100% solution, but what you want to do is something like this:

(add-hook 'rudel-document-attach-hook 'my-rudel-set-mode-appropriately)
(defun my-rudel-set-mode-appropriately (document buffer)
  "try to set the mode appropriately"
  (set-buffer buffer)
  (let ((buffer-file-name ...get-name-from-document...))
    (set-auto-mode)))

Only, you need to replace the ...get-name-from-document... portion of the code with something that evaluates to the file name that you want, for example, if the buffer is named myfile.py, then you can change that to (buffer-name). But, if the buffers get odd names, perhaps you need to extract the name from the document object (Rudel internally uses a document object to represent the thing you are sharing). So, if (buffer-name) doesn't work, you can try (rudel-suggested-buffer-name document).

i.e. try the above code but using one of these lines:

  (let ((buffer-file-name (buffer-name)))

and

  (let ((buffer-file-name (rudel-suggested-buffer-name document)))

The set-auto-mode will use value of buffer-file-name to determine the major mode using the general Emacs mechanisms.

夏雨凉 2024-08-30 12:37:06

我对 rudel 的工作原理一无所知。但是,您是否尝试过在文本文件中明确设置模式?尝试将类似这样的内容添加到文件的第一行:

# -*- mode: python; fill-column: 75; comment-column: 50; -*-

在文件中首先添加这样的行将导致 emacs 忽略文件的扩展名并以给定模式打开。

I know absolutely nothing about how rudel works. However, have you tried explicitly setting the mode in the text file? Try adding something like this to the first line of the file:

# -*- mode: python; fill-column: 75; comment-column: 50; -*-

Putting a line like this first in the file will cause emacs to ignore the file's extension and open in the given mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文