Skip to content

Commit

Permalink
Rewriting the docs showed the names of the filers for the watcher are…
Browse files Browse the repository at this point in the history
… misleading

The keywords `only`/`not` give the options a very final sounding. Also
`only` is not really true depending on the setting (depends on what the
previous filters did).

Thus, these keywords in the options are renamed to
`inc`(lude)/`exc`(lude). In order to avoid confusion with the `inc-exc`
option (which otherwise would really close to `inc-ext`), this option
is also renamed to `filter`.
  • Loading branch information
atticus-sullivan committed Jan 6, 2025
1 parent 5bcdda1 commit aac6f1c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 47 deletions.
8 changes: 4 additions & 4 deletions args.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
| verbose | verbose | V | - |
| version | version | v | - |
| watch | watch[=watch] | - | auto |
| watch_exc_ext | watch-exc-ext=watch_exc_ext | - | - |
| watch_exc_path | watch-exc-path=watch_exc_path | - | - |
| watch_inc_exc | - | - | - |
| watch_not_ext | watch-not-ext=watch_not_ext | - | - |
| watch_not_path | watch-not-path=watch_not_path | - | - |
| watch_only_ext | watch-only-ext=watch_only_ext | - | - |
| watch_only_path | watch-only-path=watch_only_path | - | - |
| watch_inc_ext | watch-inc-ext=watch_inc_ext | - | - |
| watch_inc_path | watch-inc-path=watch_inc_path | - | - |
8 changes: 4 additions & 4 deletions doc/args.tex
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
verbose & verbose & V & - \\
version & version & v & - \\
watch & watch[=watch] & - & auto \\
watch\_exc\_ext & watch-exc-ext=watch\_exc\_ext & - & - \\
watch\_exc\_path & watch-exc-path=watch\_exc\_path & - & - \\
watch\_inc\_exc & - & - & - \\
watch\_not\_ext & watch-not-ext=watch\_not\_ext & - & - \\
watch\_not\_path & watch-not-path=watch\_not\_path & - & - \\
watch\_only\_ext & watch-only-ext=watch\_only\_ext & - & - \\
watch\_only\_path & watch-only-path=watch\_only\_path & - & - \\
watch\_inc\_ext & watch-inc-ext=watch\_inc\_ext & - & - \\
watch\_inc\_path & watch-inc-path=watch\_inc\_path & - & - \\
\bottomrule
\end{longtable}
22 changes: 11 additions & 11 deletions doc/cluttealtex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1040,31 +1040,31 @@ \subsubsection{Watch Mode}
% doc new=2025-01-01,
% doc updated=2025-01-01,
doc keypath=cli,
doc name=watch-not-ext,
doc name=watch-exc-ext,
doc parameter={=\meta{ext}},
doc description={default: none, initial: none},
},
{
% doc new=2025-01-01,
% doc updated=2025-01-01,
doc keypath=cli,
doc name=watch-not-path,
doc name=watch-exc-path,
doc parameter={=\meta{path}},
doc description={default: none, initial: none},
},
{
% doc new=2025-01-01,
% doc updated=2025-01-01,
doc keypath=cli,
doc name=watch-ext,
doc name=watch-inc-ext,
doc parameter={=\meta{ext}},
doc description={default: none, initial: none},
},
{
% doc new=2025-01-01,
% doc updated=2025-01-01,
doc keypath=cli,
doc name=watch-path,
doc name=watch-inc-path,
doc parameter={=\meta{path}},
doc description={default: none, initial: none},
},
Expand All @@ -1084,8 +1084,8 @@ \subsubsection{Watch Mode}
\begin{itemize}
\item[Note:] The order of the argument matters.
\item[Note:] No matter which of these options you use, the default is always to not watch a file.
So by only using \texttt{--watch-not-path=./aux/} you will end up by not watching any path.
You can of course change this by specifying \texttt{--watch-only-path=/} before.
So by only using \texttt{--watch-exc-path=./aux/} you will end up by not watching any path.
You can of course change this by specifying \texttt{--watch-inc-path=/} before.
\end{itemize}
\end{docKeys}

Expand Down Expand Up @@ -1325,8 +1325,8 @@ \subsubsection{Filter watched files}

There are the following \emph{rules}:
\begin{itemize}
\item \iboxcmd{not} files matching this rule will be excluded
\item \iboxcmd{only} files matching this rule will be included
\item \iboxcmd{exc} files matching this rule will be excluded
\item \iboxcmd{inc} files matching this rule will be included
\end{itemize}
and the following \emph{matchers}:
\begin{itemize}
Expand All @@ -1336,15 +1336,15 @@ \subsubsection{Filter watched files}

\begin{itemize}
\item[Note:] A file continues to traverse the filters even if it was matched.
So for example \texttt{watch-only-ext="tex" watch-not-path="/usr/local/texlive"} will watch all \texttt{tex} files except the ones located in \texttt{/usr/local/texlive}.
So for example \texttt{watch-inc-ext="tex" watch-exc-path="/usr/local/texlive"} will watch all \texttt{tex} files except the ones located in \texttt{/usr/local/texlive}.
\end{itemize}

This is what happens to each file that is being a candidate for being watched:
\begin{enumerate}
\item (In case you did not define any filtering (none of \texttt{watch-\{not,only\}-\{path,ext\}} passed), the file is marked was being watched and the following steps are skipped)
\item (In case you did not define any filtering (none of \texttt{watch-\{inc,exc\}-\{path,ext\}} passed), the file is marked was being watched and the following steps are skipped)
\item The file always begins as being marked as \emph{not watched}
\item Then it traverses all filters and might change (multiple times, no stopping if one filter matches\footnote{
This enables you to use \texttt{--watch-only-path=/} to change the default easily
This enables you to use \texttt{--watch-inc-path=/} to change the default easily
}) its state.
\end{enumerate}

Expand Down
40 changes: 20 additions & 20 deletions src_teal/texrunner/option_spec.tl
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,14 @@ _M.spec = {
text = "Watch input files for change (Supported: auto, fswatch, inotifywait)\n[initial: auto]",
},
},
watch_only_path = {
long = "watch-only-path",
watch_inc_path = {
long = "watch-inc-path",
param = true,
no_cfg = true,
handle_cli = function(options:option_t.Options, param:string|boolean)
if param is string then
options.watch_inc_exc = options.watch_inc_exc or {}
table.insert(options.watch_inc_exc, {param=pathutil.abspath(param),type='only_path'})
options.watch_filter = options.watch_filter or {}
table.insert(options.watch_filter, {param=pathutil.abspath(param),type='inc_path'})
else
error("invalid param type")
end
Expand All @@ -342,14 +342,14 @@ _M.spec = {
text = "Add filter to which files are being watched",
},
},
watch_not_path = {
long = "watch-not-path",
watch_exc_path = {
long = "watch-exc-path",
param = true,
no_cfg = true,
handle_cli = function(options:option_t.Options, param:string|boolean)
if param is string then
options.watch_inc_exc = options.watch_inc_exc or {}
table.insert(options.watch_inc_exc, {param=pathutil.abspath(param),type='not_path'})
options.watch_filter = options.watch_filter or {}
table.insert(options.watch_filter, {param=pathutil.abspath(param),type='exc_path'})
else
error("invalid param type")
end
Expand All @@ -360,14 +360,14 @@ _M.spec = {
text = "Add filter to which files are not being watched",
},
},
watch_only_ext = {
long = "watch-only-ext",
watch_inc_ext = {
long = "watch-inc-ext",
param = true,
no_cfg = true,
handle_cli = function(options:option_t.Options, param:string|boolean)
if param is string then
options.watch_inc_exc = options.watch_inc_exc or {}
table.insert(options.watch_inc_exc, {param=param,type='only_ext'})
options.watch_filter = options.watch_filter or {}
table.insert(options.watch_filter, {param=param,type='inc_ext'})
else
error("invalid param type")
end
Expand All @@ -378,14 +378,14 @@ _M.spec = {
text = "Add filter to which extensions are being watched",
},
},
watch_not_ext = {
long = "watch-not-ext",
watch_exc_ext = {
long = "watch-exc-ext",
param = true,
no_cfg = true,
handle_cli = function(options:option_t.Options, param:string|boolean)
if param is string then
options.watch_inc_exc = options.watch_inc_exc or {}
table.insert(options.watch_inc_exc, {param=param,type='not_ext'})
options.watch_filter = options.watch_filter or {}
table.insert(options.watch_filter, {param=param,type='exc_ext'})
else
error("invalid param type")
end
Expand All @@ -396,14 +396,14 @@ _M.spec = {
text = "Add filter to which extensions are not being watched",
},
},
watch_inc_exc = {
watch_filter = {
no_cli = true,
accumulate = true,
handle_cfg = function(options:option_t.Options, param: {any})
for _,i in ipairs(param) do
if i is option_t.WatchIncExc then
if i.type and i.param and (i.type == "not_ext" or i.type == "only_ext" or i.type == "not_path" or i.type == "only_path") then
table.insert(options.watch_inc_exc, i)
if i is option_t.WatchFilter then
if i.type and i.param and (i.type == "exc_ext" or i.type == "inc_ext" or i.type == "exc_path" or i.type == "inc_path") then
table.insert(options.watch_filter, i)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions src_teal/texrunner/option_type.tl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ local record Module
synctex: string
tex_extraoptions: {string}
watch: string
watch_inc_exc: {WatchIncExc}
watch_filter: {WatchFilter}
fmt: string
makeindex: string
sagetex: string
Expand All @@ -43,7 +43,7 @@ local record Module

hooks: Hooks
end
record WatchIncExc
record WatchFilter
type: string
param: string
end
Expand Down
12 changes: 6 additions & 6 deletions src_teal/texrunner/watcher.tl
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,30 @@ else
end

-- Helper function to determine whether a file should be watched based on user-specified filters
local function should_watch_file(fileinfo:common_t.Filemap_ele, filters: {options.WatchIncExc}): boolean
local function should_watch_file(fileinfo:common_t.Filemap_ele, filters: {options.WatchFilter}): boolean
if not filters then
-- If no filters are provided, watch all files by default
return true
end
local watch = false
-- Loop through all filters and apply the inclusion/exclusion rules
for _,v in ipairs(filters) do
if v.type == "only_path" then
if v.type == "inc_path" then
-- Watch only files with a matching path prefix
if string.sub(fileinfo.abspath, 1, #v.param) == v.param then
watch = true
end
elseif v.type == "only_ext" then
elseif v.type == "inc_ext" then
-- Watch only files with a matching extension
if pathutil.ext(fileinfo.abspath) == v.param then
watch = true
end
elseif v.type == "not_path" then
elseif v.type == "exc_path" then
-- Exclude files with a matching path prefix
if string.sub(fileinfo.abspath, 1, #v.param) == v.param then
watch = false
end
elseif v.type == "not_ext" then
elseif v.type == "exc_ext" then
-- Exclude files with a matching extension
if pathutil.ext(fileinfo.abspath) == v.param then
watch = false
Expand All @@ -74,7 +74,7 @@ local function gather_input_files_to_watch(max_watches: integer, options: option
-- Iterate over the file list to determine files eligible for watching
for _,fileinfo in ipairs(filelist) do
if fileinfo.kind == "input" then
if should_watch_file(fileinfo, options.watch_inc_exc) then
if should_watch_file(fileinfo, options.watch_filter) then
table.insert(input_files_to_watch, fileinfo.abspath)
end
end
Expand Down

0 comments on commit aac6f1c

Please sign in to comment.