What's new

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

sonaht

New Member
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.

Shortcut_Example.png


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, 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.

Textmate_Theme_ScreenCap1.png


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. :)

Dark_Theme.png


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

Senior Member
Moderator
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

Member
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!
 
OP
sonaht

sonaht

New Member
Thread starter
  • Thread Starter
  • Thread Starter
  • #4
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
 
OP
sonaht

sonaht

New Member
Thread starter
  • Thread Starter
  • Thread Starter
  • #6
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

Member
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.
 
OP
sonaht

sonaht

New Member
Thread starter
  • Thread Starter
  • Thread Starter
  • #8
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
 
OP
sonaht

sonaht

New Member
Thread starter
  • Thread Starter
  • Thread Starter
  • #9
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

Senior Member
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
 

Attachments

  • ksp_tmTheme_and_tmLanguage.zip
    8.4 KB · Views: 39

jpernell

New Member
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

Active Member
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

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

sonaht

New Member
Thread starter
  • Thread Starter
  • Thread Starter
  • #15
Hello,

The links of the original post work again.
 

Mike Greene

Senior Member
Moderator
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"
 
OP
sonaht

sonaht

New Member
Thread starter
  • Thread Starter
  • Thread Starter
  • #18
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

Senior Member
Moderator
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

Hoser
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
 
Top Bottom