'Close file (index=None -> close current file)
Keep current file index unchanged (if current file
that is being closed)'

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

    current_index = self.get_stack_index()
    count = self.get_stack_count()
    if (index is None):
        if (count > 0):
            index = current_index
        else:
            self.find_widget.set_editor(None)
            return
    new_index = None
    if (count > 1):
        if (current_index == index):
            new_index = self._get_previous_file_index()
        else:
            new_index = current_index
    is_ok = (force or self.save_if_changed(cancelable=True, index=index))
    if is_ok:
        finfo = self.data[index]
        self.threadmanager.close_threads(finfo)
        if (self.outlineexplorer is not None):
            self.outlineexplorer.remove_editor(finfo.editor)
        self.remove_from_data(index)
        self.sig_close_file.emit(str(id(self)), index)
        if ((not self.data) and self.is_closable):
            self.close()
        self.opened_files_list_changed.emit()
        self.update_code_analysis_actions.emit()
        self._refresh_outlineexplorer()
        self.refresh_file_dependent_actions.emit()
        self.update_plugin_title.emit()
        editor = self.get_current_editor()
        if editor:
            editor.setFocus()
        if (new_index is not None):
            if (index < new_index):
                new_index -= 1
            self.set_stack_index(new_index)
        self.add_last_closed_file(finfo.filename)
    if ((self.get_stack_count() == 0) and self.create_new_file_if_empty):
        self.sig_new_file[()].emit()
        return False
    self.__modify_stack_title()
    return is_ok
