Example #1
0
    def show_occurrences(self, locations):
        buffer = self._make_buffer('*rope-occurrences*', "", switch=False)
        lisp.set_buffer(buffer)
        lisp.toggle_read_only(0)

        trunc_length = len(lisp.rope_get_project_root())

        lisp.insert('List of occurrences:\n')
        for location in locations:
            code_line = self.read_line_from_file(location.filename, location.lineno).rstrip()
            filename = location.filename[trunc_length:]
            lineno = str(location.lineno)
            offset = str(location.offset)

            lisp.insert(filename + ":" + lineno + ":" + code_line + " " + offset)

            beginning = lisp.line_beginning_position()
            end = beginning + len(filename)

            lisp.add_text_properties(beginning, end, [lisp.face, lisp.button])
            lisp.add_text_properties(beginning, end, [lisp.mouse_face, lisp.highlight,
                                                      lisp.help_echo, "mouse-2: visit this file in other window"])

            lisp.insert("\n")

        lisp.toggle_read_only(1)

        lisp.set(lisp["next-error-function"], lisp.rope_occurrences_next)
        lisp.local_set_key('\r', lisp.rope_occurrences_goto)
        lisp.local_set_key((lisp.mouse_1,), lisp.rope_occurrences_goto)
        lisp.local_set_key('q', lisp.delete_window)
def check_word():
    """
    Check the current word and try to push a help message and a completion
    """
    line = lisp.buffer_substring(lisp.line_beginning_position(),lisp.point())
    lines= lisp.buffer_substring(1,lisp.point()).splitlines()
    lines.reverse()
    d = find_completion(line,lines)
    if d[0]:   
        f,completions,target = d
        #lisp.message("Found %d completions\n%s"%(len(completions),curType))
        
        help_str = make_help_message(completions)
        
        # make sure we're probably running X:
        if lisp.window_system() is not None and \
                lisp.pos_tip_show is not None: # make sure extension is installed
            lisp.pos_tip_show(help_str,None,None,None,0)
        else:
            lisp.message(help_str) # just use the emacs mini-buffer
        if len(completions)==1:#if there's only one completion, just insert it
            d = completions[0].data['name'][len(target):]
            if len(d):lisp.insert(d)     
    else:
        lisp.message(d[1])
Example #3
0
 def occurrences_goto_occurrence(self):
     self._check_project()
     start = lisp.line_beginning_position()
     end = lisp.line_end_position()
     line = lisp.buffer_substring_no_properties(start, end)
     tokens = line.split()
     if tokens:
         resource = self.project.get_resource(tokens[0])
         offset = int(tokens[2])
         lisp.find_file_other_window(resource.real_path)
         lisp.goto_char(offset + 1)
         lisp.switch_to_buffer_other_window('*rope-occurrences*')
Example #4
0
    def wrapper():
        if lisp.mark_active.value():
            # fetch marked text
            start = lisp.point()
            end = lisp.mark(True)
        else:
            # fetch full line
            start = lisp.line_beginning_position()
            end = lisp.line_end_position()

        start, end = min(start, end), max(start, end)
            
        text = lisp.buffer_substring(start, end)
        new_text = func(text)
        if isinstance(new_text, str):
            # replace text with new text
            lisp.delete_region(start, end)
            lisp.insert(new_text)
Example #5
0
def fixer_remove_blank_lines (unused_error, errtext):
    # E303 too many blank lines (7)
    linecount = 1
    m = re.search(r"too many blank lines \((\d+)\)", errtext)
    if m:
        linecount = int(m.group(1))
        # There's a bug in flake8 it's returning 2 lines too many
        if linecount > 2:
            linecount -= 2

    # XXX try this with a comment right about the warning, deletes the comment
    lisp.beginning_of_line()
    beg = lisp.line_beginning_position()
    lisp.beginning_of_line(-(linecount - 1))
    lisp.forward_line(1)
    lisp.forward_char(-1)
    lisp.delete_region(beg, lisp.point())
    return
Example #6
0
def get_line_string ():
    start = lisp.line_beginning_position()
    end = lisp.line_end_position()
    return start, end, lisp.buffer_substring(start, end)