def get_buffer_content_prev(bend): where_am_i = lisp.point() lisp.beginning_of_buffer() st = lisp.point() s = lisp.buffer_substring(st, bend) lisp.goto_char(where_am_i) return s
def get_line_offset(): """Return number of characters cursor is offset from margin. """ user_pos = lisp.point() lisp.beginning_of_line() line_start = lisp.point() lisp.goto_char(user_pos) return user_pos - line_start
def occurrences_goto(): if lisp.line_number_at_pos() < 1: lisp.forward_line(1 - lisp.line_number_at_pos()) lisp.end_of_line() end = lisp.point() lisp.beginning_of_line() line = lisp.buffer_substring_no_properties(lisp.point(), end) tokens = line.split() semicolon_tokens = line.split(":") project_root = lisp.rope_get_project_root() if tokens and semicolon_tokens: # Mark this line with an arrow lisp(''' (remove-overlays (point-min) (point-max)) (overlay-put (make-overlay (line-beginning-position) (line-end-position)) 'before-string (propertize "A" 'display '(left-fringe right-triangle))) ''') filename = project_root + "/" + semicolon_tokens[0] offset = int(tokens[-1]) resource = _interface._get_resource(filename) LispUtils().find_file(resource.real_path, other=True) lisp.goto_char(offset + 1)
def check_word(): """ Check the current word and try to push a help message and a completion """ line = lisp.buffer_substring(lisp.line_beginning_position(),lisp.point()) lines= lisp.buffer_substring(1,lisp.point()).splitlines() lines.reverse() d = find_completion(line,lines) if d[0]: f,completions,target = d #lisp.message("Found %d completions\n%s"%(len(completions),curType)) help_str = make_help_message(completions) # make sure we're probably running X: if lisp.window_system() is not None and \ lisp.pos_tip_show is not None: # make sure extension is installed lisp.pos_tip_show(help_str,None,None,None,0) else: lisp.message(help_str) # just use the emacs mini-buffer if len(completions)==1:#if there's only one completion, just insert it d = completions[0].data['name'][len(target):] if len(d):lisp.insert(d) else: lisp.message(d[1])
def run_py_code(): remember_where = lisp.point() # check if the line contains \inputminted lisp.beginning_of_line() l1 = lisp.point() lisp.end_of_line() l2 = lisp.point() line = lisp.buffer_substring(l1,l2) # if code comes from file # get code content from latex block_begin,block_end,content = get_block_content("```python","```\n") # we have code content at this point # scan content to find plt.plot(). if there is, scan buffer # previous to *here* to determine order of _this_ plt.plot(), and # give it an appropiate index that will be appended to the end of # the .png image file, i.e. [buffer name]_[index].png. plt.plot() # commands will be replaced by the corresponding plt.savefig # command. # generate savefig for execution code (no output in emacs yet) bc = lisp.buffer_string() plt_count_before = len(re.findall('plt\.savefig\(',bc)) base = os.path.splitext(lisp.buffer_name())[0] f = '%s_%s.png' % (base, two_digit(plt_count_before+1)) rpl = "plt.savefig('%s')" % f show_replaced = True if "plt.show()" in content else False content=content.replace("plt.show()",rpl) content="plt.figure();\n"+content include_graphics_command = "![](%s)" % f # we have code content at this point start = time.time() with capture_output() as io: res_code = ip.run_cell(content) res = io.stdout elapsed = (time.time() - start) if len(res) > 0: display_results(block_end, res) # display it if show_replaced: lisp.goto_char(block_end) lisp.forward_line(2) # skip over end verbatim, leave one line emtpy lisp.insert('\n' + include_graphics_command + '\n') lisp.scroll_up(1) # skip over end verbatim, leave one line emtpy lisp.goto_char(remember_where) lisp.replace_string("plt.show()",rpl,None,block_begin,block_end) lisp.goto_char(remember_where) lisp.message("Ran in " + str(elapsed) + " seconds")
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 verb_exists(): remem = lisp.point() lisp.forward_line(1) lisp.beginning_of_line() verb_line_b = lisp.point() lisp.end_of_line() verb_line_e = lisp.point() verb_line = lisp.buffer_substring(verb_line_b, verb_line_e) lisp.goto_char(remem) if "```text" in verb_line: return True else: return False
def run_py_code(): remember_where = lisp.point() # check if the line contains \inputminted lisp.beginning_of_line() l1 = lisp.point() lisp.end_of_line() l2 = lisp.point() line = lisp.buffer_substring(l1, l2) # if code comes from file # get code content from latex block_begin, block_end, content = get_block_content("```python", "```\n") # we have code content at this point # scan content to find plt.plot(). if there is, scan buffer # previous to *here* to determine order of _this_ plt.plot(), and # give it an appropiate index that will be appended to the end of # the .png image file, i.e. [buffer name]_[index].png. plt.plot() # commands will be replaced by the corresponding plt.savefig # command. # generate savefig for execution code (no output in emacs yet) bc = lisp.buffer_string() plt_count_before = len(re.findall('plt\.savefig\(', bc)) base = os.path.splitext(lisp.buffer_name())[0] f = '%s_%s.png' % (base, two_digit(plt_count_before + 1)) rpl = "plt.savefig('%s')" % f show_replaced = True if "plt.show()" in content else False content = content.replace("plt.show()", rpl) content = "plt.figure();\n" + content include_graphics_command = "![](%s)" % f # we have code content at this point start = time.time() with capture_output() as io: res_code = get_ip().run_cell(content) res = io.stdout elapsed = (time.time() - start) if len(res) > 0: display_results(block_end, res) # display it if show_replaced: lisp.goto_char(block_end) lisp.forward_line(2) # skip over end verbatim, leave one line emtpy lisp.insert('\n' + include_graphics_command + '\n') lisp.scroll_up(1) # skip over end verbatim, leave one line emtpy lisp.goto_char(remember_where) lisp.replace_string("plt.show()", rpl, None, block_begin, block_end) lisp.goto_char(remember_where) lisp.message("Ran in " + str(elapsed) + " seconds")
def verb_exists(): remem = lisp.point() lisp.forward_line(2) lisp.beginning_of_line() verb_line_b = lisp.point() lisp.end_of_line() verb_line_e = lisp.point() verb_line = lisp.buffer_substring(verb_line_b, verb_line_e) lisp.goto_char(remem) if "\\begin{verbatim}" in verb_line: return True else: return False
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 occurrences_goto_occurrence(): lisp.end_of_line() end = lisp.point() lisp.beginning_of_line() start = lisp.point() line = lisp.buffer_substring_no_properties(start, end) tokens = line.split() if tokens: filename = tokens[0] offset = int(tokens[-1]) resource = _interface._get_resource(filename) LispUtils().find_file(resource.real_path, other=True) lisp.goto_char(offset + 1) lisp.switch_to_buffer_other_window('*rope-occurrences*')
def occurrences_goto(): if lisp.line_number_at_pos() < 3: lisp.forward_line(3 - lisp.line_number_at_pos()) lisp.end_of_line() end = lisp.point() lisp.beginning_of_line() line = lisp.buffer_substring_no_properties(lisp.point(), end) tokens = line.split() if tokens: filename = tokens[0] offset = int(tokens[-1]) resource = _interface._get_resource(filename) LispUtils().find_file(resource.real_path, other=True) lisp.goto_char(offset + 1)
def find_imports(): print "test hello" fname=lisp.buffer_file_name() print "remember:" + lisp.buffer_name() os.environ['BUFFER'] = lisp.buffer_name() remember_where = lisp.point() try: fname=lisp.buffer_file_name() project = Project(fname) thing, start = thing_at_point_regex("\W", "\W") print "thing:"+thing imports = project.find_file_for_import(thing) if (len(imports) > 1): ready_output() lisp.insert("\n") for item in imports: lisp.insert(item) lisp.insert("\n") elif (len(imports) == 1): put_import(fname, imports[0]) elif (len(imports) == 0): lisp.message("No import found for " + imports[0]) lisp.goto_char(remember_where) except Exception, e: lisp.message(e)
def emacs_engine(self, flag, find_limits): """\ Rebox text while obeying FLAG. Call FIND_LIMITS to discover the extent of the boxed comment. """ # `C-u -' means that box style is to be decided interactively. if flag == lisp['-']: flag = self.ask_for_style() # If FLAG is zero or negative, only change default box style. if isinstance(flag, int) and flag <= 0: self.default_style = -flag lisp.message("Default style set to %d" % -flag) return # Decide box style and refilling. if flag is None: style = self.default_style refill = True elif isinstance(flag, int): if self.default_style is None: style = flag else: style = merge_styles(self.default_style, flag) refill = True else: flag = flag.copy() if isinstance(flag, list): style = self.default_style refill = False else: lisp.error("Unexpected flag value %s" % flag) # Prepare for reboxing. lisp.message("Reboxing...") checkpoint = lisp.buffer_undo_list.value() start, end = find_limits() text = lisp.buffer_substring(start, end) width = lisp.fill_column.value() tabify = lisp.indent_tabs_mode.value() is not None point = lisp.point() if start <= point < end: position = point - start else: position = None # Rebox the text and replace it in Emacs buffer. old_style, new_style, text, position = engine( text, style=style, width=width, refill=refill, tabify=tabify, position=position) if text is None: lisp.error("Cannot rebox to style %d" % new_style) lisp.delete_region(start, end) lisp.insert(text) if position is not None: lisp.goto_char(start + position) # Collapse all operations into a single one, for Undo. self.clean_undo_after(checkpoint) # We are finished, tell the user. if old_style == new_style: lisp.message("Reboxed with style %d" % old_style) else: lisp.message("Reboxed from style %d to %d" % (old_style, new_style))
def _insert_import(self, name, module): lineno = self.autoimport.find_insertion_line(self.source) current = lisp.point() lisp.goto_line(lineno) newimport = 'from %s import %s\n' % (module, name) lisp.insert(newimport) lisp.goto_char(current + len(newimport))
def find_public_methods(): """ retrieves all public methods of class """ try: fname=lisp.buffer_file_name() print "remember:" + lisp.buffer_name() os.environ['BUFFER'] = lisp.buffer_name() project = Project(fname) thing, start = thing_at_point(RIGHT3, LEFT3) thing = thing.replace(".","") print "thing:"+thing pos = lisp.point() type, foundpos = project.find_declaration_type(thing, fname, pos) typefile = project.find_file_for_thing(type, fname) c = Class(project, typefile) public_methods = c.list_all_public() if (len(public_methods) == 0): lisp.message("No public methods found") else: ready_output() lisp.insert("\n") for item in public_methods: lisp.insert(item) lisp.insert("\n") except Exception, e: lisp.message(e)
def convert(): remember_where = lisp.point() block_begin, block_end, content = get_block_content("\n\n","\n\n") # alttaki listeye dokunulmamasi istenen kelimeler tek ogeli # tuple olarak yazilir, ("kelime",) gibi. eger degisim isteniyorsa # ("kelime","degisim") olarak bir tuple eklenir. r_list = [("verisi",),("Calculus",),("AIC",),("estimator",),(" ise",), ("kontur",),("ODE",),("Oklit",u'Öklit'),("karekok",u'karekök'), ("kismi", u'kısmi'),("integral",),("oldugu",u'olduğu'), ("acilimi",u'açılımı'),("acilim",u'açılım'),("aci",u'açı'), ("minimize",),("gayri",u'gayrı'),("Pandas",),("algoritma",), ("gayri",u'gayrı'),("sigma",),("volatility",),("matris",)] r_list_coded = [] for x in r_list: r_list_coded.append((x[0],str(int(random.random() * 1000000)))) for x in r_list_coded: content = content.replace(x[0],x[1]) result = to_tr(content) for x in r_list_coded: result = result.replace(x[1],x[0]) for x in r_list: if len(x)==2: result = result.replace(x[0],x[1]) lisp.delete_region(block_begin, block_end) lisp.insert(result) lisp.goto_char(remember_where)
def convert(): remember_where = lisp.point() block_begin, block_end, content = get_block_content("\n\n", "\n\n") # alttaki listeye dokunulmamasi istenen kelimeler tek ogeli # tuple olarak yazilir, ("kelime",) gibi. eger degisim isteniyorsa # ("kelime","degisim") olarak bir tuple eklenir. r_list = [("verisi", ), ("Calculus", ), ("AIC", ), ("estimator", ), (" ise", ), ("kontur", ), ("ODE", ), ("Oklit", u'Öklit'), ("karekok", u'karekök'), ("kismi", u'kısmi'), ("integral", ), ("oldugu", u'olduğu'), ("parcaci", u"parçacı"), ("acilimi", u'açılımı'), ("acilim", u'açılım'), ("acisini", u'açısını'), ("acisi", u'açısı'), ("aci", u'açı'), ("minimize", ), ("gayri", u'gayrı'), ("Pandas", ), ("algoritma", ), ("gayri", u'gayrı'), ("sigma", ), ("volatility", ), ("matris", ), ("frac", "frac"), ("sonum", u"sönüm"), ("eksen", ), ("sonusur", u"sonuşur"), ("amaci", u"amacı"), ("amacimiz", u"amacımız"), ("sarsim", u"sarsım"), ("Sarsim", u"Sarsım"), (u"olduğu", )] r_list_coded = [] for x in r_list: r_list_coded.append((x[0], str(int(random.random() * 1000000)))) for x in r_list_coded: content = content.replace(x[0], x[1]) result = to_tr(content) for x in r_list_coded: result = result.replace(x[1], x[0]) for x in r_list: if len(x) == 2: result = result.replace(x[0], x[1]) lisp.delete_region(block_begin, block_end) lisp.insert(result) lisp.goto_char(remember_where)
def get_block_content(start_tag, end_tag): remember_where = lisp.point() block_begin = lisp.search_backward(start_tag) block_end = lisp.search_forward(end_tag) block_end = lisp.search_forward(end_tag) content = lisp.buffer_substring(block_begin, block_end) lisp.goto_char(remember_where) return block_begin, block_end, content
def get_block_content(start_tag, end_tag): remember_where = lisp.point() block_begin = lisp.search_backward(start_tag) lisp.goto_char(remember_where) block_end = lisp.search_forward(end_tag) content = lisp.buffer_substring(block_begin, block_end) lisp.goto_char(remember_where) return block_begin, block_end, content
def thing_at_point(): right_set = left_set = set(['\n', ' ']) curridx = lisp.point() curr = '' while (curr in right_set) == False: curr = lisp.buffer_substring(curridx, curridx + 1) curridx += 1 start = curridx - 1 curridx = lisp.point() curr = '' while (curr in left_set) == False: curr = lisp.buffer_substring(curridx - 1, curridx) curridx -= 1 end = curridx + 1 s = lisp.buffer_substring(start, end) return s, end
def thing_at_point(): right_set = left_set = set(['\n',' ']) curridx = lisp.point() curr='' while (curr in right_set) == False: curr = lisp.buffer_substring(curridx, curridx+1) curridx += 1 start = curridx-1 curridx = lisp.point() curr='' while (curr in left_set) == False: curr = lisp.buffer_substring(curridx-1, curridx) curridx -= 1 end = curridx+1 s = lisp.buffer_substring(start, end) return s, end
def genall(): remem = lisp.point() lisp.beginning_of_buffer() res = True while res: res = lisp.re_search_forward("$$[[:ascii:][:nonascii:]]*?$$",None,lisp.t) lisp.backward_char(3) show() lisp.goto_char(remem)
def get_block_content(start_tag, end_tag): remember_where = lisp.point() block_end = lisp.search_forward(end_tag) block_begin = lisp.search_backward(start_tag) content = lisp.buffer_substring(block_begin, block_end) content = re.sub("\\\\begin{minted}.*?{python}","",content) content = re.sub("\\\\end{minted}","",content) lisp.goto_char(remember_where) return block_begin, block_end, content
def get_block_content(start_tag, end_tag): remember_where = lisp.point() block_end = lisp.search_forward(end_tag) block_begin = lisp.search_backward(start_tag) content = lisp.buffer_substring(block_begin, block_end) content = re.sub("\\\\begin{minted}.*?{python}", "", content) content = re.sub("\\\\end{minted}", "", content) lisp.goto_char(remember_where) return block_begin, block_end, content
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 show(): b,e,res = get_block_content("$$","$$") d = hash(res) foutsimple = "_preview/f-%d.png" % d if os.path.isfile(foutsimple): return # do nothing latex(res) curr_dir = os.path.dirname(lisp.buffer_file_name()) fout = "%s/_preview/f-%d.png" % (curr_dir,d) shutil.copy(dir + "\standalone.png",fout) remem = lisp.point() lisp.goto_char(e) lisp.forward_line(1) lisp.beginning_of_line(); bb = lisp.point() lisp.end_of_line(); ee = lisp.point() lisp.delete_region(bb,ee) lisp.insert("%{{" + foutsimple + "}}") lisp.goto_char(remem) lisp.iimage_mode(1)
def genall(): remem = lisp.point() lisp.beginning_of_buffer() res = True while res: res = lisp.re_search_forward("$$[[:ascii:][:nonascii:]]*?$$", None, lisp.t) lisp.backward_char(3) show() lisp.goto_char(remem)
def display_results(end_block, res): lisp.goto_char(end_block) lisp.forward_line(2) lisp.beginning_of_line() verb_line_b = lisp.point() lisp.end_of_line() verb_line_e = lisp.point() verb_line = lisp.buffer_substring(verb_line_b, verb_line_e) if "\\begin{verbatim}" in verb_line: verb_begin,verb_end,content = get_block_content("\\begin{verbatim}","\\end{verbatim}") lisp.delete_region(verb_begin, verb_end) lisp.goto_char(verb_begin) else: lisp.backward_line_nomark(1) lisp.insert("\n") res=res.replace("\r","") lisp.insert("\\begin{verbatim}\n") lisp.insert(res) lisp.insert("\\end{verbatim}")
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 pick_import(): ''' pick the whole line from the list of imports ''' print "in pick import" thing, start = thing_at_point_regex("\n", "\n") prev_buffer = os.environ['BUFFER'] print "-"+prev_buffer+"-" lisp.kill_buffer(lisp.get_buffer("*PyJde*")) lisp.switch_to_buffer(prev_buffer) remember_where = lisp.point() content = lisp.buffer_substring(1, lisp.point()) insert_where = re.search("package\s.*;", content).span()[1] lisp.goto_char(insert_where + 1) lisp.insert("\n\nimport " + thing + ";") lisp.message(thing + " is imported") lisp.goto_char(remember_where) lisp.delete_other_windows()
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 goto_definition(): """ go to definition/declaration of the pointer we are looking at """ fname=lisp.buffer_file_name() a = Project(fname) thing, start = thing_at_point(RIGHT1, LEFT1) lisp.message(thing) pos = lisp.point() type, pos = a.find_declaration_type(thing, fname, pos) lisp.goto_char(pos)
def insert_text(text,offset=0): """Insert text in buffer and move cursor to a certain offset. If called with no offset, leaves the cursor at the current position.""" # save undo state so we can roll everything into a single operation for undo checkpoint = lisp.buffer_undo_list.value() user_pos = lisp.point() lisp.insert(text) lisp.goto_char(user_pos+offset) # Collapse all operations into a single one, for Undo. clean_undo_after(checkpoint)
def insert_text(text, offset=0): """Insert text in buffer and move cursor to a certain offset. If called with no offset, leaves the cursor at the current position.""" # save undo state so we can roll everything into a single operation for undo checkpoint = lisp.buffer_undo_list.value() user_pos = lisp.point() lisp.insert(text) lisp.goto_char(user_pos + offset) # Collapse all operations into a single one, for Undo. clean_undo_after(checkpoint)
def show(): b, e, res = get_block_content("$$", "$$") d = hash(res) foutsimple = "_preview/f-%d.png" % d if os.path.isfile(foutsimple): return # do nothing latex(res) curr_dir = os.path.dirname(lisp.buffer_file_name()) fout = "%s/_preview/f-%d.png" % (curr_dir, d) shutil.copy(dir + "\standalone.png", fout) remem = lisp.point() lisp.goto_char(e) lisp.forward_line(1) lisp.beginning_of_line() bb = lisp.point() lisp.end_of_line() ee = lisp.point() lisp.delete_region(bb, ee) lisp.insert("%{{" + foutsimple + "}}") lisp.goto_char(remem) lisp.iimage_mode(1)
def thing_at_point(right_set, left_set): """ Mine is a lot better than the emacs thingy which does not 'get' types with generics """ curridx = lisp.point() curr='' while (curr in right_set) == False: curr = lisp.buffer_substring(curridx, curridx+1) curridx += 1 start = curridx-1 curridx = lisp.point() curr='' while (curr in left_set) == False: curr = lisp.buffer_substring(curridx-1, curridx) curridx -= 1 end = curridx+1 s = lisp.buffer_substring(start, end) return s, end
def thing_at_point_regex(right, left): """ Mine is a lot better than the emacs thingy which does not 'get' types with generics """ curridx = lisp.point() curr='' while (re.search(right, curr) ) == None: curr = lisp.buffer_substring(curridx, curridx+1) curridx += 1 start = curridx-1 curridx = lisp.point() curr='' while (re.search(left, curr) ) == None: curr = lisp.buffer_substring(curridx-1, curridx) curridx -= 1 end = curridx+1 s = lisp.buffer_substring(start, end) return s, end
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 pick_method(): ''' pick the whole line from the list of function calls (completions) ''' print "in pick method" thing, start = thing_at_point(RIGHT2, LEFT2) prev_buffer = os.environ['BUFFER'] print "-"+prev_buffer+"-" lisp.kill_buffer(lisp.get_buffer("*PyJde*")) lisp.switch_to_buffer(prev_buffer) lisp.insert(thing) pos = lisp.point() print "pos="+(str(pos-1)) lisp.goto_char(pos-1) lisp.delete_other_windows()
def put_import (fname, imp): print "in put_import" print fname print imp content = lisp.buffer_substring(1, lisp.point()) print content for m in re.finditer("(import\s.*?);", content): print "mgroup="+m.group(1) print imp if (re.search(imp, m.group(1))): lisp.message("Already imported") return insert_where = re.search("import\s.*;", content).span()[1] lisp.goto_char(insert_where + 1) lisp.insert("\nimport " + imp + ";")
def promptCallback(filename, line, colbegin, colend): let = Let().push_excursion() # gets popped when let goes out of scope buffer = lisp.current_buffer() if let: ans = 0 lisp.find_file(filename) lisp.goto_line(line) lisp.move_to_column(colbegin) lisp.set_mark(lisp.point() + (colend - colbegin)) if is_xemacs: lisp.activate_region() ans = lisp.y_or_n_p( "Couldn't deduce object type - rename this method reference? ") del let lisp.switch_to_buffer(buffer) return ans
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 insert_indented_text(text, offset): """Insert indented text in buffer and move cursor to a certain offset.""" # save undo state so we can roll everything into a single operation for undo checkpoint = lisp.buffer_undo_list.value() # figure out if we are indented or not, and adapt text accordingly indent_level = get_line_offset() if indent_level > 0: text = indent(text, indent_level) # perform actual insertion with proper cursor positioning offset += indent_level lisp.beginning_of_line() user_pos = lisp.point() lisp.insert(text) lisp.goto_char(user_pos + offset) # Collapse all operations into a single one, for Undo. clean_undo_after(checkpoint)
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 cursor_line_number(): point = lisp.point() line = lisp.count_lines(1, point + 1) return line new_var_info = "" infos = eval(var_info.split("\n")[1]) for time, info in infos: new_var_info += "Executed at %ss\n" % time context = [] for k, v in info.iteritems(): context += [(k, v)] context.sort(key=lambda x: -x[1][0]) for k, info in context: new_var_info += " %s => %s\n" % (k, info[1])