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