4

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?

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
hekevintran
  • 22,822
  • 32
  • 111
  • 180
  • sort of offtopic, but how'd you get it all set up? is there a good tutorial? (I've never managed to get rudel properly working) – unhammer Apr 11 '12 at 14:09
  • I cannot remember exactly, but Rudel was not simple to set up and I never got it to work 100% correctly. Even when it did work, my and my partner's buffers would often get out of sync within an hour of working. I gave up on using Rudel. These days I prefer to use tmux or GNU Screen to share a text terminal running Emacs. The downside is that this method allows only one person to type at a time. In my opinion this is better anyway since it forces you to do more collaboration. – hekevintran Apr 11 '12 at 19:25
  • That's what I use now, tmux with emacs multi-tty. But we can type at the same time (this method http://www.emacswiki.org/emacs/tmux_for_collaborative_editing ), but I think isearch and such gets a bit messed up … – unhammer Apr 12 '12 at 06:15

2 Answers2

3

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.

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
0

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.

Michael Warner
  • 464
  • 1
  • 5
  • 13