Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
 def filenames(self):
     result = []
     for buffer in lisp.buffer_list():
         filename = lisp.buffer_file_name(buffer)
         if filename:
             result.append(filename)
     return result
Ejemplo n.º 3
0
 def inline_local_variable(self):
     lisp.save_some_buffers()
     filename = lisp.buffer_file_name()
     line, col = _getCoords()
     brmctx.inlineLocalVariable(filename, line, col)
     lisp.set_marker(lisp.mark_marker(), None)
     _revertSavedFiles(brmctx.save())
Ejemplo n.º 4
0
def new_from_buffer(buffer, language):
    """Pastes the contents of buffer"""
    lisp.set_buffer(buffer)
    code = unicode(lisp.buffer_string())
    #code = lisp.buffer_substring(lisp.point_min(), lisp.point_max())
    filename = lisp.buffer_file_name()
    new_paste(code, language, filename=filename)
Ejemplo n.º 5
0
 def inline_local_variable(self):
     lisp.save_some_buffers()
     filename = lisp.buffer_file_name()
     line,col = _getCoords()
     brmctx.inlineLocalVariable(filename,line,col)
     lisp.set_marker(lisp.mark_marker(),None)
     _revertSavedFiles(brmctx.save())
Ejemplo n.º 6
0
 def _get_resource(self, filename=None):
     if filename is None:
         filename = lisp.buffer_file_name()
     if filename is None:
         return
     resource = libutils.path_to_resource(self.project, filename, 'file')
     return resource
Ejemplo n.º 7
0
def show_version(num):
    print "Getting this version ago:" + str(num)
    curr_dir = os.getcwd()
    dot_git_dir = find_dot_git()    
    os.chdir(dot_git_dir)
    
    fname=lisp.buffer_file_name()
    
    # subtract the .git location from the beginning part of the 
    # full path because git show does not like it
    suitable_dir_for_git_show = re.sub(dot_git_dir, "", fname)

    # also get rid of the first / 
    suitable_dir_for_git_show = re.sub("^/", "", suitable_dir_for_git_show)

    os.chdir(os.path.dirname(suitable_dir_for_git_show))
    cmd = "git show %s~%d:%s > %s/githist-%d.dat" % (branch(),
                                                     num,
                                                     os.path.basename(suitable_dir_for_git_show),
                                                     os.environ['TEMP'],
                                                     num)
    res = run_command(cmd)
    #lisp.switch_to_buffer_other_window(cmd)
    lisp.find_file_other_window("%s/githist-%d.dat" % (os.environ['TEMP'],num))
    os.chdir(curr_dir)
def run_file():
    path = lisp.buffer_file_name()
    if path is None:
        # TODO Complain in message bar
        pass
    else:
        client.run_file(path)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
def show_version(num):
    print "Getting this version ago:" + str(num)
    dot_git_dir = find_dot_git()
    os.chdir(dot_git_dir)

    fname = lisp.buffer_file_name()

    # subtract the .git location from the beginning part of the
    # full path because git show does not like it
    print "fname=" + fname
    print "dot_git_dir=" + dot_git_dir
    suitable_dir_for_git_show = re.sub(dot_git_dir, "", fname)
    print suitable_dir_for_git_show

    # also get rid of the first /
    suitable_dir_for_git_show = re.sub("^/", "", suitable_dir_for_git_show)
    print suitable_dir_for_git_show

    cmd = "git show master~" + str(num) + ":" + suitable_dir_for_git_show
    print cmd

    list = run_command(cmd)

    lisp.switch_to_buffer_other_window(cmd)
    for item in list:
        lisp.insert(item)
Ejemplo n.º 11
0
def new_from_buffer(buffer, language):
    """Pastes the contents of buffer"""
    lisp.set_buffer(buffer)
    code = unicode(lisp.buffer_string())
    #code = lisp.buffer_substring(lisp.point_min(), lisp.point_max())
    filename = lisp.buffer_file_name()
    new_paste(code, language, filename=filename)
Ejemplo n.º 12
0
def show_version(num):
    print "Getting this version ago:" + str(num)
    curr_dir = os.getcwd()
    dot_git_dir = find_dot_git()
    os.chdir(dot_git_dir)

    fname = lisp.buffer_file_name()
    fdir = os.path.dirname(fname)

    # subtract the .git location from the beginning part of the
    # full path because git show does not like it
    suitable_file_for_git_show = re.sub(dot_git_dir, "", fname)

    # also get rid of the first /
    dot_git_dir = dot_git_dir.replace("\\", "/")
    print dot_git_dir
    print "suitable_file_for_git_show", suitable_file_for_git_show
    suitable_file_for_git_show = suitable_file_for_git_show.replace(
        dot_git_dir, "")
    print "suitable_file_for_git_show", suitable_file_for_git_show
    tmp = '/tmp'
    if 'TEMP' in os.environ: tmp = os.environ['TEMP']
    os.chdir(dot_git_dir)
    cmd = "git show %s~%d:%s > %s/githist-%d.dat" % (
        branch(), num, suitable_file_for_git_show[1:], tmp, num)
    res = run_command(cmd)
    #lisp.switch_to_buffer_other_window(cmd)
    lisp.find_file_other_window("%s/githist-%d.dat" % (tmp, num))
    os.chdir(curr_dir)
Ejemplo n.º 13
0
def run_file():
    path = lisp.buffer_file_name()
    if path is None:
        # TODO Complain in message bar
        pass
    else:
        client.run_file(path)
Ejemplo n.º 14
0
def show_version(num):
    print "Getting this version ago:" + str(num)
    dot_git_dir = find_dot_git()
    os.chdir(dot_git_dir)
    
    fname=lisp.buffer_file_name()
    
    # subtract the .git location from the beginning part of the 
    # full path because git show does not like it
    print "fname="+fname
    print "dot_git_dir="+dot_git_dir
    suitable_dir_for_git_show = re.sub(dot_git_dir, "", fname)
    print suitable_dir_for_git_show

    # also get rid of the first / 
    suitable_dir_for_git_show = re.sub("^/", "", suitable_dir_for_git_show)
    print suitable_dir_for_git_show
    
    cmd = "git show master~" + str(num) + ":" + suitable_dir_for_git_show
    print cmd
    
    list = run_command(cmd)
    
    lisp.switch_to_buffer_other_window(cmd)
    for item in list:
        lisp.insert(item)
Ejemplo n.º 15
0
 def filenames(self):
     result = []
     for buffer in lisp.buffer_list():
         filename = lisp.buffer_file_name(buffer)
         if filename:
             result.append(filename)
     return result
Ejemplo n.º 16
0
def show_version(num):
    print "Getting this version ago:" + str(num)
    curr_dir = os.getcwd()
    dot_git_dir = find_dot_git()
    os.chdir(dot_git_dir)

    fname = lisp.buffer_file_name()
    fdir = os.path.dirname(fname)

    # subtract the .git location from the beginning part of the
    # full path because git show does not like it
    suitable_file_for_git_show = re.sub(dot_git_dir, "", fname)

    # also get rid of the first /
    dot_git_dir = dot_git_dir.replace("\\", "/")
    print dot_git_dir
    print "suitable_file_for_git_show", suitable_file_for_git_show
    suitable_file_for_git_show = suitable_file_for_git_show.replace(dot_git_dir, "")
    print "suitable_file_for_git_show", suitable_file_for_git_show
    tmp = "/tmp"
    if "TEMP" in os.environ:
        tmp = os.environ["TEMP"]
    os.chdir(dot_git_dir)
    cmd = "git show %s~%d:%s > %s/githist-%d.dat" % (branch(), num, suitable_file_for_git_show[1:], tmp, num)
    res = run_command(cmd)
    # lisp.switch_to_buffer_other_window(cmd)
    lisp.find_file_other_window("%s/githist-%d.dat" % (tmp, num))
    os.chdir(curr_dir)
Ejemplo n.º 17
0
 def before_save_actions(self):
     if self.project is not None:
         if not self._is_python_file(lisp.buffer_file_name()):
             return
         resource = self._get_resource()
         if resource.exists():
             self.old_content = resource.read()
         else:
             self.old_content = ''
Ejemplo n.º 18
0
def find_file_at_symbol():
    """
    finds file at point
    """
    fname=lisp.buffer_file_name()
    a = Project(fname)
    thing, start = thing_at_point(RIGHT1, LEFT1)
    file = a.find_file_for_thing(thing, fname)    
    lisp.message(file)
    lisp.find_file(file)
Ejemplo n.º 19
0
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)
Ejemplo n.º 20
0
 def find_references(self):
     lisp.save_some_buffers()
     filename = lisp.buffer_file_name()
     line, col = _getCoords()
     refs = brmctx.findReferencesByCoordinates(filename, line, col)
     _switchToConsole()
     numRefs = 0
     for ref in refs:
         _insertRefLineIntoConsole(ref)
         numRefs += 1
     lisp.insert("Done - %d refs found\n" % numRefs)
Ejemplo n.º 21
0
 def find_references(self):
     lisp.save_some_buffers()
     filename = lisp.buffer_file_name()
     line,col = _getCoords()
     refs = brmctx.findReferencesByCoordinates(filename,line,col)
     _switchToConsole()
     numRefs = 0
     for ref in refs:
         _insertRefLineIntoConsole(ref)
         numRefs +=1
     lisp.insert("Done - %d refs found\n"%numRefs)
Ejemplo n.º 22
0
 def rename(self, newname):
     lisp.save_some_buffers()
     filename = lisp.buffer_file_name()
     line, col = _getCoords()
     brmctx.setRenameMethodPromptCallback(promptCallback)
     try:
         self.ctx.renameByCoordinates(filename, line, col, newname)
         savedFiles = brmctx.save()
         _revertSavedFiles(savedFiles)
         lisp.set_marker(lisp.mark_marker(), None)
     except bikefacade.CouldntLocateASTNodeFromCoordinatesException:
         print >> logger, "Couldn't find AST Node. Are you renaming the declaration?"
Ejemplo n.º 23
0
    def extract_method(self,name):
        lisp.save_some_buffers()
        filename = lisp.buffer_file_name()

        bline,bcol = _getPointCoords()
        lisp.exchange_point_and_mark()
        eline,ecol = _getPointCoords()
        lisp.exchange_point_and_mark()

        brmctx.extract(filename,bline,bcol,eline,ecol,name)
        lisp.set_marker(lisp.mark_marker(),None)
        _revertSavedFiles(brmctx.save())
Ejemplo n.º 24
0
    def extract_method(self, name):
        lisp.save_some_buffers()
        filename = lisp.buffer_file_name()

        bline, bcol = _getPointCoords()
        lisp.exchange_point_and_mark()
        eline, ecol = _getPointCoords()
        lisp.exchange_point_and_mark()

        brmctx.extract(filename, bline, bcol, eline, ecol, name)
        lisp.set_marker(lisp.mark_marker(), None)
        _revertSavedFiles(brmctx.save())
Ejemplo n.º 25
0
 def rename(self,newname):
     lisp.save_some_buffers()
     filename = lisp.buffer_file_name()
     line,col = _getCoords()
     brmctx.setRenameMethodPromptCallback(promptCallback)
     try:
         self.ctx.renameByCoordinates(filename,line,col,newname)
         savedFiles = brmctx.save()
         _revertSavedFiles(savedFiles)
         lisp.set_marker(lisp.mark_marker(),None)
     except bikefacade.CouldntLocateASTNodeFromCoordinatesException:
         print >>logger,"Couldn't find AST Node. Are you renaming the declaration?"
Ejemplo n.º 26
0
def find_descendants(): 
    """
    retrieves descendants of class at point by running a Unix find. 
    simple huh?
    """
    fname=lisp.buffer_file_name()
    a = Project(fname)
    thing, start = thing_at_point(RIGHT1, LEFT1)
    descs = a.find_all_descendants(thing)
    ready_output()
    
    for item in descs:
        lisp.insert(item)
Ejemplo n.º 27
0
def find_dot_git():
    fname = lisp.buffer_file_name()
    dirname = re.sub("\/\w*?\.*\w*?$", "", fname)
    print "Dir:" + dirname

    found = False
    os.chdir(dirname)
    while (True):
        dirname = os.getcwd()
        print "Trying " + dirname + "/.git"
        if (os.path.isdir(dirname + "/.git")): return dirname
        if (os.getcwd() == "/"):
            raise Exception("no .git found")
        os.chdir(os.pardir)
Ejemplo n.º 28
0
def find_dot_git() :     
    fname=lisp.buffer_file_name()
    dirname = re.sub("\/\w*?\.*\w*?$", "", fname)
    print "Dir:"+dirname

    found = False
    os.chdir(dirname)
    while (True) :
        dirname = os.getcwd()
        print "Trying " + dirname + "/.git"
        if (os.path.isdir(dirname + "/.git")): return dirname
        if (os.getcwd() == "/"): 
            raise Exception("no .git found")
        os.chdir(os.pardir) 
Ejemplo n.º 29
0
def get_module_name_if_python_file_handle():
    fname = lisp.buffer_file_name()
    if fname == None:
        return None
    # check it:
    if fname[-3:] == ".py" and (fname.endswith("pymacs.py") == False):
        # Ok, we have got something to do:
        # replace last / with a point and try it down:
        i = fname.rfind("/")
        pk = fname[:i] + "." + fname[i + 1 : -3]
        # debug("Reloading "+pk)
        return pk
    else:
        # say(" Nothing to do for:"+fname)
        return None
Ejemplo n.º 30
0
def get_module_name_if_python_file_handle():
    fname=lisp.buffer_file_name()
    if fname==None:
        return None
    # check it:
    if fname[-3:] == '.py' and not fname.endswith("Pymacs.py")):
        # Ok, we have got something to do:
        # replace last / with a point and try it down:
        i=fname.rfind("/")
        pk=fname[:i]+"."+fname[i+1:-3]
        #debug("Reloading "+pk)
        return pk
    else:
        #say(" Nothing to do for:"+fname)
        return None
Ejemplo n.º 31
0
def update_state():
    """
    Updates the current state by looking for included files and parsing them
    """
    lisp.message("Loading... this might take a while.")
    this_text = lisp.buffer_string()
    cwd = os.path.dirname(lisp.buffer_file_name())
    includes = []
    j = cwd
    while j!="/":
        p = os.path.join(j,".lemacs")
        if os.path.isfile(p):
            includes+=parse_lemacs(p)['include']
        j = os.path.join(os.path.split(j)[:-1])[0]
    cpp.parse_from_includes(this_text,cwd = cwd,inclDIRS = includes)
    lisp.message("Loaded auto-completion data!")
Ejemplo n.º 32
0
 def _save_buffers(self, only_current=False):
     ask = lisp['ropemacs-confirm-saving'].value()
     initial = lisp.current_buffer()
     current_buffer = lisp.current_buffer()
     if only_current:
         buffers = [current_buffer]
     else:
         buffers = lisp.buffer_list()
     for buffer in buffers:
         filename = lisp.buffer_file_name(buffer)
         if filename:
             if self._is_python_file(filename) and \
                lisp.buffer_modified_p(buffer):
                 if not ask or lisp.y_or_n_p('Save %s buffer?' % filename):
                     lisp.set_buffer(buffer)
                     lisp.save_buffer()
     lisp.set_buffer(initial)
Ejemplo n.º 33
0
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)
Ejemplo n.º 34
0
def new(language, region_start=None, region_end=None):
    """
    Create a new paste.  Use the given (programming) ``language`` for server
    side highlighting.

    If ``region_start`` and ``region_end`` are given, create a paste with
    the contents of this region.

    When called interactively with transient mark mode enabled and an active
    mark, create a paste with the contents of the region.  Otherwise create
    a paste with the contents of the whole buffer.
    """

    lodgeit = lodgeIt()

    mark_active = lisp.mark_active.value()
    transient_mark_mode = lisp.transient_mark_mode.value()
    if lisp.interactive and  transient_mark_mode and mark_active:
        # use a region, if we have one
        region_start = lisp.region_beginning()
        region_end = lisp.region_end()
    elif region_start:
        # otherwise use the given arguments
        region_start = min(region_start, region_end)
        region_end = max(region_start, region_end)
    else:
        # as last resort, paste the whole buffer
        region_start = lisp.point_min_marker()
        region_end = lisp.point_max_marker()

    code = unicode(lisp.buffer_substring(region_start, region_end))
    filename = lisp.buffer_file_name()

    lisp.message('Transferring paste to server...')
    paste_id = lodgeit.new_paste(code, language, filename=filename)
    paste = lodgeit.get_paste_by_id(paste_id)
    lisp.message(
        'New paste with ID {0.id} created. Refer to {0.url}'.format(paste))
    if lisp.paste_kill_url.value():
        lisp.kill_new(paste.url)
    if lisp.paste_show_in_browser.value():
        lisp.browse_url(paste.url)
Ejemplo n.º 35
0
def show_version(num):
    print "Getting this version ago:" + str(num)
    dot_git_dir = find_dot_git()
    os.chdir(dot_git_dir)

    fname = lisp.buffer_file_name()

    # subtract the .git location from the beginning part of the
    # full path because git show does not like it
    suitable_dir_for_git_show = re.sub(dot_git_dir, "", fname)

    # also get rid of the first /
    suitable_dir_for_git_show = re.sub("^/", "", suitable_dir_for_git_show)

    cmd = "git show %s~%d:%s" % (branch(), num, suitable_dir_for_git_show)

    res = run_command(cmd)
    lisp.switch_to_buffer_other_window(cmd)
    for item in res:
        lisp.insert(item)
Ejemplo n.º 36
0
Archivo: githist.py Proyecto: ing7t/kod
def show_version(num):
    print "Getting this version ago:" + str(num)
    dot_git_dir = find_dot_git()
    os.chdir(dot_git_dir)

    fname = lisp.buffer_file_name()

    # subtract the .git location from the beginning part of the
    # full path because git show does not like it
    suitable_dir_for_git_show = re.sub(dot_git_dir, "", fname)

    # also get rid of the first /
    suitable_dir_for_git_show = re.sub("^/", "", suitable_dir_for_git_show)

    cmd = "git show %s~%d:%s" % (branch(), num, suitable_dir_for_git_show)

    res = run_command(cmd)
    lisp.switch_to_buffer_other_window(cmd)
    for item in res:
        lisp.insert(item)
Ejemplo n.º 37
0
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)
Ejemplo n.º 38
0
    def find_definition(self):
        lisp.save_some_buffers()
        filename = lisp.buffer_file_name()
        line, col = _getCoords()
        defns = brmctx.findDefinitionByCoordinates(filename, line, col)

        try:
            firstdefn = defns.next()
            lisp.find_file_other_window(firstdefn.filename)
            lisp.goto_line(firstdefn.lineno)
            lisp.forward_char(firstdefn.colno)
        except StopIteration:
            pass
        else:
            numRefs = 1
            for defn in defns:
                if numRefs == 1:
                    _switchToConsole()
                    _insertRefLineIntoConsole(firstdefn)
                _insertRefLineIntoConsole(defn)
                numRefs += 1
Ejemplo n.º 39
0
    def find_definition(self):
        lisp.save_some_buffers()
        filename = lisp.buffer_file_name()
        line,col = _getCoords()
        defns = brmctx.findDefinitionByCoordinates(filename,line,col)

        try:
            firstdefn = defns.next()
            lisp.find_file_other_window(firstdefn.filename)
            lisp.goto_line(firstdefn.lineno)
            lisp.forward_char(firstdefn.colno)
        except StopIteration:
            pass
        else:
            numRefs = 1
            for defn in defns:
                if numRefs == 1:
                    _switchToConsole()
                    _insertRefLineIntoConsole(firstdefn)
                _insertRefLineIntoConsole(defn)
                numRefs += 1
Ejemplo n.º 40
0
def qualified_module_name(buffer=None):
    """
    Determine the qualified name of the python module which is currently
    edited in the given ``buffer``.  If unset, ``buffer`` defaults to the
    current buffer.

    If the buffer has no associated filename, this function returns None.
    """
    if not buffer:
        buffer = lisp.current_buffer()
    if isinstance(buffer, basestring):
        buffer = lisp.get_buffer(buffer)
        if buffer is None:
            lisp.error('No such buffer: %s', buffername)
    filename = lisp.buffer_file_name(buffer)
    if filename is None:
        return None

    filepath = os.path.normpath(os.path.abspath(filename))
    modules = []
    modname = os.path.basename(os.path.splitext(filepath)[0])
    if modname != '__init__':
        modules.append(modname)

    directory = os.path.dirname(filepath)
    parent = os.path.dirname(directory)
    while directory != parent:
        if not is_package(directory):
            break
        pkgname = os.path.basename(directory)
        modules.append(pkgname)
        directory = parent
        parent = os.path.dirname(directory)

    modules.reverse()
    return '.'.join(modules)
Ejemplo n.º 41
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))
Ejemplo n.º 42
0
BUFFER_NAME = "*jarvis_inspect*"

VAR_KEY = "inspect_vars_timer_installed"

if 'arg' in globals():
    from Pymacs import lisp
    import jarvis.emacs.utils as utils
    import jarvis.commands
    reload(utils)

    # 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()
Ejemplo n.º 43
0
 def filename(self):
     return lisp.buffer_file_name()
Ejemplo n.º 44
0
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")
Ejemplo n.º 45
0
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")
Ejemplo n.º 46
0
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")
Ejemplo n.º 47
0
 def __init__(self):
     self.bufferName = lisp.buffer_name()
     self.fname = lisp.buffer_file_name()
Ejemplo n.º 48
0
 def __init__(self):
     self.bufferName=lisp.buffer_name()
     self.fname=lisp.buffer_file_name()
Ejemplo n.º 49
0
 def move_class(self, newfilename):
     lisp.save_some_buffers()
     filename = lisp.buffer_file_name()
     line, col = _getCoords()
     brmctx.moveClassToNewModule(filename, line, newfilename)
     _revertSavedFiles(brmctx.save())
Ejemplo n.º 50
0
 def filename(self):
     return lisp.buffer_file_name()
Ejemplo n.º 51
0
def new_from_region(start, end, language):
    """Pastes the current selection"""
    code = unicode(lisp.buffer_substring(start, end))
    filename = lisp.buffer_file_name()
    new_paste(code, language, filename=filename)