7

I've got a pretty sweet setup for editing and running maxscript from inside sublime text 2.

The one thing I've been wanting recently is to emulate or copy the behaviour of the curly brackets with the normal round brackets

EDIT: Sorry - Chrome decided I was finished editing there when I wasn't :(

If I type if (x) then { then enter I will get a nicely formatted block, with the caret now at the arrow

if(x) then {
    <-
}

but I cant find where sublime text is hiding it.

I want to copy this behaviour to the normal round brackets () instead of getting

if (x) then (
    <-)
finlaybob
  • 697
  • 10
  • 30
  • Have you looked at the Sublime plug-ins [Bracketeer](https://github.com/colinta/SublimeBracketeer) or [CodeFormatter](https://github.com/akalongman/sublimetext-codeformatter) at all? – Ghoul Fool Apr 07 '14 at 11:18
  • How are you running MxS from MaxScript? Is this a project you are posting? I'd be very curious to see how this works out! – FrozenKiwi May 14 '14 at 13:49

1 Answers1

7

I've found where it does this on curly brackets, it's simply in the default key bindings. I copied the section "keys": ["enter"] and replaced the regex with "(" instead of "{".

I also had to copy the built in AddLineInBraces.sublime-macro and add {"command": "left_delete" }, to it:

[
    {"command": "insert", "args": {"characters": "\n\n"} },
    {"command": "left_delete" },
    {"command": "move", "args": {"by": "lines", "forward": false} },
    {"command": "move_to", "args": {"to": "hardeol", "extend": false} },
    {"command": "reindent", "args": {"single_line": true} }
]

And make the enter keystroke call that macro if the regex matches. This gives the perfect result!

I've actually been doing less MXS the last while so haven't really been playing with it much.

Thanks to Ghoul Fool for the suggestions but after having a look I wanted a simpler solution.

In answer to FrozenKiwi, I have mashed together a few plugins from various places so I can send maxscript to Max from ST2. Here is a link for the heavy lifting. It does involve some work to get it running but is very handy indeed.

The rest is all just dribs and drabs of various ST2 goodness: shift+enter to evaluate selection, ctrl+e to evaluate all, lots (and lots) of macros e.g. "for" + tab will write format "var: %\n" (var as string)

I don't know if I can release it as a package as it's taken from quite a few different sources. I could check the licensing for each thing though I suppose.

My only remaining hurdle is not being able to redirect output from the maxscript listener to ST2, I've trawled the internet and nobody seems to have done it yet, and I'm not keen on trying it myself. I don't even know if Maxscript itself can be used - it might have to be a C++ plugin using the SDK - but my experience thus far with C++ plugins is minimal. I don't doubt it can be done though.

finlaybob
  • 697
  • 10
  • 30
  • 5
    Didn't want to edit your post, but just in case anyone else is wondering where to make these changes (as it took me a while to figure out): Copy the command code above and save as `Add Line In Braces.sublime-macro` within your `~/Library/Application Support/Sublime Text 3/Packages` directory and then just change the file reference for the key binding to `res://Packages/User/__` - Sublime knows where to look to find the directory, no need to add a full path. (for ST3, ST2 should have a similar directory structure) – Chris Graham Aug 29 '14 at 10:35
  • 1
    Learnt about `.sublime-macro` from this question, one step closer to perfection. :) – igauravsehrawat Jul 29 '16 at 03:50