From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?utf-8?Q?Johan_Bockg=C3=A5rd?= Newsgroups: gmane.emacs.devel Subject: Re: SMIE documentation Date: Wed, 01 Dec 2010 01:39:30 +0100 Message-ID: <87bp56mim5.fsf@gnu.org> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1291185503 26375 80.91.229.12 (1 Dec 2010 06:38:23 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 1 Dec 2010 06:38:23 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Dec 01 07:38:19 2010 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 1PNgKY-0000BD-PY for ged-emacs-devel@m.gmane.org; Wed, 01 Dec 2010 07:38:19 +0100 Original-Received: from localhost ([127.0.0.1]:35538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PNgKY-0005nA-6p for ged-emacs-devel@m.gmane.org; Wed, 01 Dec 2010 01:38:18 -0500 Original-Received: from [140.186.70.92] (port=35883 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PNdIP-0002L9-Hf for emacs-devel@gnu.org; Tue, 30 Nov 2010 22:24:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PNajN-000856-0B for emacs-devel@gnu.org; Tue, 30 Nov 2010 19:39:34 -0500 Original-Received: from smtprelay-b12.telenor.se ([62.127.194.21]:42645) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PNajM-00082A-L1 for emacs-devel@gnu.org; Tue, 30 Nov 2010 19:39:32 -0500 Original-Received: from ipb4.telenor.se (ipb4.telenor.se [195.54.127.167]) by smtprelay-b12.telenor.se (Postfix) with ESMTP id 92CDCC3F9 for ; Wed, 1 Dec 2010 01:39:31 +0100 (CET) X-SENDER-IP: [85.228.202.182] X-LISTENER: [smtp.bredband.net] X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArAzALYn9UxV5Mq2PGdsb2JhbACIHppvDAEBAQE1LcQFgwQIgjsEhRQ X-IronPort-AV: E=Sophos;i="4.59,282,1288566000"; d="scan'208";a="1695949146" Original-Received: from c-b6cae455.04-211-6c6b701.cust.bredbandsbolaget.se (HELO muon.localdomain) ([85.228.202.182]) by ipb4.telenor.se with ESMTP; 01 Dec 2010 01:39:31 +0100 Original-Received: by muon.localdomain (Postfix, from userid 1000) id 5189F484282; Wed, 1 Dec 2010 01:39:30 +0100 (CET) Mail-Copies-To: never 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-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:133253 Archived-At: Stefan Monnier writes: > While Savannah is down, maybe someone will feel like checking my attempt > at documenting SMIE. I have a few comments on the documentation and the functionality itself. First, here's a patch to make smie-next-sexp correctly return (t POS TOKEN) when bumping into a closing thingy in the forward direction. --- a/lisp/emacs-lisp/smie.el +++ b/lisp/emacs-lisp/smie.el @@ -653,7 +653,8 @@ Possible return values: (if (and halfsexp (numberp (funcall op-forw toklevels))) (push toklevels levels) (throw 'return - (prog1 (list (or (car toklevels) t) (point) token) + (prog1 (list (or (funcall op-forw toklevels) t) + (point) token) (goto-char pos))))) (t (let ((lastlevels levels)) There's a problem with the indentation when there's comment at the start of a line before a keyword, like (* Comment *) IF ... <-- Press TAB The virtual indent of the following keyword is computed as its current column. The comment indentation function tries to align the comment with this column, making the line wander farther and farther to the right for every press of the TAB key. > +Calling this function is sufficient to make commands such as > +@code{forward-sexp}, @code{backward-sexp}, and @code{transpose-sexps} > +be able to properly handle structural elements other than just the paired > +parentheses already handled by syntax tables. E.g. if the provided > +grammar is precise enough, @code{transpose-sexps} can correctly > +transpose the two arguments of a @code{+} operator, taking into account > +the precedence rules of the language. This makes C-M-f and friends behave very differently from most other major modes, which doesn't really feel right. > +To describe the lexing rules of your language to SMIE, you will need > +2 functions, one to fetch the next token, and another to fetch the > +previous token. Those functions will usually first skip whitespace and > +comments and then look at the next chunk of text to see if it > +is a special token, if so it should skip it and return a description of > +this token. Usually this is simply the string extracted from the > +buffer, but this is not necessarily the case. It would be good if users could hook their own functions into all places that extract text from the buffer ("buffer-substring"), and not just smie-forward/backward-token-function; e.g. to use interned token strings or to handle some kind of banana brackets using the syntax table. > +@code{:elem}, in which case the function should return either the offset > +to use to indent function arguments (if @var{arg} is the symbol > +@code{arg}) Either there's a bug in the code, or this should be the symbol "args" and likewise for the doc string. > +@defun smie-rule-parent &optional offset > +Return the proper offset to align with the parent. > +If non-@code{nil}, @var{offset} should be an integer giving an > +additional offset to apply. > +@end defun The function returns an absolute column, not an offset. > + (:before > + (cond > + ((equal token ",") (smie-rule-separator kind)) > + ((member token '("begin" "(" "@{")) > + (if (smie-rule-hanging-p) (smie-rule-parent))) Does this really work for "("? Most of the time smie-indent--parent seems to returns nil before a paren, which breaks smie-rule-parent.