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 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 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 _hide_buffer(self, name, delete=True): buffer = lisp.get_buffer(name) if buffer is not None: window = lisp.get_buffer_window(buffer) if window is not None: lisp.bury_buffer(buffer) if delete: lisp.delete_window(window) else: if lisp.buffer_name(lisp.current_buffer()) == name: lisp.switch_to_buffer(None)
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 complete_py(): thing, start = thing_at_point() lisp.message(thing) (kc,kernel,ip) = get_kernel_pointer(lisp.buffer_name()) text, matches = ip.complete(thing) lisp.switch_to_buffer("*pytexipy*") lisp.kill_buffer(lisp.get_buffer("*pytexipy*")) lisp.switch_to_buffer_other_window("*pytexipy*") lisp.insert(thing) for item in matches: lisp.insert(item) lisp.insert("\n")
# Retrieve current buffer file name filename = lisp.buffer_file_name() # Sample code : break on whitespace line = utils.cursor_line_number() # The +1 is because we prefer to have the result of an assignation when the cursor is on it, not one line later. var_info = jarvis.commands.external_inspect_vars(filename, line + 1) var_info = utils.inspect_format(var_info) found = False for window in lisp.window_list(): buffer = lisp.window_buffer(window) if lisp.buffer_name(buffer) == BUFFER_NAME: found = True buffer = lisp.get_buffer_create(BUFFER_NAME) lisp.set_buffer(buffer) lisp.erase_buffer() lisp.insert(str(var_info)) if not found: lisp.split_window_vertically(-10) lisp.other_window(1) lisp.switch_to_buffer(buffer) lisp.goto_line(1) lisp.other_window(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 if "\\inputminted" in line: block_begin = lisp.point() lisp.message(line) py_file = re.search("\{python\}\{(.*?)\}", line).groups(1)[0] # get code content from file curr_dir = os.path.dirname(lisp.buffer_file_name()) content = open(curr_dir + "/" + py_file).read() block_end = l2 # end of block happens to be end of include file line lisp.goto_char(remember_where) else: # get code content from latex block_begin,block_end,content = get_block_content("\\begin{minted}","\\end{minted}") # 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 = get_buffer_content_prev(block_begin) 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.hold(False)\nplt.savefig('%s')\nplt.hold(False)" % f show_replaced = True if "plt.show()" in content else False content=content.replace("plt.show()",rpl) include_graphics_command = "\\includegraphics[height=6cm]{%s}" % f #(ip) = get_kernel_pointer(lisp.buffer_name()) start = time.time() with capture_output() as io: res_code = ip.run_cell(content) res = io.stdout elapsed = (time.time() - start) display_results(block_end, res) # display it # generate includegraphics command if show_replaced: lisp.forward_line(2) # skip over end verbatim, leave one line emtpy lisp.insert(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) if "plt.savefig" in content: lisp.preview_buffer() lisp.message("Ran in " + str(elapsed) + " seconds")
# Retrieve current buffer file name filename = lisp.buffer_file_name() # Sample code : break on whitespace line = utils.cursor_line_number() # The +1 is because we prefer to have the result of an assignation when the cursor is on it, not one line later. var_info = jarvis.commands.external_inspect_vars(filename, line + 1) var_info = utils.inspect_format(var_info) found = False for window in lisp.window_list(): buffer = lisp.window_buffer(window) if lisp.buffer_name(buffer) == BUFFER_NAME: found = True buffer = lisp.get_buffer_create(BUFFER_NAME) lisp.set_buffer(buffer) lisp.erase_buffer() lisp.insert(str(var_info)) if not found: lisp.split_window_vertically(-10) lisp.other_window(1) lisp.switch_to_buffer(buffer) lisp.goto_line(1) lisp.other_window(1) # if not timer_installed:
def __init__(self): self.bufferName = lisp.buffer_name() self.fname = lisp.buffer_file_name()
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 if "\\inputminted" in line: lisp.message(line) py_file = re.search("\{python\}\{(.*?)\}", line).groups(1)[0] # get code content from file curr_dir = os.path.dirname(lisp.buffer_file_name()) content = open(curr_dir + "/" + py_file).read() block_end = l2 # end of block happens to be end of include file line lisp.goto_char(remember_where) else: # get code content from latex block_begin, block_end, content = get_block_content( "\\begin{minted}", "\\end{minted}") #lisp.message(content) # 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 = get_buffer_content_prev(block_begin) 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) include_graphics_command = "\\includegraphics[height=6cm]{%s}" % f (kc, kernel, ip) = get_kernel_pointer(lisp.buffer_name()) start = time.time() res = '' with capture_output() as io: ip.run_cell(content) res = io.stdout if kernel.shell.last_known_outflag: etype, value, tb = kernel.shell._get_exc_info() res = str(etype) + " " + str(value) + "\n" elapsed = (time.time() - start) # replace this unnecessary message so output becomes blank if res and len(res) > 0: # if result not empty res = res.replace( "Populating the interactive namespace from numpy and matplotlib\n", "") display_results(block_end, res) # display it else: display_results(block_end, "") lisp.goto_char(block_end) # generate includegraphics command if show_replaced: lisp.forward_line(2) # skip over end verbatim, leave one line emtpy lisp.insert(include_graphics_command + '\n') lisp.backward_line_nomark( 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) if "plt.savefig" in content: lisp.preview_buffer() lisp.message("Ran in " + str(elapsed) + " seconds")
def __init__(self): self.bufferName=lisp.buffer_name() self.fname=lisp.buffer_file_name()
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 if "\\inputminted" in line: block_begin = lisp.point() lisp.message(line) py_file = re.search("\{python\}\{(.*?)\}", line).groups(1)[0] # get code content from file curr_dir = os.path.dirname(lisp.buffer_file_name()) content = open(curr_dir + "/" + py_file).read() block_end = l2 # end of block happens to be end of include file line lisp.goto_char(remember_where) else: # get code content from latex block_begin, block_end, content = get_block_content( "\\begin{minted}", "\\end{minted}") # 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 = "\\includegraphics[height=6cm]{%s}" % f #(ip) = get_kernel_pointer(lisp.buffer_name()) start = time.time() with capture_output() as io: res_code = get_ip().run_cell(content) res = io.stdout elapsed = (time.time() - start) display_results(block_end, res) # display it # generate includegraphics command if show_replaced: lisp.forward_line(2) # skip over end verbatim, leave one line emtpy lisp.insert(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) if "plt.savefig" in content: lisp.preview_buffer() lisp.message("Ran in " + str(elapsed) + " seconds")
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) block_begin,block_end,content = get_block_content("```python","```") #lisp.message(content) # 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 = get_buffer_content_prev(block_begin) 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) include_graphics_command = "![](%s)" % f (kc,kernel,ip) = get_kernel_pointer(lisp.buffer_name()) start = time.time() res = '' with capture_output() as io: ip.run_cell(content) res = io.stdout if kernel.shell.last_known_outflag: etype, value, tb = kernel.shell._get_exc_info() res = str(etype) + " " + str(value) + "\n" elapsed = (time.time() - start) # replace this unnecessary message so output becomes blank if res and len(res) > 0: # if result not empty res = res.replace("Populating the interactive namespace from numpy and matplotlib\n","") display_results(block_end, res) # display it else: display_results(block_end, "") lisp.goto_char(block_end) # generate includegraphics command if show_replaced: lisp.forward_line(2) # skip over end verbatim, leave one line emtpy lisp.insert(include_graphics_command + '\n') #lisp.backward_line_nomark(1) # skip over end verbatim, leave one line emtpy 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) if "plt.savefig" in content: lisp.preview_buffer() lisp.message("Ran in " + str(elapsed) + " seconds")