[IPython-dev] Highlight lines of code in code cells?

Gabriel Becker gmbecker at ucdavis.edu
Wed Dec 4 13:27:32 EST 2013


Mark,

This seems reasonable, and like a useful piece of functionality to have.
TBH I'd prefer that computations *in* documents and computations *on*
documents be more separate conceptually, but that may just be my bias
stemming from what my research is about (dynamic data analysis documents
that can be operated on and what that buys us).

Nice work.
~G


On Mon, Dec 2, 2013 at 8:23 PM, Mark Voorhies <mark.voorhies at ucsf.edu>wrote:

> On 12/02/2013 05:41 PM, Gabriel Becker wrote:
> > Unless I completely miss my guess, shell.history_manager is going to look
> > at the code that has been executed. This is related to what is in the
> > cells, of course, but it isn't the same.
> >
> > Also, the concept of "cell number" if I am correct in assuming you are
> > referring to the numbers that appear next code cells after the run, is
> that
> > they are not persistently connected to current cell content and don't
> have
> > a 1-to-1 correspondence to the actual cells during non-headless
> execution.
> >
> > i.e. if a code cell is executed, then edited and executed again, but the
> > cell number targeted for diffing isn't changed, a magic using
> > shell.history_manager will grab the contents of the cell *when it was run
> > the first time*
>
> All of this is correct.
>
> > as opposed to what I think is conceptually intended, which
> > is what is in the cell now.
>
> It is true that my approach won't work for anything that the kernel hasn't
> seen,
> so it can't do live updates of the diff as cells are edited (and JS
> _would_ be
> the right approach for that sort of thing).  Outside of that, I think most
> behaviors can be achieved given the right interface.
>
> Here's what the current iteration (
> https://github.com/markvoorhies/ipython/commit/216ea233413a20061e6c77863798d449be6200c9
> )
> can handle:
>
> %diff 6 7
>
> --> gives diff of cells [6] and [7].  If [7] is edited (e.g., becoming
> [9]), the %diff output does not change,
>      even if re-run.  %diff 6 9 _does_ diff the new content.
>
> %diff 6
>
> --> gives diff of the last cell (e.g., [7]) with cell [6].  If cell [7] is
> edited and re-run (e.g., becoming [9]),
>      re-running the %diff _does_ diff [6] and [9].
>
> %diff
>
> --> gives diff of the last two cells (e.g. [6] and [7]).  This is not
> useful for re-running (because the %diff cell
>      itself becomes part of the history), but is a nice shorthand for the
> most common use case.
>
> %diff A B
>
> --> diffs the most recent cells with first lines "##label:A" and
> "##label:B" respectively.  If either cell is
>      edited and re-run, then re-running the %diff _does_ diff the latest
> content.
>      (This is a place-holder, pending an IPythonic mechanism for labeling
> cells)
>
> The last example allows this work flow:
>
> 1) Create cell "##label:A"
> 2) Create cell "##label:B" (via M-C,M-V in cell A and editing)
> 3) %diff A B
> 4) Fix up A and B with little edits as needed, re-running the edited cell
> and "%diff A B" with each edit.
> 5) Create cell "##label:C" (via M-C,M-V in cell B and editing)
> 6) %diff B C
> 7) Fix up C with little edits as needed, re-running the edited cell and
> "%diff B C" with each edit.
> 8) etc.
>
> For teaching, I would tend to skip the "little edits" steps, in which case
> (3) can become "%diff A"
> and (6) can become "%diff B".
>
> --Mark
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>



-- 
Gabriel Becker
Graduate Student
Statistics Department
University of California, Davis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20131204/49a3d72f/attachment.html>


More information about the IPython-dev mailing list