Mercurial > org-tools
view auto-weave.pl @ 9:d09937a6cb4b
trying to build something to automatically refresh the browser.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 25 Oct 2011 05:33:36 -0700 |
parents | 73beed20f7de |
children | 24ff8a9c76c4 |
line wrap: on
line source
1 #!/usr/bin/perl3 use Linux::Inotify2;4 use AnyEvent;7 my $inotify = new Linux::Inotify28 or die "unable to create new inotify object: $!";11 @org_files = glob("./org/*.org");13 $" = "\n";14 print "@org_files\n";16 $ignore_next = 0;19 foreach(@org_files){20 # add watchers21 $inotify->watch ($_, IN_MODIFY, sub22 {23 print ("IGNORE : $ignore_next\n");24 # ok, for some reason this get's called exactly25 # twice every time the file is saved from emacs.26 # so ignore every other invocation.27 if ($ignore_next) {28 $ignore_next = 0;29 return;30 }32 my $e = shift;33 my $name = $e->fullname;34 print "$name was modified\n" if $e->IN_MODIFY;35 $output = `weave $name`;36 print ("$name\n");37 $path = `readlink -f $name`;38 $path =~ s|/home/r/proj|http://aurellem.localhost|;39 print ("$path\n");40 $path =~ s|org|html|g;41 print ("$path\n");42 #system ("firefox $path");43 $ignore_next = 1;45 });46 }51 # integration into AnyEvent (works with EV, Glib, Tk, POE...)52 #my $inotify_w = AnyEvent->io53 # (54 # fh => $inotify->fileno, poll => 'r', cb => sub { $inotify->poll }55 # );57 # manual event loop58 1 while $inotify->poll;