Filter lines containing string and be able to edit


#1

I would like to create a package that enables filtering lines containing a certain string similar to the KEdit command “ALL”.

This is different from using “Project Find Results” on the opened file because of two things: The ALL command does not open up a new TextBuffer, it just hides all the lines not containing the given string. Also, and this is the main advantage, it allows you to perform edits on the filtered lines right away (no need to click on a specific line, do some edits, switch back to the find results and go to the next line etc.).

Another nice feature is, that once lines were filtered using “ALL”, you can use “LESS” to reduce the results by lines containing a certaing other string, or “MORE” to do the opposite.

Now my question is, how could a package providing this functionality look like? I wouldn’t mind opening a new TextBuffer, but at least I want to be able to do edits within that TextBuffer resulting in the correct changes to the original file. Folding does not seem to be an option as I could not find a way to set Folding levels manually.

Thanks for your help!

Some references to packages for other editors featuring similar behaviour:
KEdit
ALL command
Emacs
list-matching-lines


#2

I haven’t seen any features in Atom to filter out certain lines for displaying. You don’t want every line to be folded, that’s for sure, but you might be able to make a compromise by folding the entire document and recursively unfold each line that matches the search string. Here’s an example of recursively unfolding just the cursor line.


#3

Thanks for your reply! I tried your folding example, and while it goes into the right direction, the way folding is currently implemented in Atom it doesn’t allow me to truly fold the entire content of the document. Basically your left with a ton of unfoldable lines (depending on the length of your document indentation). This would work fine if there was a way to control the folding, like setting manual “fold points”.


#4

For that, you would require more expertise in how the editor object is set up than I have. Maybe a dev knows if that would be implementable given the architecture of how Atom presents a file.


#5

Here’s a package I made for this after finding myself with the same needs.

It’s very much a work in progress so feedback / pull-requests welcome :slight_smile:

FYI the crux of the folding is by editor.foldBufferRange, which I cannot find API docs for, but I borrowed the implementation from here.


#6

Wow, that’s really cool! I’ll checkout the repo asap.