wwwjfy / emacs-fish

fish-mode for emacs
99 stars 15 forks source link

odd highlighting of nested process substitution in for loops #45

Open marienz opened 3 years ago

marienz commented 3 years ago

Highlighting of for loops over process substitution gets a little confused if there's more than one level. Example (from a real script):

    for i in (seq (count $PATH) -1 2)

This is currently highlighted with font-lock-string-face from the first open parenthesis up to the first closing parenthesis (after $PATH), then normally after that. This looks "off" to me: I keep glancing at that line and thinking I have an unbalanced quote or parenthesis (I think the final closing parenthesis being highlighted differently from its matching opening parenthesis is a large part of the problem).

It looks like this happens because fish-mode highlights up to the closing parenthesis by non-greedily skipping over other characters. I'm not very familiar with either fish or Emacs syntax highlighting, but maybe it would work better to search for the end of the current command (similarly to how the "command name" highlighting works: by searching for a semicolon or newline, more or less)? Unless Emacs has regexp extensions for matching balanced groups or something similar finding the right closing parenthesis directly won't handle cases like this one, but I'm not sure if fish has cases other than backslash-escaped newlines that complicate finding the end of the "for" command.

(Personally I'd prefer to not treat process substitution specially here, but as commit b5f28b0a09d9379a3b669677902346a463ee8628 mentions that's very much a matter of preference, and doing what it currently does using pure regexp is hard...)