Skip to content

Commit

Permalink
Add exclusions config option to exclude things like temp files (#62)
Browse files Browse the repository at this point in the history
Various editors create junk files that wake up exsync, in particular a
mix format on save feature in emacs will create a copy of a file for
mix format to operate on:
foo_bar.ex => foo_bar-emacs-elixir-format.ex

Seeing this, exsync kicks off the elixir compiler and there is an
error about a module being defined in 2 different files.

Being able to exclude files matching ~/-emacs-elixir-format/ solves
this issue.
  • Loading branch information
spacebat authored Jul 14, 2024
1 parent c8eea2f commit d95d5bd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ For example, to watch `.js` and `.css` files add this to your `config.exs`:
config :exsync, extra_extensions: [".js", ".css"]
```

`:exclusions` - List of regular expressions that, if matched, exclude a file from being noticed by exsync.

For example, to exclude Emacs temporary files:

```elixir
config :exsync, exclusions: [~r/#/]
```

`:logging_enabled` - Set to false to disable logging (default true)

`:reload_callback` - A callback [MFA](https://codereviewvideos.com/blog/what-is-mfa-in-elixir/) that is called when a set of files are done reloading. Can be used to implement your own special handling to react to file reloads.
Expand Down
8 changes: 8 additions & 0 deletions lib/exsync/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ defmodule ExSync.Config do
)
end

def src_exclusions do
Application.get_env(
:exsync,
:exclusions,
Application.get_env(:exsync, :exclusions, [])
)
end

def application do
:exsync
end
Expand Down
8 changes: 7 additions & 1 deletion lib/exsync/src_monitor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ defmodule ExSync.SrcMonitor do
# isolation to trigger things.
matching_event? = :modified in events

included? =
!Enum.any?(
ExSync.Config.src_exclusions(),
&Regex.match?(&1, path)
)

state =
if matching_extension? && matching_event? do
if matching_extension? && matching_event? && included? do
maybe_recomplete(state)
else
state
Expand Down

0 comments on commit d95d5bd

Please sign in to comment.