Mercurial > emacs
annotate lisp/progmodes/simula.el @ 3771:78c629b32fd9
* configure.in: Move clause for PC-compatible i386 box to the end
of the case statement, to avoid masking configurations below.
* configure.in: Add support for HP/UX versions 7, 8, and 9 on
the HP 68000 machines.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Wed, 16 Jun 1993 21:53:54 +0000 |
parents | 507f64624555 |
children | b26469d5e812 |
rev | line source |
---|---|
805 | 1 ;;; simula.el --- SIMULA 87 code editing commands for Emacs |
2 | |
841 | 3 ;; Copyright (C) 1992 Free Software Foundation, Inc. |
4 | |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
805
diff
changeset
|
5 ;; Author: Hans Henrik Eriksen <hhe@ifi.uio.no> |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
805
diff
changeset
|
6 ;; Maintainer: simula-mode@ifi.uio.no |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
805
diff
changeset
|
7 ;; Version: 0.99 |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
805
diff
changeset
|
8 ;; Adapted-By: ESR |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
805
diff
changeset
|
9 ;; Keywords: languages |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
805
diff
changeset
|
10 |
805 | 11 ;; This file is part of GNU Emacs. |
12 | |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
14 ;; it under the terms of the GNU General Public License as published by | |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
805
diff
changeset
|
15 ;; the Free Software Foundation; either version 1, or (at your option) |
805 | 16 ;; any later version. |
17 | |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
24 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
26 | |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
805
diff
changeset
|
27 ;;; Commentary: |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
805
diff
changeset
|
28 |
2315
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2024
diff
changeset
|
29 ;; A major mode for editing the Simula language. It knows about Simula |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2024
diff
changeset
|
30 ;; syntax and standard indentation commands. It also provides convenient |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2024
diff
changeset
|
31 ;; abbrevs for Simula keywords. |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2024
diff
changeset
|
32 ;; |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2024
diff
changeset
|
33 ;; Hans Henrik Eriksen (the author) may be reached at: |
805 | 34 ;; Institutt for informatikk, |
35 ;; Universitetet i Oslo | |
36 | |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
805
diff
changeset
|
37 ;;; Code: |
805 | 38 |
39 (provide 'simula-mode) | |
40 | |
41 (defconst simula-tab-always-indent nil | |
42 "*Non-nil means TAB in SIMULA mode should always reindent the current line, | |
43 regardless of where in the line point is when the TAB command is used.") | |
44 | |
45 (defconst simula-indent-level 3 | |
46 "*Indentation of SIMULA statements with respect to containing block.") | |
47 | |
48 (defconst simula-substatement-offset 3 | |
49 "*Extra indentation after DO, THEN, ELSE, WHEN and OTHERWISE.") | |
50 | |
51 (defconst simula-continued-statement-offset 3 | |
52 "*Extra indentation for lines not starting a statement or substatement. | |
53 If value is a list, each line in a multipleline continued statement | |
54 will have the car of the list extra indentation with respect to | |
55 the previous line of the statement.") | |
56 | |
57 (defconst simula-label-offset -4711 | |
58 "*Offset of SIMULA label lines relative to usual indentation") | |
59 | |
60 (defconst simula-if-indent '(0 . 0) | |
61 "*Extra indentation of THEN and ELSE with respect to the starting IF. | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
62 Value is a cons cell, the car is extra THEN indentation and the cdr |
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
63 extra ELSE indentation. IF after ELSE is indented as the starting IF.") |
805 | 64 |
65 (defconst simula-inspect-indent '(0 . 0) | |
66 "*Extra indentation of WHEN and OTHERWISE with respect to the | |
67 corresponding INSPECT. Value is a cons cell, the car is | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
68 extra WHEN indentation and the cdr extra OTHERWISE indentation.") |
805 | 69 |
70 (defconst simula-electric-indent nil | |
71 "*If this variable is non-nil, the simula-indent-line function | |
72 will check the previous line to see if it has to be reindented.") | |
73 | |
74 (defconst simula-abbrev-keyword 'upcase | |
75 "*Determine how SIMULA keywords will be expanded. Value is one of | |
76 the symbols upcase, downcase, capitalize, (as in) abbrev-table or | |
77 nil if they should not be changed.") | |
78 | |
79 (defconst simula-abbrev-stdproc 'abbrev-table | |
80 "*Determine how standard SIMULA procedure and class names will be | |
81 expanded. Value is one of the symbols upcase, downcase, capitalize, | |
82 (as in) abbrev-table or nil if they should not be changed.") | |
83 | |
84 (defvar simula-abbrev-file nil | |
85 "*File with abbrev definitions that are merged together with | |
86 the standard abbrev definitions. Please note that the standard | |
87 definitions are required for simula-mode to function correctly.") | |
88 | |
89 (defvar simula-mode-syntax-table nil | |
90 "Syntax table in simula-mode buffers.") | |
91 | |
92 (if simula-mode-syntax-table | |
93 () | |
94 (setq simula-mode-syntax-table (standard-syntax-table)) | |
95 (modify-syntax-entry ?! "<" simula-mode-syntax-table) | |
96 (modify-syntax-entry ?$ "." simula-mode-syntax-table) | |
97 (modify-syntax-entry ?% "." simula-mode-syntax-table) | |
98 (modify-syntax-entry ?' "\"" simula-mode-syntax-table) | |
99 (modify-syntax-entry ?\( "()" simula-mode-syntax-table) | |
100 (modify-syntax-entry ?\) ")(" simula-mode-syntax-table) | |
101 (modify-syntax-entry ?\; ">" simula-mode-syntax-table) | |
102 (modify-syntax-entry ?\[ "." simula-mode-syntax-table) | |
103 (modify-syntax-entry ?\\ "." simula-mode-syntax-table) | |
104 (modify-syntax-entry ?\] "." simula-mode-syntax-table) | |
105 (modify-syntax-entry ?_ "w" simula-mode-syntax-table) | |
106 (modify-syntax-entry ?\| "." simula-mode-syntax-table) | |
107 (modify-syntax-entry ?\{ "." simula-mode-syntax-table) | |
108 (modify-syntax-entry ?\} "." simula-mode-syntax-table)) | |
109 | |
110 (defvar simula-mode-map () | |
111 "Keymap used in simula mode.") | |
112 | |
113 (if simula-mode-map | |
114 () | |
115 (setq simula-mode-map (make-sparse-keymap)) | |
116 (define-key simula-mode-map "\C-c\C-u" 'simula-backward-up-level) | |
117 (define-key simula-mode-map "\C-c\C-p" 'simula-previous-statement) | |
118 (define-key simula-mode-map "\C-c\C-d" 'simula-forward-down-level) | |
119 (define-key simula-mode-map "\C-c\C-n" 'simula-next-statement) | |
120 ;(define-key simula-mode-map "\C-c\C-g" 'simula-goto-definition) | |
121 ;(define-key simula-mode-map "\C-c\C-h" 'simula-standard-help) | |
122 (define-key simula-mode-map "\177" 'backward-delete-char-untabify) | |
123 (define-key simula-mode-map ":" 'simula-electric-label) | |
124 (define-key simula-mode-map "\t" 'simula-indent-command)) | |
125 | |
126 (defvar simula-mode-abbrev-table nil | |
127 "Abbrev table in simula-mode buffers") | |
128 | |
129 | |
130 (defun simula-mode () | |
131 "Major mode for editing SIMULA code. | |
132 \\{simula-mode-map} | |
133 Variables controlling indentation style: | |
134 simula-tab-always-indent | |
135 Non-nil means TAB in SIMULA mode should always reindent the current line, | |
136 regardless of where in the line point is when the TAB command is used. | |
137 simula-indent-level | |
138 Indentation of SIMULA statements with respect to containing block. | |
139 simula-substatement-offset | |
140 Extra indentation after DO, THEN, ELSE, WHEN and OTHERWISE. | |
141 simula-continued-statement-offset 3 | |
142 Extra indentation for lines not starting a statement or substatement, | |
143 e.g. a nested FOR-loop. If value is a list, each line in a multipple- | |
144 line continued statement will have the car of the list extra indentation | |
145 with respect to the previous line of the statement. | |
146 simula-label-offset -4711 | |
147 Offset of SIMULA label lines relative to usual indentation | |
148 simula-if-indent '(0 . 0) | |
149 Extra indentation of THEN and ELSE with respect to the starting IF. | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
150 Value is a cons cell, the car is extra THEN indentation and the cdr |
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
151 extra ELSE indentation. IF after ELSE is indented as the starting IF. |
805 | 152 simula-inspect-indent '(0 . 0) |
153 Extra indentation of WHEN and OTHERWISE with respect to the | |
154 corresponding INSPECT. Value is a cons cell, the car is | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
155 extra WHEN indentation and the cdr extra OTHERWISE indentation. |
805 | 156 simula-electric-indent nil |
157 If this variable non-nil value, simula-indent-line | |
158 will check the previous line to see if it has to be reindented. | |
159 simula-abbrev-keyword 'upcase | |
160 Determine how SIMULA keywords will be expanded. Value is one of | |
161 the symbols upcase, downcase, capitalize, (as in) abbrev-table or | |
162 nil if they should not be changed. | |
163 simula-abbrev-stdproc 'abbrev-table | |
164 Determine how standard SIMULA procedure and class names will be | |
165 expanded. Value is one of the symbols upcase, downcase, capitalize, | |
166 (as in) abbrev-table or nil if they should not be changed. | |
167 | |
168 Turning on SIMULA mode calls the value of the variable simula-mode-hook | |
169 with no arguments, if that value is non-nil | |
170 | |
171 Warning: simula-mode-hook should not read in an abbrev file without calling | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
172 the function simula-install-standard-abbrevs afterwards, preferably not |
805 | 173 at all." |
174 (interactive) | |
175 (kill-all-local-variables) | |
176 (use-local-map simula-mode-map) | |
177 (setq major-mode 'simula-mode) | |
178 (setq mode-name "SIMULA") | |
179 (make-local-variable 'comment-column) | |
180 (setq comment-column 40) | |
181 (make-local-variable 'end-comment-column) | |
182 (setq end-comment-column 75) | |
183 (set-syntax-table simula-mode-syntax-table) | |
184 (make-local-variable 'paragraph-start) | |
185 (setq paragraph-start "^[ \t]*$\\|\\f") | |
186 (make-local-variable 'paragraph-separate) | |
187 (setq paragraph-separate paragraph-start) | |
188 (make-local-variable 'indent-line-function) | |
189 (setq indent-line-function 'simula-indent-line) | |
190 (make-local-variable 'require-final-newline) | |
191 (setq require-final-newline t) | |
192 (make-local-variable 'comment-start) | |
193 (setq comment-start "! ") | |
194 (make-local-variable 'comment-end) | |
195 (setq comment-end " ;") | |
196 (make-local-variable 'comment-start-skip) | |
197 (setq comment-start-skip "!+ *") | |
198 (make-local-variable 'parse-sexp-ignore-comments) | |
199 (setq parse-sexp-ignore-comments nil) | |
200 (make-local-variable 'comment-multi-line) | |
201 (setq comment-multi-line t) | |
202 (if simula-mode-abbrev-table | |
203 () | |
204 (if simula-abbrev-file | |
205 (read-abbrev-file simula-abbrev-file) | |
206 (define-abbrev-table 'simula-mode-abbrev-table ())) | |
207 (let (abbrevs-changed) | |
208 (simula-install-standard-abbrevs))) | |
209 (setq local-abbrev-table simula-mode-abbrev-table) | |
210 (abbrev-mode 1) | |
211 (run-hooks 'simula-mode-hook)) | |
212 | |
213 | |
214 | |
215 (defun simula-indent-line () | |
216 "Indent this line as SIMULA code. If simula-electric-indent | |
217 is non-nil, indent previous line if necessary." | |
218 (let ((origin (- (point-max) (point))) | |
219 (indent (simula-calculate-indent)) | |
220 (case-fold-search t)) | |
221 (unwind-protect | |
222 (progn | |
223 ;; | |
224 ;; manually expand abbrev on last line, if any | |
225 ;; | |
226 (end-of-line 0) | |
227 (expand-abbrev) | |
228 ;; now maybe we should reindent that line | |
229 (if simula-electric-indent | |
230 (progn | |
231 (beginning-of-line) | |
232 (skip-chars-forward " \t\f") | |
233 (if (and | |
234 (looking-at | |
235 "\\(end\\|if\\|then\\|else\\|when\\|otherwise\\)\\>") | |
236 (not (simula-context))) | |
237 ;; yes - reindent | |
238 (let ((post-indent (simula-calculate-indent))) | |
239 (if (eq (current-indentation) post-indent) | |
240 () | |
241 (delete-horizontal-space) | |
242 (indent-to post-indent))))))) | |
243 (goto-char (- (point-max) origin)) | |
244 (if (eq (current-indentation) indent) | |
245 (back-to-indentation) | |
246 (delete-horizontal-space) | |
247 (indent-to indent))))) | |
248 | |
249 | |
250 (defun simula-indent-command (&optional whole-exp) | |
251 "Indent current line as SIMULA code, or insert TAB character. | |
252 If simula-tab-always-indent is non-nil, always indent current line. | |
253 Otherwise, indent only if point is before any non-whitespace | |
254 character on the line. | |
255 | |
256 A numeric argument, regardless of its value, means indent rigidly | |
257 all the lines of the SIMULA statement after point so that this line | |
258 becomes properly indented. | |
259 The relative indentation among the lines of the statement are preserved." | |
260 (interactive "P") | |
261 (let ((case-fold-search t)) | |
262 (if (or whole-exp simula-tab-always-indent | |
263 (save-excursion | |
264 (skip-chars-backward " \t\f") | |
265 (bolp))) | |
266 ;; reindent current line | |
267 (let ((indent (save-excursion | |
268 (beginning-of-line) | |
269 (simula-calculate-indent))) | |
270 (current (current-indentation)) | |
271 (origin (- (point-max) (point))) | |
272 (bol (save-excursion | |
273 (skip-chars-backward " \t\f") | |
274 (bolp))) | |
275 beg end) | |
276 (unwind-protect | |
277 (if (eq current indent) | |
278 (if (save-excursion | |
279 (skip-chars-backward " \t\f") | |
280 (bolp)) | |
281 (back-to-indentation)) | |
282 (beginning-of-line) | |
283 (delete-horizontal-space) | |
284 (indent-to indent)) | |
285 (if (not bol) | |
286 (goto-char (- (point-max) origin)))) | |
287 (setq origin (point)) | |
288 (if whole-exp | |
289 (save-excursion | |
290 (beginning-of-line 2) | |
291 (setq beg (point)) | |
292 (goto-char origin) | |
293 (simula-next-statement 1) | |
294 (setq end (point)) | |
295 (if (and (> end beg) (not (eq indent current))) | |
296 (indent-code-rigidly beg end (- indent current) "%"))))) | |
297 (insert-tab)))) | |
298 | |
299 | |
300 (defun simula-context () | |
301 "Returns value according to position of point inside SIMULA text: | |
302 0 point inside COMMENT | |
303 1 point on SIMULA-compiler directive line | |
304 2 point inside END comment | |
305 3 point inside string | |
306 4 point inside character constant | |
307 nil otherwise." | |
308 ;; first, find out if this is a compiler directive line | |
309 (if (save-excursion | |
310 (beginning-of-line) | |
311 (eq (following-char) ?%)) | |
312 ;; YES - return 1 | |
313 1 | |
314 (save-excursion | |
315 ;; The current line is NOT a compiler directive line. | |
316 ;; Now, the strategy is to search backward to find a semicolon | |
317 ;; that is NOT inside a string. The point after semicolon MUST be | |
318 ;; outside a comment, since semicolons are comment-ending and | |
319 ;; comments are non-recursive. We take advantage of the fact | |
320 ;; that strings MUST end on the same line as they started, so | |
321 ;; that we can easily decide whether we are inside a string or not. | |
322 (let (return-value (origin (point))) | |
323 (skip-chars-backward "^;" (point-min)) | |
324 ;; found semicolon or beginning of buffer | |
325 (let (loopvalue (saved-point origin)) | |
326 (while (and (not (bobp)) | |
327 (if (progn | |
328 (beginning-of-line) | |
329 ;; compiler directive line? If so, cont searching.. | |
330 (eq (following-char) ?%)) | |
331 t | |
332 (while (< (point) saved-point) | |
333 (skip-chars-forward "^;\"'") | |
334 (forward-char 1) | |
335 (cond | |
336 ((eq (preceding-char) ?\;) | |
337 (setq saved-point (point))) | |
338 ((eq (preceding-char) ?\") | |
339 (skip-chars-forward "^\";") | |
340 (if (eq (following-char) ?\;) | |
341 (setq saved-point (point) loopvalue t) | |
342 (forward-char 1))) | |
343 (t | |
344 (if (eq (following-char) ?') | |
345 (forward-char 1)) | |
346 (skip-chars-forward "^';") | |
347 (if (eq (following-char) ?\;) | |
348 (setq saved-point (point) loopvalue t) | |
349 (forward-char 1))))) | |
350 loopvalue)) | |
351 (backward-char 1) | |
352 (skip-chars-backward "^;") | |
353 (setq saved-point (point) loopvalue nil))) | |
354 ;; Now we are CERTAIN that we are outside comments and strings. | |
355 ;; The job now is to search forward again towards the origin | |
356 ;; skipping directives, comments and strings correctly, | |
357 ;; so that we know what context we are in when we find the origin. | |
358 (while (and | |
359 (< (point) origin) | |
360 (re-search-forward | |
361 "\\<end\\>\\|!\\|\"\\|'\\|^%\\|\\<comment\\>" origin 'move)) | |
362 (cond | |
363 ((memq (preceding-char) '(?d ?D)) | |
364 (setq return-value 2) | |
365 (while (and (memq (preceding-char) '(?d ?D)) (not return-value)) | |
366 (while (and (re-search-forward | |
367 ";\\|\\<end\\>\\|\\<else\\>\\|\\<otherwise\\>\\|\\<when\\>\\|^%" | |
368 origin 'move) | |
369 (eq (preceding-char) ?%)) | |
370 (beginning-of-line 2))) | |
371 (if (looking-at "[ \t\n\f]*\\(;\\|\\<end\\>\\|\\<else\\>\\|\\<otherwise\\>\\|\\<when\\>\\)") | |
372 (setq return-value nil))) | |
373 ((memq (preceding-char) '(?! ?t ?T)) | |
374 ; skip comment | |
375 (setq return-value 0) | |
376 (skip-chars-forward "^%;" origin) | |
377 (while (and return-value (< (point) origin)) | |
378 (if (eq (following-char) ?\;) | |
379 (setq return-value nil) | |
380 (if (bolp) | |
381 (beginning-of-line 2) ; skip directive inside comment | |
382 (forward-char 1)) ; or single '%' | |
383 (skip-chars-forward "^%;" origin)))) | |
384 ((eq (preceding-char) ?\") | |
385 (if (not (search-forward "\"" origin 'move)) | |
386 (setq return-value 3))) | |
387 ((eq (preceding-char) ?\') | |
388 (if (or (eq (point) origin) (eobp)) | |
389 (setq return-value 4) | |
390 (forward-char 1) | |
391 (if (not (search-forward "'" origin 'move)) | |
392 (setq return-value 4)))) | |
393 ;; compiler directive line - skip | |
394 (t (beginning-of-line 2)))) | |
395 return-value) | |
396 ))) | |
397 | |
398 | |
399 (defun simula-electric-label () | |
400 "If this is a label that starts the line, reindent the line" | |
401 (interactive) | |
402 (expand-abbrev) | |
403 (insert ?:) | |
404 (let ((origin (- (point-max) (point))) | |
405 (case-fold-search t) | |
406 ;; don't mix a label with an assignment operator := :- | |
407 ;; therefore look at next typed character... | |
2024
357941278904
(simula-electric-label): Handle any event when flushing the display.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
408 (next-char (setq unread-command-events (list (read-event)))) |
805 | 409 (com-char last-command-char)) |
410 (unwind-protect | |
411 ;; Problem: find out if character just read is a command char | |
412 ;; that would insert something after ':' making it a label. | |
413 ;; At least \n, \r (and maybe \t) falls into this category. | |
414 ;; This is a real crock, it depends on traditional keymap | |
415 ;; bindings, that is, printing characters doing self-insert, | |
416 ;; and no other command sequence inserting '-' or '='. | |
417 ;; simula-electric-label can be easily fooled... | |
418 (if (and (not (memq next-char '(?= ?-))) | |
419 (or (memq next-char '(?\n ?\r)) | |
420 (and (eq next-char ?\t) | |
421 simula-tab-always-indent) | |
422 (not (memq (following-char) '(?= ?-)))) | |
423 (not (simula-context)) | |
424 ;; label? | |
425 (progn | |
426 (backward-char 1) | |
427 (skip-chars-backward " \t\f") | |
428 (skip-chars-backward "a-zA-Z0-9_") | |
429 (if (looking-at "virtual\\>") | |
430 nil | |
431 (skip-chars-backward " \t\f") | |
432 (bolp)))) | |
433 (let ((amount (simula-calculate-indent))) | |
434 (delete-horizontal-space) | |
435 (indent-to amount))) | |
436 (goto-char (- (point-max) origin))))) | |
437 | |
438 | |
439 (defun simula-backward-up-level (count) | |
440 "Move backward up COUNT block levels. | |
441 If COUNT is negative, move forward up block level instead" | |
442 (interactive "p") | |
443 (let ((origin (point)) | |
444 (case-fold-search t)) | |
445 (condition-case () | |
446 (if (> count 0) | |
447 (while (> count 0) | |
448 (re-search-backward "\\<begin\\>\\|\\<end\\>") | |
449 (if (not (simula-context)) | |
450 (setq count (if (memq (following-char) '(?b ?B)) | |
451 (1- count) | |
452 (1+ count))))) | |
453 (while (< count 0) | |
454 (re-search-forward "\\<begin\\>\\|\\<end\\>") | |
455 (backward-word 1) | |
456 (if (not (simula-context)) | |
457 (setq count (if (memq (following-char) '(?e ?E)) | |
458 (1+ count) | |
459 (1- count)))) | |
460 (backward-word -1))) | |
461 ;; If block level not found, jump back to origin and signal an error | |
462 (error (progn | |
463 (goto-char origin) | |
464 (error "No higher block level"))) | |
465 (quit (progn | |
466 (goto-char origin) | |
467 (signal 'quit nil)))))) | |
468 | |
469 | |
470 (defun simula-forward-down-level (count) | |
471 "Move forward down COUNT block levels. | |
472 If COUNT is negative, move backward down block level instead" | |
473 (interactive "p") | |
474 ;; When we search for a deeper block level, we must never | |
475 ;; get out of the block where we started -> count >= start-count | |
476 (let ((start-count count) | |
477 (origin (point)) | |
478 (case-fold-search t)) | |
479 (condition-case () | |
480 (if (< count 0) | |
481 (while (< count 0) | |
482 (re-search-backward "\\<begin\\>\\|\\<end\\>") | |
483 (if (not (simula-context)) | |
484 (setq count (if (memq (following-char) '(?e ?E)) | |
485 (1+ count) | |
486 (1- count)))) | |
487 (if (< count start-count) (signal 'error nil))) | |
488 (while (> count 0) | |
489 (re-search-forward "\\<begin\\>\\|\\<end\\>") | |
490 (backward-word 1) | |
491 (if (not (simula-context)) | |
492 (setq count (if (memq (following-char) '(?b ?B)) | |
493 (1- count) | |
494 (1+ count)))) | |
495 (backward-word -1) | |
496 ;; deeper level has to be found within starting block | |
497 (if (> count start-count) (signal 'error nil)))) | |
498 ;; If block level not found, jump back to origin and signal an error | |
499 (error (progn | |
500 (goto-char origin) | |
501 (error "No containing block level"))) | |
502 (quit (progn | |
503 (goto-char origin) | |
504 (signal 'quit nil)))))) | |
505 | |
506 | |
507 (defun simula-previous-statement (count) | |
508 "Move backward COUNT statements. | |
509 If COUNT is negative, move forward instead (simula-next-statement)" | |
510 (interactive "p") | |
511 (if (< count 0) | |
512 (simula-next-statement (- count)) | |
513 (let (status | |
514 (case-fold-search t) | |
515 (origin (point))) | |
516 (condition-case () | |
517 (progn | |
518 (simula-skip-comment-backward) | |
519 (if (memq (preceding-char) '(?n ?N)) | |
520 (progn | |
521 (backward-word 1) | |
522 (if (not (looking-at "\\<begin\\>")) | |
523 (backward-word -1))) | |
524 (if (eq (preceding-char) ?\;) | |
525 (backward-char 1))) | |
526 (while (and (natnump (setq count (1- count))) | |
527 (setq status (simula-search-backward | |
528 ";\\|\\<begin\\>" nil 'move)))) | |
529 (if status | |
530 (progn | |
531 (if (eq (following-char) ?\;) | |
532 (forward-char 1) | |
533 (backward-word -1)))) | |
534 (simula-skip-comment-forward)) | |
535 (error (progn (goto-char origin) | |
536 (error "Incomplete statement (too many ENDs)"))) | |
537 (quit (progn (goto-char origin) (signal 'quit nil))))))) | |
538 | |
539 | |
540 (defun simula-next-statement (count) | |
541 "Move backward COUNT statements. | |
542 If COUNT is negative, move forward instead (simula-next-statement)" | |
543 (interactive "p") | |
544 (if (< count 0) | |
545 (simula-previous-statement (- count)) | |
546 (let (status | |
547 (case-fold-search t) | |
548 (origin (point))) | |
549 (condition-case () | |
550 (progn | |
551 (simula-skip-comment-forward) | |
552 (if (looking-at "\\<end\\>") (forward-word 1)) | |
553 (while (and (natnump (setq count (1- count))) | |
554 (setq status (simula-search-forward | |
555 ";\\|\\<end\\>" (point-max) 'move)))) | |
556 (if (and status (/= (preceding-char) ?\;)) | |
557 (progn | |
558 (backward-word 1) | |
559 (simula-skip-comment-backward)))) | |
560 (error (progn (goto-char origin) | |
561 (error "Incomplete statement (too few ENDs)"))) | |
562 (quit (progn (goto-char origin) (signal 'quit nil))))))) | |
563 | |
564 | |
565 (defun simula-skip-comment-backward () | |
566 "Search towards bob to find first char that is outside a comment" | |
567 (interactive) | |
568 (catch 'simula-out | |
569 (let (context) | |
570 (while t | |
571 (skip-chars-backward " \t\n\f") | |
572 (if (eq (preceding-char) ?\;) | |
573 (save-excursion | |
574 (backward-char 1) | |
575 (setq context (simula-context))) | |
576 (setq context (simula-context))) | |
577 (cond | |
578 ((memq context '(nil 3 4)) | |
579 ;; check to see if we found a label | |
580 (if (and (eq (preceding-char) ?:) | |
581 (not (memq (following-char) '(?- ?=))) | |
582 (save-excursion | |
583 (skip-chars-backward ": \t\fa-zA-Z0-9_") | |
584 (not (looking-at "virtual\\>")))) | |
585 (skip-chars-backward ": \t\fa-zA-Z0-9_") | |
586 (throw 'simula-out nil))) | |
587 ((eq context 0) | |
588 ;; since we are inside a comment, it must start somewhere! | |
589 (while (and (re-search-backward "!\\|\\<comment\\>") | |
590 (memq (simula-context) '(0 1))))) | |
591 ((eq context 1) | |
592 (end-of-line 0) | |
593 (if (bobp) | |
594 (throw 'simula-out nil))) | |
595 ((eq context 2) | |
596 ;; an END-comment must belong to an END | |
597 (re-search-backward "\\<end\\>") | |
598 (forward-word 1) | |
599 (throw 'simula-out nil)) | |
600 ;; should be impossible to get here.. | |
601 ))))) | |
602 | |
603 | |
604 (defun simula-skip-comment-forward () | |
605 "Search towards eob to find first char that is outside a comment" | |
606 ;; this function assumes we start with point .outside a comment | |
607 (interactive) | |
608 (catch 'simula-out | |
609 (while t | |
610 (skip-chars-forward " \t\n\f") | |
611 (cond | |
612 ((looking-at "!\\|\\<comment\\>") | |
613 (search-forward ";" nil 'move)) | |
614 ((and (bolp) (eq (following-char) ?%)) | |
615 (beginning-of-line 2)) | |
616 ((and (looking-at "[a-z0-9_]*[ \t\f]*:[^-=]") | |
617 (not (looking-at "virtual\\>"))) | |
618 (skip-chars-forward "a-zA-Z0-9_ \t\f:")) | |
619 (t | |
620 (throw 'simula-out t)))))) | |
621 | |
622 | |
623 (defun simula-forward-up-level () | |
624 (let ((continue-loop t) | |
625 (origin (point)) | |
626 (case-fold-search t) | |
627 return-value | |
628 temp) | |
629 (while continue-loop | |
630 (if (re-search-backward "\\<begin\\>\\|\\<end\\>" (point-min) 'move) | |
631 (setq temp (simula-context) | |
632 return-value (and (memq (preceding-char) '(?d ?D)) | |
633 (memq temp '(nil 2))) | |
634 continue-loop (and (not return-value) | |
635 (simula-forward-up-level))) | |
636 (setq continue-loop nil))) | |
637 (if return-value | |
638 t | |
639 (goto-char origin) | |
640 nil))) | |
641 | |
642 | |
643 (defun simula-calculate-indent () | |
644 (save-excursion | |
645 (let ((where (simula-context)) | |
646 (origin (point)) | |
647 (indent 0) | |
648 continued | |
649 start-line | |
650 temp | |
651 found-end | |
652 prev-cont) | |
653 (cond | |
654 ((eq where 0) | |
655 ;; | |
656 ;; Comment. | |
657 ;; If comment started on previous non-blank line, indent to the | |
658 ;; column where the comment started, else indent as that line. | |
659 ;; | |
660 (skip-chars-backward " \t\n\f") | |
661 (while (and (not (bolp)) (eq (simula-context) 0)) | |
662 (re-search-backward "^\\|!\\|\\<comment\\>")) | |
663 (skip-chars-forward " \t\n\f") | |
664 (prog1 | |
665 (current-column) | |
666 (goto-char origin))) | |
667 ;; | |
668 ;; Detect missing string delimiters | |
669 ;; | |
670 ((eq where 3) | |
671 (error "Inside string")) | |
672 ((eq where 4) | |
673 (error "Inside character constant")) | |
674 ;; | |
675 ;; check to see if inside ()'s | |
676 ;; | |
677 ((setq temp (simula-inside-parens)) | |
678 temp) | |
679 ;; | |
680 ;; Calculate non-comment indentation | |
681 (t | |
682 ;; first, find out if this line starts with something that needs | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
683 ;; special indentation (END/IF/THEN/ELSE/WHEN/OTHERWISE or label) |
805 | 684 ;; |
685 (skip-chars-forward " \t\f") | |
686 (cond | |
687 ;; | |
688 ;; END | |
689 ;; | |
690 ((looking-at "end\\>") | |
691 (setq indent (- simula-indent-level) | |
692 found-end t)) | |
693 ;; | |
694 ;; IF/THEN/ELSE | |
695 ;; | |
696 ((looking-at "if\\>\\|then\\>\\|else\\>") | |
697 ;; search for the *starting* IF | |
698 (cond | |
699 ((memq (following-char) '(?T ?t)) | |
700 (setq indent (car simula-if-indent))) | |
701 ((memq (following-char) '(?E ?e)) | |
702 (setq indent (cdr simula-if-indent))) | |
703 (t | |
704 (forward-word 1) | |
705 (setq indent 0))) | |
706 (simula-find-if)) | |
707 ;; | |
708 ;; WHEN/OTHERWISE | |
709 ;; | |
710 ((looking-at "when\\>\\|otherwise\\>") | |
711 ;; search for corresponding INSPECT | |
712 (if (memq (following-char) '(?W ?w)) | |
713 (setq indent (car simula-inspect-indent)) | |
714 (setq indent (cdr simula-inspect-indent))) | |
715 (simula-find-inspect)) | |
716 ;; | |
717 ;; label: | |
718 ;; | |
719 ((and (not (looking-at "virtual\\>")) | |
720 (looking-at "[a-z0-9_]*[ \t\f]*:[^-=]")) | |
721 (setq indent simula-label-offset))) | |
722 ;; find line with non-comment text | |
723 (simula-skip-comment-backward) | |
724 (if (and found-end | |
725 (not (eq (preceding-char) ?\;)) | |
726 (if (memq (preceding-char) '(?N ?n)) | |
727 (save-excursion | |
1621
ec2c000b8b69
* bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents:
841
diff
changeset
|
728 (backward-word 1) |
805 | 729 (not (looking-at "begin\\>"))) |
730 t)) | |
731 (progn | |
732 (simula-previous-statement 1) | |
733 (simula-skip-comment-backward))) | |
734 (setq start-line | |
735 (save-excursion (beginning-of-line) (point)) | |
736 ;; - perhaps this is a continued statement | |
737 continued | |
738 (save-excursion | |
739 (and (not (bobp)) | |
740 ;; (not found-end) | |
741 (if (eq (char-syntax (preceding-char)) ?w) | |
742 (progn | |
743 (backward-word 1) | |
744 (not (looking-at | |
745 "begin\\|then\\|else\\|when\\|otherwise\\|do" | |
746 ))) | |
747 (not (memq (preceding-char) '(?: ?\;))))))) | |
748 ;; | |
749 ;; MAIN calculation loop - count BEGIN/DO etc. | |
750 ;; | |
751 (while (not (bolp)) | |
752 (if (re-search-backward | |
753 ";\\|\\<\\(begin\\|end\\|if\\|else\\|then\\|when\\|otherwise\\|do\\)\\>" | |
754 start-line 'move) | |
755 (if (simula-context) | |
756 ();; found something in a comment/string - ignore | |
757 (setq temp (following-char)) | |
758 (cond | |
759 ((eq temp ?\;) | |
760 (simula-previous-statement 1)) | |
761 ((looking-at "begin\\>") | |
762 (setq indent (+ indent simula-indent-level))) | |
763 ((looking-at "end\\>") | |
764 (forward-word 1) | |
765 (simula-previous-statement 1)) | |
766 ((looking-at "do\\>") | |
767 (setq indent (+ indent simula-substatement-offset)) | |
768 (simula-find-do-match)) | |
769 ((looking-at "\\(if\\|then\\|else\\)\\>") | |
770 (if (memq temp '(?I ?i)) | |
771 (forward-word 1) | |
772 (setq indent (+ indent | |
773 simula-substatement-offset | |
774 (if (memq temp '(?T ?t)) | |
775 (car simula-if-indent) | |
776 (cdr simula-if-indent))))) | |
777 (simula-find-if)) | |
778 ((looking-at "\\<when\\>\\|\\<otherwise\\>") | |
779 (setq indent (+ indent | |
780 simula-substatement-offset | |
781 (if (memq temp '(?W ?w)) | |
782 (car simula-if-indent) | |
783 (cdr simula-if-indent)))) | |
784 (simula-find-inspect))) | |
785 ;; found the start of a [sub]statement | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
786 ;; add indentation for continued statement |
805 | 787 (if continued |
788 (setq indent | |
789 (+ indent | |
790 (if (listp simula-continued-statement-offset) | |
791 (car simula-continued-statement-offset) | |
792 simula-continued-statement-offset)))) | |
793 (setq start-line | |
794 (save-excursion (beginning-of-line) (point)) | |
795 continued nil)) | |
796 ;; search failed .. point is at beginning of line | |
797 ;; determine if we should continue searching | |
798 ;; (at or before comment or label) | |
799 ;; temp = t means finished | |
800 (setq temp | |
801 (and (not (simula-context)) | |
802 (save-excursion | |
803 (skip-chars-forward " \t\f") | |
804 (or (looking-at "virtual") | |
805 (not | |
806 (looking-at | |
807 "!\\|comment\\>\\|[a-z0-9_]*[ \t\f]*:[^-=]"))))) | |
808 prev-cont continued) | |
809 ;; if we are finished, find current line's indentation | |
810 (if temp | |
811 (setq indent (+ indent (current-indentation)))) | |
812 ;; find next line with non-comment SIMULA text | |
813 ;; maybe indent extra if statement continues | |
814 (simula-skip-comment-backward) | |
815 (setq continued | |
816 (and (not (bobp)) | |
817 (if (eq (char-syntax (preceding-char)) ?w) | |
818 (save-excursion | |
819 (backward-word 1) | |
820 (not (looking-at | |
821 "begin\\|then\\|else\\|when\\|otherwise\\|do"))) | |
822 (not (memq (preceding-char) '(?: ?\;)))))) | |
823 ;; if we the state of the continued-variable | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
824 ;; changed, add indentation for continued statement |
805 | 825 (if (or (and prev-cont (not continued)) |
826 (and continued | |
827 (listp simula-continued-statement-offset))) | |
828 (setq indent | |
829 (+ indent | |
830 (if (listp simula-continued-statement-offset) | |
831 (car simula-continued-statement-offset) | |
832 simula-continued-statement-offset)))) | |
833 ;; while ends if point is at beginning of line at loop test | |
834 (if (not temp) | |
835 (setq start-line (save-excursion (beginning-of-line) (point))) | |
836 (beginning-of-line)))) | |
837 ;; | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
838 ;; return indentation |
805 | 839 ;; |
840 indent))))) | |
841 | |
842 | |
843 (defun simula-find-if () | |
844 "Find starting IF of a IF-THEN[-ELSE[-IF-THEN...]] statement" | |
845 (catch 'simula-out | |
846 (while t | |
847 (if (and (simula-search-backward "\\<if\\>\\|;\\|\\<begin\\>"nil t) | |
848 (memq (following-char) '(?I ?i))) | |
849 (save-excursion | |
850 ;; | |
851 ;; find out if this IF was really the start of the IF statement | |
852 ;; | |
853 (simula-skip-comment-backward) | |
854 (if (and (eq (char-syntax (preceding-char)) ?w) | |
855 (progn | |
856 (backward-word 1) | |
857 (looking-at "else\\>"))) | |
858 () | |
859 (throw 'simula-out t))) | |
860 (if (not (looking-at "\\<if\\>")) | |
861 (error "Missing IF or misplaced BEGIN or ';' (can't find IF)") | |
862 ;; | |
863 ;; we were at the starting IF in the first place.. | |
864 ;; | |
865 (throw 'simula-out t)))))) | |
866 | |
867 | |
868 (defun simula-find-inspect () | |
869 "Find INSPECT matching WHEN or OTHERWISE" | |
870 (catch 'simula-out | |
871 (let ((level 0)) | |
872 ;; | |
873 ;; INSPECTs can be nested, have to find the corresponding one | |
874 ;; | |
875 (while t | |
876 (if (and (simula-search-backward "\\<inspect\\>\\|\\<otherwise\\>\\|;" | |
877 nil t) | |
878 (/= (following-char) ?\;)) | |
879 (if (memq (following-char) '(?O ?o)) | |
880 (setq level (1+ level)) | |
881 (if (zerop level) | |
882 (throw 'simula-out t) | |
883 (setq level (1- level)))) | |
884 (error "Missing INSPECT or misplaced ';' (can't find INSPECT)")))))) | |
885 | |
886 | |
887 (defun simula-find-do-match () | |
888 "Find keyword matching DO: FOR, WHILE, INSPECT or WHEN" | |
889 (while (and (re-search-backward | |
890 "\\<\\(do\\|for\\|while\\|inspect\\|when\\|end\\|begin\\)\\>\\|;" | |
891 nil 'move) | |
892 (simula-context))) | |
893 (if (and (looking-at "\\<\\(for\\|while\\|inspect\\|when\\)\\>") | |
894 (not (simula-context))) | |
895 () ;; found match | |
896 (error "No matching FOR, WHILE or INSPECT for DO, or misplaced ';'"))) | |
897 | |
898 | |
899 (defun simula-inside-parens () | |
900 "Return position after '(' on line if inside parentheses, nil otherwise." | |
901 (save-excursion | |
902 (let ((parlevel 0)) | |
903 (catch 'simula-out | |
904 (while t | |
905 (if (re-search-backward "(\\|)\\|;" nil t) | |
906 (if (eq (simula-context) nil) | |
907 ;; found something - check it out | |
908 (cond | |
909 ((eq (following-char) ?\;) | |
910 (if (zerop parlevel) | |
911 (throw 'simula-out nil) | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
912 (error "Parenthesis mismatch or misplaced ';'"))) |
805 | 913 ((eq (following-char) ?\() |
914 (if (zerop parlevel) | |
915 (throw 'simula-out (1+ (current-column))) | |
916 (setq parlevel (1- parlevel)))) | |
917 (t (setq parlevel (1+ parlevel)))) | |
918 );; nothing - inside comment or string | |
919 ;; search failed | |
920 (throw 'simula-out nil))))))) | |
921 | |
922 | |
923 (defun simula-goto-definition () | |
924 "Goto point of definition of variable, procedure or class." | |
925 (interactive)) | |
926 | |
927 | |
928 (defun simula-expand-stdproc () | |
929 (if (or (not simula-abbrev-stdproc) (simula-context)) | |
930 (unexpand-abbrev) | |
931 (cond | |
932 ((eq simula-abbrev-stdproc 'upcase) (upcase-word -1)) | |
933 ((eq simula-abbrev-stdproc 'downcase) (downcase-word -1)) | |
934 ((eq simula-abbrev-stdproc 'capitalize) (capitalize-word -1))))) | |
935 | |
936 | |
937 (defun simula-expand-keyword () | |
938 (if (or (not simula-abbrev-keyword) (simula-context)) | |
939 (unexpand-abbrev) | |
940 (cond | |
941 ((eq simula-abbrev-keyword 'upcase) (upcase-word -1)) | |
942 ((eq simula-abbrev-keyword 'downcase) (downcase-word -1)) | |
943 ((eq simula-abbrev-keyword 'capitalize) (capitalize-word -1))))) | |
944 | |
945 | |
946 (defun simula-electric-keyword () | |
947 "Expand SIMULA keyword. If it starts the line, reindent." | |
948 ;; redisplay | |
949 (let ((show-char (eq this-command 'self-insert-command))) | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
950 ;; If the abbrev expansion results in reindentation, the user may have |
805 | 951 ;; to wait some time before the character he typed is displayed |
952 ;; (the char causing the expansion is inserted AFTER the hook function | |
953 ;; is called). This is annoying in case of normal characters. | |
954 ;; However, if the user pressed a key bound to newline, it is better | |
955 ;; to have the line inserted after the begin-end match. | |
956 (if show-char | |
957 (progn | |
958 (insert-char last-command-char 1) | |
959 (sit-for 0) | |
960 (backward-char 1))) | |
961 (if (let ((where (simula-context)) | |
962 (case-fold-search t)) | |
963 (if where | |
964 (if (and (eq where 2) (eq (char-syntax (preceding-char)) ?w)) | |
965 (save-excursion | |
966 (backward-word 1) | |
967 (not (looking-at "end\\>")))))) | |
968 (unexpand-abbrev) | |
969 (cond | |
970 ((not simula-abbrev-keyword) (unexpand-abbrev)) | |
971 ((eq simula-abbrev-keyword 'upcase) (upcase-word -1)) | |
972 ((eq simula-abbrev-keyword 'downcase) (downcase-word -1)) | |
973 ((eq simula-abbrev-keyword 'capitalize) (capitalize-word -1))) | |
974 (let ((pos (- (point-max) (point))) | |
975 (case-fold-search t) | |
976 null) | |
977 (condition-case null | |
978 (progn | |
979 ;; check if the expanded word is on the beginning of the line. | |
980 (if (and (eq (char-syntax (preceding-char)) ?w) | |
981 (progn | |
982 (backward-word 1) | |
983 (if (looking-at "end\\>") | |
984 (save-excursion | |
985 (simula-backward-up-level 1) | |
986 (if (pos-visible-in-window-p) | |
987 (sit-for 1) | |
988 (message | |
989 (concat "Matches " | |
990 (buffer-substring | |
991 (point) | |
992 (+ (point) (window-width)))))))) | |
993 (skip-chars-backward " \t\f") | |
994 (bolp))) | |
995 (let ((indent (simula-calculate-indent))) | |
996 (if (eq indent (current-indentation)) | |
997 () | |
998 (delete-horizontal-space) | |
999 (indent-to indent))) | |
1000 (skip-chars-forward " \t\f")) | |
1001 ;; check for END - blow whistles and ring bells | |
1002 | |
1003 (goto-char (- (point-max) pos)) | |
1004 (if show-char | |
1005 (delete-char 1))) | |
1006 (quit (goto-char (- (point-max) pos)))))))) | |
1007 | |
1008 | |
1009 (defun simula-search-backward (string &optional limit move) | |
1010 (setq string (concat string "\\|\\<end\\>")) | |
1011 (let (level) | |
1012 (catch 'simula-out | |
1013 (while (re-search-backward string limit move) | |
1014 (if (simula-context) | |
1015 () | |
1016 (if (looking-at "\\<end\\>") | |
1017 (progn | |
1018 (setq level 0) | |
1019 (while (natnump level) | |
1020 (re-search-backward "\\<begin\\>\\|\\<end\\>") | |
1021 (if (simula-context) | |
1022 () | |
1023 (setq level (if (memq (following-char) '(?b ?B)) | |
1024 (1- level) | |
1025 (1+ level)))))) | |
1026 (throw 'simula-out t))))))) | |
1027 | |
1028 | |
1029 (defun simula-search-forward (string &optional limit move) | |
1030 (setq string (concat string "\\|\\<begin\\>")) | |
1031 (let (level) | |
1032 (catch 'exit | |
1033 (while (re-search-forward string limit move) | |
1034 (goto-char (match-beginning 0)) | |
1035 (if (simula-context) | |
1036 (goto-char (1- (match-end 0))) | |
1037 (if (looking-at "\\<begin\\>") | |
1038 (progn | |
1039 (goto-char (1- (match-end 0))) | |
1040 (setq level 0) | |
1041 (while (natnump level) | |
1042 (re-search-forward "\\<begin\\>\\|\\<end\\>") | |
1043 (backward-word 1) | |
1044 (if (not (simula-context)) | |
1045 (setq level (if (memq (following-char) '(?e ?E)) | |
1046 (1- level) | |
1047 (1+ level)))) | |
1048 (backward-word -1))) | |
1049 (goto-char (1- (match-end 0))) | |
1050 (throw 'exit t))))))) | |
1051 | |
1052 | |
1053 (defun simula-install-standard-abbrevs () | |
1054 "Define Simula keywords, standard procedures and classes in | |
1055 local abbrev table." | |
1056 ;; procedure and class names are as of the SIMULA 87 standard. | |
1057 (interactive) | |
1058 (mapcar (function (lambda (args) | |
1059 (apply 'define-abbrev simula-mode-abbrev-table args))) | |
1060 '(("abs" "Abs" simula-expand-stdproc) | |
1061 ("accum" "Accum" simula-expand-stdproc) | |
1062 ("activate" "ACTIVATE" simula-expand-keyword) | |
1063 ("addepsilon" "AddEpsilon" simula-expand-stdproc) | |
1064 ("after" "AFTER" simula-expand-keyword) | |
1065 ("and" "AND" simula-expand-keyword) | |
1066 ("arccos" "ArcCos" simula-expand-stdproc) | |
1067 ("arcsin" "ArcSin" simula-expand-stdproc) | |
1068 ("arctan" "ArcTan" simula-expand-stdproc) | |
1069 ("arctan2" "ArcTan2" simula-expand-stdproc) | |
1070 ("array" "ARRAY" simula-expand-keyword) | |
1071 ("at" "AT" simula-expand-keyword) | |
1072 ("before" "BEFORE" simula-expand-keyword) | |
1073 ("begin" "BEGIN" simula-expand-keyword) | |
1074 ("blanks" "Blanks" simula-expand-stdproc) | |
1075 ("boolean" "BOOLEAN" simula-expand-keyword) | |
1076 ("breakoutimage" "BreakOutImage" simula-expand-stdproc) | |
1077 ("bytefile" "ByteFile" simula-expand-stdproc) | |
1078 ("call" "Call" simula-expand-stdproc) | |
1079 ("cancel" "Cancel" simula-expand-stdproc) | |
1080 ("cardinal" "Cardinal" simula-expand-stdproc) | |
1081 ("char" "Char" simula-expand-stdproc) | |
1082 ("character" "CHARACTER" simula-expand-keyword) | |
1083 ("checkpoint" "CheckPoint" simula-expand-stdproc) | |
1084 ("class" "CLASS" simula-expand-keyword) | |
1085 ("clear" "Clear" simula-expand-stdproc) | |
1086 ("clocktime" "ClockTime" simula-expand-stdproc) | |
1087 ("close" "Close" simula-expand-stdproc) | |
1088 ("comment" "COMMENT" simula-expand-keyword) | |
1089 ("constant" "Constant" simula-expand-stdproc) | |
1090 ("copy" "Copy" simula-expand-stdproc) | |
1091 ("cos" "Cos" simula-expand-stdproc) | |
1092 ("cosh" "CosH" simula-expand-stdproc) | |
1093 ("cotan" "CoTan" simula-expand-stdproc) | |
1094 ("cputime" "CpuTime" simula-expand-stdproc) | |
1095 ("current" "Current" simula-expand-stdproc) | |
1096 ("datetime" "DateTime" simula-expand-stdproc) | |
1097 ("decimalmark" "DecimalMark" simula-expand-stdproc) | |
1098 ("delay" "DELAY" simula-expand-keyword) | |
1099 ("deleteimage" "DeleteImage" simula-expand-stdproc) | |
1100 ("detach" "Detach" simula-expand-stdproc) | |
1101 ("digit" "Digit" simula-expand-stdproc) | |
1102 ("directbytefile" "DirectByteFile" simula-expand-stdproc) | |
1103 ("directfile" "DirectFile" simula-expand-stdproc) | |
1104 ("discrete" "Discrete" simula-expand-stdproc) | |
1105 ("do" "DO" simula-expand-keyword) | |
1106 ("downcase" "Downcase" simula-expand-stdproc) | |
1107 ("draw" "Draw" simula-expand-stdproc) | |
1108 ("eject" "Eject" simula-expand-stdproc) | |
1109 ("else" "ELSE" simula-electric-keyword) | |
1110 ("empty" "Empty" simula-expand-stdproc) | |
1111 ("end" "END" simula-electric-keyword) | |
1112 ("endfile" "Endfile" simula-expand-stdproc) | |
1113 ("entier" "Entier" simula-expand-stdproc) | |
1114 ("eq" "EQ" simula-expand-keyword) | |
1115 ("eqv" "EQV" simula-expand-keyword) | |
1116 ("erlang" "Erlang" simula-expand-stdproc) | |
1117 ("error" "Error" simula-expand-stdproc) | |
1118 ("evtime" "EvTime" simula-expand-stdproc) | |
1119 ("exp" "Exp" simula-expand-stdproc) | |
1120 ("external" "EXTERNAL" simula-expand-keyword) | |
1121 ("false" "FALSE" simula-expand-keyword) | |
1122 ("field" "Field" simula-expand-stdproc) | |
1123 ("file" "File" simula-expand-stdproc) | |
1124 ("first" "First" simula-expand-stdproc) | |
1125 ("follow" "Follow" simula-expand-stdproc) | |
1126 ("for" "FOR" simula-expand-keyword) | |
1127 ("ge" "GE" simula-expand-keyword) | |
1128 ("getchar" "GetChar" simula-expand-stdproc) | |
1129 ("getfrac" "GetFrac" simula-expand-stdproc) | |
1130 ("getint" "GetInt" simula-expand-stdproc) | |
1131 ("getreal" "GetReal" simula-expand-stdproc) | |
1132 ("go" "GO" simula-expand-keyword) | |
1133 ("goto" "GOTO" simula-expand-keyword) | |
1134 ("gt" "GT" simula-expand-keyword) | |
1135 ("head" "Head" simula-expand-stdproc) | |
1136 ("hidden" "HIDDEN" simula-expand-keyword) | |
1137 ("histd" "HistD" simula-expand-stdproc) | |
1138 ("histo" "Histo" simula-expand-stdproc) | |
1139 ("hold" "Hold" simula-expand-stdproc) | |
1140 ("idle" "Idle" simula-expand-stdproc) | |
1141 ("if" "IF" simula-expand-keyword) | |
1142 ("image" "Image" simula-expand-stdproc) | |
1143 ("imagefile" "ImageFile" simula-expand-stdproc) | |
1144 ("imp" "IMP" simula-expand-keyword) | |
1145 ("in" "IN" simula-expand-keyword) | |
1146 ("inbyte" "InByte" simula-expand-stdproc) | |
1147 ("inbytefile" "InByteFile" simula-expand-stdproc) | |
1148 ("inchar" "InChar" simula-expand-stdproc) | |
1149 ("infile" "InFile" simula-expand-stdproc) | |
1150 ("infrac" "InFrac" simula-expand-stdproc) | |
1151 ("inimage" "InImage" simula-expand-stdproc) | |
1152 ("inint" "InInt" simula-expand-stdproc) | |
1153 ("inner" "INNER" simula-expand-keyword) | |
1154 ("inreal" "InReal" simula-expand-stdproc) | |
1155 ("inrecord" "InRecord" simula-expand-stdproc) | |
1156 ("inspect" "INSPECT" simula-expand-keyword) | |
1157 ("integer" "INTEGER" simula-expand-keyword) | |
1158 ("intext" "InText" simula-expand-stdproc) | |
1159 ("into" "Into" simula-expand-stdproc) | |
1160 ("is" "IS" simula-expand-keyword) | |
1161 ("isochar" "ISOChar" simula-expand-stdproc) | |
1162 ("isopen" "IsOpen" simula-expand-stdproc) | |
1163 ("isorank" "ISORank" simula-expand-stdproc) | |
1164 ("label" "LABEL" simula-expand-keyword) | |
1165 ("last" "Last" simula-expand-stdproc) | |
1166 ("lastitem" "LastItem" simula-expand-stdproc) | |
1167 ("lastloc" "LastLoc" simula-expand-stdproc) | |
1168 ("le" "LE" simula-expand-keyword) | |
1169 ("length" "Length" simula-expand-stdproc) | |
1170 ("letter" "Letter" simula-expand-stdproc) | |
1171 ("line" "Line" simula-expand-stdproc) | |
1172 ("linear" "Linear" simula-expand-stdproc) | |
1173 ("linesperpage" "LinesPerPage" simula-expand-stdproc) | |
1174 ("link" "Link" simula-expand-stdproc) | |
1175 ("linkage" "Linkage" simula-expand-stdproc) | |
1176 ("ln" "Ln" simula-expand-stdproc) | |
1177 ("locate" "Locate" simula-expand-stdproc) | |
1178 ("location" "Location" simula-expand-stdproc) | |
1179 ("lock" "Lock" simula-expand-stdproc) | |
1180 ("locked" "Locked" simula-expand-stdproc) | |
1181 ("log10" "Log10" simula-expand-stdproc) | |
1182 ("long" "LONG" simula-expand-keyword) | |
1183 ("lowcase" "LowCase" simula-expand-stdproc) | |
1184 ("lowerbound" "LowerBound" simula-expand-stdproc) | |
1185 ("lowten" "LowTen" simula-expand-stdproc) | |
1186 ("lt" "LT" simula-expand-keyword) | |
1187 ("main" "Main" simula-expand-stdproc) | |
1188 ("max" "Max" simula-expand-stdproc) | |
1189 ("maxint" "MaxInt" simula-expand-stdproc) | |
1190 ("maxlongreal" "MaxLongReal" simula-expand-stdproc) | |
1191 ("maxloc" "MaxLoc" simula-expand-stdproc) | |
1192 ("maxrank" "MaxRank" simula-expand-stdproc) | |
1193 ("maxreal" "MaxReal" simula-expand-stdproc) | |
1194 ("min" "Min" simula-expand-stdproc) | |
1195 ("minint" "MinInt" simula-expand-stdproc) | |
1196 ("minlongreal" "MinLongReal" simula-expand-stdproc) | |
1197 ("minrank" "MinRank" simula-expand-stdproc) | |
1198 ("minreal" "MinReal" simula-expand-stdproc) | |
1199 ("mod" "Mod" simula-expand-stdproc) | |
1200 ("more" "More" simula-expand-stdproc) | |
1201 ("name" "NAME" simula-expand-keyword) | |
1202 ("ne" "NE" simula-expand-keyword) | |
1203 ("negexp" "NegExp" simula-expand-stdproc) | |
1204 ("new" "NEW" simula-expand-keyword) | |
1205 ("nextev" "NextEv" simula-expand-stdproc) | |
1206 ("none" "NONE" simula-expand-keyword) | |
1207 ("normal" "Normal" simula-expand-stdproc) | |
1208 ("not" "NOT" simula-expand-keyword) | |
1209 ("notext" "NOTEXT" simula-expand-keyword) | |
1210 ("open" "Open" simula-expand-stdproc) | |
1211 ("or" "OR" simula-expand-keyword) | |
1212 ("otherwise" "OTHERWISE" simula-electric-keyword) | |
1213 ("out" "Out" simula-expand-stdproc) | |
1214 ("outbyte" "OutByte" simula-expand-stdproc) | |
1215 ("outbytefile" "OutByteFile" simula-expand-stdproc) | |
1216 ("outchar" "OutChar" simula-expand-stdproc) | |
1217 ("outfile" "OutFile" simula-expand-stdproc) | |
1218 ("outfix" "OutFix" simula-expand-stdproc) | |
1219 ("outfrac" "OutFrac" simula-expand-stdproc) | |
1220 ("outimage" "OutImage" simula-expand-stdproc) | |
1221 ("outint" "OutInt" simula-expand-stdproc) | |
1222 ("outreal" "OutReal" simula-expand-stdproc) | |
1223 ("outrecord" "OutRecord" simula-expand-stdproc) | |
1224 ("outtext" "OutText" simula-expand-stdproc) | |
1225 ("page" "Page" simula-expand-stdproc) | |
1226 ("passivate" "Passivate" simula-expand-stdproc) | |
1227 ("poisson" "Poisson" simula-expand-stdproc) | |
1228 ("pos" "Pos" simula-expand-stdproc) | |
1229 ("precede" "Precede" simula-expand-stdproc) | |
1230 ("pred" "Pred" simula-expand-stdproc) | |
1231 ("prev" "Prev" simula-expand-stdproc) | |
1232 ("printfile" "PrintFile" simula-expand-stdproc) | |
1233 ("prior" "PRIOR" simula-expand-keyword) | |
1234 ("procedure" "PROCEDURE" simula-expand-keyword) | |
1235 ("process" "Process" simula-expand-stdproc) | |
1236 ("protected" "PROTECTED" simula-expand-keyword) | |
1237 ("putchar" "PutChar" simula-expand-stdproc) | |
1238 ("putfix" "PutFix" simula-expand-stdproc) | |
1239 ("putfrac" "PutFrac" simula-expand-stdproc) | |
1240 ("putint" "PutInt" simula-expand-stdproc) | |
1241 ("putreal" "PutReal" simula-expand-stdproc) | |
1242 ("qua" "QUA" simula-expand-keyword) | |
1243 ("randint" "RandInt" simula-expand-stdproc) | |
1244 ("rank" "Rank" simula-expand-stdproc) | |
1245 ("reactivate" "REACTIVATE" simula-expand-keyword) | |
1246 ("real" "REAL" simula-expand-keyword) | |
1247 ("ref" "REF" simula-expand-keyword) | |
1248 ("resume" "Resume" simula-expand-stdproc) | |
1249 ("setaccess" "SetAccess" simula-expand-stdproc) | |
1250 ("setpos" "SetPos" simula-expand-stdproc) | |
1251 ("short" "SHORT" simula-expand-keyword) | |
1252 ("sign" "Sign" simula-expand-stdproc) | |
1253 ("simset" "SimSet" simula-expand-stdproc) | |
1254 ("simulaid" "SimulaId" simula-expand-stdproc) | |
1255 ("simulation" "Simulation" simula-expand-stdproc) | |
1256 ("sin" "Sin" simula-expand-stdproc) | |
1257 ("sinh" "SinH" simula-expand-stdproc) | |
1258 ("sourceline" "SourceLine" simula-expand-stdproc) | |
1259 ("spacing" "Spacing" simula-expand-stdproc) | |
1260 ("sqrt" "Sqrt" simula-expand-stdproc) | |
1261 ("start" "Start" simula-expand-stdproc) | |
1262 ("step" "STEP" simula-expand-keyword) | |
1263 ("strip" "Strip" simula-expand-stdproc) | |
1264 ("sub" "Sub" simula-expand-stdproc) | |
1265 ("subepsilon" "SubEpsilon" simula-expand-stdproc) | |
1266 ("suc" "Suc" simula-expand-stdproc) | |
1267 ("switch" "SWITCH" simula-expand-keyword) | |
1268 ("sysin" "SysIn" simula-expand-stdproc) | |
1269 ("sysout" "SysOut" simula-expand-stdproc) | |
1270 ("tan" "Tan" simula-expand-stdproc) | |
1271 ("tanh" "TanH" simula-expand-stdproc) | |
1272 ("terminate_program" "Terminate_Program" simula-expand-stdproc) | |
1273 ("terminated" "Terminated" simula-expand-stdproc) | |
1274 ("text" "TEXT" simula-expand-keyword) | |
1275 ("then" "THEN" simula-electric-keyword) | |
1276 ("this" "THIS" simula-expand-keyword) | |
1277 ("time" "Time" simula-expand-stdproc) | |
1278 ("to" "TO" simula-expand-keyword) | |
1279 ("true" "TRUE" simula-expand-keyword) | |
1280 ("uniform" "Uniform" simula-expand-stdproc) | |
1281 ("unlock" "Unlock" simula-expand-stdproc) | |
1282 ("until" "UNTIL" simula-expand-keyword) | |
1283 ("upcase" "Upcase" simula-expand-stdproc) | |
1284 ("upperbound" "UpperBound" simula-expand-stdproc) | |
1285 ("value" "VALUE" simula-expand-keyword) | |
1286 ("virtual" "VIRTUAL" simula-expand-keyword) | |
1287 ("wait" "Wait" simula-expand-stdproc) | |
1288 ("when" "WHEN" simula-electric-keyword) | |
1289 ("while" "WHILE" simula-expand-keyword)))) | |
1290 | |
1291 ;;; simula.el ends here |