emacsindentationmajor-mode

How to set tab behaviour in a custom major mode?


Currently in the major mode I am writing pressing tab moves the point a certain number of spaces.

What I want to happen is more like how python mode makes it so that tab moves the whole line to the correct indentation.

Does anyone know how this is done?


Solution

  • Set indent-line-function appropriately in the major mode function, e.g. with something like

    (defun my-mode-indent-line (&optional _arg)
      ...)
    
    (define-derived-mode my-mode prog-mode "MyMode"
      "Have fun with My Mode."
      ...
      (setq-local indent-line-function #'my-mode-indent-line)
      ...)