Salvete,
in a new language definition (MuPAD), I have
foldingStartMarker = '\b(proc|domain|case|if|%if|for|while|repeat|axiom|category)\b'; foldingStopMarker = '\b(end|end_proc|end_domain|end_case|end_if|end_for|end_while|end_repeat|end_axiom|end_category)\b';
Now, this works as expected, but I get folding markers whenever I type the word βforβ in a comment. Should I switch comment contents explicitly to text scope or what is the recommended way of dealing with keywords appearing in comments?
As an aside, another question on folding: MuPAD allows code of the following structure (and that is actually quite common):
if foo then dosomething() elif bar then dosome(); thingelse(); else noidea(); end;
case x of 1 do ...; break; of 2 do ...; break; otherwise ... end;
What I would like to have is the ability to fold away the indented parts above, i.e., everything fom an if or elif to the next elif, else, end, or end_if, whatever comes first, from else to end/end_if, from an of inside case to the next of, otherwisem end_case, or end and so on. But it seems I can't have begin and end of two folding regions on the same line, or can I?
regards, Christopher
foldingStartMarker = '\b(proc|domain|case|if|%if|for|while|repeat|axiom|category)\b'; foldingStopMarker = '\b(end|end_proc|end_domain|end_case|end_if|end_for|end_while| end_repeat|end_axiom|end_category)\b';
You could do for instance...
'[^#]*?\b(proc|domain|case|if|%if|for|while|repeat|axiom|category)\b'
Provided your comment char is # that is, basically whatever it is look for it preceding the keyword to negate the entire rule.
Michael Sheets wrote:
foldingStartMarker =
'\b(proc|domain|case|if|%if|for|while|repeat|axiom|category)\b'; foldingStopMarker = '\b(end|end_proc|end_domain|end_case|end_if|end_for|end_while|end_repeat|end_axiom|end_category)\b';
You could do for instance...
'[^#]*?\b(proc|domain|case|if|%if|for|while|repeat|axiom|category)\b'
That would work, but it seems to me that you really want:
'^\s*\b(proc|domain|case|if|%if|for|while|repeat|axiom|category)\b'
So that if it is the first word on a line (possibly preceded by whitespace), it is a fold start.
Jeroen.
Jeroen van der Ham wrote:
Michael Sheets wrote:
You could do for instance...
'[^#]*?\b(proc|domain|case|if|%if|for|while|repeat|axiom|category)\b'
That would work, but it seems to me that you really want:
'^\s*\b(proc|domain|case|if|%if|for|while|repeat|axiom|category)\b'
Thanks, I thought of these and dismissed them β I'd really prefer
print(Unquoted, "// ".if a < 0 then a else a^2 end);
to work. What's more,
/* This should be done if and only if we have a solution. But then ... */
is a comment as well. I think I should really use TM's wonderful scope selectors. Just wanted to check what others are doing, since the problem is not restricted to MuPAD and I couldn't find a workaround or fix in the bundles I peeked into.
regards, Christopher
Christopher Creutzig wrote:
Thanks, I thought of these and dismissed them β I'd really prefer
print(Unquoted, "// ".if a < 0 then a else a^2 end);
to work. What's more,
/* This should be done if and only if we have a solution. But then ... */
is a comment as well. I think I should really use TM's wonderful scope selectors. Just wanted to check what others are doing, since the problem is not restricted to MuPAD and I couldn't find a workaround or fix in the bundles I peeked into.
I'm not completely sure, but I don't think you can use scope selectors when defining folds. But note that the if occuring in the comment might match the foldstartmarker, but there would have to be a matching foldstopmarker at the same indent level to make it a fold. So I don't think that it would show up as a fold.
I think that if you really want this to work properly, you'll have to expand the match more to not only match "if", but also the pattern after it.
Jeroen.
Jeroen van der Ham wrote:
I'm not completely sure, but I don't think you can use scope selectors when defining folds.
That would explain why I haven't managed to do so. But I do think folding markers inside comments should be defined completely separate from those outside comments. (I'd also like to specify pairs, so if and end_while don't match, but thanks to snippets, that's less of an issue.)
But note that the if occuring in the comment might match the foldstartmarker, but there would have to be a matching foldstopmarker at the same indent level to make it a fold. So I don't think that it would show up as a fold.
I do get a start-of-fold marker.
I think that if you really want this to work properly, you'll have to expand the match more to not only match "if", but also the pattern after it.
That would have to be a multi-line match, and still catch ordinary English text in comments.
best regards, Christopher