Home Download Buy Blog Forum Support

Fold Away Lines Not Matching A Pattern

Re: Fold Away Lines Not Matching A Pattern

Postby sawfoot on Mon Nov 12, 2012 3:54 pm

Forgive me as I am not a coder, but how can you adapt the code so that it folds away lines that DO match the pattern? And/or to allow regex search?

Also, sylvanaar's suggestion is a good one (as otherwise you have to do something like press ctrl-a, then ctrl-shift-] to unfold), but two problems:

1. After running the command on a particular file, when command rerun it folds for the same text as before and the selection box no longer appears.
2. I bound a "all_toggle" command but it does nothing.
sawfoot
 
Posts: 7
Joined: Fri Nov 09, 2012 12:06 pm

Re: Fold Away Lines Not Matching A Pattern

Postby quodlibet on Mon Nov 12, 2012 10:12 pm

I've tinkered with this to improve its behavior (for what I'm using it for). I'm not a programmer, so it's rather rickety.

You can find my version here:
https://raw.github.com/alehandrof/MDSH/ ... %20Fold.py

Bind a key as follows
Code: Select all
{ "keys": ["ctrl+'"], "command": "all_toggle", "args": { "foldstr": ""  } },


This command will toggle between:
* unfold all lines, and
* fold all lines EXCEPT those matching "foldstr"

"Foldstr" can be passed as an argument, by selected text, or input.

What I use this for is to parse a todo list based on #tags and @contexts:
find a place in the text, hit Ctrl+D to select the word, and Ctrl+' to fold all lines except those matching the word.

Hope this makes sense / is useful.

Alex
quodlibet
 
Posts: 547
Joined: Sat Jun 18, 2011 5:53 pm

Re: Fold Away Lines Not Matching A Pattern

Postby sawfoot on Tue Nov 13, 2012 2:30 pm

Cheers Alex, I did manage to figure out that commenting out:

# if self.view.settings().has("all"):
# self.done(self.view.settings().get("all"))
# return

stopped the repeating of the filter. And having a single command to switch between folding state seems a sensible behaviour. I had a similar usage scenario to yours, though I also wanted to allow filtering out of lines (e.g. those with a @done tag).
sawfoot
 
Posts: 7
Joined: Fri Nov 09, 2012 12:06 pm

Re: Fold Away Lines Not Matching A Pattern

Postby quodlibet on Tue Nov 13, 2012 9:39 pm

The argument is also quite handy, because it means you can set up commands in the palette to fold for standard tags like @home, @calls, etc. (I also list agenda items by @person, as in @bob.)

I've been thinking of adding an exclusion filter for the same reason (the files I'm using are loosely based on todo.txt so I would be looking to exclude a regex like `^x \d{4}-\d{2}-\d{2}`). It shouldn't be too tricky, but I don't entirely understand the code of the all function. I'll take a stab at it when I can. Let me know if you come up with anything.

Alex
quodlibet
 
Posts: 547
Joined: Sat Jun 18, 2011 5:53 pm

Re: Fold Away Lines Not Matching A Pattern

Postby sawfoot on Thu Nov 15, 2012 8:39 am

I did find this:
http://superuser.com/questions/452189/h ... ime-text-2
And tried to adapt it, but my understanding of the coding is limited. But having a separate regular text search and regex search would be good.

This regex filter in the link would be useful for destructive removal of items (e.g. @done lines)

Use of regex with negative look arounds can also be used to filter out instances, so this:
^((?!DONE).)*$
Will match any string, or line without a line break, not containing the (sub) string 'DONE'. You could then combine that with regex term to exclude dones and include something else, which means the regex would start getting complicated, but running from the palette would help.
sawfoot
 
Posts: 7
Joined: Fri Nov 09, 2012 12:06 pm

Re: Fold Away Lines Not Matching A Pattern

Postby quodlibet on Thu Nov 15, 2012 9:40 pm

That's a nice find. Although I suspect the folding, rather than the regex, is the tricky bit.

Actually, I don't really like the folding on this plugin, I would prefer the fold market at the end. You mention SmartMarkdown elsewhere, which has a similar problem: the folding marker is underneath the `# heading`, which makes it more likely I will leave something behind when moving chunks around. I would prefer if it folded like so:

Code: Select all
# heading [...]
## other heading [...]
&c.


Incidentally, did you notice that all your posts are in threads I had started or posted in? -- with this exception:
viewtopic.php?f=6&t=3465

(I'm surprised that didn't take off, @facelessuser and @castles_made_of_sand can usually pull amazing things seemingly out of a hat.)

Anyway, if you tell me what you're trying to cook up, I can tell you whether I have failed to find it/make it :D

Alex
quodlibet
 
Posts: 547
Joined: Sat Jun 18, 2011 5:53 pm

Re: Fold Away Lines Not Matching A Pattern

Postby sawfoot on Fri Nov 16, 2012 5:19 pm

I guess, without really being aware of its existence, that I have inadvertently being trying to emulate foldingtext which I recently discovered, which is a freeform outliner/task manager from the maker of taskpaper (of which plaintasks is a copy of).

If you watch the folding text video they use folds next to the item rather than below, as you were suggesting.
http://www.foldingtext.com/about/

To avoid overly complicated and lengthy nested structures, markdown headings (with folding) allow structure, but still provide nesting if you want with tabbed bullet points below them (which can also be folded with native sublime), and it all looks nice in markdown. One minor issue with markdone syntax is that the state of item (e.g. + for completed) isn't shown in markdown view, which is why appending @done to items is useful. There is the itodo plugin which works well with markdone to make converting todo items ( starting with -) to done items, e.g.:

+ done task @done (2012-11-16 16:59)

One thing that I haven't seen in sublime is a "zoom" mode, which is what workflowy does well, and is found in foldingtext and writemonkey - so you press a hotkey and you only see the current scope (e.g. the level of the heading within markdown), and "zoom out" to see the whole document.

Anyway, putting all these things together makes for something pretty similar to foldingtext and potentially quite a nice and powerful tool. If I was more technically minded I would think about creating a package.
sawfoot
 
Posts: 7
Joined: Fri Nov 09, 2012 12:06 pm

Re: Fold Away Lines Not Matching A Pattern

Postby quodlibet on Fri Nov 16, 2012 11:55 pm

It sounds like we're treading pretty similar territory.

After about a year of using half-baked workflows I had cobbled together from orgmode, todotxt, iTodo, and various other packages, I decided to switch to Plain Tasks a few weeks ago. Almost immediately I started re-writing it to make it more Markdown-like. After a few days I gave up and went back to my half-baked system, which currently consists of the following:

* A syntax almost identical to todo.txt, along with some useful commands to add and complete actions. This is where I find use for the All Fold command, because the syntax is just one item per line. I've taken the plunge and am trying to implement a full GTD system, and, although I dislike this format, I found I have the least resistance to using it.

* A syntax which is a sort of fast-and-loose Markdown. For example, you can cram things next to each other without empty lines (which is not valid in strict Markdown):

Code: Select all
# Heading 1
## Heading 2
- List item
## Heading 2


This syntax is in flux always and mostly broken at the moment.

I've gone ahead and installed the Clickable URLs plugin and chucked my own orgmode-derived abominations.

I have some mostly working code for opening local files with Wiki style links `[other-file.md]`. (From the Wiki plugin).

I use SmartMarkdown but it doesn't "feel" right, although it's probably an improvement over what Sublime provides by default. Navigating a file with lots of folded coded is very annoying and very easy to erase entire chunks. I wish there was a plugin that made folded text indestructible.

I think that "zoom" is an interesting idea. It should be possible to write a plugin that does this by folding the text above and below the current location. I think a sane way of doing this is to re-write the Markdown (or whatever) syntax so that there's a scope defined between headings (including the heading itelf), otherwise you have to resort to regexs at the plugin level. (Does this make sense?)

I'm very fond of the orgmode checkboxes:

Code: Select all
- [ ] Incomplete item
- [X] Completed item


For about the first half of 2012, all my organization was basically Markdown + orgmode-style checkboxes.

(Then this happened: viewtopic.php?f=3&t=7388&hilit=+usb#p34327 )

I just watched the Folding Text video again, and I noticed that the ".todo" lists use checkboxes. I've been trying to figure out how to use checkboxes or checkbox-like things with the minimum of conversion difficulties (via Pandoc and the like) and have encountered the difficulty you also point out. I think I'll go back to combining the Markdown syntax with the checkboxes (and maybe some bits of the GTD syntax/commands) and worry about how to convert to other formats later.

Although I like the Workflow/PaperTasks/FoldingText simplicity, one of the things I've found really useful is to date everything, so I can refer to it later. I only need the date, not the time, but it's pretty intrusive:

Code: Select all
- incomplete item @added(2012-02-06)
+ complete item @added(2012-05-24) @done(2012-06-02)


In my todo.txt syntax, I color it using the comment scope so that I can tune it out, but I can only do so because the dates are always at the beginning of the line.

Maybe folding these meta-tags, coupled with the orgmode checkboxes is the way to go:

Code: Select all
- [ ] incomplete item [...]
- [X] complete item [...]


I'm not quite sure how this would work, though.

(Sorry for the long, chaotic post.)

Alex
quodlibet
 
Posts: 547
Joined: Sat Jun 18, 2011 5:53 pm

Re: Fold Away Lines Not Matching A Pattern

Postby quodlibet on Sat Nov 17, 2012 11:03 am

I opened an issue on SmartMarkdown regarding folding the content on the same line as the heading:
https://github.com/demon386/SmartMarkdown/issues/12

(Although the developer of SmartMarkdown has stated he's quite busy.)
quodlibet
 
Posts: 547
Joined: Sat Jun 18, 2011 5:53 pm

Re: Fold Away Lines Not Matching A Pattern

Postby lmedinas on Wed Feb 27, 2013 9:13 pm

Does it support multiple pattern or single matching ?
lmedinas
 
Posts: 11
Joined: Thu Feb 21, 2013 10:46 pm
Location: Germany

PreviousNext

Return to Ideas and Feature Requests

Who is online

Users browsing this forum: No registered users and 15 guests