Emacs shared buffers open incorrectly

I use Emacs and Rudel to collaborate with a remote programmer. Rudel has the concept of published buffers. When my partner publishes a buffer, I can subscribe to it, and we can edit it at the same time.

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

+4
source share
2 answers

I donโ€™t know that Rudel gave a 100% solution well enough, 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 part of the code ...get-name-from-document... code that evaluates the name of the file you want, for example, if the buffer is called myfile.py , then you can change it to (buffer-name) , But if buffers get odd names, maybe you need to extract the name from the document object (Rudel internally uses the document object to represent what 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 the following lines:

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

and

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

set-auto-mode will use the value of buffer-file-name to determine the main mode using common Emacs mechanisms .

+3
source

I know absolutely nothing about how the rudel works. However, did you try to explicitly set 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; -*- 

Entering a line similar to the first in the file will cause emacs to ignore the file extension and open it in the specified mode.

0
source

Source: https://habr.com/ru/post/1303056/


All Articles