From 1ba3043f397d3b9bb3acbc00100a4854903603cb Mon Sep 17 00:00:00 2001 From: "Billy.Zheng" Date: Thu, 19 Aug 2021 14:40:02 +0800 Subject: [PATCH 1/2] Ignore emacs backup/swap files by default. --- lib/listen/silencer.rb | 3 +++ spec/lib/listen/silencer_spec.rb | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/listen/silencer.rb b/lib/listen/silencer.rb index b0156b90..8f0657ba 100644 --- a/lib/listen/silencer.rb +++ b/lib/listen/silencer.rb @@ -34,6 +34,9 @@ class Silencer | \.swpx | ^4913 + # Emacs backup/swap files + | (?:\.\#.+|\#.+\#) + # Sed temporary files - but without actual words, like 'sedatives' | (?:^ sed diff --git a/spec/lib/listen/silencer_spec.rb b/spec/lib/listen/silencer_spec.rb index 8d4145fa..aad4ae2f 100644 --- a/spec/lib/listen/silencer_spec.rb +++ b/spec/lib/listen/silencer_spec.rb @@ -34,6 +34,9 @@ # Vim swap files ignored += %w[foo.swp foo.swx foo.swpx 4913] + # Emacs backup/swap files + ignored += %w[#hello.rb# .#hello.rb] + # sed temp files ignored += %w[sedq7eVAR sed86w1kB] From 5aa8cc797570ce9a807d0d3cedfd33e6e3c99d6d Mon Sep 17 00:00:00 2001 From: "Billy.Zheng" Date: Sun, 29 Aug 2021 00:56:24 +0800 Subject: [PATCH 2/2] Refactor to use \A \z instead of ^ $ in ignore regexp pattern. --- README.md | 4 ++-- lib/listen/silencer.rb | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c63359be..a0b145d9 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ listener.stop # stop both listening to changes and processing them ### Ignore / ignore! -`Listen` ignores some directories and extensions by default (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer). +`Listen` ignores some directories and extensions by default (See DEFAULT_IGNORED_FILES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer). You can add ignoring patterns with the `ignore` option/method or overwrite default with `ignore!` option/method. ``` ruby @@ -157,7 +157,7 @@ All the following options can be set through the `Listen.to` after the directory ```ruby ignore: [%r{/foo/bar}, /\.pid$/, /\.coffee$/] # Ignore a list of paths - # default: See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer + # default: See DEFAULT_IGNORED_FILES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer ignore!: %r{/foo/bar} # Same as ignore options, but overwrite default ignored paths. diff --git a/lib/listen/silencer.rb b/lib/listen/silencer.rb index 8f0657ba..7253a8b8 100644 --- a/lib/listen/silencer.rb +++ b/lib/listen/silencer.rb @@ -3,8 +3,8 @@ module Listen class Silencer # The default list of directories that get ignored. - DEFAULT_IGNORED_DIRECTORIES = %r{^(?: - \.git + DEFAULT_IGNORED_FILES = %r{\A(?: + \.git | \.svn | \.hg | \.rbx @@ -13,8 +13,12 @@ class Silencer | vendor/bundle | log | tmp - |vendor/ruby - )(/|$)}x.freeze + | vendor/ruby + + # emacs temp files + | \#.+\# + | \.\#.+ + )(/|\z)}x.freeze # The default list of files that get ignored. DEFAULT_IGNORED_EXTENSIONS = %r{(?: @@ -34,11 +38,8 @@ class Silencer | \.swpx | ^4913 - # Emacs backup/swap files - | (?:\.\#.+|\#.+\#) - # Sed temporary files - but without actual words, like 'sedatives' - | (?:^ + | (?:\A sed (?: @@ -58,7 +59,7 @@ class Silencer | \.DS_Store | \.tmp | ~ - )$}x.freeze + )\z}x.freeze # TODO: deprecate these mutators; use attr_reader instead attr_accessor :only_patterns, :ignore_patterns @@ -92,7 +93,7 @@ def _only?(path) def _init_ignores(ignores, overrides) patterns = [] unless overrides - patterns << DEFAULT_IGNORED_DIRECTORIES + patterns << DEFAULT_IGNORED_FILES patterns << DEFAULT_IGNORED_EXTENSIONS end