skeeto / nasm-mode

Major mode for editing NASM assembly programs
The Unlicense
79 stars 17 forks source link

labels with percent sign are not formatted correctly #6

Open travisdowns opened 8 years ago

travisdowns commented 8 years ago

The default for nasm-mode seems to be to format labels fully left-aligned (starting in the first column), like so:

foo:
    xor eax, eax

So far, so good. If a label contains a % character, however, the indentation changes - the labels are now aligned one tab in, same as assembly instructions, like so:

    foo%1:
    xor eax, eax

Probably this happens because nasm-mode doesn't detect it as a valid label - but such labels are common, for example, in macro definitions.

skeeto commented 8 years ago

Hmmm, this is a tricky one. I knew dealing with NASM macros would be messy, which is why I mostly ignored the problem, but I didn't think of this case. Perhaps it should count % as part of a label, just to deal with this common use case?

travisdowns commented 8 years ago

I think it depends what the current parsing logic is? It seems like in nasm, outside of a macro the % character does terminate a label (and likely results in an error since % isn't a valid character after a label).

So I think you could treat %[number] as part of a label. In the weird case where you weren't in a macro, but you wrote that anyway, that's gonna be a compile error, but I think for formatting purposes, treating it like a label still makes sense (e.g., you should still format stuff best-effort even if it won't compile).