13.4 Auto-Indentation

forth-mode automatically tries to indent lines in a smart way, whenever you type TAB or break a line with C-m.

Simple customization can be achieved by setting ‘forth-indent-level’ and ‘forth-minor-indent-level’ in your .emacs file. For historical reasons gforth.el indents per default by multiples of 4 columns. To use the more traditional 3-column indentation, add the following lines to your .emacs:

(add-hook 'forth-mode-hook (function (lambda ()
   ;; customize variables here:
   (setq forth-indent-level 3)
   (setq forth-minor-indent-level 1)
)))

If you want indentation to recognize non-default words, customize it by setting ‘forth-custom-indent-words’ in your .emacs. See the docstring of ‘forth-indent-words’ for details (in Emacs, type C-h v forth-indent-words).

To customize indentation in a file-specific manner, set ‘forth-local-indent-words’ in a local-variables section at the end of your source file (see Variables in Emacs Manual).

Example:

0 [IF]
   Local Variables:
   forth-local-indent-words:
      ((("t:") (0 . 2) (0 . 2))
       ((";t") (-2 . 0) (0 . -2)))
   End:
[THEN]