# Textmate - New KSP Editor with Custom syntax Highlighting/Folding and Code Snippets



## sonaht (Nov 9, 2011)

Hi Everyone,

Like many of you I have been using Nils KSE editor for scripting however it does not work as good on OS X as it does on the PC (different line endings, problem with big scripts, slightly outdated etc.). This is partly because it is/was ported into OS X not by Nils himself but by someone else.

Please note that this post is not meant in any way to start a war in code editors, just my personal choice and my sharing it with the community. Also I am not affiliated with macromates (the developer of textmate). I merely made a custom bundle to support custom syntax highlighting and folding for KSP for my own(and now your) use. 

The cool thing about Texmate is that it does code snippets. 

I have spent the last couple of weeks copying every command from the KSP 5.0 Reference Manual and (with a few exceptions) you type only the first 3 letters of a Built-in variable and press *"tab"* and you are presented with all the commands that 
start with those letters. Same goes for all the callbacks, functions, conditional statements etc, they are all typed in and when let's say you want to do an if statement you type "if" press tab and you get a completed if statement where you can tab between all
the various conditions, variables etc... I made it so all the commands come pre typed with the syntax as a placeholder 
So if let's say you type "set" and press tab and then type "1" you will get: set_control_par($ui-ID,$CONTROL-PARameter,$value) and you can tab between the various parameters and fill in the different variables. 







One thing to note is to select the KSP customization use the shortcut: shift-control-option-command-K or select it in the lower left corner (just like BBEdit)

Here is where you can download the editor (it has a 30 day trial and it's 40 dollars after that I think:
http://macromates.com/

After installation of the software, unzip the attachment of this thread, http://pinartoprak.com/KSP/KSP_OSX.zip (KSP OSX Custom Bundle) double click on ALL the files to install them, the "KSP.tmbundle" file, the "Source.tmbundle" file, the "KSP - *BRIGHT*.tmTheme" file as well as the Inconsolata.otf font file(it's a programmers font that looks really nice).

You can also access all the custom made shortcuts from textmate with the shortcut "control-option-command-K". I also made an excel sheet that documents all the commands as well as their shortcut.

• Escape "~" rotates all typed parameters in the script(aotocomplete). So if you have used "$count" before all you have to type is "$co" and press escape and it will show up ( or it will rotate between $count_1 and $count_2 if you had used these before).

• Command - 4 prefixes variables with the $ sign. I tend to write a variable and decide afterwards if it's a variable or an array or a string array etc so I made a macro with that shortcut that basically goes to the beginning of the word appends $ and goes back to the end of the word. That comes in handy with the above example of autocompletion where you could type "co" without the $ sign, esc to autocomplete and then press command 4 and voila!

• Command-5 prefixes a word with the % symbol (same as above)

• Command-2 is for @ string variables

• Command-1 is for string arrays

• All callbacks are foldable as well as functions, if and while statements.






For custom folding beyond the callbacks you can do it with:
{<custom-fold>}
...
code
...
{</custom-fold>}

• You can comment out a variable or anything by selecting it and pressing "command-forward slash (/)"

• You can also comment a block of code out by selecting it and pressing "option-command-forward slash (/)"

• The assign symbol := can be typed just with the " : " It drives me mad to have to type both all the time so I made a macro that types := when I only type : 

• Typing "todo" and pressing tab creates a commend with all the "To do" items that you might need on your script. What makes this feature great is that you can put this anywhere in the script and then pressing "Control - Shift T" gets you a pop up window with whatever notes you made to yourself.

• Typing "head" and pressing tab in the beginning of the document creates a comment header where you can type in all the usually header info.

• The custom coloring that I created is accessed through the preferences (command ,) and you don't have to use it or can customize it to your liking. I made it so there is different colors for variables, arrays, built in or constant variables in capitals, strings, numbers, keywords(if, while, on init, end on etc) and comments. There are also some dark themes that are easier in the eyes for scripting at night. 






It can be customized even more with more snippets or macros but I'll add more stuff as I go. You can add more stuff too if you end up using it.

I hope you like it

Best,
Thanos


----------



## Mike Greene (Nov 9, 2011)

Very cool! 

Funny, after loading the Windows version of KScript, I noticed a couple of the differences, most noticeably that KScript no longer crashes when scrolling too fast in big scripts. It's nice not having those crashes anymore!

I'd love to be able to go back to the Mac for this, plus I look forward to checking out some of these other features. I love the syntax placeholder idea. _(set_control_par($ui-ID,$CONTROL-PARameter,$value))_ I don't code every day, so for me, I have to constantly check the manual for the syntax, so this will be a big help.

Thank you for making this available. o-[][]-o


----------



## UCAudio (Nov 24, 2011)

Thanos, this looks awesome. I'm probably just doing something stupid but I can't seem to get my code to be colored. All of the text is black. I installed textmate along with the files in your zip. 

Do I need to create a KSP template? I'd like my code to look how yours does in the screenshots posted with the white background. 

Thanks!


----------



## sonaht (Nov 24, 2011)

Hello,

It's probably in plain text mode. You have to select KSP from the lower left corner where you select the language syntax highlighting. Or you can press the shortcut I made which is: Command-option-Control-Shift + K
And that should bring the KSP coloring to the script. 

Best,
Thanos


----------



## UCAudio (Nov 24, 2011)

Yep that worked, thanks again.


----------



## sonaht (Nov 24, 2011)

Or if you have done that, then it's a matter of going to the TxMT preferences under colors or Syntax Highlighting and select the KSP theme of your choice.


----------



## UCAudio (Nov 24, 2011)

One more thing, I'm trying to comment out a block of code using "option command /" and it tries to comment it out using /* ...code... */. Is there a way to make it instead use { ...code... } so that the comment block turns green? 

I'm loving this so far, great job.


----------



## sonaht (Nov 25, 2011)

Hi there,

Yes there is a way to have the command / and option command / comment a block or a line and it's part of modifying another part either the source or C bundle. I have it like that in my system but I need to look and see what I modified. Did you doubleclick to install the source bundle that was included in the zip file?

If that is not where that behavior happens I need to see what else I modified to change it to {} that KSP needs for comments.

I can let you know on Monday.

Best,
Thanos


----------



## sonaht (Nov 30, 2011)

Hi UCAudio,

I just installed it in a computer with no TxMt and I have the comments in. I think if you doubleclick the "Source" bundler in the unzipped folder and then click ok on the "Update/Modify question" window then the {...comment...} functionality with 
"Command / " or " Command-Option / " should work. 

Best,
Thanos


----------



## kotori (Oct 2, 2013)

I can't seem to be able to download the file KSP OSX Custom Bundle. Anyway, I thought I'd attach a couple of files that I made for my Sublime Text 3 KSP plugin. I think they might be compatible with TextMate as well.

Cheers,
Nils


----------



## jpernell (Jan 7, 2014)

Hi Thanos,

I stumbled across this thread and am curious to try out your custom bundle, but the link seems to be down at this point. Is there any way of re-uploading the link? Thanks very much 

Cheers,
Jacob


----------



## derstefmitf (Jan 8, 2014)

jpernell @ Tue Jan 07 said:


> Hi Thanos,
> 
> I stumbled across this thread and am curious to try out your custom bundle, but the link seems to be down at this point. Is there any way of re-uploading the link? Thanks very much
> 
> ...



+1
It would be really nice if someone could upload the file again. Sounds like an awesome tool.
Thanks.


----------



## mk282 (Jan 8, 2014)

Better switch to Sublime Text 3 and Nils' SublimeKSP extension, which he posted in the post above yours, jpernell.

Also: http://www.vi-control.net/forum/viewtop ... 65#3731865


----------



## jpernell (Jan 8, 2014)

Ah, I'll check it out. Thanks


----------



## sonaht (Jan 8, 2014)

Hello,

The links of the original post work again.


----------



## jpernell (Jan 8, 2014)

Cheers Thanos!


----------



## Mike Greene (Jan 8, 2014)

I finally took the plunge and installed this. I love these features. The folding is especially useful.

One question, though. I assume there is a way to either compile or check syntax? Typically I would go to the Bundles dropdown menu, and select something like Applescript, where I see options for compiling or checking syntax or whatever, but when I select KSP, rather than those options, I instead get a long list of all the possible lines from the manual, starting with "on init...end on"


----------



## sonaht (Jan 9, 2014)

Hi Mike,

I'm not sure if your question is aimed at me or Nils.. I actually also moved from Textmate to Sublime Text. Sublime also reads all the tmlanguage settings and code snippets so the transition was easy. Plus it has auto completion and multiple cursors as well as different text plugins for formatting arrays, text etc..

In both I have used regex for syntax highlights and fuzy search for auto completion but it does not compile or check syntax. 

In TextMate the KSP menu will only give you a list of the code snippets along with placeholders for the different function arguments. I have not written a compiler for it like Nils did for Sublime 3 and his KSP plugin that includes a python compiler and syntax checker.

If the question was aimed at Nils then disregard all the above


----------



## Mike Greene (Jan 9, 2014)

Thanks Thanos. The question was indeed aimed at you.

Hmmm . . . I was really liking TextMate, but maybe I'll go to Sublime Text, since you guys are there. I'm way too incompetent to go a different route than everyone else. :mrgreen: My problem, though, is that I'm still on Snow Leopard, which only supports Sublime Text 2.

How do you check syntax or compile? Do you just just copy code into Kontakt? For me, Kontakt's error messages tend to be really unhelpful, plus their line numbers never seem to match mine, so I can't imagine using it to check syntax. That's one thing I love about Nils KSP Editor is it's really clear about where my syntax errors are.

Then again, you probably make a lot fewer errors than I do!


----------



## polypx (Jan 9, 2014)

I'm also using Sublime Text with Nils' KSP plugin now, and it's absolutely awesome. (Just throwing another vote up here to convince Mike to switch. )

I also dual boot, Mike, I have one drive with 10.6.8 on it, but most of the time use 10.8 now.

cheers, Dan


----------



## Mike Greene (Jan 9, 2014)

I'm playing with it on Sublime Text 2 right now and it's great. But how the heck do you compile?


----------



## mk282 (Jan 9, 2014)

I think it's F5, or Cmd+K (for "Kompile" ).


----------



## Mike Greene (Jan 9, 2014)

Neither of those work. I have a script and attached a .ksp extension. If I hit F5, instead of compiling, it does this bizarre process of sorting all the lines according to tab structure. Blank lines first, then all the lines tabbed 6 deep, then all the lines 5 deep, etc. I'm trying to figure out why anyone would ever want to do that. :mrgreen: 

Command-K doesn't compile either. It just deletes whatever line I'm on. Apple-K does the same thing, but seems to take two steps instead of one.

Maybe I installed this wrong? I went to the Sublime Text 2 folder in Library >> Application Support. Then in the "Packages" folder, I created a "KSP" folder and dragged the three items from Nils' zip file (KSP.tmLanguage and KScriptDark.tmTheme and KScriptLight.tmTheme) into this new folder.

Files with .ksp extensions open up as they should (commands and variables colored as they should be,) and KSP is checked as a lanuage option, so it seems correct. But no indication of Compile options (or anything else KSP related) under the Tools menu.


----------



## polypx (Jan 9, 2014)

It's command-K, or KSP-Compile from the "Tools" menu. 

Do you see all the KSP specific stuff in the Tools menu? If not, it's probably not installed correctly. I couldn't get anything to install correctly until I got Sublime Text 3 myself. Not sure if it CAN work in 2 or not.


EDIT- I just noticed in Nils Read me... quote:

## SublimeKSP
A Sublime Text 3 plugin for working with and compiling Kontakt script code (KSP code).


----------



## Mike Greene (Jan 9, 2014)

polypx @ Thu Jan 09 said:


> I couldn't get anything to install correctly until I got Sublime Text 3 myself. Not sure if it CAN work in 2 or not.


I have a feeling that's my problem. I may have to finally bite the bullet and got to 10.8. Not until after NAMM, though . . .


----------



## kotori (Jan 9, 2014)

In case someone else wonders too the files I posted in this thread are only meant to add syntax highlighting. They are part of my SublimeKSP plugin, but they aren't the plugin.


----------



## d.healey (Jan 11, 2014)

Is the plugin available for download? Does it have any advantages/disadvantages compared to the wonderful KSE?


----------



## mk282 (Jan 11, 2014)

No disadvantages, it's better and faster than KSE. Well, the only disadvantage (maybe) would be lack of function tree in Sublime, but there's a workaround utilizing Ctrl+R and then fuzzy search for what you want.

PM Nils for the whole plugin.


----------



## d.healey (Jan 11, 2014)

I shall, thanks!


----------



## d.healey (Jan 11, 2014)

While I wait for Nils to get back to me I just thought I'd ask about a couple of things. 

Does the plugin support: code import, task functions, macros, properties, and all the other things I've grown to love?


----------



## mk282 (Jan 11, 2014)

Yes, it contains everything KSE had since it's based on the compiler Nils wrote for it. This is just a change of "shell", so to speak. Some more benefits: compiling when you have save_compiled_code pragma active doesn't fill your clipboard anymore, you can restart a compile during compiling (say you made a typo and pressed compile, this lets you fix the typo fast and rerun the compiling process), and I bet there was some more things Nils added but I can't remember right now. :D


----------



## d.healey (Jan 11, 2014)

Ooo I'm excited now!


----------



## Mike Greene (Jan 14, 2014)

polypx @ Thu Jan 09 said:


> I'm also using Sublime Text with Nils' KSP plugin now, and it's absolutely awesome. (Just throwing another vote up here to convince Mike to switch.)
> 
> I also dual boot, Mike, I have one drive with 10.6.8 on it, but most of the time use 10.8 now.


I finally took the plunge this morning and made a shiny new 10.8 system drive with Sublime Text3. Why the heck didn't I do this a long time ago??? You are so right, Dan - this is absolutely awesome!

I've seriously been giddy most of the day. Scrolling as fast as I want without crashing is such a treat. (That was by far my biggest wish. Even knowing I had to take it slow, I'd still crash several times a day.)

Along with that goes the ability to copy and paste large sections. So nice not having to do that in little pieces at a time.

The ability to collapse sections to make the script appear more manageable is also ultra cool. And that scoll bar with the representation of the script as I scroll . . . nice!

Definitely worth another visit to the Donate button. Thanks Nils! 8)


----------



## dxmachina (Jan 14, 2014)

+1 here. Switched to Nils' Sublime Text implementation about a month ago and haven't opened KSE since. _Seriously_ great.

I do occasionally miss the function/callback/macro browser pane on larger scripts - but the goto-symbol (cmd-R) works most of the time. A persistent function list is an often requested feature for ST2/3 if you Google around. I looked a bit into it, but I'm not sure the current plugin architecture would allow for this... but maybe in the future.

I customized a bunch of the snippets to better suit my style. It's incredibly easy to do and really worth it if you find any of the auto-completion ever getting in your way (or you want to add some code blocks that you end up using a lot).

NI built a pretty great engine... but it was Nils who made it a pleasure to script for.

o-[][]-o 

Sebastian


----------



## djdarko (Feb 26, 2014)

Really looking forward to trying Nil's Sublime Text 3 Plugin, but it looks like he hasn't been online since a few hours before I sent him the PM over 7 days ago.


----------



## joris de man (Mar 16, 2014)

Any movement on this? Would love to try it out.....(the sublime text 3 plug-in that is


----------



## djdarko (Mar 19, 2014)

Yeah, me to. It's been 30 days now since I sent the request to Nils.

Has anyone heard from him lately? I wonder whats going on.


----------



## d.healey (Mar 20, 2014)

Hello guys,

I've just spoken with Nils and he's happy for me to share the Sublime 3 plugin with you. I've put it in my dropbox.

Here's the link: https://www.dropbox.com/s/b84i4f3x7qbjs ... imeKSP.zip

I'll keep this link active until Nils asks me to do otherwise - or until he puts it up on his site - http://nilsliberg.se/ksp/ (check out his site!).


----------



## TGV (Mar 20, 2014)

I might want to try it out one day too. I've written two simple scripts, but I'm contemplating another one. Thanks (to you and Nils) for sharing.


----------



## mk282 (Mar 20, 2014)

Perhaps a new thread for that link might be useful, TC?


----------



## joris de man (Mar 20, 2014)

Awesome! Thank you Nils and TC....


----------



## d.healey (Mar 20, 2014)

Good idea, I'll do it!


----------



## djdarko (Mar 21, 2014)

TotalComposure @ Thu Mar 20 said:


> Hello guys,
> 
> I've just spoken with Nils and he's happy for me to share the Sublime 3 plugin with you. I've put it in my dropbox...



Thank you so much for caring enough to contact Nil's to help us out.

I truly appreciate it.


----------



## modularsamples (Jul 28, 2021)

Hey, sorry to revive this ancient thread, but does the textmate bundle still exist in any usable form? I'd really like to check it out, I'm sure Sublime is great but I'm really quite happy with TM and not super interested in learning another app right now.

Thanks!


----------



## snattack (Sep 14, 2021)

I'd like to know that too, I'm currently using LUA in textmate, but it misses most things.


----------

