all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Engster <deng@randomsample.de>
To: emacs-devel@gnu.org
Subject: Re: good "modern" example code for a programming-language mode?
Date: Wed, 16 Feb 2011 17:58:41 +0100	[thread overview]
Message-ID: <87oc6b29xa.fsf@engster.org> (raw)
In-Reply-To: <jwvaahwjb2w.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Wed, 16 Feb 2011 09:56:05 -0500")

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



  parent reply	other threads:[~2011-02-16 16:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-15  9:11 good "modern" example code for a programming-language mode? Miles Bader
2011-02-15 17:43 ` Stefan Monnier
2011-02-16  5:16   ` Miles Bader
2011-02-15 22:22 ` Michael Welsh Duggan
2011-02-16  0:47   ` Miles Bader
2011-02-16 10:19     ` David Engster
2011-02-16 13:59       ` Andy Moreton
2011-02-16 15:00         ` David Kastrup
2011-02-16 14:56       ` Stefan Monnier
2011-02-16 15:54         ` Tassilo Horn
2011-02-16 21:00           ` Stefan Monnier
2011-02-16 16:58         ` David Engster [this message]
2011-02-16 21:07           ` Stefan Monnier
2011-02-17  3:42       ` Miles Bader

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oc6b29xa.fsf@engster.org \
    --to=deng@randomsample.de \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.