1 ;;; awk-mode.el --- AWK code editing commands for Emacs
3 ;; Copyright (C) 1988,94,96,2000 Free Software Foundation, Inc.
6 ;; Keywords: unix, languages
8 ;; This file is part of XEmacs.
10 ;; XEmacs is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; XEmacs is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 ;;; Synched up with: GNU Emacs 21.2 except not derived from c-mode and we
26 ;;; have a bit different regexp-opt syntax.
30 ;; Sets up C-mode with support for awk-style #-comments and a lightly
31 ;; hacked syntax table.
35 (defvar awk-mode-syntax-table nil
36 "Syntax table in use in Awk-mode buffers.")
38 (if awk-mode-syntax-table
40 (setq awk-mode-syntax-table (make-syntax-table))
41 (modify-syntax-entry ?\\ "\\" awk-mode-syntax-table)
42 (modify-syntax-entry ?\n "> " awk-mode-syntax-table)
43 (modify-syntax-entry ?\f "> " awk-mode-syntax-table)
44 (modify-syntax-entry ?\# "< " awk-mode-syntax-table)
45 (modify-syntax-entry ?/ "." awk-mode-syntax-table)
46 (modify-syntax-entry ?* "." awk-mode-syntax-table)
47 (modify-syntax-entry ?+ "." awk-mode-syntax-table)
48 (modify-syntax-entry ?- "." awk-mode-syntax-table)
49 (modify-syntax-entry ?= "." awk-mode-syntax-table)
50 (modify-syntax-entry ?% "." awk-mode-syntax-table)
51 (modify-syntax-entry ?< "." awk-mode-syntax-table)
52 (modify-syntax-entry ?> "." awk-mode-syntax-table)
53 (modify-syntax-entry ?& "." awk-mode-syntax-table)
54 (modify-syntax-entry ?| "." awk-mode-syntax-table)
55 (modify-syntax-entry ?_ "_" awk-mode-syntax-table)
56 (modify-syntax-entry ?\' "\"" awk-mode-syntax-table))
58 (defvar awk-mode-abbrev-table nil
59 "Abbrev table in use in Awk-mode buffers.")
60 (define-abbrev-table 'awk-mode-abbrev-table ())
62 ;; Regexps written with help from Peter Galbraith <galbraith@mixing.qc.dfo.ca>.
63 (defconst awk-font-lock-keywords
67 ;; Regular expressions. npak@ispras.ru
68 ;; We shoul do it before any other fontification
69 ;; Split into two cases for Speed god.
70 (cons "^[ \t]*/\\(\\(\\([\\].\\)?[^/\\]*\\)+\\)"
71 '(1 'font-lock-string-face))
72 (cons "[-!~+*=&<>|(][ \t]*/\\(\\(\\([\\].\\)?[^/\\]*\\)+\\)"
73 '(1 font-lock-string-face))
76 '("^[ \t]*\\(function\\)\\>[ \t]*\\(\\sw+\\)?"
77 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
80 ;; "RT", field identifiers $0, $1 etc added by npak@ispras.ru
84 '("ARGC" "ARGIND" "ARGV" "CONVFMT" "ENVIRON" "ERRNO"
85 "FIELDWIDTHS" "FILENAME" "FNR" "FS" "IGNORECASE" "NF" "NR"
86 "OFMT" "OFS" "ORS" "RLENGTH" "RS" "RT" "RSTART" "SUBSEP"))
87 "\\|\\$\\(?:[0-9]+\\|\\sw+\\)\\)\\>")
88 'font-lock-variable-name-face)
91 ;; "do", "in", "nextfile" added by npak@ispras.ru
95 '("BEGIN" "END" "break" "continue" "delete" "do" "else" "exit" "for"
96 "getline" "if" "in" "next" "nextfile" "print" "printf" "return"
101 ;; "fflush" added by npak@ispras.ru
105 '("atan2" "close" "cos" "ctime" "exp" "gsub" "index" "int"
106 "length" "log" "match" "rand" "sin" "split" "sprintf"
107 "sqrt" "srand" "sub" "substr" "system" "time" "fflush"
108 "tolower" "toupper"))
110 1 'font-lock-reference-face)
112 ;; Function call, variables. npak@ispras.ru
113 (list "\\<\\([A-Za-z_]\\sw*\\)("
114 1 'font-lock-function-name-face)
115 (list "\\<\\([A-Za-z_]\\sw*\\)\\($\\|[^(]\\)"
116 1 'font-lock-variable-name-face)
118 ;; Operators. Is this too much?
119 ;; Yes, it is. npak@ispras.ru
120 ;(cons (regexp-opt '("&&" "||" "<=" "<" ">=" ">" "==" "!=" "!~" "~"))
121 ; 'font-lock-reference-face)
123 "Default expressions to highlight in AWK mode.")
126 (put 'awk-mode 'font-lock-defaults
127 '(awk-font-lock-keywords nil nil ((?_ . "w"))))
131 "Major mode for editing AWK code.
132 This is much like C mode except for the syntax of comments. It uses
133 the same keymap as C mode and has the same variables for customizing
134 indentation. It has its own abbrev table and its own syntax table.
136 Turning on AWK mode calls the value of the variable `awk-mode-hook'
137 with no args, if that value is non-nil."
139 (kill-all-local-variables)
141 (c-initialize-cc-mode)
142 (use-local-map c-mode-map)
144 (setq major-mode 'awk-mode)
145 (setq mode-name "AWK")
146 (setq local-abbrev-table awk-mode-abbrev-table)
147 (set-syntax-table awk-mode-syntax-table)
148 (make-local-variable 'paragraph-start)
149 (setq paragraph-start (concat "$\\|" page-delimiter))
150 (make-local-variable 'paragraph-separate)
151 (setq paragraph-separate paragraph-start)
152 (make-local-variable 'paragraph-ignore-fill-prefix)
153 (setq paragraph-ignore-fill-prefix t)
154 (make-local-variable 'indent-line-function)
155 (setq indent-line-function 'c-indent-line)
156 (make-local-variable 'require-final-newline)
157 (setq require-final-newline t)
158 (make-local-variable 'comment-start)
159 (setq comment-start "# ")
160 (make-local-variable 'comment-end)
161 (setq comment-end "")
162 (make-local-variable 'comment-column)
163 (setq comment-column 32)
164 (make-local-variable 'comment-start-skip)
165 (setq comment-start-skip "#+ *")
166 (make-local-variable 'comment-indent-function)
167 (setq comment-indent-function 'c-comment-indent)
168 (make-local-variable 'parse-sexp-ignore-comments)
169 (setq parse-sexp-ignore-comments t)
171 ;(make-local-variable 'font-lock-defaults)
172 ;(setq font-lock-defaults '(awk-font-lock-keywords nil nil ((?_ . "w"))))
173 (run-hooks 'awk-mode-hook))
176 ;;;###autoload(add-to-list 'auto-mode-alist '("\\.awk\\'" . awk-mode))
177 ;;;###autoload(add-to-list 'interpreter-mode-alist '("awk\\b" . awk-mode))
181 ;;; awk-mode.el ends here