Sublime Forum

Fold Away Lines Not Matching A Pattern

#21

FWIW you can do ad-hoc folding without any plugins by selecting all the text of interest (e.g., via Find All), and then using the Edit/Code Folding menu. In S1 there was an invert_selection command, which would enable selecting all the non-matching bits of text, I’ll have to add it back in for S3.

0 Likes

#22

Not sure what you mean. It matches all lines based on one pattern (string, actually; I failed to rewrite this as a regex).

What I would like to do is to automate precisely this. I think the ideal command would be folding (as well as inverted folding) based on a regex. This is very useful for logfiles, todo lists and other files where lines are standalone. (Some kind of hook between Goto Symbol and this command would also be useful…)

Alex

0 Likes

#23

http://ndudfield.com/zencoding/old/Untitled\Untitled_media\Untitled.gif

I wrote a command back in the day for someone on the forum along them lines. The command would use folding to preview lines matching a pattern to filter from the document.

I’ll see if I can dig up the code.

0 Likes

#24

That looks interesting – and more sophisticated (i.e., more moving parts) than what I described, but I’d have to use it to be sure – please share your code if you can dig it up!

Incidentally, I see you have a TODO.txt file open. Do you use anything to parse it, or do you use a long static file that you just scroll through?

Alex

0 Likes

#25

TODO.txt is just one big text file I’ve been using since 2009 or so

New entries go at the top of the file

Don’t really use any special plugins

I always was annoyed that I hadn’t gotten around to making it show the whole current function/class/node/etc of a match, rather than a simplistic 2 lines above/below

More so, when using a similar technique for debugging / writing tmLanguage files

I might just try writing it again because I can’t find the code for that plugin

0 Likes

#26

Ah, I see. I thought it parsed the indentation or the scope, which would have been quite a bit more ambitious.

You’re such a tease, I’m still waiting for those keybindings… :unamused:

0 Likes

#27

Soz, busy as shit atm :smile:

My old man’s coming to visit in me (overseas for him) and got an event need to have a new website up for.

Trying to smash it out so I can spend some time with him

FFFFFF. deadlines :confused:

0 Likes

#28

Pft! Excuses, excuses :wink:

0 Likes

#29

FFFFF. Now you gone and called me on my BS.

Ok, you got me, it’s trick screencast photography. It’s not a real plugin.

0 Likes

#30

If anyone is playing along, I have a slightly improved version of this plugin here:
raw.github.com/alehandrof/MarkD … Folding.py

It’s part of a bigger mess called MarkDo that I will clean up and describe soonish*.

What it does

Trigger the plugin with a binding such as this:

{ "keys": "ctrl+'"], "command": "all_toggle", "args": { "foldstr": ""  } },

If there is nothing folded, it will fold all lines NOT matching (in order of preference):

  1. the selection
  2. the “foldstr” argument
  3. user input

When there are folded sections, triggering the plugin will unfold everything. (It’s a toggle, you see.)

Sorry for the very sloppy instructions :smile: Let me know if you need any help using this.

  • One hopes.

Alex

0 Likes