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