Example #1
0
    def update(self, anno_id=None, disabled=False):
        """Update the buffer with netbeans."""
        # open file in netbeans
        if not self.registered:
            self.nbsock.send_cmd(self, 'editFile', misc.quote(self.name))
            self.nbsock.send_cmd(self, 'putBufferNumber', misc.quote(self.name))
            self.nbsock.send_cmd(self, 'stopDocumentListen')
            self.registered = True

        # update annotations
        if anno_id:
            self[anno_id].update(disabled)
        else:
            for anno_id in self.keys():
                self[anno_id].update()
Example #2
0
    def update(self, anno_id=None, disabled=False):
        """Update the buffer with netbeans."""
        # open file in netbeans
        if not self.registered:
            self.nbsock.send_cmd(self, 'editFile', misc.quote(self.name))
            self.nbsock.send_cmd(self, 'putBufferNumber',
                                 misc.quote(self.name))
            self.nbsock.send_cmd(self, 'stopDocumentListen')
            self.registered = True

        # update annotations
        if anno_id:
            self[anno_id].update(disabled)
        else:
            for anno_id in self.keys():
                self[anno_id].update()
Example #3
0
    def evt_fileOpened(self, buf_id, pathname, arg_list):
        """A file was opened by the user."""
        unused = arg_list
        if pathname:
            clewnbuf = vimbuffer.is_clewnbuf(pathname)
            if os.path.isabs(pathname) or clewnbuf:
                if clewnbuf:
                    buf = self._bset[os.path.basename(pathname)]
                    if buf.editport is not None:
                        buf.editport.visible = True
                else:
                    buf = self._bset[pathname]

                if buf.buf_id != buf_id:
                    if buf_id == 0:
                        self.send_cmd(buf, 'putBufferNumber',
                                                misc.quote(pathname))
                        self.send_cmd(buf, 'stopDocumentListen')
                        buf.registered = True
                        buf.update()
                    else:
                        warning('got fileOpened with wrong bufId')
                elif clewnbuf and not isinstance(buf.editport, Console):
                    self.send_function(buf, 'getLength')

            else:
                warning('absolute pathname required')
        else:
            self.show_balloon(
                '\nYou cannot use netbeans on a "[No Name]" file.\n'
                'Please, edit a file.\n'
                )
Example #4
0
    def update(self, content):
        """Update the vim buffer with the new content."""
        self.dirty = False
        if not self.buf.registered:
            return

        offset = 0
        newlist = content.splitlines(1)
        send_function = self.send_function
        try:
            for line in self.differ.compare(self.linelist, newlist):
                assert len(line) > 2

                if line.startswith('  '):
                    offset += len(line) - 2
                elif line.startswith('+ '):
                    delta = len(line) - 2
                    send_function('insert',
                            '%s %s' % (str(offset), misc.quote(line[2:])))
                    self.len += delta
                    offset += delta
                elif line.startswith('- '):
                    delta = len(line) - 2
                    self.remove(offset, delta)
                    self.len -= delta
                elif line.startswith('? '):
                    pass    # skip line not present in either input sequence
                else:
                    assert False, "line not prefixed by the differ instance"
        finally:
            self.terminate_editing()

        self.linelist = newlist
Example #5
0
    def evt_fileOpened(self, buf_id, pathname, arg_list):
        """A file was opened by the user."""
        unused = arg_list
        if pathname:
            clewnbuf = vimbuffer.is_clewnbuf(pathname)
            if os.path.isabs(pathname) or clewnbuf:
                if clewnbuf:
                    buf = self._bset[os.path.basename(pathname)]
                    if buf.editport is not None:
                        buf.editport.visible = True
                else:
                    buf = self._bset[pathname]

                if buf.buf_id != buf_id:
                    if buf_id == 0:
                        self.send_cmd(buf, 'putBufferNumber',
                                                misc.quote(pathname))
                        self.send_cmd(buf, 'stopDocumentListen')
                        buf.registered = True
                        buf.update()
                    else:
                        warning('got fileOpened with wrong bufId')
                elif clewnbuf and not isinstance(buf.editport, Console):
                    self.send_function(buf, 'getLength')

            else:
                warning('absolute pathname required')
        else:
            self.show_balloon(
                '\nYou cannot use netbeans on a "[No Name]" file.\n'
                'Please, edit a file.\n'
                )
Example #6
0
    def update(self, content):
        """Update the vim buffer with the new content."""
        self.dirty = False
        if not self.buf.registered:
            return

        offset = 0
        newlist = content.splitlines(1)
        send_function = self.send_function
        try:
            for line in self.differ.compare(self.linelist, newlist):
                assert len(line) > 2

                if line.startswith('  '):
                    offset += len(line) - 2
                elif line.startswith('+ '):
                    delta = len(line) - 2
                    send_function(
                        'insert',
                        '%s %s' % (str(offset), misc.quote(line[2:])))
                    self.len += delta
                    offset += delta
                elif line.startswith('- '):
                    delta = len(line) - 2
                    self.remove(offset, delta)
                    self.len -= delta
                elif line.startswith('? '):
                    pass  # skip line not present in either input sequence
                else:
                    assert False, "line not prefixed by the differ instance"
        finally:
            self.terminate_editing()

        self.linelist = newlist
Example #7
0
    def update(self, content):
        """Update the vim buffer with the new content."""
        self.dirty = False
        if not self.buf.registered:
            return

        # build the list of the offsets of the beginning of each line
        newlist = content.splitlines(1)
        num_lines = len(newlist)
        offsets = [offset for offset in misc.offset_gen(newlist)]

        started = False
        hunk_a = hunk_b = 0
        send_function = self.send_function
        try:
            if logger.level <= logging.DEBUG:
                for line in difflib.unified_diff(self.linelist, newlist):
                    debug(line.strip('\n'))

            for line in difflib.unified_diff(self.linelist, newlist):
                if not started:
                    if line.startswith('+++'):
                        started = True
                    continue
                if hunk_a == hunk_b == 0:
                    matchobj = re_unidiff.match(line.strip())
                    if matchobj:
                        lnum = int(matchobj.group('lnum'))
                        hunk_a = int(matchobj.group('a'))
                        hunk_b = int(matchobj.group('b'))
                    else:
                        assert False, "missing unified-diff control line"
                    continue
                if line[0] == ' ':
                    lnum += 1
                    hunk_a -= 1
                    hunk_b -= 1
                elif line[0] == '+':
                    delta = len(line) - 1
                    send_function('insert',
                        '%s %s' % (str(offsets[lnum-1]), misc.quote(line[1:])))
                    self.len += delta
                    lnum += 1
                    hunk_b -= 1
                elif line[0] == '-':
                    delta = len(line) - 1
                    if lnum <= num_lines:
                        self.remove(offsets[lnum-1], delta)
                    else:
                        # removing (one of) the last line(s)
                        self.remove(len(content), delta)
                    self.len -= delta
                    hunk_a -= 1
                else:
                    assert False, "unknown unified-diff line type"
        finally:
            self.terminate_editing()

        self.linelist = newlist
Example #8
0
File: gdbmi.py Project: Skip/vim
 def sendcmd(self):
     """Send the gdb command."""
     if self.gdb.accepting_cmd():
         self.result = ''
         self.gdb.gdb_busy = True
         return self.send('-data-evaluate-expression %s\n',
                                     misc.quote(self.text))
     return False
Example #9
0
    def vim_script_custom(self, prefix):
        """Return gdb specific vim statements to add to the vim script.

        This is used to load the symbols completion list to the break and clear
        gdb commands.

        """
        symcompletion = string.Template(SYMCOMPLETION).substitute(pre=prefix,
                        ack_tmpfile=misc.quote(self.globaal.f_ack.name),
                        complete_tmpfile=misc.quote(self.globaal.f_clist.name),
                        complete_timeout=SYMBOL_COMPLETION_TIMEOUT)

        cwindow = string.Template(CWINDOW).substitute(pre=prefix,
                                            tmpfile=self.globaal.f_bps.name)

        sequences = string.Template(SEQUENCES).substitute(pre=prefix)

        return symcompletion + cwindow + sequences
Example #10
0
    def vim_script_custom(self, prefix):
        """Return gdb specific vim statements to add to the vim script.

        This is used to load the symbols completion list to the break and clear
        gdb commands.

        """
        symcompletion = string.Template(SYMCOMPLETION).substitute(pre=prefix,
                        ack_tmpfile=misc.quote(self.globaal.f_ack.name),
                        complete_tmpfile=misc.quote(self.globaal.f_clist.name),
                        complete_timeout=SYMBOL_COMPLETION_TIMEOUT)

        cwindow = string.Template(CWINDOW).substitute(pre=prefix,
                                            tmpfile=self.globaal.f_bps.name)

        sequences = string.Template(SEQUENCES).substitute(pre=prefix)

        return symcompletion + cwindow + sequences
Example #11
0
def install():
    """Write the bat file and copy the runtime files."""
    prefix = sysconfig.get_config_var('prefix')
    scripts = pathjoin(prefix, 'scripts')
    vim_features()

    # install runtime files
    runtime_dir = pathjoin(prefix, 'pyclewn')
    icon_file = pathjoin(runtime_dir, ICON_NAME)
    copy_file(icon_file, scripts)
    print >> sys.stderr, 'copying file %s' % icon_file
    unlink(icon_file)

    # substitute templates in the autoload plugin
    clewnbat = pathjoin(scripts, 'pyclewn.bat')
    mapping = {'pgm': misc.quote(clewnbat), 'start': 'start '}
    substitute_autoload(runtime_dir, mapping)

    for filename in dir_util.copy_tree(runtime_dir, vimdir()):
        print >> sys.stderr, 'copying file %s' % filename
    print >> sys.stderr, 'removing directory %s' % runtime_dir
    dir_util.remove_tree(runtime_dir)

    build_vimhelp()

    # create pyclewn.bat
    pyexe = pathjoin(prefix, 'python.exe')
    scriptpy = pathjoin(scripts, 'pyclewn')
    f = open(clewnbat, 'w')
    f.write("@start %s %s %%*\n" % (pyexe, scriptpy))
    f.close()

    # create Windows shortcut
    create_shortcut(
        clewnbat,
        'Pyclewn allows using Vim as a front end to a debugger.',
        PYCLEWN_SHORTCUT,
        r'--pgm=C:\mingw\bin\gdb.exe --daemon',
        '',
        pathjoin(scripts, ICON_NAME),
        0)

    # copy shortcut to Desktop when it does not exist
    desktop_path = get_special_folder_path('CSIDL_DESKTOPDIRECTORY')
    pyclewn_shortcut = pathjoin(desktop_path, PYCLEWN_SHORTCUT)
    if not os.path.exists(pyclewn_shortcut):
        copy_file(PYCLEWN_SHORTCUT, desktop_path)
        print >> sys.stderr, 'copying pyclewn to the desktop: %s' % pyclewn_shortcut

    # cleanup
    unlink(PYCLEWN_SHORTCUT)
    unlink(pathjoin(scripts, 'pyclewn_install.py'))
    unlink(pathjoin(scripts, 'pyclewn_install.pyc'))
    unlink(pathjoin(scripts, 'pyclewn_install.pyo'))

    print >> sys.stderr, 'pyclewn postinstall completed'
Example #12
0
    def sendcmd(self, cmd):
        """Send a cli command."""
        if not self.gdb.accepting_cmd():
            self.gdb.console_print("gdb busy: command discarded, please retry\n")
            return False

        self.gdb.gdb_busy = True
        cmd = misc.norm_unixpath(cmd)
        self.stream_record = ""
        return self.send("-interpreter-exec console %s\n", misc.quote(cmd))
Example #13
0
    def vim_script_custom(self, prefix):
        """Return gdb specific vim statements to add to the vim script.

        This is used to load the symbols completion list to the break and clear
        gdb commands.

        """
        symcompletion = string.Template(SYMCOMPLETION).substitute(pre=prefix,
                        ack_tmpfile=misc.quote(self.globaal.f_ack.name),
                        complete_tmpfile=misc.quote(self.globaal.f_clist.name),
                        complete_timeout=SYMBOL_COMPLETION_TIMEOUT)

        if os.name == 'nt':
            grepprg = 'cmd\\ /c\\ type'
        else:
            grepprg = 'cat'
        grepprg += '\\ ' + self.globaal.f_bps.name
        cwindow = string.Template(CWINDOW).substitute(pre=prefix, gp=grepprg)

        return symcompletion + cwindow
Example #14
0
    def show_balloon(self, text):
        """Show the Vim balloon."""
        # do not show a balloon when the debugger is not started
        if not self.debugger or not self.debugger.started:
            return

        # restrict size to 2000 chars, about...
        size = 2000
        if len(text) > size:
            size //= 2
            text = text[:size] + '...' + text[-size:]
        self.send_cmd(None, 'showBalloon', misc.quote(text))
Example #15
0
    def show_balloon(self, text):
        """Show the Vim balloon."""
        # do not show a balloon when the debugger is not started
        if not self.debugger or not self.debugger.started:
            return

        # restrict size to 2000 chars, about...
        size = 2000
        if len(text) > size:
            size //= 2
            text = text[:size] + '...' + text[-size:]
        self.send_cmd(None, 'showBalloon', misc.quote(text))
Example #16
0
    def vim_script_custom(self, prefix):
        """Return gdb specific vim statements to add to the vim script.

        This is used to load the symbols completion list to the break and clear
        gdb commands.

        """
        symcompletion = string.Template(SYMCOMPLETION).substitute(
            pre=prefix,
            ack_tmpfile=misc.quote(self.globaal.f_ack.name),
            complete_tmpfile=misc.quote(self.globaal.f_clist.name),
            complete_timeout=SYMBOL_COMPLETION_TIMEOUT)

        if os.name == 'nt':
            grepprg = 'cmd\\ /c\\ type'
        else:
            grepprg = 'cat'
        grepprg += '\\ ' + self.globaal.f_bps.name
        cwindow = string.Template(CWINDOW).substitute(pre=prefix, gp=grepprg)

        return symcompletion + cwindow
Example #17
0
    def remove(self, offset, count):
        """Remove 'count' bytes at 'offset'.

        Vim 7.1 remove implementation is buggy and cannot remove a single or
        partial line. In this case we insert first an empty line and remove all
        lines in one shot (NOTE that this implies this method MUST NOT be
        called when removing partial lines with a buggy vim 7.1).
        It is Ok with a more recent vim version.

        """
        send_function = self.send_function
        if self.nbsock.remove_fix == '0':
            send_function('insert', '%s %s' % (str(offset), misc.quote('\n')))
            send_function('remove', '%s %s' % (str(offset), str(count + 1)))
        else:
            send_function('remove', '%s %s' % (str(offset), str(count)))
Example #18
0
    def remove(self, offset, count):
        """Remove 'count' bytes at 'offset'.

        Vim 7.1 remove implementation is buggy and cannot remove a single or
        partial line. In this case we insert first an empty line and remove all
        lines in one shot (NOTE that this implies this method MUST NOT be
        called when removing partial lines with a buggy vim 7.1).
        It is Ok with a more recent vim version.

        """
        send_function = self.send_function
        if self.nbsock.remove_fix == '0':
            send_function('insert', '%s %s' % (str(offset), misc.quote('\n')))
            send_function('remove', '%s %s' % (str(offset), str(count + 1)))
        else:
            send_function('remove', '%s %s' % (str(offset), str(count)))
Example #19
0
    def append(self, msg, *args):
        """Append text to the end of the editport."""
        if not self.buf.registered:
            return
        if self.nonempty_last:
            self.nonempty_last = False
            self.len -= 1
        if args:
            msg = msg % args
        self.send_function('insert', '%s %s' % (str(self.len), misc.quote(msg)))

        if not msg.endswith('\n'):
            self.nonempty_last = True
            self.len += 1
        self.len += len(msg)

        # show the last line if the buffer is displayed in a Vim window
        self.setdot(offset=(self.len - 1))
        self.terminate_editing()
Example #20
0
 def special_keys(self, key):
     """Send the specialKeys netbeans command."""
     self.send_cmd(None, 'specialKeys', misc.quote(key))
Example #21
0
File: gdbmi.py Project: Skip/vim
 def sendcmd(self):
     """Send the gdb command."""
     return MiCommand.docmd(self, '-var-create - * %s\n',
                                 misc.quote(self.varobj['exp']))
Example #22
0
    def update(self, content):
        """Update the vim buffer with the new content."""
        self.dirty = False
        if not self.buf.registered:
            return

        # build the list of the offsets of the beginning of each line
        newlist = content.splitlines(1)
        num_lines = len(newlist)
        offsets = [offset for offset in misc.offset_gen(newlist)]

        started = False
        hunk_a = hunk_b = 0
        send_function = self.send_function
        try:
            if logger.level <= logging.DEBUG:
                for line in difflib.unified_diff(self.linelist, newlist):
                    debug(line.strip('\n'))

            for line in difflib.unified_diff(self.linelist, newlist):
                if not started:
                    if line.startswith('+++'):
                        started = True
                    continue
                if hunk_a == hunk_b == 0:
                    matchobj = re_unidiff.match(line.strip())
                    if matchobj:
                        lnum = int(matchobj.group('lnum'))
                        if lnum == 0:
                            lnum = 1
                        # @@ -l,s +l,s @@
                        # each range can omit the comma and trailing value s, in
                        # which case s defaults to 1
                        hunk_a = matchobj.group('a')
                        if hunk_a is not None:
                            hunk_a = int(hunk_a)
                        else:
                            hunk_a = 1
                        hunk_b = matchobj.group('b')
                        if hunk_b is not None:
                            hunk_b = int(hunk_b)
                        else:
                            hunk_b = 1
                    else:
                        assert False, "missing unified-diff control line"
                    continue
                if line[0] == ' ':
                    lnum += 1
                    hunk_a -= 1
                    hunk_b -= 1
                elif line[0] == '+':
                    delta = len(line) - 1
                    send_function('insert',
                        '%s %s' % (str(offsets[lnum-1]), misc.quote(line[1:])))
                    self.len += delta
                    lnum += 1
                    hunk_b -= 1
                elif line[0] == '-':
                    delta = len(line) - 1
                    if lnum <= num_lines:
                        self.remove(offsets[lnum-1], delta)
                    else:
                        # removing (one of) the last line(s)
                        self.remove(len(content), delta)
                    self.len -= delta
                    hunk_a -= 1
                else:
                    assert False, "unknown unified-diff line type"
        finally:
            self.terminate_editing()

        self.linelist = newlist
Example #23
0
 def register(self):
     """Register the buffer with netbeans vim."""
     self.nbsock.send_cmd(self.buf, 'editFile', misc.quote(self.buf.name))
     self.nbsock.send_cmd(self.buf, 'setReadOnly', 'T')
     self.buf.registered = True
Example #24
0
 def special_keys(self, key):
     """Send the specialKeys netbeans command."""
     self.send_cmd(None, 'specialKeys', misc.quote(key))
Example #25
0
 def sendcmd(self):
     """Send the gdb command."""
     self.result = ""
     return self.send("-data-evaluate-expression %s\n", misc.quote(self.text))
Example #26
0
 def sendcmd(self):
     """Send the gdb command."""
     if self.gdb.accepting_cmd():
         self.gdb.gdb_busy = True
         return self.send("-interpreter-exec console %s\n", misc.quote("whatis %s" % self.text))
     return False
Example #27
0
 def sendcmd(self):
     """Send the gdb command."""
     return MiCommand.docmd(self, "-var-create - * %s\n", misc.quote(self.varobj["exp"]))
Example #28
0
 def register(self):
     """Register the buffer with netbeans vim."""
     self.nbsock.send_cmd(self.buf, 'editFile', misc.quote(self.buf.name))
     self.nbsock.send_cmd(self.buf, 'setReadOnly', 'T')
     self.buf.registered = True