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

Support multiple kernels per markdown file #637

Merged
merged 3 commits into from
Mar 19, 2017
Merged

Conversation

lgeiger
Copy link
Member

@lgeiger lgeiger commented Mar 15, 2017

This PR adapts #566 to our current setup of handling state with MobX and fixes #566 (comment).

@fasiha Would you like to try out this branch?

@lgeiger
Copy link
Member Author

lgeiger commented Mar 15, 2017

One thing I noticed is that with this workflow the commands "Run All" and "Run Cell" won't work as expected since our parsing doesn't respect the markdown syntax.

@lgeiger
Copy link
Member Author

lgeiger commented Mar 15, 2017

multilang

this.subscriptions.add(atom.workspace.observeTextEditors((editor) => {
if (isMultilanguageGrammar(editor.getGrammar())) {
const cursorSubscription = editor.onDidChangeCursorPosition(
_.debounce(() => { store.setGrammar(editor); }, 75),
Copy link
Member Author

@lgeiger lgeiger Mar 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to switch grammar instantaneously. Therefor we debounce the event to prevent flickering in the statusbar and watch sidebar.

@lgeiger
Copy link
Member Author

lgeiger commented Mar 17, 2017

I tested this branch and didn't found any regressions 🎉
The only downside is that "Run All" and "Run Cell" aren't supported in this workflow, since we would need to do a lot of language specific parsing to be able to do the right thing.

@fasiha
Copy link

fasiha commented Mar 17, 2017

This is so awesome—thank you!!! I’m not sure what “Run Cell” means but could “Run All” be faked by scrolling to the top of the doc, jumping to each fenced code block (triple-ticks or triple-tildes), evaluating “Run” till the last fenced code block, before returning to the original cursor location…? Would that be a super-awful user experience for long-running code blocks?

@rgbkrk
Copy link
Member

rgbkrk commented Mar 17, 2017

Wow, Hydrogen just keeps getting better and more stable. drool

@lgeiger
Copy link
Member Author

lgeiger commented Mar 17, 2017

@fasiha Would you be willing to add a few lines about the usage of this feature to our README? That would be super cool! 🎉

Could “Run All” be faked

You're right we could fake it but that would mean introducing (probably a lot of) language specific code which we try to avoid in Hydrogen since it makes maintaining quite hard.
Unless you are interested in implementing this I think for now the best way would be to disable "Run Cell" and "Run All" for markdown files.
What do you think?

@fasiha
Copy link

fasiha commented Mar 17, 2017

@fasiha Would you be willing to add a few lines about the usage of this feature to our README?

@lgeiger that’d be the least I could do, thanks for trusting me with it. I’m using the feature right now to write a doc for Real Work (¡!), let me see how compelling a use-case I can make.

Could of questions, because I’m dense—

(1) Is there anything Markdown-specific about this? From quickly reading the source, it appears that it should work with AsciiDoc or reST or in fact any format that Atom understands to have “code blocks”—am I right? (Not asking this to be ungrateful 😂! Just wondering how inclusive it can be. I personally don’t use anything except Markdown, though that’s just out of laziness than any proper investigation of alternatives.)

(2) If so, is that what you mean by “language-specific code”? I.e., Hydrogen would have to know, for each format (Markdown, asciiDoc, etc.), where the fenced code block around the cursor started and ended, in order to send that code snippet to Jupyter? I can see that as being really bothersome, yes, so I’m fine with having to manually-select the fenced code block (or have a custom macro, as I have) and Running them, without recourse to Run Cell or Run All.

@nikitakit
Copy link
Contributor

With this functionality, doesn't it make sense to have "Run Cell" run the current fenced block?

I don't use multi-language Markdown documents myself, but my understanding is that a natural way of splitting up code into sections is to create multiple code blocks (possibly with Markdown text in between)

@lgeiger
Copy link
Member Author

lgeiger commented Mar 19, 2017

That’d be the least I could do, thanks for trusting me with it. I’m using the feature right now to write a doc for Real Work (¡!), let me see how compelling a use-case I can make.

Excellent, thanks @fasiha! If you want to write a whole blog post about your use case we're always happy to add it to our Medium publication. 😄

(1) Is there anything Markdown-specific about this?

You are right, it works for every markup language that supports code blocks with syntax highlighting in Atom (I only tested it with markdown so far). To support another language one only needs to add it to this array.

(2) If so, is that what you mean by “language-specific code”?

Correct. We would need to write a different parser for every supported language.

With this functionality, doesn't it make sense to have "Run Cell" run the current fenced block?

@nikitakit That's absolutely true, I just don't see a great way of implementing this right now and personally won't take a closer look at this problem. 😉

@mcburton
Copy link

@lgeiger I know this is closed and merged, but I just want to say being able to "Run Cell" on Markdown fenced blocks is a crucial feature. If Hydrogen could support this it would make possible Atom a plagform for writing generalized rmarkdown-ish files (whatever kernel jupyter supports). As @fasiha mentioned, this would also allow me to do "real work" (scholarly writing with citations, charts/graphs/, code blocks, SPELL CHECK). In short, it would be amazing (and a nice complement to the Notebook, which I also use heavily).

@fasiha
Copy link

fasiha commented Mar 22, 2017 via email

@mcburton
Copy link

@fasiha I'd be happy to try it out!

@fasiha
Copy link

fasiha commented Mar 22, 2017 via email

@mcburton
Copy link

mcburton commented Mar 22, 2017 via email

@rgbkrk
Copy link
Member

rgbkrk commented Mar 22, 2017

Building up a "log" of code run + outputs wouldn't be too bad. Call it "record", have it create a new cell (in-memory) on everything executed, save it to disk. That would be sweet.

@lgeiger
Copy link
Member Author

lgeiger commented Mar 23, 2017

@fasiha @mcburton Great suggestions! I'm really happy to hear you working on a plugin for this!

In the past we had some discussions about introducing a plugin API for such language specific features. It would be awesome to expose more of Hydrogen's functionality to be able to interact with it in a more powerful way.

@lgeiger
Copy link
Member Author

lgeiger commented Mar 23, 2017

I think we should ship a new version soon so people are able to try it out!

In the current state it's already pretty great for writing a README with powerful examples that are ensured to work 😄

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

Successfully merging this pull request may close these issues.

None yet

5 participants