当我保存文件时,Sublime Text 在做什么? [英] What is Sublime Text doing when I save a file?

查看:50
本文介绍了当我保存文件时,Sublime Text 在做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 fsnotify 观看文件,这是一个 Go 库,我发现触发了很多事件当我保存文件时.

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

为什么 Sublime Text 能做这么多?

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

推荐答案

Sublime Text 3(我假设您正在使用)默认使用原子保存(可以通过设置 "atomic_save": false 在您的用户设置中),这意味着它会创建临时文件,然后在保存时覆盖原始文件(并删除临时文件).有关更多信息,请参阅 Sublime 论坛上的此主题信息,尤其是 jps(Sublime 的作者)对其缺点的回复.

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.

基本上,原子保存很有用,因为如果在保存过程中发生任何事情,您(理论上)不应该以损坏的原始文件结束.缺点包括文件元数据的潜在丢失(尽管 Sublime 使用本机 OS X 和 Windows API 来防止这种情况),具有非标准权限的目录中的意外行为(例如,它们允许修改现有文件,但不允许创建新文件),以及保存到某些网络驱动器或服务(如我个人经历过的 Dropbox)时出现问题.

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.

自从我最初回答这个问题以来,我遇到了许多问题,其中 LESS/SASS/SCSS、Guard 等保存后文件监视编译器/预处理器没有做他们的事情,因为他们是原始文件观看已被原子保存删除,然后再次创建,但他们不再观看了.在使用网络文件系统(尤其是 SSHFS)时,它还会严重影响文件 I/O 速度.理论上这是个好主意,但如果你不知道它在那里或它在做什么,它可能会造成严重破坏,所以如果你将在网络/共享/观看文件上做任何类型的工作,最好只是打开它关了.只需转到 Preferences ->设置-用户并添加这一行

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

到最后(文件必须是有效的 JSON,所以请确保有一个逗号 在上一行之后).保存,你就可以开始了!

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!

从 Sublime Text 3 Build 3072 开始,atomic_save 现在默认禁用!如果您是注册用户,您可以在这里下载最新的开发版本.此功能尚未移植到公测版(目前为 Build 3065),但希望很快会发布新版本.截至 2015 年 2 月/3 月,Sublime 的开发速度已大幅加快,并添加了许多新功能.一旦解决了这些错误,新的公共版本应该即将推出.

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

"atomic_save": false 现在是 Build 3080 及更高版本的默认设置(截至 2015 年 3 月).

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

这篇关于当我保存文件时,Sublime Text 在做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆