Tying to write a new mode, I am stuck at:

(define-derived-mode NEWS-mode
  text-mode "NEWS"
  "Major mode for NEWS file."
  (setq tab-stop-list '(2 6 59 65))
  (setq indent-tabs-mode nil)
  (setq indent-relative 'tab-to-tab-stop)

Pressing TAB in the 1st line of the file has the desired result of jumping to column 2, 6, 59 then 65.

But when pressing TAB in a line with text above it, then it jumps to the word-start positions of the previous line and ignores tab-stop-list.

I found Disable `indent-relative` and it says one should not re-define indent-relative (which does not do what I want anyway).

So how to ditch that indent-relative behaviour?

1 Answer 1


You can find information about Emacs indentation commands here. To get the desired indent behavior you want to use the function bound to M-i (tab-to-tab-stop).

The docstring of indent-for-tab-command (TAB), mentions that for indentation it calls the function set by the indent-line-function. By default, this variable is set to indent-relative. Simply set it to tab-to-tab-stop to achieve the desired behavior.

(setq indent-line-function 'tab-to-tab-stop)

I guess you could locally set this (use setq-local) within your major-mode definition.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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