def launch_editor(cfg, all_tasks=False, calendar=None):
    tmpfile = tempfile.NamedTemporaryFile(dir=cfg['tmppath'], delete=False)

    try:
        with tmpfile as f:
            tasks = model.walk_calendars(cfg['path'])

            def task_filter():
                for task in tasks:
                    if calendar is not None and task.calendar != calendar:
                        continue
                    if not all_tasks and task.done:
                        continue
                    yield task

            header = u'// Showing {status} tasks from {calendar}'.format(
                status=(u'all' if all_tasks else u'pending'),
                calendar=(u'all calendars' if calendar is None else u'@{}'
                          .format(calendar))
            )
            old_ids = editor.generate_tmpfile(f, task_filter(), header)

        new_ids = None
        while new_ids is None:
            cmd = cfg['editor'] + ' ' + tmpfile.name
            print('>>> {}'.format(cmd))
            subprocess.call(cmd, shell=True)

            with open(tmpfile.name, 'rb') as f:
                try:
                    new_ids = editor.parse_tmpfile(f)

                    changes = editor.get_changes(old_ids, new_ids)

                    if cfg['confirmation']:
                        changes = confirm_changes(changes)
                    make_changes(changes, cfg)

                except (__HOLE__, CliError) as e:
                    print(e)
                    click.confirm('Do you want to edit again? '
                                  'Otherwise changes will be discarded.',
                                  default=True, abort=True)
                else:
                    break
    finally:
        os.remove(tmpfile.name)
dataset/ETHPy150Open untitaker/watdo/watdo/cli.py/launch_editor