Fold content on the same line as the heading #12

Closed
alehandrof opened this Issue Nov 17, 2012 · 16 comments

3 participants

@alehandrof

Is it possible to fold the content on the same line of the heading?

Like this:

# Heading 1 [...]
## Heading 2

Rather than like this:

# Heading 1
[...]
## Heading 2
@vovkkk

Yes, just put beginning of region one less (new line); like this:

self.view.fold(sublime.Region(sublime.Region.begin(content_region) - 1,
                              sublime.Region.end(content_region)))

@demon386 what you think? the issue so old; do you prefer current behavior?

@demon386
Owner

Thanks for the suggestion.

There's one undesirable outcome here. Let's try:

# hello world
folding the content

Folding it, and it will become:

# hello world...

Assume that this is all you have, right now you want to start a new line and type somethings new, the behavior will be weird. You may try "cmd + enter" or "ctrl + e" to try to move beyond the "...", but you can't, because they are actually in the next line.

Thus, we have to at least rewrite the behaviors of "cmd + enter" and "ctrl +e" in this case.

This style is reasonable and I know that Org-mode and FoldingText use it. FoldingText doesn't solve this as good as Org-mode. I will try to investigate and solve this problem.

@alehandrof alehandrof referenced this issue Mar 23, 2013
Merged

Nicer folding #20

@alehandrof

The default Ctrl+Enter macro is not that sophisticated: it moves the cursor to the hard EOL and then adds a newline. My pull request adds a move to the soft eol between these two, which pushes the cursor past the fold marker (if it exists), improving its handling somewhat. There are two situations it doesn't handle well, mentioned in the request.

I understand your concern, but for me, @vovkkk's code (which I incorporated in the pull), makes the folding a lot more usable. I'll have to test it some more myself to see what else might blow up :)

I'm not sure what the issue you have in mind with Ctrl+E. (Something with Vintage or OSX?)

PS. I'm still finding my way around github and this is my first pull request. Let me know if it doesn't make sense :D

@vovkkk

@demon386 I press down key and cursor moves after 'those dots' (if there are no other lines) or on next header line - so no problem :)
Dunno, if it's platform specific or something, I'm on ST2 on Windows7.

Didn't look at PR yet, sorry.

@vovkkk

@alehandrof I'm not sure if changing default Ctrl+Enter is good idea, you know like you used to smthng and then BAM! it ain't work in the same way for some reason.

@alehandrof

@vovkkk I hear you. The new macro is only triggered on a markdown heading and, if I've thought it through properly, it should not have any adverse effects. Assuming we all agree that pressing Ctrl+Enter on # Heading [...]
should place the caret on the next line after the fold mark. If anything, this macro is too conservative as if fails to address two edge cases.

@vovkkk

@alehandrof I understand this intention: 'press one keystroke and here we go'.
But 'default' folding doesn't work this way, I mean when you fold code block ctrl+shift+[ and then ctrl+enter it adds new line before those dots. These are defaults.
We may agree or disagree if that way is right or wrong or whatever, but it's default.
And down key does the trick.

So this is only matter of two keystrokes (down key, enter) vs. one keystroke plus unexpected behavior.
I'm not insist, but imho it doesn't worth it.
Or (if my reasoning is not convince) there should be note about this feature in readme.

@alehandrof

Because:

  1. Sublime's folding is both limited and very fussy.
  2. SmartMarkdown is an extension of Sublime's folding functionality which already introduces new (and unexpected) behaviours (e.g., Shift+Tab).

I think that it's worth implementing whatever seems most reasonable for us writers of Markdown and not worry too much about what Jon is cooking up for when he's looking at C+ code :)

I rather like the Ctrl+Enter workaround, but I would prefer if it was more robust.

@demon386 suggests that that Org-Mode handles this well. I would like to try it out but I still wake up screaming from the last time I saw Emacs' UI.

@vovkkk

Okay, yes, agree.

However, I'm sure that for code blocks (you have those in your mds, eh?) default ctrl+enter makes more sense, beacause you have new line after fold mark anyway.
So I made that both cases are used alehandrof/SmartMarkdown#5

Thoughts?

@alehandrof

I've merged your code in the pull; it seems robust. Waiting on @demon386 to check it out.

I'm sure that for code blocks (you have those in your mds, eh?) default ctrl+enter makes more sense,

I'm not sure I understand what you mean.

@demon386
Owner

Hey guys.

Thanks for the work. I've merged your work into the develop branch. It will go to master branch and get released eventually, I have to test it for a while and also write documentation to not confuse the current user.

Thanks again for the contribution!

@vovkkk

I'm not sure I understand what you mean.

In fact, we have two types of folding:
1. Default - possible only with indentations; including code blocks and nested lists.
2. 'SmartMarkdown' folding which possible only with # symbol(s).

First one folds only indented lines; and you have new line or last symbol anyway:
pic 2013-04-02 17 59 07
pic 2013-04-02 17 59 29

Second one folds all stuff untill next headline or end of file.

Maybe it would be better if ctrl+enter worked indetically in all cases or maybe not; I'm personally can't decide.

BTW, @demon386 when you will test it, note that when headline is not folded and you press ctrl+enter nothing happens :) I've missed that case, noticed just now.

@alehandrof

Sorry for taking so long to respond.

@demon386 What kind of documentation do you have in mind? I'd like to help since I opened this particular can of worms :)

I took a stab at it, let me know if this is what you were thinking of:


Smart Header folding / unfolding

Pressing Tab on a header will fold the content of that section and all its subsections.

Pressing Tab on a folded header will unfold the content of that section, but keep its subsections folded.

Features/limitations:

  • Smart Folding will only work with Atx-style headers (e.g., ## Header).
  • Pressing Ctrl+Enter (or Cmd+Enter) on a folded header will insert a new line after the folded content.

If you'd find it useful, I can shape up the README directly.


@vovkkk I don't use Sublime's built-in folding much, because I don't find it that useful. I hadn't even noticed this issue. This seems buggy behavior to me. Have you seen this addressed in the forum at all?

@demon386
Owner

Sorry for the delay, but finally got the leisure to take care of this. I've pushed to master. Thanks very much for the contribution!

@demon386 demon386 closed this Jun 16, 2013
@alehandrof

👍

Let me know about the docs.

Also, although I requested this feature originally, I think it was exclusively @vovkkk's code which ended up in the PR.

@demon386
Owner

Thanks for reminding.

I'll modify readme.md to reflect his contribution. Let me check the Ctrl+Enter functionality later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment