function handleFileSave(commandData) {
        var activeEditor = EditorManager.getActiveEditor(),
            activeDoc = activeEditor && activeEditor.document,
            doc = (commandData && commandData.doc) || activeDoc,
            settings;

        if (doc && !doc.isSaving) {
            if (doc.isUntitled()) {
                if (doc === activeDoc) {
                    settings = {
                        selections: activeEditor.getSelections(),
                        scrollPos: activeEditor.getScrollPos()
                    };
                }

                return _doSaveAs(doc, settings);
            } else {
                return doSave(doc);
            }
        }

        return $.Deferred().reject().promise();
    }
Saves the given file. If no file specified, assumes the current document.
@param {?{doc: ?Document}} commandData  Document to close, or null
@return {$.Promise} resolved with the saved document's File (which MAY DIFFER from the doc
  passed in, if the doc was untitled). Rejected in case of IO error (after error dialog
  dismissed), or if doc was untitled and the Save dialog was canceled (will be rejected with
  USER_CANCELED object).