Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / lisp / obsolete / awk-mode.el
blobfdf0c41131b4913c40d0012426a3ee371913f92c
1 ;;; awk-mode.el --- AWK code editing commands for Emacs
3 ;; Copyright (C) 1988, 1994, 1996, 2000-2014 Free Software Foundation,
4 ;; Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: unix, languages
8 ;; Obsolete-since: 22.1
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; Sets up C-mode with support for awk-style #-comments and a lightly
28 ;; hacked syntax table.
30 ;;; Code:
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.")
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
61 ;; Function names.
62 '("^[ \t]*\\(function\\)\\>[ \t]*\\(\\sw+\\)?"
63 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
65 ;; Variable names.
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)
70 'font-lock-variable-name-face)
72 ;; Keywords.
73 (regexp-opt
74 '("BEGIN" "END" "break" "continue" "delete" "do" "exit" "else" "for"
75 "getline" "if" "next" "print" "printf" "return" "while") 'words)
77 ;; Builtins.
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)
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.")
91 (require 'syntax)
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'.")
103 ;; No longer autoloaded since it might clobber the autoload directive in CC 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))))
122 (provide 'awk-mode)
124 ;;; awk-mode.el ends here