[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/code-cells e6f0230a40 05/36: Notes about the Jupytext i
From: |
ELPA Syncer |
Subject: |
[elpa] externals/code-cells e6f0230a40 05/36: Notes about the Jupytext integration |
Date: |
Mon, 28 Feb 2022 15:57:41 -0500 (EST) |
branch: externals/code-cells
commit e6f0230a40e1d446b9518feeffc963032ff55dae
Author: Augusto Stoffel <astoff@users.noreply.github.com>
Commit: Augusto Stoffel <astoff@users.noreply.github.com>
Notes about the Jupytext integration
---
README.md | 66 ++++++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 51 insertions(+), 15 deletions(-)
diff --git a/README.md b/README.md
index 0ebc7b12d8..a65cb836f9 100644
--- a/README.md
+++ b/README.md
@@ -10,13 +10,14 @@ script in the web interface or with
jupyter nbconvert --to script <FILE.ipynb>
```
-It's also worth mentioning [jupytext] and [ipynb-py-convert], which
-can convert to and from notebook format.
+If you have [Jupytext] installed, you can also directly open ipynb
+notebook files in Emacs. They will be automatically converted to a
+script for editing, and converted back to notebook format when saving.
Instead of defining every conceivable command relevant to code with
cells, this package provides a simple way to turn ordinary editing
commands into “cell-aware” ones. The `cells-command` function takes
-as argument a function that acts a region, and returns an anonymous
+as argument a function that acts on a region, and returns an anonymous
command that acts on the current cell. Thus, one can redefine `C-c
C-c` in Python mode to evaluate the current cell by doing the
following:
@@ -28,19 +29,31 @@ following:
(cells-command 'python-shell-send-region))
```
-See below for a more substantial configuration example, which is
-specifically for Jupyter mode but can be easily adapted to any other
-mode or language with a REPL in Emacs.
+There is also a `cells-do` macro, which evaluates its body with the
+current cell bounds accessible as variables. See the documentation
+for details.
-Also available in this package are the following; see the
-documentation for more details.
+Editing commands and minor mode
+-------------------------------
+
+Out of the box, only three editing commands are provided:
+
+- `cells-forward-cell` and `cells-backward-cell` jump to the
+ next/previous cell header.
+- `cells-mark-cell` marks the current cell and activates the region.
+
+Everything else is left up for the user to define with the mechanism
+explained above. See below for a more substantial configuration
+example, which is specific for Jupyter mode but can be easily adapted
+to any other mode or language with a REPL in Emacs.
+
+Finally, there is a minor-mode, `cells-mode`, which provides the
+following things:
-- `cells-do`: a macro that makes the current cells bounds accessible
- as variables.
-- `cells-mark-cell`: mark current cell and activate region
-- `cells-mode`: for now, just adds font locking to the cell
- boundaries. Also provides a keymap where one can add any desired
- cell-related commands.
+- Font locking for cell boundaries.
+- A keymap, `cells-mode-map`, for your custom cell commands.
+- (TODO) Special `adaptive-fill-mode` settings to handle markdown text
+ behind a "wall" of comment characters on the left margin.
Keybindings for [emacs-jupyter]
-------------------------------
@@ -70,7 +83,9 @@ A hydra for [emacs-jupyter]
The following defines a handy [hydra] for Jupyter mode. Activate it
with `M-x notebook-hydra/body RET` or bind that command to a key in
-`jupyter-repl-interaction-mode-map`.
+`jupyter-repl-interaction-mode-map`. Note that since `defhydra` is a
+macro and wraps the definition of a key in an interactive lambda, we need
+to use `cells-do` instead of `cells-command` here.
``` elisp
(defhydra notebook-hydra (:color red :hint nil)
@@ -103,6 +118,27 @@ The head `x` asks for a command like `M-x`, and executes
it with the
current cell as active region. Thus, for instance, typing `x
comment-dwim RET` in this hydra will comment out the current cell.
+Handling Jupyter notebook files with Jupytext
+---------------------------------------------
+
+With this package installed, you can edit Jupyter notebook (`*.ipynb`)
+files as if they were normal plain-text scripts. Converting to and
+from the JSON-based ipynb format is done by the [Jupytext] utility,
+which needs to be installed separately.
+
+**Important notice:** The automatic format conversion on save hasn't
+been thoroughly tested. In particular, it (probably) doesn't handle
+backups in the expected way. Do not rely on its correctness!
+
+Note also that the result cells of ipynb files are not retained in the
+conversion to script format. This means that opening and then saving
+an ipynb file clears all cell outputs.
+
+Within a ipynb buffer, you can use `write-file` (`C-x C-w`) to save a
+copy in script format, as shown in the screen. Moreover, from any
+script file with cell separators understood by Jupytext, you can call
+`cells-write-ipynb` to save a copy in notebook format.
+
[jupytext]: https://github.com/mwouts/jupytext
[ipynb-py-convert]: https://github.com/kiwi0fruit/ipynb-py-convert/
[emacs-jupyter]: https://github.com/dzop/emacs-jupyter
- [elpa] externals/code-cells 7bad8f1cf6 11/36: Speed keys, (continued)
- [elpa] externals/code-cells 7bad8f1cf6 11/36: Speed keys, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells 2dc51b44a3 12/36: Correct outline level before first cell header, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells 9500e07f83 15/36: Fix byte-compilation issue, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells adda62ec82 16/36: Address some packaging issues, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells 67e1479a75 28/36: Add code-cells-mode-maybe, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells f93db2d65c 29/36: Refinement in Commentary section, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells 47305f5439 31/36: Indicate that spaces are allowed before cell boundary marker, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells 68148cfc1f 33/36: Improve cell boundary face, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells f5150fc213 34/36: Update README.md, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells 55e108733a 06/36: Add helper function to call external processes, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells e6f0230a40 05/36: Notes about the Jupytext integration,
ELPA Syncer <=
- [elpa] externals/code-cells 83cb4d0095 24/36: Add code-cells-eval, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells 84cc996bff 32/36: Add missing compile-time requirement, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells dcb0465a46 36/36: Fix image link, ELPA Syncer, 2022/02/28