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

When calling %%writefile cell magic disable syntax highlighting #1447

Open
SimonBiggs opened this issue May 11, 2016 · 24 comments
Open

When calling %%writefile cell magic disable syntax highlighting #1447

SimonBiggs opened this issue May 11, 2016 · 24 comments
Milestone

Comments

@SimonBiggs
Copy link

When calling the %%writefile cell magic python syntax highlighting continues. This can be quite confusing for people who are being shown the notebook and reading the code for the first time.

An example of what I mean can be seen here:
http://mybinder.org/repo/Simonbiggs/electroninserts_bundle/electroninserts_notebook.ipynb#Recording-and-loading-the-data

@Carreau
Copy link
Member

Carreau commented May 12, 2016

Good point, we should do that for most %%whatever magics.

@blink1073
Copy link
Contributor

blink1073 commented May 12, 2016

In this case you could use Codemirror.findModeByFileName() to find the right mode.

@Carreau
Copy link
Member

Carreau commented May 12, 2016

In this case you could use Codemirror.findModeByFileName() to find the right mode.

Oh, is this function as recent addition to CM ?

@blink1073
Copy link
Contributor

blink1073 commented May 12, 2016

I'm not sure when it was added, but we're using it in JupyterLab: https://github.com/jupyter/jupyter-js-ui/blob/master/src/codemirror/index.ts#L24

@SimonBiggs
Copy link
Author

As a question, how difficult would it be to make it so that should ever the file type of %%writefile be a CSV, then the text is justified to align to commas?

This would visually present CSV files very well, and double as an intuitive way to input data.

@takluyver
Copy link
Member

I'm not sure exactly what options codemirror provides, but I'd guess that would be pretty hard.

Have a look at handsontablejs for a (prototype) way to edit data frames in the notebook - it works with pandas data frames, but they can easily load from and save to CSV.

@SimonBiggs
Copy link
Author

Yeah, I thought it would be non trivial. Do you think it would be worth me attempting a plugin that simply adds spaces before commas to pad out the csv for alignment? Or would that also be non trivial? I haven't played around with plugins before.

I'll give handsontablesjs a try. Thanks for the tip.

@SimonBiggs
Copy link
Author

Unfortunately the handsontablesjs method won't work for my purpose. I have been specifically requested to have a permanent record of everything used to make the model within the notebook. Hence writing the CSV file directly into the notebook.

@takluyver
Copy link
Member

We have an idea we're planning to develop that we call 'editor plugins' - i.e. alternative interfaces to write/edit the contents of a cell. A data entry table would make perfect sense in that system, so you might want to keep an eye out for that functionality. It should, I hope, get implemented in the next few weeks.

@SimonBiggs
Copy link
Author

Ahh brilliant. Thank you. Will do. One great feature currently available is that I can drag and drop a csv file from the file browser directly into the cell and it fills it out as expected.

Would a custom data entry table plugin stop something like that from working?

@takluyver
Copy link
Member

I'm surprised that works at present, actually 😕 . A custom editor plugin should be able to handle drop events, though, so it should work with that.

@SimonBiggs
Copy link
Author

Brilliant. Would the custom editor plugin be able to activate only if certain text is within the cell?

And would this maybe work like "tabs" above a cell? Essentially if the plugin is active, and then "%%writefile (*).csv" gets written at the top of a cell, then a data entry tab would appear.

Might the set up be something like that?

@SimonBiggs
Copy link
Author

I just realised you would probably use the metadata dropdown box...

@takluyver
Copy link
Member

The UI hasn't been worked out, but that's roughly the idea - there'll be some way to switch between the table view that the plugin provides and the raw code that it translates the table into.

@SimonBiggs
Copy link
Author

Wonderful. Do you know anyone else who is looking to make a data table type editor with the new plugin method? See if I can work together with them.

@takluyver
Copy link
Member

Not yet, but I imagine that once support for editor plugins is implemented, there will be other people who'd want to work on a data table editor with you.

@fperez fperez added this to the wishlist milestone Jun 17, 2016
@JamiesHQ
Copy link
Member

@takluyver @blink1073 @gnestor : is this functionality available now? thanks!

@gnestor
Copy link
Contributor

gnestor commented May 30, 2017

@takluyver What's the status of this? Is this something that we should revisit at the team meeting this week?

@takluyver
Copy link
Member

The original issue of disabling syntax highlighting for %%writefile or the larger question about editor plugins that we discussed in this thread? I think the former should be fairly easy to fix (just add a pattern in the JS that recognises cell magics).

@gnestor
Copy link
Contributor

gnestor commented May 31, 2017

Ya, it sounds like editor plugins require a much larger discussion. Ok, I will take a crack at disabling syntax highlighting for %%writefile and potentially other magics...

@jeremyf21
Copy link

This might be worthy of opening another issue, but i've noticed that when using %%writefile filename , the filename argument is taken as a literal i.e. if I have variable filename = '/path/to/some/file.txt/' defined in my notebook, running %%writefile filename will write the content of the cell to my current path in a file called filename instead of /path/to/some/file.txt.

@takluyver
Copy link
Member

takluyver commented Feb 27, 2018

That's expected. You might be able to use a Python variable like %%writefile {filename} or %%writefile $filename.

@connectdotz
Copy link

I bump into the same issue, using a variable doesn't really help...

for example setting variable f f="ab c", followed by %%writefile {f}, which yielded UsageError: unrecognized arguments: c; clearly didn't recognize "ab c" as a whole string.

Is there any reason why the filename has to be litteral rather than using standard string syntax?

@Charan7221
Copy link

UsageError: Cell magic %%Writefile not found.
it was my error in jupyter notebook

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

No branches or pull requests

10 participants