Esempio n. 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
Esempio n. 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
Esempio n. 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)
Esempio n. 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
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 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")
Esempio n. 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
Esempio n. 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
Esempio n. 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)
Esempio n. 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)
Esempio n. 14
0
    def find_region(self):
        """\
Return the limits of the region.
"""
        return lisp.point(), lisp.mark(lisp.t)
Esempio n. 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))
Esempio n. 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))
Esempio n. 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))
Esempio n. 18
0
def mark_exists():
    if is_xemacs:
        return lisp.mark()
    else:
        return lisp("mark-active") and lisp.mark()
Esempio n. 19
0
def mark_exists():
    if is_xemacs:
        return lisp.mark()
    else:
        return lisp("mark-active") and lisp.mark()
Esempio n. 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))
Esempio n. 21
0
File: rebox.py Progetto: ing7t/kod
    def find_region(self):
        """\
Return the limits of the region.
"""
        return lisp.point(), lisp.mark(lisp.t)