// EMACS-AWK — EMACS MAJOR MODE FOR AWK (AWKRS)

filetype detection (*.awk + awk shebang) · font-lock for keywords, built-in vars/funcs, fields, /regex/ · brace-aware indent · run via awkrs · LSP via awkrs --lsp

eglot + lsp-mode · eldoc + completion · settings awkrs-executable / awkrs-indent-offset · Package-Requires emacs 27.1

Report GitHub

>_EMACS-AWK — AWK IN EMACS

Open a .awk file and the pattern/action engine lights up. emacs-awk targets awkrs, the Rust AWK implementation. awkrs-mode derives from prog-mode, font-locks AWK keywords, the 16 built-in variables, the 22 built-in functions, field references ($0 $1 $NF) and /regex/ literals, indents brace blocks, runs the buffer through awkrs (C-c C-c), serves eldoc + completion for builtins, and wires awkrs --lsp into both eglot and lsp-mode. Named awkrs-mode so it does not clash with Emacs' built-in awk-mode.

Install

The awkrs binary must be on $PATH to run buffers and for the language server (build awkrs with cargo install --path .).

;; manual
(add-to-list 'load-path "/path/to/emacs-awk")
(require 'awkrs-mode)

;; use-package + built-in VC
(use-package awkrs-mode
  :mode "\\.awk\\'"
  :vc (:url "https://github.com/MenkeTechnologies/emacs-awk"))

Press C-c C-c to run a buffer. With eglot: M-x eglot in a .awk buffer, or (add-hook 'awkrs-mode-hook #'eglot-ensure).

What you get

Filetype detection

Every *.awk file uses awkrs-mode (auto-mode-alist); awk / awkrs shebangs are detected via interpreter-mode-alist.

Field-aware font-lock

Keywords, the 16 built-in variables, the 22 built-in functions, field references $0/$1/$NF, and /regex/ literals — with their own faces for built-in vars and fields.

Regex in operand position

A syntax-propertize rule recognizes /regex/ only where AWK allows it (after ~, (, ,, =, a keyword, line start), so division a / b is not mistaken for a regex.

Run via awkrs

awkrs-run-buffer (C-c C-c) runs the buffer's program through awkrs -f FILE in a *compilation* buffer with next-error navigation.

eldoc + completion

One-line builtin signatures in the echo area and completion-at-point over the builtin function names, from awkrs-stdlib.el.

Language server

Registers awkrs --lsp for eglot (built in since Emacs 29) and lsp-mode, both loaded lazily. Launched with --lsp only — no appended --stdio.

Verified

scripts/face-test.el byte-compiles the package and asserts the face at each probe token — proven to load and classify correctly.

Faces

Token groupFace
Keywords (BEGIN END function if for print)font-lock-keyword-face
Built-in variables (NR NF FS OFS RS SUBSEP)awkrs-builtin-var-face
Built-in functions (length substr gsub sprintf split)font-lock-builtin-face
Field references ($0 $1 $NF)awkrs-field-ref-face
User function namesfont-lock-function-name-face
Strings / comments / /regex/via syntax table + syntax-propertize

Run, language server & config

Setting / commandEffect
awkrs-executable"awkrs" — path to the executable used to run buffers and start the server
awkrs-indent-offset4 — spaces per indent level
C-c C-c (awkrs-run-buffer)run the buffer's program through awkrs -f FILE via compile
M-x eglotstart the server via eglot (Emacs 29+)
M-x lspstart the server via lsp-mode

Compatibility

TargetStatus
Emacs 27.1+Mode + font-lock + indent + run + eldoc + completion
eglotBuilt in since Emacs 29; works on 27/28 if installed
lsp-modeRegistered client
Syntax highlightingNo binary required