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

benogle commented 10 years ago

You can try the ! char. We use minimatch.

TrevorSayre commented 10 years ago

Something like *.js, !*.min.js does not work Using just !*.min.js actually only searches .min.js files (inverse of what you might expect) Unsure how to search .js files but not .min.js files

dbkaplun commented 10 years ago

Searching for require in !node_modules/* returns no results. Am I doing it wrong?

jaikdean commented 10 years ago

I am seeing the same buggy behaviour. If I do a search for something with the path pattern of "!directory/to/ignore" it search only in that directory rather than ignoring it and searching everything else.

noahrc commented 10 years ago

'!' also doesn't exclude a file or directory for me, and using it multiple times makes no difference.

probablycorey commented 10 years ago

Using the ! syntax to negate a search won't work right now. The problem is from this line https://github.com/atom/scandal/blob/master/src/path-filter.coffee#L47.

But I don't see a solution around it other than fixing how scandal handles directory/file filtering.

probablycorey commented 10 years ago

Moving from bug to enhancement.

TrevorSayre commented 10 years ago

TextMate just added this feature on 2014-04-18 (v2.0-alpha.9539), so it may be useful to have as a reference: https://github.com/textmate/textmate/compare/v2.0-alpha.9533...v2.0-alpha.9539 https://github.com/textmate/textmate/commit/45481d2e4d42ff46d5a158ae418af16b6dcfc27e https://github.com/textmate/textmate/commit/9524439aef32bfc02470d477473540b949866bda

They describe their method as follows:

In file pattern globs the tilde (~) and bang (!) operators both indicate that what follows must not match the file path. For example: .{c,h}~vendor/* will match .c and .h files except when under the vendor/ directory. It’s possible to specify multiple exclusion patterns and also to start the pattern with the exclude operator, e.g. !build/!cache/ will match anything not in build/ or cache/. If the operator is used inside brace expansion (e.g. {Icon\r,~.nib}) then it’ll be treated as a literal match, similarly when used last in the pattern (e.g. .txt~).

dbkaplun commented 10 years ago

Just checking on the status of this. I think this is a very important feature!

philipgiuliani commented 10 years ago

:+1: Its a really important feature because it finds about 1000 results in my log/ directory when i search something and so the search gets reaaalllyy slow...

kwerle commented 10 years ago

This is [now] marked as an enhancement, but with the horrible results from logfiles and the like, find is barely usable. Please consider this a bug.

m3kka commented 10 years ago

+1 this feature is badly needed

acusti commented 10 years ago

Exclusions for Find in Project is definitely a big deal. In web dev, just being able to !bower_components,!node_modules in the File/directory pattern field would feel like :godmode:

tregusti commented 10 years ago

Exclusions for Find in Project is definitely a big deal. In web dev, just being able to !bower_components, !node_modules in the File/directory pattern field would feel like :godmode:

I second this, I too get 1000+ results here that make a search replace impossible to do.

mattbasta commented 10 years ago

This issue is one of only a small handful of things blocking me from using Atom. If I can't filter out the vendor/ or node_modules/ directories in my projects, it's impossible for me to search in any meaningful way.

rodrigoAbril commented 10 years ago

same here

mattvagni commented 10 years ago

I think this should be addressed by: https://github.com/atom/scandal/pull/17

Unless anyone knows why atom currently disables negation?

vincentcr commented 9 years ago

The issue is not fixed, because it only works with file patterns. For example, trying !node_modules has no effect

swrobel commented 9 years ago

Indeed, I tried a variety of ways of negating paths and none worked:

psnider commented 9 years ago

I think there are two parts to this problem:

I also think using a general pattern would be an improvement over the TextMate approach of just a pathname.

jaxspades commented 9 years ago

Sublime has this capability as well in their settings. You can use file_exclude_patterns or folder_exclude_patterns in order to have it ignore those files and folders in the project tree and pretty much anything that the editor uses to traverse the folders and files. I also use this feature heavily so that I can ignore svn folders, .min.js files, node_modules and the like. Please add this as it is a much needed feature.

benogle commented 9 years ago

@jaxspades there is the ignoredNames setting in the settings view:

screen shot 2014-10-07 at 11 33 22 am

hugomn commented 9 years ago

+1 for this being a bug. There's no way to use atom search including node_modules, bower_components and logs.

acusti commented 9 years ago

Thanks for the suggestion, @benogle! Using the ignoredNames setting works well for me. Here’s what I have in that setting’s input:

.git, .hg, .svn, .DS_Store, Thumbs.db, .codekit-cache, bower_components, node_modules

which translates to

    'ignoredNames': [
      '.git'
      '.hg'
      '.svn'
      '.DS_Store'
      'Thumbs.db'
      '.codekit-cache'
      'bower_components'
      'node_modules'
    ]

in ~/.atom/config.cson. All of those files/folders still show up in the project (tree-view) sidebar, which is important (so I can dig through bower_components especially), but are completely excluded from Find in project. Just what I need :ok_hand:

chibicode commented 9 years ago

:+1:

samtsai commented 9 years ago

@acusti how did you get those folders to still show in tree-view? As soon as I add them to ignoredNames they are excluded from the view.

jaikdean commented 9 years ago

You can't, that one of the reasons why we need a proper solution for excluding files from project searches, and using ignoredNames is the wrong way to go about it.

acusti commented 9 years ago

@samtsai I didn’t do anything special that I know of, other than what I described. Here’s a site I have with lodash installed via bower (you can see that the string lodash shows up, for example, in lodash’s bower.json), where I have searched for the string lodash:

Find in project for “lodash”

No results from bower_components. I’m using Atom 0.142.0 on Mac OS. Here’s the only potential relevant bits from my config.cson:

'global':
 'core':
    'excludeVcsIgnoredPaths': false
    'ignoredNames': [
      '.git'
      '.hg'
      '.svn'
      '.DS_Store'
      'Thumbs.db'
      '.codekit-cache'
      'bower_components'
      'node_modules'
    ]
acusti commented 9 years ago

@jaikdean I’m not sure why my experience is different. I was expecting ignoredNames to make Atom ignore those directories/files entirely, but in my install, they remain browsable from tree-view while being hidden from Find in project (see my previous comment for details).

benogle commented 9 years ago

@acusti there is an option in the tree-view (settings -> search for tree view -> click) to hide ignoredNames files.

acusti commented 9 years ago

@benogle Nice! Thanks.

@samtsai @jaikdean To make files or folders matched by ignoredNames appear in the Tree View, open the settings for the Tree View package and make sure the Hide Ignored Names settings is unchecked.

clayzermk1 commented 9 years ago

:+1:

dwelle commented 9 years ago

:+1:

TerrenceLJones commented 9 years ago

What is the current status of this bug/feature? Has a decision been made to start work on this? Nothing truly has been said that someone is working on this.

benogle commented 9 years ago

We are not currently working on this. PRs are welcome, though!

msisto commented 9 years ago

+1

davewhitley commented 9 years ago

It'd be great to get someone working on this. The solutions I see here don't apply to me.

If I'm doing a find and replace and want to exclude one of the files in the results, it's impossible. For example, if I want to replace $light-blue with $blue in every file except for colors.scss, it's not possible.

backspaces commented 9 years ago

I'd like to eliminate "derived files" from my searches .. i.e. min.js, docco directory (documentation generated from src/ files), tools/ (.js files used in demos, not the project) and so on. I'd like to do this on a per-repo basis.

Thus far it seems like atom does not search node_modules (and other files in my .gitignore file?). I'm not sure why folks are seeing node_modules in their global searches .. they are typically not included in the repo, but referred to by package.json.

Apparently all I have to do is put the dirs I want to search in the "pattern" line of the global search pane. It would be nice to automate that, somehow. Not sure if best to have "positive" or "negative" i.e. include or ignore semantics.

-- Owen

AGregg commented 9 years ago

In the case of excluding a directory for a find and replace, my current workaround is to make sure my directory is clean, do the find and replace, then go into git bash and type git checkout <directory>/.

I would definitely like for this feature to happen. Hopefully this can help people in the meantime. @drw158

brendanfalkowski commented 9 years ago

The ability to exclude folders is very important to me. For Magento projects, there are sometimes 4 or 5 versions of the same file due to theme inheritance. Example:

/app/design/frontend/base/default/template/...
/app/design/frontend/default/default/template/...
/app/design/frontend/enterprise/default/template/...
/app/design/frontend/rwd/default/template/...
/app/design/frontend/custom/default/template/...

/skin/frontend/base/...
/skin/frontend/default/...
/skin/frontend/enterprise/...
/skin/frontend/rwd/...
/skin/frontend/custom/...

Only the custom/default files are being opened/edited 99% of the time.

It's not good enough to hide VCS ignored files, because these inherited theme files do need to be deployed but I don't need to edit them.

In Sublime Text, I can exclude the other folders:

{
"folder_exclude_patterns":
    [
        ".git",
        "*/frontend/base",
        "*/frontend/default",
        "*/frontend/enterprise",
        "*/frontend/rwd",
    ]
}

Sidebar: I don't like that Sublime also hides those folders from the tree. I do still need access to them occasionally.

In Atom, you can't exclude paths or use wildcards. You can only add individual folders to "ignored names":

.git, base, default, enterprise, rwd

But this is way too generic because it hides wanted folders/files. So it's not useful.

When you "find in project" for "pageheader.phtml" you should be able to configure seeing only your theme files. But now you have to scrutinize the list to select yours among all themes, it's very annoying.

Ideally, you could set exclusions per project (Atom should make "project-manager" a core package). It would be nicer if (like Sublime) this was simply JSON and you could comment out lines temporarily. Otherwise if global, it needs to be simple to toggle folder exclusions on/off (not a long text input).

danielweck commented 9 years ago

+1 to mimic SublimeText folder_exclude_patterns and file_exclude_patterns on a per-project basis, except that SublimeText maps its search-index with the files/folders shown in the folder tree view ... which isn't really adequate (especially as this behaviour cannot be deactivated, i.e. if my 'build' folder is excluded from search, then I cannot browse it in the file tree view).

ilianaza commented 9 years ago

+1 very important feature!

e00dan commented 9 years ago

+1, it's crucial for code editor.

lmartins commented 9 years ago

Another annoying +1 on this one too. Surprised to find this is default behaviour yet.

thomasjo commented 9 years ago

Given all the +1's, I'm really surprised that nobody in the community has opened a PR yet... this is open source, so if you desperately need a feature, contribute instead of complaining. There are many of us who would love to provide you with guidance, testing, and what not.

lmartins commented 9 years ago

@thomasjo You're absolutely right, I probably extended my comment too much, but when I say annoying it was just self awareness of the fact that all those +1, including mine, are a bit annoying considering what you said. For my part, I don't do it myself as im afraid is a task over my skills.

kylegoetz commented 9 years ago

I can already search for strings using regex. Why can't that code just be extended to apply to the file/directory pattern field like it already does for the find-in-project field? That seems best to me: if you search using regex in one field, it should be applied to all fields. Otherwise, I have to think about escaping . characters and stuff in one field but doing a totally different syntax in the other field, and that gets jarring.

jehoshua02 commented 9 years ago

@thomasjo Let's be realistic. It's probably going to take more time than many of us can afford to get familiar enough with the code and process to submit a PR. We have jobs and most of us would get in trouble for going on a tangent to fix our editor. My employer would probably demand I switch to another editor.

kylegoetz commented 9 years ago

If I'm reading the code right (I don't know CoffeeScript), there is a file in src called scan-handler.coffee that imports scandal, which performs path scanning using minimatch. Minimatch supports regex, but Scandal appears to have omitted incorporating Minimatch's support of regex matching.

So I might take a look at this sometime, but it doesn't look like adding it would be too hard.

At minimum, you could probably in the scan-handler.coffee file, once you get the results back from scandal, just pass each path through the correct regex using UnderscoreJS's filter or something.

I'm thinking (but again I don't speak CoffeeScript) you could add a new line 20 such that the logic becomes "on results found, if result path matches regex -> emit result found." That'd probably do it.

igor10k commented 9 years ago

Even though some of you point to Sublime Text, I'd like to introduce you to they way TextMate handles exclusions and honestly I think it's the best solution possible. TextMate has a list of config variables that give you the flexibility to set things up for the optimal performance and usability.

excludeDirectoriesInBrowser
excludeDirectoriesInFileChooser
excludeDirectoriesInFolderSearch
excludeDirectories
excludeFilesInBrowser
excludeFilesInFileChooser
excludeFilesInFolderSearch
excludeFiles
excludeInBrowser
excludeInFileChooser
excludeInFolderSearch
exclude

Not sure if these variables require any explanation. Compared to this even Sublime Text falls short. You can of course use this feature per project and/or globally. This feature alone is the main reason I always switch back to TextMate.