From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Engster Newsgroups: gmane.emacs.devel Subject: Re: good "modern" example code for a programming-language mode? Date: Wed, 16 Feb 2011 17:58:41 +0100 Message-ID: <87oc6b29xa.fsf@engster.org> References: <87d3mtc4zw.fsf@maru.md5i.com> <87zkpwztya.fsf@catnip.gol.com> <87wrl01dts.fsf@engster.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1297875603 5243 80.91.229.12 (16 Feb 2011 17:00:03 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 16 Feb 2011 17:00:03 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Feb 16 17:59:57 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PpkjJ-0005TW-Mw for ged-emacs-devel@m.gmane.org; Wed, 16 Feb 2011 17:59:57 +0100 Original-Received: from localhost ([127.0.0.1]:56749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PpkjD-0001pw-7l for ged-emacs-devel@m.gmane.org; Wed, 16 Feb 2011 11:59:47 -0500 Original-Received: from [140.186.70.92] (port=37984 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ppkj4-0001o2-Mu for emacs-devel@gnu.org; Wed, 16 Feb 2011 11:59:40 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ppkj0-0005r7-HT for emacs-devel@gnu.org; Wed, 16 Feb 2011 11:59:35 -0500 Original-Received: from v3-1008.vxen.de ([79.140.41.8]:45958) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ppkj0-0005qz-5r for emacs-devel@gnu.org; Wed, 16 Feb 2011 11:59:34 -0500 Original-Received: from dslc-082-082-180-097.pools.arcor-ip.net ([82.82.180.97] helo=spaten) by v3-1008.vxen.de with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1Ppkiw-0000n6-QU for emacs-devel@gnu.org; Wed, 16 Feb 2011 17:59:31 +0100 In-Reply-To: (Stefan Monnier's message of "Wed, 16 Feb 2011 09:56:05 -0500") User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.2 (gnu/linux) Mail-Followup-To: emacs-devel@gnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-Received-From: 79.140.41.8 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:136111 Archived-At: 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