atom / find-and-replace

Find and replace in a single buffer and in the project
MIT License
242 stars 219 forks source link

There's no way to exclude paths from a search #149

Closed mattbasta closed 9 years ago

mattbasta commented 10 years ago

When searching, filters can be specified. However, there's no way to exclude paths from the search.

E.g.: *.js, -*.min.js cannot be used to exclude minified files from a search of JS

kylegoetz commented 9 years ago

OK I forked and cloned Atom and have loaded it with atom --dev and have opened /src/scan-handler.coffee and, to make sure I'm doing this right (never hacked on Atom before), and added

console.log "Foo"

as line 1 in the file, saved the file, and did ctrl-cmd-alt-L to reload. The developer console does not ever show this log. How do I get started implementing a solution? The docs are bereft of how to edit the core of Atom. They just talk about creating new plugins/extensions/whatever they're called in Atom.

I'm going to implement regular expressions for directories and not just the filenames themselves. Then I'll do a PR. If Atom rejects it, that's fine. But at this point, lack of regex in paths has added hours and hours of development time, and if no one else is going to do it, then I'm going to get it done, at least to my satisfaction. It shouldn't be too hard. The Regexp package is already loaded and the path search backend (scandal, minimatch) already supports it. Just for some reason Atom doesn't.

jaspervalero commented 9 years ago

+1 This is a fundamental feature that should be supported in any code editor/IDE from day 1. Please treat this with some priority. Thank you!

kylegoetz commented 9 years ago

I implemented regex support in the Project search path field today and just created a pull request. We'll see if the maintainers accept my PR or want to modify it in some way. It works for me, and I'm going to keep using it, so if you're interested in the same, here it is: https://github.com/atom/find-and-replace/pull/420

It was a nice simple fix once I learned how to read CoffeeScript and how to set up Atom for development work and how everything is laid out in Atom.

Edit I'll be creating some unit tests for my solution because (understandably) it couldn't be incorporated into this project without them. But in the meantime, and also as a note for myself, you would exclude a path containing "foo" by doing this as a regex command:

^((?!foo).)*$

serapath commented 9 years ago

is there an estimate when this might feature might become available?

kylegoetz commented 9 years ago

If you're referring to my implementation (not sure if you are), then I need to write a comprehensive unit test suite for it. But I have to learn how to do that first, and find time in my insanely busy actual job and life schedule to do it. So no estimate, but I would hope in the next couple weeks I could complete some tests.

After that, I imagine the people in charge would have to discuss internally whether they like my solution and want to include it or not. That part, I have no idea about, so would defer to someone else who knows like benogle.

That being said, I see a day ago the 1.0-roadmap label was removed, which leads me to assume it's being kicked further down the road.

mbrammer commented 9 years ago

+1 Please add ignore pattern

zeroedin commented 9 years ago

:+1:

icetraxx commented 9 years ago

+1

Fire-Dragon-DoL commented 9 years ago

Has this been added? I'm waiting specifically for this feature to start using atom

kylegoetz commented 9 years ago

I added the ability to do regex path filtering to my fork but need to implement unit tests before I think Atom will even consider a pull request (understandably so). I just don't have time to learn how to do create unit tests for this right now with work and home life. You're welcome to take a look at my fork and implement unit tests if you want.

mwielondek commented 9 years ago

+1 Essential feature. Hard to believe this is a 1,5-yr-old issue..

RiFi2k commented 9 years ago

Trying doing a find a replace " for ' 34000 times on 2 full websites... At least I use git Needs added* bed

scott-kennedy commented 9 years ago

+1 - Can't use the editor without this feature.

mnquintana commented 9 years ago

Thanks for the feedback everyone! However, all these +1s and :+1:s are just adding noise, so to minimize that I'm going to lock this issue for now – we may unlock it once someone starts working on this enhancement to get further feedback.

benogle commented 9 years ago

A fix for this will be in atom 1.0.3 tomorrow.

benogle commented 9 years ago

See https://github.com/atom/scandal/pull/29 for a little bit about handled cases.

swrobel commented 9 years ago

:clap:

Fire-Dragon-DoL commented 9 years ago

That's great downloading atom, preparing for tomorrow.

acusti commented 9 years ago

:tada:

mwielondek commented 9 years ago

It seems now that VCS ignored paths are no longer excluded from the results. Is it just me?

Fire-Dragon-DoL commented 9 years ago

mhhh did you try with these syntax?

inclusions: []
exclusions: []
globalExclusions: ['vendor/', '*.pyc']

(I didn't test it yet, so I don't know)

Fire-Dragon-DoL commented 9 years ago

I tested with:

# projects.cson
'MyProj':
  'title': 'MyProj'
  'exclusions': [
    'node_modules/*'
  ]
  'paths': ['/Users/myuser/Projects/MyProj']

With ctrl + P, node modules directory is still included entirely, making it unusable.

Edit: Notice that I might definitely misunderstood the usage, so it's not a complaint, sorry if it gave this feeling. I would like a few "directions" though

sasikanth513 commented 9 years ago

I've added ".git, .meteor" to the Ignored Names and enabled both "Hide Ignored Names" and "Hide VCS Ignored Files" in tree-view settings.

Still search results are showing from those folders.

benogle commented 9 years ago

It will search the gitignored or ignored names files when you explicitly call out an ignored folder like node_modules.

Can one of you open a new issue with the following info:

Mine

screen shot 2015-07-29 at 11 56 17 am

benogle commented 9 years ago

With ctrl + P, node modules directory is still included entirely, making it unusable.

I dont understand what this means. Can you elaborate in a new issue with very explicit steps?

Fire-Dragon-DoL commented 9 years ago

@benogle yes, but I want first to understand if i'm setting options correctly in the right place. I'm doing it in projects.cson

benogle commented 9 years ago

Open the settings view with cmd-,

settings

These are the settings that will affect find and replace (along with .gitignore).

Fire-Dragon-DoL commented 9 years ago

Uhm, what you point out works. I mean, after adding it (and reloading project so it reindexes), ctrl + p (and find) don't look into node_modules anymore. Good.

Although, I was sent here from a bug which stated it should be possible to configure this on a per-project basis. Is this possible?

benogle commented 9 years ago

Although, I was sent here from a bug which stated it should be possible to configure this on a per-project basis. Is this possible?

Maybe with a package, but not in the default distribution. This issue only affects find-and-replace, not the command palette or the fuzzy-finder.

Fire-Dragon-DoL commented 9 years ago

Mh ok thanks.

I'm testing with find (I'm not replacing, does it matter?), with node_modules in ignoredNames, it doesn't find the text "coffee-script/repl" (which is the content of a file in node modules), however when I remove "node_modules" from ignored names I still can't find that (I restarted the editor). Probably it needs reindexing but I can't find a way to force it. The only way I found is adding the pattern **/* which allowed me to find the text either if it's in ignoredNames or not

benogle commented 9 years ago

Can you make a new issue? Each comment on here notifies 50+ people.

Fire-Dragon-DoL commented 9 years ago

@benogle https://github.com/atom/find-and-replace/issues/466 I can't stress this enough, I'm not sure if this is a bug.

P.S. Project manager allows per-project settings so fixed my problem from this point of view. Although, I can't get "negated" paths to work. if I add !node_modules it includes only node_modules directory

nicolas-van commented 9 years ago

My case is quite simple, in 1.0.7 I have this:

atom.config.get('core.ignoredNames')
[".git", ".hg", ".svn", ".DS_Store", "._*", "Thumbs.db"]
atom.config.get('core.excludeVcsIgnoredPaths')
true

And yet when I make a search in my project I can find results in my .git folder.

cluxter commented 9 years ago

Not working for me in Atom v1.0.10 in Windows 7. Here is the result of the commands in the console:

atom.config.get('core.ignoredNames')
[".git", ".meteor", ".semantic-ui", ".git\", ".git/"]
atom.config.get('core.excludeVcsIgnoredPaths')
true

Yet when I right-click on my project root folder, click on "Search in Directory" and search a word, results from ".git" folder are shown.

However it works when I add this in the "File/Directory pattern":

!.git/

Am I doing it wrong or is it a bug? I tried everythink I could, including modifying the "config.cson" file and adding the "exclusions" line. Nothing worked.

EDIT: my goal is to avoid writing the !.git/ filter everytime. That's all.

MichaelJCole commented 9 years ago

I just edited my config and got something like this to work. I added an ignoredNames section to my config.cson (Preferences -> Open Config Folder -> config.cson):

"*":
  core:
    autoHideMenuBar: true
    ignoredNames: [
      ".meteor"
      ".git"
      "etc"
    ]

and don't get results in these directories:

/etc/*
/src/.git/*
/src/admin/.meteor/*

Not saying there isn't a bug, but this worked for me on 1.0.7 on Linux Mint

TerrenceLJones commented 9 years ago

@MichaelJCole This works for me as well on 1.0.15 on Mac O.S.

jagc commented 8 years ago

@MichaelJCole Thanks!! Worked for me.

Atom.io: 1.0.19 OS: Windows 7 Ultimate SP1 64bit

Would be great though if we have an option where we could input a list of directories of where (and not) to search.

Sam-Gram commented 8 years ago

Just use commas and start the path from the root project directory. Works well.

PierBover commented 8 years ago

Is there a way a exclude files from the command "find file"?

I've added .jpg, .png in the ignored names setting but they do still appear there.

Edit: So *.jpg, *.png did it.

CharlesMcKeever commented 8 years ago

Bless you @MichaelJCole Works for me on 1.0.19 on OS X El Capitan. You are awesome!

chung-leong commented 8 years ago

Feature is still buggy in 1.1.0. A file can still pop up if the path matches the file/directory pattern. I.e. If you do "Search in directory", files in ignored folders will show up (and promptly crashes the editor).

benogle commented 8 years ago

If you do "Search in directory", files in ignored folders will show up

Can you make a new issue giving the exact values you have in each text box + if possible, a test repo? I know it will do this in some case due to some ambiguity.

proehlen commented 8 years ago

@MichaelJCole Thanks so much for that man. Works well and removes a major frustration with Atom for me.

jldec commented 8 years ago

@benogle see #621

kevin-smets commented 8 years ago

@MichaelJCole thanks for that quick fix. I added 2 project which led to 2 million files being indexed, it was crazy...

Imho it should be as easy as right clicking on a folder - exclude from index or something, where you could then take just that specific folder, or use it as a pattern.

leongaban commented 8 years ago

Ok I finally got this working, had to add .sass-cache into my config.cson file, now when I fuzzy search I don't get .scssc files

 core:
    closeEmptyWindows: false
    ignoredNames: [
      ".scssc"
      ".sass-cache"
      ".git"
      ".hg"
      ".svn"
      ".DS_Store"
      "Thumbs.db"
      "node_modules"
    ]
    themes: [
      "atom-material-ui"
      "atom-material-syntax"
    ]
ghost commented 8 years ago

+1 @MichaelJCole @leongaban Your config.cson hack worked for me.

Trying to exclude paths by typing them in the search does not work for me. Trying to exclude paths using .gitignore (with "Ignore VCS" enabled in Prefs) does not work either.

konstantinmagg commented 8 years ago

+1 Would be great to ignore folters (e.g. 'bower_components' or 'node_modules') in the search bar.

@leongaban your solution worked for me, too. thx ;)

ocssor commented 8 years ago

Right Click Folder -> Search in directory

Still searches in '.svn' despite that being in ignored names (both in core settings view and in config.cson).

akmur commented 8 years ago

Thanks @leongaban