def rename_command():
    project, file = eclim.get_context()    
    # we cannot read the code from TM via stdin, as it will not have 
    # the correct line endings when editing windows files (it will just have \n)
    #code = sys.stdin.read()

    # so we read from disk
    with open(os.environ["TM_FILEPATH"]) as f:
        code = f.read()
    pos = caret_position(code)
    identifier = current_identifier()
    pos = code.find(identifier, pos-len(identifier))
    
    new_name = util.get_input(default=identifier,title="Enter new name")
    
    call_eclim(project, file, len(identifier), pos, new_name)
def completion_command():
    project, file = eclim.get_context()    
    # we cannot read the code from TM via stdin, as it will not have 
    # the correct line endings when editing windows files (it will just have \n)
    #code = sys.stdin.read()

    # so we read from disk
    with open(os.environ["TM_FILEPATH"]) as f:
        code = f.read()
    pos = caret_position(code)

    proposals, with_snippets = to_proposals(call_eclim(project, file, pos))
    if with_snippets:
        completion_popup_with_snippet(proposals)
    else:
        completion_popup(proposals)
def go_to_definition_command():
    project, file = eclim.get_context()    
    # we cannot read the code from TM via stdin, as it will not have 
    # the correct line endings when editing windows files (it will just have \n)
    #code = sys.stdin.read()

    # so we read from disk
    with open(os.environ["TM_FILEPATH"]) as f:
        code = f.read()
    pos = caret_position(code)
    identifier = current_identifier()
    pos = code.find(identifier, pos-len(identifier))

    locations = call_eclim(project, file, pos, len(identifier))
    locations = to_list(locations)
    if len(locations) == 1:
        go_to_location(locations[0])
def correction_command():
    project, file = eclim.get_context()
    # we cannot read the code from TM via stdin, as it will not have
    # the correct line endings when editing windows files (it will just have \n)
    # code = sys.stdin.read()

    # so we read from disk
    with open(os.environ["TM_FILEPATH"]) as f:
        code = f.read()
    pos = caret_position(code)
    line = int(os.environ["TM_LINE_NUMBER"])

    corrections = call_eclim(project, file, line, pos)
    corrections = to_list(corrections)
    if corrections:
        correction_to_apply = show_corrections_window(corrections)
    else:
        correction_to_apply = None
    if correction_to_apply != None:
        new_code = call_eclim(project, file, line, pos, correction_to_apply)
        if new_code:
            return new_code
    return code