+4
Completed

powershell syntax support

Mike Foley 14 years ago updated by Alexander Blach (Developer) 13 years ago 9
Hi,
Could you add Powershell Syntax Highlighting support please? You can get an example from Notepad++.

http://notepad-plus.sourceforge.net/commun/userDefinedLang/NotepadPlusPlus_PowerShell.zip

There's also a VIM file for the highlighting.
http://www.vim.org/scripts/script.php?script_id=1327


I occasionally write stuff in Powershell and it would be really nice to be able to do that on my iPad! I'll be buying your app regardless and I thank you for considering it.

Answer

Answer
Completed
PowerShell support will be added in Textastic 2.2.
A generalized method for adding our own syntax highlighting would mean that anything could be supported. If there was some way of sharing schemes, then you (Alexander) could direct your energies towards other things.
Well, the syntax highlighter is based on the open source text editor Fraise (http://www.fraiseapp.com/) which is in turn based on Smultron.

The syntax highlighter uses simple plist files that contain information about keywords, strings, comments, keywords and so on.

If you find a syntax definition compatible with Fraise or Smultron it's really easy for me to support it in an update.

But it's easy to get the regular expressions in the syntax definition wrong so that it either hangs because the regular expression is too complex and takes too long to parse or it's just wrong and makes the app crash...

For the moment, I think it's better if I manually integrate new syntax files.
+1
I would love to see PowerShell added to the syntax support as well. We use it daily at work and it is just one more reason I can try to convince the higher ups to get some iPads for our group.
I've been looking for a PowerShell editor on iPad for a while, and this is the closest I've come, so I'll give this a shot:

I've created a smultron compatible powershell.plist based off of a vb.plist and a powershell.properties file that controls Scite's syntactical highlighting.  I've tested on Smultron 3.5.1 on Leopard.

The file is available here: http://pastebin.com/SwZR2NBa

I noticed that textastic uses the binary plist instead of the xml, but for the sake of encoding woes I think it's better just to paste xml and then you can convert with plutil or somesuch tool.


Really like the app by the way, great work putting together such an elegant tool.
Cool, thanks!

I also noticed that the latest Mac App Store version of Smultron now has a PowerShell syntax definition. This one is quite different from yours. Can you try it out and tell me which one is "better"?
Hi Alexander,

After converting the powershell_smultron.plist to xml from the binary format it was much easier to parse the differences.

"Better" in powershell_smultron.plist:
   * functionDefinition key regex encapsulates the function name and up to the first curly-brace
   *endVariable key is more succinct and relevant for PS.  Frankly, I got lazy with that one.
   *beginInstruction & endInstruction keys have entries which could be useful

"Better" in my powershell.plist
   *support for multi-line comments
   *auto-complete section is not a null array - I list all the powershell cmdlets in here rather than the keywords section

Neither have support for aliases of cmdlets currently.  As these can vary by machine I wouldn't see a need for inclusion either.

So what I did was take the 'better' parts from each, and I have posted the xml version here:

http://pastebin.com/0EDpCE51

As I noted in my previous post, you'll likely want to convert this to binary type so that it is a smaller filesize.
In order to convert to binary mode, on your mac, open terminal and cd to the directory containing the powershell.plist. 
Then run the following command:

plutil -convert binary1 powershell_smultron.plist -e powershell_smultron.plist


You'll obviously need to modify the SyntaxDefinitions.plist as well to include the new language.  Relevant keys would be:
Name (as type string without quotes): "PowerShell"
File (as type string without quotes): "powershell"
Extensions (as type string without quotes): "ps1 ps1xml psc1 psd1 psm1"

Please let me know if there's anything more I can do to help make this happen :)
Great, thanks a lot for your efforts. I've added the syntax definition with some minor edits to Textastic. I had to move the autocompleteWords to keywords because Textastic doesn't highlight the autocompleteWords. It will be included in the next update.

The only problem is that the escape rules of PowerShell are not honored. But that's something I can't fix easily right now.

Here's a screenshot of the syntax definition in action:

Thanks for the quick turn-around on this! 
I shall be advertising the app to my geek friends as being a well implemented tool with stellar development support!
Look forward to 2.2!
Answer
Completed
PowerShell support will be added in Textastic 2.2.