function handleChangedFile(path) {
            var session = sessions[path];
            if (!session) {
                return;
            }
            // Don't do the asking for a reload dance when this is the config project,
            // or if the preference to automatically revert is set.
            if ((opts.get("url").indexOf("config:") === 0) || (config.getPreference("globalAutoRevert"))) {
                return reloadFile();
            }
            if (session.$prompting) {
                // Already showing a prompt
                return;
            }
            session.$prompting = true;
            ui.prompt({
                message: "File '" + path + "' changed on disk, reload (Ok) or keep original (Cancel)?"
            }).then(function(yes) {
                session.$prompting = false;
                if (yes) {
                    reloadFile();
                } else {
                    // Create backup of changed file on disk
                    return fs.readFile(path).then(function(text) {
                        return fs.writeFile(path + ".bak", text);
                    }).then(function() {
                        return fs.writeFile(path, session.getValue());
                    }).then(function() {
                        console.log("Did not reload file, saved backup of disk-version in", path + ".bak");
                    }, function(err) {
                        console.error("Could not backup file:", path, err);
                    });
                }
            });

            function reloadFile() {
                return fs.readFile(path).then(function(text) {
                    session.ignoreChange = true;

                    // Save scroll/cursor state
                    var scrollTop = session.getScrollTop();
                    var scrollLeft = session.getScrollLeft();
                    var cursorPos = session.selection.getCursor();

                    var lineCount = session.getLength();
                    var range = new Range(0, 0, lineCount, session.getLine(lineCount - 1).length);

                    session.replace(range, text);

                    // Restore
                    session.selection.clearSelection();
                    session.selection.moveCursorToPosition(cursorPos);
                    session.setScrollTop(scrollTop);
                    session.setScrollLeft(scrollLeft);

                    session.ignoreChange = false;
                }, function(err) {
                    console.error("Could not load file:", path, err);
                    return Promise.reject(err);
                });
            }
        }
Reloads a file when it has been changed on disk (observed by a file watcher)