+21

Need ability to open file to specific line from external applications (OSX)

Calvin Rien 6 years ago • updated by Allan Lavell 4 years ago 13
When the Unity3D authoring tool shows warnings or errors about a line of code, you can double click the line in the Unity console to open the specified file in an external text editor.

In TextMate, BBEdit, Smultron, and MonoDevelop the specified file opens with the cursor at the specified line.  This is not the behavior in Sublime Text 2.  It would be very useful to include this behavior in Sublime Text, I'm assuming that the line number is passed as an argument in the open file event.
+2

Already exists. From "subl --help":

"Filenames may be given a :line or :line:column suffix to open at a specific location."
+2
It seems like these other Applications are adhering to a common format that is different from Sublime Text's format.  It would be great to support the common format too.
Yep add me to this too :)


It's the one thing that's keeping me on the fence about Sublime Text. I know a number of Unity3D developers evaluating the editor are also asking about this feature too.

+1
I've written something that does this, its a bit hackish but works great. I'll post back when its ready.
Hey Seb. That's great! Look forward to see what you've come up with.
Here's a blog post from someone who has worked around this on Windows:
http://www.jacobpennock.com/Blog/?p=568

It appears that the issue is that Unity (and some other text editors) uses ';' as the delimiter between filename and line number.  Sublime uses ':' as the delimiter.

Is there a way to handle this with a Python plugin for sublime, or a way to retrieve the full name of the file being opened (along with the ;[linenum] part)?
be nice to have ST2 supporting this natively. But couldn't one write an Applescript app to do the same thing the exe is in that post does? Looking into it myself....

It seems like sublime text 2 isn't paying attention to the 'kpos' parameter of the 'odoc' apple event.   If I do this with BBEdit the apple even sent is the same but the insertion point is place in the correct place:

Oct 22 12:30:33 com.barebones.bbedit[32725]: { 1 } 'aevt':  aevt/rapp (i386){

Oct 22 12:30:33 com.barebones.bbedit[32725]:           return id: 32699 (0x7fbb)

Oct 22 12:30:33 com.barebones.bbedit[32725]:      transaction id: 0 (0x0)

Oct 22 12:30:33 com.barebones.bbedit[32725]:   interaction level: 112 (0x70)

Oct 22 12:30:33 com.barebones.bbedit[32725]:      reply required: 0 (0x0)

Oct 22 12:30:33 com.barebones.bbedit[32725]:              remote: 0 (0x0)

Oct 22 12:30:33 com.barebones.bbedit[32725]:       for recording: 0 (0x0)

Oct 22 12:30:33 com.barebones.bbedit[32725]:          reply port: 10507 (0x290b)

Oct 22 12:30:33 com.barebones.bbedit[32725]:   target:

Oct 22 12:30:33 com.barebones.bbedit[32725]:     { 1 } 'psn ':  8 bytes {

Oct 22 12:30:33 com.barebones.bbedit[32725]:       { 0x0, 0x2f02f0 } (Unity)

Oct 22 12:30:33 com.barebones.bbedit[32725]:     }

Oct 22 12:30:33 com.barebones.bbedit[32725]:   fEventSourcePSN: { 0x0,0x2f02f0 } (Unity)

Oct 22 12:30:33 com.barebones.bbedit[32725]:   optional attributes:

Oct 22 12:30:33 com.barebones.bbedit[32725]:     < empty record >

Oct 22 12:30:33 com.barebones.bbedit[32725]:   event data:

Oct 22 12:30:33 com.barebones.bbedit[32725]:     { 1 } 'aevt':  - 0 items {

Oct 22 12:30:33 com.barebones.bbedit[32725]:     }

Oct 22 12:30:33 com.barebones.bbedit[32725]: }

Oct 22 12:30:33 com.barebones.bbedit[32725]: { 1 } 'aevt':  aevt/odoc (i386){

Oct 22 12:30:33 com.barebones.bbedit[32725]:           return id: 32700 (0x7fbc)

Oct 22 12:30:33 com.barebones.bbedit[32725]:      transaction id: 0 (0x0)

Oct 22 12:30:33 com.barebones.bbedit[32725]:   interaction level: 16 (0x10)

Oct 22 12:30:33 com.barebones.bbedit[32725]:      reply required: 0 (0x0)

Oct 22 12:30:33 com.barebones.bbedit[32725]:              remote: 0 (0x0)

Oct 22 12:30:33 com.barebones.bbedit[32725]:       for recording: 0 (0x0)

Oct 22 12:30:33 com.barebones.bbedit[32725]:          reply port: 10507 (0x290b)

Oct 22 12:30:33 com.barebones.bbedit[32725]:   target:

Oct 22 12:30:33 com.barebones.bbedit[32725]:     { 1 } 'psn ':  8 bytes {

Oct 22 12:30:33 com.barebones.bbedit[32725]:       { 0x0, 0x2f02f0 } (Unity)

Oct 22 12:30:33 com.barebones.bbedit[32725]:     }

Oct 22 12:30:33 com.barebones.bbedit[32725]:   fEventSourcePSN: { 0x0,0x2f02f0 } (Unity)

Oct 22 12:30:33 com.barebones.bbedit[32725]:   optional attributes:

Oct 22 12:30:33 com.barebones.bbedit[32725]:     { 1 } 'reco':  - 1 items {

Oct 22 12:30:33 com.barebones.bbedit[32725]:       key 'shas' - 

Oct 22 12:30:33 com.barebones.bbedit[32725]:         { 1 } 'list':  - 1 elements {

Oct 22 12:30:33 com.barebones.bbedit[32725]:           { 1 } 'TEXT':  218 bytes {

Oct 22 12:30:33 com.barebones.bbedit[32725]:             "7a4094ec7aca52f44c117bac760ca3116372834c;00000000;0000000000000020;com.apple.app-sandbox.read-write;00000001;0e000002;0000000000a9cf30;/users/private/documents/work/projects/tests/terraintest2-unity/assets/terraintest.cs"

Oct 22 12:30:33 com.barebones.bbedit[32725]:           }

Oct 22 12:30:33 com.barebones.bbedit[32725]:         }

Oct 22 12:30:33 com.barebones.bbedit[32725]:     }

Oct 22 12:30:33 com.barebones.bbedit[32725]:   event data:

Oct 22 12:30:33 com.barebones.bbedit[32725]:     { 1 } 'aevt':  - 3 items {

Oct 22 12:30:33 com.barebones.bbedit[32725]:       key '----' - 

Oct 22 12:30:33 com.barebones.bbedit[32725]:         { 1 } 'fsrf':  80 bytes {

Oct 22 12:30:33 com.barebones.bbedit[32725]:                 000: 9cff 0080  0000 0000  30cf a900  9ed7 9000     ........0.......

Oct 22 12:30:33 com.barebones.bbedit[32725]:                 001: 0000 0000  0000 0000  0000 0000  0000 0000     ................

Oct 22 12:30:33 com.barebones.bbedit[32725]:                 002: 0000 0000  0000 0000  0000 0000  0000 0000     ................

Oct 22 12:30:33 com.barebones.bbedit[32725]:                 003: 0000 0000  0000 0000  0000 0000  0000 0000     ................

Oct 22 12:30:33 com.barebones.bbedit[32725]:                 004: 0000 0000  0000 0000  0000 0000  0000 0000     ................

Oct 22 12:30:33 com.barebones.bbedit[32725]:          

Oct 22 12:30:33 com.barebones.bbedit[32725]:         }

Oct 22 12:30:33 com.barebones.bbedit[32725]:       key 'kpos' - 

Oct 22 12:30:33 com.barebones.bbedit[32725]:         { 1 } 'TEXT':  20 bytes {

Oct 22 12:30:33 com.barebones.bbedit[32725]:           "

basically seems like the sublime text 2 programmers aren't paying attention to that last appleevent arguement 'kpos' that Unity is sending out.  Maybe someone knows them and can suggest/request that they add this ASAP!  :)

BTW - this is nothing to do with a BareBones API - this is straight up Apple Events Open Document Apple Event parameter documented here:

http://developer.apple.com/legacy/mac/library/documentation/mac/pdf/Interapplication_Communication/AE_Term_Resources.pdf

search for "keyAEPosition"

Indeed it's straight up Apple Events handling. The reason, apparently that TextMate and MacVim work correctly when Unity3d launches them, is because of their scripting implementation. It doesn't work with SublimeText 2 or 3. So yeah, big bump here!

On the Mac OS X side, I have gotten a start at a Cocoa app to proxy the Apple Event over to Sublime Text. When I get the event, however, the kpos param looks like an empty string:


5/19/13 11:53:37.002 PM Unity[5720]: AE2000 (5720 ): Sending an event:

------oo start of event oo------

aevt('aevt'\'odoc' transactionID=0 sourcePSN=[0x0,6e06e "MonoDevelop-Unity"] timeout=7200 eventSource=3 { '----':fsrf("/Users/tkeating/hg-repos/Kingdoms/Assets/Scripts/maps/TraverseWaypointAI.cs"), 'kpos':TEXT(""), 'FSnd':type('UNED') })

------oo  end of event  oo------

 (AESendMessage()/AEMach.cp #2482) main


I'm sure there's actually some data in the NSAppleEventDescriptor, because (as you can tell if you look carefully at that example) this is actually an event that Unity sent to MonoDevelop, which correctly jumps to the indicated line. However, I can't seem to figure out how to extract it.


If anyone has a wild hair and wants to try and take a crack at figuring out how to get valid data out of the event descriptor, the project is available at https://github.com/MrTact/SublimeProxy.

Hey,


so I forked Tim's project and made it work. Check out the blog post explaining how I did it, along with a link to the Github page, here:


http://twistedoakstudios.com/blog/Post5204_making-sublime-text-2-jump-to-the-correct-line-with-unity-on-os-x