Auto reload changed files


#1

Am I missing a way to have atom just reload files that are changed on disk without prompting me? I tend to log test runs to a file and then keep the file open in my editor, having atom ask me literally dozens of times to reload the same file gets old really fast.

Other than that, I’m quite liking atom, it has a ton of potential.


#2

:+1:

It would be nice to have a live reload of files, without asking ever single time that something new it’s on the file (you can take a look on the attachment). What do you guys think?


#3

Actually on my mac Mavericks with Atom 0.137.0, when file changes externally, I don’t even get a prompt warning me. Is there an option to enable it?


#4

Doesn’t prompt me either (Win 7, Atom 0.153) - it doesn’t update the file at all, which I have to do manually via atom/revert-buffer package. And if it did prompt me, I’d second the feature request of silent updating.


#5

Lots of good questions, no answers… ???

I am too looking for automatic reload, prompt or not. Is there a setting or package missing?


#6

+1 for this feature


#7

I was looking for a way to make Atom prompt me before reloading a file if there were pending modifications and even if the first post was asking for the opposite, I kept ending on this discussion.

For me, Atom v0.196 on Linux automatically reloaded modifies files without prompting me (even if there were modifications pending).

So here is a package I found that fixes this issue : lwblackledge’s File Watcher


#8

The File-Watcher package works as advertised, namely if there is an unsaved edit and somewhere else a change is made and Atom detects the conflict. If no actual conflict (no unsaved edits) in Atom, it will silently reload the file from the changed version on disk.

Works for me, but doesn’t really provide an alert when there ARE changes (e.g., to accept/decline), only on editor conflict.


#9

Hi @jeffmcneill, I had a few people raise that as an issue so I just released an update to file-watcher that adds this as an option.
It is not enabled by default but can be turned on in the package settings.

I hope that helps,

Laurence


#10

Wow, nice! You’ve even given a compare option on change. Very good. Thank you @lwblackledge


#11

I’m glad you like it. I was fighting the order of operations in text-buffer for a while, but I found that registering my file change event then re-registering the ones from text-buffer actually worked.

If you have any problems please raise them on Github :smile:


#12

I tried both
https://github.com/atom/revert-buffer and
https://github.com/lwblackledge/file-watcher
and neither seems to work.
I am on atom v 1.12.
Are there any alternatives?


#13

A buffer that hasn’t been changed from the saved file should automatically update if the file changes from outside.


#14

@Stingery if you can tell me what you are doing specifically I can update file-watcher if I can repro the problem. You can create an issue in GitHub.

Are you using a mounted file system? I added support for mounted files just recently, as it involved intercepting some of the lower level file events and also adding polling. You have to enable it in the package settings first, and reload Atom.


#15

Thanks for the file-watcher package! Works fine so far. I think it should be the default Atom functionality out of the box… a text editor that can so easily lose edits is not a good text editor.


#16

It’s 2018, and this problem still exists? Maybe one of us should finally make a PR.

I tried closing the file, then going to File > Reopen Last Item, and it re-opens it with all the unsaved changes I had last time, which doesn’t help in this case. I’m sure it helps during crashes though.

It seems like an obvious feature to have: reloading a file on demand. Or, maybe it isn’t obvious at all how to do it. Come on guys.


#17

Or maybe Atom already gives you a way.

atom.commands.add "atom-workspace", "custom:revert-to-disk", ->
  atom.workspace.getActiveTextEditor().buffer.reload()

#18

I just overwrote changes to a file by accident, because I was having an old state open and didn’t notice that file was out of sync with the filesystem. Sometimes it refreshes automatically for me but most of the time it does not.

@DamnedScholar, this command means I have to refresh it manually, right? Sorry I’m new to custom atom commands. Well that would be better than having to close and re-open it as I’m currently doing. But having it automatically reload would still be best, in case it changes without me noticing (e.g. a git pull that changes many files).


#19

I believe that it is a more effective strategy to make sure that your files are all saved before you use git commands. Since I know Atom’s behavior, I try to never leave files unsaved longer than absolutely necessary. Sometimes it can be useful to transfer changes across a pull, but that’s only to be done deliberately.

If you want to check every time you open Atom, you can do it like this:

atom.workspace.observeTextEditors (editor) ->
  editor.buffer.reload()

however, that may be destructive if you try to Split Right on an unsaved editor. Whether you have to trigger the reset manually or can automate it depends on how well you can translate your needs into the precise conditional language of the software. The API documentation is extensive and I can explain anything you need.


#20

I see, it’s not a command. It’d be great for there to be a command like “core:reload-current-tab” or similar.