Emacs TAB Issue in Makefile#

Introduction to Emacs and Makefile TAB Issues#

During work with Emacs and Makefile, you may encounter an issue with the TAB key. This post will show you how to notice this issue and how to fix it.

Why Your Makefile Might Fail to Run#

When one is working with shell and runs make command, one can see following error:

$ make
Makefile:5: *** missing separator.  Stop.

Above error is caused by the issue with the TAB key in the Makefile.

Editing the Makefile for Compatibility#

Emacs is good editor with built-in support for Makefiles. However there is an issue with the TAB key in the Makefile.

Even when one opens Makefile and press TAB key, it is not always working as expected. And this is not easy to notice.

Please see the following screenshot:

Hint

To make this bigger please right click on screenshot and open in new tab

emacs-makefile-tab-issue.jpeg

On the screenshot above, one can see:

  1. There are four dots in the beginning of the line which are not visible in the editor (without special mode) And even when TAB was pressed from some reason Emacs converted it to spaces.

  2. Line below one needed to force TAB key to be inserted by pressing C-q TAB key sequence (C-q stands for CTRL-q)

  3. Emacs is aware that is working with Makefile

  4. Emacs is having makefile-mode enabled

This is something which is not easy to notice and can cause issues with running Makefile.

Visualizing Whitespace in Emacs#

Above points allowed to notice the issue with the TAB key in the Makefile. However Emacs needs to be configured to show whitespace characters which are not visible by default.

To enable this feature please run following command: M-x whitespace-mode

Steps to Resolve the TAB Issue#

Once the whitespace characters are visible, one can run following commands to fix the issue:

  1. Move cursor to the beginning of file M-<

  2. Select full buffer: M-SPC and M->

  3. Run command M-x tabify

Final Thoughts on Emacs TAB Fixes#

This post showed how to notice and fix the issue with the TAB key in the Makefile when working with Emacs.

Additional Resources#