Mercurial > emacs
annotate lisp/progmodes/delphi.el @ 102233:5d5d7ede9176
(flyspell-use-meta-tab): Add a custom :set function. (Bug#2429)
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Tue, 24 Feb 2009 04:44:19 +0000 |
parents | a9dc0e7c3f2b |
children | 71f778b32ef5 |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
35624
diff
changeset
|
1 ;;; delphi.el --- major mode for editing Delphi source (Object Pascal) in Emacs |
25072 | 2 |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
3 ;; Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
100908 | 4 ;; 2008, 2009 Free Software Foundation, Inc. |
25072 | 5 |
97926 | 6 ;; Authors: Ray Blaak <blaak@infomatch.com>, |
7 ;; Simon South <ssouth@member.fsf.org> | |
8 ;; Maintainer: Simon South <ssouth@member.fsf.org> | |
25072 | 9 ;; Keywords: languages |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; it under the terms of the GNU General Public License as published by |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
16 ;; (at your option) any later version. |
25072 | 17 |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
18 ;; GNU Emacs is distributed in the hope that it will be useful, |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
21 ;; GNU General Public License for more details. |
25072 | 22 |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
23 ;; You should have received a copy of the GNU General Public License |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
25072 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; To enter Delphi mode when you find a Delphi source file, one must override | |
29 ;; the auto-mode-alist to associate Delphi with .pas (and .dpr and .dpk) | |
30 ;; files. Emacs, by default, will otherwise enter Pascal mode. E.g. | |
31 ;; | |
32 ;; (autoload 'delphi-mode "delphi") | |
33 ;; (setq auto-mode-alist | |
34 ;; (cons '("\\.\\(pas\\|dpr\\|dpk\\)$" . delphi-mode) auto-mode-alist)) | |
35 | |
25161
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
36 ;; To get keyword, comment, and string literal coloring, be sure that font-lock |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
37 ;; is running. One can manually do M-x font-lock-mode in a Delphi buffer, or |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
38 ;; one can put in .emacs: |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
39 ;; |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
40 ;; (add-hook 'delphi-mode-hook 'turn-on-font-lock) |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
41 |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
42 ;; If font-lock is not loaded by default, you might have to do: |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
43 ;; |
25161
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
44 ;; (autoload 'font-lock-mode "font-lock") |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
45 ;; (autoload 'turn-on-font-lock "font-lock") |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
46 ;; (setq font-lock-support-mode 'lazy-lock-mode) |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
47 ;; |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
48 ;; Lazy lock is very necessary for faster screen updates. |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
49 |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
50 ;; For good performance, be sure to byte-compile delphi.el, e.g. |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
51 ;; |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
52 ;; M-x byte-compile-file <give the path to delphi.el when prompted> |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
53 |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
54 ;; This will generate delphi.elc, which will be loaded instead of delphi.el |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
55 ;; when delphi-mode is autoloaded. |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
56 |
25072 | 57 ;; When you have entered Delphi mode, you may get more info by pressing |
58 ;; C-h m. | |
59 | |
25161
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
60 ;; This delphi mode implementation is fairly tolerant of syntax errors, relying |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
61 ;; as much as possible on the indentation of the previous statement. This also |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
62 ;; makes it faster and simpler, since there is less searching for properly |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
63 ;; constructed beginnings. |
25072 | 64 |
65 ;;; Code: | |
66 | |
67 (provide 'delphi) | |
68 | |
69 (defgroup delphi nil | |
64041
e28ab96f1223
(delphi): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63276
diff
changeset
|
70 "Major mode for editing Delphi source in Emacs." |
27551
2dd8115a9f72
(delphi): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents:
25317
diff
changeset
|
71 :version "21.1" |
25072 | 72 :group 'languages) |
73 | |
74 (defconst delphi-debug nil | |
75 "True if in debug mode.") | |
76 | |
77 (defcustom delphi-search-path "." | |
78 "*Directories to search when finding external units. It is a list of | |
79 directory strings. If only a single directory, it can be a single | |
80 string instead of a list. If a directory ends in \"...\" then that | |
81 directory is recursively searched." | |
82 :type 'string | |
83 :group 'delphi) | |
84 | |
85 (defcustom delphi-indent-level 3 | |
86 "*Indentation of Delphi statements with respect to containing block. E.g. | |
87 | |
88 begin | |
89 // This is an indent of 3. | |
90 end;" | |
91 :type 'integer | |
92 :group 'delphi) | |
93 | |
94 (defcustom delphi-compound-block-indent 0 | |
95 "*Extra indentation for blocks in compound statements. E.g. | |
96 | |
97 // block indent = 0 vs // block indent = 2 | |
98 if b then if b then | |
99 begin begin | |
100 end else begin end | |
101 end; else | |
102 begin | |
103 end;" | |
104 :type 'integer | |
105 :group 'delphi) | |
106 | |
107 (defcustom delphi-case-label-indent delphi-indent-level | |
108 "*Extra indentation for case statement labels. E.g. | |
109 | |
110 // case indent = 0 vs // case indent = 3 | |
111 case value of case value of | |
112 v1: process_v1; v1: process_v1; | |
113 v2: process_v2; v2: process_v2; | |
114 else else | |
115 process_else; process_else; | |
116 end; end;" | |
117 :type 'integer | |
118 :group 'delphi) | |
119 | |
120 (defcustom delphi-verbose t ; nil | |
121 "*If true then delphi token processing progress is reported to the user." | |
122 :type 'boolean | |
123 :group 'delphi) | |
124 | |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
125 (defcustom delphi-tab-always-indents t |
25072 | 126 "*Non-nil means TAB in Delphi mode should always reindent the current line, |
127 regardless of where in the line point is when the TAB command is used." | |
128 :type 'boolean | |
129 :group 'delphi) | |
130 | |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
131 (defcustom delphi-newline-always-indents t |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
132 "*Non-nil means NEWLINE in Delphi mode should always reindent the current |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
133 line, insert a blank line and move to the default indent column of the blank |
63276
bb8a71ee1f10
(delphi-newline-always-indents): Fix spellings in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
62772
diff
changeset
|
134 line. If nil, then no indentation occurs, and NEWLINE does the usual |
bb8a71ee1f10
(delphi-newline-always-indents): Fix spellings in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
62772
diff
changeset
|
135 behavior. This is useful when one needs to do customized indentation that |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
136 differs from the default." |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
137 :type 'boolean |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
138 :group 'delphi) |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
139 |
25072 | 140 (defcustom delphi-comment-face 'font-lock-comment-face |
141 "*Face used to color delphi comments." | |
35624
6878c61d1877
(delphi-comment-face, delphi-string-face)
Dave Love <fx@gnu.org>
parents:
27647
diff
changeset
|
142 :type 'face |
25072 | 143 :group 'delphi) |
144 | |
145 (defcustom delphi-string-face 'font-lock-string-face | |
146 "*Face used to color delphi strings." | |
35624
6878c61d1877
(delphi-comment-face, delphi-string-face)
Dave Love <fx@gnu.org>
parents:
27647
diff
changeset
|
147 :type 'face |
25072 | 148 :group 'delphi) |
149 | |
150 (defcustom delphi-keyword-face 'font-lock-keyword-face | |
151 "*Face used to color delphi keywords." | |
35624
6878c61d1877
(delphi-comment-face, delphi-string-face)
Dave Love <fx@gnu.org>
parents:
27647
diff
changeset
|
152 :type 'face |
25072 | 153 :group 'delphi) |
154 | |
155 (defcustom delphi-other-face nil | |
156 "*Face used to color everything else." | |
67911
6b887a742b11
(delphi-other-face): Add tag "None" to const nil.
Juri Linkov <juri@jurta.org>
parents:
67806
diff
changeset
|
157 :type '(choice (const :tag "None" nil) face) |
25072 | 158 :group 'delphi) |
159 | |
160 (defconst delphi-directives | |
161 '(absolute abstract assembler automated cdecl default dispid dynamic | |
162 export external far forward index inline message name near nodefault | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
163 overload override pascal private protected public published read readonly |
25072 | 164 register reintroduce resident resourcestring safecall stdcall stored |
165 virtual write writeonly) | |
166 "Delphi4 directives.") | |
167 | |
168 (defconst delphi-keywords | |
169 (append | |
170 '(;; Keywords. | |
171 and array as asm at begin case class const constructor contains | |
172 destructor dispinterface div do downto else end except exports | |
173 file finalization finally for function goto if implementation implements | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
174 in inherited initialization interface is label library mod nil not |
25072 | 175 of object on or out package packed procedure program property |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
176 raise record repeat requires result self set shl shr then threadvar |
25072 | 177 to try type unit uses until var while with xor |
178 | |
179 ;; These routines should be keywords, if Borland had the balls. | |
180 break exit) | |
181 | |
182 ;; We want directives to look like keywords. | |
183 delphi-directives) | |
184 "Delphi4 keywords.") | |
185 | |
186 (defconst delphi-previous-terminators `(semicolon comma) | |
187 "Expression/statement terminators that denote a previous expression.") | |
188 | |
189 (defconst delphi-comments | |
190 '(comment-single-line comment-multi-line-1 comment-multi-line-2) | |
191 "Tokens that represent comments.") | |
192 | |
193 (defconst delphi-strings | |
194 '(string double-quoted-string) | |
195 "Tokens that represent string literals.") | |
196 | |
197 (defconst delphi-whitespace `(space newline ,@delphi-comments) | |
198 "Tokens that are considered whitespace.") | |
199 | |
200 (defconst delphi-routine-statements | |
201 '(procedure function constructor destructor property) | |
202 "Marks the start of a routine, or routine-ish looking expression.") | |
203 | |
204 (defconst delphi-body-expr-statements '(if while for on) | |
205 "Statements that have either a single statement or a block as a body and also | |
206 are followed by an expression.") | |
207 | |
208 (defconst delphi-expr-statements `(case ,@delphi-body-expr-statements) | |
209 "Expression statements contain expressions after their keyword.") | |
210 | |
211 (defconst delphi-body-statements `(else ,@delphi-body-expr-statements) | |
212 "Statements that have either a single statement or a block as a body.") | |
213 | |
214 (defconst delphi-expr-delimiters '(then do of) | |
215 "Expression delimiter tokens.") | |
216 | |
217 (defconst delphi-binary-ops | |
218 '(plus minus equals not-equals times divides div mod and or xor) | |
219 "Delphi binary operations.") | |
220 | |
221 (defconst delphi-visibilities '(public private protected published automated) | |
222 "Class visibilities.") | |
223 | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
224 (defconst delphi-block-statements |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
225 '(begin try case repeat initialization finalization asm) |
25072 | 226 "Statements that contain multiple substatements.") |
227 | |
228 (defconst delphi-mid-block-statements | |
229 `(except finally ,@delphi-visibilities) | |
230 "Statements that mark mid sections of the enclosing block.") | |
231 | |
232 (defconst delphi-end-block-statements `(end until) | |
233 "Statements that end block sections.") | |
234 | |
235 (defconst delphi-match-block-statements | |
236 `(,@delphi-end-block-statements ,@delphi-mid-block-statements) | |
237 "Statements that match the indentation of the parent block.") | |
238 | |
27647
c8d739c1aaf0
Make resourcestring a declaration region, like const and var.
Ray Blaak <blaak@infomatch.com>
parents:
27551
diff
changeset
|
239 (defconst delphi-decl-sections '(type const var label resourcestring) |
25072 | 240 "Denotes the start of a declaration section.") |
241 | |
97926 | 242 (defconst delphi-interface-types '(dispinterface interface) |
243 "Interface types.") | |
244 | |
25072 | 245 (defconst delphi-class-types '(class object) |
246 "Class types.") | |
247 | |
97926 | 248 (defconst delphi-composite-types |
249 `(,@delphi-class-types ,@delphi-interface-types record) | |
25072 | 250 "Types that contain declarations within them.") |
251 | |
252 (defconst delphi-unit-sections | |
253 '(interface implementation program library package) | |
254 "Unit sections within which the indent is 0.") | |
255 | |
256 (defconst delphi-use-clauses `(uses requires exports contains) | |
257 "Statements that refer to foreign symbols.") | |
258 | |
259 (defconst delphi-unit-statements | |
260 `(,@delphi-use-clauses ,@delphi-unit-sections initialization finalization) | |
261 "Statements indented at level 0.") | |
262 | |
263 (defconst delphi-decl-delimiters | |
264 `(,@delphi-decl-sections ,@delphi-unit-statements | |
265 ,@delphi-routine-statements) | |
266 "Statements that a declaration statement should align with.") | |
267 | |
268 (defconst delphi-decl-matchers | |
269 `(begin ,@delphi-decl-sections) | |
270 "Statements that should match to declaration statement indentation.") | |
271 | |
272 (defconst delphi-enclosing-statements | |
273 `(,@delphi-block-statements ,@delphi-mid-block-statements | |
274 ,@delphi-decl-sections ,@delphi-use-clauses ,@delphi-routine-statements) | |
275 "Delimits an enclosing statement.") | |
276 | |
277 (defconst delphi-previous-statements | |
278 `(,@delphi-unit-statements ,@delphi-routine-statements) | |
279 "Delimits a previous statement.") | |
280 | |
281 (defconst delphi-previous-enclosing-statements | |
282 `(,@delphi-block-statements ,@delphi-mid-block-statements | |
283 ,@delphi-decl-sections) | |
284 "Delimits a previous enclosing statement.") | |
285 | |
286 (defconst delphi-begin-enclosing-tokens | |
287 `(,@delphi-block-statements ,@delphi-mid-block-statements) | |
288 "Tokens that a begin token indents from.") | |
289 | |
290 (defconst delphi-begin-previous-tokens | |
291 `(,@delphi-decl-sections ,@delphi-routine-statements) | |
292 "Tokens that a begin token aligns with, but only if not part of a nested | |
293 routine.") | |
294 | |
295 (defconst delphi-space-chars "\000-\011\013- ") ; all except \n | |
296 (defconst delphi-non-space-chars (concat "^" delphi-space-chars)) | |
297 (defconst delphi-spaces-re (concat "[" delphi-space-chars "]*")) | |
298 (defconst delphi-leading-spaces-re (concat "^" delphi-spaces-re)) | |
299 (defconst delphi-word-chars "a-zA-Z0-9_") | |
300 | |
301 (defmacro delphi-save-match-data (&rest forms) | |
302 ;; Executes the forms such that the current match data is preserved, so as | |
303 ;; not to disturb any existing search results. | |
304 `(let ((data (match-data))) | |
305 (unwind-protect | |
306 (progn ,@forms) | |
307 (set-match-data data)))) | |
308 | |
309 (defmacro delphi-save-excursion (&rest forms) | |
310 ;; Executes the forms such that any movements have no effect, including | |
311 ;; searches. | |
312 `(save-excursion | |
313 (delphi-save-match-data | |
314 (let ((inhibit-point-motion-hooks t) | |
315 (deactivate-mark nil)) | |
316 (progn ,@forms))))) | |
317 | |
318 (defmacro delphi-save-state (&rest forms) | |
319 ;; Executes the forms such that any buffer modifications do not have any side | |
320 ;; effects beyond the buffer's actual content changes. | |
321 `(let ((delphi-ignore-changes t) | |
322 (old-supersession-threat | |
323 (symbol-function 'ask-user-about-supersession-threat)) | |
324 (buffer-read-only nil) | |
325 (inhibit-read-only t) | |
326 (buffer-undo-list t) | |
327 (before-change-functions nil) | |
328 (after-change-functions nil) | |
329 (modified (buffer-modified-p))) | |
330 ;; Disable any queries about editing obsolete files. | |
331 (fset 'ask-user-about-supersession-threat (lambda (fn))) | |
332 (unwind-protect | |
333 (progn ,@forms) | |
334 (set-buffer-modified-p modified) | |
335 (fset 'ask-user-about-supersession-threat old-supersession-threat)))) | |
336 | |
337 (defsubst delphi-is (element in-set) | |
338 ;; If the element is in the set, the element cdr is returned, otherwise nil. | |
339 (memq element in-set)) | |
340 | |
341 (defun delphi-string-of (start end) | |
342 ;; Returns the buffer string from start to end. | |
343 (buffer-substring-no-properties start end)) | |
344 | |
345 (defun delphi-looking-at-string (p s) | |
346 ;; True if point p marks the start of string s. s is not a regular | |
347 ;; expression. | |
348 (let ((limit (+ p (length s)))) | |
349 (and (<= limit (point-max)) | |
350 (string= s (delphi-string-of p limit))))) | |
351 | |
352 (defun delphi-token-of (kind start end) | |
353 ;; Constructs a token from a kind symbol and its start/end points. | |
354 `[,kind ,start ,end]) | |
355 | |
356 (defsubst delphi-token-kind (token) | |
357 ;; Returns the kind symbol of the token. | |
358 (if token (aref token 0) nil)) | |
359 | |
360 (defun delphi-set-token-kind (token to-kind) | |
361 ;; Sets the kind symbol of the token. | |
362 (if token (aset token 0 to-kind))) | |
363 | |
364 (defsubst delphi-token-start (token) | |
365 ;; Returns the start point of the token. | |
366 (if token (aref token 1) (point-min))) | |
367 | |
368 (defsubst delphi-token-end (token) | |
369 ;; Returns the end point of the token. | |
370 (if token (aref token 2) (point-min))) | |
371 | |
372 (defun delphi-set-token-start (token start) | |
373 ;; Sets the start point of the token. | |
374 (if token (aset token 1 start))) | |
375 | |
376 (defun delphi-set-token-end (token end) | |
377 ;; Sets the end point of the token. | |
378 (if token (aset token 2 end))) | |
379 | |
380 (defun delphi-token-string (token) | |
381 ;; Returns the string image of the token. | |
382 (if token | |
383 (delphi-string-of (delphi-token-start token) (delphi-token-end token)) | |
384 "")) | |
385 | |
386 (defun delphi-in-token (p token) | |
387 ;; Returns true if the point p is within the token's start/end points. | |
388 (and (<= (delphi-token-start token) p) (< p (delphi-token-end token)))) | |
389 | |
390 (defun delphi-column-of (p) | |
391 ;; Returns the column of the point p. | |
392 (save-excursion (goto-char p) (current-column))) | |
393 | |
394 (defun delphi-face-of (token-kind) | |
395 ;; Returns the face property appropriate for the token kind. | |
396 (cond ((delphi-is token-kind delphi-comments) delphi-comment-face) | |
397 ((delphi-is token-kind delphi-strings) delphi-string-face) | |
398 ((delphi-is token-kind delphi-keywords) delphi-keyword-face) | |
399 (delphi-other-face))) | |
400 | |
401 (defvar delphi-progress-last-reported-point nil | |
402 "The last point at which progress was reported.") | |
403 | |
404 (defconst delphi-parsing-progress-step 16384 | |
405 "Number of chars to process before the next parsing progress report.") | |
406 (defconst delphi-scanning-progress-step 2048 | |
407 "Number of chars to process before the next scanning progress report.") | |
408 (defconst delphi-fontifying-progress-step delphi-scanning-progress-step | |
409 "Number of chars to process before the next fontification progress report.") | |
410 | |
411 (defun delphi-progress-start () | |
412 ;; Initializes progress reporting. | |
413 (setq delphi-progress-last-reported-point nil)) | |
414 | |
415 (defun delphi-progress-done (&rest msgs) | |
416 ;; Finalizes progress reporting. | |
417 (setq delphi-progress-last-reported-point nil) | |
418 (when delphi-verbose | |
419 (if (null msgs) | |
420 (message "") | |
421 (apply #'message msgs)))) | |
422 | |
423 (defun delphi-step-progress (p desc step-size) | |
424 ;; If enough distance has elapsed since the last reported point, then report | |
425 ;; the current progress to the user. | |
426 (cond ((null delphi-progress-last-reported-point) | |
427 ;; This is the first progress step. | |
428 (setq delphi-progress-last-reported-point p)) | |
429 | |
430 ((and delphi-verbose | |
431 (>= (abs (- p delphi-progress-last-reported-point)) step-size)) | |
432 ;; Report the percentage complete. | |
433 (setq delphi-progress-last-reported-point p) | |
434 (message "%s %s ... %d%%" | |
435 desc (buffer-name) (/ (* 100 p) (point-max)))))) | |
436 | |
437 (defun delphi-next-line-start (&optional from-point) | |
438 ;; Returns the first point of the next line. | |
439 (let ((curr-point (point)) | |
440 (next nil)) | |
441 (if from-point (goto-char from-point)) | |
442 (end-of-line) | |
443 (setq next (min (1+ (point)) (point-max))) | |
444 (goto-char curr-point) | |
445 next)) | |
446 | |
447 (defun delphi-set-text-properties (from to properties) | |
448 ;; Like `set-text-properties', except we do not consider this to be a buffer | |
449 ;; modification. | |
450 (delphi-save-state | |
451 (set-text-properties from to properties))) | |
452 | |
453 (defun delphi-literal-kind (p) | |
454 ;; Returns the literal kind the point p is in (or nil if not in a literal). | |
455 (if (and (<= (point-min) p) (<= p (point-max))) | |
456 (get-text-property p 'token))) | |
457 | |
458 (defun delphi-literal-start-pattern (literal-kind) | |
459 ;; Returns the start pattern of the literal kind. | |
460 (cdr (assoc literal-kind | |
461 '((comment-single-line . "//") | |
462 (comment-multi-line-1 . "{") | |
463 (comment-multi-line-2 . "(*") | |
464 (string . "'") | |
465 (double-quoted-string . "\""))))) | |
466 | |
467 (defun delphi-literal-end-pattern (literal-kind) | |
468 ;; Returns the end pattern of the literal kind. | |
469 (cdr (assoc literal-kind | |
470 '((comment-single-line . "\n") | |
471 (comment-multi-line-1 . "}") | |
472 (comment-multi-line-2 . "*)") | |
473 (string . "'") | |
474 (double-quoted-string . "\""))))) | |
475 | |
476 (defun delphi-literal-stop-pattern (literal-kind) | |
477 ;; Returns the pattern that delimits end of the search for the literal kind. | |
478 ;; These are regular expressions. | |
479 (cdr (assoc literal-kind | |
480 '((comment-single-line . "\n") | |
481 (comment-multi-line-1 . "}") | |
482 (comment-multi-line-2 . "\\*)") | |
483 ;; Strings cannot span lines. | |
484 (string . "['\n]") | |
485 (double-quoted-string . "[\"\n]"))))) | |
486 | |
487 (defun delphi-is-literal-start (p) | |
25161
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
488 ;; True if the point p is at the start point of a (completed) literal. |
25072 | 489 (let* ((kind (delphi-literal-kind p)) |
490 (pattern (delphi-literal-start-pattern kind))) | |
491 (or (null kind) ; Non-literals are considered as start points. | |
492 (delphi-looking-at-string p pattern)))) | |
493 | |
494 (defun delphi-is-literal-end (p) | |
495 ;; True if the point p is at the end point of a (completed) literal. | |
496 (let* ((kind (delphi-literal-kind (1- p))) | |
497 (pattern (delphi-literal-end-pattern kind))) | |
498 (or (null kind) ; Non-literals are considered as end points. | |
499 | |
500 (and (delphi-looking-at-string (- p (length pattern)) pattern) | |
501 (or (not (delphi-is kind delphi-strings)) | |
502 ;; Special case: string delimiters are start/end ambiguous. | |
503 ;; We have an end only if there is some string content (at | |
504 ;; least a starting delimiter). | |
505 (not (delphi-is-literal-end (1- p))))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
506 |
25072 | 507 ;; Special case: strings cannot span lines. |
508 (and (delphi-is kind delphi-strings) (eq ?\n (char-after (1- p))))))) | |
509 | |
510 (defun delphi-is-stable-literal (p) | |
511 ;; True if the point p marks a stable point. That is, a point outside of a | |
512 ;; literal region, inside of a literal region, or adjacent to completed | |
513 ;; literal regions. | |
514 (let ((at-start (delphi-is-literal-start p)) | |
515 (at-end (delphi-is-literal-end p))) | |
516 (or (>= p (point-max)) | |
517 (and at-start at-end) | |
518 (and (not at-start) (not at-end) | |
519 (eq (delphi-literal-kind (1- p)) (delphi-literal-kind p)))))) | |
520 | |
521 (defun delphi-complete-literal (literal-kind limit) | |
522 ;; Continues the search for a literal's true end point and returns the | |
523 ;; point past the end pattern (if found) or the limit (if not found). | |
524 (let ((pattern (delphi-literal-stop-pattern literal-kind))) | |
525 (if (not (stringp pattern)) | |
526 (error "Invalid literal kind %S" literal-kind) | |
527 ;; Search up to the limit. | |
528 (re-search-forward pattern limit 'goto-limit-on-fail) | |
529 (point)))) | |
530 | |
531 (defun delphi-literal-text-properties (kind) | |
532 ;; Creates a list of text properties for the literal kind. | |
533 (if (and (boundp 'font-lock-mode) | |
534 font-lock-mode) | |
535 (list 'token kind 'face (delphi-face-of kind) 'lazy-lock t) | |
536 (list 'token kind))) | |
537 | |
538 (defun delphi-parse-next-literal (limit) | |
539 ;; Searches for the next literal region (i.e. comment or string) and sets the | |
540 ;; the point to its end (or the limit, if not found). The literal region is | |
541 ;; marked as such with a text property, to speed up tokenizing during face | |
542 ;; coloring and indentation scanning. | |
543 (let ((search-start (point))) | |
544 (cond ((not (delphi-is-literal-end search-start)) | |
545 ;; We are completing an incomplete literal. | |
546 (let ((kind (delphi-literal-kind (1- search-start)))) | |
547 (delphi-complete-literal kind limit) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
548 (delphi-set-text-properties |
25072 | 549 search-start (point) (delphi-literal-text-properties kind)))) |
550 | |
551 ((re-search-forward | |
552 "\\(//\\)\\|\\({\\)\\|\\((\\*\\)\\|\\('\\)\\|\\(\"\\)" | |
553 limit 'goto-limit-on-fail) | |
554 ;; We found the start of a new literal. Find its end and mark it. | |
555 (let ((kind (cond ((match-beginning 1) 'comment-single-line) | |
556 ((match-beginning 2) 'comment-multi-line-1) | |
557 ((match-beginning 3) 'comment-multi-line-2) | |
558 ((match-beginning 4) 'string) | |
559 ((match-beginning 5) 'double-quoted-string))) | |
560 (start (match-beginning 0))) | |
561 (delphi-set-text-properties search-start start nil) | |
562 (delphi-complete-literal kind limit) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
563 (delphi-set-text-properties |
25072 | 564 start (point) (delphi-literal-text-properties kind)))) |
565 | |
566 ;; Nothing found. Mark it as a non-literal. | |
567 ((delphi-set-text-properties search-start limit nil))) | |
568 (delphi-step-progress (point) "Parsing" delphi-parsing-progress-step))) | |
569 | |
570 (defun delphi-literal-token-at (p) | |
571 ;; Returns the literal token surrounding the point p, or nil if none. | |
572 (let ((kind (delphi-literal-kind p))) | |
573 (when kind | |
574 (let ((start (previous-single-property-change (1+ p) 'token)) | |
575 (end (next-single-property-change p 'token))) | |
576 (delphi-token-of kind (or start (point-min)) (or end (point-max))))))) | |
577 | |
578 (defun delphi-point-token-at (p kind) | |
579 ;; Returns the single character token at the point p. | |
580 (delphi-token-of kind p (1+ p))) | |
581 | |
582 (defsubst delphi-char-token-at (p char kind) | |
583 ;; Returns the token at the point p that describes the specified character. | |
584 ;; If not actually over such a character, nil is returned. | |
585 (when (eq char (char-after p)) | |
586 (delphi-token-of kind p (1+ p)))) | |
587 | |
588 (defun delphi-charset-token-at (p charset kind) | |
589 ;; Returns the token surrounding point p that contains only members of the | |
590 ;; character set. | |
591 (let ((currp (point)) | |
592 (end nil) | |
593 (start nil) | |
594 (token nil)) | |
595 (goto-char p) | |
596 (when (> (skip-chars-forward charset) 0) | |
597 (setq end (point)) | |
598 (goto-char (1+ p)) | |
599 (skip-chars-backward charset) | |
600 (setq token (delphi-token-of kind (point) end))) | |
601 (goto-char currp) | |
602 token)) | |
603 | |
604 (defun delphi-space-token-at (p) | |
605 ;; If point p is surrounded by space characters, then return the token of the | |
606 ;; contiguous spaces. | |
607 (delphi-charset-token-at p delphi-space-chars 'space)) | |
608 | |
609 (defun delphi-word-token-at (p) | |
610 ;; If point p is over a word (i.e. identifier characters), then return a word | |
611 ;; token. If the word is actually a keyword, then return the keyword token. | |
612 (let ((word (delphi-charset-token-at p delphi-word-chars 'word))) | |
613 (when word | |
614 (let* ((word-image (downcase (delphi-token-string word))) | |
615 (keyword (intern-soft word-image))) | |
616 (when (and (or keyword (string= "nil" word-image)) | |
617 (delphi-is keyword delphi-keywords)) | |
618 (delphi-set-token-kind word keyword)) | |
619 word)))) | |
620 | |
621 (defun delphi-explicit-token-at (p token-string kind) | |
622 ;; If point p is anywhere in the token string then returns the resulting | |
623 ;; token. | |
624 (let ((token (delphi-charset-token-at p token-string kind))) | |
625 (when (and token (string= token-string (delphi-token-string token))) | |
626 token))) | |
627 | |
628 (defun delphi-token-at (p) | |
629 ;; Returns the token from parsing text at point p. | |
630 (when (and (<= (point-min) p) (<= p (point-max))) | |
631 (cond ((delphi-literal-token-at p)) | |
632 | |
633 ((delphi-space-token-at p)) | |
634 | |
635 ((delphi-word-token-at p)) | |
636 | |
637 ((delphi-char-token-at p ?\( 'open-group)) | |
638 ((delphi-char-token-at p ?\) 'close-group)) | |
639 ((delphi-char-token-at p ?\[ 'open-group)) | |
640 ((delphi-char-token-at p ?\] 'close-group)) | |
641 ((delphi-char-token-at p ?\n 'newline)) | |
642 ((delphi-char-token-at p ?\; 'semicolon)) | |
643 ((delphi-char-token-at p ?. 'dot)) | |
644 ((delphi-char-token-at p ?, 'comma)) | |
645 ((delphi-char-token-at p ?= 'equals)) | |
646 ((delphi-char-token-at p ?+ 'plus)) | |
647 ((delphi-char-token-at p ?- 'minus)) | |
648 ((delphi-char-token-at p ?* 'times)) | |
649 ((delphi-char-token-at p ?/ 'divides)) | |
650 ((delphi-char-token-at p ?: 'colon)) | |
651 | |
652 ((delphi-explicit-token-at p "<>" 'not-equals)) | |
653 | |
654 ((delphi-point-token-at p 'punctuation))))) | |
655 | |
656 (defun delphi-current-token () | |
657 ;; Returns the delphi source token under the current point. | |
658 (delphi-token-at (point))) | |
659 | |
660 (defun delphi-next-token (token) | |
661 ;; Returns the token after the specified token. | |
662 (when token | |
663 (let ((next (delphi-token-at (delphi-token-end token)))) | |
664 (if next | |
665 (delphi-step-progress (delphi-token-start next) "Scanning" | |
666 delphi-scanning-progress-step)) | |
667 next))) | |
668 | |
669 (defun delphi-previous-token (token) | |
670 ;; Returns the token before the specified token. | |
671 (when token | |
672 (let ((previous (delphi-token-at (1- (delphi-token-start token))))) | |
673 (if previous | |
674 (delphi-step-progress (delphi-token-start previous) "Scanning" | |
675 delphi-scanning-progress-step)) | |
676 previous))) | |
677 | |
678 (defun delphi-next-visible-token (token) | |
679 ;; Returns the first non-space token after the specified token. | |
680 (let (next-token) | |
681 (while (progn | |
682 (setq next-token (delphi-next-token token)) | |
683 (delphi-is (delphi-token-kind next-token) '(space newline)))) | |
684 next-token)) | |
685 | |
686 (defun delphi-parse-region (from to) | |
687 ;; Parses the literal tokens in the region. The point is set to "to". | |
688 (save-restriction | |
689 (widen) | |
690 (goto-char from) | |
691 (while (< (point) to) | |
692 (delphi-parse-next-literal to)))) | |
693 | |
694 (defun delphi-parse-region-until-stable (from to) | |
695 ;; Parses at least the literal tokens in the region. After that, parsing | |
696 ;; continues as long as obsolete literal regions are encountered. The point | |
697 ;; is set to the encountered stable point. | |
698 (save-restriction | |
699 (widen) | |
700 (delphi-parse-region from to) | |
701 (while (not (delphi-is-stable-literal (point))) | |
702 (delphi-parse-next-literal (point-max))))) | |
703 | |
704 (defun delphi-fontify-region (from to &optional verbose) | |
705 ;; Colors the text in the region according to Delphi rules. | |
706 (delphi-save-excursion | |
707 (delphi-save-state | |
708 (let ((p from) | |
709 (delphi-verbose verbose) | |
710 (token nil)) | |
711 (delphi-progress-start) | |
712 (while (< p to) | |
713 ;; Color the token and move past it. | |
714 (setq token (delphi-token-at p)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
715 (add-text-properties |
25072 | 716 (delphi-token-start token) (delphi-token-end token) |
717 (list 'face (delphi-face-of (delphi-token-kind token)) 'lazy-lock t)) | |
718 (setq p (delphi-token-end token)) | |
719 (delphi-step-progress p "Fontifying" delphi-fontifying-progress-step)) | |
720 (delphi-progress-done))))) | |
721 | |
51360
f48326c934af
(large-file-warning-threshold): Add type, groups.
John Paul Wallington <jpw@pobox.com>
parents:
49598
diff
changeset
|
722 (defvar delphi-ignore-changes t |
25072 | 723 "Internal flag to control if the delphi-mode responds to buffer changes. |
724 Defaults to t in case the delphi-after-change function is called on a | |
725 non-delphi buffer. Set to nil in a delphi buffer. To override, just do: | |
726 (let ((delphi-ignore-changes t)) ...)") | |
727 | |
728 (defun delphi-after-change (change-start change-end old-length) | |
729 ;; Called when the buffer has changed. Reparses the changed region. | |
730 (unless delphi-ignore-changes | |
731 (let ((delphi-ignore-changes t)) ; Prevent recursive calls. | |
732 (delphi-save-excursion | |
733 (delphi-progress-start) | |
734 ;; Reparse at least from the token previous to the change to the end of | |
735 ;; line after the change. | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
736 (delphi-parse-region-until-stable |
25072 | 737 (delphi-token-start (delphi-token-at (1- change-start))) |
738 (progn (goto-char change-end) (end-of-line) (point))) | |
739 (delphi-progress-done))))) | |
740 | |
741 (defun delphi-group-start (from-token) | |
742 ;; Returns the token that denotes the start of the ()/[] group. | |
743 (let ((token (delphi-previous-token from-token)) | |
744 (token-kind nil)) | |
745 (catch 'done | |
746 (while token | |
747 (setq token-kind (delphi-token-kind token)) | |
748 (cond | |
749 ;; Skip over nested groups. | |
750 ((eq 'close-group token-kind) (setq token (delphi-group-start token))) | |
751 ((eq 'open-group token-kind) (throw 'done token))) | |
752 (setq token (delphi-previous-token token))) | |
753 ;; Start not found. | |
754 nil))) | |
755 | |
756 (defun delphi-group-end (from-token) | |
757 ;; Returns the token that denotes the end of the ()/[] group. | |
758 (let ((token (delphi-next-token from-token)) | |
759 (token-kind nil)) | |
760 (catch 'done | |
761 (while token | |
762 (setq token-kind (delphi-token-kind token)) | |
763 (cond | |
764 ;; Skip over nested groups. | |
765 ((eq 'open-group token-kind) (setq token (delphi-group-end token))) | |
766 ((eq 'close-group token-kind) (throw 'done token))) | |
767 (setq token (delphi-next-token token))) | |
768 ;; end not found. | |
769 nil))) | |
770 | |
771 (defun delphi-indent-of (token &optional offset) | |
772 ;; Returns the start column of the token, plus any offset. | |
773 (let ((indent (+ (delphi-column-of (delphi-token-start token)) | |
774 (if offset offset 0)))) | |
775 (when delphi-debug | |
776 (delphi-debug-log | |
777 (concat "\n Indent of: %S %S" | |
778 "\n column: %d indent: %d offset: %d") | |
779 token (delphi-token-string token) | |
780 (delphi-column-of (delphi-token-start token)) | |
781 indent (if offset offset 0))) | |
782 indent)) | |
783 | |
784 (defun delphi-line-indent-of (from-token &optional offset &rest terminators) | |
785 ;; Returns the column of first non-space character on the token's line, plus | |
786 ;; any offset. We also stop if one of the terminators or an open ( or [ is | |
787 ;; encountered. | |
788 (let ((token (delphi-previous-token from-token)) | |
789 (last-token from-token) | |
790 (kind nil)) | |
791 (catch 'done | |
792 (while token | |
793 (setq kind (delphi-token-kind token)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
794 (cond |
25072 | 795 ;; Skip over ()/[] groups. |
796 ((eq 'close-group kind) (setq token (delphi-group-start token))) | |
797 | |
798 ;; Stop at the beginning of the line or an open group. | |
799 ((delphi-is kind '(newline open-group)) (throw 'done nil)) | |
800 | |
801 ;; Stop at one of the specified terminators. | |
802 ((delphi-is kind terminators) (throw 'done nil))) | |
803 (unless (delphi-is kind delphi-whitespace) (setq last-token token)) | |
804 (setq token (delphi-previous-token token)))) | |
805 (delphi-indent-of last-token offset))) | |
806 | |
807 (defun delphi-stmt-line-indent-of (from-token &optional offset) | |
25161
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
808 ;; Like `delphi-line-indent-of' except is also stops on a use clause, and |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
809 ;; colons that precede statements (i.e. case labels). |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
810 (let ((token (delphi-previous-token from-token)) |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
811 (last-token from-token) |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
812 (kind nil)) |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
813 (catch 'done |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
814 (while token |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
815 (setq kind (delphi-token-kind token)) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
816 (cond |
25161
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
817 ((and (eq 'colon kind) |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
818 (delphi-is (delphi-token-kind last-token) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
819 `(,@delphi-block-statements |
25161
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
820 ,@delphi-expr-statements))) |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
821 ;; We hit a label followed by a statement. Indent to the statement. |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
822 (throw 'done nil)) |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
823 |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
824 ;; Skip over ()/[] groups. |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
825 ((eq 'close-group kind) (setq token (delphi-group-start token))) |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
826 |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
827 ((delphi-is kind `(newline open-group ,@delphi-use-clauses)) |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
828 ;; Stop at the beginning of the line, an open group, or a use clause |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
829 (throw 'done nil))) |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
830 (unless (delphi-is kind delphi-whitespace) (setq last-token token)) |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
831 (setq token (delphi-previous-token token)))) |
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
832 (delphi-indent-of last-token offset))) |
25072 | 833 |
834 (defun delphi-open-group-indent (token last-token &optional offset) | |
835 ;; Returns the indent relative to an unmatched ( or [. | |
836 (when (eq 'open-group (delphi-token-kind token)) | |
837 (if last-token | |
838 (delphi-indent-of last-token offset) | |
839 ;; There is nothing following the ( or [. Indent from its line. | |
840 (delphi-stmt-line-indent-of token delphi-indent-level)))) | |
841 | |
842 (defun delphi-composite-type-start (token last-token) | |
97926 | 843 ;; Returns true (actually the last-token) if the pair equals (= class), (= |
844 ;; dispinterface), (= interface), (= object), or (= record), and nil | |
845 ;; otherwise. | |
25072 | 846 (if (and (eq 'equals (delphi-token-kind token)) |
847 (delphi-is (delphi-token-kind last-token) delphi-composite-types)) | |
848 last-token)) | |
849 | |
850 (defun delphi-is-simple-class-type (at-token limit-token) | |
851 ;; True if at-token is the start of a simple class type. E.g. | |
852 ;; class of TClass; | |
853 ;; class (TBaseClass); | |
854 ;; class; | |
855 (when (delphi-is (delphi-token-kind at-token) delphi-class-types) | |
856 (catch 'done | |
857 ;; Scan until the semi colon. | |
858 (let ((token (delphi-next-token at-token)) | |
859 (token-kind nil) | |
860 (limit (delphi-token-start limit-token))) | |
861 (while (and token (<= (delphi-token-start token) limit)) | |
862 (setq token-kind (delphi-token-kind token)) | |
863 (cond | |
864 ;; A semicolon delimits the search. | |
865 ((eq 'semicolon token-kind) (throw 'done token)) | |
866 | |
867 ;; Skip over the inheritance list. | |
868 ((eq 'open-group token-kind) (setq token (delphi-group-end token))) | |
869 | |
870 ;; Only allow "of" and whitespace, and an identifier | |
871 ((delphi-is token-kind `(of word ,@delphi-whitespace))) | |
872 | |
873 ;; Otherwise we are not in a simple class declaration. | |
874 ((throw 'done nil))) | |
875 (setq token (delphi-next-token token))))))) | |
876 | |
877 (defun delphi-block-start (from-token &optional stop-on-class) | |
878 ;; Returns the token that denotes the start of the block. | |
879 (let ((token (delphi-previous-token from-token)) | |
880 (last-token nil) | |
881 (token-kind nil)) | |
882 (catch 'done | |
883 (while token | |
884 (setq token-kind (delphi-token-kind token)) | |
885 (cond | |
886 ;; Skip over nested blocks. | |
887 ((delphi-is token-kind delphi-end-block-statements) | |
888 (setq token (delphi-block-start token))) | |
889 | |
890 ;; Regular block start found. | |
891 ((delphi-is token-kind delphi-block-statements) (throw 'done token)) | |
892 | |
893 ;; A class/record start also begins a block. | |
894 ((delphi-composite-type-start token last-token) | |
895 (throw 'done (if stop-on-class last-token token))) | |
896 ) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
897 (unless (delphi-is token-kind delphi-whitespace) |
25072 | 898 (setq last-token token)) |
899 (setq token (delphi-previous-token token))) | |
900 ;; Start not found. | |
901 nil))) | |
902 | |
903 (defun delphi-else-start (from-else) | |
904 ;; Returns the token of the if or case statement. | |
905 (let ((token (delphi-previous-token from-else)) | |
906 (token-kind nil) | |
907 (semicolon-count 0) | |
908 (if-count 0)) | |
909 (catch 'done | |
910 (while token | |
911 (setq token-kind (delphi-token-kind token)) | |
912 (cond | |
913 ;; Skip over nested groups. | |
914 ((eq 'close-group token-kind) (setq token (delphi-group-start token))) | |
915 | |
916 ;; Skip over any nested blocks. | |
917 ((delphi-is token-kind delphi-end-block-statements) | |
918 (setq token (delphi-block-start token))) | |
919 | |
920 ((eq 'semicolon token-kind) | |
921 ;; Semicolon means we are looking for an enclosing if, unless we | |
922 ;; are in a case statement. Keep counts of the semicolons and decide | |
923 ;; later. | |
924 (setq semicolon-count (1+ semicolon-count))) | |
925 | |
926 ((and (eq 'if token-kind) (= semicolon-count 0)) | |
927 ;; We only can match an if when there have been no intervening | |
928 ;; semicolons. | |
929 (throw 'done token)) | |
930 | |
931 ((eq 'case token-kind) | |
932 ;; We have hit a case statement start. | |
933 (throw 'done token))) | |
934 (setq token (delphi-previous-token token))) | |
935 ;; No if or case statement found. | |
936 nil))) | |
937 | |
938 (defun delphi-comment-content-start (comment) | |
939 ;; Returns the point of the first non-space character in the comment. | |
940 (let ((kind (delphi-token-kind comment))) | |
941 (when (delphi-is kind delphi-comments) | |
942 (delphi-save-excursion | |
943 (goto-char (+ (delphi-token-start comment) | |
944 (length (delphi-literal-start-pattern kind)))) | |
945 (skip-chars-forward delphi-space-chars) | |
946 (point))))) | |
947 | |
948 (defun delphi-comment-block-start (comment) | |
949 ;; Returns the starting comment token of a contiguous // comment block. If | |
950 ;; the comment is multiline (i.e. {...} or (*...*)), the original comment is | |
951 ;; returned. | |
952 (if (not (eq 'comment-single-line (delphi-token-kind comment))) | |
953 comment | |
954 ;; Scan until we run out of // comments. | |
955 (let ((prev-comment comment) | |
956 (start-comment comment) | |
957 (kind nil)) | |
958 (while (let ((kind (delphi-token-kind prev-comment))) | |
959 (cond ((eq kind 'space)) | |
960 ((eq kind 'comment-single-line) | |
961 (setq start-comment prev-comment)) | |
962 (t nil))) | |
963 (setq prev-comment (delphi-previous-token prev-comment))) | |
964 start-comment))) | |
965 | |
966 (defun delphi-comment-block-end (comment) | |
967 ;; Returns the end comment token of a contiguous // comment block. If the | |
968 ;; comment is multiline (i.e. {...} or (*...*)), the original comment is | |
969 ;; returned. | |
970 (if (not (eq 'comment-single-line (delphi-token-kind comment))) | |
971 comment | |
972 ;; Scan until we run out of // comments. | |
973 (let ((next-comment comment) | |
974 (end-comment comment) | |
975 (kind nil)) | |
976 (while (let ((kind (delphi-token-kind next-comment))) | |
977 (cond ((eq kind 'space)) | |
978 ((eq kind 'comment-single-line) | |
979 (setq end-comment next-comment)) | |
980 (t nil))) | |
981 (setq next-comment (delphi-next-token next-comment))) | |
982 end-comment))) | |
983 | |
984 (defun delphi-on-first-comment-line (comment) | |
985 ;; Returns true if the current point is on the first line of the comment. | |
986 (save-excursion | |
987 (let ((comment-start (delphi-token-start comment)) | |
988 (current-point (point))) | |
989 (goto-char comment-start) | |
990 (end-of-line) | |
991 (and (<= comment-start current-point) (<= current-point (point)))))) | |
992 | |
993 (defun delphi-comment-indent-of (comment) | |
994 ;; Returns the correct indentation for the comment. | |
995 (let ((start-comment (delphi-comment-block-start comment))) | |
996 (if (and (eq start-comment comment) | |
997 (delphi-on-first-comment-line comment)) | |
998 ;; Indent as a statement. | |
999 (delphi-enclosing-indent-of comment) | |
1000 (save-excursion | |
1001 (let ((kind (delphi-token-kind comment))) | |
1002 (beginning-of-line) | |
1003 (cond ((eq 'comment-single-line kind) | |
1004 ;; Indent to the first comment in the // block. | |
1005 (delphi-indent-of start-comment)) | |
1006 | |
1007 ((looking-at (concat delphi-leading-spaces-re | |
1008 (delphi-literal-stop-pattern kind))) | |
1009 ;; Indent multi-line comment terminators to the comment start. | |
1010 (delphi-indent-of comment)) | |
1011 | |
1012 ;; Indent according to the comment's content start. | |
1013 ((delphi-column-of (delphi-comment-content-start comment))))))) | |
1014 )) | |
1015 | |
1016 (defun delphi-is-use-clause-end (at-token last-token last-colon from-kind) | |
1017 ;; True if we are after the end of a uses type clause. | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
1018 (when (and last-token |
25072 | 1019 (not last-colon) |
1020 (eq 'comma (delphi-token-kind at-token)) | |
1021 (eq 'semicolon from-kind)) | |
1022 ;; Scan for the uses statement, just to be sure. | |
1023 (let ((token (delphi-previous-token at-token)) | |
1024 (token-kind nil)) | |
1025 (catch 'done | |
1026 (while token | |
1027 (setq token-kind (delphi-token-kind token)) | |
1028 (cond ((delphi-is token-kind delphi-use-clauses) | |
1029 (throw 'done t)) | |
1030 | |
1031 ;; Whitespace, identifiers, strings, "in" keyword, and commas | |
1032 ;; are allowed in use clauses. | |
1033 ((or (delphi-is token-kind '(word comma in newline)) | |
1034 (delphi-is token-kind delphi-whitespace) | |
1035 (delphi-is token-kind delphi-strings))) | |
1036 | |
1037 ;; Nothing else is. | |
1038 ((throw 'done nil))) | |
1039 (setq token (delphi-previous-token token))) | |
1040 nil)))) | |
1041 | |
1042 (defun delphi-is-block-after-expr-statement (token) | |
1043 ;; Returns true if we have a block token trailing an expression delimiter (of | |
1044 ;; presumably an expression statement). | |
1045 (when (delphi-is (delphi-token-kind token) delphi-block-statements) | |
1046 (let ((previous (delphi-previous-token token)) | |
1047 (previous-kind nil)) | |
1048 (while (progn | |
1049 (setq previous-kind (delphi-token-kind previous)) | |
1050 (eq previous-kind 'space)) | |
1051 (setq previous (delphi-previous-token previous))) | |
1052 (or (delphi-is previous-kind delphi-expr-delimiters) | |
1053 (eq previous-kind 'else))))) | |
1054 | |
1055 (defun delphi-previous-indent-of (from-token) | |
1056 ;; Returns the indentation of the previous statement of the token. | |
1057 (let ((token (delphi-previous-token from-token)) | |
1058 (token-kind nil) | |
1059 (from-kind (delphi-token-kind from-token)) | |
1060 (last-colon nil) | |
1061 (last-token nil)) | |
1062 (catch 'done | |
1063 (while token | |
1064 (setq token-kind (delphi-token-kind token)) | |
1065 (cond | |
1066 ;; An open ( or [ always is an indent point. | |
1067 ((eq 'open-group token-kind) | |
1068 (throw 'done (delphi-open-group-indent token last-token))) | |
1069 | |
1070 ;; Skip over any ()/[] groups. | |
1071 ((eq 'close-group token-kind) (setq token (delphi-group-start token))) | |
1072 | |
1073 ((delphi-is token-kind delphi-end-block-statements) | |
1074 (if (eq 'newline (delphi-token-kind (delphi-previous-token token))) | |
1075 ;; We can stop at an end token that is right up against the | |
1076 ;; margin. | |
1077 (throw 'done 0) | |
1078 ;; Otherwise, skip over any nested blocks. | |
1079 (setq token (delphi-block-start token)))) | |
1080 | |
1081 ;; Special case: if we encounter a ", word;" then we assume that we | |
1082 ;; are in some kind of uses clause, and thus indent to column 0. This | |
1083 ;; works because no other constructs are known to have that form. | |
1084 ;; This fixes the irritating case of having indents after a uses | |
1085 ;; clause look like: | |
1086 ;; uses | |
1087 ;; someUnit, | |
1088 ;; someOtherUnit; | |
1089 ;; // this should be at column 0! | |
1090 ((delphi-is-use-clause-end token last-token last-colon from-kind) | |
1091 (throw 'done 0)) | |
1092 | |
1093 ;; A previous terminator means we can stop. If we are on a directive, | |
1094 ;; however, then we are not actually encountering a new statement. | |
1095 ((and last-token | |
1096 (delphi-is token-kind delphi-previous-terminators) | |
1097 (not (delphi-is (delphi-token-kind last-token) | |
1098 delphi-directives))) | |
1099 (throw 'done (delphi-stmt-line-indent-of last-token 0))) | |
1100 | |
1101 ;; Ignore whitespace. | |
1102 ((delphi-is token-kind delphi-whitespace)) | |
1103 | |
1104 ;; Remember any ':' we encounter, since that affects how we indent to | |
1105 ;; a case statement. | |
1106 ((eq 'colon token-kind) (setq last-colon token)) | |
1107 | |
1108 ;; A case statement delimits a previous statement. We indent labels | |
1109 ;; specially. | |
1110 ((eq 'case token-kind) | |
1111 (throw 'done | |
1112 (if last-colon (delphi-line-indent-of last-colon) | |
1113 (delphi-line-indent-of token delphi-case-label-indent)))) | |
1114 | |
1115 ;; If we are in a use clause then commas mark an enclosing rather than | |
1116 ;; a previous statement. | |
1117 ((delphi-is token-kind delphi-use-clauses) | |
1118 (throw 'done | |
1119 (if (eq 'comma from-kind) | |
1120 (if last-token | |
1121 ;; Indent to first unit in use clause. | |
1122 (delphi-indent-of last-token) | |
1123 ;; Indent from use clause keyword. | |
1124 (delphi-line-indent-of token delphi-indent-level)) | |
1125 ;; Indent to use clause keyword. | |
1126 (delphi-line-indent-of token)))) | |
1127 | |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1128 ;; Assembly sections always indent in from the asm keyword. |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
1129 ((eq token-kind 'asm) |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1130 (throw 'done (delphi-stmt-line-indent-of token delphi-indent-level))) |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1131 |
25072 | 1132 ;; An enclosing statement delimits a previous statement. |
1133 ;; We try to use the existing indent of the previous statement, | |
1134 ;; otherwise we calculate from the enclosing statement. | |
1135 ((delphi-is token-kind delphi-previous-enclosing-statements) | |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1136 (throw 'done (if last-token |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1137 ;; Otherwise indent to the last token |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1138 (delphi-line-indent-of last-token) |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1139 ;; Just indent from the enclosing keyword |
25072 | 1140 (delphi-line-indent-of token delphi-indent-level)))) |
1141 | |
1142 ;; A class or record declaration also delimits a previous statement. | |
1143 ((delphi-composite-type-start token last-token) | |
1144 (throw | |
1145 'done | |
1146 (if (delphi-is-simple-class-type last-token from-token) | |
1147 ;; c = class; or c = class of T; are previous statements. | |
1148 (delphi-line-indent-of token) | |
1149 ;; Otherwise c = class ... or r = record ... are enclosing | |
1150 ;; statements. | |
1151 (delphi-line-indent-of last-token delphi-indent-level)))) | |
1152 | |
1153 ;; We have a definite previous statement delimiter. | |
1154 ((delphi-is token-kind delphi-previous-statements) | |
1155 (throw 'done (delphi-stmt-line-indent-of token 0))) | |
1156 ) | |
1157 (unless (delphi-is token-kind delphi-whitespace) | |
1158 (setq last-token token)) | |
1159 (setq token (delphi-previous-token token))) | |
1160 ;; We ran out of tokens. Indent to column 0. | |
1161 0))) | |
1162 | |
1163 (defun delphi-section-indent-of (section-token) | |
1164 ;; Returns the indentation appropriate for begin/var/const/type/label | |
1165 ;; tokens. | |
1166 (let* ((token (delphi-previous-token section-token)) | |
1167 (token-kind nil) | |
1168 (last-token nil) | |
1169 (nested-block-count 0) | |
1170 (expr-delimited nil) | |
1171 (last-terminator nil)) | |
1172 (catch 'done | |
1173 (while token | |
1174 (setq token-kind (delphi-token-kind token)) | |
1175 (cond | |
1176 ;; Always stop at unmatched ( or [. | |
1177 ((eq token-kind 'open-group) | |
1178 (throw 'done (delphi-open-group-indent token last-token))) | |
1179 | |
1180 ;; Skip over any ()/[] groups. | |
1181 ((eq 'close-group token-kind) (setq token (delphi-group-start token))) | |
1182 | |
1183 ((delphi-is token-kind delphi-end-block-statements) | |
1184 (if (eq 'newline (delphi-token-kind (delphi-previous-token token))) | |
1185 ;; We can stop at an end token that is right up against the | |
1186 ;; margin. | |
1187 (throw 'done 0) | |
1188 ;; Otherwise, skip over any nested blocks. | |
1189 (setq token (delphi-block-start token) | |
1190 nested-block-count (1+ nested-block-count)))) | |
1191 | |
1192 ;; Remember if we have encountered any forward routine declarations. | |
1193 ((eq 'forward token-kind) | |
1194 (setq nested-block-count (1+ nested-block-count))) | |
1195 | |
1196 ;; Mark the completion of a nested routine traversal. | |
1197 ((and (delphi-is token-kind delphi-routine-statements) | |
1198 (> nested-block-count 0)) | |
1199 (setq nested-block-count (1- nested-block-count))) | |
1200 | |
1201 ;; Remember if we have encountered any statement terminators. | |
1202 ((eq 'semicolon token-kind) (setq last-terminator token)) | |
1203 | |
1204 ;; Remember if we have encountered any expression delimiters. | |
1205 ((delphi-is token-kind delphi-expr-delimiters) | |
1206 (setq expr-delimited token)) | |
1207 | |
1208 ;; Enclosing body statements are delimiting. We indent the compound | |
1209 ;; bodies specially. | |
1210 ((and (not last-terminator) | |
1211 (delphi-is token-kind delphi-body-statements)) | |
1212 (throw 'done | |
1213 (delphi-stmt-line-indent-of token delphi-compound-block-indent))) | |
1214 | |
1215 ;; An enclosing ":" means a label. | |
1216 ((and (eq 'colon token-kind) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
1217 (delphi-is (delphi-token-kind section-token) |
25072 | 1218 delphi-block-statements) |
1219 (not last-terminator) | |
1220 (not expr-delimited) | |
1221 (not (eq 'equals (delphi-token-kind last-token)))) | |
1222 (throw 'done | |
1223 (delphi-stmt-line-indent-of token delphi-indent-level))) | |
1224 | |
1225 ;; Block and mid block tokens are always enclosing | |
1226 ((delphi-is token-kind delphi-begin-enclosing-tokens) | |
1227 (throw 'done | |
25161
ae69eef1b98b
checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents:
25072
diff
changeset
|
1228 (delphi-stmt-line-indent-of token delphi-indent-level))) |
25072 | 1229 |
1230 ;; Declaration sections and routines are delimiters, unless they | |
1231 ;; are part of a nested routine. | |
1232 ((and (delphi-is token-kind delphi-decl-delimiters) | |
1233 (= 0 nested-block-count)) | |
1234 (throw 'done (delphi-line-indent-of token 0))) | |
1235 | |
1236 ;; Unit statements mean we indent right to the left. | |
1237 ((delphi-is token-kind delphi-unit-statements) (throw 'done 0)) | |
1238 ) | |
1239 (unless (delphi-is token-kind delphi-whitespace) | |
1240 (setq last-token token)) | |
1241 (setq token (delphi-previous-token token))) | |
1242 ;; We ran out of tokens. Indent to column 0. | |
1243 0))) | |
1244 | |
1245 (defun delphi-enclosing-indent-of (from-token) | |
1246 ;; Returns the indentation offset from the enclosing statement of the token. | |
1247 (let ((token (delphi-previous-token from-token)) | |
1248 (from-kind (delphi-token-kind from-token)) | |
1249 (token-kind nil) | |
1250 (stmt-start nil) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
1251 (last-token nil) |
25072 | 1252 (equals-encountered nil) |
1253 (before-equals nil) | |
1254 (expr-delimited nil)) | |
1255 (catch 'done | |
1256 (while token | |
1257 (setq token-kind (delphi-token-kind token)) | |
1258 (cond | |
1259 ;; An open ( or [ always is an indent point. | |
1260 ((eq 'open-group token-kind) | |
1261 (throw 'done | |
1262 (delphi-open-group-indent | |
1263 token last-token | |
1264 (if (delphi-is from-kind delphi-binary-ops) | |
1265 ;; Keep binary operations aligned with the open group. | |
1266 0 | |
1267 delphi-indent-level)))) | |
1268 | |
1269 ;; Skip over any ()/[] groups. | |
1270 ((eq 'close-group token-kind) (setq token (delphi-group-start token))) | |
1271 | |
1272 ;; Skip over any nested blocks. | |
1273 ((delphi-is token-kind delphi-end-block-statements) | |
1274 (setq token (delphi-block-start token))) | |
1275 | |
1276 ;; An expression delimiter affects indentation depending on whether | |
1277 ;; the point is before or after it. Remember that we encountered one. | |
1278 ;; Also remember the last encountered token, since if it exists it | |
1279 ;; should be the actual indent point. | |
1280 ((delphi-is token-kind delphi-expr-delimiters) | |
1281 (setq expr-delimited token stmt-start last-token)) | |
1282 | |
1283 ;; With a non-delimited expression statement we indent after the | |
1284 ;; statement's keyword, unless we are on the delimiter itself. | |
1285 ((and (not expr-delimited) | |
1286 (delphi-is token-kind delphi-expr-statements)) | |
1287 (throw 'done | |
1288 (cond ((delphi-is from-kind delphi-expr-delimiters) | |
1289 ;; We are indenting a delimiter. Indent to the statement. | |
1290 (delphi-stmt-line-indent-of token 0)) | |
1291 | |
1292 ((and last-token (delphi-is from-kind delphi-binary-ops)) | |
1293 ;; Align binary ops with the expression. | |
1294 (delphi-indent-of last-token)) | |
1295 | |
1296 (last-token | |
1297 ;; Indent in from the expression. | |
1298 (delphi-indent-of last-token delphi-indent-level)) | |
1299 | |
1300 ;; Indent in from the statement's keyword. | |
1301 ((delphi-indent-of token delphi-indent-level))))) | |
1302 | |
1303 ;; A delimited case statement indents the label according to | |
1304 ;; a special rule. | |
1305 ((eq 'case token-kind) | |
1306 (throw 'done | |
1307 (if stmt-start | |
1308 ;; We are not actually indenting to the case statement, | |
1309 ;; but are within a label expression. | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
1310 (delphi-stmt-line-indent-of |
25072 | 1311 stmt-start delphi-indent-level) |
1312 ;; Indent from the case keyword. | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
1313 (delphi-stmt-line-indent-of |
25072 | 1314 token delphi-case-label-indent)))) |
1315 | |
1316 ;; Body expression statements are enclosing. Indent from the | |
1317 ;; statement's keyword, unless we have a non-block statement following | |
1318 ;; it. | |
1319 ((delphi-is token-kind delphi-body-expr-statements) | |
1320 (throw 'done | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
1321 (delphi-stmt-line-indent-of |
25072 | 1322 (or stmt-start token) delphi-indent-level))) |
1323 | |
1324 ;; An else statement is enclosing, but it doesn't have an expression. | |
1325 ;; Thus we take into account last-token instead of stmt-start. | |
1326 ((eq 'else token-kind) | |
1327 (throw 'done (delphi-stmt-line-indent-of | |
1328 (or last-token token) delphi-indent-level))) | |
1329 | |
1330 ;; We indent relative to an enclosing declaration section. | |
1331 ((delphi-is token-kind delphi-decl-sections) | |
1332 (throw 'done (delphi-indent-of (if last-token last-token token) | |
1333 delphi-indent-level))) | |
1334 | |
1335 ;; In unit sections we indent right to the left. | |
97926 | 1336 ((delphi-is token-kind delphi-unit-sections) |
1337 (throw 'done | |
1338 ;; Handle specially the case of "interface", which can be used | |
1339 ;; to start either a unit section or an interface definition. | |
1340 (if (delphi-is token-kind delphi-interface-types) | |
1341 (progn | |
1342 ;; Find the previous non-whitespace token. | |
1343 (while (progn | |
1344 (setq last-token token | |
1345 token (delphi-previous-token token) | |
1346 token-kind (delphi-token-kind token)) | |
1347 (and token | |
1348 (delphi-is token-kind | |
1349 delphi-whitespace)))) | |
1350 ;; If this token is an equals sign, "interface" is being | |
1351 ;; used to start an interface definition and we should | |
1352 ;; treat it as a composite type; otherwise, we should | |
1353 ;; consider it the start of a unit section. | |
1354 (if (and token (eq token-kind 'equals)) | |
1355 (delphi-line-indent-of last-token | |
1356 delphi-indent-level) | |
1357 0)) | |
1358 0))) | |
25072 | 1359 |
1360 ;; A previous terminator means we can stop. | |
1361 ((delphi-is token-kind delphi-previous-terminators) | |
1362 (throw 'done | |
1363 (cond ((and last-token | |
1364 (eq 'comma token-kind) | |
1365 (delphi-is from-kind delphi-binary-ops)) | |
1366 ;; Align binary ops with the expression. | |
1367 (delphi-indent-of last-token)) | |
1368 | |
1369 (last-token | |
1370 ;; Indent in from the expression. | |
1371 (delphi-indent-of last-token delphi-indent-level)) | |
1372 | |
1373 ;; No enclosing expression; use the previous statment's | |
1374 ;; indent. | |
1375 ((delphi-previous-indent-of token))))) | |
1376 | |
1377 ;; A block statement after an expression delimiter has its start | |
1378 ;; column as the expression statement. E.g. | |
1379 ;; if (a = b) | |
1380 ;; and (a != c) then begin | |
1381 ;; //... | |
1382 ;; end; | |
1383 ;; Remember it for when we encounter the expression statement start. | |
1384 ((delphi-is-block-after-expr-statement token) | |
1385 (throw 'done | |
1386 (cond (last-token (delphi-indent-of last-token delphi-indent-level)) | |
1387 | |
1388 ((+ (delphi-section-indent-of token) delphi-indent-level))))) | |
1389 | |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1390 ;; Assembly sections always indent in from the asm keyword. |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
1391 ((eq token-kind 'asm) |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1392 (throw 'done (delphi-stmt-line-indent-of token delphi-indent-level))) |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1393 |
25072 | 1394 ;; Stop at an enclosing statement and indent from it. |
1395 ((delphi-is token-kind delphi-enclosing-statements) | |
1396 (throw 'done (delphi-stmt-line-indent-of | |
1397 (or last-token token) delphi-indent-level))) | |
1398 | |
1399 ;; A class/record declaration is also enclosing. | |
1400 ((delphi-composite-type-start token last-token) | |
1401 (throw 'done | |
1402 (delphi-line-indent-of last-token delphi-indent-level))) | |
1403 | |
1404 ;; A ":" we indent relative to its line beginning. If we are in a | |
1405 ;; parameter list, then stop also if we hit a ";". | |
1406 ((and (eq token-kind 'colon) | |
1407 (not expr-delimited) | |
1408 (not (delphi-is from-kind delphi-expr-delimiters)) | |
1409 (not equals-encountered) | |
1410 (not (eq from-kind 'equals))) | |
1411 (throw 'done | |
1412 (if last-token | |
1413 (delphi-indent-of last-token delphi-indent-level) | |
1414 (delphi-line-indent-of token delphi-indent-level 'semicolon)))) | |
1415 | |
1416 ;; If the ":" was not processed above and we have token after the "=", | |
1417 ;; then indent from the "=". Ignore :=, however. | |
1418 ((and (eq token-kind 'colon) equals-encountered before-equals) | |
1419 (cond | |
1420 ;; Ignore binary ops for now. It would do, for example: | |
1421 ;; val := 1 + 2 | |
1422 ;; + 3; | |
1423 ;; which is good, but also | |
1424 ;; val := Foo | |
1425 ;; (foo, args) | |
1426 ;; + 2; | |
1427 ;; which doesn't look right. | |
1428 ;;;; Align binary ops with the before token. | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
1429 ;;((delphi-is from-kind delphi-binary-ops) |
25072 | 1430 ;;(throw 'done (delphi-indent-of before-equals 0))) |
1431 | |
1432 ;; Assignments (:=) we skip over to get a normal indent. | |
1433 ((eq (delphi-token-kind last-token) 'equals)) | |
1434 | |
1435 ;; Otherwise indent in from the equals. | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
1436 ((throw 'done |
25072 | 1437 (delphi-indent-of before-equals delphi-indent-level))))) |
1438 | |
1439 ;; Remember any "=" we encounter if it has not already been processed. | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
1440 ((eq token-kind 'equals) |
25072 | 1441 (setq equals-encountered token |
1442 before-equals last-token)) | |
1443 ) | |
1444 (unless (delphi-is token-kind delphi-whitespace) | |
1445 (setq last-token token)) | |
1446 (setq token (delphi-previous-token token))) | |
1447 ;; We ran out of tokens. Indent to column 0. | |
1448 0))) | |
1449 | |
1450 (defun delphi-corrected-indentation () | |
1451 ;; Returns the corrected indentation for the current line. | |
1452 (delphi-save-excursion | |
1453 (delphi-progress-start) | |
1454 ;; Move to the first token on the line. | |
1455 (beginning-of-line) | |
1456 (skip-chars-forward delphi-space-chars) | |
1457 (let* ((token (delphi-current-token)) | |
1458 (token-kind (delphi-token-kind token)) | |
1459 (indent | |
1460 (cond ((eq 'close-group token-kind) | |
1461 ;; Indent to the matching start ( or [. | |
1462 (delphi-indent-of (delphi-group-start token))) | |
1463 | |
1464 ((delphi-is token-kind delphi-unit-statements) 0) | |
1465 | |
1466 ((delphi-is token-kind delphi-comments) | |
1467 ;; In a comment. | |
1468 (delphi-comment-indent-of token)) | |
1469 | |
1470 ((delphi-is token-kind delphi-decl-matchers) | |
1471 ;; Use a previous section/routine's indent. | |
1472 (delphi-section-indent-of token)) | |
1473 | |
1474 ((delphi-is token-kind delphi-match-block-statements) | |
1475 ;; Use the block's indentation. | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41810
diff
changeset
|
1476 (let ((block-start |
25072 | 1477 (delphi-block-start token 'stop-on-class))) |
1478 (cond | |
1479 ;; When trailing a body statement, indent to | |
1480 ;; the statement's keyword. | |
1481 ((delphi-is-block-after-expr-statement block-start) | |
1482 (delphi-section-indent-of block-start)) | |
1483 | |
1484 ;; Otherwise just indent to the block start. | |
1485 ((delphi-stmt-line-indent-of block-start 0))))) | |
1486 | |
1487 ((eq 'else token-kind) | |
1488 ;; Find the start of the if or case statement. | |
1489 (delphi-stmt-line-indent-of (delphi-else-start token) 0)) | |
1490 | |
1491 ;; Otherwise indent in from enclosing statement. | |
1492 ((delphi-enclosing-indent-of | |
1493 (if token token (delphi-token-at (1- (point))))))))) | |
1494 (delphi-progress-done) | |
1495 indent))) | |
1496 | |
1497 (defun delphi-indent-line () | |
1498 "Indent the current line according to the current language construct. If | |
1499 before the indent, the point is moved to the indent." | |
1500 (interactive) | |
1501 (delphi-save-match-data | |
1502 (let ((marked-point (point-marker)) ; Maintain our position reliably. | |
1503 (new-point nil) | |
1504 (line-start nil) | |
1505 (old-indent 0) | |
1506 (new-indent 0)) | |
1507 (beginning-of-line) | |
1508 (setq line-start (point)) | |
1509 (skip-chars-forward delphi-space-chars) | |
1510 (setq old-indent (current-column)) | |
1511 (setq new-indent (delphi-corrected-indentation)) | |
1512 (if (< marked-point (point)) | |
1513 ;; If before the indent column, then move to it. | |
1514 (set-marker marked-point (point))) | |
1515 ;; Advance our marked point after inserted spaces. | |
1516 (set-marker-insertion-type marked-point t) | |
1517 (when (/= old-indent new-indent) | |
1518 (delete-region line-start (point)) | |
64041
e28ab96f1223
(delphi): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63276
diff
changeset
|
1519 (insert (make-string new-indent ?\s))) |
25072 | 1520 (goto-char marked-point) |
1521 (set-marker marked-point nil)))) | |
1522 | |
1523 (defvar delphi-mode-abbrev-table nil | |
1524 "Abbrev table in use in delphi-mode buffers.") | |
1525 (define-abbrev-table 'delphi-mode-abbrev-table ()) | |
1526 | |
1527 (defmacro delphi-ensure-buffer (buffer-var buffer-name) | |
1528 ;; Ensures there exists a buffer of the specified name in the specified | |
1529 ;; variable. | |
1530 `(when (not (buffer-live-p ,buffer-var)) | |
1531 (setq ,buffer-var (get-buffer-create ,buffer-name)))) | |
1532 | |
1533 (defun delphi-log-msg (to-buffer the-msg) | |
1534 ;; Writes a message to the end of the specified buffer. | |
1535 (with-current-buffer to-buffer | |
1536 (save-selected-window | |
1537 (switch-to-buffer-other-window to-buffer) | |
1538 (goto-char (point-max)) | |
62462
8fb97ebd6910
Replace `set-window-dot' by `set-window-point'.
Juanma Barranquero <lekktu@gmail.com>
parents:
54770
diff
changeset
|
1539 (set-window-point (get-buffer-window to-buffer) (point)) |
25072 | 1540 (insert the-msg)))) |
1541 | |
1542 ;; Debugging helpers: | |
1543 | |
1544 (defvar delphi-debug-buffer nil | |
1545 "Buffer to write delphi-mode debug messages to. Created on demand.") | |
1546 | |
1547 (defun delphi-debug-log (format-string &rest args) | |
1548 ;; Writes a message to the log buffer. | |
1549 (when delphi-debug | |
1550 (delphi-ensure-buffer delphi-debug-buffer "*Delphi Debug Log*") | |
1551 (delphi-log-msg delphi-debug-buffer | |
1552 (concat (format-time-string "%H:%M:%S " (current-time)) | |
1553 (apply #'format (cons format-string args)) | |
1554 "\n")))) | |
1555 | |
1556 (defun delphi-debug-token-string (token) | |
1557 (let* ((image (delphi-token-string token)) | |
1558 (has-newline (string-match "^\\([^\n]*\\)\n\\(.+\\)?$" image))) | |
1559 (when has-newline | |
1560 (setq image (concat (match-string 1 image) | |
1561 (if (match-beginning 2) "...")))) | |
1562 image)) | |
1563 | |
1564 (defun delphi-debug-show-current-token () | |
1565 (interactive) | |
1566 (let ((token (delphi-current-token))) | |
1567 (delphi-debug-log "Token: %S %S" token (delphi-debug-token-string token)))) | |
1568 | |
1569 (defun delphi-debug-goto-point (p) | |
1570 (interactive "NGoto char: ") | |
1571 (goto-char p)) | |
1572 | |
1573 (defun delphi-debug-goto-next-token () | |
1574 (interactive) | |
1575 (goto-char (delphi-token-start (delphi-next-token (delphi-current-token))))) | |
1576 | |
1577 (defun delphi-debug-goto-previous-token () | |
1578 (interactive) | |
1579 (goto-char | |
1580 (delphi-token-start (delphi-previous-token (delphi-current-token))))) | |
1581 | |
1582 (defun delphi-debug-show-current-string (from to) | |
1583 (interactive "r") | |
1584 (delphi-debug-log "String: %S" (buffer-substring from to))) | |
1585 | |
1586 (defun delphi-debug-show-is-stable () | |
1587 (interactive) | |
1588 (delphi-debug-log "stable: %S prev: %S next: %S" | |
1589 (delphi-is-stable-literal (point)) | |
1590 (delphi-literal-kind (1- (point))) | |
1591 (delphi-literal-kind (point)))) | |
1592 | |
1593 (defun delphi-debug-unparse-buffer () | |
1594 (interactive) | |
1595 (delphi-set-text-properties (point-min) (point-max) nil)) | |
1596 | |
1597 (defun delphi-debug-parse-region (from to) | |
1598 (interactive "r") | |
1599 (let ((delphi-verbose t)) | |
1600 (delphi-save-excursion | |
1601 (delphi-progress-start) | |
1602 (delphi-parse-region from to) | |
1603 (delphi-progress-done "Parsing done")))) | |
1604 | |
1605 (defun delphi-debug-parse-window () | |
1606 (interactive) | |
1607 (delphi-debug-parse-region (window-start) (window-end))) | |
1608 | |
1609 (defun delphi-debug-parse-buffer () | |
1610 (interactive) | |
1611 (delphi-debug-parse-region (point-min) (point-max))) | |
1612 | |
1613 (defun delphi-debug-fontify-window () | |
1614 (interactive) | |
1615 (delphi-fontify-region (window-start) (window-end) t)) | |
1616 | |
1617 (defun delphi-debug-fontify-buffer () | |
1618 (interactive) | |
1619 (delphi-fontify-region (point-min) (point-max) t)) | |
1620 | |
1621 (defun delphi-debug-tokenize-region (from to) | |
1622 (interactive) | |
1623 (delphi-save-excursion | |
1624 (delphi-progress-start) | |
1625 (goto-char from) | |
1626 (while (< (point) to) | |
1627 (goto-char (delphi-token-end (delphi-current-token))) | |
1628 (delphi-step-progress (point) "Tokenizing" delphi-scanning-progress-step)) | |
1629 (delphi-progress-done "Tokenizing done"))) | |
1630 | |
1631 (defun delphi-debug-tokenize-buffer () | |
1632 (interactive) | |
1633 (delphi-debug-tokenize-region (point-min) (point-max))) | |
1634 | |
1635 (defun delphi-debug-tokenize-window () | |
1636 (interactive) | |
1637 (delphi-debug-tokenize-region (window-start) (window-end))) | |
1638 | |
1639 (defun delphi-newline () | |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1640 "Terminate the current line with a newline and indent the next, unless |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1641 `delphi-newline-always-indents' is nil, in which case no reindenting occurs." |
25072 | 1642 (interactive) |
1643 ;; Remove trailing spaces | |
1644 (delete-horizontal-space) | |
1645 (newline) | |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1646 (when delphi-newline-always-indents |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1647 ;; Indent both the (now) previous and current line first. |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1648 (save-excursion |
85408
a7ff857f476d
(delphi-newline): Use forward-line.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
84919
diff
changeset
|
1649 (forward-line -1) |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1650 (delphi-indent-line)) |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1651 (delphi-indent-line))) |
25072 | 1652 |
1653 | |
1654 (defun delphi-tab () | |
1655 "Indent the current line or insert a TAB, depending on the value of | |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1656 `delphi-tab-always-indents' and the current line position." |
25072 | 1657 (interactive) |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1658 (if (or delphi-tab-always-indents ; We are always indenting |
25072 | 1659 ;; Or we are before the first non-space character on the line. |
1660 (save-excursion (skip-chars-backward delphi-space-chars) (bolp))) | |
1661 (delphi-indent-line) | |
1662 (insert "\t"))) | |
1663 | |
1664 | |
1665 (defun delphi-is-directory (path) | |
1666 ;; True if the specified path is an existing directory. | |
1667 (let ((attributes (file-attributes path))) | |
1668 (and attributes (car attributes)))) | |
1669 | |
1670 (defun delphi-is-file (path) | |
1671 ;; True if the specified file exists as a file. | |
1672 (let ((attributes (file-attributes path))) | |
1673 (and attributes (null (car attributes))))) | |
1674 | |
1675 (defun delphi-search-directory (unit dir &optional recurse) | |
1676 ;; Searches for the unit in the specified directory. If recurse is true, then | |
1677 ;; the directory is recursively searched. File name comparison is done in a | |
1678 ;; case insensitive manner. | |
1679 (when (delphi-is-directory dir) | |
1680 (let ((files (directory-files dir)) | |
1681 (unit-file (downcase unit))) | |
1682 (catch 'done | |
1683 ;; Search for the file. | |
84919
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1684 (mapc #'(lambda (file) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1685 (let ((path (concat dir "/" file))) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1686 (if (and (string= unit-file (downcase file)) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1687 (delphi-is-file path)) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1688 (throw 'done path)))) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1689 files) |
25072 | 1690 |
1691 ;; Not found. Search subdirectories. | |
1692 (when recurse | |
84919
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1693 (mapc #'(lambda (subdir) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1694 (unless (member subdir '("." "..")) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1695 (let ((path (delphi-search-directory |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1696 unit (concat dir "/" subdir) recurse))) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1697 (if path (throw 'done path))))) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1698 files)) |
25072 | 1699 |
1700 ;; Not found. | |
1701 nil)))) | |
1702 | |
1703 | |
1704 (defun delphi-find-unit-in-directory (unit dir) | |
1705 ;; Searches for the unit in the specified directory. If the directory ends | |
1706 ;; in \"...\", then it is recursively searched. | |
1707 (let ((dir-name dir) | |
1708 (recurse nil)) | |
1709 ;; Check if we need to recursively search the directory. | |
1710 (if (string-match "^\\(.+\\)\\.\\.\\.$" dir-name) | |
1711 (setq dir-name (match-string 1 dir-name) | |
1712 recurse t)) | |
1713 ;; Ensure the trailing slash is removed. | |
1714 (if (string-match "^\\(.+\\)[\\\\/]$" dir-name) | |
1715 (setq dir-name (match-string 1 dir-name))) | |
1716 (delphi-search-directory unit dir-name recurse))) | |
1717 | |
1718 (defun delphi-find-unit-file (unit) | |
1719 ;; Finds the specified delphi source file according to `delphi-search-path'. | |
1720 ;; If found, the full path is returned, otherwise nil is returned. | |
1721 (catch 'done | |
1722 (cond ((null delphi-search-path) | |
1723 (delphi-find-unit-in-directory unit ".")) | |
1724 | |
1725 ((stringp delphi-search-path) | |
1726 (delphi-find-unit-in-directory unit delphi-search-path)) | |
1727 | |
84919
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1728 ((mapc |
25072 | 1729 #'(lambda (dir) |
1730 (let ((file (delphi-find-unit-in-directory unit dir))) | |
1731 (if file (throw 'done file)))) | |
1732 delphi-search-path))) | |
1733 nil)) | |
1734 | |
1735 (defun delphi-find-unit (unit) | |
1736 "Finds the specified delphi source file according to `delphi-search-path'. | |
1737 If no extension is specified, .pas is assumed. Creates a buffer for the unit." | |
1738 (interactive "sDelphi unit name: ") | |
1739 (let* ((unit-file (if (string-match "^\\(.*\\)\\.[a-z]+$" unit) | |
1740 unit | |
1741 (concat unit ".pas"))) | |
1742 (file (delphi-find-unit-file unit-file))) | |
1743 (if (null file) | |
1744 (error "unit not found: %s" unit-file) | |
1745 (find-file file) | |
1746 (if (not (eq major-mode 'delphi-mode)) | |
1747 (delphi-mode))) | |
1748 file)) | |
1749 | |
1750 (defun delphi-find-current-def () | |
1751 "Find the definition of the identifier under the current point." | |
1752 (interactive) | |
1753 (error "delphi-find-current-def: not implemented yet")) | |
1754 | |
1755 (defun delphi-find-current-xdef () | |
1756 "Find the definition of the identifier under the current point, searching | |
1757 in external units if necessary (as listed in the current unit's use clause). | |
1758 The set of directories to search for a unit is specified by the global variable | |
1759 delphi-search-path." | |
1760 (interactive) | |
1761 (error "delphi-find-current-xdef: not implemented yet")) | |
1762 | |
1763 (defun delphi-find-current-body () | |
1764 "Find the body of the identifier under the current point, assuming | |
1765 it is a routine." | |
1766 (interactive) | |
1767 (error "delphi-find-current-body: not implemented yet")) | |
1768 | |
1769 (defun delphi-fill-comment () | |
1770 "Fills the text of the current comment, according to `fill-column'. | |
1771 An error is raised if not in a comment." | |
1772 (interactive) | |
1773 (save-excursion | |
72068
cf25c4a644cd
(delphi-fill-comment): Use save-restriction.
Eli Zaretskii <eliz@gnu.org>
parents:
68773
diff
changeset
|
1774 (save-restriction |
25072 | 1775 (let* ((comment (delphi-current-token)) |
1776 (comment-kind (delphi-token-kind comment))) | |
1777 (if (not (delphi-is comment-kind delphi-comments)) | |
1778 (error "Not in a comment") | |
1779 (let* ((start-comment (delphi-comment-block-start comment)) | |
1780 (end-comment (delphi-comment-block-end comment)) | |
1781 (comment-start (delphi-token-start start-comment)) | |
1782 (comment-end (delphi-token-end end-comment)) | |
1783 (content-start (delphi-comment-content-start start-comment)) | |
1784 (content-indent (delphi-column-of content-start)) | |
64041
e28ab96f1223
(delphi): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63276
diff
changeset
|
1785 (content-prefix (make-string content-indent ?\s)) |
25072 | 1786 (content-prefix-re delphi-leading-spaces-re) |
1787 (p nil) | |
1788 (marked-point (point-marker))) ; Maintain our position reliably. | |
1789 (when (eq 'comment-single-line comment-kind) | |
1790 ;; // style comments need more work. | |
1791 (setq content-prefix | |
1792 (let ((comment-indent (delphi-column-of comment-start))) | |
64041
e28ab96f1223
(delphi): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63276
diff
changeset
|
1793 (concat (make-string comment-indent ?\s) "//" |
25072 | 1794 (make-string (- content-indent comment-indent 2) |
64041
e28ab96f1223
(delphi): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63276
diff
changeset
|
1795 ?\s))) |
25072 | 1796 content-prefix-re (concat delphi-leading-spaces-re |
1797 "//" | |
1798 delphi-spaces-re) | |
1799 comment-end (if (delphi-is-literal-end comment-end) | |
1800 ;; Don't include the trailing newline. | |
1801 (1- comment-end) | |
1802 comment-end))) | |
1803 | |
1804 ;; Advance our marked point after inserted spaces. | |
1805 (set-marker-insertion-type marked-point t) | |
1806 | |
1807 ;; Ensure we can modify the buffer | |
1808 (goto-char content-start) | |
1809 (insert " ") | |
1810 (delete-char -1) | |
1811 | |
1812 (narrow-to-region content-start comment-end) | |
1813 | |
1814 ;; Strip off the comment prefixes | |
1815 (setq p (point-min)) | |
1816 (while (when (< p (point-max)) | |
1817 (goto-char p) | |
1818 (re-search-forward content-prefix-re nil t)) | |
1819 (replace-match "" nil nil) | |
1820 (setq p (1+ (point)))) | |
1821 | |
1822 ;; add an extra line to prevent the fill from doing it for us. | |
1823 (goto-char (point-max)) | |
1824 (insert "\n") | |
1825 | |
1826 ;; Fill the comment contents. | |
1827 (let ((fill-column (- fill-column content-indent))) | |
1828 (fill-region (point-min) (point-max))) | |
1829 | |
1830 (goto-char (point-max)) | |
1831 (delete-char -1) | |
1832 | |
1833 ;; Restore comment prefixes. | |
1834 (goto-char (point-min)) | |
1835 (end-of-line) ; Don't reset the first line. | |
1836 (setq p (point)) | |
1837 (while (when (< p (point-max)) | |
1838 (goto-char p) | |
1839 (re-search-forward "^" nil t)) | |
1840 (replace-match content-prefix nil nil) | |
1841 (setq p (1+ (point)))) | |
1842 | |
1843 (setq comment-end (point-max)) | |
1844 (widen) | |
1845 | |
1846 ;; Restore our position | |
1847 (goto-char marked-point) | |
1848 (set-marker marked-point nil) | |
1849 | |
1850 ;; React to the entire fill change as a whole. | |
1851 (delphi-progress-start) | |
1852 (delphi-parse-region comment-start comment-end) | |
72068
cf25c4a644cd
(delphi-fill-comment): Use save-restriction.
Eli Zaretskii <eliz@gnu.org>
parents:
68773
diff
changeset
|
1853 (delphi-progress-done))))))) |
25072 | 1854 |
1855 (defun delphi-new-comment-line () | |
1856 "If in a // comment, does a newline, indented such that one is still in the | |
1857 comment block. If not in a // comment, just does a normal newline." | |
1858 (interactive) | |
1859 (let ((comment (delphi-current-token))) | |
1860 (if (not (eq 'comment-single-line (delphi-token-kind comment))) | |
1861 ;; Not in a // comment. Just do the normal newline. | |
1862 (delphi-newline) | |
1863 (let* ((start-comment (delphi-comment-block-start comment)) | |
1864 (comment-start (delphi-token-start start-comment)) | |
1865 (content-start (delphi-comment-content-start start-comment)) | |
1866 (prefix | |
64041
e28ab96f1223
(delphi): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63276
diff
changeset
|
1867 (concat (make-string (delphi-column-of comment-start) ?\s) "//" |
e28ab96f1223
(delphi): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63276
diff
changeset
|
1868 (make-string (- content-start comment-start 2) ?\s)))) |
25072 | 1869 (delete-horizontal-space) |
1870 (newline) | |
1871 (insert prefix))))) | |
1872 | |
1873 (defun delphi-match-token (token limit) | |
1874 ;; Sets the match region used by (match-string 0) and friends to the token's | |
1875 ;; region. Sets the current point to the end of the token (or limit). | |
1876 (set-match-data nil) | |
1877 (if token | |
1878 (let ((end (min (delphi-token-end token) limit))) | |
1879 (set-match-data (list (delphi-token-start token) end)) | |
1880 (goto-char end) | |
1881 token))) | |
1882 | |
1883 (defconst delphi-font-lock-defaults | |
1884 '(nil ; We have our own fontify routine, so keywords don't apply. | |
1885 t ; Syntactic fontification doesn't apply. | |
1886 nil ; Don't care about case since we don't use regexps to find tokens. | |
1887 nil ; Syntax alists don't apply. | |
1888 nil ; Syntax begin movement doesn't apply | |
1889 (font-lock-fontify-region-function . delphi-fontify-region) | |
1890 (font-lock-verbose . delphi-fontifying-progress-step)) | |
1891 "Delphi mode font-lock defaults. Syntactic fontification is ignored.") | |
1892 | |
1893 (defvar delphi-debug-mode-map | |
1894 (let ((kmap (make-sparse-keymap))) | |
84919
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1895 (mapc #'(lambda (binding) (define-key kmap (car binding) (cadr binding))) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1896 '(("n" delphi-debug-goto-next-token) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1897 ("p" delphi-debug-goto-previous-token) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1898 ("t" delphi-debug-show-current-token) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1899 ("T" delphi-debug-tokenize-buffer) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1900 ("W" delphi-debug-tokenize-window) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1901 ("g" delphi-debug-goto-point) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1902 ("s" delphi-debug-show-current-string) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1903 ("a" delphi-debug-parse-buffer) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1904 ("w" delphi-debug-parse-window) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1905 ("f" delphi-debug-fontify-window) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1906 ("F" delphi-debug-fontify-buffer) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1907 ("r" delphi-debug-parse-region) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1908 ("c" delphi-debug-unparse-buffer) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1909 ("x" delphi-debug-show-is-stable) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1910 )) |
25072 | 1911 kmap) |
1912 "Keystrokes for delphi-mode debug commands.") | |
1913 | |
1914 (defvar delphi-mode-map | |
1915 (let ((kmap (make-sparse-keymap))) | |
84919
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1916 (mapc #'(lambda (binding) (define-key kmap (car binding) (cadr binding))) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1917 (list '("\r" delphi-newline) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1918 '("\t" delphi-tab) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1919 '("\177" backward-delete-char-untabify) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1920 ;; '("\C-cd" delphi-find-current-def) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1921 ;; '("\C-cx" delphi-find-current-xdef) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1922 ;; '("\C-cb" delphi-find-current-body) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1923 '("\C-cu" delphi-find-unit) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1924 '("\M-q" delphi-fill-comment) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1925 '("\M-j" delphi-new-comment-line) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1926 ;; Debug bindings: |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1927 (list "\C-c\C-d" delphi-debug-mode-map))) |
25072 | 1928 kmap) |
1929 "Keymap used in Delphi mode.") | |
1930 | |
1931 (defconst delphi-mode-syntax-table (make-syntax-table) | |
1932 "Delphi mode's syntax table. It is just a standard syntax table. | |
1933 This is ok since we do our own keyword/comment/string face coloring.") | |
1934 | |
1935 ;;;###autoload | |
1936 (defun delphi-mode (&optional skip-initial-parsing) | |
1937 "Major mode for editing Delphi code. \\<delphi-mode-map> | |
1938 \\[delphi-tab]\t- Indents the current line for Delphi code. | |
1939 \\[delphi-find-unit]\t- Search for a Delphi source file. | |
1940 \\[delphi-fill-comment]\t- Fill the current comment. | |
1941 \\[delphi-new-comment-line]\t- If in a // comment, do a new comment line. | |
1942 | |
1943 M-x indent-region also works for indenting a whole region. | |
1944 | |
1945 Customization: | |
1946 | |
1947 `delphi-indent-level' (default 3) | |
1948 Indentation of Delphi statements with respect to containing block. | |
1949 `delphi-compound-block-indent' (default 0) | |
1950 Extra indentation for blocks in compound statements. | |
1951 `delphi-case-label-indent' (default 0) | |
1952 Extra indentation for case statement labels. | |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1953 `delphi-tab-always-indents' (default t) |
25072 | 1954 Non-nil means TAB in Delphi mode should always reindent the current line, |
1955 regardless of where in the line point is when the TAB command is used. | |
25317
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1956 `delphi-newline-always-indents' (default t) |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1957 Non-nil means NEWLINE in Delphi mode should always reindent the current |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1958 line, insert a blank line and move to the default indent column of the |
06136c6979f1
checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents:
25161
diff
changeset
|
1959 blank line. |
25072 | 1960 `delphi-search-path' (default .) |
1961 Directories to search when finding external units. | |
1962 `delphi-verbose' (default nil) | |
1963 If true then delphi token processing progress is reported to the user. | |
1964 | |
1965 Coloring: | |
1966 | |
1967 `delphi-comment-face' (default font-lock-comment-face) | |
1968 Face used to color delphi comments. | |
1969 `delphi-string-face' (default font-lock-string-face) | |
1970 Face used to color delphi strings. | |
1971 `delphi-keyword-face' (default font-lock-keyword-face) | |
1972 Face used to color delphi keywords. | |
1973 `delphi-other-face' (default nil) | |
1974 Face used to color everything else. | |
1975 | |
1976 Turning on Delphi mode calls the value of the variable delphi-mode-hook with | |
1977 no args, if that value is non-nil." | |
1978 (interactive) | |
1979 (kill-all-local-variables) | |
1980 (use-local-map delphi-mode-map) | |
1981 (setq major-mode 'delphi-mode) | |
1982 (setq mode-name "Delphi") | |
1983 | |
1984 (setq local-abbrev-table delphi-mode-abbrev-table) | |
1985 (set-syntax-table delphi-mode-syntax-table) | |
1986 | |
1987 ;; Buffer locals: | |
84919
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1988 (mapc #'(lambda (var) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1989 (let ((var-symb (car var)) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1990 (var-val (cadr var))) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1991 (make-local-variable var-symb) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1992 (set var-symb var-val))) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1993 (list '(indent-line-function delphi-indent-line) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1994 '(comment-indent-function delphi-indent-line) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1995 '(case-fold-search t) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1996 '(delphi-progress-last-reported-point nil) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1997 '(delphi-ignore-changes nil) |
73311bfc1e1e
(delphi-search-directory, delphi-find-unit-file, delphi-debug-mode-map,
Juanma Barranquero <lekktu@gmail.com>
parents:
78234
diff
changeset
|
1998 (list 'font-lock-defaults delphi-font-lock-defaults))) |
25072 | 1999 |
2000 ;; We need to keep track of changes to the buffer to determine if we need | |
2001 ;; to retokenize changed text. | |
2002 (add-hook 'after-change-functions 'delphi-after-change nil t) | |
2003 | |
2004 (widen) | |
2005 (unless skip-initial-parsing | |
2006 (delphi-save-excursion | |
2007 (let ((delphi-verbose t)) | |
2008 (delphi-progress-start) | |
2009 (delphi-parse-region (point-min) (point-max)) | |
2010 (delphi-progress-done)))) | |
2011 | |
62772
f2892faa87d4
* progmodes/ada-mode.el (ada-mode):
Lute Kamstra <lute@gnu.org>
parents:
62462
diff
changeset
|
2012 (run-mode-hooks 'delphi-mode-hook)) |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
35624
diff
changeset
|
2013 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
2014 ;; arch-tag: 410e192d-e9b5-4397-ad62-12340fc3fa41 |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
35624
diff
changeset
|
2015 ;;; delphi.el ends here |