[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jedit-users
Subject:    Re: [ jEdit-users ] "Random" folding and unfolding
From:       Wildemar Wildenburger <wildemar () freakmail ! de>
Date:       2007-12-26 14:28:03
Message-ID: 477264F3.9030107 () freakmail ! de
[Download RAW message or body]

I use jEdit 4.3pre11. Also, sometimes it changes the fold state and
sometimes it doesn't. You might need to try it with several different
files, in order to observe the wonkyness.

Anyways, let's see how it works after the update.

/W

Matthieu Casanova wrote:
> Hi, what version of jEdit did you use ?
> I'm trying with the latest trunk and it seems it works fine
>
> Matthieu
>
> On Dec 24, 2007 3:09 AM, Wildemar Wildenburger <wildemar@freakmail.de> wrote:
>   
>> Dang! Forgot the attachment, sure enough.
>>
>>
>> Wildemar Wildenburger wrote:
>>     
>>> Hello :)
>>>
>>> I've written a macro to beautify my explicit folds upon save (via the
>>> ActionHooks plugin). However, since the fold-start lines are altered by
>>> the macro, I find the buffer's collapsed/expanded state is (somewhat
>>> unpredictably) different after the macro ran. It must have something to
>>> do with the chagning of the fold-start line, because when not changing
>>> those, nothing bad happens. See the attached file for reference. What it
>>> should be doing:
>>>
>>>     * Prepend the fold-opening and -closing strings with asterisks,
>>>       according to the depth of the fold (to ease quick visual
>>>       disrimination of fold-nesting)
>>>     * append the fold name to the closing line (in parenthesis), to make
>>>       it clear which fold actually ends there
>>>     * leave collapsed folds collapsed and expanded folds expanded
>>>
>>> The third point it doesn't quite get right.
>>>
>>> BTW: Has jEdit's behavior regarding folds changed recently? Now, when I
>>> delete the line above a collapsed fold, thus entering the fold-start
>>> line, the fold expands. I don't think that it always did that. Am I wrong?
>>>
>>> /W
>>>
>>> -------------------------------------------------------------------------
>>> This SF.net email is sponsored by: Microsoft
>>> Defy all challenges. Microsoft(R) Visual Studio 2005.
>>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>>>
>>>       
>> /** Beautify_Explicit_Folds.bsh
>>  *
>>  * Author: Andreas Waldenburger (wildemar@freakmail.de)
>>  * Created: 2007 11 27
>>  * Updates:
>>  *      2007 12 22
>>  *          Made nesting more visible by adding *'s to the folds.
>>  *
>>  * For each opened explicit fold followed by a name on the same line
>>  * this macro decorates the fold end with the name.
>>  *
>>  * So this
>>  *    {{{ * SOME FOLD NAME
>>  * leads to this
>>  *    }}} * (SOME FOLD NAME)
>>  *
>>  * The nesting depth of folds is indicated by the number of *'s before the
>>  * fold name.
>>  *
>>  * This helps understanding the fold-structure, because you explicitly see
>>  * which fold ends when. Works great when called via ActionHooks on saving.
>>  */
>>
>> import java.util.regex.Pattern;
>>
>> //{{{ * Helper Functions
>> String getDepthMarker(int depth, String marker) {
>>     String s = "";
>>     for (int i=1; i<=depth; i++)
>>         s = s + marker;
>>     return s;
>> }
>>
>> void replaceLine(int linenumber, String content) {
>>     start = buffer.getLineStartOffset(linenumber);
>>     buffer.remove(start, buffer.getLineLength(linenumber));
>>     buffer.insert(start, newline);
>> }
>> //}}} * (Helper Functions)
>>
>> if (buffer.isReadOnly())
>>         Macros.error(view, "Buffer is read-only.");
>> else if (!buffer.getFoldHandler().getName().equals("explicit"))
>>     return;
>> else {
>>     // Save the current Fold-Handler, so we can restore it later
>>     // fh_backup = buffer.getFoldHandler();
>>     // buffer.setFoldHandler(fh_backup.getFoldHandler("explicit"));
>>
>>     displayManager = textArea.getDisplayManager();
>>
>>     //{{{ * Regex for Fold-Lines
>>     // We construct the line in parts for easier editing
>>
>>     // Fold Delimiters
>>     fold_start_string = "\\{\\{\\{";
>>     fold_end_string = "\\}\\}\\}";
>>     depth_mark = "[*]";
>>
>>     // Fold Lines
>>     fold_start_line_re = "^(.*" + fold_start_string + ")\\s*" + depth_mark + "*\\s*(.*)$";
>>     fold_end_line_re = "^(.*" + fold_end_string + ")\\s*.*$";
>>
>>     Pattern fold_start_line = Pattern.compile(fold_start_line_re);
>>     Pattern fold_end_line = Pattern.compile(fold_end_line_re);
>>     //}}} * (Regex for Fold-Lines)
>>
>>     linecount = buffer.getLineCount();
>>     foldstack = new ArrayDeque();
>>     depth = 0;
>>     for (i=0; i<linecount; i++) {
>>         if (buffer.isFoldStart(i)) {
>>             depth = depth + 1;
>>             //{{{ * Save Fold Name
>>             linetext = buffer.getLineText(i);
>>             matcher = fold_start_line.matcher(linetext);
>>             matcher.find();
>>             foldname = matcher.group(2);
>>             foldstack.push(foldname);
>>             //}}} * (Save Fold Name)
>>             //{{{ * Prepend Depth
>>             // save the folding status of the current line
>>             isCollapsed = displayManager.getNextVisibleLine(i) > i+1;
>>
>>             linestart = matcher.group(1);
>>             newline = linestart + " " + getDepthMarker(depth, "*");
>>             if (!foldname.isEmpty())
>>                 newline = newline + " " + foldname;
>>             replaceLine(i, newline);
>>
>>             // restore the saved folding status
>>             if (isCollapsed)
>>                 displayManager.collapseFold(i);
>>             //}}} * (Prepend Depth)
>>         } else if (buffer.isFoldEnd(i)) {
>>             //{{{ * Append Fold Name to Fold End Mark
>>             foldname = foldstack.pop();
>>             linetext = buffer.getLineText(i);
>>             matcher = fold_end_line.matcher(linetext);
>>             matcher.find();
>>             // Extract the part that goes we're going to insert the name after.
>>             pre_name = matcher.group(1);
>>             newline = pre_name + " " + getDepthMarker(depth, "*");
>>             if (!foldname.isEmpty())
>>                 newline = newline + " (" + foldname + ")";
>>             replaceLine(i, newline);
>>             //}}} * (Append Fold Name to Fold End Mark)
>>             depth = depth - 1;
>>         }
>>     }
>>
>>     // Restore Fold-Handler
>>     // buffer.setFoldHandler(fh_backup);
>> }
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by: Microsoft
>> Defy all challenges. Microsoft(R) Visual Studio 2005.
>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>> --
>> -----------------------------------------------
>> jEdit Users' List
>> jEdit-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/jedit-users
>>
>>
>>     


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
-- 
-----------------------------------------------
jEdit Users' List
jEdit-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jedit-users
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic