Example #1
0
def get_region(delete=0):
    """Returns the text of the current region, optionally
     deleting the region from the buffer."""

    start = lisp.point()
    end = lisp.mark(lisp.t)
    text = lisp.buffer_substring(start, end)
    if delete:
        lisp.delete_region(start, end)
    return text
Example #2
0
def get_region(delete=0):
     """Returns the text of the current region, optionally
     deleting the region from the buffer."""
     
     start = lisp.point()
     end = lisp.mark(lisp.t)
     text = lisp.buffer_substring(start, end)
     if delete:
          lisp.delete_region(start, end)
     return text
Example #3
0
def camelCase_to_underscore():
    start, end = lisp.point(), lisp.mark(True)
    text = lisp.buffer_substring(start, end)

    replacement =re.sub(r'\w+',
                        lambda x: "".join(upper_split_gen(x)),
                        text)

    lisp.delete_region(start, end)
    lisp.insert(replacement)
Example #4
0
def run_text():
    start = lisp.point()
    end = lisp.mark(True)
    if start > end:
        start, end = end, start
    text = lisp.buffer_substring(start, end)
    if len(text):
        client.run_text(text)
    else:
        # TODO Complain in message bar
        pass
Example #5
0
def replace_region(replacer):
    start = lisp.point()
    end = lisp.mark(True)
    if start > end:
        start, end = end, start
    text = lisp.buffer_substring(start, end)

    replacement = replacer(text)

    lisp.delete_region(start, end)
    lisp.insert(replacement)
Example #6
0
def _getCoords():
    line = lisp.count_lines(1, lisp.point())
    col = lisp.current_column()
    if col == 0:
        line += 1  # get round 'if col == 0, then line is 1 out' problem

    if mark_exists() and lisp.point() > lisp.mark():
        lisp.exchange_point_and_mark()
        col = lisp.current_column()
        lisp.exchange_point_and_mark()
    return line, col
def run_text():
    start = lisp.point()
    end = lisp.mark(True)
    if start > end:
        start, end = end, start
    text = lisp.buffer_substring(start, end)
    if len(text):
        client.run_text(text)
    else:
        # TODO Complain in message bar
        pass
Example #8
0
def _getCoords():
    line = lisp.count_lines(1,lisp.point())
    col = lisp.current_column()
    if col == 0:            
        line += 1  # get round 'if col == 0, then line is 1 out' problem

    if mark_exists() and lisp.point() > lisp.mark():
        lisp.exchange_point_and_mark()
        col = lisp.current_column()
        lisp.exchange_point_and_mark()
    return line,col
Example #9
0
def pexec_region():
    global glob
    start = time.time()
    start, end = lisp.point(), lisp.mark(lisp.t)
    content = lisp.buffer_substring(start, end)
    lines = content.split("\n")
    for line in lines:
        line = line.replace("\n","")
        if line != "":
            c = compile(source=line,filename="",mode="single")
            eval(c,glob)
    elapsed = (time.time() - start)
    lisp.message("Ran in " + str(elapsed) + " seconds")
Example #10
0
def cut_region(mode='string'):
    """Return the active region and remove it from Emacs.

    The mode parameter (default 'string') defines whether to return the region
    as a string or as a list of lines (mode='list').

    It is the caller's responsibility to insert the updated text at the
    end back in the Emacs buffer with a call to lisp.insert(...)."""

    start, end = lisp.point(), lisp.mark(lisp.t)
    # BUG: buffer_substring() can't extract regions with dos line endings (\r\n)
    # It dumps a traceback.
    region = lisp.buffer_substring(start, end)
    if mode == 'list':
        region = region.splitlines()
    lisp.delete_region(start, end)
    return region
Example #11
0
def cut_region(mode='string'):
    """Return the active region and remove it from Emacs.

    The mode parameter (default 'string') defines whether to return the region
    as a string or as a list of lines (mode='list').

    It is the caller's responsibility to insert the updated text at the
    end back in the Emacs buffer with a call to lisp.insert(...)."""

    start, end = lisp.point(), lisp.mark(lisp.t)
    # BUG: buffer_substring() can't extract regions with dos line endings (\r\n)
    # It dumps a traceback.
    region = lisp.buffer_substring(start, end)
    if mode == 'list':
        region = region.splitlines()
    lisp.delete_region(start, end)
    return region
Example #12
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 #13
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 #14
0
    def find_region(self):
        """\
Return the limits of the region.
"""
        return lisp.point(), lisp.mark(lisp.t)
Example #15
0
if 'arg' in globals():
    from Pymacs import lisp

    # Retrieve current buffer file name
    filename = lisp.buffer_file_name()

    # Sample code : break on whitespace
    start, end = lisp.point(), lisp.mark(True)
    words = lisp.buffer_substring(start, end).split("\n")

    words = map(lambda x: x.rstrip(" "), words)
    lisp.delete_region(start, end)
    lisp.insert('\n'.join(words))
Example #16
0
def break_on_whitespace():
    start, end = lisp.point(), lisp.mark(True)
    words = lisp.buffer_substring(start, end).split()
    lisp.delete_region(start, end)
    lisp.insert('\n'.join(words))
Example #17
0
if 'arg' in globals():
    from Pymacs import lisp

    # Retrieve current buffer file name
    filename = lisp.buffer_file_name()
    
    # Sample code : break on whitespace
    start, end = lisp.point(), lisp.mark(True)
    words = lisp.buffer_substring(start, end).split("\n")

    words = map(lambda x : x.rstrip(" "), words)
    lisp.delete_region(start, end)        
    lisp.insert('\n'.join(words))
Example #18
0
def mark_exists():
    if is_xemacs:
        return lisp.mark()
    else:
        return lisp("mark-active") and lisp.mark()
Example #19
0
def mark_exists():
    if is_xemacs:
        return lisp.mark()
    else:
        return lisp("mark-active") and lisp.mark()
Example #20
0
def break_on_whitespace():
    start, end = lisp.point(), lisp.mark(True)
    words = lisp.buffer_substring(start, end).split()
    lisp.delete_region(start, end)
    lisp.insert('\n'.join(words))
Example #21
0
File: rebox.py Project: ing7t/kod
    def find_region(self):
        """\
Return the limits of the region.
"""
        return lisp.point(), lisp.mark(lisp.t)