     #   Command Handlers   #
     ########################
 
-    goalsAction: (indices) ->
+    goalsAction: (indices) -> @protectCursor =>
         unless @changed indices
             log 'Text Buffer', "setting goals #{indices}"
             @removeGoals()

        if positions.length isnt 0
            @core.editor.setCursorBufferPosition previousGoal

    give: -> @getCurrentGoal().then (goal) =>
        @warnCurrentGoalIfEmpty goal, 'Please type in the expression to give'
        @core.executable.give goal

    goalType: -> @getCurrentGoal().then (goal) =>
        @core.executable.goalType goal

    context: -> @getCurrentGoal().then (goal) =>
        @core.executable.context goal

    goalTypeAndContext: -> @getCurrentGoal().then (goal) =>
        @core.executable.goalTypeAndContext goal

    goalTypeAndInferredType: -> @getCurrentGoal().then (goal) =>
        @warnCurrentGoalIfEmpty goal, 'Please type in the expression to infer'
        @core.executable.goalTypeAndInferredType goal

    refine: -> @getCurrentGoal().then (goal) =>
        @warnCurrentGoalIfEmpty goal, 'Please type in the expression to refine'
        @core.executable.refine goal

    case: -> @getCurrentGoal().then (goal) =>
        @warnCurrentGoalIfEmpty goal, 'Please type in the expression to make case'
        @core.executable.case goal

    auto: -> @getCurrentGoal().then (goal) =>
        @core.executable.auto goal



            if goals.length is 1
                resolve goals[0]
            else
                reject()

    getCurrentGoalOrWarn: (cursor = @core.editor.getCursorBufferPosition()) ->
        @getCurrentGoal cursor
            .fail =>
                warn 'Text Buffer', 'out of goal'
                @core.panel.outputInfo 'For this command, please place the cursor in a goal'

    warnCurrentGoalIfEmpty: (goal, warning) =>
        content = goal.getContent()
