Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: use special comment lines to divide code into notebook-like cells #63

Closed
cdsousa opened this issue Nov 5, 2015 · 15 comments

Comments

@cdsousa
Copy link

cdsousa commented Nov 5, 2015

I love working in Jupyter but I miss a full fledged editor too many times.
On the other hand I'm also liking working in Atom+atom-julia-client but then I miss the custom block/cell code division.

I think the approach Matlab editor uses for solving this is a good trade-off.

Do you think it would be feasible to have a special comment line (e.g., ## this splits cells or #== this splits cells ==#) and a key shortcut to evaluate the cursor current cell?

@pfitzseb
Copy link
Member

pfitzseb commented Nov 5, 2015

👍
Not sure what syntax would be better, but I kinda like ## since it's close to matlab and could be interpreted as markdown as well -- you jsut take a h2 and structure your code with that.

@cdsousa
Copy link
Author

cdsousa commented Nov 5, 2015

Let me add that displaying the results of each cell inline, right before the next cell division, would be awesome and would make Atom work more like a notebook. I guess that is harder from a technical perspective though.

@sglyon
Copy link
Contributor

sglyon commented Nov 5, 2015

I like the idea of cells, good suggestion.

But I also don't want my editor to become a notebook so I don't know that I'm on board with holding all results to the bottom of each cell. Given that we don't have a harsh of a visual break between cells (like the notebook does) I think it would be confusing to collect results at cell breaks

@pfitzseb
Copy link
Member

pfitzseb commented Nov 5, 2015

Yeah, I think I'd prefer the results to stay inline, i.e. have the cell-evaluation work like manually evaling all lines in the cell instead of working like the eval file command.

@nilshg
Copy link

nilshg commented Nov 6, 2015

Maybe a compromise would be to have cell Eval when evaluating the cell division line, and line eval for all other lines?

@sglyon
Copy link
Contributor

sglyon commented Nov 6, 2015

I think that another keybindings for cell eval is fine to distinguish
between line and cell eval. The discussion above was about where cell eval
output should go.

// Spencer
On Nov 5, 2015 7:11 PM, "Nils" notifications@github.com wrote:

Maybe a compromise would be to have cell Eval when evaluating the cell
division line, and line eval for all other lines?


Reply to this email directly or view it on GitHub
#63 (comment)
.

@pfitzseb
Copy link
Member

Once atom/atom#9930 lands, we could easily implement @cdsousa's suggestion (along with a setting to switch to sequential inline evaluation of all lines in the cell).

@CarloLucibello
Copy link

atom/atom#9930 has been merged

@ChrisRackauckas
Copy link
Member

Would this be a good time to revive this?

@cdsousa
Copy link
Author

cdsousa commented Sep 21, 2016

I've just noticed that Hydrogen now supports this (just search for "cell" in the page).
It uses a syntax I'm not a big fan, but maybe if this gets implemented here it would be good to be compatible.

@dgleich
Copy link
Contributor

dgleich commented Oct 26, 2016

I would dearly love to have this feature. So much so that I'd been looking at what might be necessary to implement it.

In Hydrogen, the code to select the current cell is (https://github.com/nteract/hydrogen/blob/d850f50df78e20ff7d5918884155bb67bfa02cde/lib/code-manager.coffee):

    getCurrentCell: ->
        buffer = @editor.getBuffer()
        start = buffer.getFirstPosition()
        end = buffer.getEndPosition()
        regexString = @getRegexString @editor

        unless regexString?
            return [start, end]

        regex = new RegExp regexString
        cursor = @editor.getCursorBufferPosition()

        while cursor.row < end.row and @isComment cursor
            cursor.row += 1
            cursor.column = 0

        if cursor.row > 0
            buffer.backwardsScanInRange regex, [start, cursor], ({range}) ->
                start = range.start

        buffer.scanInRange regex, [cursor, end], ({range}) ->
            end = range.start

        console.log 'CellManager: Cell [start, end]:', [start, end],
            'cursor:', cursor

        return [start, end]

The Regex just checks if this is a "cell delimiter line" so I'm sure it would be easy to substitute in a regex for "##" until something else emerges.

Then in terms of atom-juno-client, it seems like you'd just need to either update the blocks.coffee code (https://github.com/JunoLab/atom-julia-client/blob/master/lib/misc/blocks.coffee) to add something about the cell...

Or maybe write a cells.coffee set of code with a 'get' function.

Finally, then you'd need to add something to evaluation.coffee (https://github.com/JunoLab/atom-julia-client/blob/master/lib/runtime/evaluation.coffee) to use the cell instead of the block.

I have zero free time, and have never done anything with coffee, etc. but I might be able to defer more important work to do this :)

@JobJob
Copy link
Contributor

JobJob commented Nov 25, 2016

I picked up from @dgleich's comment above, and got an initial version of this working. I don't really have time to make this better, and don't think it's quite ready for merging, but the commit is here if someone wants to run with it: JobJob@f2bff9b

It just adds one command: julia-client:run-cell. You separate cells with #---(delimiter is set here) and it will run the code in the cell the cursor is currently in.

Edit: found a little time to also add run-cell-and-move and decided to make a PR, latest version of code in PR linked below.

JobJob added a commit to JobJob/atom-julia-client that referenced this issue Nov 27, 2016
Very basic cell based eval, partially addressing JunoLab#63
Adds two commands: `run-cell` and `run-cell-and-move`. When either command is executed, the code in the current cell is eval'd. Cells are delimited with `#---`

Gotcha: doesn't support anything to do with selections, probably won't do what users expect when these commands are run when text is selected.
JobJob added a commit to JobJob/atom-julia-client that referenced this issue Nov 27, 2016
Partially addresses JunoLab#63
Adds two commands: `run-cell` and `run-cell-and-move`. When either command is executed, the code in the current cell is eval'd. Results are displayed block style, below the cell delimiter.
Cells are delimited with `#---` by default, but this also adds an option to set the delimiter in the julia-client settings.

Gotcha: doesn't support anything to do with selections, probably won't do what users expect when the commands added are run when text is selected.
JobJob added a commit to JobJob/atom-julia-client that referenced this issue Dec 2, 2016
Partially addresses JunoLab#63
Adds two commands: `run-cell` and `run-cell-and-move`. When either command is executed, the code in the current cell is eval'd. Results are displayed block style, below the cell delimiter.
Cells are delimited with `#---` by default, but this also adds an option to set the delimiter in the julia-client settings.

Gotcha: doesn't support anything to do with selections, probably won't do what users expect when the commands added are run when text is selected.
@dgleich
Copy link
Contributor

dgleich commented Dec 13, 2016

Just wanted to add some kudos here! This is great to have!

@ChrisRackauckas
Copy link
Member

Should this be closed now?

@pfitzseb
Copy link
Member

Sure, makes sense.

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

No branches or pull requests

8 participants