{"id":13871972,"url":"https://github.com/ChimeHQ/TextFormation","last_synced_at":"2025-07-16T01:32:22.077Z","repository":{"id":43842023,"uuid":"454080491","full_name":"ChimeHQ/TextFormation","owner":"ChimeHQ","description":"Rules system for live typing completions","archived":false,"fork":false,"pushed_at":"2024-03-02T18:55:38.000Z","size":150,"stargazers_count":42,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-24T08:59:36.014Z","etag":null,"topics":["appkit","nstextview","swift","text"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChimeHQ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["mattmassicotte"]}},"created_at":"2022-01-31T16:23:18.000Z","updated_at":"2024-08-06T00:34:24.020Z","dependencies_parsed_at":"2023-11-21T15:49:51.295Z","dependency_job_id":"eec81518-8072-444d-8c95-d23b6f54c220","html_url":"https://github.com/ChimeHQ/TextFormation","commit_stats":{"total_commits":69,"total_committers":3,"mean_commits":23.0,"dds":0.02898550724637683,"last_synced_commit":"f07ecbdb8daab6cdb5344a88e8685ae55a7a44c3"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChimeHQ%2FTextFormation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChimeHQ%2FTextFormation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChimeHQ%2FTextFormation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChimeHQ%2FTextFormation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChimeHQ","download_url":"https://codeload.github.com/ChimeHQ/TextFormation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226090030,"owners_count":17572114,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appkit","nstextview","swift","text"],"created_at":"2024-08-05T23:00:31.602Z","updated_at":"2025-07-16T01:32:22.068Z","avatar_url":"https://github.com/ChimeHQ.png","language":"Swift","funding_links":["https://github.com/sponsors/mattmassicotte"],"categories":["Swift"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n[![Build Status][build status badge]][build status]\n[![License][license badge]][license]\n[![Platforms][platforms badge]][platforms]\n[![Documentation][documentation badge]][documentation]\n\n\u003c/div\u003e\n\n# TextFormation\n\nTextFormation is simple rule system that can be used to implement typing completions and whitespace control.\n\nThink matching typing \"{\", hitting return, and getting \"}\" with indenting.\n\n- Text system agnostic\n- Many pre-built filters for common language patterns\n- Compatible with multiple cursors editing systems\n- Flexible whitespace calculations\n\n\u003e [!WARNING]\n\u003e The main branch has undergone some major changes to support new capabilities. Not all indentation calculation features are available quite yet.\n\n## Integration\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/ChimeHQ/TextFormation\", branch: \"main\")\n]\n```\n\n## Concept\n\nTextFormation's core model is a `Filter`. Filters are typically set up once for a given language. From there, changes in the form of a `TextMutation` are fed in. The filter examines a `TextMutation` **before** it has been applied. Filters can be stateful, but if they return `MutationOutput`, it means it has processed the mutation and no further action should be taken.\n\nTextFormation is fully text system-agnostic and it models the text system using an abstraction based on types from [Rearrange](https://github.com/ChimeHQ/Rearrange). This requires that you provide a `TextSystemInterface` implementation. This type is responsible for supporting the querying and mutation capabilities filters need, along with an abstraction for how text positions and ranges are represented.\n\n## Filters\n\nCareful filter ordering can produce some pretty powerful behaviors. Here's an example of a chain that produces typing completions that roughly matches what Xcode does for open/close curly braces:\n\n```swift\n// skip over closings\nlet skip = SkipFilter\u003cMyTextSystem\u003e(matching: \"}\")\n\n// apply whitespace to the closing delimiter\nlet closeWhitespace = LineLeadingWhitespaceFilter\u003cMyTextSystem\u003e(string: \"}\")\n\n// handle newlines inserted in between opening and closing\nlet newlinePair = NewlineWithinPairFilter\u003cMyTextSystem\u003e(open: \"{\", close: \"}\")\n\n// auto-insert closings after an opening, with special-handling for newlines\nlet closePair = ClosePairFilter\u003cMyTextSystem\u003e(open: \"{\", close: \"}\")\n\n// surround selection-replacements with the pair\nlet openPairReplacement = OpenPairReplacementFilter\u003cMyTextSystem\u003e(open: \"{\", close: \"}\")\n\n// delete a matching close when adjacent and the opening is deleted\nlet deleteClose = DeleteCloseFilter\u003cMyTextSystem\u003e(open: \"{\", close: \"}\")\n```\n\nThis kind of usage is probably going to be common, so all this behavior is wrapped up in a pre-made filter: `StandardOpenPairFilter`.\n\n```swift\nlet filter = StandardOpenPairFilter\u003cMyTextSystem\u003e(open: \"{\", close: \"}\")\n```\n\n## Indentation\n\nCorrectly indenting in the general case may require parsing. It also typically needs some understanding of the user's preferences. The included `TextualIndenter` type has a pattern-based system that can perform sufficiently in many situations.\n\nIt includes `basicPatterns` that work well for many languages. There are also some pre-defined patterns:\n\n```swift\nTextualIndenter.rubyPatterns\nTextualIndenter.pythonPatterns\n```\n\n## Contributing and Collaboration\n\nI would love to hear from you! Issues or pull requests work great. Both a [Matrix space][matrix] and [Discord][discord] are available for live help, but I have a strong bias towards answering in the form of documentation. You can also find me on [the web](https://www.massicotte.org).\n\nI prefer collaboration, and would love to find ways to work together if you have a similar project.\n\nI prefer indentation with tabs for improved accessibility. But, I'd rather you use the system you want and make a PR than hesitate because of whitespace.\n\nBy participating in this project you agree to abide by the [Contributor Code of Conduct](CODE_OF_CONDUCT.md).\n\n[build status]: https://github.com/ChimeHQ/TextFormation/actions\n[build status badge]: https://github.com/ChimeHQ/TextFormation/workflows/CI/badge.svg\n[license]: https://opensource.org/licenses/BSD-3-Clause\n[license badge]: https://img.shields.io/github/license/ChimeHQ/TextFormation\n[platforms]: https://swiftpackageindex.com/ChimeHQ/TextFormation\n[platforms badge]: https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FChimeHQ%2FTextFormation%2Fbadge%3Ftype%3Dplatforms\n[documentation]: https://swiftpackageindex.com/ChimeHQ/TextFormation/main/documentation\n[documentation badge]: https://img.shields.io/badge/Documentation-DocC-blue\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FChimeHQ%2FTextFormation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FChimeHQ%2FTextFormation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FChimeHQ%2FTextFormation/lists"}