annotate lisp/progmodes/cc-awk.el @ 64400:e169c8755108

(allout-isearch-did-quit): Variable deleted. (allout-real-isearch-abort): Function name no longer used. (allout-mode): Do allout-enwrap-isearch whenever feature is wanted. (allout-isearch-rectification): isearch-mode always exists. Don't set allout-isearch-did-quit. (allout-isearch-expose): Check isearch-mode-end-hook-error, not allout-isearch-did-quit. (allout-enwrap-isearch): Just add the hook. (allout-isearch-abort): Function deleted. (allout-pre-command-business): Avoid warning.
author Richard M. Stallman <rms@gnu.org>
date Sat, 16 Jul 2005 19:15:06 +0000
parents 18a818a2ee7c
children 629afbe74e61 f9a65d7ebd29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
1 ;;; cc-awk.el --- AWK specific code within cc-mode.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
2
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
3 ;; Copyright (C) 1988,94,96,2000,01,02,03 Free Software Foundation, Inc.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
4
62641
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
5 ;; Author: Alan Mackenzie <acm@muc.de> (originally based on awk-mode.el)
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
6 ;; Maintainer: FSF
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
7 ;; Keywords: AWK, cc-mode, unix, languages
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
8
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
10
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
14 ;; any later version.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
15
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
19 ;; GNU General Public License for more details.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
20
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63517
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63517
diff changeset
24 ;; Boston, MA 02110-1301, USA.
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
25
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
26 ;;; Commentary:
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
27
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
28 ;; This file contains (most of) the adaptations to cc-mode required for the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
29 ;; integration of AWK Mode.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
30 ;; It is organised thusly:
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
31 ;; 1. The AWK Mode syntax table.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
32 ;; 2. Indentation calculation stuff ("c-awk-NL-prop text-property").
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
33 ;; 3. Syntax-table property/font-locking stuff, but not including the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
34 ;; font-lock-keywords setting.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
35 ;; 4. The AWK Mode before/after-change-functions.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
36 ;; 5. AWK Mode specific versions of commands like beginning-of-defun.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
37 ;; The AWK Mode keymap, abbreviation table, and the mode function itself are
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
38 ;; in cc-mode.el.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
39
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
40 ;;; Code:
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
41
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
42 (eval-when-compile
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
43 (let ((load-path
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
44 (if (and (boundp 'byte-compile-dest-file)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
45 (stringp byte-compile-dest-file))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
46 (cons (file-name-directory byte-compile-dest-file) load-path)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
47 load-path)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
48 (load "cc-bytecomp" nil t)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
49
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
50 (cc-require 'cc-defs)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
51
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
52 ;; Silence the byte compiler.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
53 (cc-bytecomp-defvar font-lock-mode) ; Checked with boundp before use.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
54
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
55 ;; Some functions in cc-engine that are used below. There's a cyclic
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
56 ;; dependency so it can't be required here. (Perhaps some functions
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
57 ;; could be moved to cc-engine to avoid it.)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
58 (cc-bytecomp-defun c-backward-token-1)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
59 (cc-bytecomp-defun c-beginning-of-statement-1)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
60 (cc-bytecomp-defun c-backward-sws)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
61
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
62 (defvar awk-mode-syntax-table
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
63 (let ((st (make-syntax-table)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
64 (modify-syntax-entry ?\\ "\\" st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
65 (modify-syntax-entry ?\n "> " st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
66 (modify-syntax-entry ?\r "> " st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
67 (modify-syntax-entry ?\f "> " st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
68 (modify-syntax-entry ?\# "< " st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
69 ;; / can delimit regexes or be a division operator. By default we assume
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
70 ;; that it is a division sign, and fix the regexp operator cases with
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
71 ;; `font-lock-syntactic-keywords'.
63517
7316ffa5763c (c-awk-beginning-of-defun): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62641
diff changeset
72 (modify-syntax-entry ?/ "." st) ; ACM 2002/4/27.
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
73 (modify-syntax-entry ?* "." st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
74 (modify-syntax-entry ?+ "." st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
75 (modify-syntax-entry ?- "." st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
76 (modify-syntax-entry ?= "." st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
77 (modify-syntax-entry ?% "." st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
78 (modify-syntax-entry ?< "." st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
79 (modify-syntax-entry ?> "." st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
80 (modify-syntax-entry ?& "." st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
81 (modify-syntax-entry ?| "." st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
82 (modify-syntax-entry ?_ "_" st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
83 (modify-syntax-entry ?\' "." st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
84 st)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
85 "Syntax table in use in AWK Mode buffers.")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
86
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
87 ;; ACM, 2002/5/29:
63517
7316ffa5763c (c-awk-beginning-of-defun): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62641
diff changeset
88 ;;
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
89 ;; The next section of code is about determining whether or not an AWK
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
90 ;; statement is complete or not. We use this to indent the following line.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
91 ;; The determination is pretty straightforward in C, where a statement ends
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
92 ;; with either a ; or a }. Only "while" really gives any trouble there, since
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
93 ;; it might be the end of a do-while. In AWK, on the other hand, semicolons
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
94 ;; are rarely used, and EOLs _usually_ act as "virtual semicolons". In
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
95 ;; addition, we have the complexity of escaped EOLs. The core of this
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
96 ;; analysis is in the middle of the function
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
97 ;; c-awk-calculate-NL-prop-prev-line, about 130 lines lower down.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
98 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
99 ;; To avoid continually repeating this expensive analysis, we "cache" its
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
100 ;; result in a text-property, c-awk-NL-prop, whose value for a line is set on
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
101 ;; the EOL (if any) which terminates that line. Should the property be
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
102 ;; required for the very last line (which has no EOL), it is calculated as
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
103 ;; required but not cached. The c-awk-NL-prop property should be thought of
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
104 ;; as only really valid immediately after a buffer change, not a permanently
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
105 ;; set property. (By contrast, the syntax-table text properties (set by an
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
106 ;; after-change function) must be constantly updated for the mode to work
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
107 ;; properly).
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
108 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
109 ;; The valid values for c-awk-NL-prop are:
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
110 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
111 ;; nil The property is not currently set for this line.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
112 ;; '#' There is NO statement on this line (at most a comment), and no open
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
113 ;; statement from a previous line which could have been completed on this
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
114 ;; line.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
115 ;; '{' There is an unfinished statement on this (or a previous) line which
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
116 ;; doesn't require \s to continue onto another line, e.g. the line ends
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
117 ;; with {, or the && operator, or "if (condition)". Note that even if the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
118 ;; newline is redundantly escaped, it remains a '{' line.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
119 ;; '\' There is an escaped newline at the end of this line and this '\' is
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
120 ;; essential to the syntax of the program. (i.e. if it had been a
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
121 ;; frivolous \, it would have been ignored and the line been given one of
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
122 ;; the other property values.)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
123 ;; ';' A statement is completed as the last thing (aside from ws) on the line -
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
124 ;; i.e. there is (at least part of) a statement on this line, and the last
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
125 ;; statement on the line is complete, OR (2002/10/25) the line is
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
126 ;; content-free but terminates a statement from the preceding (continued)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
127 ;; line (which has property \).
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
128 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
129 ;; This set of values has been chosen so that the property's value on a line
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
130 ;; is completely determined by the contents of the line and the property on
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
131 ;; the previous line, EXCEPT for where a "while" might be the closing
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
132 ;; statement of a do-while.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
133
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
134 (defun c-awk-after-if-for-while-condition-p (&optional do-lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
135 ;; Are we just after the ) in "if/for/while (<condition>)"?
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
136 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
137 ;; Note that the end of the ) in a do .... while (<condition>) doesn't
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
138 ;; count, since the purpose of this routine is essentially to decide
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
139 ;; whether to indent the next line.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
140 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
141 ;; DO-LIM sets a limit on how far back we search for the "do" of a possible
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
142 ;; do-while.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
143 (and
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
144 (eq (char-before) ?\))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
145 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
146 (let ((par-pos (c-safe (scan-lists (point) -1 0))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
147 (when par-pos
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
148 (goto-char par-pos) ; back over "(...)"
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
149 (c-backward-token-1) ; BOB isn't a problem.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
150 (or (looking-at "\\(if\\|for\\)\\>\\([^_]\\|$\\)")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
151 (and (looking-at "while\\>\\([^_]\\|$\\)") ; Ensure this isn't a do-while.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
152 (not (eq (c-beginning-of-statement-1 do-lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
153 'beginning)))))))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
154
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
155 (defun c-awk-after-function-decl-param-list ()
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
156 ;; Are we just after the ) in "function foo (bar)" ?
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
157 (and (eq (char-before) ?\))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
158 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
159 (let ((par-pos (c-safe (scan-lists (point) -1 0))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
160 (when par-pos
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
161 (goto-char par-pos) ; back over "(...)"
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
162 (c-backward-token-1) ; BOB isn't a problem
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
163 (and (looking-at "[_a-zA-Z][_a-zA-Z0-9]*\\>")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
164 (progn (c-backward-token-1)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
165 (looking-at "func\\(tion\\)?\\>"))))))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
166
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
167 ;; 2002/11/8: FIXME! Check c-backward-token-1/2 for success (0 return code).
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
168 (defun c-awk-after-continue-token ()
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
169 ;; Are we just after a token which can be continued onto the next line without
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
170 ;; a backslash?
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
171 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
172 (c-backward-token-1) ; FIXME 2002/10/27. What if this fails?
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
173 (if (and (looking-at "[&|]") (not (bobp)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
174 (backward-char)) ; c-backward-token-1 doesn't do this :-(
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
175 (looking-at "[,{?:]\\|&&\\|||\\|do\\>\\|else\\>")))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
176
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
177 (defun c-awk-after-rbrace-or-statement-semicolon ()
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
178 ;; Are we just after a } or a ; which closes a statement?
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
179 ;; Be careful about ;s in for loop control bits. They don't count!
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
180 (or (eq (char-before) ?\})
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
181 (and
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
182 (eq (char-before) ?\;)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
183 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
184 (let ((par-pos (c-safe (scan-lists (point) -1 1))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
185 (when par-pos
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
186 (goto-char par-pos) ; go back to containing (
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
187 (not (and (looking-at "(")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
188 (c-backward-token-1) ; BOB isn't a problem
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
189 (looking-at "for\\>")))))))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
190
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
191 (defun c-awk-back-to-contentful-text-or-NL-prop ()
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
192 ;; Move back to just after the first found of either (i) an EOL which has
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
193 ;; the c-awk-NL-prop text-property set; or (ii) non-ws text; or (iii) BOB.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
194 ;; We return either the value of c-awk-NL-prop (in case (i)) or nil.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
195 ;; Calling function can best distinguish cases (ii) and (iii) with (bolp).
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
196 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
197 ;; Note that an escaped eol counts as whitespace here.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
198 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
199 ;; Kludge: If c-backward-syntactic-ws gets stuck at a BOL, it is likely
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
200 ;; that the previous line contains an unterminated string (without \). In
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
201 ;; this case, assume that the previous line's c-awk-NL-prop is a ;.
63517
7316ffa5763c (c-awk-beginning-of-defun): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62641
diff changeset
202 ;;
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
203 ;; POINT MUST BE AT THE START OF A LINE when calling this function. This
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
204 ;; is to ensure that the various backward-comment functions will work
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
205 ;; properly.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
206 (let ((nl-prop nil)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
207 bol-pos bsws-pos) ; starting pos for a backward-syntactic-ws call.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
208 (while ;; We are at a BOL here. Go back one line each iteration.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
209 (and
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
210 (not (bobp))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
211 (not (setq nl-prop (c-get-char-property (1- (point)) 'c-awk-NL-prop)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
212 (progn (setq bol-pos (c-point 'bopl))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
213 (setq bsws-pos (point))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
214 ;; N.B. the following function will not go back past an EOL if
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
215 ;; there is an open string (without \) on the previous line.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
216 (c-backward-syntactic-ws bol-pos)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
217 (or (/= (point) bsws-pos)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
218 (progn (setq nl-prop ?\;)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
219 nil)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
220 ;; If we had a backslash at EOL, c-backward-syntactic-ws will
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
221 ;; have gone backwards over it. Check the backslash was "real".
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
222 (progn
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
223 (if (looking-at "[ \t]*\\\\+$")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
224 (if (progn
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
225 (end-of-line)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
226 (search-backward-regexp
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
227 "\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\$" ; ODD number of \s at EOL :-)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
228 bol-pos t))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
229 (progn (end-of-line) ; escaped EOL.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
230 (backward-char)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
231 (c-backward-syntactic-ws bol-pos))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
232 (end-of-line))) ; The \ at eol is a fake.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
233 (bolp))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
234 nl-prop))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
235
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
236 (defun c-awk-calculate-NL-prop-prev-line (&optional do-lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
237 ;; Calculate and set the value of the c-awk-NL-prop on the immediately
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
238 ;; preceding EOL. This may also involve doing the same for several
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
239 ;; preceding EOLs.
63517
7316ffa5763c (c-awk-beginning-of-defun): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62641
diff changeset
240 ;;
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
241 ;; NOTE that if the property was already set, we return it without
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
242 ;; recalculation. (This is by accident rather than design.)
63517
7316ffa5763c (c-awk-beginning-of-defun): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62641
diff changeset
243 ;;
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
244 ;; Return the property which got set (or was already set) on the previous
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
245 ;; line. Return nil if we hit BOB.
63517
7316ffa5763c (c-awk-beginning-of-defun): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62641
diff changeset
246 ;;
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
247 ;; See c-awk-after-if-for-while-condition-p for a description of DO-LIM.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
248 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
249 (save-match-data
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
250 (beginning-of-line)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
251 (let* ((pos (point))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
252 (nl-prop (c-awk-back-to-contentful-text-or-NL-prop)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
253 ;; We are either (1) at a BOL (with nl-prop containing the previous
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
254 ;; line's c-awk-NL-prop) or (2) after contentful text on a line. At
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
255 ;; the BOB counts as case (1), so we test next for bolp rather than
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
256 ;; non-nil nl-prop.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
257 (when (not (bolp))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
258 (setq nl-prop
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
259 (cond
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
260 ;; Incomplete statement which doesn't require escaped EOL?
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
261 ((or (c-awk-after-if-for-while-condition-p do-lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
262 (c-awk-after-function-decl-param-list)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
263 (c-awk-after-continue-token))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
264 ?\{)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
265 ;; Escaped EOL (where there's also something to continue)?
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
266 ((and (looking-at "[ \t]*\\\\$")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
267 (not (c-awk-after-rbrace-or-statement-semicolon)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
268 ?\\)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
269 (t ?\;))) ; A statement was completed on this line
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
270 (end-of-line)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
271 (c-put-char-property (point) 'c-awk-NL-prop nl-prop)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
272 (forward-line))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
273
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
274 ;; We are now at a (possibly empty) sequence of content-free lines.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
275 ;; Set c-awk-NL-prop on each of these lines's EOL.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
276 (while (< (point) pos) ; one content-free line each iteration.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
277 (cond ; recalculate nl-prop from previous line's value.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
278 ((memq nl-prop '(?\; nil)) (setq nl-prop ?\#))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
279 ((eq nl-prop ?\\)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
280 (if (not (looking-at "[ \t]*\\\\$")) (setq nl-prop ?\;))) ; was ?\# 2002/10/25
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
281 ;; ?\# (empty line) and ?\{ (open stmt) don't change.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
282 )
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
283 (forward-line)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
284 (c-put-char-property (1- (point)) 'c-awk-NL-prop nl-prop))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
285 nl-prop))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
286
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
287 (defun c-awk-get-NL-prop-prev-line (&optional do-lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
288 ;; Get the c-awk-NL-prop text-property from the previous line, calculating
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
289 ;; it if necessary. Return nil iff we're already at BOB.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
290 ;; See c-awk-after-if-for-while-condition-p for a description of DO-LIM.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
291 (if (bobp)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
292 nil
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
293 (or (c-get-char-property (c-point 'eopl) 'c-awk-NL-prop)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
294 (c-awk-calculate-NL-prop-prev-line do-lim))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
295
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
296 (defun c-awk-get-NL-prop-cur-line (&optional do-lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
297 ;; Get the c-awk-NL-prop text-property from the current line, calculating it
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
298 ;; if necessary. (As a special case, the property doesn't get set on an
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
299 ;; empty line at EOB (there's no position to set the property on), but the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
300 ;; function returns the property value an EOL would have got.)
63517
7316ffa5763c (c-awk-beginning-of-defun): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62641
diff changeset
301 ;;
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
302 ;; See c-awk-after-if-for-while-condition-p for a description of DO-LIM.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
303 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
304 (let ((extra-nl nil))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
305 (end-of-line) ; Necessary for the following test to work.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
306 (when (= (forward-line) 1) ; if we were on the last line....
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
307 (insert-char ?\n 1) ; ...artificial eol is needed for comment detection.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
308 (setq extra-nl t))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
309 (prog1 (c-awk-get-NL-prop-prev-line do-lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
310 (if extra-nl (delete-backward-char 1))))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
311
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
312 (defun c-awk-prev-line-incomplete-p (&optional do-lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
313 ;; Is there an incomplete statement at the end of the previous line?
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
314 ;; See c-awk-after-if-for-while-condition-p for a description of DO-LIM.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
315 (memq (c-awk-get-NL-prop-prev-line do-lim) '(?\\ ?\{)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
316
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
317 (defun c-awk-cur-line-incomplete-p (&optional do-lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
318 ;; Is there an incomplete statement at the end of the current line?
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
319 ;; See c-awk-after-if-for-while-condition-p for a description of DO-LIM.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
320 (memq (c-awk-get-NL-prop-cur-line do-lim) '(?\\ ?\{)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
321
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
322 (defun c-awk-completed-stmt-ws-ends-prev-line-p (&optional do-lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
323 ;; Is there a termination of a statement as the last thing (apart from an
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
324 ;; optional comment) on the previous line?
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
325 ;; See c-awk-after-if-for-while-condition-p for a description of DO-LIM.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
326 (eq (c-awk-get-NL-prop-prev-line do-lim) ?\;))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
327
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
328 (defun c-awk-completed-stmt-ws-ends-line-p (&optional pos do-lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
329 ;; Same as previous function, but for the line containing position POS (or
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
330 ;; the current line if POS is omitted).
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
331 ;; See c-awk-after-if-for-while-condition-p for a description of DO-LIM.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
332 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
333 (if pos (goto-char pos))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
334 (eq (c-awk-get-NL-prop-cur-line do-lim) ?\;)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
335
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
336 (defun c-awk-after-logical-semicolon (&optional do-lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
337 ;; Are we at BOL, the preceding EOL being a "logical semicolon"?
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
338 ;; See c-awk-after-if-for-while-condition-p for a description of DO-LIM.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
339 (and (bolp)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
340 (eq (c-awk-get-NL-prop-prev-line do-lim) ?\;)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
341
63517
7316ffa5763c (c-awk-beginning-of-defun): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62641
diff changeset
342 (defun c-awk-backward-syntactic-ws (&optional lim)
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
343 ;; Skip backwards over awk-syntactic whitespace. This is whitespace
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
344 ;; characters, comments, and NEWLINES WHICH AREN'T "VIRTUAL SEMICOLONS". For
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
345 ;; this function, a newline isn't a "virtual semicolon" if that line ends with
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
346 ;; a real semicolon (or closing brace).
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
347 ;; However if point starts inside a comment or preprocessor directive, the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
348 ;; content of it is not treated as whitespace. LIM (optional) sets a limit on
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
349 ;; the backward movement.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
350 (let ((lim (or lim (point-min)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
351 after-real-br)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
352 (c-backward-syntactic-ws (max lim (c-point 'bol)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
353 (while ; go back one WS line each time round this loop.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
354 (and (bolp)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
355 (> (point) lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
356 (/= (c-awk-get-NL-prop-prev-line) ?\;)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
357 (/= (point)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
358 ;; The following function requires point at BONL [not EOL] to
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
359 ;; recognise a preceding comment,.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
360 (progn (c-backward-syntactic-ws (max lim (c-point 'bopl)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
361 (point)))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
362 ;; Does the previous line end with a real ; or }? If so, go back to it.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
363 (if (and (bolp)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
364 (eq (c-awk-get-NL-prop-prev-line) ?\;)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
365 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
366 (c-backward-syntactic-ws (max lim (c-point 'bopl)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
367 (setq after-real-br (point))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
368 (c-awk-after-rbrace-or-statement-semicolon)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
369 (goto-char after-real-br))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
370
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
371 (defun c-awk-NL-prop-not-set ()
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
372 ;; Is the NL-prop on the current line either nil or unset?
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
373 (not (c-get-char-property (c-point 'eol) 'c-awk-NL-prop)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
374
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
375 (defun c-awk-clear-NL-props (beg end)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
376 ;; This function is run from before-change-hooks. It clears the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
377 ;; c-awk-NL-prop text property from beg to the end of the buffer (The END
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
378 ;; parameter is ignored). This ensures that the indentation engine will
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
379 ;; never use stale values for this property.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
380 (save-restriction
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
381 (widen)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
382 (c-clear-char-properties beg (point-max) 'c-awk-NL-prop)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
383
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
384 (defun c-awk-unstick-NL-prop ()
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
385 ;; Ensure that the text property c-awk-NL-prop is "non-sticky". Without
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
386 ;; this, a new newline inserted after an old newline (e.g. by C-j) would
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
387 ;; inherit any c-awk-NL-prop from the old newline. This would be a Bad
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
388 ;; Thing. This function's action is required by c-put-char-property.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
389 (if (and (boundp 'text-property-default-nonsticky) ; doesn't exist in Xemacs
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
390 (not (assoc 'c-awk-NL-prop text-property-default-nonsticky)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
391 (setq text-property-default-nonsticky
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
392 (cons '(c-awk-NL-prop . t) text-property-default-nonsticky))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
393
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
394 ;; The following is purely a diagnostic command, to be commented out of the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
395 ;; final release. ACM, 2002/6/1
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
396 ;; (defun NL-props ()
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
397 ;; (interactive)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
398 ;; (let (pl-prop cl-prop)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
399 ;; (message "Prev-line: %s Cur-line: %s"
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
400 ;; (if (setq pl-prop (c-get-char-property (c-point 'eopl) 'c-awk-NL-prop))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
401 ;; (char-to-string pl-prop)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
402 ;; "nil")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
403 ;; (if (setq cl-prop (c-get-char-property (c-point 'eol) 'c-awk-NL-prop))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
404 ;; (char-to-string cl-prop)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
405 ;; "nil"))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
406 ;(define-key awk-mode-map [?\C-c ?\r] 'NL-props) ; commented out, 2002/8/31
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
407 ;for now. In the byte compiled version, this causes things to crash because
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
408 ;awk-mode-map isn't yet defined. :-(
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
409
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
410 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
411
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
412 ;; The following section of the code is to do with font-locking. The biggest
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
413 ;; problem for font-locking is deciding whether a / is a regular expression
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
414 ;; delimiter or a division sign - determining precisely where strings and
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
415 ;; regular expressions start and stop is also troublesome. This is the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
416 ;; purpose of the function c-awk-set-syntax-table-properties and the myriad
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
417 ;; elisp regular expressions it uses.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
418 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
419 ;; Because AWK is a line oriented language, I felt the normal cc-mode strategy
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
420 ;; for font-locking unterminated strings (i.e. font-locking the buffer up to
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
421 ;; the next string delimiter as a string) was inappropriate. Instead,
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
422 ;; unbalanced string/regexp delimiters are given the warning font, being
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
423 ;; refonted with the string font as soon as the matching delimiter is entered.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
424 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
425 ;; This requires the region processed by the current font-lock after-change
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
426 ;; function to have access to the start of the string/regexp, which may be
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
427 ;; several lines back. The elisp "advice" feature is used on these functions
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
428 ;; to allow this.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
429
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
430 (defun c-awk-beginning-of-logical-line (&optional pos)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
431 ;; Go back to the start of the (apparent) current line (or the start of the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
432 ;; line containing POS), returning the buffer position of that point. I.e.,
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
433 ;; go back to the last line which doesn't have an escaped EOL before it.
63517
7316ffa5763c (c-awk-beginning-of-defun): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62641
diff changeset
434 ;;
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
435 ;; This is guaranteed to be "safe" for syntactic analysis, i.e. outwith any
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
436 ;; comment, string or regexp. IT MAY WELL BE that this function should not be
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
437 ;; executed on a narrowed buffer.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
438 (if pos (goto-char pos))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
439 (forward-line 0)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
440 (while (and (> (point) (point-min))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
441 (eq (char-before (1- (point))) ?\\))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
442 (forward-line -1))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
443 (point))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
444
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
445 (defun c-awk-end-of-logical-line (&optional pos)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
446 ;; Go forward to the end of the (apparent) current logical line (or the end of
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
447 ;; the line containing POS), returning the buffer position of that point. I.e.,
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
448 ;; go to the end of the next line which doesn't have an escaped EOL.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
449 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
450 ;; This is guaranteed to be "safe" for syntactic analysis, i.e. outwith any
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
451 ;; comment, string or regexp. IT MAY WELL BE that this function should not be
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
452 ;; executed on a narrowed buffer.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
453 (if pos (goto-char pos))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
454 (end-of-line)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
455 (while (and (< (point) (point-max))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
456 (eq (char-before) ?\\))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
457 (end-of-line 2))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
458 (point))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
459
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
460 ;; N.B. In the following regexps, an EOL is either \n OR \r. This is because
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
461 ;; Emacs has in the past used \r to mark hidden lines in some fashion (and
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
462 ;; maybe still does).
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
463
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
464 (defconst c-awk-esc-pair-re "\\\\\\(.\\|\n\\|\r\\|\\'\\)")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
465 ;; Matches any escaped (with \) character-pair, including an escaped newline.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
466 (defconst c-awk-comment-without-nl "#.*")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
467 ;; Matches an AWK comment, not including the terminating NL (if any). Note
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
468 ;; that the "enclosing" (elisp) regexp must ensure the # is real.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
469 (defconst c-awk-nl-or-eob "\\(\n\\|\r\\|\\'\\)")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
470 ;; Matches a newline, or the end of buffer.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
471
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
472 ;; "Space" regular expressions.
63517
7316ffa5763c (c-awk-beginning-of-defun): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62641
diff changeset
473 (defconst c-awk-escaped-nl "\\\\[\n\r]")
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
474 ;; Matches an escaped newline.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
475 (defconst c-awk-escaped-nls* (concat "\\(" c-awk-escaped-nl "\\)*"))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
476 ;; Matches a possibly empty sequence of escaped newlines. Used in
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
477 ;; awk-font-lock-keywords.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
478 ;; (defconst c-awk-escaped-nls*-with-space*
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
479 ;; (concat "\\(" c-awk-escaped-nls* "\\|" "[ \t]+" "\\)*"))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
480 ;; The above RE was very slow. It's runtime was doubling with each additional
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
481 ;; space :-( Reformulate it as below:
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
482 (defconst c-awk-escaped-nls*-with-space*
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
483 (concat "\\(" c-awk-escaped-nl "\\|" "[ \t]" "\\)*"))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
484 ;; Matches a possibly empty sequence of escaped newlines with optional
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
485 ;; interspersed spaces and tabs. Used in awk-font-lock-keywords.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
486
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
487 ;; REGEXPS FOR "HARMLESS" STRINGS/LINES.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
488 (defconst c-awk-harmless-char-re "[^_#/\"\\\\\n\r]")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
489 ;; Matches any character but a _, #, /, ", \, or newline. N.B. _" starts a
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
490 ;; localisation string in gawk 3.1
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
491 (defconst c-awk-harmless-_ "_\\([^\"]\\|\\'\\)")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
492 ;; Matches an underline NOT followed by ".
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
493 (defconst c-awk-harmless-string*-re
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
494 (concat "\\(" c-awk-harmless-char-re "\\|" c-awk-esc-pair-re "\\|" c-awk-harmless-_ "\\)*"))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
495 ;; Matches a (possibly empty) sequence of chars without unescaped /, ", \,
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
496 ;; #, or newlines.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
497 (defconst c-awk-harmless-string*-here-re
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
498 (concat "\\=" c-awk-harmless-string*-re))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
499 ;; Matches the (possibly empty) sequence of chars without unescaped /, ", \,
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
500 ;; at point.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
501 (defconst c-awk-harmless-line-re
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
502 (concat c-awk-harmless-string*-re
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
503 "\\(" c-awk-comment-without-nl "\\)?" c-awk-nl-or-eob))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
504 ;; Matches (the tail of) an AWK \"logical\" line not containing an unescaped
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
505 ;; " or /. "logical" means "possibly containing escaped newlines". A comment
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
506 ;; is matched as part of the line even if it contains a " or a /. The End of
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
507 ;; buffer is also an end of line.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
508 (defconst c-awk-harmless-lines+-here-re
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
509 (concat "\\=\\(" c-awk-harmless-line-re "\\)+"))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
510 ;; Matches a sequence of (at least one) \"harmless-line\" at point.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
511
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
512
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
513 ;; REGEXPS FOR AWK STRINGS.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
514 (defconst c-awk-string-ch-re "[^\"\\\n\r]")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
515 ;; Matches any character which can appear unescaped in a string.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
516 (defconst c-awk-string-innards-re
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
517 (concat "\\(" c-awk-string-ch-re "\\|" c-awk-esc-pair-re "\\)*"))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
518 ;; Matches the inside of an AWK string (i.e. without the enclosing quotes).
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
519 (defconst c-awk-string-without-end-here-re
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
520 (concat "\\=_?\"" c-awk-string-innards-re))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
521 ;; Matches an AWK string at point up to, but not including, any terminator.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
522 ;; A gawk 3.1+ string may look like _"localisable string".
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
523
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
524 ;; REGEXPS FOR AWK REGEXPS.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
525 (defconst c-awk-regexp-normal-re "[^[/\\\n\r]")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
526 ;; Matches any AWK regexp character which doesn't require special analysis.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
527 (defconst c-awk-escaped-newlines*-re "\\(\\\\[\n\r]\\)*")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
528 ;; Matches a (possibly empty) sequence of escaped newlines.
62641
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
529
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
530 ;; NOTE: In what follows, "[asdf]" in a regexp will be called a "character
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
531 ;; list", and "[:alpha:]" inside a character list will be known as a
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
532 ;; "character class". These terms for these things vary between regexp
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
533 ;; descriptions .
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
534 (defconst c-awk-regexp-char-class-re
62641
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
535 "\\[:[a-z]+:\\]")
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
536 ;; Matches a character class spec (e.g. [:alpha:]).
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
537 (defconst c-awk-regexp-char-list-re
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
538 (concat "\\[" c-awk-escaped-newlines*-re "^?" c-awk-escaped-newlines*-re "]?"
62641
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
539 "\\(" c-awk-esc-pair-re "\\|" c-awk-regexp-char-class-re
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
540 "\\|" "[^]\n\r]" "\\)*" "\\(]\\|$\\)"))
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
541 ;; Matches a regexp char list, up to (but not including) EOL if the ] is
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
542 ;; missing.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
543 (defconst c-awk-regexp-innards-re
62641
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
544 (concat "\\(" c-awk-esc-pair-re "\\|" c-awk-regexp-char-list-re
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
545 "\\|" c-awk-regexp-normal-re "\\)*"))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
546 ;; Matches the inside of an AWK regexp (i.e. without the enclosing /s)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
547 (defconst c-awk-regexp-without-end-re
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
548 (concat "/" c-awk-regexp-innards-re))
63517
7316ffa5763c (c-awk-beginning-of-defun): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62641
diff changeset
549 ;; Matches an AWK regexp up to, but not including, any terminating /.
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
550
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
551 ;; REGEXPS used for scanning an AWK buffer in order to decide IF A '/' IS A
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
552 ;; REGEXP OPENER OR A DIVISION SIGN. By "state" in the following is meant
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
553 ;; whether a '/' at the current position would by a regexp opener or a
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
554 ;; division sign.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
555 (defconst c-awk-neutral-re
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
556 ; "\\([{}@` \t]\\|\\+\\+\\|--\\|\\\\.\\)+") ; changed, 2003/6/7
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
557 "\\([{}@` \t]\\|\\+\\+\\|--\\|\\\\.\\)")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
558 ;; A "neutral" char(pair). Doesn't change the "state" of a subsequent /.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
559 ;; This is space/tab, braces, an auto-increment/decrement operator or an
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
560 ;; escaped character. Or one of the (illegal) characters @ or `. But NOT an
62641
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
561 ;; end of line (even if escaped).
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
562 (defconst c-awk-neutrals*-re
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
563 (concat "\\(" c-awk-neutral-re "\\)*"))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
564 ;; A (possibly empty) string of neutral characters (or character pairs).
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
565 (defconst c-awk-var-num-ket-re "[]\)0-9a-zA-Z_$.\x80-\xff]+")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
566 ;; Matches a char which is a constituent of a variable or number, or a ket
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
567 ;; (i.e. closing bracKET), round or square. Assume that all characters \x80 to
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
568 ;; \xff are "letters".
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
569 (defconst c-awk-div-sign-re
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
570 (concat c-awk-var-num-ket-re c-awk-neutrals*-re "/"))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
571 ;; Will match a piece of AWK buffer ending in / which is a division sign, in
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
572 ;; a context where an immediate / would be a regexp bracket. It follows a
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
573 ;; variable or number (with optional intervening "neutral" characters). This
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
574 ;; will only work when there won't be a preceding " or / before the sought /
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
575 ;; to foul things up.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
576 (defconst c-awk-non-arith-op-bra-re
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
577 "[[\(&=:!><,?;'~|]")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
578 ;; Matches an openeing BRAcket ,round or square, or any operator character
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
579 ;; apart from +,-,/,*,%. For the purpose at hand (detecting a / which is a
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
580 ;; regexp bracket) these arith ops are unnecessary and a pain, because of "++"
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
581 ;; and "--".
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
582 (defconst c-awk-regexp-sign-re
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
583 (concat c-awk-non-arith-op-bra-re c-awk-neutrals*-re "/"))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
584 ;; Will match a piece of AWK buffer ending in / which is an opening regexp
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
585 ;; bracket, in a context where an immediate / would be a division sign. This
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
586 ;; will only work when there won't be a preceding " or / before the sought /
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
587 ;; to foul things up.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
588
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
589 ;; ACM, 2002/02/15: The idea of the next function is to put the "Error font"
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
590 ;; on strings/regexps which are missing their closing delimiter.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
591 ;; 2002/4/28. The default syntax for / has been changed from "string" to
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
592 ;; "punctuation", to reduce hassle when this character appears within a string
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
593 ;; or comment.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
594
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
595 (defun c-awk-set-string-regexp-syntax-table-properties (beg end)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
596 ;; BEG and END bracket a (possibly unterminated) string or regexp. The
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
597 ;; opening delimiter is after BEG, and the closing delimiter, IF ANY, is AFTER
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
598 ;; END. Set the appropriate syntax-table properties on the delimiters and
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
599 ;; contents of this string/regex.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
600 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
601 ;; "String" here can also mean a gawk 3.1 "localizable" string which starts
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
602 ;; with _". In this case, we step over the _ and ignore it; It will get it's
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
603 ;; font from an entry in awk-font-lock-keywords.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
604 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
605 ;; If the closing delimiter is missing (i.e., there is an EOL there) set the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
606 ;; STRING-FENCE property on the opening " or / and closing EOL.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
607 (if (eq (char-after beg) ?_) (setq beg (1+ beg)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
608
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
609 ;; First put the properties on the delimiters.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
610 (cond ((eq end (point-max)) ; string/regexp terminated by EOB
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
611 (put-text-property beg (1+ beg) 'syntax-table '(15))) ; (15) = "string fence"
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
612 ((/= (char-after beg) (char-after end)) ; missing end delimiter
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
613 (put-text-property beg (1+ beg) 'syntax-table '(15))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
614 (put-text-property end (1+ end) 'syntax-table '(15)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
615 ((eq (char-after beg) ?/) ; Properly bracketed regexp
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
616 (put-text-property beg (1+ beg) 'syntax-table '(7)) ; (7) = "string"
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
617 (put-text-property end (1+ end) 'syntax-table '(7)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
618 (t)) ; Properly bracketed string: Nothing to do.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
619 ;; Now change the properties of any escaped "s in the string to punctuation.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
620 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
621 (goto-char (1+ beg))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
622 (or (eobp)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
623 (while (search-forward "\"" end t)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
624 (put-text-property (1- (point)) (point) 'syntax-table '(1))))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
625
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
626 (defun c-awk-syntax-tablify-string ()
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
627 ;; Point is at the opening " or _" of a string. Set the syntax-table
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
628 ;; properties on this string, leaving point just after the string.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
629 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
630 ;; The result is nil if a / immediately after the string would be a regexp
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
631 ;; opener, t if it would be a division sign.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
632 (search-forward-regexp c-awk-string-without-end-here-re nil t) ; a (possibly unterminated) string
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
633 (c-awk-set-string-regexp-syntax-table-properties
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
634 (match-beginning 0) (match-end 0))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
635 (cond ((looking-at "\"")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
636 (forward-char)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
637 t) ; In AWK, ("15" / 5) gives 3 ;-)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
638 ((looking-at "[\n\r]") ; Unterminated string with EOL.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
639 (forward-char)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
640 nil) ; / on next line would start a regexp
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
641 (t nil))) ; Unterminated string at EOB
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
642
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
643 (defun c-awk-syntax-tablify-/ (anchor anchor-state-/div)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
644 ;; Point is at a /. Determine whether this is a division sign or a regexp
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
645 ;; opener, and if the latter, apply syntax-table properties to the entire
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
646 ;; regexp. Point is left immediately after the division sign or regexp, as
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
647 ;; the case may be.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
648 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
649 ;; ANCHOR-STATE-/DIV identifies whether a / at ANCHOR would have been a
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
650 ;; division sign (value t) or a regexp opener (value nil). The idea is that
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
651 ;; we analyse the line from ANCHOR up till point to determine what the / at
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
652 ;; point is.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
653 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
654 ;; The result is what ANCHOR-STATE-/DIV (see above) is where point is left.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
655 (let ((/point (point)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
656 (goto-char anchor)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
657 ;; Analyse the line to find out what the / is.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
658 (if (if anchor-state-/div
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
659 (not (search-forward-regexp c-awk-regexp-sign-re (1+ /point) t))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
660 (search-forward-regexp c-awk-div-sign-re (1+ /point) t))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
661 ;; A division sign.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
662 (progn (goto-char (1+ /point)) nil)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
663 ;; A regexp opener
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
664 ;; Jump over the regexp innards, setting the match data.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
665 (goto-char /point)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
666 (search-forward-regexp c-awk-regexp-without-end-re)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
667 (c-awk-set-string-regexp-syntax-table-properties
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
668 (match-beginning 0) (match-end 0))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
669 (cond ((looking-at "/") ; Terminating /
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
670 (forward-char)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
671 t)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
672 ((looking-at "[\n\r]") ; Incomplete regexp terminated by EOL
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
673 (forward-char)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
674 nil) ; / on next line would start another regexp
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
675 (t nil))))) ; Unterminated regexp at EOB
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
676
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
677 (defun c-awk-set-syntax-table-properties (lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
678 ;; Scan the buffer text between point and LIM, setting (and clearing) the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
679 ;; syntax-table property where necessary.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
680 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
681 ;; This function is designed to be called as the FUNCTION in a MATCHER in
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
682 ;; font-lock-syntactic-keywords, and it always returns NIL (to inhibit
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
683 ;; repeated calls from font-lock: See elisp info page "Search-based
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
684 ;; Fontification"). It also gets called, with a bit of glue, from
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
685 ;; after-change-functions when font-lock isn't active. Point is left
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
686 ;; "undefined" after this function exits. THE BUFFER SHOULD HAVE BEEN
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
687 ;; WIDENED, AND ANY PRECIOUS MATCH-DATA SAVED BEFORE CALLING THIS ROUTINE.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
688 ;;
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
689 ;; We need to set/clear the syntax-table property on:
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
690 ;; (i) / - It is set to "string" on a / which is the opening or closing
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
691 ;; delimiter of the properly terminated regexp (and left unset on a
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
692 ;; division sign).
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
693 ;; (ii) the opener of an unterminated string/regexp, we set the property
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
694 ;; "generic string delimiter" on both the opening " or / and the end of the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
695 ;; line where the closing delimiter is missing.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
696 ;; (iii) "s inside strings/regexps (these will all be escaped "s). They are
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
697 ;; given the property "punctuation". This will later allow other routines
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
698 ;; to use the regexp "\\S\"*" to skip over the string innards.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
699 ;; (iv) Inside a comment, all syntax-table properties are cleared.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
700 (let (anchor
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
701 (anchor-state-/div nil)) ; t means a following / would be a div sign.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
702 (c-awk-beginning-of-logical-line) ; ACM 2002/7/21. This is probably redundant.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
703 (put-text-property (point) lim 'syntax-table nil)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
704 (search-forward-regexp c-awk-harmless-lines+-here-re nil t) ; skip harmless lines.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
705
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
706 ;; Once round the next loop for each string, regexp, or div sign
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
707 (while (< (point) lim)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
708 (setq anchor (point))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
709 (search-forward-regexp c-awk-harmless-string*-here-re nil t)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
710 ;; We are now looking at either a " or a /.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
711 ;; Do our thing on the string, regexp or divsion sign.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
712 (setq anchor-state-/div
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
713 (if (looking-at "_?\"")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
714 (c-awk-syntax-tablify-string)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
715 (c-awk-syntax-tablify-/ anchor anchor-state-/div)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
716
63517
7316ffa5763c (c-awk-beginning-of-defun): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62641
diff changeset
717 ;; Skip any further "harmless" lines before the next tricky one.
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
718 (if (search-forward-regexp c-awk-harmless-lines+-here-re nil t)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
719 (setq anchor-state-/div nil)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
720 nil))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
721
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
722
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
723 ;; ACM, 2002/07/21: Thoughts: We need an AWK Mode after-change function to set
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
724 ;; the syntax-table properties even when font-lock isn't enabled, for the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
725 ;; subsequent use of movement functions, etc. However, it seems that if font
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
726 ;; lock _is_ enabled, we can always leave it to do the job.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
727 (defvar c-awk-old-EOLL 0)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
728 (make-variable-buffer-local 'c-awk-old-EOLL)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
729 ;; End of logical line following the region which is about to be changed. Set
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
730 ;; in c-awk-before-change and used in c-awk-after-change.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
731
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
732 (defun c-awk-before-change (beg end)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
733 ;; This function is called exclusively from the before-change-functions hook.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
734 ;; It does two things: Finds the end of the (logical) line on which END lies,
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
735 ;; and clears c-awk-NL-prop text properties from this point onwards.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
736 (save-restriction
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
737 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
738 (setq c-awk-old-EOLL (c-awk-end-of-logical-line end))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
739 (c-save-buffer-state nil
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
740 (c-awk-clear-NL-props end (point-max))))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
741
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
742 (defun c-awk-end-of-change-region (beg end old-len)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
743 ;; Find the end of the region which needs to be font-locked after a change.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
744 ;; This is the end of the logical line on which the change happened, either
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
745 ;; as it was before the change, or as it is now, which ever is later.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
746 ;; N.B. point is left undefined.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
747 (max (+ (- c-awk-old-EOLL old-len) (- end beg))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
748 (c-awk-end-of-logical-line end)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
749
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
750 (defun c-awk-after-change (beg end old-len)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
751 ;; This function is called exclusively as an after-change function in
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
752 ;; AWK Mode. It ensures that the syntax-table properties get set in the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
753 ;; changed region. However, if font-lock is enabled, this function does
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
754 ;; nothing, since an enabled font-lock after-change function will always do
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
755 ;; this.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
756 (unless (and (boundp 'font-lock-mode) font-lock-mode)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
757 (save-restriction
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
758 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
759 (setq end (c-awk-end-of-change-region beg end old-len))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
760 (c-awk-beginning-of-logical-line beg)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
761 (c-save-buffer-state nil ; So that read-only status isn't affected.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
762 ; (e.g. when first loading the buffer)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
763 (c-awk-set-syntax-table-properties end))))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
764
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
765 ;; ACM 2002/5/25. When font-locking is invoked by a buffer change, the region
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
766 ;; specified by the font-lock after-change function must be expanded to
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
767 ;; include ALL of any string or regexp within the region. The simplest way to
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
768 ;; do this in practice is to use the beginning/end-of-logical-line functions.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
769 ;; Don't overlook the possibility of the buffer change being the "recapturing"
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
770 ;; of a previously escaped newline.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
771 (defmacro c-awk-advise-fl-for-awk-region (function)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
772 `(defadvice ,function (before get-awk-region activate)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
773 ;; When font-locking an AWK Mode buffer, make sure that any string/regexp is
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
774 ;; completely font-locked.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
775 (when (eq major-mode 'awk-mode)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
776 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
777 (ad-set-arg 1 (c-awk-end-of-change-region
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
778 (ad-get-arg 0) ; beg
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
779 (ad-get-arg 1) ; end
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
780 (ad-get-arg 2))) ; old-len
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
781 (ad-set-arg 0 (c-awk-beginning-of-logical-line (ad-get-arg 0)))))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
782
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
783 (c-awk-advise-fl-for-awk-region font-lock-after-change-function)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
784 (c-awk-advise-fl-for-awk-region jit-lock-after-change)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
785 (c-awk-advise-fl-for-awk-region lazy-lock-defer-rest-after-change)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
786 (c-awk-advise-fl-for-awk-region lazy-lock-defer-line-after-change)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
787
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
788 ;; ACM 2002/9/29. Functions for C-M-a and C-M-e
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
789
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
790 (defconst c-awk-terminated-regexp-or-string-here-re "\\=\\s\"\\S\"*\\s\"")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
791 ;; Matches a terminated string/regexp (utilising syntax-table properties).
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
792
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
793 (defconst c-awk-unterminated-regexp-or-string-here-re "\\=\\s|\\S|*$")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
794 ;; Matches an unterminated string/regexp, NOT including the eol at the end.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
795
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
796 (defconst c-awk-harmless-pattern-characters*
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
797 (concat "\\([^{;#/\"\\\\\n\r]\\|" c-awk-esc-pair-re "\\)*"))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
798 ;; Matches any "harmless" character in a pattern or an escaped character pair.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
799
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
800 (defun c-awk-beginning-of-defun (&optional arg)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
801 "Move backward to the beginning of an AWK \"defun\". With ARG, do it that
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
802 many times. Negative arg -N means move forward to Nth following beginning of
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
803 defun. Returns t unless search stops due to beginning or end of buffer.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
804
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
805 By a \"defun\" is meant either a pattern-action pair or a function. The start
63517
7316ffa5763c (c-awk-beginning-of-defun): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62641
diff changeset
806 of a defun is recognized as code starting at column zero which is neither a
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
807 closing brace nor a comment nor a continuation of the previous line. Unlike
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
808 in some other modes, having an opening brace at column 0 is neither necessary
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
809 nor helpful."
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
810 (interactive "p")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
811 (save-match-data
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
812 (c-save-buffer-state ; ensures the buffer is writable.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
813 nil
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
814 (let ((found t)) ; Has the most recent regexp search found b-of-defun?
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
815 (if (>= arg 0)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
816 ;; Go back one defun each time round the following loop. (For +ve arg)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
817 (while (and found (> arg 0) (not (eq (point) (point-min))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
818 ;; Go back one "candidate" each time round the next loop until one
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
819 ;; is genuinely a beginning-of-defun.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
820 (while (and (setq found (search-backward-regexp
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
821 "^[^#} \t\n\r]" (point-min) 'stop-at-limit))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
822 (not (memq (c-awk-get-NL-prop-prev-line) '(?\; ?\#)))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
823 (setq arg (1- arg)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
824 ;; The same for a -ve arg.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
825 (if (not (eq (point) (point-max))) (forward-char 1))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
826 (while (and found (< arg 0) (not (eq (point) (point-max)))) ; The same for -ve arg.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
827 (while (and (setq found (search-forward-regexp
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
828 "^[^#} \t\n\r]" (point-max) 'stop-at-limit))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
829 (not (memq (c-awk-get-NL-prop-prev-line) '(?\; ?\#)))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
830 (setq arg (1+ arg)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
831 (if found (goto-char (match-beginning 0))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
832 (eq arg 0)))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
833
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
834 (defun c-awk-forward-awk-pattern ()
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
835 ;; Point is at the start of an AWK pattern (which may be null) or function
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
836 ;; declaration. Move to the pattern's end, and past any trailing space or
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
837 ;; comment. Typically, we stop at the { which denotes the corresponding AWK
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
838 ;; action/function body. Otherwise we stop at the EOL (or ;) marking the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
839 ;; absence of an explicit action.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
840 (while
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
841 (progn
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
842 (search-forward-regexp c-awk-harmless-pattern-characters*)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
843 (if (looking-at "#") (end-of-line))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
844 (cond
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
845 ((eobp) nil)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
846 ((looking-at "[{;]") nil) ; We've finished!
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
847 ((eolp)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
848 (if (c-awk-cur-line-incomplete-p)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
849 (forward-line) ; returns non-nil
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
850 nil))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
851 ((search-forward-regexp c-awk-terminated-regexp-or-string-here-re nil t))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
852 ((search-forward-regexp c-awk-unterminated-regexp-or-string-here-re nil t))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
853 ((looking-at "/") (forward-char) t))))) ; division sign.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
854
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
855 (defun c-awk-end-of-defun1 ()
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
856 ;; point is at the start of a "defun". Move to its end. Return end position.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
857 (c-awk-forward-awk-pattern)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
858 (cond
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
859 ((looking-at "{") (goto-char (scan-sexps (point) 1)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
860 ((looking-at ";") (forward-char))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
861 ((eolp))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
862 (t (error "c-awk-end-of-defun1: Failure of c-awk-forward-awk-pattern")))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
863 (point))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
864
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
865 (defun c-awk-beginning-of-defun-p ()
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
866 ;; Are we already at the beginning of a defun? (i.e. at code in column 0
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
867 ;; which isn't a }, and isn't a continuation line of any sort.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
868 (and (looking-at "^[^#} \t\n\r]")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
869 (not (c-awk-prev-line-incomplete-p))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
870
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
871 (defun c-awk-end-of-defun (&optional arg)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
872 "Move forward to next end of defun. With argument, do it that many times.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
873 Negative argument -N means move back to Nth preceding end of defun.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
874
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
875 An end of a defun occurs right after the closing brace that matches the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
876 opening brace at its start, or immediately after the AWK pattern when there is
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
877 no explicit action; see function `c-awk-beginning-of-defun'."
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
878 (interactive "p")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
879 (or arg (setq arg 1))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
880 (save-match-data
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
881 (c-save-buffer-state
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
882 nil
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
883 (let ((start-point (point)) end-point)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
884 ;; Strategy: (For +ve ARG): If we're not already at a beginning-of-defun,
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
885 ;; move backwards to one.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
886 ;; Repeat [(i) move forward to end-of-current-defun (see below);
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
887 ;; (ii) If this isn't it, move forward to beginning-of-defun].
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
888 ;; We start counting ARG only when step (i) has passed the original point.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
889 (when (> arg 0)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
890 ;; Try to move back to a beginning-of-defun, if not already at one.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
891 (if (not (c-awk-beginning-of-defun-p))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
892 (when (not (c-awk-beginning-of-defun 1)) ; No bo-defun before point.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
893 (goto-char start-point)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
894 (c-awk-beginning-of-defun -1))) ; if this fails, we're at EOB, tough!
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
895 ;; Now count forward, one defun at a time
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
896 (while (and (not (eobp))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
897 (c-awk-end-of-defun1)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
898 (if (> (point) start-point) (setq arg (1- arg)) t)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
899 (> arg 0)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
900 (c-awk-beginning-of-defun -1))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
901
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
902 (when (< arg 0)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
903 (setq end-point start-point)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
904 (while (and (not (bobp))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
905 (c-awk-beginning-of-defun 1)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
906 (if (< (setq end-point (if (bobp) (point)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
907 (save-excursion (c-awk-end-of-defun1))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
908 start-point)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
909 (setq arg (1+ arg)) t)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
910 (< arg 0)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
911 (goto-char (min start-point end-point)))))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
912
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
913 (cc-provide 'cc-awk) ; Changed from 'awk-mode, ACM 2002/5/21
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51714
diff changeset
914
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51714
diff changeset
915 ;;; arch-tag: c4836289-3aa4-4a59-9934-9ccc2bacccf3
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
diff changeset
916 ;;; awk-mode.el ends here