From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: SMIE documentation
Date: Tue, 07 Dec 2010 14:27:04 -0500 [thread overview]
Message-ID: <jwvr5dte6qi.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87bp56mim5.fsf@gnu.org> ("Johan Bockgård"'s message of "Wed, 01 Dec 2010 01:39:30 +0100")
> 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))
I do not understand what case this intends to solve. When I try to
"bump into a closing thingy in the forward direction" with the current
code, it seems to work correctly.
> 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.
Good catch, thanks. Don't have a fix yet, sadly.
>> +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.
I think it doesn't feel right because you're not yet used to it.
What it does is make C-M-[fbt] behave similar to how they behave in
Lisp languages. It's very intuitive when skipping over begin...end.
It's admittedly less obviously intuitive for infix/mixfix constructs.
>> +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.
I do not understand what you're referring to.
>> +@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.
I meant @code{args}, indeed.
>> +@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.
It does not return an absolute column (which would be a number) but
a cons cell (column . N), i.e. it returns an "offset" in the sense of:
@var{offset} can be:
@itemize
@item
@code{nil}: use the default indentation rule.
@item
@code{(column . @var{column})}: indent to column @var{column}.
@item
@var{number}: offset by @var{number}, relative to a base token which is
the current token for @code{:after} and its parent for @code{:before}.
@end itemize
>> + (:before
>> + (cond
>> + ((equal token ",") (smie-rule-separator kind))
>> + ((member token '("begin" "(" "@{"))
>> + (if (smie-rule-hanging-p) (smie-rule-parent)))
> Does this really work for "("?
It works in those cases where I've used it, yes.
> Most of the time smie-indent--parent seems to returns nil before
> a paren, which breaks smie-rule-parent.
That would be a bug, indeed. Please post a test case to reproduce it.
Stefan
next prev parent reply other threads:[~2010-12-07 19:27 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
2010-12-07 19:27 ` Stefan Monnier [this message]
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=jwvr5dte6qi.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--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).