Refactor editor #55
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
seq-lisp-2-backport
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/seq-lisp!55
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "refactor-editor"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull Request Review: Refactor Editor
Overview
This PR refactors the vim-line editor by introducing structured types (
EditorStateandUndoEntry) to encapsulate editor state, replacing the previous approach of threading multiple stack values. The refactoring adds 783 lines while removing 199 lines, with significant new functionality including yank/paste operations, bracket matching, undo support, and improved word motion handling.✅ Strengths
1. Excellent Architectural Improvement
The introduction of
EditorStateis a major win for maintainability:( EditorState -- EditorState Bool )vs( String Int Int -- String Int Int Bool )2. Well-Designed Updater Pattern
The updater functions (
ed-with-buffer,ed-with-cursor, etc.) follow immutable data structure patterns effectively:This approach maintains immutability while providing ergonomic state updates.
3. Comprehensive Feature Additions
%motion): Properly implements depth tracking for nested bracketsy,p,P): Full clipboard functionality with register supportuin normal mode): Stack-based undo with depth limiting4. Good Documentation
Stack comments are thorough and helpful for understanding Seq's stack-based execution:
⚠️ Issues & Concerns
1. Bug: Undo Stack Lost After Undo (HIGH)
Location:
src/vim-line.seq:1184Problem: After performing an undo, the undo stack is completely discarded and replaced with an empty stack. This means:
Expected behavior: The popped undo stack should be preserved so subsequent
ucommands can continue undoing previous changes.Suggested fix:
2. Incomplete Feature: undo-limit Not Implemented (MEDIUM)
Location:
src/vim-line.seq:134Problem: The function
undo-limitis called after every undo push but has an empty body. This means:undo-limit-loop(lines 138-154) is defined but never usedSuggested fix:
3. Potential Stack Overflow in Recursive Functions (MEDIUM)
Locations: Several helper functions use deep recursion:
undo-limit-loop(lines 138-154)find-bracket-forward(lines 319-356)find-bracket-backward(lines 360-397)Problem: These recursive functions don't appear to be tail-recursive in Seq terms due to operations after the recursive call:
Risk: Very deep bracket nesting (1000+ levels) or large undo stacks could cause stack overflow.
Suggested mitigation: Consider iterative versions or verify that Seq's TCO handles these cases. Document maximum safe nesting depth.
4. Missing Ctrl+D/Ctrl+C Consistency (LOW)
Location: Multiple locations in key handlers
The PR changes EOF detection from
string.empty?to"\x04"string equality (good!), but:In
src/repl.seq:9:In
src/vim-line.seq:960-961:Issue: The comment conflates Ctrl+C and Ctrl+D, but they have different semantics:
Both returning
"\x04"may be correct for this REPL, but it should be documented clearly. Consider whether Ctrl+C should return empty string or a different sentinel.5. Tab Character Handling Added (MINOR)
Location:
src/vim-line.seq:243Change: Added tab (ASCII 9) to trailing whitespace trimming.
Question: Is this intentional for the REPL history? Tabs in Lisp code may be significant for some users. Consider whether this should only trim from history, not from the actual buffer content.
🔍 Code Quality Observations
Positive:
ed-*,undo-*,history-*prefixesSuggestions:
Extract magic numbers to named constants:
Add error handling for bracket matching with extreme nesting
Test coverage: Ensure tests exist for:
🛡️ Security Considerations
No security concerns identified. The code operates on user input in a REPL context with appropriate bounds checking.
📊 Performance Considerations
Positive:
Concerns:
undo-limit, 50 entries × (buffer + cursor) could be significant for large edits🧪 Test Coverage
Status: Cannot verify without running tests, but areas needing coverage:
yy,y$,yw,p,P)📝 Recommendations
Must Fix (Before Merge):
undo-limitproperly (issue #2) - memory leak potentialShould Fix (Before or Shortly After Merge):
Nice to Have:
Summary
This is a well-designed refactoring that significantly improves code maintainability and adds valuable vim features. The
EditorStateencapsulation is exactly the right architectural move for a stack-based language implementation.However, there are two critical issues that need attention before merge:
Both are straightforward fixes. Once addressed, this will be an excellent improvement to the codebase.
Recommendation: Request changes for issues #1 and #2, then approve after fixes are verified.
Review generated for commit
bc33dcd(Refactor editor)Pull Request Review: Refactor Editor
Overview
This is a substantial refactoring that improves the vim-line editor architecture significantly. The changes total +787/-199 lines across 2 files, introducing an EditorState type to encapsulate editor state, undo functionality, and new vim operations.
Strengths
1. Excellent Architectural Improvement
2. Undo System Implementation
3. Enhanced Vim Features
4. Code Quality
Issues and Concerns
1. Potential Bug: EOF Detection Change (repl.seq:9-10)
Changed from string.empty? to checking for literal \x04 character. This could cause issues if Ctrl+D is typed mid-input. Please verify this is intentional.
2. Undo Stack Performance
3. Stack Manipulation Complexity
Despite EditorState abstraction, some functions (like dw operator lines 655-677) have very complex stack manipulations. Consider extracting helper functions like delete-range.
4. Bracket Matching Edge Cases
Implementation doesn't handle strings or comments (e.g., opening paren in a string would be matched). Document this limitation or consider context-aware matching.
5. Tab Character Now Stripped
Tabs are now stripped from trailing whitespace. This is a behavior change that could affect existing workflows.
6. Missing Test Coverage
No test files were added/modified. Given complexity of refactor and new features, comprehensive tests are essential for EditorState updaters, undo/redo, bracket matching, and yank/paste.
Security and Performance
Security: Low risk. Undo stack has 50-entry limit. Control character handling with \x04 could be confusing if it appears in pasted content.
Performance:
Summary
Overall Assessment: This is a high-quality refactor that significantly improves the codebase. The EditorState abstraction is excellent, and new features add substantial value.
Before merging, please address:
Recommendation: Approve with minor changes. Core architecture is sound, but test coverage and EOF handling should be addressed.
Great work on this refactor! 🎉
PR Review: Refactor editor
Summary
This is a significant and well-executed refactor of the vim-line editor. The PR successfully introduces several major improvements while maintaining the core functionality. Overall, this is high-quality work with excellent code organization and thoughtful design decisions.
Stats: +798 lines, -199 lines across 2 files
✅ Strengths
1. Excellent Architectural Improvements
EditorStateunion type is a major win. It encapsulatesbuffer,cursor,mode, andyank_reginto a single value, dramatically simplifying stack management throughout the codebase.ed-buffer,ed-cursor,ed-with-buffer, etc.) provides a clean, functional interface for state manipulation.EditorState, making the code much easier to reason about.2. Feature Additions
Impressive set of new vim features:
ucommand)y,p,Poperators with proper register management%motion for navigating matching brackets(),[],{}dw,cwfor word-based operationswmotion that distinguishes between word chars, punctuation, and whitespace3. Code Quality
# Stack: EdState(1) NewBuf(0))ed-*,undo-*,normal-key-*)⚠️ Issues & Concerns
1. Critical: Missing Test Coverage
Severity: HIGH
This is the biggest concern. A refactor of this magnitude (798 additions, 199 deletions) with zero visible test coverage is risky:
EditorStatetypeRecommendation:
2. Potential Bug: Undo Stack Doesn't Preserve Yank Register
Location:
vim-line.seq:1194-1198When restoring from undo, the yank register is always set to
"". This means:Expected behavior: Undo should preserve the yank register or at least document this limitation.
Recommendation: Either:
UndoListtype (addyank_reg: Stringfield)3. Stack Management Complexity in Updaters
Location:
vim-line.seq:52-68The
ed-with-cursoranded-with-modefunctions have subtle off-by-one patterns in theirpickoperations:vs
The comments
(position 2, not 3!)and(position 3, not 4!)suggest this was error-prone during development. While the code appears correct, this pattern is fragile.Recommendation: Consider a helper macro or function to reduce boilerplate and potential for stack manipulation errors.
4. Bracket Matching: No Timeout for Large Files
Location:
vim-line.seq:328-407The
find-bracket-forwardandfind-bracket-backwardfunctions recursively scan the entire buffer. For a large input buffer (e.g., 10,000+ chars), this could cause:Recommendation:
5. Ctrl+D Behavior Change May Be Breaking
Location:
repl.seq:9andvim-line.seq:971The PR changes Ctrl+D handling:
This changes the contract of
vim-edit. Callers now receive"\x04"instead of""for EOF.Recommendation:
repl.seq6. Undo Limit Algorithm Inefficiency
Location:
vim-line.seq:138-160The
undo-limit-loopfunction rebuilds the entire undo list on every push:Performance impact:
Recommendation:
🔍 Minor Issues
7. Magic Numbers
While 50 is reasonable, consider making this configurable or documenting why 50 was chosen.
8. Missing Edge Case: Empty Buffer with
%What happens if user presses
%on an empty buffer? The code doesn't explicitly handle this.9. Tab Character in Whitespace Strip
Location:
vim-line.seq:171Good catch adding tab (9) to whitespace stripping! But verify this doesn't break anything that relied on the old behavior.
🛡️ Security Review
No security concerns identified. This is editor UI code with no:
📊 Performance Considerations
string.substringcalls in yank/paste - acceptable for typical line editing🎯 Recommendations Summary
Must Fix Before Merge:
Should Fix:
4. Add max search distance to bracket matching
5. Optimize undo-limit to only rebuild when needed
Nice to Have:
6. Reduce stack manipulation boilerplate in updaters
7. Add edge case handling for empty buffers
8. Document undo-max-depth rationale
📝 Final Verdict
Recommendation: Approve with required changes
This is excellent work that significantly improves the editor architecture and adds valuable features. The
EditorStateabstraction is a major quality improvement. However, the lack of test coverage is a blocker for a refactor of this size.Suggested next steps:
Once tests are added and the yank register issue is addressed, this will be ready to merge!
Great work overall! The refactor shows careful thought and clean execution. 🎉
Code Review - PR #55: Refactor Editor
Summary
This PR refactors the vim-style line editor with significant architectural improvements. The changes demonstrate excellent attention to detail in stack-based programming, with comprehensive documentation and careful state management.
Strengths
Architecture & Design
New Features
Code Quality
Potential Issues & Suggestions
Minor Issues
Stack complexity in ed-with-cursor (vim-line.seq:57-64): The updater functions use pick with complex indices. While the comments are excellent, this pattern is inherently fragile.
Undo memory for yank register: The undo stack limits entries to 50, but yank_reg field could theoretically hold unbounded text. Likely acceptable for a line editor.
Bracket matching edge cases: Doesn't handle string literals containing brackets or comments. Acceptable for a line editor where context is limited.
Error handling in paste operations: Complex stack manipulations with multiple nip operations. Consider adding stack validation.
History navigation: Complex stack juggling makes verification difficult. Consider adding integration tests.
Performance Considerations
Security Considerations
No security issues identified. The code properly handles untrusted input, has no buffer overflows, and no injection vulnerabilities.
Test Coverage
Observation: The PR modifies 806 lines but doesn't include new tests.
Recommendations:
Best Practices
Conclusion
This is a high-quality refactor that significantly improves the editor's architecture and functionality. The main concern is lack of test coverage for the new features.
Recommendation: Approve with suggestion to add tests in a follow-up PR.
Review conducted by Claude Code