atom / find-and-replace

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

next search based on last search result #595

Open hyiltiz opened 8 years ago

hyiltiz commented 8 years ago

Consider two scenarios:

  1. You wanted to find all lines that calls a function collect with the input arguments of apple but not orange. Normally, one would come up with a rather complicated regex that looks similar to this (this is not even correct; could not get my head around something like this as a single regex) collect.*[(apple)][^(orange)]. Solution: first search all lines that contain collect, then in those lines search for lines that contain apple, then in these lines, continue searching for lines that does not have orange. Basically, it is grep 'collect' file | grep 'apple' | grep -v 'orange' using grep.
  2. Similar task as above. Let's search through the whole project for files that has lines like that above, but also only for files than mention orchard. You would use grep -rl 'orchard' /path/to/project/ | grep 'collect' | grep 'apple' | grep -v 'orange' using grep and it's -l switch along with xargs.

Basically, it is the | tunnels, but being able to perform grep's -v and -l switches as well, easily, right from within almighty atom. I could not find how to do that from within atom vanilla, or using any of the existing packages. Am I missing something, or is this actually a feature to consider?

jeancroy commented 8 years ago

Selection can act as a pipe as in, make a search, select results (bunch of cmd+d), then make a new search in selection. Multiple selection work great for that. However search does not support negative query.

With complex query usually i'm either OK with doing manual pruning, or if it's a data collection task then OK with using dedicated tool. Grep looks like the right tool for your task.

hyiltiz commented 8 years ago

While it is not a one shot search, I would not call it "complex" query. I think you are suggesting that this is not an editor task. I think I agree, thought Unite for Vim dues that happily. (I believe there are Emacs packages that dues this too).

With search on selection, can we search into the selected files when each selection is a filename? Haven't tried, but I doubt so.

On Mon, Nov 16, 2015, 23:06 Jean Christophe Roy notifications@github.com wrote:

Selection can act as a pipe as in, make a search, select results (bunch of cmd+d), then make a new search in selection. Multiple selection work great for that. However search does not support negative query.

With complex query usually i'm either OK with doing manual pruning, or if it's a data collection task then OK with using dedicated tool. Grep looks like the right tool for your task.

— Reply to this email directly or view it on GitHub https://github.com/atom/find-and-replace/issues/595#issuecomment-157262639 .

Sent from Gmail Mobile.

jeancroy commented 8 years ago

While it is not a one shot search, I would not call it "complex" query.

com·plex adjective 1. consisting of many different and connected parts. synonyms: compound, composite, multiplex

Unite for Vim dues that happily. (I believe there are Emacs packages that dues this too)

Possibly the proper solution for atom is a community package too ? A lot of discussion about package development happens on the https://discuss.atom.io/ board.

jeancroy commented 8 years ago

Maybe what I was trying to say is that in grep the unit of work is a line. This make it easy to make query such as :

Find & replace works on consecutive characters. This make it easy to do:

And while ultimately a line is made up of consecutive character, the different representation make different kind of query very easy / hard to express.