Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore emacs backup/swap files by default. #546

Merged
merged 2 commits into from Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/listen/silencer.rb
Expand Up @@ -34,6 +34,9 @@ class Silencer
| \.swpx
| ^4913

# Emacs backup/swap files
| (?:\.\#.+|\#.+\#)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these should be anchored per our discussion on the Issue. And \A and \z are the best way to anchor in Ruby so as not to be tripped up by newlines (which are rare in filenames...but possible). So I think this does it:

(?:\A\.\#.|\A\#.+\#\z)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ColinDKelley , oh, i add to wrong place, i thought where i insert in regexp is around with a ^...$

for \A, \z, agree with you, but why i can't find those anchor within exists regexp? (only see some ^, $ anchor out of group)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that those who wrote the earlier code didn't know about the Ruby trap of ^ and $ not working the same as in every other language.

I can also believe the some of the existing patterns weren't anchored at all, even when they should have been.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, so, double confirm, you want me fix those exists regexp anchor, and then add emacs pattern into it, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, two separate commits should make it clear:

  1. Fix the existing ^ and $ anchors to \A and \z.
  2. Add your new emacs patterns with \A and \z anchors.

Or if you'd rather keep this PR simple, we can flip the order and I can take care of (2):

  1. You add your new emacs patterns with ^ and $ anchors.
  2. [after merging this PR] I fix all the ^ and $ anchors to \A and \z.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, let me do both of them first anyway.


# Sed temporary files - but without actual words, like 'sedatives'
| (?:^
sed
Expand Down
3 changes: 3 additions & 0 deletions spec/lib/listen/silencer_spec.rb
Expand Up @@ -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]

Expand Down