Commit | Line | Data |
---|---|---|
c0274f38 ER |
1 | ;;; awk-mode.el --- AWK code editing commands for Emacs |
2 | ||
73b0cd50 | 3 | ;; Copyright (C) 1988, 1994, 1996, 2000-2011 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 | ||
4936186e | 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
745bc783 | 11 | ;; it under the terms of the GNU General Public License as published by |
4936186e GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
745bc783 JB |
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 | |
4936186e | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
745bc783 | 22 | |
e41b2db1 ER |
23 | ;;; Commentary: |
24 | ||
e94a9773 GM |
25 | ;; This file has been obsolete since Emacs 22.1. |
26 | ||
e41b2db1 ER |
27 | ;; Sets up C-mode with support for awk-style #-comments and a lightly |
28 | ;; hacked syntax table. | |
29 | ||
fd7fa35a | 30 | ;;; Code: |
745bc783 | 31 | |
61b8c98e SM |
32 | (defvar awk-mode-syntax-table |
33 | (let ((st (make-syntax-table))) | |
34 | (modify-syntax-entry ?\\ "\\" st) | |
35 | (modify-syntax-entry ?\n "> " st) | |
36 | (modify-syntax-entry ?\f "> " st) | |
37 | (modify-syntax-entry ?\# "< " st) | |
38 | ;; / can delimit regexes or be a division operator. We assume that it is | |
39 | ;; more commonly used for regexes and fix the remaining cases with | |
40 | ;; `font-lock-syntactic-keywords'. | |
41 | (modify-syntax-entry ?/ "\"" st) | |
42 | (modify-syntax-entry ?* "." st) | |
43 | (modify-syntax-entry ?+ "." st) | |
44 | (modify-syntax-entry ?- "." st) | |
45 | (modify-syntax-entry ?= "." st) | |
46 | (modify-syntax-entry ?% "." st) | |
47 | (modify-syntax-entry ?< "." st) | |
48 | (modify-syntax-entry ?> "." st) | |
49 | (modify-syntax-entry ?& "." st) | |
50 | (modify-syntax-entry ?| "." st) | |
51 | (modify-syntax-entry ?_ "_" st) | |
52 | (modify-syntax-entry ?\' "\"" st) | |
53 | st) | |
54 | "Syntax table in use in `awk-mode' buffers.") | |
745bc783 | 55 | |
4e59dfb5 SM |
56 | ;; Regexps written with help from Peter Galbraith <galbraith@mixing.qc.dfo.ca>. |
57 | (defconst awk-font-lock-keywords | |
58 | (eval-when-compile | |
59 | (list | |
60 | ;; | |
61 | ;; Function names. | |
178a6a45 | 62 | '("^[ \t]*\\(function\\)\\>[ \t]*\\(\\sw+\\)?" |
4e59dfb5 SM |
63 | (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)) |
64 | ;; | |
65 | ;; Variable names. | |
178a6a45 SM |
66 | (cons (regexp-opt |
67 | '("ARGC" "ARGIND" "ARGV" "CONVFMT" "ENVIRON" "ERRNO" | |
68 | "FIELDWIDTHS" "FILENAME" "FNR" "FS" "IGNORECASE" "NF" "NR" | |
69 | "OFMT" "OFS" "ORS" "RLENGTH" "RS" "RSTART" "SUBSEP") 'words) | |
4e59dfb5 SM |
70 | 'font-lock-variable-name-face) |
71 | ;; | |
72 | ;; Keywords. | |
178a6a45 | 73 | (regexp-opt |
e14c5251 | 74 | '("BEGIN" "END" "break" "continue" "delete" "do" "exit" "else" "for" |
178a6a45 | 75 | "getline" "if" "next" "print" "printf" "return" "while") 'words) |
4e59dfb5 SM |
76 | ;; |
77 | ;; Builtins. | |
178a6a45 SM |
78 | (list (regexp-opt |
79 | '("atan2" "close" "cos" "ctime" "exp" "gsub" "index" "int" | |
80 | "length" "log" "match" "rand" "sin" "split" "sprintf" | |
81 | "sqrt" "srand" "sub" "substr" "system" "time" | |
82 | "tolower" "toupper") 'words) | |
4e59dfb5 SM |
83 | 1 'font-lock-builtin-face) |
84 | ;; | |
85 | ;; Operators. Is this too much? | |
178a6a45 | 86 | (cons (regexp-opt '("&&" "||" "<=" "<" ">=" ">" "==" "!=" "!~" "~")) |
883212ce | 87 | 'font-lock-constant-face) |
4e59dfb5 SM |
88 | )) |
89 | "Default expressions to highlight in AWK mode.") | |
90 | ||
61b8c98e SM |
91 | (require 'syntax) |
92 | ||
93 | (defconst awk-font-lock-syntactic-keywords | |
94 | ;; `/' is mostly used for /.../ regular expressions, but is also | |
95 | ;; used as a division operator. Distinguishing between the two is | |
96 | ;; a pain in the youknowwhat. | |
97 | ;; '(("\\(^\\|[<=>-+*%/!^,~(?:|&]\\)\\s-*\\(/\\)\\([^/\n\\]\\|\\\\.\\)*\\(/\\)" | |
98 | ;; (2 "\"") (4 "\""))) | |
99 | '(("[^<=>-+*%/!^,~(?:|& \t\n\f]\\s-*\\(/\\)" | |
100 | (1 (unless (nth 3 (syntax-ppss (match-beginning 1))) ".")))) | |
101 | "Syntactic keywords for `awk-mode'.") | |
102 | ||
75d6bc9b | 103 | ;; No longer autoloaded since it might clobber the autoload directive in CC Mode. |
178a6a45 | 104 | (define-derived-mode awk-mode c-mode "AWK" |
745bc783 | 105 | "Major mode for editing AWK code. |
178a6a45 SM |
106 | This is much like C mode except for the syntax of comments. Its keymap |
107 | inherits from C mode's and it has the same variables for customizing | |
745bc783 JB |
108 | indentation. It has its own abbrev table and its own syntax table. |
109 | ||
178a6a45 SM |
110 | Turning on AWK mode runs `awk-mode-hook'." |
111 | (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter)) | |
112 | (set (make-local-variable 'paragraph-separate) paragraph-start) | |
113 | (set (make-local-variable 'comment-start) "# ") | |
114 | (set (make-local-variable 'comment-end) "") | |
115 | (set (make-local-variable 'comment-start-skip) "#+ *") | |
61b8c98e SM |
116 | (setq font-lock-defaults '(awk-font-lock-keywords |
117 | nil nil ((?_ . "w")) nil | |
118 | (parse-sexp-lookup-properties . t) | |
119 | (font-lock-syntactic-keywords | |
120 | . awk-font-lock-syntactic-keywords)))) | |
c0274f38 | 121 | |
4e59dfb5 SM |
122 | (provide 'awk-mode) |
123 | ||
c0274f38 | 124 | ;;; awk-mode.el ends here |