Add ibuffer-filter-by-derived-mode to ibuffer menu and doc
[emacs.git] / lisp / obsolete / awk-mode.el
blobc931af9df5e37463cf99a0df3139984edf928b52
1 ;;; awk-mode.el --- AWK code editing commands for Emacs
3 ;; Copyright (C) 1988, 1994, 1996, 2000-2012 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Keywords: unix, languages
7 ;; Obsolete-since: 22.1
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 of the License, or
14 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; Sets up C-mode with support for awk-style #-comments and a lightly
27 ;; hacked syntax table.
29 ;;; Code:
31 (defvar awk-mode-syntax-table
32 (let ((st (make-syntax-table)))
33 (modify-syntax-entry ?\\ "\\" st)
34 (modify-syntax-entry ?\n "> " st)
35 (modify-syntax-entry ?\f "> " st)
36 (modify-syntax-entry ?\# "< " st)
37 ;; / can delimit regexes or be a division operator. We assume that it is
38 ;; more commonly used for regexes and fix the remaining cases with
39 ;; `font-lock-syntactic-keywords'.
40 (modify-syntax-entry ?/ "\"" st)
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 st)
53 "Syntax table in use in `awk-mode' buffers.")
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
60 ;; Function names.
61 '("^[ \t]*\\(function\\)\\>[ \t]*\\(\\sw+\\)?"
62 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
64 ;; Variable names.
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)
69 'font-lock-variable-name-face)
71 ;; Keywords.
72 (regexp-opt
73 '("BEGIN" "END" "break" "continue" "delete" "do" "exit" "else" "for"
74 "getline" "if" "next" "print" "printf" "return" "while") 'words)
76 ;; Builtins.
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)
82 1 'font-lock-builtin-face)
84 ;; Operators. Is this too much?
85 (cons (regexp-opt '("&&" "||" "<=" "<" ">=" ">" "==" "!=" "!~" "~"))
86 'font-lock-constant-face)
88 "Default expressions to highlight in AWK mode.")
90 (require 'syntax)
92 (defconst awk-font-lock-syntactic-keywords
93 ;; `/' is mostly used for /.../ regular expressions, but is also
94 ;; used as a division operator. Distinguishing between the two is
95 ;; a pain in the youknowwhat.
96 ;; '(("\\(^\\|[<=>-+*%/!^,~(?:|&]\\)\\s-*\\(/\\)\\([^/\n\\]\\|\\\\.\\)*\\(/\\)"
97 ;; (2 "\"") (4 "\"")))
98 '(("[^<=>-+*%/!^,~(?:|& \t\n\f]\\s-*\\(/\\)"
99 (1 (unless (nth 3 (syntax-ppss (match-beginning 1))) "."))))
100 "Syntactic keywords for `awk-mode'.")
102 ;; No longer autoloaded since it might clobber the autoload directive in CC Mode.
103 (define-derived-mode awk-mode c-mode "AWK"
104 "Major mode for editing AWK code.
105 This is much like C mode except for the syntax of comments. Its keymap
106 inherits from C mode's and it has the same variables for customizing
107 indentation. It has its own abbrev table and its own syntax table.
109 Turning on AWK mode runs `awk-mode-hook'."
110 (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter))
111 (set (make-local-variable 'paragraph-separate) paragraph-start)
112 (set (make-local-variable 'comment-start) "# ")
113 (set (make-local-variable 'comment-end) "")
114 (set (make-local-variable 'comment-start-skip) "#+ *")
115 (setq font-lock-defaults '(awk-font-lock-keywords
116 nil nil ((?_ . "w")) nil
117 (parse-sexp-lookup-properties . t)
118 (font-lock-syntactic-keywords
119 . awk-font-lock-syntactic-keywords))))
121 (provide 'awk-mode)
123 ;;; awk-mode.el ends here