How to define new code completions?

Florian Lücke 11 years ago in General updated by Teddy Svoronos 8 years ago 9

I know there are examples for custom completion files, but somehow I just don't get it. I would really like code completion for LaTeX on my iPad, so I copied one of the example files, generated a new uuid on my MacBook using uuidgen and changed some stuff around, then uploaded the file to my iPad and restarted Textastic, but the code completion window won't show up. I feel like my main problem is the pattern in the context part of the file. Which kind of regex does Textastic use? Textmate uses Oniguruma Regular Expressions, does Textastic, too? Also, what happens if the regex matches/does not match?

I thought it should be fairly easy to create those files, but unfortunately the git repository has not been updated for almost a year and the file format is not documented :( Help is greatly apreciated!


Textastic uses the Oniguruma regex engine like TextMate.

Here's how Textastic checks whether it needs to display code completions:

  • First, it looks if the scope at the cursor matches the scope selector of a code completion context (this is the "scope" element in a context) - you can show the current scope in Textastic by tapping in the editor with three fingers. It's probably easier to use TextMate on a Mac though.
  • If the scope selector matches, Textastic tries to match the regular expression in the "pattern" backwards from the cursor position
  • If the regular expression matches, it will uses the capture defined by the "completionCaptureIndex" as a prefix for the strings referenced by the "completionSetNames" array
  • It will show all strings from the completionSet that have the prefix found in the previous step

Thanks for your quick answer! Seems I'm just a bit too stupid for that kind of stuff ;) I'll play around with it some more :)

Is it possible backslashes prevent code completion? No matter how I set up my regex it does not seem to match. I set up a completionSet called "latex.keywords" and added a few basic latex keywords to it, like \begin{, \end{, \usepackage{... Then I created a context, set its scope to "text.tex.latex" and the completionSetNames array to only contain "latex.keywords", but no matter how I set up my regex it does not seem to match. I tried "\\([a-z]*)" (among others) to detect a backslash followed by a sequence of letters, which should match for example \beg so Textastic should suggest inserting \begin{ but nothing happens. Any clue what might cause this?

This is a JSON file, so you need to escape the regular expression string:

If your regular expression contains one backslash "\", it needs to be encoded for JSON like this "\\".

So, if your regular expression starts with two backslashes, you need to actually put four backslashes in the json file: "\\\\([a-z]*)".

Sorry, I should have been more clear about that. "\\([a-z]*)" is the encoded form of the regex, which should detect a single backslash followed by an arbitrary amount of letters, which is the form of a LaTeX keyword. Am I missing something here?

Can you send me the .json file to support@textasticapp.com so I can have a look at it and try to make it work?

I would like to use code completion for LaTeX as well, and I wonder if the issue has been solved. I have tried the same as the OP.

Check out my Textastic-Customization repo over at github. I uploaded my json file there. Not sure if it's what you need, but if not you can always take a look inside and see what you can come up with ;)

Hello, I see that this is many years old but am hoping that some version of code completion for latex is available? Florian's last link no longer works, but perhaps Alexander has access to that JSON file