emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: good "modern" example code for a programming-language mode?


From: David Engster
Subject: Re: good "modern" example code for a programming-language mode?
Date: Wed, 16 Feb 2011 17:58:41 +0100
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.2 (gnu/linux)

Stefan Monnier writes:
>> Regarding indentation: this is much more a matter of taste than
>> semantics or syntax. If there was a direct connection between semantical
>> analysis and indentation, why were all those wars fought for the
>> "correct" indentation of C, for instance?
>
> OTOH there is a clear connection between syntax and indentation.

Yes, there is a connection, but it's only covering a certain amount of
indentation cases, depending on the language. Let's take comments, for
example. Just looking at the doc-string from c-lineup-C-comments, I
wonder what a grammar could help you here?  Or indenting continuation
lines; at least in Semantic those are usually dealt with in the lexer,
so the grammar doesn't even "see" those. In the end, you're still
looking around with some regexps to see where you're at.

> My experience (which lead me to write SMIE) is that all indentation
> styles for all languages share a lot of common principles, so that
> indentation can be (partly) automatically derived from the language's
> grammar.  And indeed, if you give a valid grammar to SMIE, it will
> give you a valid indentation function in return.  Of course, the
> indentation style it uses will most likely not fully match the user's
> expectations, so SMIE provides a hook to tweak the default indentation
> rules for the various possible situations.

This is really interesting. So you're generating something like
c-offsets-alist from a grammar?

> Indeed, for some reason C indentation is a lot more contentious than
> most other languages.  I haven't yet tried to use SMIE for C-like
> languages, so I'm not sure how well it would accommodate all the
> nitty-gritty details of each one's personal favorite indentation style.

C-like languages are an extreme case, for sure. I'm not saying a
semantic analysis won't help. It is absolutely possible to use Semantic
as an aid for indentation or highlighting (I use it for that in
minimap.el, for example). I just wanted to make clear that it's not
possible to base font-locking or indentation solely on Semantic, mainly
because it doesn't parse the whole buffer (usually not even close).

-David



reply via email to

[Prev in Thread] Current Thread [Next in Thread]