Skip to content

fix: keyword scope detection never matched (broken Lua pattern alternation) - #16

Merged
nemanjamalesija merged 3 commits into
mainfrom
fix/scope-keyword-patterns
Jul 3, 2026
Merged

nemanjamalesija merged 3 commits into
mainfrom
fix/scope-keyword-patterns

Conversation

@nemanjamalesija

@nemanjamalesija nemanjamalesija commented Jul 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes #15.

looks_like_scope_opener and looks_like_scope_closer in paste.lua used | alternation inside Lua patterns — but Lua patterns don't support alternation, so those patterns only matched the literal strings then|do|else|elseif|repeat|function and end|elif|else|elseif|catch|finally. Keyword-based scope detection has never fired.

Brace languages were mostly unaffected because {/}/(/: are caught by character classes, which is why existing tests never surfaced it. But in the issue's scenario — dd a python if-block body, then [p with the cursor on the elif line — the elif was not recognized as a scope closer, so resolve_linewise_target_indent never consulted the previous line and returned the elif's own indent instead of hitting the existing empty-block branch (closer preceded by opener at same indent → current_indent + shiftwidth). The line pasted at column 0, which is a syntax error position in Python:

if foo:
bar()          ← pasted here; should be indented into the if body
elif baz:
    blah()

The same bug silently broke keyword openers/closers everywhere: Lua then/do/end, Ruby end, catch/finally, else.

Fix

Test each keyword with its own pattern instead of one alternation pattern. Behavior is exactly what the surrounding code already intended; no policy change.

Also drops the personal editor context file entry from .gitignore (kept ignored locally via .git/info/exclude instead).

Tests

Two regression tests added (both fail on main, pass with the fix):

Full suite: 64/64 passing.

Lua patterns have no | alternation, so looks_like_scope_opener and
looks_like_scope_closer only matched the literal strings
'then|do|else|...' and 'end|elif|else|...' — keyword-based scope
detection never fired. Brace/colon tokens masked the bug in most
languages, but pasting above a python elif (or below a lua 'then')
resolved to the closer's own indent instead of the enclosing block
body.

Test each keyword with its own pattern instead.

Fixes #15
@nemanjamalesija
nemanjamalesija force-pushed the fix/scope-keyword-patterns branch from 6c7f8ba to 5783d2a Compare July 3, 2026 08:07
The keyword scope-detection fix adds per-keyword match loops to
paste.lua (415 -> 429 lines), exceeding the 420-line soft cap in the
e2e verification script. Raise the cap to keep headroom.
@nemanjamalesija
nemanjamalesija merged commit ba7ef8c into main Jul 3, 2026
6 checks passed
@nemanjamalesija
nemanjamalesija deleted the fix/scope-keyword-patterns branch July 3, 2026 08:27
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.

Bad indentation in Python if/else blocks?

1 participant