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