]> code.delx.au - gnu-emacs/blob - lisp/progmodes/awk-mode.el
Changed version to 1.2.1.
[gnu-emacs] / lisp / progmodes / awk-mode.el
1 ;;; awk-mode.el --- AWK code editing commands for Emacs
2
3 ;; Copyright (C) 1988, 1994, 1996 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Keywords: unix, languages
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; Sets up C-mode with support for awk-style #-comments and a lightly
28 ;; hacked syntax table.
29
30 ;;; Code:
31
32 (defvar awk-mode-syntax-table nil
33 "Syntax table in use in Awk-mode buffers.")
34
35 (if awk-mode-syntax-table
36 ()
37 (setq awk-mode-syntax-table (make-syntax-table))
38 (modify-syntax-entry ?\\ "\\" awk-mode-syntax-table)
39 (modify-syntax-entry ?\n "> " awk-mode-syntax-table)
40 (modify-syntax-entry ?\f "> " awk-mode-syntax-table)
41 (modify-syntax-entry ?\# "< " awk-mode-syntax-table)
42 (modify-syntax-entry ?/ "." awk-mode-syntax-table)
43 (modify-syntax-entry ?* "." 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
55 (defvar awk-mode-abbrev-table nil
56 "Abbrev table in use in Awk-mode buffers.")
57 (define-abbrev-table 'awk-mode-abbrev-table ())
58
59 ;; Regexps written with help from Peter Galbraith <galbraith@mixing.qc.dfo.ca>.
60 (defconst awk-font-lock-keywords
61 (eval-when-compile
62 (list
63 ;;
64 ;; Function names.
65 '("^[ \t]*\\(function\\)\\>[ \t]*\\(\\sw+\\)?"
66 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
67 ;;
68 ;; Variable names.
69 (cons (concat "\\<\\("
70 ; ("ARGC" "ARGIND" "ARGV" "CONVFMT" "ENVIRON" "ERRNO"
71 ; "FIELDWIDTHS" "FILENAME" "FNR" "FS" "IGNORECASE" "NF" "NR"
72 ; "OFMT" "OFS" "ORS" "RLENGTH" "RS" "RSTART" "SUBSEP")
73 "ARG\\([CV]\\|IND\\)\\|CONVFMT\\|E\\(NVIRON\\|RRNO\\)\\|"
74 "F\\(I\\(ELDWIDTHS\\|LENAME\\)\\|NR\\|S\\)\\|IGNORECASE\\|"
75 "N[FR]\\|O\\(F\\(MT\\|S\\)\\|RS\\)\\|"
76 "R\\(LENGTH\\|S\\(\\|TART\\)\\)\\|SUBSEP"
77 "\\)\\>")
78 'font-lock-variable-name-face)
79 ;;
80 ;; Keywords.
81 (concat "\\<\\("
82 ; ("BEGIN" "END" "break" "continue" "delete" "exit" "for"
83 ; "getline" "if" "next" "print" "printf" "return" "while")
84 "BEGIN\\|END\\|break\\|continue\\|delete\\|exit\\|for\\|"
85 "getline\\|if\\|next\\|printf?\\|return\\|while"
86 "\\)\\>")
87 ;;
88 ;; Builtins.
89 (list (concat "\\<\\("
90 ; ("atan2" "close" "cos" "ctime" "exp" "gsub" "index" "int"
91 ; "length" "log" "match" "rand" "sin" "split" "sprintf"
92 ; "sqrt" "srand" "sub" "substr" "system" "time"
93 ; "tolower" "toupper")
94 "atan2\\|c\\(lose\\|os\\|time\\)\\|exp\\|gsub\\|"
95 "in\\(dex\\|t\\)\\|l\\(ength\\|og\\)\\|match\\|rand\\|"
96 "s\\(in\\|p\\(lit\\|rintf\\)\\|qrt\\|rand\\|"
97 "ub\\(\\|str\\)\\|ystem\\)\\|"
98 "t\\(ime\\|o\\(lower\\|upper\\)\\)"
99 "\\)(")
100 1 'font-lock-builtin-face)
101 ;;
102 ;; Operators. Is this too much?
103 (cons (mapconcat 'identity
104 '("&&" "||" "<=" "<" ">=" ">" "==" "!=" "!~" "~")
105 "\\|")
106 'font-lock-constant-face)
107 ))
108 "Default expressions to highlight in AWK mode.")
109
110 ;;;###autoload
111 (defun awk-mode ()
112 "Major mode for editing AWK code.
113 This is much like C mode except for the syntax of comments. It uses
114 the same keymap as C mode and has the same variables for customizing
115 indentation. It has its own abbrev table and its own syntax table.
116
117 Turning on AWK mode calls the value of the variable `awk-mode-hook'
118 with no args, if that value is non-nil."
119 (interactive)
120 (kill-all-local-variables)
121 (require 'cc-mode)
122 (c-initialize-cc-mode)
123 (use-local-map c-mode-map)
124 (setq major-mode 'awk-mode)
125 (setq mode-name "AWK")
126 (setq local-abbrev-table awk-mode-abbrev-table)
127 (set-syntax-table awk-mode-syntax-table)
128 (make-local-variable 'paragraph-start)
129 (setq paragraph-start (concat "$\\|" page-delimiter))
130 (make-local-variable 'paragraph-separate)
131 (setq paragraph-separate paragraph-start)
132 (make-local-variable 'paragraph-ignore-fill-prefix)
133 (setq paragraph-ignore-fill-prefix t)
134 (make-local-variable 'indent-line-function)
135 (setq indent-line-function 'c-indent-line)
136 (make-local-variable 'require-final-newline)
137 (setq require-final-newline t)
138 (make-local-variable 'comment-start)
139 (setq comment-start "# ")
140 (make-local-variable 'comment-end)
141 (setq comment-end "")
142 (make-local-variable 'comment-column)
143 (setq comment-column 32)
144 (make-local-variable 'comment-start-skip)
145 (setq comment-start-skip "#+ *")
146 (make-local-variable 'comment-indent-function)
147 (setq comment-indent-function 'c-comment-indent)
148 (make-local-variable 'parse-sexp-ignore-comments)
149 (setq parse-sexp-ignore-comments t)
150 (make-local-variable 'font-lock-defaults)
151 (setq font-lock-defaults '(awk-font-lock-keywords nil nil ((?_ . "w"))))
152 (run-hooks 'awk-mode-hook))
153
154 (provide 'awk-mode)
155
156 ;;; awk-mode.el ends here