Live data from Hacker News

Why Don't We Have a General-Purpose Tree Editor? (2014)

pcmonk.me

141–150 of 222 posts

Re: Why Don't We Have a General-Purpose Tree Editor? (2014)

#141
There have been pure S-expression editors in LISP. INTERLISP worked that way. Yet EMACS, which is a text editor which knows a little about S-expressions, won out. INTERLISP's LISP editor had features never seen since, such as "Make this code subexpression a standalone function". This would pull the subexpression out and make it a named function, inserting the correct calls with the correct arguments in the original code. The inverse operation, "expand this function here", was also available. This eased refactoring.

There don't seem to be tree-oriented editors for XML. Or HTML. Or even JSON. That would be useful. At least the tree structure would always be correct. More effort is going into figuring out how to parse "bad JSON" than into writing editors for it.

Re: Why Don't We Have a General-Purpose Tree Editor? (2014)

#142

Check gingko, which is more focussed on docs, but is a tree editor at its core. https://gingkoapp.com/ Used it at university for notes, and is great for quick revisions before the exams too!

Whoops, I am a bad community member and posted before seeing this.

Yeah, Gingko is really phenomenal, especially for multiplayer!

Re: Why Don't We Have a General-Purpose Tree Editor? (2014)

#143
post #45

Check gingko, which is more focussed on docs, but is a tree editor at its core. https://gingkoapp.com/ Used it at university for notes, and is great for quick revisions before the exams too!

Looks great but it only does text. The link speaks of beyond ASCII. For this the old school PIM were better at storage of thoughts.

"old school PIM"? Wikipedia and I find this ambiguous [1].

1. https://en.wikipedia.org/wiki/PIM

Re: Why Don't We Have a General-Purpose Tree Editor? (2014)

#144
Trees are not all alike and I think this stops most such plans. Some trees have types and tags, quoting of other trees, container patterns that are representable as a tree but unpleasant to edit.

And we get stuck on that and say "Let's have a syntax." And then we're back to text again.

Re: Why Don't We Have a General-Purpose Tree Editor? (2014)

#145

There have been pure S-expression editors in LISP. INTERLISP worked that way. Yet EMACS, which is a text editor which knows a little about S-expressions, won out. INTERLISP's LISP editor had features never seen since, such as "Make this code subexpression a standalone function". This would pull the subexpression out and make it a named function, inserting the correct calls with the correct arguments in the original c…

This doesn't sound like a difficult macro/function to write. More, this has been replicated in other languages, now. These refactoring capabilities are considered a hallmark of the popular IDEs that people point to.

And keeping HTML "well formed" is a battle that lost hard with xhtml. Further, any "rich" editor likely kept the tree structure well formed. It did little to keep it manageable, though.

And I wager that most "bad JSON" is programmatically generated. This is literally a problem with countless solutions today. But, it is almost always quicker to println something out that you are certain you know the structure of, than it is to use a library. So, people don't. :(

Re: Why Don't We Have a General-Purpose Tree Editor? (2014)

#146

There have been pure S-expression editors in LISP. INTERLISP worked that way. Yet EMACS, which is a text editor which knows a little about S-expressions, won out. INTERLISP's LISP editor had features never seen since, such as "Make this code subexpression a standalone function". This would pull the subexpression out and make it a named function, inserting the correct calls with the correct arguments in the original c…

>features never seen since, such as "Make this code subexpression a standalone function". This would pull the subexpression out and make it a named function, inserting the correct calls with the correct arguments in the original code.

Isn't that a pretty basic refactoring feature of most IDEs?

Re: Why Don't We Have a General-Purpose Tree Editor? (2014)

#147
post #59

http://www.yworks.com/products/yed and GraphML ?

I second this.

I'm using yEd a lot, and I especially like layouting functions like hierarchical layout. I often use it to plan interdependent tasks. I just start with tasks I know are required and the thing of their prerequisites. Quite fast this gives a big graph structure. Then I run a hierarchical layout on this and suddenly I have a very clear structure of tasks. Their hierarchical layouting algorithm is great. I suspect it may be based on GraphViz dot's algorithm (http://www.graphviz.org/Documentation/TSE93.pdf) as it produces results of similar high quality.

I also love the UI of yEd. Zooming in and out, creating nodes and dependencies/edges feels just great.

Re: Why Don't We Have a General-Purpose Tree Editor? (2014)

#148
I don't want a general purpose tree editor. I want a general purpose text editor that understands the semantics of the text I'm editing. One that understands all the various not-necessarily-sexp-based code I'm editing is a tree and supports (ParEdit style) operations on that tree. Especially with languages in the Algol/C family. I think this can be accomplished (eventually) via language servers and editors that speak the Language Server Protocol (LSP) [0].

But I don't need a UI oriented around visually displaying tree-like things. Expanding / collapsing nodes is very meh. Moving / splitting / joining nodes is much more interesting and useful.

As a simple concrete example: changing the order of the parameters (and their type) in a function definition. Wouldn't it be great to 'swap-with-prev-node' or 'swap-with-next-node' rather than copy/paste and dealing with commas? The same operations could swap the order of two fields in a struct or two functions or two classes or any pair of adjacent nodes in a tree.

Or how about moving an 'if' block inside the 'for' block that follows it? Just execute the 'move-node-inside-next-node' (or whatever) command.

This only requires editors that (indirectly) understand the semantics of the text you're editing. Thus far the biggest barrier is all wheel re-invention needed for the cartesian product of all editors and all languages. But that's the wrong approach. We need each language to provide a tool that each editor can use via a common protocol.

This is precisely the point of the LSP. The functionality only needs to be written once per language and per editor. This is totally tractable. I don't know if LSP currently supports the specific tree-manipulation functionality I mentioned, but I'm confident it could.

Does anyone knowledgeable about LSP know if this is already possible, feasible, and/or generally desirable? Are there deal breakers that make this hard / not worthwhile?

[0] http://langserver.org/

Re: Why Don't We Have a General-Purpose Tree Editor? (2014)

#149
The key insight of this post for me is this: Code editing is tree editing! The reason why code is edited in text editors, is that tree editing interfaces are fundamentally difficult to do well, and often have to be carefully tuned to the properties of the particular trees and editing tasks. (Simple examples: Huge fanout vs. at most 2 children. Very large information-rich nodes vs. tiny nodes.)

In the early days of programming text editors, we dealt with this difficulty by exploiting the human brain's mechanisms for dealing with serialized trees -- which is to say the human brain's facilities for processing language and reading and writing text. By doing this, we could represent all kinds of hierarchically structured code, and let the human brain process it. But even in these early days, we started bringing in visual aids for reading structure: indentation and braces.

Now, if you look at modern IDEs, you'll find even more geometric/visual representation of the tree structure of code, in the form of collapsible tree controls operating on the code. This isn't to naively say that graphical programming is the way to go, since the potential for interrelation and complexity of structure in code is far too high to comfortably represent in 2 or even 3 dimensions. The way forward is to be able to dynamically visualize very specific contexts. (One example I can think of of the top of my head, would be to quickly visualize all "subscribers" of an Observer, then be able to visualize the 2nd order "users" of those subscribers. Another would be to visualize patterns in code supporting dataflows as an explicit flow graph.)

Re: Why Don't We Have a General-Purpose Tree Editor? (2014)

#150
post #133

I think it's important to distinguish between "tree-structured data" and "tree-structured UI"; many of the suggestions here and in the article's comments mention s-expressions (or alternatives e.g. using indentation or similar); many others mention diagramming/mindmapping tools. I think the real issue is how disconnected such approaches are from each other: why can't I press a key and have my parenthesised expression…

> Fold/unfold terms/trees (code folding, but for expressions rather than lines) Emacs can hide/show blocks in Lisp expressions (and others). Install HideShow ( https://www.emacswiki.org/emacs/HideShow ). I personally never use it, generally the right solution is to refactor (but there might be good use cases too). > As a more elaborate idea, we could allow plugins to extend the tree/graph structure with "virtual" nod…

> Emacs can hide/show blocks in Lisp expressions (and others). Install HideShow (https://www.emacswiki.org/emacs/HideShow).

Yes, I've used it before and it's quite nice.

I've not used Slime, or done any Common Lisp programming for that matter.

I do love Emacs, and calling out to a sub/inferior-process for language-specific info is a good idea; it can just be frustrating to actually get the darn things to work though. After failing to get Geiser to work for Racket, or ghc-mod || intero || dante for Haskell, I've resigned myself to being happy with just syntax colouring :(

Post reply on HN