Open SimonBiggs opened 8 years ago
Good point, we should do that for most %%whatever
magics.
In this case you could use Codemirror.findModeByFileName()
to find the right mode.
In this case you could use Codemirror.findModeByFileName() to find the right mode.
Oh, is this function as recent addition to CM ?
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
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.
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.
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.
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.
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.
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?
I'm surprised that works at present, actually :confused: . A custom editor plugin should be able to handle drop events, though, so it should work with that.
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?
I just realised you would probably use the metadata dropdown box...
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.
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.
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.
@takluyver @blink1073 @gnestor : is this functionality available now? thanks!
@takluyver What's the status of this? Is this something that we should revisit at the team meeting this week?
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).
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...
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
.
That's expected. You might be able to use a Python variable like %%writefile {filename}
or %%writefile $filename
.
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?
UsageError: Cell magic %%Writefile
not found.
it was my error in jupyter notebook
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