Merge from emacs--rel--22
[emacs.git] / lisp / obsolete / awk-mode.el
blob6c20b9bffa64efa9e3822aa9940ffe6188d5d6ec
1 ;;; awk-mode.el --- AWK code editing commands for Emacs
3 ;; Copyright (C) 1988, 1994, 1996, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: unix, languages
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
26 ;;; Commentary:
28 ;; Sets up C-mode with support for awk-style #-comments and a lightly
29 ;; hacked syntax table.
31 ;;; Code:
33 (defvar awk-mode-syntax-table
34 (let ((st (make-syntax-table)))
35 (modify-syntax-entry ?\\ "\\" st)
36 (modify-syntax-entry ?\n "> " st)
37 (modify-syntax-entry ?\f "> " st)
38 (modify-syntax-entry ?\# "< " st)
39 ;; / can delimit regexes or be a division operator. We assume that it is
40 ;; more commonly used for regexes and fix the remaining cases with
41 ;; `font-lock-syntactic-keywords'.
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 (modify-syntax-entry ?\' "\"" st)
54 st)
55 "Syntax table in use in `awk-mode' buffers.")
57 ;; Regexps written with help from Peter Galbraith <galbraith@mixing.qc.dfo.ca>.
58 (defconst awk-font-lock-keywords
59 (eval-when-compile
60 (list
62 ;; Function names.
63 '("^[ \t]*\\(function\\)\\>[ \t]*\\(\\sw+\\)?"
64 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
66 ;; Variable names.
67 (cons (regexp-opt
68 '("ARGC" "ARGIND" "ARGV" "CONVFMT" "ENVIRON" "ERRNO"
69 "FIELDWIDTHS" "FILENAME" "FNR" "FS" "IGNORECASE" "NF" "NR"
70 "OFMT" "OFS" "ORS" "RLENGTH" "RS" "RSTART" "SUBSEP") 'words)
71 'font-lock-variable-name-face)
73 ;; Keywords.
74 (regexp-opt
75 '("BEGIN" "END" "break" "continue" "delete" "do" "exit" "else" "for"
76 "getline" "if" "next" "print" "printf" "return" "while") 'words)
78 ;; Builtins.
79 (list (regexp-opt
80 '("atan2" "close" "cos" "ctime" "exp" "gsub" "index" "int"
81 "length" "log" "match" "rand" "sin" "split" "sprintf"
82 "sqrt" "srand" "sub" "substr" "system" "time"
83 "tolower" "toupper") 'words)
84 1 'font-lock-builtin-face)
86 ;; Operators. Is this too much?
87 (cons (regexp-opt '("&&" "||" "<=" "<" ">=" ">" "==" "!=" "!~" "~"))
88 'font-lock-constant-face)
90 "Default expressions to highlight in AWK mode.")
92 (require 'syntax)
94 (defconst awk-font-lock-syntactic-keywords
95 ;; `/' is mostly used for /.../ regular expressions, but is also
96 ;; used as a division operator. Distinguishing between the two is
97 ;; a pain in the youknowwhat.
98 ;; '(("\\(^\\|[<=>-+*%/!^,~(?:|&]\\)\\s-*\\(/\\)\\([^/\n\\]\\|\\\\.\\)*\\(/\\)"
99 ;; (2 "\"") (4 "\"")))
100 '(("[^<=>-+*%/!^,~(?:|& \t\n\f]\\s-*\\(/\\)"
101 (1 (unless (nth 3 (syntax-ppss (match-beginning 1))) "."))))
102 "Syntactic keywords for `awk-mode'.")
104 ;; No longer autoloaded since it might clobber the autoload directive in CC Mode.
105 (define-derived-mode awk-mode c-mode "AWK"
106 "Major mode for editing AWK code.
107 This is much like C mode except for the syntax of comments. Its keymap
108 inherits from C mode's and it has the same variables for customizing
109 indentation. It has its own abbrev table and its own syntax table.
111 Turning on AWK mode runs `awk-mode-hook'."
112 (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter))
113 (set (make-local-variable 'paragraph-separate) paragraph-start)
114 (set (make-local-variable 'comment-start) "# ")
115 (set (make-local-variable 'comment-end) "")
116 (set (make-local-variable 'comment-start-skip) "#+ *")
117 (setq font-lock-defaults '(awk-font-lock-keywords
118 nil nil ((?_ . "w")) nil
119 (parse-sexp-lookup-properties . t)
120 (font-lock-syntactic-keywords
121 . awk-font-lock-syntactic-keywords))))
123 (provide 'awk-mode)
125 ;;; arch-tag: 14ebc02a-b3c5-4e76-8034-6ca9ac0af0e6
126 ;;; awk-mode.el ends here