def save_backup(self, view, on_load_event):

        # don't save files above configured size
        if view.size() > settings.get("max_backup_file_size_bytes"):
            print 'Backup not saved, file too large (%d bytes)' % view.size()
            return

        filename = view.file_name()
        newname = backup_paths.get_backup_filepath(filename)
        if newname == None:
            return

        # not create file backup if current file is backup
        if (on_load_event & self.is_backup_file(filename)):
            return

        # not create file if exists
        if (on_load_event & os.path.isfile(newname)):
            return

        (backup_dir, file_to_write) = os.path.split(newname)


        # not create file backup on open event if current file is backup
        if os.access(backup_dir, os.F_OK) == False:
            os.makedirs(backup_dir)

        shutil.copy(filename, newname)
        print 'Backup saved to:', newname
    def run(self, edit):
        window = sublime.active_window()
        view = sublime.Window.active_view(window)
        filepath = view.file_name()
        newname = backup_paths.get_backup_filepath(filepath)

        if (os.path.isfile(newname)):
            window.open_file(newname)
        else:
            sublime.error_message('Backup for ' + filepath + ' not exists!')
    def on_post_save(self, view):
        """When a file is saved, put a copy of the file into the
        backup directory."""

        # don't save files above configured size
        if view.size() > settings.get("max_backup_file_size_bytes"):
            print 'Backup not saved, file too large (%d bytes)' % view.size()
            return

        filename = view.file_name()
        newname = backup_paths.get_backup_filepath(filename)
        if newname == None:
            return

        (backup_dir, file_to_write) = os.path.split(newname)

        # make sure that we have a directory to write into
        if os.access(backup_dir, os.F_OK) == False:
            os.makedirs(backup_dir)

        shutil.copy(filename, newname)
        print 'Backup saved to:', newname

        nav.reinit()