     Gemfile: 'ruby'
     Rakefile: 'ruby'
 
-  setModeForSession: (session) ->
-    return if not @url
+  modeForURL: (url) ->
+    return if not url
 
-    if not modeName = @modeFileMap[ _.last @url.split '/' ]
-      language = _.last @url.split '.'
+    if not modeName = @modeFileMap[ _.last url.split '/' ]
+      language = _.last url.split '.'
       language = language.toLowerCase()
       modeName = @modeMap[language] or language
 
     try
-      mode = require("ace/mode/#{modeName}").Mode
-      session.setMode new mode
+      require("ace/mode/#{modeName}").Mode
     catch e
       console.error e
+
+  setModeForURL: (url) ->
+    @ace.session.setMode new (@modeForURL url)
 
   title: ->
     if @url then _.last @url.split '/' else 'untitled'


  setCode: (code) ->
    @ace.getSession().setValue code
    
  removeTrailingWhitespace: ->
    return
    @ace.replaceAll "",

    session.setTabSize if useSoftTabs then @guessTabSize code else 8
    session.setUndoManager new UndoManager
    session.on 'change', => @dirty = true
    @ace.setSession session
    @setModeForURL @url if @url

    window.setTitle @title()
    @dirty = false
