I've begun adding folding support to the Makefile mode, specifically by adding a
Command state to indicate the blocks of build commands for a target. I have a
few questions and observations.
First, the keywords are not colored as I would expect. As a specific example of
the issue, consider the following two lines:
SHELL=/bin/sh
SHELL = /bin/sh
The SHELL in the first line is colored as a keyword, the SHELL in the second is
not. Some keywords don't ever seem to be colored. This happens with the
unmodified Makefile mode as downloaded from the codingmonkeys.de website, before
I make any changes. I really don't have any idea why this is. The definitions
seem consistent with how keywords are given in other modes, so I suspect it may
have something to do with the state definitions.
Second, where should states actually be defined? The C mode has all states as
substates of the default state. The current Makefile mode has a default mode and
two other modes (SingleComment and String) at the same level. What makes more
sense, here?
I relatively arbitrarily decided that I'd put the new state at the same level as
the other three, and not as a substate of the default state. After some
experimentation, I've arrived at this:
<state id="Command" type="block" foldable="yes">
<begin><regex>(?:^\t)</regex></begin>
<end><regex>[\n\r](?=[^\t])</regex></end>
<import keywords-only="yes" />
<state-link state="SingleComment" />
<state-link state="String" />
</state>
That is, a command block starts with a tab at the beginning of a line and ends
with a linefeed or carriage return that is not followed by a tab. The keywords
are imported from the default state, and the SingleComment and String states are
linked. Note that a single <import /> wouldn't work, as it would lead to nested
blocks instead of keeping consecutive tab-indented lines in the same block.
As I understand the file format, as described at
<http://codingmonkeys.de/subethaedit/mode.html>, it should have been possible to
use imports instead of the state links, but it did not work. Why is this?
The end regex for the Command state is quite similar to that for the
SingleComment state, which ends with [\n\r]. The similarity produces an edge
case where a command block cannot end with a comment line; in such a case, the
following line is taken as part of the command block. It seems clear enough why
this is: the final linefeed of the command block is taken to close the comment,
so another one is needed to close the command block. That makes sense;
otherwise, it would not be possible to, e.g., nest curly braces. Should I just
accept this edge case, or is there a solution?
Incidentally, I think the definition is wrong. I don't think a carriage return
\r is a valid line ending for a makefile. It is not in GNU Make, at least. I
just followed what was already in the SingleComment state. Can anyone provide an
authoritative answer to this?