Ticket #11235: IPython-edit.patch

File IPython-edit.patch, 1.5 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 5e61674c552d71bfe4d24caf5d09b70a230ddd06
    # Parent  6c09423456c9f0ad326ce470f7c4e0aec5049bcf
    #11235 make the magic ipython %edit edit the version controlled source files
    
    diff -r 6c09423456c9 -r 5e61674c552d sage/misc/edit_module.py
    a b  
    4040import inspect
    4141import os
    4242import sys
     43import re
     44import IPython
    4345
    4446from string import Template
    4547
     
    100102   sageroot = sage.misc.sageinspect.SAGE_ROOT+'/'
    101103   runpathpattern = '^'+sageroot+'local/lib/python[^/]*/site-packages'
    102104   develbranch = sageroot+'devel/sage'
    103    import re
    104105   filename=re.sub(runpathpattern,develbranch,filename)
    105106
    106107   return filename, lineno+1
     
    253254      cmd=cmd[:-1]
    254255     
    255256   os.system(cmd)
     257
     258
     259def edit_devel(self, filename, linenum):
     260    """
     261    This hook calls the default implementation but with a diffrent filename.
     262
     263    If the filename begins with SAGE_ROOT/local/lib/python2.6/site-packages/
     264    it replaces this by SAGE_ROOT/devel/sage
     265    """
     266    sageroot = sage.misc.sageinspect.SAGE_ROOT+'/'
     267    runpathpattern = '^'+sageroot+'local/lib/python[^/]*/site-packages'
     268    develbranch = sageroot+'devel/sage'
     269    filename=re.sub(runpathpattern,develbranch,filename)
     270    IPython.hooks.editor(self, filename, linenum)
     271
     272ip = IPython.ipapi.get()
     273if ip:
     274    ip.set_hook('editor', edit_devel)
     275
     276