by mickeyp · 12y ago · 0 comments
It's a shame Emacs lacks the facility to properly capture the more complex requirements of languages today - especially files with mixed content, such as HTML, Javascript and templating tools. The few that do support this do it using a variety of clever hacks to work around this problem; and still, using regular expressions to capture the nuances and complexities of some languages make it an error-prone way of writing major modes in Emacs. Not to mention you lose out on the many advantages of having an AST in memory for code jumping, refactoring, syntax checking and what have you.
Emacs could do with a shake-up in this space. The proposed solution (Semantic Mode / CEDET) has never really caught on, even though it adds much of the same functionality to Emacs; my suspicion is that this is because Semantic/CEDET is ridiculously complex and lacking in documentation.
So, sooo much this. And it's a real shame, because semantic is quite a usable tool once you get to know it.
One thing I really wanted to have was a semantic index, a database of semantic symbols inside a project. I wanted to be able to write "Form" and have it display all the class names containing "Form". Grepping (even ag) is just much too slow and building my own index was too much work. I then saw "semanticdb" module.
A week, I'm not kidding, a week - instead of half an hour - later I finally managed to preload a custom tag database and to query it. And that was with Python code, which has Semantic parser already, which is well integrated into the rest of CEDET.
Now I'm fighting with CoffeeScript/LiveScript support. They both expose their parsers - I can get their AST with one line of code. After another week I still don't have working Semantic plugin for them.
When I last checked, the activity on a CEDET and Semantic mailgroup was almost non-existent. The home page for CEDET looks like it comes from last century and even info pages are not a big help.
It's a friggin shame, because when Semantic works, it does work well.
http://news.gmane.org/gmane.emacs.cedet
Sure, it's not LKML, but still, questions usually get answered.
> Now I'm fighting with CoffeeScript/LiveScript support. They both expose their parsers - I can get their AST with one line of code. After another week I still don't have working Semantic plugin for them.
I'm afraid an AST is just the beginning for properly supporting a language. If you need help, don't hesitate to ask on the mailing list.
> The home page for CEDET looks like it comes from last century and even info pages are not a big help.
Yes, unfortunately.
What Yegge's project shows is: that EMACS does not lack the facility to do what is needed [LISP is it's command language after all], and that implementing the task is non-trivial even for skilled programmers.
It's just that historically it just wasn't done. The rise of IDEs tied closely to the compiler/environment changed that equation and now it's Emacs that's behind the curve.
Parsers have been used to do semantic highlighting of symbols, e.g. paint identifiers in different colors depending on whether they're interfaces or classes, etc. But the big win for parsing isn't highlighting, it's completion. You can't do super useful completion without a fairly rich parse tree, and not just for the current file, but also for all the libraries.
And while it may be trivial against some other metric to deal with AST's in another language, the solution tends to be a one-off, that is dealing with the AST of C++ doesn't offer an advanced starting position for dealing with the AST of JavaScript - most of the work is in the details of a particular language not at the higher level abstractions of languages in general.
I'd also point to Ensime as an example of a language plugin that uses an external parser to check code.