What is Sublime Text doing when I save a file?
Asked Answered
F

2

36

I was watching files with fsnotify which is a Go library, and I found there are many events triggered when I save a file.

Why does Sublime Text do so much?

2013/12/17 20:46:25 event: "parser.go": MODIFY
2013/12/17 20:46:25 event: ".subl317.tmp": MODIFY
2013/12/17 20:46:25 event: "parser.go": DELETE
2013/12/17 20:46:25 event: ".subl317.tmp": DELETE
2013/12/17 20:46:25 event: "parser.go": CREATE
2013/12/17 20:46:27 event: "parser.go": MODIFY
2013/12/17 20:46:27 event: ".subl3aa.tmp": MODIFY
2013/12/17 20:46:28 event: ".subl28d.tmp": CREATE
2013/12/17 20:46:28 event: ".subl28d.tmp": MODIFY
2013/12/17 20:46:28 event: "parser.go": MODIFY
2013/12/17 20:46:28 event: ".subl3aa.tmp": MODIFY
2013/12/17 20:46:28 event: "parser.go": DELETE
2013/12/17 20:46:28 event: ".subl3aa.tmp": DELETE
Fiddlehead answered 17/12, 2013 at 12:52 Comment(0)
U
74

Sublime Text 3 (which I assume you're using) uses atomic saves by default (it can be disabled by setting "atomic_save": false in your user settings), which means it creates temp files and then overwrites the original file (and deletes the temp file) on save. See this thread on the Sublime forums for a little more info, especially the reply from jps (Sublime's author) on its disadvantages.

Basically, atomic saving is useful because if anything were to happen during saving you (theoretically) shouldn't end up with a corrupted original file. Downsides include potential loss of file metadata (although Sublime uses native OS X and Windows APIs to prevent that), unexpected behavior in directories with nonstandard permissions (for example, they allow modification of existing files, but not the creation of new ones), and issues when saving to some network drives or services like Dropbox, which I've experienced personally.

EDIT

Since I originally answered this, I've come across a number of questions where post-save file-watching compilers/preprocessors like LESS/SASS/SCSS, Guard, etc. were not doing their thing because the original file they were watching had been deleted by atomic saving, then created again, but they weren't watching it any more. It can also severely affect file I/O speed when working with network filesystems, SSHFS in particular. It's a good idea in theory, but it can wreak havoc if you don't know it's there or what it's doing, so if you'll be doing any kind of work on networked/shared/watched files, it's probably best just to turn it off. Just go to Preferences -> Settings-User and add this line

"atomic_save": false

to the end (the file has to be valid JSON, so make sure there's a comma , after the previous line). Save, and you're good to go!

UPDATE

As of Sublime Text 3 Build 3072, atomic_save is now disabled by default! If you are a registered user, you can download the latest development build here. This feature has not been ported to the public beta (currently Build 3065), but hopefully a new version will be released soon. As of Feb/March 2015, Sublime's development pace has picked up substantially, with a number of new features having been added. Once the bugs have been worked out of them, a new public version should be forthcoming.

update to the UPDATE

"atomic_save": false is (as of March 2015) now in the default settings from Build 3080 and higher.

Ursula answered 17/12, 2013 at 16:11 Comment(7)
I was experiencing random failures using jsx watch where it complained about missing files/directories. Turning atomic saves off seems to do the trick, thanks! facebook.github.io/react/docs/tooling-integration.htmlBrianna
I had the same problem as described above for file-watching compilers/preprocessors like LESS/SASS/SCSS, but with the Plone library sauna.reload. Setting "atomic_save" to false solves the reloading problem. Thanks!Incisive
I experienced a problem with lsyncd on saving files on OSX. The saved file just was not transferred to the remote server. Disabling atomic_save solved this issue.Hammurabi
this didn't solve the problem, im using dev channel build 3095. and it adds x permissions to the file I save. I am coding in windows and the files are being accessed through samba.Tomfool
@Tomfool that's a different issue than what's being described hereUrsula
Oh sorry, didn't notice that. I was actually planning to comment on an issue that's linked to this one. @UrsulaTomfool
this was helpful in understanding why npm packages nodemon and pm2 --watch were not playing nice with docker containers with volume mountsWitless
D
2

If it is related to name.php file,and after saving you are getting another name.php-tmp file, then you can remove PHPTools package From Preference ->Browse Packages, It will be rectified.

Discern answered 13/2, 2016 at 14:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.