Commit | Line | Data |
---|---|---|
c0274f38 ER |
1 | ;;; awk-mode.el --- AWK code editing commands for Emacs |
2 | ||
4e59dfb5 | 3 | ;; Copyright (C) 1988, 1994, 1996 Free Software Foundation, Inc. |
9750e079 | 4 | |
fd7fa35a | 5 | ;; Maintainer: FSF |
e9571d2a | 6 | ;; Keywords: unix, languages |
fd7fa35a | 7 | |
745bc783 JB |
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 | |
fd7fa35a | 12 | ;; the Free Software Foundation; either version 2, or (at your option) |
745bc783 JB |
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 | |
b578f267 EN |
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. | |
745bc783 | 24 | |
e41b2db1 ER |
25 | ;;; Commentary: |
26 | ||
27 | ;; Sets up C-mode with support for awk-style #-comments and a lightly | |
28 | ;; hacked syntax table. | |
29 | ||
fd7fa35a | 30 | ;;; Code: |
745bc783 JB |
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) | |
6c045717 RS |
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) | |
745bc783 JB |
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) | |
4e59dfb5 | 52 | (modify-syntax-entry ?_ "_" awk-mode-syntax-table) |
745bc783 JB |
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 | ||
4e59dfb5 SM |
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") | |
e1abf2bb | 84 | "BEGIN\\|END\\|break\\|continue\\|delete\\|exit\\|else\\|for\\|" |
4e59dfb5 SM |
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 | "\\|") | |
883212ce | 106 | 'font-lock-constant-face) |
4e59dfb5 SM |
107 | )) |
108 | "Default expressions to highlight in AWK mode.") | |
109 | ||
745bc783 JB |
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) | |
a1bf98fa | 121 | (require 'cc-mode) |
8248aeb5 | 122 | (c-initialize-cc-mode) |
745bc783 JB |
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) | |
8e32e928 | 129 | (setq paragraph-start (concat "$\\|" page-delimiter)) |
745bc783 JB |
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) | |
3591cb55 | 135 | (setq indent-line-function 'c-indent-line) |
745bc783 JB |
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 "#+ *") | |
e41b2db1 ER |
146 | (make-local-variable 'comment-indent-function) |
147 | (setq comment-indent-function 'c-comment-indent) | |
12554a4f RS |
148 | (make-local-variable 'parse-sexp-ignore-comments) |
149 | (setq parse-sexp-ignore-comments t) | |
4e59dfb5 SM |
150 | (make-local-variable 'font-lock-defaults) |
151 | (setq font-lock-defaults '(awk-font-lock-keywords nil nil ((?_ . "w")))) | |
745bc783 | 152 | (run-hooks 'awk-mode-hook)) |
c0274f38 | 153 | |
4e59dfb5 SM |
154 | (provide 'awk-mode) |
155 | ||
c0274f38 | 156 | ;;; awk-mode.el ends here |