* SMIE: Indentation after comments
@ 2020-10-06 15:34 Andreas Matthias
2020-10-06 15:59 ` Stefan Monnier
0 siblings, 1 reply; 2+ messages in thread
From: Andreas Matthias @ 2020-10-06 15:34 UTC (permalink / raw)
To: help-gnu-emacs
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?
============================================================
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)))
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: SMIE: Indentation after comments
2020-10-06 15:34 SMIE: Indentation after comments Andreas Matthias
@ 2020-10-06 15:59 ` Stefan Monnier
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2020-10-06 15:59 UTC (permalink / raw)
To: help-gnu-emacs
> 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)))
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-10-06 15:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-06 15:34 SMIE: Indentation after comments Andreas Matthias
2020-10-06 15:59 ` Stefan Monnier
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).