 
     D.wins = wins = # mapping between window ids and widget instances (D.Session or D.Editor)
       0: session = D.Session $('.ui-layout-center'),
-        edit: (s, i) -> socket.emit 'Edit', win: 0, pos: i, text: s
-        autocomplete: (s, i) -> socket.emit 'Autocomplete', line: s, pos: i, token: 0
-        exec: (lines, trace) -> (if !trace then execQueue = lines[1..]); socket.emit 'Execute', {trace, text: lines[0] + '\n'}; return
+        edit: (s, i) -> D.socket.emit 'Edit', win: 0, pos: i, text: s
+        autocomplete: (s, i) -> D.socket.emit 'Autocomplete', line: s, pos: i, token: 0
+        exec: (lines, trace) -> (if !trace then execQueue = lines[1..]); D.socket.emit 'Execute', {trace, text: lines[0] + '\n'}; return
 
     popWindow = (w) ->
       if !opener

          $.alert 'Popups are blocked.'
      return

    socket
      .on '*identify', (i) -> D.remoteIdentification = i; return
      .on 'UpdateDisplayName', ({displayName}) -> $('title').text displayName
      .on 'EchoInput', ({input}) -> session.add input
      .on 'AppendSessionOutput', ({result}) -> session.add result
      .on 'NotAtInputPrompt', -> session.noPrompt()
      .on 'AtInputPrompt', ({why}) ->
        if execQueue.length then socket.emit 'Execute', trace: 0, text: execQueue.shift() + '\n' else session.prompt why
        return
      .on 'HadError', -> execQueue.splice 0, execQueue.length; return
      .on 'FocusWindow', ({win}) -> $("#wintab#{win} a").click(); wins[win].focus(); return

  overlap = (x0, x1, x2, x3) -> x2 < x1 && x0 < x3 # helper: do the segments (x0,x1) and (x2,x3) overlap?

  D.idePage = ->
    $('body').html """
      <div class="ide">
        <div class="lbar ui-layout-north" style="display:none">
