5.6 AWK Mode Font Locking

The general appearance of font-locking in AWK mode is much like in any other programming mode. See Faces For Font Lock in GNU Emacs Lisp Reference Manual.

The following faces are, however, used in a non-standard fashion in AWK mode:

font-lock-variable-name-face

This face was intended for variable declarations. Since variables are not declared in AWK, this face is used instead for AWK system variables (such as NF) and “Special File Names” (such as "/dev/stderr").

font-lock-builtin-face (Emacs)/font-lock-preprocessor-face (XEmacs)

This face is normally used for preprocessor directives in CC Mode. There are no such things in AWK, so this face is used instead for standard functions (such as match).

font-lock-string-face

As well as being used for strings, including localizable strings, (delimited by ‘"’ and ‘_"’), this face is also used for AWK regular expressions (delimited by ‘/’).

font-lock-warning-face (Emacs)/c-invalid-face (XEmacs)

This face highlights the following syntactically invalid AWK constructs:

  • An unterminated string or regular expression. Here the opening delimiter (‘"’ or ‘/’ or ‘_"’) is displayed in font-lock-warning-face. This is most noticeable when typing in a new string/regular expression into a buffer, when the warning-face serves as a continual reminder to terminate the construct.

    AWK mode fontifies unterminated strings/regular expressions differently from other modes: Only the text up to the end of the line is fontified as a string (escaped newlines being handled correctly), rather than the text up to the next string quote.

  • A space between the function name and opening parenthesis when calling a user function. The last character of the function name and the opening parenthesis are highlighted. This font-locking rule will spuriously highlight a valid concatenation expression where an identifier precedes a parenthesized expression. Unfortunately.
  • Whitespace following the ‘\’ in what otherwise looks like an escaped newline. The ‘\’ is highlighted.