Skip to content

Let lf-code quote an excerpt under its file's own line numbers, with a Rust sort film example - #1134

Merged
max-sixty merged 9 commits into
mainfrom
lf-code-excerpts
Sep 24, 2026
Merged

max-sixty merged 9 commits into
mainfrom
lf-code-excerpts

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Closes #15.

lf-code can now quote an excerpt of a longer file under that file's own line numbers. The new lines attribute uses the range grammar hi already uses (lines="1505-1507,1520-1527"):

  • The gutter shows those numbers, and a gap between ranges draws an elided row ("⋮ 12 lines").
  • hi, a note's at, and another widget's indication key all name lines by those numbers. A range may span a gap.
  • Without lines, the body is lines 1..N, so quick snippets are unchanged.
  • The gutter numbers and the elided rows are painted by CSS from data attributes. They never enter the clipboard, and no anchor can land on them.
  • The gutter widens to fit the largest number. --lf-code-gutter is a registered <length>, so a note beside the code stays aligned with it.

Validation. A new registry key, x-numbering, names the attribute that numbers a data body. version check refuses:

  • a numbering whose count differs from the body's line count;
  • ranges that are backwards or not ascending;
  • a line 0;
  • any x-lines reference to a line the excerpt does not show.

Named lines, not added. A line is addressed only by its number. A driver that wants readable names keeps a name→number table in its own code. The worked example does this.

New example. examples/rust-sort.html explains Rust's 2016 merge sort. The sort film plays beside three lf-code excerpts of slice.rs. Each step calls indicate() with the source line it runs, and the matching excerpt lights that line. The example is in the catalog, and the preview stills are refreshed. feature-gallery.html now uses lines too.

This was written by Claude Code on behalf of max-sixty

🤖 Generated with Claude Code

max-sixty and others added 7 commits September 24, 2026 11:07
Add `indicate(owner, attribute, key)` to the widget API: a widget marks the
elements a key addresses under the widget its declared `x-refers` attribute
names, in place of what it last marked there, and `null` clears. The runtime
paints the union of every driver's elements with `data-lf-indicated` and
`aria-current="true"`, never scrolls, focuses, reveals, hydrates or announces,
and resolves standing indications again on `lf-layout`. It is browser state
like hover: nothing is logged or published. Marked experimental in its module
header and in the packages.md subsection heading.

`lf-code` answers the hook with its `hi` grammar (`lfElementsFor("3-5,8")`),
states its rendered lines with `layoutChanged`, and gives an indicated line an
accent gutter bar, number and wash, distinct from an `hi` line. marks.css
carries a zero-specificity accent outline for everything else.

Contract changes:
- One key space for x-refers verbs: `addressedElements(source, key)` resolves
  the target's `lfElementsFor` hook, else a registered visual part id, else a
  projected datum key. `navigateToDatum` now travels to the first element it
  returns, so it also reaches visual parts and hook-addressed parts.
- `referencedProjection` resolves in the owner's own authored document first,
  then the page's main, matching the server's request check (thread markup
  before page). It used to search the whole document, so a page element won
  over the owner's own message and another message's markup could answer.
  `authoredScope` moves to passages.js beside `elementById`, which gains a
  root argument.
- The undeclared-attribute TypeError is shared by both verbs
  (`requireReference`).
- `data-lf-indicated` joins PAGE_PAINT_ATTRIBUTES.
- The `x-refers` $keys entry no longer claims the runtime renders every value
  as a followable reference; it names the two verbs and the resolution scope.
- packages.md gains "Following a reference" (scope, key space,
  navigateToDatum moved from External or derived data, and "Indicating
  (experimental)"), and a behavior module's disconnect duty now includes
  clearing its indication.

Tests: new tests/runtime/indication.test.mjs (scope precedence, union and
replace bookkeeping, re-resolution on lf-layout, argument errors) and
test_a_widget_indicates_lines_of_a_code_block_without_moving_the_page in
test_render_widgets.py. No existing test moved.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`lines` on an lf-code gives the source line numbers its body quotes, in the
range grammar `hi` already speaks ("1505-1507,1520-1527"). The gutter shows
those numbers, widening to fit four digits; each gap between ranges draws an
elided row saying how many lines are left out, painted from an attribute so
it stays out of the clipboard and out of anchoring. Without `lines` a body is
lines 1..N, so a quick snippet is written and rendered as before.

Every reference into the block now names lines by those numbers: `hi`, a
note's `at`, and the key another widget indicates (#1129's lfElementsFor). A
number the block does not show addresses nothing, so a driver can offer one
key to several excerpts of the same file. Lines carry no names: a driver that
wants readable ones keeps its own table from name to number.

The layer gains `x-numbering`, naming the attribute that numbers a data body,
so `version check` stays free of tag names: it holds the numbering to one
ascending number per body line and refuses a line reference to a number the
body does not quote. The feature gallery's code specimen is now an excerpt.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	skills/leaf/assets/runtime/anchor-travel.js
#	skills/leaf/assets/runtime/indication.js
#	skills/leaf/packages/default/widgets/lf-code.js
#	skills/leaf/references/packages.md
#	tests/runtime/indication.test.mjs
#	tests/test_render_widgets.py
examples/rust-sort.html plays the merge sort Rust shipped in 1.15 on four
inputs, beside the three functions it runs quoted as lf-code excerpts under
slice.rs's own line numbers. Each step lights the line it executes through
indicate(): the film keeps its step names in a table from name to line
numbers and offers each key to all three excerpts, and only the one that
quotes the line marks it. The catalog lists it under specialized examples
and the corpus carries it as "Sort film".

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Source lines count from 1, so the lines pattern now requires each number to
start with a nonzero digit; a line 0 used to render a 0 in the gutter.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

version check can exhaust memory on an invalid lines value, as noted inline. The current lint check is also red: the new Rust example has trailing whitespace, and the new tests need Ruff fixes before this is ready to merge.

Comment thread tests/test_interact_document.py Resolved
max-sixty and others added 2 commits September 24, 2026 13:52
Trailing spaces on blank lines of the Rust sort excerpts, and ruff's formatting
of two new tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
version check expanded lines into every number it holds, so lines="1-1000000000"
on a one-line block tried to allocate a billion entries. It now sums the ranges'
lengths and tests a reference against the ranges themselves.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit c7df318 into main Sep 24, 2026
5 checks passed
@max-sixty
max-sixty deleted the lf-code-excerpts branch September 24, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants