Mercurial > emacs
comparison lisp/obsolete/awk-mode.el @ 51955:55e857ca3791
Obsoleted the old awk-mode.el package in favor of the AWK support in CC Mode.
author | Martin Stjernholm <mast@lysator.liu.se> |
---|---|
date | Thu, 17 Jul 2003 11:40:43 +0000 |
parents | |
children | 695cf19ef79e |
comparison
equal
deleted
inserted
replaced
51954:cde857fd741d | 51955:55e857ca3791 |
---|---|
1 ;;; awk-mode.el --- AWK code editing commands for Emacs | |
2 | |
3 ;; Copyright (C) 1988,94,96,2000 Free Software Foundation, Inc. | |
4 | |
5 ;; Maintainer: FSF | |
6 ;; Keywords: unix, languages | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
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) | |
13 ;; any later version. | |
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 | |
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. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; Sets up C-mode with support for awk-style #-comments and a lightly | |
28 ;; hacked syntax table. | |
29 | |
30 ;;; Code: | |
31 | |
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.") | |
55 | |
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. | |
62 '("^[ \t]*\\(function\\)\\>[ \t]*\\(\\sw+\\)?" | |
63 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)) | |
64 ;; | |
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) | |
71 ;; | |
72 ;; Keywords. | |
73 (regexp-opt | |
74 '("BEGIN" "END" "break" "continue" "delete" "exit" "else" "for" | |
75 "getline" "if" "next" "print" "printf" "return" "while") 'words) | |
76 ;; | |
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) | |
84 ;; | |
85 ;; Operators. Is this too much? | |
86 (cons (regexp-opt '("&&" "||" "<=" "<" ">=" ">" "==" "!=" "!~" "~")) | |
87 'font-lock-constant-face) | |
88 )) | |
89 "Default expressions to highlight in AWK mode.") | |
90 | |
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 | |
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. | |
109 | |
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)))) | |
121 | |
122 (provide 'awk-mode) | |
123 | |
124 ;;; awk-mode.el ends here |