I've written a very simple mode using SMIE (see code below) that produces some weird indentation after comments that I do not understand. Here is an example:

int a /**/ ;
int b;

int a /**/;
      int b;

Why is the last line indented? I expected the last line to look like the second line.

Here is the code to replicate this result:

(require 'smie)

(setq foobar-grammar
    `((insts (insts ";" insts) (inst))
      (inst ("int" id))
    '((assoc ";")))))

(defun foobar-rules (kind token)
  (message "rule: (%s . %s) at point %d" kind token (point))
  (pcase (list 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-ensure (point-min) (point-max)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.