Codex – Find and Replace for Code (codex-kappa-dusky.vercel.app)
Codex (https://codex-kappa-dusky.vercel.app/) is an attempt to rethink what find & replace should look like in a modern code editor. It defines a simple but powerful syntax for describing code modifications, combining plain text, regular expressions and Tree-sitter queries, along with sensible handling of newlines and indentation*.
It can be used just like regular plain text find & replace, but allows freely mixing in regexes and Tree-sitter queries as more flexibility is needed.
It introduces "line quantifiers" for matching a bunch of lines at the same nesting level, so basic structural changes can be achieved without even using a query (see the JavaScript function example in the link).
I designed Codex with a specific use case in mind (the one I show in my demo video: https://www.youtube.com/watch?v=MQ_N0-AJ2Qg), so any suggestions for other things it should support would be much appreciated, as well as general feedback.
*Indentation is relative and space/tab agnostic.
20 comments
[ 0.33 ms ] story [ 56.7 ms ] threadOne feature that I miss from code editors is “record actions”. The last time I remember having it was maybe in visual studio around the late 90s. It would record whatever you did (keystrokes/copy paste/find replace/etc). At that time, I found that I could often address use cases similar to those I think you are targeting by thoughtfully recording the right sequence of actions.
This is pretty cool. I wonder though if the tree sitter query syntax is the right thing to directly expose. This is definitely useful beneath the hood for people writing specific refactoring patterns, but it would seem overkill for general dev. Is there some syntax that looks closer to regexes for this (tree sitter inside regex rather than regex inside tree sitter)?
I wonder if attacking this problem at one level up say the LSP level could be a good idea.
I wonder if you could add escapes for specific syntax features, something like:
\z{FunctionName=Foo}
Yes a simpler syntax would be good - I was surprised at how complex the query got for the use case I designed it for. I do like the separation of queries and regex though, and keeping the whole structure as regex and queries inside plain text, as it starts you off in the simplest mode (just text) and lets you add flexibility as needed (although it does mean some chars have to be escaped).
Tree-sitter queries is an interesting addition. That and bazel build system queries seem like a step up in editing and compiling code.
Ideally other editors will take inspiration from it and add their own implementations. The code is available for reference here and I'd be happy to go over it in detail with anyone who wants to: https://gitlab.com/gushogg-blake/edita-release/-/tree/main/s....
It'd be pretty cool to be able to find-by-example, selecting snippets of code and having the algorithm tell you what they all have in common.
https://www.jetbrains.com/help/idea/structural-search-and-re...