If one highlights a tab-indented line in makefile-mode
and runs a comment function (eg. comment-dwim
, comment-line
, comment-region
, etc.), the comment symbol (#
) is inserted after the initial tab, like so:
target:
# echo This "commented" line will be passed to the shell
As explained in this illuminating answer, Make does not recognise this line as a comment, and the line will be passed to the Shell to interpret on its own terms. makefile-mode
helpfully highlights the leading tab to alert us.
What would be the simplest way to alter the behaviour of Emacs for Makefiles, so that for whole lines within the region the inbuilt comment functions cause the comment symbol to be added at the very start of the line, creating true Makefile comments, rather than shell comments?
#
above the region you need to comment, then select the region together with that new line.