             @state.history.length = 0
             window.localStorage.rethinkdb_history = JSON.stringify @state.history
 
+        # Save the current query (the one in codemirror) in local storage
+        save_current_query: =>
+            if window.localStorage?
+                window.localStorage.current_query = JSON.stringify @codemirror.getValue()
+
         initialize: (args) =>
             @TermBaseConstructor = r.expr(1).constructor.__super__.constructor.__super__.constructor
 


            # Save the last query (even incomplete)
            @state.current_query = @codemirror.getValue()

            # Look for special commands
            if event?.which?

            # Load options from local storage
            if window.localStorage?.options?
                @state.options = JSON.parse window.localStorage.options

            # Load the query that was written in code mirror (that may not have been executed before)
            if typeof window.localStorage?.current_query is 'string'
                @state.current_query = JSON.parse window.localStorage.current_query

            if window.localStorage?.rethinkdb_history?
                @state.history = JSON.parse window.localStorage.rethinkdb_history
