def save(self, path=None, encoding=None, fallback_encoding=None):
        """
        Save the editor content to a file.

        :param path: optional file path. Set it to None to save using the
                     current path (save), set a new path to save as.
        :param encoding: optional encoding, will use the current
                         file encoding if None.
        :param fallback_encoding: Fallback encoding to use in case of encoding
            error. None to use the locale preferred encoding

        """
        if not self.editor.dirty and \
                (encoding is None and encoding == self.encoding) and \
                (path is None and path == self.path):
            # avoid saving if editor not dirty or if encoding or path did not
            # change
            return
        if fallback_encoding is None:
            fallback_encoding = locale.getpreferredencoding()
        _logger().log(
            5, "saving %r with %r encoding", path, encoding)
        if path is None:
            if self.path:
                path = self.path
            else:
                _logger().debug(
                    'failed to save file, path argument cannot be None if '
                    'FileManager.path is also None')
                return False
        # use cached encoding if None were specified
        if encoding is None:
            encoding = self._encoding
        self.saving = True
        self.editor.text_saving.emit(str(path))

        # get file persmission on linux
        try:
            st_mode = os.stat(path).st_mode
        except (ImportError, TypeError, AttributeError, OSError):
            st_mode = None

        # perform a safe save: we first save to a temporary file, if the save
        # succeeded we just rename the temporary file to the final file name
        # and remove it.
        if self.safe_save:
            tmp_path = path + '~'
        else:
            tmp_path = path
        try:
            with open(tmp_path, 'wb') as file:
                file.write(self._get_text(encoding))
        except UnicodeEncodeError:
            # fallback to utf-8 in case of error.
            with open(tmp_path, 'wb') as file:
                file.write(self._get_text(fallback_encoding))
        except (IOError, OSError) as e:
            self._rm(tmp_path)
            self.saving = False
            self.editor.text_saved.emit(str(path))
            raise e
        # cache update encoding
        Cache().set_file_encoding(path, encoding)
        self._encoding = encoding
        # remove path and rename temp file, if safe save is on
        if self.safe_save:
            self._rm(path)
            os.rename(tmp_path, path)
            self._rm(tmp_path)
        # reset dirty flags
        self.editor.document().setModified(False)
        # remember path for next save
        self._path = os.path.normpath(path)
        self.editor.text_saved.emit(str(path))
        self.saving = False
        _logger().debug('file saved: %s', path)
        self._check_for_readonly()

        # restore file permission
        if st_mode:
            try:
                os.chmod(path, st_mode)
            except (ImportError, TypeError, AttributeError):
                pass
Save the editor content to a file.

        :param path: optional file path. Set it to None to save using the
                     current path (save), set a new path to save as.
        :param encoding: optional encoding, will use the current
                         file encoding if None.
        :param fallback_encoding: Fallback encoding to use in case of encoding
            error. None to use the locale preferred encoding