Python源码示例:neovim.command()

示例1
def place_sign(self, buffname, lineno):
        """place_sign
        Places a new sign on the buffer and registers it as a breakpoint with
        pudb
        :param buffname:
        :param lineno:
        """
        # do nothing without a line number
        if not lineno:
            return None
        # don't place it if it has already been placed
        if self.has_breakpoint(buffname, lineno):
            return self.pudbbp(buffname, lineno)
        signcmd = "sign place {} line={} name={} file={}".format(
            signid(buffname, lineno),
            lineno,
            self.sgnname(),
            buffname)
        __logger__.debug(signcmd)
        self.nvim.command(signcmd)
        if buffname in self._bps_placed:
            self._bps_placed[buffname].append(signid(buffname, lineno))
        else:
            self._bps_placed[buffname] = [signid(buffname, lineno)]
        return self.pudbbp(buffname, lineno) 
示例2
def remove_sign(self, buffname, lineno):
        """remove_sign
        removes the sign from the buffer and the breakpoint from pudb
        :param buffname:
        :param bpt:
        """
        if not self.has_breakpoint(buffname, lineno):
            return
        __logger__.info(
            'removing sign %d at line: %d',
            signid(buffname, lineno),
            lineno)
        vimmsg = 'sign unplace {} file={}'.format(
            signid(buffname, lineno),
            buffname)
        __logger__.debug(vimmsg)
        self.nvim.command(vimmsg)
        self._bps_placed[buffname].pop(
            self._bps_placed[buffname].index(
                signid(buffname, lineno))) 
示例3
def AerojumpUp(self, args, range):
        """ Go up one line of matches

        Parameters:
            n/a

        Returns:
            n/a
        """
        self.aj.cursor_line_up()
        # TODO: [Performance] Incremental update of highlights?
        self.__update_highlights(self.aj.get_highlights())
        self.main_win.cursor = self.aj.get_cursor()

        self.nvim.command('startinsert')
        self.nvim.command('normal! $') 
示例4
def AerojumpDown(self, args, range):
        """ Go down one line of matches

        Parameters:
            n/a

        Returns:
            n/a
        """
        self.aj.cursor_line_down()
        # TODO: [Performance] Incremental update of highlights?
        self.__update_highlights(self.aj.get_highlights())
        self.main_win.cursor = self.aj.get_cursor()

        self.nvim.command('startinsert')
        self.nvim.command('normal! $') 
示例5
def AerojumpSelNext(self, args, range):
        """ Select the next match

        Parameters:
            n/a

        Returns:
            n/a
        """
        self.aj.cursor_match_next()
        # TODO: [Performance] Incremental update of highlights?
        self.__update_highlights(self.aj.get_highlights())
        self.main_win.cursor = self.aj.get_cursor()

        self.nvim.command('startinsert')
        self.nvim.command('normal! $') 
示例6
def AerojumpSelPrev(self, args, range):
        """ Select the previous match

        Parameters:
            n/a

        Returns:
            n/a
        """
        self.aj.cursor_match_prev()
        # TODO: [Performance] Incremental update of highlights?
        self.__update_highlights(self.aj.get_highlights())
        self.main_win.cursor = self.aj.get_cursor()

        self.nvim.command('startinsert')
        self.nvim.command('normal! $') 
示例7
def AerojumpExit(self, args, range):
        """ Exit aerojump without moving the selection

        Parameters:
            n/a

        Returns:
            n/a
        """
        self.nvim.command('stopinsert')
        self.nvim.current.buffer = self.og_buf
        self.nvim.command('bwipeout %s' % self.aerojump_buf_num)
        self.nvim.command('bwipeout %s' % self.filt_buf_num)
        if self.uses_tabs:
            self.nvim.command('tabclose')
        # Restore original position
        self.nvim.current.window.cursor = self.top_pos
        self.nvim.command('normal! zt')
        self.nvim.current.window.cursor = self.og_pos 
示例8
def session(self, args):
        if not plugin.is_active:
            self._vim.async_call(
                lambda: self._vim.command('echom "No instance running."'),
            )
            return
        self._vim.async_call(
            lambda: self._vim.command('echom "Session ID: {}"'
                                      .format(self._session_id)),
        ) 
示例9
def _handle_message(self, message):
        if isinstance(message, m.WriteRequest):
            self._message = message
            self._text_applied.clear()
            self._vim.async_call(
                lambda: self._vim.funcs.TandemHandleWriteRequest(async=True),
            )
            self._text_applied.wait()
        elif isinstance(message, m.SessionInfo):
            self._session_id = message.session_id
            self._vim.async_call(
                lambda: self._vim.command('echom "Session ID: {}"'
                                          .format(message.session_id)),
            ) 
示例10
def open_temp_matlab_script(self, args):
        dirname = os.path.join(os.path.expanduser('~'), '.vim-matlab/scratch/')
        if not os.path.exists(dirname):
            try:
                os.makedirs(dirname)
            except OSError as ex:
                # In case of a race condition
                if ex.errno != errno.EEXIST:
                    raise
        timestamp = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
        if len(args) > 0:
            filename = "{}_{}.m".format(timestamp, args[0])
        else:
            filename = "{}.m".format(timestamp)
        self.vim.command('edit {}'.format(os.path.join(dirname, filename))) 
示例11
def fix_name(self, args):
        curr_file = vim_helper.get_current_file_path()
        modified = os.path.getmtime(curr_file)
        changed = os.path.getctime(curr_file)
        head_lines = self.vim.current.buffer[:100]
        head_string = '\n'.join(head_lines)

        def get_basename_ext(path):
            filename = os.path.basename(path)
            return os.path.splitext(filename)

        def rename_function(name):
            new_head = self.function_name_pattern.sub(
                r"\1{}\3".format(name), head_string).split('\n')
            for i, line in enumerate(new_head):
                if line != head_lines[i]:
                    self.vim.current.buffer[i] = line

        basename, ext = get_basename_ext(curr_file)

        if len(args) > 0:
            new_name, new_ext = get_basename_ext(args[0])
            new_ext = new_ext if len(new_ext) > 0 else ext
            rename_function(new_name)
            self.vim.command("Rename {}{}".format(new_name, new_ext))
            return

        if vim_helper.is_current_buffer_modified() or changed != modified:
            match = self.function_name_pattern.search(head_string)
            if match is None:
                return
            function_name = match.group(2)
            self.vim.command("Rename {}{}".format(function_name, ext))
        else:
            rename_function(basename) 
示例12
def set_sgnname(self, sgnname):
        self.nvim.command("let g:pudb_sign_name='{}'".format(sgnname))

    # @property 
示例13
def set_bpsymbol(self, bpsymbol):
        self.nvim.command("let g:pudb_breakpoint_symbol='{}'".format(bpsymbol))

    # @property 
示例14
def set_lgroup(self, hlgroup):
        self.nvim.command("let g:pudb_highlight_group='{}'".format(hlgroup))

    # @property 
示例15
def set_launcher(self, launcher):
        self.nvim.command("let g:pudb_python_launcher='{}'".format(launcher))

    # @property 
示例16
def set_entrypoint(self, entrypoint):
        self.nvim.command("let g:pudb_entry_point='{}'".format(entrypoint))

    # @property 
示例17
def clear_all_bps(self, buffname=None):
        """clear_all_bps
        removes all signs from the buffer and all breakpoints from pudb
        :param buffname:
        """
        if not buffname:
            buffname = self.cbname()
        self.nvim.command('sign unplace * file={}'.format(buffname))
        self._bps_placed[buffname] = []
        __logger__.debug(
            'there should be no signs for this buffer:\n    %s',
            pprint.pformat(self._bps_placed[buffname]))
        self.update_pudb_breakpoints(buffname) 
示例18
def launchdebugtab(self):
        # if necessary, get the virtual env setup
        # autocmd FileType python nnoremap <silent> <leader>td :tabnew
        # term://source ${HOME}/.virtualenvs/$(cat .dbve)/bin/activate
        # && python -mpudb %<CR>:startinsert<CR>
        new_term_tab_cmd = 'tabnew term://{} -m pudb.run {}'.format(
            self.launcher(),
            self.entrypoint())
        __logger__.info('Starting debug tab with command:\n    {}'.format(
            new_term_tab_cmd))
        self.nvim.command(new_term_tab_cmd)
        # we have to wait for the terminal to be opened...
        self.nvim.command('startinsert') 
示例19
def update_breakpoints_cmd(self, buffname=None):
        '''update_breakpoints_cmd
        expose the UpdateBreakPoints command
        :param buffname:
        '''
        if not buffname:
            buffname = self.cbname()
        __logger__.debug('refreshing breakpoints for file: %s', (buffname))
        # remove existing signs if any
        self.update_buffer(buffname)

    # set sync so that the current buffer can't change until we are done 
示例20
def au_buf_enter(self, *args, **kwargs):
        # Workaround for issue #388
        # TODO: remove it once the Neovim fix has landed in a stable release
        # (Github issue to do that: #390)
        self._vim.command('call EnTick()')
        super(NeovimEnsime, self).au_buf_enter(*args, **kwargs) 
示例21
def get_output_of_vim_cmd(nvim, cmd):
    """ Utility function to get the current output
        of a vim command

    Parameters:
        nvim: Neovim instance
        cmd: Command to fetch output from

    Returns:
        n/a
    """
    nvim.command('redir @a')
    nvim.command(cmd)
    nvim.command('redir END')
    return nvim.eval('@a').strip('\n') 
示例22
def __open_aerojump_buf(self):
        self.nvim.command('silent split Aerojump')
        self.nvim.command('silent setlocal buftype=nofile')
        self.nvim.command('silent setlocal filetype=aerojump')
        # Fix filetype in order to keep old syntax
        self.nvim.command('silent set filetype='+self.ft+'.aerojump')
        self.aerojump_buf_num = self.nvim.current.buffer.number 
示例23
def __open_aerojump_filter_buf(self, filter_string=''):
        if self.uses_tabs:
            self.nvim.command('tabedit AerojumpFilter')
        else:
            self.nvim.command('edit AerojumpFilter')
        self.nvim.command('setlocal buftype=nofile')
        self.nvim.command('setlocal filetype=AerojumpFilter')
        if filter_string != '':
            # TODO Idea: Maybe add some special characters
            # like regexp to enforce whole matches only?
            self.nvim.current.buffer[0] = filter_string
        self.filt_buf_num = self.nvim.current.buffer.number 
示例24
def __set_top_pos(self, top_pos):
        old_win = self.nvim.current.window
        self.nvim.current.window = self.main_win
        self.nvim.current.window.cursor = top_pos
        self.nvim.command('normal! zt')
        self.nvim.current.window = old_win 
示例25
def __create_keymap(self):
        keymaps = self.default_keymaps.copy()
        keymaps.update(self.nvim.vars.get("aerojump_keymaps", {}))
        for k in keymaps:
            self.nvim.command(f"inoremap <buffer> {k} <ESC>:{keymaps[k]}<CR>") 
示例26
def AerojumpShowLog(self, args, range):
        """ Show the aerojump log

        Parameters:
            n/a

        Returns:
            n/a
        """
        self.nvim.command('e Aerojump_log')
        self.nvim.command('setlocal buftype=nofile')
        self.nvim.command('setlocal filetype=aerojump_log')
        self.nvim.current.buffer.append(self.logstr)
        self.nvim.current.buffer.append('== Aerojump log ==')
        self.nvim.current.buffer.extend(self.aj.get_log())