示例#1
0
def sel_pipe(command, buffer=None):
    """Process the current selection in BUFFER through COMMAND,
       and replace that selection with the output of the command"""
    if not buffer:
        buffer = EditorBuffer.get()
    start = buffer.selection_start()
    end = buffer.selection_end()

    # Ignore white spaces and newlines at end, to preserve the rest
    # of the text
    if start != end:
        while end.get_char() == ' ' or end.get_char() == '\n':
            end = end - 1

        text = buffer.get_chars(start, end)
    else:
        text = ""

    proc = Process(command)
    proc.send(text)
    proc.send(chr(4))  # Close input
    output = proc.get_result()
    with buffer.new_undo_group():
        if start != end:
            buffer.delete(start, end)
        buffer.insert(start, output.rstrip())
示例#2
0
 def on_lock_taken(self, proc, exit_status, output):
     """
     Called when we have finished taking the lock on the local RCS file
     """
     pwd = os.getcwd()
     os.chdir(self.rcs_dir)
     # Specify our own date, so that the date associated with the revision
     # is the one when the file was saved. Otherwise, it defaults to the
     # last modification of the date, and this might dependent on the local
     # time zone
     proc = Process(
         "ci -d" + datetime.datetime.now().strftime("%Y/%m/%d\\ %H:%M:%S") +
         " " + os.path.basename(self.file))
     os.chdir(pwd)
     proc.send(".\n")