[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12. Status of AWK Mode

AWK mode existed until recently in the file `awk-mode.el' as a mode derived from c-mode. It had not been actively maintained to keep pace with the newer CC Mode, and its indentation mechanism no longer worked satisfactorally.

The current AWK mode is based around the GNU implementation, GAWK version 3.1.0, though it should work pretty well with any AWK. It has now been updated and integrated into CC Mode to a substantial extent, though as yet not all the features of CC Mode have been adapted to support it.

If your (X)Emacs is set up to use the old file `awk-mode.elc' (which will usually be the case if you have obtained this CC Mode independently of (X)Emacs itself), or if you are not sure, insert the following form into your `.emacs' or `init.el' so that the new AWK mode will be used instead:

(autoload 'awk-mode "cc-mode" nil t)

You can check which AWK mode you are running by displaying the mode documentation string with C-h m from an AWK buffer. The newer mode's doc string contains To submit a problem report, enter `C-c C-b' near the top of the doc string where the older mode has This is much like C mode except .....

Since this newer AWK mode makes essential use of a relatively new Emacs Lisp feature(34), you need either GNU Emacs 20.1 (or later) or XEmacs 21.4 (or later) to use it. If your Emacs version is earlier than one of these, the older `awk-mode.el' will get loaded and run in place of the AWK mode described here, even when you have put the above autoload form into your `.emacs' or `init.el'. Upgrading your (X)Emacs is strongly recommended if this is the case.

Here is an overview of which CC Mode features currently work with AWK mode and which don't:

Indentation Engine
The CC Mode indentation engine fully supports AWK mode. See section 3. Indentation Engine.

AWK mode handles code formatted in the conventional AWK fashion: `{'s which start actions, user-defined functions, or compound statements are placed on the same line as the associated construct; the matching `}'s are normally placed under the start of the respective pattern, function definition, or structured statement.

The predefined indentation functions (see section 11. Indentation Functions) haven't yet been adapted for AWK mode, though some of them may work serendipitously. There shouldn't be any problems writing custom indentation functions for AWK mode.

The command C-c C-q (c-indent-defun) hasn't yet been adapted for AWK, though in practice it works properly nearly all the time. Should it fail, explicitly set the region around the function (using C-u C-SPC: C-M-h probably won't work either) then do C-M-\ (indent-region).

Font Locking
There is a single level of font locking in AWK mode, rather than the three distinct levels the other modes have. There are several idiosyncrasies in AWK mode's font-locking due to the peculiarities of the AWK language itself. See section 12.2 AWK Mode Font Locking.

Comment Commands
M-; (indent-for-comment) works fine. None of the other CC Mode comment formatting commands have yet been adapted for AWK mode. See section 5. Text Filling and Line Breaking.

Movement Commands
Most of the movement commands work in AWK mode. The most important exceptions are M-a (c-beginning-of-statement) and M-e (c-end-of-statement) which haven't yet been adapted.

The notion of defun has been augmented to include pattern-action pairs. See 12.3 AWK Mode Defuns for a description of commands which work on AWK "defuns".

Since there is no preprocessor in AWK, the commands which move to preprocessor directives (e.g. c-up-conditional) are meaningless in AWK mode and are not bound in the AWK mode keymap.

Auto-newline Insertion and Clean-ups
Auto-newline insertion hasn't yet been adapted for AWK. Some of the clean-ups can actually convert good AWK code into syntactically invalid code.

If auto-newline or its associated clean-ups are enabled generally for the modes in CC Mode, you are strongly recommended to disable them in the AWK Mode hook. See section 12.1 AWK mode - What to put in your `.emacs' or `init.el'.

The clean-up space-before-funcall, which is independent of auto-newline, should never be active in AWK mode (since inserting a space between a user function's name and its opening `(' makes the call syntactically invalid). If necessary, this should be disabled in the AWK Mode hook. See section 12.1 AWK mode - What to put in your `.emacs' or `init.el'.

12.1 AWK mode - What to put in your `.emacs' or `init.el'  
12.2 AWK Mode Font Locking  
12.3 AWK Mode Defuns  

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.1 AWK mode - What to put in your `.emacs' or `init.el'

Much of the AWK mode initialization can, of course, be done by the CC Mode general initialization procedure. You may want to use certain CC Mode features such as auto-newline and clean-ups in the other modes, and you might thus have enabled them in a c-mode-common-hook function, as described in D. Sample .emacs file. These features have not yet been amended for AWK mode, and far from being useful, can be irritating in AWK mode or actually make AWK code syntactically invalid. Adding the following code to your `.emacs' or `init.el' file will disable them for AWK mode.

(defun my-awk-mode-hook ()
  "Disable certain CC Mode features which could impair AWK mode."
  (c-toggle-auto-state -1)       ; disable automatic insertions of newlines
  (if (memq 'space-before-funcall c-cleanup-list)
      (setq c-cleanup-list ; don't automatically insert a space into "foo("
            (remove 'space-before-funcall c-cleanup-list))))
(add-hook 'awk-mode-hook 'my-awk-mode-hook)

Naturally you can add your own AWK-specific customizations to this function. See section 9.3 Hooks.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.2 AWK Mode Font Locking

The general appearance of font-locking in AWK mode is much like in any other programming mode. @xref{Faces For Font Lock,,,elisp}.

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

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).

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:

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.3 AWK Mode Defuns

In AWK mode, defun means either a user-defined function or a pattern-action pair. Either the pattern or the action may be implicit.

The beginning of a defun is recognised heuristically as, more or less, code which begins in column zero. Having the `{' in column zero, as is suggested for some modes, is neither necessary nor helpful in AWK mode.

More precisely, the beginning of a defun is code which begins in column zero, and which isn't a closing brace, a comment, or a continuation of the previous line. Code is the continuation of the previous line when that line is syntactically incomplete, for example when it ends with `{' or an escaped newline.

The end of a defun is the `}' which matches the `{' (if any) at the beginning of the action or function body, or the EOL or `;' which marks an implicit action. Although this `}' is usually placed in column zero, AWK mode doesn't need it to be placed there.

C-M-a c-awk-beginning-of-defun
C-M-e c-awk-end-of-defun
Move point back to the beginning or forward to the end of the current AWK defun. These functions can take prefix-arguments, their functionality being entirely equivalent to beginning-of-defun and end-of-defun. @xref{Moving by Defuns,,,emacs}.

C-M-h c-mark-function
This works fine with AWK defuns. See section 8.1 Indentation Commands.

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by XEmacs Webmaster on October, 2 2007 using texi2html