1

I am trying to use emacs as an editor with other applications which allow people to open text in an editor (Sublime in this case), save it, and see it updated in the application. For example, in Houdini, a 3D software, I can type code in an external editor (in this case, Sublime), modify, save... and see it update in the application (Houdini). When I use emacs, it doesn't work. As an example, here I am adding a line of text using Sublime in Houdini:

editing text externally using Sublime, step 1

Once I save and close, the text is updated in Houdini, and I can continue working:

text entered and saved in Sublime, step 2, success!

Try as I might, I can't get this to work in emacs. I am sure the file has the same name, and when I save, it confirms the right file path. What am I missing? I have run into the same problem with an application called Joplin: Sublime works, emacs does not.

legoscia
  • 39,593
  • 22
  • 116
  • 167
lumogas
  • 11
  • 1
  • Are you looking for `global-auto-revert-mode`? "Global Auto-Revert Mode is a global minor mode that reverts any buffer associated with a file when the file changes on disk" – Etienne Laurin Aug 10 '20 at 14:14
  • I'm not sure that this is a Sublime Text question since the issue seems to be with getting some external software to run Emacs; the fact that it works in Sublime seems to be incidental. – OdatNurd Aug 10 '20 at 22:00
  • I agree: it's about the external application's protocol for how to invoke an editor and what to do with the result. I suspect a question in a Houdini forum (if such a thing exists) would be the more productive approaach. BTW, assuming you have a long running emacs, I would recommend `M-x server-start` in that emacs session and then using `emacsclient` as the `EDITOR`. – NickD Aug 11 '20 at 13:46
  • Thanks for the replies. Sublime is offered as an example of an editor that is working as expected. Emacs (which I would prefer using) is not. Posting in a Houdini forum would not help: Houdini is opening a specific editor, as requested. The problem is emacs is **not** writing out the temporary file that gets sent back to the application (in this case Houdini and Joplin) whereas Sublime **does** work as expected straight off the bat, with both applications (Houdini and Joplin). – lumogas Aug 11 '20 at 15:24
  • There is still a chance however that the Houdini people have run into the problem and know the answer. In any case, @legoscia's answer below has the ring of truth, so try it out and let us know. If it works, you might also notify the Houdini people about the problem and the solution, so that a future you will find the answer and thank you for asking the question and thank legoscia for providing the answer (if it is indeed correct). – NickD Aug 15 '20 at 03:22
  • Thanks again for the replies. I tried setting backup-by-copying to t, but the issue persists. legoscia's answer, though, does seem have the ring of truth to it, so I will keep exploring in this direction, trying to find out what happens when I'm saving that buffer, and let you know if I manage to stumble onto an answer. – lumogas Aug 16 '20 at 12:23

1 Answers1

2

A wild guess: Emacs has different behaviour when saving files than Sublime, and Houdini gets confused by that.

When you save a file in Emacs, Emacs creates a backup of the previous contents of the file, suffixing the file name with a tilde. By default it does this by renaming the existing file to the backup name, and then writing the contents to the real filename, thereby creating a new file.

(You can observe this by running ls -i before and after: the backup file will have the inode number that the main file had previously. Note that Emacs doesn't make backups after the first save during the same editor session, so you might need to restart Emacs or kill the buffer with C-x k to see this.)

I suspect that Houdini keeps the file open while Emacs is editing it, and so when you save the file from Emacs, the file that Houdini has open is actually the backup file.

You can configure Emacs to make backups by copying instead of renaming by setting the variable backup-by-copying to t. Add this to your ~/.emacs file (creating it if it doesn't exist):

(setq backup-by-copying t)
legoscia
  • 39,593
  • 22
  • 116
  • 167