1

new Emacs user (on Windows) here! So far Emacs looks really cool!

I'm developing website using Parcel and every time I save my main .html file with Emacs it breaks my development server. HTML file I use has the same name, I just change contents of the buffer inside Emacs and then save it.

Parcel and Emacs

Parcel says this file just doesn't exist 😵

I think Emacs handles file saving differently than other editors and it's just not what my Parcel likes. Do any of you guys had similar problem? It looks like Emacs deletes file and Parcel just breaks haha.

My Emacs config is brand new, nothing really changed besides color theme and fonts.

4
  • I have a feeling you'll need to provide some more info. E.g. say whether the HTML file that's saved has the same name, or show some of its content, or provide a more exact error message (e.g. that says what - or where - the problem is with the file).
    – Drew
    Commented Jul 24, 2022 at 14:52
  • Hey @PSCHC what font are you using? Commented Jul 24, 2022 at 19:08
  • 1
    @ArchStanton it's Iosevka Slab, you can find it here: typeof.net/Iosevka
    – PSCHC
    Commented Jul 24, 2022 at 19:20
  • Have you tried either telling Parcel to reload its config (assuming Parcel offers this -- I haven't come across it previously) or restarting Parcel? I realize both would be unsatisfactory methods to have to rely on, but it would give us a couple more useful insights. Commented Jul 27, 2022 at 11:59

1 Answer 1

0

The way Emacs saves is the correct way to do things. I’ve never heard of Parcel, so I don’t know how it expects things to work.

What Emacs does is save your buffer to a temporary file in the target directory, waits for that write to finish successfully, and then renames the temporary so that it has the correct name. This probably seems like extra steps, but it avoids data corruption that would happen otherwise.

Suppose Emacs instead overwrote the target file. This would likely involve either truncating the file and then writing the entire contents out, or diffing the files and writing out only those blocks or parts of the file that differ. Either would work most of the time, but they both have unfortunate consequences in the case of errors, hardware failure, loss of power, etc.

Imagine that your power is shut off while you are saving a file. The shutoff could happen before Emacs actually saves anything, in which case the file is left exactly as it was. You lost a little bit of data, but the file is still how you left it so we’ll count that as a win. But suppose the power went out after the file was truncated but before any data was written out. Now you’ve lost everything! You lost your changes, and also the file is now empty, so you lost what was already there. Or perhaps the power goes out after half of the file is written out. Again, you lose your changes and most of what was already there.

Meanwhile, the way Emacs does it guarantees that the existing file is either left intact, or atomically replaced with a complete file. No matter when the power goes out, you never end up with an empty file, or a partially written file. You might end up with the original file plus a temporary file with some or all of your data in it. In that case, when you open the original file Emacs will point out that the temporary exists and will ask you what you want to do with it.

You might want to read Files are Hard which explains the pitfalls in more detail. This is talking about Linux, but Windows has the same sort of problems; only the names change.

I don’t know exactly how Parcel is going wrong. It might be that it has opened the file once and is trying to keep using it. Since Emacs has replaced the file, the original is no longer available. (Interestingly, on Linux the original would still be available even after it was replaced. Parcel probably wouldn’t fail, but would continue to serve the old contents of the file). It sounds like Parcel needs to close the file and reopen it, now that there is a new file there with that name.

Either way, you should file a bug report over on their Github repository, if nobody else has already done so.

1
  • Thank you for your answer! It helps me to understand quite a bit! Thank you for "Files are hard" recommendation! I'm gonna read it for sure! Github bug report is great way to go for sure!
    – PSCHC
    Commented Jul 24, 2022 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.