Scriptless Language Module help for text documents

111 views
Skip to first unread message

Travis Edrington

unread,
Sep 14, 2022, 5:18:04 PM9/14/22
to BBEdit Talk
I use BBEdit for all of my generic text needs, but one thing I love from programming that is not available (as far as I can tell) is folding for generic text files.  Sometimes when I am using Bbedit for notes I will create blocks like I am writing code.  I wanted to be able to fold these blocks out of the way when I don’t need them.  I decided to make a Language Module that lets me add comments and blocks using common programming comment styrax like // or /* */ or <!— —>.  I think I am where I want it to be, my comment pattern’s all work as expected, and I used a pList editor, but when I save and restart BBEdit it does not appear in the list.
Could anyone help me figure out why it's not loading (guessing I have an error). I know I have the pList in the right folder.  I have a github started at https://github.com/traisjames/BBEdit-FoldingText because if its working I am happy to share my crazy.

jj

unread,
Sep 15, 2022, 4:38:09 AM9/15/22
to BBEdit Talk
Hi Travis,

There are a few issues with your module.

1. BBEdit reports an error in your module

    Menu BBEdit > Folders > Logs
    Check ~/Library/Containers/com.barebones.bbedit/Data/Library/Logs/BBEdit/Language Module Errors.log

        ================================================================================
        2022-09-15 10:30:24.678: Startup
        The following problem(s) were encountered while loading the language module at ~/Library/Application Support/BBEdit/Language Modules/foldingtext.plist:
            The Comment Pattern was invalid (missing closing parenthesis (error 112114) at offset 224 in pattern).
        The reported problems will prevent the language module from loading.

    This is due to the '#' characters not being escaped in '(?s:^#.*?#$)' when using the (?x) modifier. Should be '(?s:^\#.*?\#$)' .

 2. Not sure if Codeless Language Modules will do Comment Pattern folding.  You could use Function Pattern folding instead.
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>BBLMCanSpellCheckCodeRuns</key>
        <true/>
        <key>BBLMCommentPrefixDefault</key>
        <string>#</string>
        <key>BBLMCommentSuffixDefault</key>
        <string>#</string>
        <key>BBLMCommentLineDefault</key>
        <string>//</string>
        <key>BBEditDocumentType</key>
        <string>CodelessLanguageModule</string>
        <key>BBLMColorsSyntax</key>
        <true/>
        <key>BBLMIsCaseSensitive</key>
        <false/>
        <key>BBLMLanguageCode</key>
        <string>txtF</string>
        <key>BBLMLanguageDisplayName</key>
        <string>Folding Text</string>
        <key>BBLMScansFunctions</key>
        <false/>
        <key>BBLMSuffixMap</key>
        <array>
            <dict>
                <key>BBLMLanguageSuffix</key>
                <string>.txt</string>
            </dict>
        </array>
        <key>BBLMScansFunctions</key>
        <true/>
        <key>BBLMFunctionScannerDoesFoldsToo</key>
        <true/>
        <key>Language Features</key>
        <dict>
            <key>Identifier and Keyword Character Class</key>
            <string>\p{Xwd}</string>
            <key>Function Pattern</key>
            <string><![CDATA[(?x)(?s)
    (?P<function>
        (?P<function_name>
            //[^\v]*                    (?# Line comment using //)
        |
            \/\*.*?\*\/                 (?# Block comment using /* */)
        |    
            ^\#.*?\#$                   (?# Block comment using #...#)
        |
            ^<!--.*?-->$                (?# Block comment using <!-- -->)
        )
    )
    ]]></string>
        </dict>
    </dict>
    </plist>

HTH,

Jean Jourdain

Keith Irwin

unread,
Sep 15, 2022, 7:05:54 AM9/15/22
to bbe...@googlegroups.com
Not sure if this helps (because it doesn’t answer your direct question), but you can select an arbitrary block of text, then right-click and choose “Fold Selection”. Could assign a keyboard shortcut, or use the ⌘⇧U and type in Folds.

On Sep 14, 2022, at 2:16 PM, Travis Edrington <trais...@gmail.com> wrote:

I use BBEdit for all of my generic text needs, but one thing I love from programming that is not available (as far as I can tell) is folding for generic text files.  Sometimes when I am using Bbedit for notes I will create blocks like I am writing code.  I wanted to be able to fold these blocks out of the way when I don’t need them.  I decided to make a Language Module that lets me add comments and blocks using common programming comment styrax like // or /* */ or <!— —>.  I think I am where I want it to be, my comment pattern’s all work as expected, and I used a pList editor, but when I save and restart BBEdit it does not appear in the list.
Could anyone help me figure out why it's not loading (guessing I have an error). I know I have the pList in the right folder.  I have a github started at https://github.com/traisjames/BBEdit-FoldingText because if its working I am happy to share my crazy.

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/ed5dceda-03a8-40fc-95ac-893f6bf3b01an%40googlegroups.com.

Travis Edrington

unread,
Sep 15, 2022, 3:19:06 PM9/15/22
to BBEdit Talk
Oh thank you, I was hoping there would be some place it tossed errors but wasnt sure.
I wasn't sure if # needed to be escaped or not.  Thank you for the suggestions, I will try them and let you know what works.

Travis Edrington

unread,
Sep 15, 2022, 3:56:06 PM9/15/22
to BBEdit Talk
Your right it doesn't do comment folding.  I will use your method instead.  Thank you.

On Thursday, September 15, 2022 at 3:38:09 AM UTC-5 jj wrote:

Travis Edrington

unread,
Sep 15, 2022, 3:59:33 PM9/15/22
to BBEdit Talk
Now to figure out how to make it go ahead and color the comments just for the fun of it.  But that is for after work Travis
Reply all
Reply to author
Forward
0 new messages