From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: good "modern" example code for a programming-language mode? Date: Wed, 16 Feb 2011 09:56:05 -0500 Message-ID: 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 1297869879 1588 80.91.229.12 (16 Feb 2011 15:24:39 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 16 Feb 2011 15:24:39 +0000 (UTC) Cc: Michael Welsh Duggan , emacs-devel@gnu.org To: Miles Bader Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Feb 16 16:24:34 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 1PpjEv-0007lg-DH for ged-emacs-devel@m.gmane.org; Wed, 16 Feb 2011 16:24:25 +0100 Original-Received: from localhost ([127.0.0.1]:49371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PpivH-0000Ja-Tg for ged-emacs-devel@m.gmane.org; Wed, 16 Feb 2011 10:04:07 -0500 Original-Received: from [140.186.70.92] (port=49757 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PpinY-0005PJ-9O for emacs-devel@gnu.org; Wed, 16 Feb 2011 09:56:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PpinW-0003Pl-Rn for emacs-devel@gnu.org; Wed, 16 Feb 2011 09:56:08 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:49376 helo=ironport2-out.pppoe.ca) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PpinW-0003PY-Mx; Wed, 16 Feb 2011 09:56:06 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEANdzW01MCqmX/2dsb2JhbAClX3S8OoVeBIUIj0c X-IronPort-AV: E=Sophos;i="4.60,480,1291611600"; d="scan'208";a="91878391" Original-Received: from 76-10-169-151.dsl.teksavvy.com (HELO ceviche.home) ([76.10.169.151]) by ironport2-out.pppoe.ca with ESMTP/TLS/ADH-AES256-SHA; 16 Feb 2011 09:56:05 -0500 Original-Received: by ceviche.home (Postfix, from userid 20848) id 56BDF66188; Wed, 16 Feb 2011 09:56:05 -0500 (EST) In-Reply-To: <87wrl01dts.fsf@engster.org> (David Engster's message of "Wed, 16 Feb 2011 11:19:43 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 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:136105 Archived-At: > 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. 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. E.g. for Prolog, the tweaks I've needed until now are limited to: (defun prolog-smie-rules (kind token) (pcase (cons kind token) (`(:elem . basic) prolog-indent-width) (`(:after . ".") 0) ;; To work around smie-closer-alist. (`(:after . ,(or `":-" `"->" `"-->")) prolog-indent-width)) and for /bin/sh it currently looks like: (defun sh-smie-rules (kind token) (pcase (cons kind token) (`(:elem . basic) sh-indentation) (`(:after . "case-)") (or sh-indentation smie-indent-basic)) (`(:before . ,(or `"(" `"{" `"[")) (if (smie-rule-hanging-p) (smie-rule-parent))) ;; FIXME: Maybe this handling of ;; should be made into ;; a smie-rule-terminator function that takes the substitute ";" as arg. (`(:before . ,(or `";;" `";&" `";;&")) (if (and (smie-rule-bolp) (looking-at ";;?&?[ \t]*\\(#\\|$\\)")) (cons 'column (smie-indent-keyword ";")) (smie-rule-separator kind))) (`(:after . ,(or `";;" `";&" `";;&")) (with-demoted-errors (smie-backward-sexp token) (cons 'column (current-column)))))) You can check what's used in Modula-2 and Octave by looking for "smie-rules". For SML it is a good bit more complex, for some reason (even though SML was my original inspiration for SMIE). Maybe it's because the language's syntax tends to introduce a lot more indentation than is practical, so people have come up with all kinds of conventions for cases where indentation can be reduced without losing the property that indentation reflects internal structure. > Just looking at c-style-alist will make that clear. 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. Stefan