`code_mode` API auto-formats edited cells even when `save.format_on_save` = false · Issue #9348 · marimo-team/marimo · GitHub
Skip to content

code_mode API auto-formats edited cells even when save.format_on_save = false #9348

@ouatu-ro

Description

@ouatu-ro

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:

  1. code_mode respects save.format_on_save
  2. code_mode exposes an explicit format=False option on edit_cell / create_cell
  3. 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?

  • Yes

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions