annotate lisp/progmodes/awk-mode.el @ 49822:02529e3b1f2c

(vc-cvs-dir-state): Protect against DIR not being under CVS control.
author André Spiegel <spiegel@gnu.org>
date Mon, 17 Feb 2003 08:11:13 +0000
parents c6e48d7cdb07
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 257
diff changeset
1 ;;; awk-mode.el --- AWK code editing commands for Emacs
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 257
diff changeset
2
33210
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
3 ;; Copyright (C) 1988,94,96,2000 Free Software Foundation, Inc.
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
4
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
5 ;; Maintainer: FSF
2247
2c7997f249eb Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 845
diff changeset
6 ;; Keywords: unix, languages
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
7
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;; any later version.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; GNU General Public License for more details.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13471
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13471
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13471
diff changeset
23 ;; Boston, MA 02111-1307, USA.
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
25 ;;; Commentary:
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
26
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
27 ;; Sets up C-mode with support for awk-style #-comments and a lightly
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
28 ;; hacked syntax table.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
29
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
30 ;;; Code:
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31
39833
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
32 (defvar awk-mode-syntax-table
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
33 (let ((st (make-syntax-table)))
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
34 (modify-syntax-entry ?\\ "\\" st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
35 (modify-syntax-entry ?\n "> " st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
36 (modify-syntax-entry ?\f "> " st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
37 (modify-syntax-entry ?\# "< " st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
38 ;; / can delimit regexes or be a division operator. We assume that it is
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
39 ;; more commonly used for regexes and fix the remaining cases with
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
40 ;; `font-lock-syntactic-keywords'.
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
41 (modify-syntax-entry ?/ "\"" st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
42 (modify-syntax-entry ?* "." st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
43 (modify-syntax-entry ?+ "." st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
44 (modify-syntax-entry ?- "." st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
45 (modify-syntax-entry ?= "." st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
46 (modify-syntax-entry ?% "." st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
47 (modify-syntax-entry ?< "." st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
48 (modify-syntax-entry ?> "." st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
49 (modify-syntax-entry ?& "." st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
50 (modify-syntax-entry ?| "." st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
51 (modify-syntax-entry ?_ "_" st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
52 (modify-syntax-entry ?\' "\"" st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
53 st)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
54 "Syntax table in use in `awk-mode' buffers.")
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55
16451
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
56 ;; Regexps written with help from Peter Galbraith <galbraith@mixing.qc.dfo.ca>.
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
57 (defconst awk-font-lock-keywords
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
58 (eval-when-compile
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
59 (list
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
60 ;;
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
61 ;; Function names.
33210
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
62 '("^[ \t]*\\(function\\)\\>[ \t]*\\(\\sw+\\)?"
16451
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
63 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
64 ;;
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
65 ;; Variable names.
33210
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
66 (cons (regexp-opt
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
67 '("ARGC" "ARGIND" "ARGV" "CONVFMT" "ENVIRON" "ERRNO"
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
68 "FIELDWIDTHS" "FILENAME" "FNR" "FS" "IGNORECASE" "NF" "NR"
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
69 "OFMT" "OFS" "ORS" "RLENGTH" "RS" "RSTART" "SUBSEP") 'words)
16451
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
70 'font-lock-variable-name-face)
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
71 ;;
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
72 ;; Keywords.
33210
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
73 (regexp-opt
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
74 '("BEGIN" "END" "break" "continue" "delete" "exit" "else" "for"
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
75 "getline" "if" "next" "print" "printf" "return" "while") 'words)
16451
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
76 ;;
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
77 ;; Builtins.
33210
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
78 (list (regexp-opt
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
79 '("atan2" "close" "cos" "ctime" "exp" "gsub" "index" "int"
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
80 "length" "log" "match" "rand" "sin" "split" "sprintf"
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
81 "sqrt" "srand" "sub" "substr" "system" "time"
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
82 "tolower" "toupper") 'words)
16451
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
83 1 'font-lock-builtin-face)
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
84 ;;
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
85 ;; Operators. Is this too much?
33210
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
86 (cons (regexp-opt '("&&" "||" "<=" "<" ">=" ">" "==" "!=" "!~" "~"))
20953
f3f9df46d008 Changed font-lock-reference-face to font-lock-constant-face.
Simon Marshall <simon@gnu.org>
parents: 19322
diff changeset
87 'font-lock-constant-face)
16451
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
88 ))
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
89 "Default expressions to highlight in AWK mode.")
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
90
39833
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
91 (require 'syntax)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
92
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
93 (defconst awk-font-lock-syntactic-keywords
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
94 ;; `/' is mostly used for /.../ regular expressions, but is also
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
95 ;; used as a division operator. Distinguishing between the two is
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
96 ;; a pain in the youknowwhat.
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
97 ;; '(("\\(^\\|[<=>-+*%/!^,~(?:|&]\\)\\s-*\\(/\\)\\([^/\n\\]\\|\\\\.\\)*\\(/\\)"
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
98 ;; (2 "\"") (4 "\"")))
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
99 '(("[^<=>-+*%/!^,~(?:|& \t\n\f]\\s-*\\(/\\)"
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
100 (1 (unless (nth 3 (syntax-ppss (match-beginning 1))) "."))))
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
101 "Syntactic keywords for `awk-mode'.")
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
102
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 ;;;###autoload
33210
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
104 (define-derived-mode awk-mode c-mode "AWK"
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 "Major mode for editing AWK code.
33210
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
106 This is much like C mode except for the syntax of comments. Its keymap
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
107 inherits from C mode's and it has the same variables for customizing
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 indentation. It has its own abbrev table and its own syntax table.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109
33210
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
110 Turning on AWK mode runs `awk-mode-hook'."
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
111 (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter))
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
112 (set (make-local-variable 'paragraph-separate) paragraph-start)
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
113 (set (make-local-variable 'comment-start) "# ")
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
114 (set (make-local-variable 'comment-end) "")
19d92160ddac Update copyright.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31984
diff changeset
115 (set (make-local-variable 'comment-start-skip) "#+ *")
39833
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
116 (setq font-lock-defaults '(awk-font-lock-keywords
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
117 nil nil ((?_ . "w")) nil
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
118 (parse-sexp-lookup-properties . t)
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
119 (font-lock-syntactic-keywords
c6e48d7cdb07 (awk-mode-syntax-table): / has string syntax.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33210
diff changeset
120 . awk-font-lock-syntactic-keywords))))
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 257
diff changeset
121
16451
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
122 (provide 'awk-mode)
0e181c85b17e Add Font Lock support. Provide when loaded.
Simon Marshall <simon@gnu.org>
parents: 14169
diff changeset
123
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 257
diff changeset
124 ;;; awk-mode.el ends here