I've defined my own major mode using define-generic-mode, and in the setup function I have (set (make-local-variable 'indent-line-function) 'my-indent-function).

This works fine in general code, however it is not called at all when I'm inside a comment, as defined by the syntax table with:

;; // Comments (style a)
(modify-syntax-entry ?\/ ". 124" (syntax-table))
(modify-syntax-entry ?\n "> " (syntax-table))
;; /* Comments (style b) */
(modify-syntax-entry ?* ". 23b" (syntax-table))

Either // line comments or /* Java comments */ are allowed.

I've tried setting comment-line-break-function as I saw that it is set in Java mode, but this doesn't have any effect. I also tried setting comment-indent-function to nil, but again I couldn't see any effect.

EDIT: Added example minimal repro.

To test, just run emacs -Q, paste the following into a buffer and run eval-buffer, then open test.tmp. Every time you hit return not inside a comment you will see "Called indent-line!" in the mini-buffer. Inside a comment you will not. This is my question.

    tmp-mode ; mode name

  ;; comments

  ;; keywords
  '("if" "then" "else")

  ;; other things to highlight

  ;; auto mode alist

  ;; other function to run
  (list 'tmp-mode--setup-function)
  "A mode for tmp files")

(defun tmp-mode--setup-function ()
  (modify-syntax-entry ?_ "w" (syntax-table))
  ;; // Comments (style a)
  (modify-syntax-entry ?\/ ". 124" (syntax-table))
  (modify-syntax-entry ?\n "> " (syntax-table))
  ;; /* Comments (style b) */
  (modify-syntax-entry ?* ". 23b" (syntax-table))
  (modify-syntax-entry ?@ "_" (syntax-table))

  (set (make-local-variable 'indent-line-function) 'tmp-mode/indent-line))

(defun tmp-mode/indent-line ()
  (message "Called indent-line!"))

(provide 'tmp)

May reproduce your problem meanwhile - answer edited. While without electric-indent-mode indent-according-to-mode would call indent-line-function- if electric-indent-mode is on, no indent any more. IIUC it's worth a bug-report.

| improve this answer | |
  • I'm not sure if you saw, but I defined my own indentation function as this is my own major mode. The indentation function is not called on newline at all inside comments when in electric-indent-mode, while every other newline does. – rneatherway Jun 11 '15 at 13:30
  • @meatherway Maybe post your indent-function, so we can have a look? – Andreas Röhler Jun 11 '15 at 14:51
  • The trouble is that the indent-function is never even being called. I will update with a minimal repro major-mode tomorrow morning. – rneatherway Jun 11 '15 at 18:57
  • Right, I've added a repro – rneatherway Jun 12 '15 at 15:31

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.