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
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)
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
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)
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 _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 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")
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
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)
def find_region(self): """\ Return the limits of the region. """ return lisp.point(), lisp.mark(lisp.t)
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))
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))
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))
def mark_exists(): if is_xemacs: return lisp.mark() else: return lisp("mark-active") and lisp.mark()