Custom Completion List?

212 views
Skip to first unread message

Shawn Liebling

unread,
Jan 17, 2022, 5:09:29 PM1/17/22
to BBEdit Talk
I have a question that is hopefully simple. I'm somewhat of a BBEdit beginner, so please keep that in mind when answering.

I'm currently working on a huge project in which I am adding character attributions to book dialogue from a very large fantasy series, so it's a lot of work. I'm trying to make the process go as fast as possible, so I'm hoping to have autocomplete use a list of character names to make it go faster. Here is a screenshot of some sample text from the book I'm working on:

AutoComplete_ScreenShot.png

As you can see, I am using a custom language called "Shawn" so that I can use custom colors for attributions (blue), normal text (black), and dialogue text (brown). I figured out how to do this by asking a question of this group and y'all were very helpful!

So my current process is to find "xxx" which selects the "xxx" and allows me to just type the character name, then do a "find next" (command-G) to move on to the next one. However, I want to be able to just type the first 1-2 letters of the name and then hit <tab> to insert the name using autocomplete. Ideally the autocomplete suggestions would only include character names from a list, such as "Bran, Cenn, Mat" for the above example. This doesn't speed up the process much with the short names, but it would definitely be helpful for longer more complex names.

From reading the BBEdit documentation this seems possible, especially since I'm using a custom language, but I can't figure out how to do it. I also can't get autocomplete to work at all when using my custom language. Nothing happens, and the "Complete" menu item in the Edit menu is grayed out. I have completion enabled in both the completion preferences and the language specific settings, so I don't know why it's not working.

Thanks in advance for any help that y'all can offer!

-shawn

P.S. In case anyone was wondering, I'm adding the blank attributions ([xxx]) in one step using a Python script that inserts [xxx] at the begging of every line that has dialogue in it (lines that contain a beginning quote mark).

Rich Siegel

unread,
Jan 17, 2022, 5:16:07 PM1/17/22
to BBEdit Talk
Since you have a custom language module, make sure that it specifies that it supports completion:

<key>BBLMSupportsTextCompletion</key>
<true/>

(And of course, completion isn't available in Free Mode, but if you have a paid license or active Mac App Store subscription, that won't be the issue here.)

As to the character names: offhand, I'm thinking that you could add your character names as predefined symbols in the language module. That way, completion would present them to you as such. (Multi-word names with spaces in them can be a challenge, though.)

Auto-replacement using external tools (TypeIt4Me, Text Expander, Typinator, etc) might be an option, as well.

Good luck,

R.


--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <https://www.barebones.com/>

Someday I'll look back on all this and laugh... until they sedate me.

Shawn Liebling

unread,
Jan 17, 2022, 8:05:40 PM1/17/22
to BBEdit Talk
Thanks for the tip on how to enable text completion! However, it still doesn't appear to be working for me. I added those lines to the language PLIST file, but perhaps I did something wrong? I will attach the PLIST file for your inspection. Oh, and I do have a paid license through an App Store subscription.

Also, how so I add character names as predefined symbols?

Thanks!
Shawn

Shawn.plist

Rich Siegel

unread,
Jan 17, 2022, 8:19:57 PM1/17/22
to BBEdit Talk
On 17 Jan 2022, at 18:50, Shawn Liebling wrote:

> Thanks for the tip on how to enable text completion! However, it still
> doesn't appear to be working for me. I added those lines to the language
> PLIST file, but perhaps I did something wrong?

Sorry I wasn't clearer - you still need to add a list of things to the module to complete. (Also, don't forget that if you edit your language module, you have to quit and relaunch BBEdit for the changes to take effect.)

To add a list of predefined names, use the "BBLMPredefinedNameList" key:

<key>BBLMPredefinedNameList</key>
<array>
<string>John Lennon</string>
<string>Paul McCartney</string>
<string>George Harrison</string>
<string>Ringo Starr</string>
</array>

(NOTE: These won't be colored correctly because of the spaces, and I don't actually know :-) whether they'll behave as desired for completion, but if they don't, please write to Tech Support.)

Shawn Liebling

unread,
Jan 17, 2022, 8:36:31 PM1/17/22
to BBEdit Talk
> you still need to add a list of things to the module to complete

Ah.. so it won't use words from inside the document for autocomplete? For example, when editing that same text file using "Text File" as the language, it autocompletes names/words from the text file, and I would like to know how to have the same thing work in my document when it's set to the "Shawn" language (if that's possible). I figure this is my fall back option if I can't get the custom name list to work.

> Also, don't forget that if you edit your language module, you have to quit and relaunch BBEdit for the changes to take effect.

Yep, I've been restarting BBEdit every time I edit the PLIST file.

> To add a list of predefined names, use the "BBLMPredefinedNameList" key

Ok, I tried doing that and the autocomplete still doesn't work (for words in the document, and when typing in the names you provided in the example). I'll go ahead and attach my newest PLIST file in case I made a mistake.

Also, here are screenshots from the appropriate settings in case it's helpful:

Completion_Settings.png

Language_Settings.png

Thanks!
-shawn
Shawn.plist

jj

unread,
Jan 18, 2022, 5:44:29 AM1/18/22
to BBEdit Talk
Hi Shawn,

Here is a Shawn.plist that follows Rich's recommendations and seems to work regarding completions.

There was a misconfiguration in the .plist I originally posted. Sorry for that.
Apparently the key defining 'Identifier and Keyword Characters' prevented BBEdit from displaying completions.

The key:

    <key>Identifier and Keyword Characters</key>
    <string>\S</string>

is now replaced by:

    <key>Identifier and Keyword Character Class</key>
    <string>\S</string>

I also note that you changed the Number Pattern.
Be aware that <[\d+]> is a regular expression that will only match a single decimal or a '+' sign in between angle brackets (i.e., <0>, ..., <9>, <+>) :

    <key>Number Pattern</key>
    <string><![CDATA[(?x)
    <
        [\d+]
    >
    ]]></string>

If what you want to match is someting in the form <123,456> then this pattern is more appropriate:

    <key>Number Pattern</key>
    <string><![CDATA[(?x)
    <
        [\d,]+?
    >
    ]]></string>

HTH,

Jean Jourdain

--
Shawn.plist

```
<?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>BBEditDocumentType</key>
    <string>CodelessLanguageModule</string>
    <key>BBLMColorsSyntax</key>
    <true/>
    <key>BBLMIsCaseSensitive</key>
    <true/>
    <key>BBLMSupportsTextCompletion</key>
    <false/>
    <key>BBLMPredefinedNameList</key>
    <array>
    <string>John Lennon</string>
    <string>Paul McCartney</string>
    <string>George Harrison</string>
    <string>Ringo Starr</string>
    <string>Beyoncé With Accent</string>
    </array>
    <key>BBLMLanguageCode</key>
    <string>SHAW</string>
    <key>BBLMLanguageDisplayName</key>
    <string>Shawn</string>
    <key>BBLMScansFunctions</key>
    <false/>
    <key>BBLMFunctionScannerDoesFoldsToo</key>
    <false/>
    <key>BBLMSuffixMap</key>
    <array>
        <dict>
            <key>BBLMLanguageSuffix</key>
            <string>.shawn</string>
        </dict>
    </array>
    <key>Language Features</key>
    <dict>
        <key>Close Block Comments</key>
        <false/>
        <key>Close Statement Blocks</key>
        <false/>
        <key>End-of-line Ends Strings 1</key>
        <false/>
        <key>End-of-line Ends Strings 2</key>
        <false/>
        <key>Escape Char in Strings 1</key>
        <string>\</string>
        <key>Escape Char in Strings 2</key>
        <string>\</string>
        <key>Identifier and Keyword Character Class</key>
        <string>\S</string>
        <key>Open Block Comments</key>
        <false/>
        <key>Open Line Comments</key>
        <false/>
        <key>Open Statement Blocks</key>
        <false/>
        <key>Close Strings 1</key>
        <false/>
        <key>Close Strings 2</key>
        <false/>
        <key>Open Strings 1</key>
        <false/>
        <key>Open Strings 2</key>
        <false/>
        <key>Number Pattern</key>
        <string><![CDATA[(?x)
<
    [\d,]+?
>
]]></string>
        <key>String Pattern</key>
        <string><![CDATA[(?x)
(
    “(\\“|[^”])*?”  (?# Double-curly-quote)
|
    "(\\"|[^"])*?"  (?# Double-quote)
|
    '(\\'|[^'])*?'  (?# Single-quote)
)
]]></string>
        <key>Comment Pattern</key>
        <string><![CDATA[(?x)
\[
    [^\[\]]+?
\]
]]></string>
    </dict>
</dict>
</plist>

Shawn Liebling

unread,
Jan 18, 2022, 11:26:52 AM1/18/22
to BBEdit Talk
Hi JJ! Thanks for helping out again. Unfortunately that new PLIST doesn't seem to make a difference and autocomplete still doesn't work using my "Shawn" language (and yes, I've restarted BBEdit multiple times and double checked the PLIST to make sure I updated it using your new code).

I'm also not sure having the name list in the PLIST is an ideal solution since the book series has over 2,500 names and trying to put them all in that PLIST seems like a bad idea. I also want to only use names from each individual book series when I am working on that book, so the ideal situation would be to have a series of files that each have all the names from each book, and then have BBEdit only be using autocomplete from that book's file.

From looking at the documentation, it seems like using the "Completion Data" folder might be a solution? It says that I can put a "tags" file into a subfolder named "Shawn" and BBEdit will use that file for autocompletion? However, I don't know how to generate such a file and it's not entirely clear how to do it in the user manual.

Anyways, I currently have 3 items I'm trying to address:

1. The fact that I can't get autocomplete to work at all when using the Shawn language. For example, here is a screenshot of trying to use autocompletion using "Shawn" (imagine the cursor to the right of "Ra" within the brackets):

AutoComplete_Shawn.png

And when I switch the file to use a different language such as Python, it works as shown here:

AutoComplete_Python.png

2. If it's possible to have BBEdit only use a specific list for AutoComplete and not present other options (such as the words in the document). So in the Python example above, typing "Ra" would only result in the name "Rand" since it would only be using the name list.

3. How to have BBEdit only use words from within the document for autocomplete. I'm thinking this is a good backup option that might work just fine for me. In the example above, "Rand" is the only word that comes up when I type "Ra" if I am in Text File mode, so I expect it will work fairly well for many of the names.. with the only exceptions being when a similar word starts a sentence, such as if the word "Random" started a sentence in the document, then it would present me with both "Rand" and "Random".

Also, what do the little letters mean in the autocomplete? Like in the Python example above it has "C" and "k" and "Rand" shows up twice?

And..

> Be aware that <[\d+]> is a regular expression that will only match a single decimal

Ya, that was my mistake. Over the past couple weeks I've been learning regular expressions in Python, so I'm getting a better grasp of them, but I'm still learning and don't fully understand how everything works. I also don't entirely understand the formatting of that PLIST file, so I had to play with it a bit to change the pattern and have it work, which it did.. and I'm not sure why it did since it doesn't seem like it would work for the reasons you provided. Hmm..

Thanks again for everyone's help! I also have a case opened with BBEdit, so if nobody here can figure this out then I'll see if they can help me (they are standing by to see if I can come up with a solution with you folks).

-Shawn

P.S. I'm attaching the test file I'm using just in case that is creating an issue for some reason (which seems unlikely).
AutoComplete_Test.txt

jj

unread,
Jan 18, 2022, 12:48:42 PM1/18/22
to BBEdit Talk
Shawn,

1. It seems that the problem is in the "Identifier and Keyword Character Class".
By specifying \S (Anything that is not whitespace) the starting square bracket is included in the completion prefix.
Obviously there is no "[ra..." entry in "BBLMPredefinedNameList".

Try with this:

    <key>Identifier and Keyword Character Class</key>
    <string>\p{Xwd}</string>
 
\p{Xwd} is a unicode character class that matches letters, digits and underscores.
The BBEdit keyword parser should now use "ra..." as a completion prefix.


2. BTW, a completely different but probably easier approach whould be to use Clippings. (BBEdit manual p. 315).

Create a directory for the Shawn language clippings:

    % mkdir -p ~/Library/Application\ Support/BBEdit/Clippings/Shawn.shawn/
   
Inside that directory create a file named "ys".
and inside that file paste this content: "We all live in a yellow submarine."

    % echo "We all live in a yellow submarine." > ~/Library/Application\ Support/BBEdit/Clippings/Shawn.shawn/ys

The "ys" entry should now appear in the completion menu after you type a "y" in a Shawn language document .

This approach doesn't need you to restart BBEdit.
Just keep adding clipping files to the Shawn.shawn/ directory.
The name of the file should be the abbreviation, the contents of the file should be the replacement string.

HTH

Jean Jourdain

Shawn Liebling

unread,
Jan 18, 2022, 3:19:21 PM1/18/22
to BBEdit Talk
> 1. It seems that the problem is in the "Identifier and Keyword Character Class".

I made the suggested change, and now it works with keywords (the ones defined in the PLIST file are considered "keywords" right?) and clippings (which I assume are the little "C" in the autocomplete list). I actually tried using clippings before and already have a clippings file with "Rand" in it, so Rand now shows up from that clipping file. However, using clippings means I would have to create hundreds/thousands of individual files for each character? If so, that seems like an odd way of going about it. I guess I could make a Python script that generates all those files.. but it seems like having a basic list of character names for each book makes the most sense (if that's possible). Is there a way to create a keyword list that is separate from the PLIST file? If creating a list isn't possible, then I could probably make the clippings thing work, assuming thousands of clippings files will work and not slow things down.

Also, I still can't get the normal autocomplete to work properly with my "Shawn" language, which still might be a solution that works good enough. So how do I go about making it so that autocomplete uses words from the document when using my "Shawn" language? For example, if I type "Ce" then it would autofill "Cenn" which is a word found in that sample text, but that still doesn't work.

Thanks much,
Shawn 

Patrick Woolsey

unread,
Jan 18, 2022, 4:47:39 PM1/18/22
to bbe...@googlegroups.com
I'm borrowing this specific question as a chance to promote some general advice :-):

Also, what do the little letters mean in the autocomplete? Like in the Python example above it has "C" and "k" and "Rand" shows up twice?


In the screenshot Shawn posted:


The first entry with a "C" in a black circle is indeed a _clipping item_.

The second entry with no prefix is a token from the current document's content.

The third entry with a lower-case "k" in a blue square is a _predefined symbol_.

For reference, you can find a comprehensive enumeration of completion symbols in the table of the same name within Chapter 4 of the PDF manual (page 122 of the current edition).


Regards,

 Patrick Woolsey
==
Bare Bones Software, Inc.             <https://www.barebones.com/>

jj

unread,
Jan 18, 2022, 5:25:52 PM1/18/22
to BBEdit Talk
Shawn,

If you have hundreds/thousands of possible completions, you could simply use the System Text Replacement feature.

https://support.apple.com/en-bh/guide/mac-help/mchl2a7bd795/mac

You can export/import a hand crafted Text Substitutions.plist into 'System Preferences > Keyboard > Text' by drag & drop.

Here is a sample Text Substitutions.plist with ± 250 entries if you want to test the concept.

WARNING: Backup your existing Substitutions if you have some by dragging them to the finder before adding new entries.

HTH

Jean Jourdain

Shawn Liebling

unread,
Jan 18, 2022, 5:42:51 PM1/18/22
to BBEdit Talk
Hi JJ,

Thanks for the tip! I figured out how to use a keyword list which seems to be a great solution, but I will try out the system text replacement if a large keyword list causes issues. However, I'm still not able to use normal autocomplete with my "Shawn" language, so the System substitutions won't work until I figure that out. I'm currently emailing with BBEdit tech support to address this issue (I'm communicating with Patrick who posted a message above).

BTW, to make the keyword list work (thanks to Patrick for the instructions), I simply put a text file into the "Custom Keywords" directory within the BBEdit application support folder. The text file has the extension ".Shawn" and simply has a keyword per line of the file such as this:

Mat
Cenn Buie
Bran al'Vere

I've attached a video of the keyword list in action to this message. And here is a screenshot from that video:

KeyWord_Autocomplete.png

Thanks again for your help! And many thanks to Patrick at BBEdit tech support as well.
-shawn
AutoComplete_Screen_Record.mov

Christopher Stone

unread,
Jan 18, 2022, 6:30:02 PM1/18/22
to BBEdit-Talk
I'm currently working on a huge project in which I am adding character attributions to book dialogue from a very large fantasy series, so it's a lot of work.


Hey Shawn,

Personally I'd do this with either Typinator or Keyboard Maestro instead of wrestling with BBEdit language modules.

Flexibility and ease of use are the name of the game with such tasks.

Typinator offers easily configured custom quick search lists.

Keyboard Maestro is the best of breed macro utility available for the Mac these days and allows the easy creation of searchable pop-up lists from a plain text file (or other media).  You can add keywords to the prompt text to make searching even easier.



Typinator showing my regular expression pattern list:


Abbreviation ⇢ Descriptive Text



Keyboard Maestro Prompt-With-List action showing URL bookmarks from a text file.

Only titles and tags are shown.

Selection will insert the object text (in this case a URL).


You can edit the text file with ease using BBEdit.

--
Best Regards,
Chris

Shawn Liebling

unread,
Jan 18, 2022, 6:55:01 PM1/18/22
to BBEdit Talk
Hi Chris,

Thanks for the recommendations! I got BBEdit to work fairly well using a custom keyword list, but if I encounter any issues or slow-downs, I'll definitely look further into Typinator and Keyboard Maestro. The first response from Rich also recommended Typinator along with some others, so I did take a quick look at the Typinator website already.

It sounds like I have lots of different options to choose from for this project, so that's great.

Cheers,
Shawn

jj

unread,
Jan 19, 2022, 7:01:05 AM1/19/22
to BBEdit Talk
Hi Shawn,

If you are not yet able to autocomplete within the Shawn language, try adding this to your Shawn.plist

    <key>BBLMSpellableRunKinds</key>
    <array>
        <string>*</string>
    </array>
    <key>BBLMCompletableRunKinds</key>
    <array>
        <string>*</string>
    </array>

Jean

Shawn Liebling

unread,
Jan 19, 2022, 10:15:01 AM1/19/22
to BBEdit Talk
Hi JJ,

> If you are not yet able to autocomplete within the Shawn language, try adding this to your Shawn.plist

I gave that a try and it doesn't seem to change anything. Patrick at BBEdit tech support is currently working to solve the issue, so hopefully I will hear from him today.

Thanks much,
Shawn

Reply all
Reply to author
Forward
0 new messages