-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Watch for file notifications #31
Comments
I actually have something like this implemented outside of emacs/weblorg. I've built a docker container that expects the weblorg site base dir to me mounted in, and when started, it will build the site (also supports pre and post build scripts via file naming conventions), start up a web server, and continuously monitor for changes to trigger rebuilds. The hard part feels like the determination of what needs to be rebuilt (especially when templates are modified). My container naively rebuilds everything on any file change. I can clean that up and provide an example in the next few days. |
Hi @nanzhong! That would be lovely. Even if we add the file watcher with pure Emacs-Lisp, having a docker setup that people could copy from would be pretty awesome. Off the top of my head, I can think of creating a new directory under What do you think? |
Yup, for sure. Sorry for the delay, it's been a busy week. I'll try and have something up in the next few days. |
No rush @nanzhong! thanks for the heads up and take your time! I hope the week is going great 😄 |
@clarete I've put together #40 with a small change to demonstrate what I've thrown together in https://github.com/nanzhong/weblorg-docker. |
This is very exciting. Thank you so much for putting the docker image together and for integrating the build of the example with it! Thank you so much for the PR @nanzhong! |
On the native file change notification, I did get a little proof of concept going locally but I've noticed that although it works very well while Emacs is in interactive mode, it doesn't really seem to work when I try the very same code under |
Regarding the CLI tool. I actually have another version of this tooling that's written in go. It removes the dependency on I also took a stab at exploring a native file watcher in weblorg, but didn't make much progress. I also realized that I ended up going back and forth on the usability argument for native file watching. This is just my opinion, but I feel like introducing this watcher loop or async watching logic in welorg might not be the most ideal approach unless it can work via If weblorg supported incremental builds where it only rebuilt the pages that needed to be rebuilt (there are a bunch of ways this could potentially work, but I haven't spent too much time thinking about which would make the most sense yet), having a companion cli tool that handles the file watching and triggering the rebuilds feels like a pretty good compromise. That cli tool would have an emacs dependency, but that feels like a reasonable expectation given how weblorg works. |
Hi @nanzhong! Sorry for taking a bit to answer such thoroughly written message. And thanks for sharing such cool ideas! Thank you for spending some time thinking of all these options and I agree with you that the Emacs Lisp solution is mostly appealing if that works with But also, even when we achieve good usability of file watchers purely written in Emacs Lisp, I think this docker setup is still invaluable for weblorg because a lot of people have docker installed in their computers, and it becomes friction free to get started from there. Regarding your thoughts on incremental builds, I agree with you that this isn't exactly a trivial issue. If we get the watchers to work with Once we receive a change notification, we need to sort out the type of changed file parse it and find extends tags in case of templates or include statements if they're org-mode files. We can't be that smart for any other type of file, but we can allow people to hook up arbitrary commands to patterns e.g.: These of course are just thoughts until we understand why registering file notifications work but the file descriptor of inotify within Emacs ( I will dive this weekend and figure out why my build didn't work. I noticed that I didn't have weblorg installed within the container, though templatel was there. That was where I left the debugging but I'll get to the bottom of it soon and report! 😄 Thank you once again for all your thoughts and time on this! Have a great weekend! 🙇🏾 |
I had a bit of spare time today to revisit this. My understanding of emacs internal and emacs lisp is very superficial, so take what I say with a giant grain of salt 😛. I think the reason you're having trouble with the file watches is because of the way emacs batch mode handles events (it doesn't have the usual event loop as in interactive mode) and emacs' threading model (cooperative threads, but still single-threaded). What I think is happening on your branch is that you are either deadlocking or livelocking between the worker and main thread, and not actually allowing the file watch handler to run. I've taken a stab at this and have something basic working (only tested on linux). The general idea is:
The sequence of things is:
Generally this seems to work, but there are some really obvious issues:
I've pushed my basic implementation to https://github.com/nanzhong/weblorg/tree/watch. Feel free to take that and improve on it. cc @clarete |
hi hi @nanzhong this is pretty awesome to say the least. thank you so much for taking the time and for putting together something so fun to play with! What a great hack with the timers! 😄 I've just had some time to look more closely to the code and the watching does seem to work well enough to be worth exploring implementing this feature more seriously. Now that we have a direction on such a deep issue, I think building the dependency graph sounds like a good next task. Since without it, we can't really provide a good implementation of what to do when a notifier event arrives. That might be something that we have to add to templatel first (to be able to map template inheritance into that graph). The other random thought I had was to generate HTML on the fly instead of re-exporting the whole site to disk, and then adding some hot reloading script to integrate nicely with the browser development experience. Hehehe, of course every word I wrote in this last paragraph is worth 50h of Emacs Lisp hacking, so might not happen very soon but it's still worth thinking about it 😺 Fun times! \o/ |
The current build process is currently comprised of scanning the list of all websites within
weblorg--sites
and then scanning all the routes within each site once, and running the pipeline once. That must work well reasonably fast since it's part of the main feature of weblorg. However, while developing themes or even during the process of building the content, it'd be quite helpful if we triggered the build of only the files that were changed.It'd be great if
weblorg-export
could take a:watch
parameter and block forever if that was set to true and re-generate the website over any file changes.at the end of our well known publish.el files we'd do something like
at the terminal we'd do something like this
That'd hang the terminal and print out events every time files got changed.
Notice that this is pretty limited; but if it serves us well, it can be expanded to 1. be smarter about what it watches, maybe by taking something like
:watch-pattern
and:watch-exclude
and then 2. by trying to only re-generate pieces related to the modification. Notice that 2 might get a bit more complicated because if we receive a notification about a change on a template, it's not enough to look for:template
entries in routes, as maybe the template being changed isn't there, but might be in theextends
of another template.The text was updated successfully, but these errors were encountered: