thlorenz / replpad

Pipes content of files to a node repl whenever they change to enable a highly interactive coding experience.
http://thlorenz.github.com/replpad/
MIT License
213 stars 19 forks source link

replpad refuses to re-read files once they're saved #7

Open toddself opened 11 years ago

toddself commented 11 years ago

OS: Mac 10.8.4 iTerm2 replpad v0.11.1

node v0.10.18 | Calvin | 8 cpus | darwin platform | v8 v3.14.5.9 | uv v0.10.15

Editors tried: Sublime Text 3 and vim

Issue:

Launching replpad . enumerates the .js files in the directory. Opening and saving one of them causes replpad to correctly re-read the file.

Making more changes and saving it does not ever cause replpad to re-save.

replpadbug

thlorenz commented 10 years ago

I'm about to close this since no one else ever reported this issue or added comments to this one.

Is this working better for you now?

toddself commented 10 years ago

Nope :).

Brand new machine -- same issue.

replpad v0.11.8

node v0.10.28 | NewOSX | 8 cpus | darwin platform | v8 v3.14.5.9 | uv v0.10.27

I'll try to look at it one day.

thlorenz commented 10 years ago

really friggin weird is all I can say

benrhughes commented 10 years ago

FWIW I'm seeing exactly the same behavior. The first save of any monitored file is detected, but no further changes are.

For me it seems to be related to vim. I can echo into a file (or even just touch it), and replpad picks it up just fine. However with vim, it only ever picks up the first save. Once it stops picking up changes, it never starts again. So, if I edit in vim, then touch the file, replpad doesn't trigger.

replpad v0.11.8 node v0.10.29 | xps | 8 cpus | linux platform | v8 v3.14.5.9 | uv v0.10.27

thlorenz commented 10 years ago

Interesting find, does it work with other editors? Maybe your vim setup is different somehow.

I installed mine via brew install macvim --override-system-vim.

Overall seems to be a vim issue though since somehow it doesn't trigger the file change event that replpad depends on.

toddself commented 10 years ago

Doesn't matter what editor - vim, sublime, atom, emacs -- all the same result.

benrhughes commented 10 years ago

I don't imagine vim is particularly unusual in how it writes files, but I can try some other editors tomorrow to confirm.

From a quick glance at your dependencies I'm not sure how you're doing the file watching, but I've successfully used watchr in the past. It certainly works with vim IME.

Cheers,

Ben On 13 Jun 2014 00:12, "Thorsten Lorenz" notifications@github.com wrote:

Interesting find, does it work with other editors? Maybe your guy's vim setup is different somehow.

I installed mine via brew install macvim --override-system-vim.

Overall seems to be a vim issue though since somehow it doesn't trigger the file change event that replpad depends on.

— Reply to this email directly or view it on GitHub https://github.com/thlorenz/replpad/issues/7#issuecomment-45896100.

thlorenz commented 10 years ago

The watcher stuff is here.

I'm open to have that swapped out with a dependency however. The key is though that it needs to be able to pick up newly created files as well and not fire too often, i.e. twice per save (which some of them do).

benrhughes commented 10 years ago

Watchr seems to behave well in those regards (I use it to trigger cache invalidation when a new file is created).

I'll see if I can find some time to swap it in, and if it fixes my problem I'll send you a PR. On 13 Jun 2014 00:34, "Thorsten Lorenz" notifications@github.com wrote:

The watcher stuff is here https://github.com/thlorenz/replpad/blob/master/lib/watcher.js.

I'm open to have that swapped out with a dependency however. The key is though that it needs to be able to pick up newly created files as well and not fire too often, i.e. twice per save (which some of them do).

— Reply to this email directly or view it on GitHub https://github.com/thlorenz/replpad/issues/7#issuecomment-45899107.

thlorenz commented 10 years ago

Would love a PR @benrhughes. Feel free to reach out if you have any questions and/or even submit a semi working PR that we can improve on.

benrhughes commented 10 years ago

OK, after a bit of investigation, this seems to be a problem with fs.watch, not your watch code specifically. This bare-bones code appears to have the same issue:

var fs = require('fs');
fs.watch('a.js', {persistent: false}, console.log);
process.openStdin().addListener('data', process.exit);

It appears to still be a problem in 0.11.xx too.

I did some testing and it seems that watchr has the same issue (presumably because it uses fs.watch) - I didn't notice before because I'm using it to detect new files, not updates.

benrhughes commented 10 years ago

According to https://github.com/joyent/node/issues/3172, this is a vim issue (or at least partially a vim issue).

Setting the vim option backupcopy=yes appears to "fix" things, although it leads to the change being detected (and hence the file being loaded) twice.

thlorenz commented 10 years ago

Thanks for digging into this. So seems like this can't be fixed in replpad then? I'm just wondering why @toddself also experiences this with other editors or is it just that the backup=yes is just a hack that makes it work in vim and other editors would need another hack?

Also peculiar why I don't have that problem (and I assume it works for lots of others since I haven't heard about this bug from many). FWIW here is my vimrc maybe I have a setting in there that happens to make it work, although I did turn off swapfiles (not sure how that relates to backupcopy).

toddself commented 10 years ago

In sublime if you set: "atomic_save": false in your user preferences it fixes this issue as well in this editor. Perhaps updating the documentation to explain?

thlorenz commented 10 years ago

Yeah including this in the docs would be nice indeed. We could document how to configure specific editors to play nice with replpad.

wildeyes commented 10 years ago

I tried setting all the various backup options in various combinations, still can't make replpad eval once via Vim. :(

dylnb commented 10 years ago

I just came across replpad today, installed it, and was experiencing the same issue that @toddself originally reported: replpad would pipe over whatever it found the very first time I saved a file (actually it would pipe it over twice), but would not react to anything after that. Adding backupcopy=yes to my vimrc seems to have solved the problem.