summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/support/cluttex/src/cluttex.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/doc/support/cluttex/src/cluttex.lua')
-rw-r--r--Master/texmf-dist/doc/support/cluttex/src/cluttex.lua92
1 files changed, 77 insertions, 15 deletions
diff --git a/Master/texmf-dist/doc/support/cluttex/src/cluttex.lua b/Master/texmf-dist/doc/support/cluttex/src/cluttex.lua
index 0e56e8bf4bd..92952af58df 100644
--- a/Master/texmf-dist/doc/support/cluttex/src/cluttex.lua
+++ b/Master/texmf-dist/doc/support/cluttex/src/cluttex.lua
@@ -18,7 +18,7 @@
along with ClutTeX. If not, see <http://www.gnu.org/licenses/>.
]]
-CLUTTEX_VERSION = "v0.2"
+CLUTTEX_VERSION = "v0.3"
-- Standard libraries
local table = table
@@ -45,6 +45,8 @@ local message = require "texrunner.message"
local extract_bibtex_from_aux_file = require "texrunner.auxfile".extract_bibtex_from_aux_file
local handle_cluttex_options = require "texrunner.handleoption".handle_cluttex_options
+os.setlocale("", "ctype") -- Workaround for recent Universal CRT
+
-- arguments: input file name, jobname, etc...
local function genOutputDirectory(...)
-- The name of the temporary directory is based on the path of input file.
@@ -491,6 +493,7 @@ end
if options.watch then
-- Watch mode
local success, status = do_typeset()
+ -- TODO: filenames here can be UTF-8 if command_line_encoding=utf-8
local filelist, filemap = reruncheck.parse_recorder_file(recorderfile, options)
if engine.is_luatex and fsutil.isfile(recorderfile2) then
filelist, filemap = reruncheck.parse_recorder_file(recorderfile2, options, filelist, filemap)
@@ -501,28 +504,87 @@ if options.watch then
table.insert(input_files_to_watch, fileinfo.abspath)
end
end
- local fswatch_command = {"fswatch", "--event=Updated", "--"}
- for _,path in ipairs(input_files_to_watch) do
- table.insert(fswatch_command, shellutil.escape(path))
- end
- if CLUTTEX_VERBOSITY >= 1 then
- message.exec(table.concat(fswatch_command, " "))
+ local fswatcherlib
+ if os.type == "windows" then
+ -- Windows: Try built-in filesystem watcher
+ local succ, result = pcall(require, "texrunner.fswatcher_windows")
+ if not succ and CLUTTEX_VERBOSITY >= 1 then
+ message.warn("Failed to load texrunner.fswatcher_windows: " .. result)
+ end
+ fswatcherlib = result
end
- local fswatch = assert(io.popen(table.concat(fswatch_command, " "), "r"))
- for l in fswatch:lines() do
- local found = false
+ if fswatcherlib then
+ if CLUTTEX_VERBOSITY >= 2 then
+ message.info("Using built-in filesystem watcher for Windows")
+ end
+ local watcher = assert(fswatcherlib.new())
for _,path in ipairs(input_files_to_watch) do
- if l == path then
- found = true
- break
- end
+ assert(watcher:add_file(path))
end
- if found then
+ while true do
+ local result = assert(watcher:next())
+ if CLUTTEX_VERBOSITY >= 2 then
+ message.info(string.format("%s %s"), result.action, result.path)
+ end
local success, status = do_typeset()
if not success then
-- Not successful
end
end
+ elseif shellutil.has_command("fswatch") then
+ local fswatch_command = {"fswatch", "--event=Updated", "--"}
+ for _,path in ipairs(input_files_to_watch) do
+ table.insert(fswatch_command, shellutil.escape(path))
+ end
+ local fswatch_command_str = table.concat(fswatch_command, " ")
+ if CLUTTEX_VERBOSITY >= 1 then
+ message.exec(fswatch_command_str)
+ end
+ local fswatch = assert(io.popen(fswatch_command_str, "r"))
+ for l in fswatch:lines() do
+ local found = false
+ for _,path in ipairs(input_files_to_watch) do
+ if l == path then
+ found = true
+ break
+ end
+ end
+ if found then
+ local success, status = do_typeset()
+ if not success then
+ -- Not successful
+ end
+ end
+ end
+ elseif shellutil.has_command("inotifywait") then
+ local inotifywait_command = {"inotifywait", "--monitor", "--event=modify", "--event=attrib", "--format=%w", "--quiet"}
+ for _,path in ipairs(input_files_to_watch) do
+ table.insert(inotifywait_command, shellutil.escape(path))
+ end
+ local inotifywait_command_str = table.concat(inotifywait_command, " ")
+ if CLUTTEX_VERBOSITY >= 1 then
+ message.exec(inotifywait_command_str)
+ end
+ local inotifywait = assert(io.popen(inotifywait_command_str, "r"))
+ for l in inotifywait:lines() do
+ local found = false
+ for _,path in ipairs(input_files_to_watch) do
+ if l == path then
+ found = true
+ break
+ end
+ end
+ if found then
+ local success, status = do_typeset()
+ if not success then
+ -- Not successful
+ end
+ end
+ end
+ else
+ message.error("Could not watch files because neither `fswatch' nor `inotifywait' was installed.")
+ message.info("See ClutTeX's manual for details.")
+ os.exit(1)
end
else