unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: SMIE: Indentation after comments
Date: Tue, 06 Oct 2020 11:59:14 -0400	[thread overview]
Message-ID: <jwvtuv7tkkk.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: CAHp59H2QpAofVuczdUyx3cKPpHdk9xuX-e0wn9ChnzPtPgG3Gg@mail.gmail.com

> The last line of the following example is not indented correctly
> whereas the second line is correct. The difference is just a space
> before the semi-colon. How can I fix this?

You're using the default lexer, which is almost never the right thing
to do.  It does a good "90%" job, but that's it.


        Stefan


> ============================================================
> int a /**/ ;
> int b;
>
> int a /**/;
>       int b;
> ============================================================
>
> Here is the code:
>
> (require 'smie)
>
> (setq foobar-grammar
>   (smie-prec2->grammar
>    (smie-bnf->prec2
>     `((insts (insts ";" insts) (inst))
>       (inst ("int" id))
>       (id))
>     '((assoc ";")))))
>
> (defun foobar-rules (kind token)
>   (message "rule: (%s . %s) at point %d" kind token (point))
>   (pcase (cons kind token)
>     ;; ???
>     ))
>
> (define-derived-mode foobar-mode prog-mode "foobar"
>   :syntax-table nil
>   (modify-syntax-entry ?/ ". 124")
>   (modify-syntax-entry ?* ". 23b")
>   (modify-syntax-entry ?\n ">")
>   (setq comment-start "//")
>   (smie-setup foobar-grammar #'foobar-rules)
>   (font-lock-add-keywords nil '(("int" . font-lock-keyword-face)))
>   (font-lock-mode)
>   (font-lock-ensure (point-min) (point-max)))




      reply	other threads:[~2020-10-06 15:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-06 15:34 SMIE: Indentation after comments Andreas Matthias
2020-10-06 15:59 ` Stefan Monnier [this message]

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=jwvtuv7tkkk.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=help-gnu-emacs@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.
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).