Beispiel #1
0
def _drop(view: View, defx: Defx, context: Context) -> None:
    """
    Open like :drop.
    """
    command = context.args[0] if context.args else 'edit'

    for target in context.targets:
        path = target['action__path']

        if path.is_dir():
            view.cd(defx, defx._source.name, str(path), context.cursor)
            continue

        bufnr = view._vim.call('bufnr', f'^{path}$')
        winids = view._vim.call('win_findbuf', bufnr)

        if winids:
            view._vim.call('win_gotoid', winids[0])
        else:
            if context.prev_winid != view._winid and view._vim.call(
                    'win_id2win', context.prev_winid):
                view._vim.call('win_gotoid', context.prev_winid)
            else:
                view._vim.command('wincmd w')
            view._vim.call('defx#util#execute_path', command, str(path))

        view.restore_previous_buffer()
Beispiel #2
0
def _open(view: View, defx: Defx, context: Context) -> None:
    """
    Open the file.
    """
    cwd = view._vim.call('getcwd', -1)
    command = context.args[0] if context.args else 'edit'
    previewed_buffers = view._vim.vars['defx#_previewed_buffers']
    for target in context.targets:
        path = target['action__path']

        if path.is_dir():
            view.cd(defx, defx._source.name, str(path), context.cursor)
            continue

        if not view._vim.call('haslocaldir'):
            try:
                path = path.relative_to(cwd)
            except ValueError:
                pass

        view._vim.call('defx#util#execute_path', command, str(path))

        bufnr = str(view._vim.call('bufnr', str(path)))
        if bufnr in previewed_buffers:
            previewed_buffers.pop(bufnr)
            view._vim.vars['defx#_previewed_buffers'] = previewed_buffers

        view.restore_previous_buffer()
    view.close_preview()
Beispiel #3
0
    def _drop(self, view: View, defx: Defx, context: Context) -> None:
        """
        Open like :drop.
        """
        cwd = view._vim.call('getcwd', -1)
        command = context.args[0] if context.args else 'edit'

        for target in context.targets:
            path = target['action__path']

            if path.is_dir():
                view.cd(defx, defx._source.name, str(path), context.cursor)
                continue

            # bufnr check
            winids = []
            try:
                bufnr = view._vim.call('bufnr', f'^{path}$')
                winids = view._vim.call('win_findbuf', bufnr)
            except NvimError:
                pass

            if winids:
                view._vim.call('win_gotoid', winids[0])
            else:
                # Jump to the last accessed window
                view._vim.command('wincmd p')

                if view._vim.call('win_getid') == view._winid:
                    view._vim.command('wincmd w')

                if (not view._vim.call('haslocaldir')
                        and not bool(view._vim.options['autochdir'])):
                    # Note: autochdir is dangerous option
                    try:
                        path = path.relative_to(cwd)
                    except ValueError:
                        pass

                view._vim.call('defx#util#execute_path', command,
                               self.get_buffer_name(str(path)))

            view.restore_previous_buffer(view._prev_bufnr)
        view.close_preview()
Beispiel #4
0
def _open(view: View, defx: Defx, context: Context) -> None:
    """
    Open the file.
    """
    cwd = view._vim.call('getcwd')
    command = context.args[0] if context.args else 'edit'
    for target in context.targets:
        path = target['action__path']

        if path.is_dir():
            view.cd(defx, defx._source.name, str(path), context.cursor)
            continue

        try:
            path = path.relative_to(cwd)
        except ValueError:
            pass
        view._vim.call('defx#util#execute_path', command, str(path))

        view.restore_previous_buffer()
Beispiel #5
0
    def _open(self, view: View, defx: Defx, context: Context) -> None:
        """
        Open the file.
        """
        cwd = view._vim.call('getcwd', -1)
        command = context.args[0] if context.args else 'edit'
        choose = command == 'choose' and (
            view._vim.call('exists', 'g:loaded_choosewin')
            or view._vim.call('hasmapto', '<Plug>(choosewin)', 'n'))
        previewed_buffers = view._vim.vars['defx#_previewed_buffers']
        for target in context.targets:
            path = target['action__path']

            if path.is_dir():
                view.cd(defx, defx._source.name, str(path), context.cursor)
                continue

            if (not view._vim.call('haslocaldir')
                    and not bool(view._vim.options['autochdir'])):
                # Note: autochdir is dangerous option
                try:
                    path = path.relative_to(cwd)
                except ValueError:
                    pass

            if choose:
                self.switch(view)

            view._vim.call('defx#util#execute_path',
                           'edit' if choose else command,
                           self.get_buffer_name(str(path)))

            bufnr = str(view._vim.call('bufnr', str(path)))
            if bufnr in previewed_buffers:
                previewed_buffers.pop(bufnr)
                view._vim.vars['defx#_previewed_buffers'] = previewed_buffers

            view.restore_previous_buffer(view._prev_bufnr)
        view.close_preview()
Beispiel #6
0
def _drop(view: View, defx: Defx, context: Context) -> None:
    """
    Open like :drop.
    """
    cwd = view._vim.call('getcwd', -1)
    command = context.args[0] if context.args else 'edit'

    for target in context.targets:
        path = target['action__path']

        if path.is_dir():
            view.cd(defx, defx._source.name, str(path), context.cursor)
            continue

        bufnr = view._vim.call('bufnr', f'^{path}$')
        winids = view._vim.call('win_findbuf', bufnr)

        if winids:
            view._vim.call('win_gotoid', winids[0])
        else:
            if context.prev_winid != view._winid and view._vim.call(
                    'win_id2win', context.prev_winid):
                view._vim.call('win_gotoid', context.prev_winid)
            else:
                view._vim.command('wincmd w')

            if not view._vim.call('haslocaldir'):
                try:
                    path = path.relative_to(cwd)
                except ValueError:
                    pass

            view._vim.call('defx#util#execute_path', command, str(path))

        view.restore_previous_buffer(view._prev_bufnr)
    view.close_preview()