unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Johan Bockgård" <bojohan@gnu.org>
To: emacs-devel@gnu.org
Subject: Re: SMIE documentation
Date: Wed, 01 Dec 2010 01:39:30 +0100	[thread overview]
Message-ID: <87bp56mim5.fsf@gnu.org> (raw)
In-Reply-To: jwvwrnxur2f.fsf-monnier+emacs@gnu.org


Stefan Monnier <monnier@IRO.UMontreal.CA> 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.




  parent reply	other threads:[~2010-12-01  0:39 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-28 20:36 SMIE documentation Stefan Monnier
2010-11-28 21:56 ` Štěpán Němec
2010-12-04 18:01   ` Stefan Monnier
2010-12-04 19:46     ` Drew Adams
2010-12-04 20:21       ` Andreas Schwab
2010-12-04 21:36         ` Drew Adams
2010-12-04 21:04       ` Bob Rogers
2010-12-04 19:56     ` Štěpán Němec
2010-12-06 18:26       ` Stefan Monnier
2010-11-29 17:54 ` Chong Yidong
2010-11-29 21:34   ` Stefan Monnier
2010-12-07 17:54   ` Stefan Monnier
2010-12-01  0:39 ` Johan Bockgård [this message]
2010-12-07 19:27   ` Stefan Monnier
2012-05-13 11:51     ` Johan Bockgård
2012-05-15 13:25       ` Stefan Monnier
2010-12-01 19:23 ` Johan Bockgård
2010-12-04  4:41   ` Stefan Monnier

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87bp56mim5.fsf@gnu.org \
    --to=bojohan@gnu.org \
    --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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).