Describe the bug
When using marimo’s code_mode API, ctx.edit_cell(...) and ctx.create_cell(...) appear to auto-format changed Python code before applying it, even when the user config has:
[save]
format_on_save = false
In my case this is surprising because I’m using code_mode for very local structural edits in a live notebook, and carefully formatted compact code gets rewritten by ruff format / black.
From reading the source, this seems to happen in _code_mode/_context.py, where _format_plan(...) always runs changed code through DefaultFormatter(...) if a formatter is available, using only formatting.line_length from config.
That means:
save.format_on_save = false does not prevent formatting for code-mode edits
- code-mode formatting is effectively always on when
ruff or black is installed
Expected
One of:
code_mode respects save.format_on_save
code_mode exposes an explicit format=False option on edit_cell / create_cell
- marimo adds a separate config key for API/code-mode formatting
Actual
ctx.edit_cell(...) reformats code unconditionally (subject to formatter availability), even when save-formatting is disabled.
Issues
For notebooks that intentionally use dense/compact source layout, code-mode edits currently cannot preserve author formatting. This is especially frustrating when using the marimo-pair skill.
Will you submit a PR?
Environment
Details
marimo 0.23.2
installed via uvx
save.format_on_save = false
formatting.line_length = 79
ruff available
Code to reproduce
[save]
format_on_save = false
Describe the bug
When using marimo’s
code_modeAPI,ctx.edit_cell(...)andctx.create_cell(...)appear to auto-format changed Python code before applying it, even when the user config has:In my case this is surprising because I’m using
code_modefor very local structural edits in a live notebook, and carefully formatted compact code gets rewritten byruff format/black.From reading the source, this seems to happen in
_code_mode/_context.py, where_format_plan(...)always runs changed code throughDefaultFormatter(...)if a formatter is available, using onlyformatting.line_lengthfrom config.That means:
save.format_on_save = falsedoes not prevent formatting for code-mode editsrufforblackis installedExpected
One of:
code_moderespectssave.format_on_savecode_modeexposes an explicitformat=Falseoption onedit_cell/create_cellActual
ctx.edit_cell(...)reformats code unconditionally (subject to formatter availability), even when save-formatting is disabled.Issues
For notebooks that intentionally use dense/compact source layout, code-mode edits currently cannot preserve author formatting. This is especially frustrating when using the
marimo-pairskill.Will you submit a PR?
Environment
Details
Code to reproduce
[save]
format_on_save = false