Skip to content

Conversation

@lucharo
Copy link
Contributor

@lucharo lucharo commented Oct 4, 2025

Summary / Use case

When working with AI coding assistants on marimo notebooks, it's much clearer to reference code by its actual line number in the source file (e.g., "modify line 42") rather than using relative cell references. This is particularly valuable in notebooks with many cells where cell-based references become difficult to track.

Features Implemented

  • Absolute line number display: CodeMirror extension that shows actual line numbers from the Python script file
  • Keyboard shortcut: Cmd+Shift+A (Ctrl+Shift+A on Windows/Linux) to toggle absolute line numbers
  • UI toggle: Settings → Display → "Absolute line numbers" checkbox
  • Visual indicator: Small "A" badge appears in the top-left corner of cells when absolute mode is active
  • Configuration persistence: Setting is saved in user config and persists across sessions
Screen.Recording.2025-10-04.at.19.13.53.mov

Note I also added editable marimo install in the pixi section of pyproject.toml as performed in the #6679 PR

test cases

  • Does this work if you move cells around?
  • Does this work for multi-column?
  • As you add new lines, do they get updated?
  • updates when adding/deleting cells?

caveat

doesn't work in a temporary notebook when a file hasn't been assigned yet (e.g. when creating notebook via marimo edit rather than marimo edit nb.py)

🤖 Generated with Claude Code

@vercel
Copy link

vercel bot commented Oct 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
marimo-docs Ready Ready Preview Comment Oct 4, 2025 7:22pm

@github-actions github-actions bot added the bash-focus Area to focus on during release bug bash label Oct 4, 2025
- Display line numbers from source Python file instead of relative cell numbers
- Add keyboard shortcut (Cmd+Shift+A) to toggle absolute line numbers
- Add UI toggle in Settings → Display → "Absolute line numbers"
- Add visual indicator ("A" badge) in cell corner when enabled
- Persist configuration in user config

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
# Store line numbers in cell data after registering
self._register_cell(cell, app=app)
# Update with line numbers
if cell._cell.cell_id in self._cell_data:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this will work when you first load the notebook. But updating the notebook (adding/deleting cells, adding new lines etc etc) and this won't work anymore.

It's a nice idea, but there's more to keep the back end in sync with the frontend

@mscolnick
Copy link
Contributor

Does this work if you move cells around? Does this work for multi-column? As you add new lines, do they get updated?

@lucharo
Copy link
Contributor Author

lucharo commented Oct 5, 2025

hey guys, thanks for the feedback, indeed in those scenarios it's not currently working, I added those as test cases to the PR description.

It does work when adding new lines but indeed when you move cells around or add a new cell it doesn't work, I'll keep working on it

@dmadisetti
Copy link
Collaborator

@lucharo it's a pretty hairy, I considered going down this path for adding debugging capabilities- but instead settled for https://github.com/marimo-team/marimo/pull/6311/files#diff-26c1c93dacf92c199621cd07b116adc86d6d6fc66e5447d5a94a6c51c51f05b5R1404 which just re-parses the notebook on execution every single time.

But if you're up for it, would be awesome

@mscolnick
Copy link
Contributor

re-parsing on execution sounds not ideal for performance. i understand this would be behind a config flag, but just something to consider both if you still plan to implement this and something worth showing in the UI

@lucharo
Copy link
Contributor Author

lucharo commented Oct 6, 2025

@lucharo it's a pretty hairy, I considered going down this path for adding debugging capabilities- but instead settled for https://github.com/marimo-team/marimo/pull/6311/files#diff-26c1c93dacf92c199621cd07b116adc86d6d6fc66e5447d5a94a6c51c51f05b5R1404 which just re-parses the notebook on execution every single time.

But if you're up for it, would be awesome

which bit do you consider hairy? is it the keeping track of line count without reparsing the source script?

@dmadisetti
Copy link
Collaborator

which bit do you consider hairy? is it the keeping track of line count without reparsing the source script?

Yes, namely because what is in memory is not bound to be what's on disk (esp with autosave off). Toggling could send a request to save and then get line offsets. This would be a simplification over attempting to carry around line number and do constant accounting (which is the more complex, edge-case filled "hairy" issue)

@lucharo
Copy link
Contributor Author

lucharo commented Oct 6, 2025

which bit do you consider hairy? is it the keeping track of line count without reparsing the source script?

Yes, namely because what is in memory is not bound to be what's on disk (esp with autosave off). Toggling could send a request to save and then get line offsets. This would be a simplification over attempting to carry around line number and do constant accounting (which is the more complex, edge-case filled "hairy" issue)

yeah I thought so! I am thinking that this could be a feature that's only really available when --watch or auto-save is on as parse on save seems to be probably the sanest approach. This would make sense in the sense that having absolute line count would probably only makes sense when people are running marimo alongside an agent and likely have watch and auto save on

and clear on the keeping track of line number, that'd be indeed hairy, I understood correctly! I'll keep cracking on this feature working "on save" (if you guys like the feature enough)

@mscolnick
Copy link
Contributor

@lucharo - i think even with on-save, the line numbers will be outdated. personally, i think the complexity is not worth effort.

taking a large step back, is there another way you can give Claude context of where is should focus that is not based on line numbers (e.g. cell name, cell contents)

@lucharo
Copy link
Contributor Author

lucharo commented Oct 6, 2025

@lucharo - i think even with on-save, the line numbers will be outdated. personally, i think the complexity is not worth effort.

taking a large step back, is there another way you can give Claude context of where is should focus that is not based on line numbers (e.g. cell name, cell contents)

Fair enough! I won't pursue it then.

I think cell name would work but by default cells are not named. It'd be great to have something that works out of the box. It could be cell number (again, toggleable) so that the human and the agent both have something to share perspectives over. I think agents would probably need to "count" the number of cells and might get it wrong sometimes. Cell content works fine but again might lose precision in longer periods, can copy and paste the exact function/snippet of code but that also makes for worse UX I think.

I think the reason I suggested line count was because I see agents often use grep or sed or similar tools to scan files so line count works out of the box for referencing files.

What are your thoughts?

@mscolnick
Copy link
Contributor

im not sure how large your notebooks are, but i find agents pretty good at consuming the whole file. not sure i have other thoughts on other ways give exact context, but open to explore

@dmadisetti
Copy link
Collaborator

@lucharo we did have a feature request/ idea for auto-naming cells with an agent. I can't find the exact issue- but maybe that would help with your issue?

@lucharo
Copy link
Contributor Author

lucharo commented Oct 15, 2025

This line of work is too thorny and with how marimo is currently set up would be very expensive to set up (parsing source script at every save) so will abandone for other simpler ways of referencing code cells, thanks @dmadisetti and @mscolnick for the discussion!

@lucharo lucharo closed this Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bash-focus Area to focus on during release bug bash

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants