Updated to release 0.6:

* Remove the .err-file if the compile was succesful.
* Watch the directories of the files that should be watched
  instead of the files themself.
* Look for CLOSE_WRITE events instead of MODIFY.  This makes
  rubberin compatible with vim/gedit/ispell/svn/git/etc.
This commit is contained in:
Paul van Tilburg 2009-03-25 12:51:33 +01:00
parent 06750505d3
commit 5d621b32e8
1 changed files with 16 additions and 7 deletions

View File

@ -68,8 +68,10 @@ def compile(infile, mode)
params = ARGV.join(' ')
err_file = infile.with_extname('err')
system "rubber --inplace #{mode_opt} #{params} #{infile} 2> #{err_file}"
ret = system "rubber --inplace #{mode_opt} #{params} #{infile} 2> #{err_file}"
File.open(err_file) { |file| puts file.read }
# Remove the output save file if compile was succesful.
File.unlink(err_file) if ret
end
# Start the right viewer based on the mode.
@ -97,7 +99,7 @@ end
## Initialisation
Program = File.basename $0
Version = '0.4a'
Version = '0.6'
# Parse the command line options.
# Determine the compile mode from the options.
@ -166,12 +168,19 @@ Signal.trap("CLD") { puts "#{Program}: viewer exited, so will I!"; exit }
# Add input file with dependancies to the watch list and start event loop.
i = Inotify.new
files.each do |file|
i.add_watch(file, Inotify::MODIFY)
dirs = files.map { |file| File.dirname(file) }
dirmap = {}
dirs.each do |dir|
# Use a watch descriptor per directory and save it for later.
wd = i.add_watch(dir, Inotify::CLOSE_WRITE)
dirmap[wd] = dir
end
# Process the events, recompile and reload when necessary.
i.each_event do |ev|
puts "I: file #{ev.name} modified, compiling #{infile}..."
compile(infile, mode)
reload(infile, mode)
# Only recompile if files are modified that we are interested in.
if files.include?(dirmap[ev.wd] + "/" + ev.name)
puts "I: file #{ev.name} modified, compiling #{infile}..."
compile(infile, mode)
reload(infile, mode)
end
end