I like the idea. Reminds me of a talk about syntax editor in racket but I forget what it was named. What languages can pantograph support?
rybla 36 days ago [-]
Currently, we've only instantiated the system for the simply-typed SML-like language that you can use in the tutorial (https://pantographeditor.github.io/Pantograph). Going through that tutorial will also give you a tour of the language features in there.
The next phase of work is on instantiating more complicated languages and type systems, to see how the framework can be extended. In theory, a lot (such as the entirety of SML) could be instantiated currently, but it would be quite cumbersome (here's what the implementation of the currently instantiated language looks like https://github.com/jeprinz/pantograph/blob/main/src/Language...). So we're working on trimming down the formalism and developing new abstractions to make things easier, and to support some more advanced typing systems that actually would have problems with the current system.
makizar 36 days ago [-]
(ninth RacketCon): Andrew Blinn - Fructure:
A Structured Editing Engine in Racket
Would anyone use this for real programming, if it supported your favorite programming language? I know "supported" is a loaded word there, but just take that to mean: supports all the basic edits you need, in composition, to make any complex edit, but not fancy refactors or fancy language-specific stuff.
schube 36 days ago [-]
I absolutely would. I feel like the text editing ecosystem is slowly inching towards this anyway with incremental improvements:
- Thanks to formatters like gofmt and prettier when I edit code I can do so with exactly zero concern for spacing, new lines, alignment, indent, etc. Close to structure editors where, in my understanding, the way code is stored and the way it is presented may be completely independent.
- Mass-renaming like what is provided by LSPs and other refactoring tools also go in this direction of thinking about symbols and their identity, rather than their text name.
- Tree-sitter lets traditionally text-oriented tools be re-created to be structure-aware, for example difftastic for diffs or ast-grep for structured search-and-replace.
I didn’t quite understand how the structure editor shown here works with types though, and though I’d love to edit my Typescript in a structure editor that just couldn’t work if my inputs got delayed by the Typescript type system figuring things out. I would take enforced type correctness if it can be instant, but I’d still use structure editing without type awareness.
ivanjermakov 35 days ago [-]
I utilize structural editing in nvim using some plugins:
No. I believe it was JetBrains that released a product like this years ago. I tried it briefly. Didn't like it.
Anything that even gets slightly in the way of my text is a big nuisance. Visual Studio likes to add their "Lenses" which may offer some OK information but it mucks up the vertical spacing so I have to disable it. The inlay type hints that some editors have is also great info but again, it just messes with my cursor positioning. And now we have all the LLM stuff -- the "ghost" text after my cursor I can mostly handle, particularly if its 1 line, but when it goes back and strikes out parts of my code that its suggesting I delete/refactor, it can get confusing. It is incredibly useful when it's correct though so depending on how much I trust it, I might tab to Accept and then try to make heads and tails of what it actually wrote.
These structured texts get in the way of copying and pasting and all kinds of stuff. I want to be able to find and replace with regexes, drop a cursor onto every line and just start typing (sometimes I copy and paste code into PLAINTEXT mode so that the editor doesn't try to get too clever while I'm doing a gross refactor).
I don't think I could get used to this. And I don't think I care if my code is momentarily uncompilable. Modern IDEs recover from errors pretty well. C++ can be a little slow to reparse after a refactor unfortunately, but I somehow don't think C++ inside a structured editor would be better.
daotoad 36 days ago [-]
I could see something like this operating like a WYSWYG HTML editor that either has a split screen or toggles between source and rendered views.
I think creating any sizable chunk of code in something like this would be likely to involve way too much clicking around.
But I can also see that it could be a really useful way to spot errors and a big help with refactoring tasks.
layer8 36 days ago [-]
Features like the mentioned tree selection do make sense. But I prefer tools to be more like a library than a rigid framework. Give me the ability to perform powerful transformations, but don’t put me in a straightjacket that disallows non-well-formed intermediate states.
TuringTest 36 days ago [-]
You might enjoy the experimental editor Lapis.
This Pantograph somewhat reminds me of that lightweight structure editor, though Lapis is able to find regularities on the fly without a need to follow a perfect tree structure, just by finding bottom-up syntax of language elements (mostly HTML and basic data types).
Super cool work! I'm always excited and a little terrified to see other people who share my sensibilities about which direction is forward in code editing : )
conartist6 36 days ago [-]
I'm taking my own stab at the same problem over in this org: https://github.com/bablr-lang/. It makes my head spin seeing the problem domain expressed in such a different way!
rybla 36 days ago [-]
Looks interesting, but I'm having trouble finding where to start reading about what's involved. Do you have a suggestion?
conartist6 36 days ago [-]
I keep trying to write docs but then I also keep making them out of date. The idea is that instead of each author of a tool like Pantograph building its own system of language support, (with each language author having to build support for each tool) our hope was that we could design some set of data structures, APIs, and capabilities which would allow a proper frontend/backend divide between languages and the the tools which consume their definitions.
The best place to get started is to see how CSTML works in the playground: https://bablr.org/playground. It's meant to be a self-describing format. It can be streamed, and we have a btree-backed storage format for it that makes incremental editing of immutable trees a breeze.
36 days ago [-]
yellowapple 35 days ago [-]
License?
rybla 35 days ago [-]
Thanks for the catch, added
rybla 36 days ago [-]
Pantograph is a new kind of structure editor where you directly edit a typed program. In order to accomplish this, it introduces a new kind of selection -- tree selection -- and a automatic typed refactoring system.
The link is the Pantograph tutorial. Follow the [about] link from the tutorial for more information on Pantograph's implementation and published formalization.
Yoric 36 days ago [-]
That is nice!
Would this work well with weirder type-based features, such as typeclasses, regions, etc?
rybla 36 days ago [-]
Thanks! We're working on extending the system to support more advanced type systems. In theory, the current system could already support these kinds of features (but not in quite as slick a way as modern languages, most likely), but it would be very cumbersome, so the work is in trimming down the formalization and taking advantage of new abstractions. Check out the implementation for a look at how defining the actual language (and typing rules) works currently https://github.com/jeprinz/pantograph/blob/main/src/Language...
36 days ago [-]
nikolay 36 days ago [-]
This is like what Chime [0][1] did, but it seems dead now, unfortunately.
The next phase of work is on instantiating more complicated languages and type systems, to see how the framework can be extended. In theory, a lot (such as the entirety of SML) could be instantiated currently, but it would be quite cumbersome (here's what the implementation of the currently instantiated language looks like https://github.com/jeprinz/pantograph/blob/main/src/Language...). So we're working on trimming down the formalism and developing new abstractions to make things easier, and to support some more advanced typing systems that actually would have problems with the current system.
https://youtu.be/CnbVCNIh1NA?si=JZxjUdTLbBp6IEaK
- Thanks to formatters like gofmt and prettier when I edit code I can do so with exactly zero concern for spacing, new lines, alignment, indent, etc. Close to structure editors where, in my understanding, the way code is stored and the way it is presented may be completely independent.
- Mass-renaming like what is provided by LSPs and other refactoring tools also go in this direction of thinking about symbols and their identity, rather than their text name.
- Tree-sitter lets traditionally text-oriented tools be re-created to be structure-aware, for example difftastic for diffs or ast-grep for structured search-and-replace.
I didn’t quite understand how the structure editor shown here works with types though, and though I’d love to edit my Typescript in a structure editor that just couldn’t work if my inputs got delayed by the Typescript type system figuring things out. I would take enforced type correctness if it can be instant, but I’d still use structure editing without type awareness.
- treesitter-textobjects with powerful select and expand selection motions: https://github.com/nvim-treesitter/nvim-treesitter-textobjec...
- sibling-swap fun name but does exactly that: https://github.com/Wansmer/sibling-swap.nvim
Both use Tree-sitter for AST provision and you can use it with any popular language or even write your own parser: https://tree-sitter.github.io/tree-sitter/
Anything that even gets slightly in the way of my text is a big nuisance. Visual Studio likes to add their "Lenses" which may offer some OK information but it mucks up the vertical spacing so I have to disable it. The inlay type hints that some editors have is also great info but again, it just messes with my cursor positioning. And now we have all the LLM stuff -- the "ghost" text after my cursor I can mostly handle, particularly if its 1 line, but when it goes back and strikes out parts of my code that its suggesting I delete/refactor, it can get confusing. It is incredibly useful when it's correct though so depending on how much I trust it, I might tab to Accept and then try to make heads and tails of what it actually wrote.
These structured texts get in the way of copying and pasting and all kinds of stuff. I want to be able to find and replace with regexes, drop a cursor onto every line and just start typing (sometimes I copy and paste code into PLAINTEXT mode so that the editor doesn't try to get too clever while I'm doing a gross refactor).
I don't think I could get used to this. And I don't think I care if my code is momentarily uncompilable. Modern IDEs recover from errors pretty well. C++ can be a little slow to reparse after a refactor unfortunately, but I somehow don't think C++ inside a structured editor would be better.
I think creating any sizable chunk of code in something like this would be likely to involve way too much clicking around.
But I can also see that it could be a really useful way to spot errors and a big help with refactoring tasks.
This Pantograph somewhat reminds me of that lightweight structure editor, though Lapis is able to find regularities on the fly without a need to follow a perfect tree structure, just by finding bottom-up syntax of language elements (mostly HTML and basic data types).
https://en.wikipedia.org/wiki/Lapis_(text_editor) (Look at the links for an archived download page)
The best place to get started is to see how CSTML works in the playground: https://bablr.org/playground. It's meant to be a self-describing format. It can be streamed, and we have a btree-backed storage format for it that makes incremental editing of immutable trees a breeze.
The link is the Pantograph tutorial. Follow the [about] link from the tutorial for more information on Pantograph's implementation and published formalization.
Would this work well with weirder type-based features, such as typeclasses, regions, etc?
[0]: https://www.chimehq.com/
[1]: https://github.com/ChimeHQ/Chime