Layered Design
Zep’s architecture consists of three primary layers:Core Components
The architecture is documented ininclude/zep/editor.h:24-41:
Text Layer (ZepBuffer)
The text layer is responsible for storing and manipulating text efficiently:Gap Buffer
Efficient data structure for text editing with O(1) insertions at the cursor
UTF-8 Support
Full Unicode support through glyph iterators
Line Tracking
Fast line-based operations and navigation
Undo/Redo
Command pattern for reversible operations
Buffer Operations
Frominclude/zep/buffer.h:154-156:
Mode Layer (ZepMode)
The mode layer handles user input and translates it into buffer operations:Modes process keyboard input, handle key mappings, and generate commands that modify buffers. Each mode defines its own editing behavior.
include/zep/mode.h:66-73:
Available Modes
ZepMode_Vim (include/zep/mode_vim.h): Full Vim emulation with modal editing, operators, motions, and text objects.
ZepMode_Standard (include/zep/mode_standard.h): Standard editor behavior similar to most modern text editors.
Display Layer (ZepDisplay)
The display layer is an abstraction that allows Zep to render using any graphics API: Frominclude/zep/display.h:71-83:
The display abstraction is minimal by design - only four core drawing primitives are required to implement a complete renderer.
Component Communication
Components communicate through a message broadcasting system: Frominclude/zep/editor.h:101-117:
Message Flow
- User Input → Mode processes keys
- Mode → Generates commands
- Commands → Modify buffers
- Buffers → Broadcast change messages
- Components → React to changes (syntax, display, etc.)
The ZepEditor Hub
TheZepEditor class ties everything together:
- Manages buffer collection
- Coordinates modes and windows
- Handles configuration and themes
- Broadcasts messages between components
- Provides syntax highlighting registry
Windows and Tabs
Zep supports multiple windows displaying the same or different buffers:Window Hierarchy
Window Hierarchy
include/zep/editor.h:27-30:
Design Principles
Separation of Concerns
Text storage, editing logic, and rendering are independent
Pluggable Components
Modes, syntax highlighters, and displays are interchangeable
Message-Based
Loose coupling through message broadcasting
Platform Agnostic
No dependencies on specific UI frameworks
Next Steps
Buffers
Deep dive into text storage and gap buffers
Modes
Understanding input handling and editing modes
Display Layer
Implementing custom rendering backends
Syntax Highlighting
Adding language support and custom highlighters
