help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SMIE: Indentation after comments


From: Stefan Monnier
Subject: Re: SMIE: Indentation after comments
Date: Tue, 06 Oct 2020 11:59:14 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]