by gopiandcode · 6y ago · 0 comments
Have you had a look at the various Emacs plugins for editing lisp? Given the simplicity of the syntax, it would be fairly simple to make a lisp editor only performs AST-based transformations, however most lisp plugins support a mixture of both AST and line-based transformations. I find this approach to be very natural, allowing me to rely on the AST when I need it, and then being able to ignore it when I don't need it. My main motivation for gopcaml-mode was just to achieve a similar editing experience for OCaml code.
Question about your approach: what happens if the code is syntactically invalid? Dark prevents code from being syntactically invalid cause it's AST only, but for example ocamlformat just refuses to run if it can't parse the whole file.
In the future I plan to move over to the Merlin parser, which has partial support for syntactically invalid buffers (I believe it wraps invalid regions with another syntactic construct), so it should still be possible to move around in other parts of the buffer.
As an aside, as I mentioned on the OCaml forum, I haven’t found this to be a major issue as I find that most of the time when I’m moving around (i.e not inserting text), the code is usually syntactically correct - I’ve also bound M-RET to insert a type hole (??) to easily allow movement even when I haven’t completed a function definition, and overall this leads to quite a natural editing experience.