Commit | Line | Data |
---|---|---|
c0274f38 ER |
1 | ;;; awk-mode.el --- AWK code editing commands for Emacs |
2 | ||
178a6a45 | 3 | ;; Copyright (C) 1988,94,96,2000 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 | ||
4e59dfb5 SM |
55 | ;; Regexps written with help from Peter Galbraith <galbraith@mixing.qc.dfo.ca>. |
56 | (defconst awk-font-lock-keywords | |
57 | (eval-when-compile | |
58 | (list | |
59 | ;; | |
60 | ;; Function names. | |
178a6a45 | 61 | '("^[ \t]*\\(function\\)\\>[ \t]*\\(\\sw+\\)?" |
4e59dfb5 SM |
62 | (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)) |
63 | ;; | |
64 | ;; Variable names. | |
178a6a45 SM |
65 | (cons (regexp-opt |
66 | '("ARGC" "ARGIND" "ARGV" "CONVFMT" "ENVIRON" "ERRNO" | |
67 | "FIELDWIDTHS" "FILENAME" "FNR" "FS" "IGNORECASE" "NF" "NR" | |
68 | "OFMT" "OFS" "ORS" "RLENGTH" "RS" "RSTART" "SUBSEP") 'words) | |
4e59dfb5 SM |
69 | 'font-lock-variable-name-face) |
70 | ;; | |
71 | ;; Keywords. | |
178a6a45 SM |
72 | (regexp-opt |
73 | '("BEGIN" "END" "break" "continue" "delete" "exit" "else" "for" | |
74 | "getline" "if" "next" "print" "printf" "return" "while") 'words) | |
4e59dfb5 SM |
75 | ;; |
76 | ;; Builtins. | |
178a6a45 SM |
77 | (list (regexp-opt |
78 | '("atan2" "close" "cos" "ctime" "exp" "gsub" "index" "int" | |
79 | "length" "log" "match" "rand" "sin" "split" "sprintf" | |
80 | "sqrt" "srand" "sub" "substr" "system" "time" | |
81 | "tolower" "toupper") 'words) | |
4e59dfb5 SM |
82 | 1 'font-lock-builtin-face) |
83 | ;; | |
84 | ;; Operators. Is this too much? | |
178a6a45 | 85 | (cons (regexp-opt '("&&" "||" "<=" "<" ">=" ">" "==" "!=" "!~" "~")) |
883212ce | 86 | 'font-lock-constant-face) |
4e59dfb5 SM |
87 | )) |
88 | "Default expressions to highlight in AWK mode.") | |
89 | ||
745bc783 | 90 | ;;;###autoload |
178a6a45 | 91 | (define-derived-mode awk-mode c-mode "AWK" |
745bc783 | 92 | "Major mode for editing AWK code. |
178a6a45 SM |
93 | This is much like C mode except for the syntax of comments. Its keymap |
94 | inherits from C mode's and it has the same variables for customizing | |
745bc783 JB |
95 | indentation. It has its own abbrev table and its own syntax table. |
96 | ||
178a6a45 SM |
97 | Turning on AWK mode runs `awk-mode-hook'." |
98 | (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter)) | |
99 | (set (make-local-variable 'paragraph-separate) paragraph-start) | |
100 | (set (make-local-variable 'comment-start) "# ") | |
101 | (set (make-local-variable 'comment-end) "") | |
102 | (set (make-local-variable 'comment-start-skip) "#+ *") | |
103 | (setq font-lock-defaults '(awk-font-lock-keywords nil nil ((?_ . "w"))))) | |
c0274f38 | 104 | |
4e59dfb5 SM |
105 | (provide 'awk-mode) |
106 | ||
c0274f38 | 107 | ;;; awk-mode.el ends here |