def for_each_cursor(self, function, *args, **kwargs):
        view = self.view
        selection = view.sel()
        regions = list(selection)
        selection.clear()

        # REMIND: for delete-white-space and other commands that change the size of the
        # buffer, you need to keep the cursors in a named set of cursors (like the mark
        # ring) so that they are adjusted properly. Also if the function returns None,
        # grab the cursor from the selection.
        can_modify = kwargs.pop('can_modify', False)

        if can_modify:
            key = "tmp_cursors"
            view.add_regions(key, regions, "tmp", "", sublime.HIDDEN)
            for i in range(len(regions)):
                # Grab the region (whose position has been maintained/adjusted by
                # sublime). Unfortunately we need to assume one region might merge into
                # another at any time, and reload all regions to check.
                regions = view.get_regions(key)
                if i >= len(regions):
                    # we've deleted some cursors along the way - we're done
                    break
                selection.add(regions[i])
                cursor = function(regions[i], *args, **kwargs)
                selection.clear()
            cursors = view.get_regions(key)
            view.erase_regions(key)
        else:
            # run the command passing in each cursor and collecting the returned cursor
            cursors = []
            for i,cursor in enumerate(regions):
                selection.add(cursor)
                cursor = function(cursor, *args, **kwargs)
                selection.clear()
                cursors.append(cursor)

        # add them all back when we're done
        selection.add_all(cursors)
dataset/ETHPy150Open grundprinzip/sublemacspro/jove.py/CmdUtil.for_each_cursor/original