$ show coteditor/CotEditor
CotEditor is a native macOS text editor written in Swift, designed for code editing with syntax highlighting, file management, find/replace, and scripting support. It uses a hybrid AppKit/SwiftUI architecture, with core editing logic in the EditorCore package, syntax parsing in the Syntax package (supporting both regex-based and tree-sitter incremental parsing), and macOS-specific UI controls in the MacUI package. The application follows an MVVM pattern with @Observable models, async task-based background processing, and extensive localization across 19 languages. Key entry points include the DocumentWindow and DocumentViewController for the main editing interface, the SettingsWindow for configuration, and the command-line tool `cot`. Data flows involve file opening with encoding detection, syntax highlighting via incremental parsers, find/replace operations with progress tracking, and remote editing via the rmate protocol. External dependencies include tree-sitter grammars for 20+ languages, Sparkle for updates, and various macOS system APIs. The codebase demonstrates strong engineering practices: modular package design, protocol-oriented interfaces, reactive state management, and comprehensive test coverage. It is actively maintained with frequent releases and security fixes.
The LLM identified 6 files worth highlighting for reuse:
Actor-based incremental parser that manages tree-sitter instances for highlights and outline extraction. Handles edit tracking, parse invalidation, and result caching. Reusable as a template for integrating tree-sitter into any Swift application.
Configurable regex-based parser for nested tokens (inline comments, pair delimiters) with support for prefixes, escape characters, and double-delimiter escaping. Demonstrates careful handling of nesting depth and longest-prefix matching. Could be extracted for any text parsing task requiring nested token recognition.
Extensions to NSString for substring range finding, line number/range calculations, grapheme-aware index navigation, and safe CRLF handling. Provides a cohesive set of string operations that are reusable across any text-processing project.
Folder-wide search engine with query compilation, file filtering, decoding options, and match range tracking after edits. Supports cancellation and progress reporting. Reusable pattern for implementing search across a file tree with live result updates.
SwiftUI FileDocument that packages all user settings (syntaxes, themes, snippets, replacements) into a portable bundle with Info.plist and per-type directories. Demonstrates a clean pattern for settings portability that could be adapted for any application.
Singleton that monitors a user script folder using NSFilePresenter, builds a dynamic Script menu with recursive directory scanning, and applies keyboard shortcuts per syntax scope. Reusable pattern for any application needing folder-watching with dynamic menu generation.