Ticket #11235: IPython-edit.patch.patch

File IPython-edit.patch.patch, 1.8 KB (added by mderickx, 10 years ago)
  • sage/misc/edit_module.py

    # HG changeset patch
    # User Maarten Derickx <m.derickx.student@gmail.com>
    # Date 1303424572 -7200
    # Node ID d5d8c45ab0f1ca3321a7e43e493a0519e3209f89
    # Parent  df5620969fbddef0cf191407d046c2ed522d6a49
    #11235 make the magic ipython %edit edit the version controlled source files
    
    diff --git a/sage/misc/edit_module.py b/sage/misc/edit_module.py
    a b  
    4444import sage.misc.sageinspect
    4545import inspect
    4646import os
     47import re
     48import IPython
    4749
    4850from string import Template
    4951
     
    118120   sageroot = sage.misc.sageinspect.SAGE_ROOT+'/'
    119121   runpathpattern = '^'+sageroot+'local/lib/python[^/]*/site-packages'
    120122   develbranch = sageroot+'devel/sage'
    121    import re
    122123   filename=re.sub(runpathpattern,develbranch,filename)
    123124
    124125   return filename, lineno+1
     
    280281      cmd=cmd[:-1]
    281282     
    282283   os.system(cmd)
     284
     285
     286def edit_devel(self, filename, linenum):
     287    """
     288    This hook calls the default implementation but with a diffrent filename.
     289
     290    If the filename begins with SAGE_ROOT/local/lib/python2.6/site-packages/
     291    it replaces this by SAGE_ROOT/devel/sage
     292
     293    This function is called by IPython when you do either:
     294
     295    sage: %edit gcd         # not tested
     296    sage: %ed gcd           # not tested
     297
     298    The above should open your favorite editor (as stored in the environment
     299    variable $EDITOR) with the file in witch gcd is defined, and when your
     300    editor supports it, also at the line in wich gcd is defined.
     301    """
     302    sageroot = sage.misc.sageinspect.SAGE_ROOT+'/'
     303    runpathpattern = '^'+sageroot+'local/lib/python[^/]*/site-packages'
     304    develbranch = sageroot+'devel/sage'
     305    filename=re.sub(runpathpattern,develbranch,filename)
     306    IPython.hooks.editor(self, filename, linenum)
     307
     308ip = IPython.ipapi.get()
     309if ip:
     310    ip.set_hook('editor', edit_devel)
     311
     312