[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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:
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
).
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.
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.
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] | [ ? ] |
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] | [ ? ] |
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:
font-lock-variable-name-face
NF
) and "Special File Names" (such as
"/dev/stderr"
).
font-lock-builtin-face
(Emacs)/font-lock-preprocessor-face
(XEmacs)
match
).
font-lock-string-face
font-lock-warning-face
(Emacs)/c-invalid-face
(XEmacs)
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.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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-awk-beginning-of-defun
c-awk-end-of-defun
beginning-of-defun
and end-of-defun
. @xref{Moving by Defuns,,,emacs}.
c-mark-function
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by XEmacs shared group account on December, 19 2009
using texi2html 1.65.