Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

inactive code cells #2125

Open
MrCreosote opened this Issue Jul 12, 2012 · 18 comments

Comments

Projects
None yet
7 participants

Ability to mark cells as inactive, meaning they will not be run by Cell>Run all and have some sort of visual identifier.

Work around: mark cell as raw text.

Owner

minrk commented Jul 12, 2012

I think a new cell type is not the right approach (there is a high cost to adding one). A property of CodeCells is probably more appropriate, or you can right now put code in markdown cells, and it will be highlighted.

Owner

Carreau commented Jul 12, 2012

Also, don't forget that changing cell type clear undo history.

Sorry, over-specified my request. s/type/behavior/ on the OP.

I prefer raw text as a workaround because you can cntl-m t and the code is still legible and cntl-m y restores it. To make code legible in markdown requires editing the code cell (unless there's some trick I'm unaware of).

Like my other request, this is very much a nicety and not particularly important.

Owner

Carreau commented Jul 12, 2012

We can try to provide different type of highlighting in raw-cell, that shouldn't be to hard.

Owner

minrk commented Jul 12, 2012

If I remember correctly, prettify, which we are using to highlight literal blocks in markdown cells, tries to autodetect languages. Perhaps we should be applying that to raw cells.

I would guess that having something like a CodeCell.isActive boolean property (as per minrk's post) that's settable by the menu & keyboard shortcuts where False means the cell's contents aren't evaluated would be easier than adding code highlighting to the raw text cells. That being said, I don't want to specify the solution, so however you choose to do it (if you do choose to spend time on a low priority feature such as this) is fine with me.

Owner

Carreau commented Jul 12, 2012

I would go for highlighting raw cell, preventing execution would be brittle, and highlighting can support many languages.
Moreover it makes the raw-cell more usefull.

The other point I forgot to mention is from your prior post - apparently when you switch between text and code cells you lose the undo history. Whether this is worse than the drawbacks you note above I don't know.

Owner

Carreau commented Jul 12, 2012

Well nothing prevent from dooing both, right now, the raw cell have an rst highlighting mode.
Codecell have a readonly flag that does not work (used for readonly notebook/printview and should also prevent editting, so not the same).

I would vote for having a way to overwrite the highlighting mode in the class cell.js so that every XXXcell that inherit from it can get the hability to change theirs highlighting, and store the value in cell metadata. This would be also usefull for cellmagics like %%ruby, %%R or %%Pyton ...

Thought ?

Not sure if you're addressing that at minrk or me; assuming the latter, I'm afraid I've only been using IPy for a couple of weeks now and I'm not familiar enough with IPy (let alone the code) to fully understand your proposal.

That being said, I think you're proposing that 1) raw text cells be upgraded to prettify code, and 2) undo history isn't zapped when converting between cell types. That sounds great to me.

If that's not what you're proposing, I'm afraid I'll need clarification before I can comment usefully.

Owner

Carreau commented Jul 13, 2012

Sorry, it might have not bean really clear.

Actual state :

  • Codecell have already a read-only attribute that does not work.
    • it is used for print view, and was ment to prevent both executing and editting.
  • RawCell already have an highlighting mode enabled (rst).

Future :

  • Keeping history when changing cell type is something we want, but nos easy / separate issue.
  • I propose of adding a way to change highlighting mode to the common ancestor of all cell, so that user can change
    the highlighting at will, hence for raw text cell, but also for code cell, MD cell ...whatever. I'm thinking of this because one might want to use R highlighting in a code cell with %%R cell magic, or ruby for %%ruby...

I'm not sure about prettify because then the rawcell have to be renderd... and I think we wish to keep raw-cell...raw and have highlighting at writing time.

These all sound like implementation decisions to me, and as such I don't feel as if I understand the code well enough to provide intelligent comments as yet.

ronenabr commented May 4, 2013

I would like to remark one thing:

I have a similar problem (I want to mark cell code as inactive) but I want do that after the code already ran and produced outputs (text, plots, etc.)

In the "mark cell as raw text" the output dose not saved. Will it save when the cell added read-only attribute?

Thanks,
Ronen

Contributor

samuela commented Jul 31, 2013

I find myself continually wishing for this feature.

I would also definitely vote for adding an isActive attribute to CodeCells instead of hacking together something with RawCells. When I was rewriting the Sage Notebook frontend I was faced with a similar choice and opted for this implementation mainly because it more accurately reflects what I envision disabled code cells being: exactly that, code cells. Users expect disabled code cells to behave exactly like normal code cells except that they are disabled and using an isActive attribute has the advantage of giving us all of that behavior for free. Using raw cells requires adding a bunch of hacks to make them behave more like code cells.

Regardless of implementation however, I think hiding cell contents and/or input of disabled code cells would be very helpful.

Owner

jasongrout commented Aug 1, 2013

On 5/4/13 9:09 AM, ronenabr wrote:

I would like to remark one thing:

I have a similar problem (I want to mark cell code as inactive) but I
want do that after the code already ran and produced outputs (text,
plots, etc.)

In the "mark cell as raw text" the output dose not saved. Will it save
when the cell added read-only attribute?

A cell decorator seems like a great solution here; one that basically
just throws away the code.

%%inactive

whatever code

-> executing the cell will do nothing.

Thanks,

Jason

Contributor

samuela commented Aug 1, 2013

+1 for @jasongrout's %%inactive idea.

@janschulz janschulz referenced this issue in minrk/ipython_extensions Aug 2, 2013

Merged

Inactive magic and doc updates to writeandexecute magic #13

Owner

Carreau commented Aug 5, 2013

I would also definitely vote for adding an isActive attribute to CodeCells instead of hacking together something with RawCells.

Raw cell have a specific purpose which is to go untouch to nbconvert, they are not ment to be hacked to more or less behave like raw cells.

When I was rewriting the Sage Notebook frontend I was faced with a similar choice and opted for this implementation mainly because it more accurately reflects what I envision disabled code cells being: exactly that, code cells. Users expect disabled code cells to behave exactly like normal code cells except that they are disabled and using an isActive attribute has the advantage of giving us all of that behavior for free. Using raw cells requires adding a bunch of hacks to make them behave more like code cells.

And this is exactly why code cell have arbitrary metadata. CodeMirror support read-only, and it is not hard to have a js-extension that add a read-only field to the metadata and disable the execute action of this cell. It would be really easy like this with only slight modifications.

Contributor

jlstevens commented Sep 23, 2014

This %%inactive magic doesn't prevent the display data from being destroyed when the cell is executed.

Personally, I am hoping for a magic (or otherwise) that skips cells without disrupting display data.

@minrk minrk removed the type-enhancement label Jan 14, 2015

@minrk minrk removed the quickfix label Jun 12, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment