However, I've noticed that the overlay doesn't apply to one-line comments at the end of a line of normal code. If I place the delimiter on the next line, it works, but it yields an undesired extra space, and using emptylines=1 does not rid me of the latter.

Is there a way to also highlight the comments that are on the same line as normal code?

The @ after a % is simply not processed by the moredelim option, so the next one is used (which is the reason the first c = 1 line isn’t even highlighted). You could do @@b and @@c with omitting the last @ (to avoid an empty line at the end).
–
QrrbrbirlbelMar 2 '13 at 4:17

Yes I know. My approach would be: 1 - detect if after '@' there is a blank line; 2 - If true, remove the line, like 'emptylines=1' does. But I have no clue how to implement it.
–
cacamailgMar 2 '13 at 14:35

1 Answer
1

As stated by Qrrbrbirlbel in his comment, the problem is that, because % is a (one-line) comment delimiter in the Octave language, listings treats your closing overlay delimiter @ as part of the comment.

One workaround is to undefine % as a comment delimiter, but use literate to apply the comment style when that character is encountered anyway. You also need to reset the style at the beginning of each line.

Two caveats of this approach:

any % character that occurs within a string literal will mess up the highlighting,