If you want to customize a MajorMode, you may have to execute some code whenever the major mode is activated. This is done using the major mode hook. It usually has the same name as the major mode with “-hook” appended. Thus, in order to change some things in text-mode, you’d add code to text-mode-hook.

Remember, most customizations can be set and saved using M-x customize-group. Only rarely will you need to put code on the hook. One such thing might be customization of font-lock keywords. See ShowWhiteSpace for an example.