'Save file'

def save(self, index=None, force=False):

    if (index is None):
        if (not self.get_stack_count()):
            return
        index = self.get_stack_index()
    finfo = self.data[index]
    if ((not (finfo.editor.document().isModified() or finfo.newly_created)) and (not force)):
        return True
    if ((not osp.isfile(finfo.filename)) and (not force)):
        return self.save_as(index=index)
    if self.always_remove_trailing_spaces:
        self.remove_trailing_spaces(index)
    txt = to_text_string(finfo.editor.get_text_with_eol())
    try:
        finfo.encoding = encoding.write(txt, finfo.filename, finfo.encoding)
        finfo.newly_created = False
        self.encoding_changed.emit(finfo.encoding)
        finfo.lastmodified = QFileInfo(finfo.filename).lastModified()
        self.file_saved.emit(str(id(self)), index, finfo.filename)
        finfo.editor.document().setModified(False)
        self.modification_changed(index=index)
        self.analyze_script(index)
        self.introspector.validate()
        finfo.editor.rehighlight()
        self._refresh_outlineexplorer(index)
        return True
    except EnvironmentError as error:
        self.msgbox = QMessageBox(QMessageBox.Critical, _('Save'), (_("<b>Unable    to    save    file    '%s'</b><br><br>Error    message:<br>%s") % (osp.basename(finfo.filename), str(error))), self)
        self.msgbox.exec_()
        return False
