     save: =>
         text = @$pad.val()
         # replace tabs by spaces
-        space = (" " for _ in [0...@tabwidth]).join("")
+        space = (" " for _ in [0...@tab_width]).join("")
         text = text.replace(/\t/g, space)
         # strip trailing white space onlines
         text = text.replace(/[ \r]*\n/g,"\n").replace(/\s*$/g, "\n")


    autocomplete: =>
        [text, [start, end], s] = @get_text_state()
        string = text.substr(0, start)
        at = text[start]
        string = string.match(/\w+$/)
        print "ac", at, string
        if (not at or at.match("\s")) and string
            options = {}
            words = text.split(/\W+/).sort()
            if words

        @set_text(text)

        if just_tab
            @$pad[0].selectionStart = real + @tab_width
            @$pad[0].selectionEnd = @$pad[0].selectionStart
        else
            @$pad[0].selectionStart = @lines[start][1]
            @$pad[0].selectionEnd = @lines[end][2] + @tab_width * (end-start+1)

    deindent: =>
        [start, end] = @selected_line_range()
        if start == end
           real = @$pad[0].selectionStart
           just_tab = true

        lines = (l[3] for l in @lines)
        old_length = 0
        for n in [start..end]
            old_length += lines[n].length + 1
            for t in [0...@tab_width]
                if lines[n][0] == " "
                    lines[n] = lines[n][1..]
        text = (l for l in lines).join("\n")
        @set_text(text)

        new_length = 0
        for n in [start..end]
            new_length += lines[n].length + 1

        print "o/n", old_length, new_length

        if just_tab
            if real - @tab_width > @lines[start][1]
                @$pad[0].selectionStart = real - @tab_width
            else
                @$pad[0].selectionStart = @lines[start][1]
            @$pad[0].selectionEnd = @$pad[0].selectionStart
        else
            @$pad[0].selectionStart = @lines[start][1]

            @$pad[0].selectionEnd = @$pad[0].selectionStart + new_length



    set_text: (text) ->
        @$pad.val(text)
