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 GNU Emacs.
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)
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.
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.
27 ;; Sets up C-mode with support for awk-style #-comments and a lightly
28 ;; hacked syntax table.
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
)
54 "Syntax table in use in `awk-mode' buffers.")
56 ;; Regexps written with help from Peter Galbraith <galbraith@mixing.qc.dfo.ca>.
57 (defconst awk-font-lock-keywords
62 '("^[ \t]*\\(function\\)\\>[ \t]*\\(\\sw+\\)?"
63 (1 font-lock-keyword-face
) (2 font-lock-function-name-face nil t
))
67 '("ARGC" "ARGIND" "ARGV" "CONVFMT" "ENVIRON" "ERRNO"
68 "FIELDWIDTHS" "FILENAME" "FNR" "FS" "IGNORECASE" "NF" "NR"
69 "OFMT" "OFS" "ORS" "RLENGTH" "RS" "RSTART" "SUBSEP") 'words
)
70 'font-lock-variable-name-face
)
74 '("BEGIN" "END" "break" "continue" "delete" "exit" "else" "for"
75 "getline" "if" "next" "print" "printf" "return" "while") 'words
)
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
)
83 1 'font-lock-builtin-face
)
85 ;; Operators. Is this too much?
86 (cons (regexp-opt '("&&" "||" "<=" "<" ">=" ">" "==" "!=" "!~" "~"))
87 'font-lock-constant-face
)
89 "Default expressions to highlight in AWK mode.")
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'.")
104 (define-derived-mode awk-mode c-mode
"AWK"
105 "Major mode for editing AWK code.
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
108 indentation. It has its own abbrev table and its own syntax table.
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
) "#+ *")
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
))))
124 ;;; awk-mode.el ends here