from_absolute_cursor_pos = function (cm, cursor_pos) {
        /**
         * turn absolute cursor postion into CodeMirror col, ch cursor
         */
        var i, line;
        var offset = 0;
        for (i = 0, line = cm.getLine(i); line !== undefined; i++, line = cm.getLine(i)) {
            if (offset + line.length < cursor_pos) {
                offset += line.length + 1;
            } else {
                return {
                    line: i,
                    ch: cursor_pos - offset,
                };
            }
        }
        // reached end, return endpoint
        return {
            ch: line.length - 1,
            line: i - 1,
        };
    }
get the absolute cursor position from CodeMirror's col, ch