Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

inactive code cells #2125

Open
MrCreosote opened this Issue · 18 comments

7 participants

@MrCreosote

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.

@minrk
Owner

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.

@Carreau
Owner

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

@MrCreosote

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.

@Carreau
Owner

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

@minrk
Owner

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.

@MrCreosote

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.

@Carreau
Owner

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.

@MrCreosote

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.

@Carreau
Owner

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 ?

@MrCreosote

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.

@Carreau
Owner

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.

@MrCreosote

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

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

@samuela

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.

@jasongrout
@samuela

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

@JanSchulz JanSchulz referenced this issue in minrk/ipython_extensions
Merged

Inactive magic and doc updates to writeandexecute magic #13

@Carreau
Owner

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.

@jlstevens

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.