Mercurial > emacs
annotate lisp/progmodes/simula.el @ 5020:94de08fd8a7c
(Fnext_single_property_change): Fix missing \n\.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Mon, 15 Nov 1993 06:41:45 +0000 |
| parents | c791d8c3bdec |
| children | 67b7d1ea7b2e |
| 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 | |
| 24 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
| 25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 26 | |
|
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
805
diff
changeset
|
27 ;;; Commentary: |
|
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
805
diff
changeset
|
28 |
|
2315
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2024
diff
changeset
|
29 ;; A major mode for editing the Simula language. It knows about Simula |
|
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2024
diff
changeset
|
30 ;; syntax and standard indentation commands. It also provides convenient |
|
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2024
diff
changeset
|
31 ;; abbrevs for Simula keywords. |
|
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2024
diff
changeset
|
32 ;; |
|
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2024
diff
changeset
|
33 ;; Hans Henrik Eriksen (the author) may be reached at: |
| 805 | 34 ;; Institutt for informatikk, |
| 35 ;; Universitetet i Oslo | |
| 36 | |
|
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
805
diff
changeset
|
37 ;;; Code: |
| 805 | 38 |
| 39 (provide 'simula-mode) | |
| 40 | |
| 41 (defconst simula-tab-always-indent nil | |
| 4664 | 42 "*Non-nil means TAB in SIMULA mode should always reindent the current line. |
| 43 Otherwise TAB indents only when point is within | |
| 44 the run of whitespace at the beginning of the line.") | |
| 805 | 45 |
| 46 (defconst simula-indent-level 3 | |
| 47 "*Indentation of SIMULA statements with respect to containing block.") | |
| 48 | |
| 49 (defconst simula-substatement-offset 3 | |
| 50 "*Extra indentation after DO, THEN, ELSE, WHEN and OTHERWISE.") | |
| 51 | |
| 52 (defconst simula-continued-statement-offset 3 | |
| 53 "*Extra indentation for lines not starting a statement or substatement. | |
| 54 If value is a list, each line in a multipleline continued statement | |
| 55 will have the car of the list extra indentation with respect to | |
| 56 the previous line of the statement.") | |
| 57 | |
| 58 (defconst simula-label-offset -4711 | |
| 4664 | 59 "*Offset of SIMULA label lines relative to usual indentation.") |
| 805 | 60 |
| 61 (defconst simula-if-indent '(0 . 0) | |
| 62 "*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
|
63 Value is a cons cell, the car is extra THEN indentation and the cdr |
| 4664 | 64 extra ELSE indentation. IF after ELSE is indented as the starting IF.") |
| 805 | 65 |
| 66 (defconst simula-inspect-indent '(0 . 0) | |
| 4664 | 67 "*Extra indentation of WHEN and OTHERWISE with respect to the INSPECT. |
| 68 Value is a cons cell, the car is extra WHEN indentation | |
| 69 and the cdr extra OTHERWISE indentation.") | |
| 805 | 70 |
| 71 (defconst simula-electric-indent nil | |
| 4664 | 72 "*Non-nil means `simula-indent-line' function may reindent previous line.") |
| 805 | 73 |
| 74 (defconst simula-abbrev-keyword 'upcase | |
| 4664 | 75 "*Specify how to convert case for SIMULA keywords. |
| 76 Value is one of the symbols `upcase', `downcase', `capitalize', | |
| 77 (as in) `abbrev-table' or nil if they should not be changed.") | |
| 805 | 78 |
| 79 (defconst simula-abbrev-stdproc 'abbrev-table | |
| 4664 | 80 "*Specify how to convert case for standard SIMULA procedure and class names. |
| 81 Value is one of the symbols `upcase', `downcase', `capitalize', | |
| 82 (as in) `abbrev-table', or nil if they should not be changed.") | |
| 805 | 83 |
| 84 (defvar simula-abbrev-file nil | |
| 4664 | 85 "*File with extra abbrev definitions for use in SIMULA mode. |
| 86 These are used together with the standard abbrev definitions for SIMULA. | |
| 87 Please note that the standard definitions are required | |
| 88 for SIMULA mode to function correctly.") | |
| 805 | 89 |
| 90 (defvar simula-mode-syntax-table nil | |
| 4664 | 91 "Syntax table in SIMULA mode buffers.") |
| 805 | 92 |
| 93 (if simula-mode-syntax-table | |
| 94 () | |
| 4664 | 95 (setq simula-mode-syntax-table (copy-syntax-table (standard-syntax-table))) |
| 805 | 96 (modify-syntax-entry ?! "<" simula-mode-syntax-table) |
| 97 (modify-syntax-entry ?$ "." simula-mode-syntax-table) | |
| 98 (modify-syntax-entry ?% "." simula-mode-syntax-table) | |
| 99 (modify-syntax-entry ?' "\"" simula-mode-syntax-table) | |
| 100 (modify-syntax-entry ?\( "()" simula-mode-syntax-table) | |
| 101 (modify-syntax-entry ?\) ")(" simula-mode-syntax-table) | |
| 102 (modify-syntax-entry ?\; ">" simula-mode-syntax-table) | |
| 103 (modify-syntax-entry ?\[ "." simula-mode-syntax-table) | |
| 104 (modify-syntax-entry ?\\ "." simula-mode-syntax-table) | |
| 105 (modify-syntax-entry ?\] "." simula-mode-syntax-table) | |
| 106 (modify-syntax-entry ?_ "w" simula-mode-syntax-table) | |
| 107 (modify-syntax-entry ?\| "." simula-mode-syntax-table) | |
| 108 (modify-syntax-entry ?\{ "." simula-mode-syntax-table) | |
| 109 (modify-syntax-entry ?\} "." simula-mode-syntax-table)) | |
| 110 | |
| 111 (defvar simula-mode-map () | |
| 4664 | 112 "Keymap used in SIMULA mode.") |
| 805 | 113 |
| 114 (if simula-mode-map | |
| 115 () | |
| 116 (setq simula-mode-map (make-sparse-keymap)) | |
| 117 (define-key simula-mode-map "\C-c\C-u" 'simula-backward-up-level) | |
| 118 (define-key simula-mode-map "\C-c\C-p" 'simula-previous-statement) | |
| 119 (define-key simula-mode-map "\C-c\C-d" 'simula-forward-down-level) | |
| 120 (define-key simula-mode-map "\C-c\C-n" 'simula-next-statement) | |
| 121 ;(define-key simula-mode-map "\C-c\C-g" 'simula-goto-definition) | |
| 122 ;(define-key simula-mode-map "\C-c\C-h" 'simula-standard-help) | |
| 123 (define-key simula-mode-map "\177" 'backward-delete-char-untabify) | |
| 124 (define-key simula-mode-map ":" 'simula-electric-label) | |
| 125 (define-key simula-mode-map "\t" 'simula-indent-command)) | |
| 126 | |
| 127 (defvar simula-mode-abbrev-table nil | |
| 4664 | 128 "Abbrev table in SIMULA mode buffers") |
| 805 | 129 |
| 130 | |
| 131 (defun simula-mode () | |
| 132 "Major mode for editing SIMULA code. | |
| 133 \\{simula-mode-map} | |
| 134 Variables controlling indentation style: | |
| 135 simula-tab-always-indent | |
| 136 Non-nil means TAB in SIMULA mode should always reindent the current line, | |
| 137 regardless of where in the line point is when the TAB command is used. | |
| 138 simula-indent-level | |
| 139 Indentation of SIMULA statements with respect to containing block. | |
| 140 simula-substatement-offset | |
| 141 Extra indentation after DO, THEN, ELSE, WHEN and OTHERWISE. | |
| 142 simula-continued-statement-offset 3 | |
| 143 Extra indentation for lines not starting a statement or substatement, | |
| 4664 | 144 e.g. a nested FOR-loop. If value is a list, each line in a multiple- |
| 805 | 145 line continued statement will have the car of the list extra indentation |
| 146 with respect to the previous line of the statement. | |
| 147 simula-label-offset -4711 | |
| 4664 | 148 Offset of SIMULA label lines relative to usual indentation. |
| 805 | 149 simula-if-indent '(0 . 0) |
| 150 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
|
151 Value is a cons cell, the car is extra THEN indentation and the cdr |
| 4664 | 152 extra ELSE indentation. IF after ELSE is indented as the starting IF. |
| 805 | 153 simula-inspect-indent '(0 . 0) |
| 154 Extra indentation of WHEN and OTHERWISE with respect to the | |
| 4664 | 155 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
|
156 extra WHEN indentation and the cdr extra OTHERWISE indentation. |
| 805 | 157 simula-electric-indent nil |
| 4664 | 158 If this variable is non-nil, `simula-indent-line' |
| 805 | 159 will check the previous line to see if it has to be reindented. |
| 160 simula-abbrev-keyword 'upcase | |
| 4664 | 161 Determine how SIMULA keywords will be expanded. Value is one of |
| 162 the symbols `upcase', `downcase', `capitalize', (as in) `abbrev-table', | |
| 163 or nil if they should not be changed. | |
| 805 | 164 simula-abbrev-stdproc 'abbrev-table |
| 165 Determine how standard SIMULA procedure and class names will be | |
| 4664 | 166 expanded. Value is one of the symbols `upcase', `downcase', `capitalize', |
| 167 (as in) `abbrev-table', or nil if they should not be changed. | |
| 805 | 168 |
| 169 Turning on SIMULA mode calls the value of the variable simula-mode-hook | |
| 170 with no arguments, if that value is non-nil | |
| 171 | |
| 172 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
|
173 the function simula-install-standard-abbrevs afterwards, preferably not |
| 805 | 174 at all." |
| 175 (interactive) | |
| 176 (kill-all-local-variables) | |
| 177 (use-local-map simula-mode-map) | |
| 178 (setq major-mode 'simula-mode) | |
| 179 (setq mode-name "SIMULA") | |
| 180 (make-local-variable 'comment-column) | |
| 181 (setq comment-column 40) | |
| 182 (make-local-variable 'end-comment-column) | |
| 183 (setq end-comment-column 75) | |
| 184 (set-syntax-table simula-mode-syntax-table) | |
| 185 (make-local-variable 'paragraph-start) | |
| 186 (setq paragraph-start "^[ \t]*$\\|\\f") | |
| 187 (make-local-variable 'paragraph-separate) | |
| 188 (setq paragraph-separate paragraph-start) | |
| 189 (make-local-variable 'indent-line-function) | |
| 190 (setq indent-line-function 'simula-indent-line) | |
| 191 (make-local-variable 'require-final-newline) | |
| 192 (setq require-final-newline t) | |
| 193 (make-local-variable 'comment-start) | |
| 194 (setq comment-start "! ") | |
| 195 (make-local-variable 'comment-end) | |
| 196 (setq comment-end " ;") | |
| 197 (make-local-variable 'comment-start-skip) | |
| 198 (setq comment-start-skip "!+ *") | |
| 199 (make-local-variable 'parse-sexp-ignore-comments) | |
| 200 (setq parse-sexp-ignore-comments nil) | |
| 201 (make-local-variable 'comment-multi-line) | |
| 202 (setq comment-multi-line t) | |
| 203 (if simula-mode-abbrev-table | |
| 204 () | |
| 205 (if simula-abbrev-file | |
| 206 (read-abbrev-file simula-abbrev-file) | |
| 207 (define-abbrev-table 'simula-mode-abbrev-table ())) | |
| 208 (let (abbrevs-changed) | |
| 209 (simula-install-standard-abbrevs))) | |
| 210 (setq local-abbrev-table simula-mode-abbrev-table) | |
| 211 (abbrev-mode 1) | |
| 212 (run-hooks 'simula-mode-hook)) | |
| 213 | |
| 214 | |
| 215 | |
| 216 (defun simula-indent-line () | |
| 4664 | 217 "Indent this line as SIMULA code. |
| 218 If `simula-electric-indent' is non-nil, indent previous line if necessary." | |
| 805 | 219 (let ((origin (- (point-max) (point))) |
| 220 (indent (simula-calculate-indent)) | |
| 221 (case-fold-search t)) | |
| 222 (unwind-protect | |
| 223 (progn | |
| 224 ;; | |
| 225 ;; manually expand abbrev on last line, if any | |
| 226 ;; | |
| 227 (end-of-line 0) | |
| 228 (expand-abbrev) | |
| 229 ;; now maybe we should reindent that line | |
| 230 (if simula-electric-indent | |
| 231 (progn | |
| 232 (beginning-of-line) | |
| 233 (skip-chars-forward " \t\f") | |
| 234 (if (and | |
| 235 (looking-at | |
| 236 "\\(end\\|if\\|then\\|else\\|when\\|otherwise\\)\\>") | |
| 237 (not (simula-context))) | |
| 238 ;; yes - reindent | |
| 239 (let ((post-indent (simula-calculate-indent))) | |
| 240 (if (eq (current-indentation) post-indent) | |
| 241 () | |
| 242 (delete-horizontal-space) | |
| 243 (indent-to post-indent))))))) | |
| 244 (goto-char (- (point-max) origin)) | |
| 245 (if (eq (current-indentation) indent) | |
| 246 (back-to-indentation) | |
| 247 (delete-horizontal-space) | |
| 248 (indent-to indent))))) | |
| 249 | |
| 250 | |
| 251 (defun simula-indent-command (&optional whole-exp) | |
| 252 "Indent current line as SIMULA code, or insert TAB character. | |
| 4664 | 253 If `simula-tab-always-indent' is non-nil, always indent current line. |
| 805 | 254 Otherwise, indent only if point is before any non-whitespace |
| 255 character on the line. | |
| 256 | |
| 257 A numeric argument, regardless of its value, means indent rigidly | |
| 258 all the lines of the SIMULA statement after point so that this line | |
| 259 becomes properly indented. | |
| 260 The relative indentation among the lines of the statement are preserved." | |
| 261 (interactive "P") | |
| 262 (let ((case-fold-search t)) | |
| 263 (if (or whole-exp simula-tab-always-indent | |
| 264 (save-excursion | |
| 265 (skip-chars-backward " \t\f") | |
| 266 (bolp))) | |
| 267 ;; reindent current line | |
| 268 (let ((indent (save-excursion | |
| 269 (beginning-of-line) | |
| 270 (simula-calculate-indent))) | |
| 271 (current (current-indentation)) | |
| 272 (origin (- (point-max) (point))) | |
| 273 (bol (save-excursion | |
| 274 (skip-chars-backward " \t\f") | |
| 275 (bolp))) | |
| 276 beg end) | |
| 277 (unwind-protect | |
| 278 (if (eq current indent) | |
| 279 (if (save-excursion | |
| 280 (skip-chars-backward " \t\f") | |
| 281 (bolp)) | |
| 282 (back-to-indentation)) | |
| 283 (beginning-of-line) | |
| 284 (delete-horizontal-space) | |
| 285 (indent-to indent)) | |
| 286 (if (not bol) | |
| 287 (goto-char (- (point-max) origin)))) | |
| 288 (setq origin (point)) | |
| 289 (if whole-exp | |
| 290 (save-excursion | |
| 291 (beginning-of-line 2) | |
| 292 (setq beg (point)) | |
| 293 (goto-char origin) | |
| 294 (simula-next-statement 1) | |
| 295 (setq end (point)) | |
| 296 (if (and (> end beg) (not (eq indent current))) | |
| 297 (indent-code-rigidly beg end (- indent current) "%"))))) | |
| 298 (insert-tab)))) | |
| 299 | |
| 300 | |
| 301 (defun simula-context () | |
| 4664 | 302 "Returns value according to syntactic SIMULA context of point. |
| 303 0 point inside COMMENT comment | |
| 805 | 304 1 point on SIMULA-compiler directive line |
| 305 2 point inside END comment | |
| 306 3 point inside string | |
| 307 4 point inside character constant | |
| 308 nil otherwise." | |
| 309 ;; first, find out if this is a compiler directive line | |
| 310 (if (save-excursion | |
| 311 (beginning-of-line) | |
| 312 (eq (following-char) ?%)) | |
| 313 ;; YES - return 1 | |
| 314 1 | |
| 315 (save-excursion | |
| 316 ;; The current line is NOT a compiler directive line. | |
| 317 ;; Now, the strategy is to search backward to find a semicolon | |
| 318 ;; that is NOT inside a string. The point after semicolon MUST be | |
| 319 ;; outside a comment, since semicolons are comment-ending and | |
| 320 ;; comments are non-recursive. We take advantage of the fact | |
| 321 ;; that strings MUST end on the same line as they started, so | |
| 322 ;; that we can easily decide whether we are inside a string or not. | |
| 323 (let (return-value (origin (point))) | |
| 324 (skip-chars-backward "^;" (point-min)) | |
| 325 ;; found semicolon or beginning of buffer | |
| 326 (let (loopvalue (saved-point origin)) | |
| 327 (while (and (not (bobp)) | |
| 328 (if (progn | |
| 329 (beginning-of-line) | |
| 330 ;; compiler directive line? If so, cont searching.. | |
| 331 (eq (following-char) ?%)) | |
| 332 t | |
| 333 (while (< (point) saved-point) | |
| 334 (skip-chars-forward "^;\"'") | |
| 335 (forward-char 1) | |
| 336 (cond | |
| 337 ((eq (preceding-char) ?\;) | |
| 338 (setq saved-point (point))) | |
| 339 ((eq (preceding-char) ?\") | |
| 340 (skip-chars-forward "^\";") | |
| 341 (if (eq (following-char) ?\;) | |
| 342 (setq saved-point (point) loopvalue t) | |
| 343 (forward-char 1))) | |
| 344 (t | |
| 345 (if (eq (following-char) ?') | |
| 346 (forward-char 1)) | |
| 347 (skip-chars-forward "^';") | |
| 348 (if (eq (following-char) ?\;) | |
| 349 (setq saved-point (point) loopvalue t) | |
| 350 (forward-char 1))))) | |
| 351 loopvalue)) | |
| 352 (backward-char 1) | |
| 353 (skip-chars-backward "^;") | |
| 354 (setq saved-point (point) loopvalue nil))) | |
| 355 ;; Now we are CERTAIN that we are outside comments and strings. | |
| 356 ;; The job now is to search forward again towards the origin | |
| 357 ;; skipping directives, comments and strings correctly, | |
| 358 ;; so that we know what context we are in when we find the origin. | |
| 359 (while (and | |
| 360 (< (point) origin) | |
| 361 (re-search-forward | |
| 362 "\\<end\\>\\|!\\|\"\\|'\\|^%\\|\\<comment\\>" origin 'move)) | |
| 363 (cond | |
| 364 ((memq (preceding-char) '(?d ?D)) | |
| 365 (setq return-value 2) | |
| 366 (while (and (memq (preceding-char) '(?d ?D)) (not return-value)) | |
| 367 (while (and (re-search-forward | |
| 368 ";\\|\\<end\\>\\|\\<else\\>\\|\\<otherwise\\>\\|\\<when\\>\\|^%" | |
| 369 origin 'move) | |
| 370 (eq (preceding-char) ?%)) | |
| 371 (beginning-of-line 2))) | |
| 372 (if (looking-at "[ \t\n\f]*\\(;\\|\\<end\\>\\|\\<else\\>\\|\\<otherwise\\>\\|\\<when\\>\\)") | |
| 373 (setq return-value nil))) | |
| 374 ((memq (preceding-char) '(?! ?t ?T)) | |
| 375 ; skip comment | |
| 376 (setq return-value 0) | |
| 377 (skip-chars-forward "^%;" origin) | |
| 378 (while (and return-value (< (point) origin)) | |
| 379 (if (eq (following-char) ?\;) | |
| 380 (setq return-value nil) | |
| 381 (if (bolp) | |
| 382 (beginning-of-line 2) ; skip directive inside comment | |
| 383 (forward-char 1)) ; or single '%' | |
| 384 (skip-chars-forward "^%;" origin)))) | |
| 385 ((eq (preceding-char) ?\") | |
| 386 (if (not (search-forward "\"" origin 'move)) | |
| 387 (setq return-value 3))) | |
| 388 ((eq (preceding-char) ?\') | |
| 389 (if (or (eq (point) origin) (eobp)) | |
| 390 (setq return-value 4) | |
| 391 (forward-char 1) | |
| 392 (if (not (search-forward "'" origin 'move)) | |
| 393 (setq return-value 4)))) | |
| 394 ;; compiler directive line - skip | |
| 395 (t (beginning-of-line 2)))) | |
| 396 return-value) | |
| 397 ))) | |
| 398 | |
| 399 | |
| 400 (defun simula-electric-label () | |
| 4664 | 401 "If this is a label that starts the line, reindent the line." |
| 805 | 402 (interactive) |
| 403 (expand-abbrev) | |
| 404 (insert ?:) | |
| 405 (let ((origin (- (point-max) (point))) | |
| 406 (case-fold-search t) | |
| 407 ;; don't mix a label with an assignment operator := :- | |
| 408 ;; 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
|
409 (next-char (setq unread-command-events (list (read-event)))) |
| 805 | 410 (com-char last-command-char)) |
| 411 (unwind-protect | |
| 412 ;; Problem: find out if character just read is a command char | |
| 413 ;; that would insert something after ':' making it a label. | |
| 414 ;; At least \n, \r (and maybe \t) falls into this category. | |
| 415 ;; This is a real crock, it depends on traditional keymap | |
| 416 ;; bindings, that is, printing characters doing self-insert, | |
| 417 ;; and no other command sequence inserting '-' or '='. | |
| 418 ;; simula-electric-label can be easily fooled... | |
| 419 (if (and (not (memq next-char '(?= ?-))) | |
| 420 (or (memq next-char '(?\n ?\r)) | |
| 421 (and (eq next-char ?\t) | |
| 422 simula-tab-always-indent) | |
| 423 (not (memq (following-char) '(?= ?-)))) | |
| 424 (not (simula-context)) | |
| 425 ;; label? | |
| 426 (progn | |
| 427 (backward-char 1) | |
| 428 (skip-chars-backward " \t\f") | |
| 429 (skip-chars-backward "a-zA-Z0-9_") | |
| 430 (if (looking-at "virtual\\>") | |
| 431 nil | |
| 432 (skip-chars-backward " \t\f") | |
| 433 (bolp)))) | |
| 434 (let ((amount (simula-calculate-indent))) | |
| 435 (delete-horizontal-space) | |
| 436 (indent-to amount))) | |
| 437 (goto-char (- (point-max) origin))))) | |
| 438 | |
| 439 | |
| 440 (defun simula-backward-up-level (count) | |
| 441 "Move backward up COUNT block levels. | |
| 4664 | 442 If COUNT is negative, move forward up block level instead." |
| 805 | 443 (interactive "p") |
| 444 (let ((origin (point)) | |
| 445 (case-fold-search t)) | |
| 446 (condition-case () | |
| 447 (if (> count 0) | |
| 448 (while (> count 0) | |
| 449 (re-search-backward "\\<begin\\>\\|\\<end\\>") | |
| 450 (if (not (simula-context)) | |
| 451 (setq count (if (memq (following-char) '(?b ?B)) | |
| 452 (1- count) | |
| 453 (1+ count))))) | |
| 454 (while (< count 0) | |
| 455 (re-search-forward "\\<begin\\>\\|\\<end\\>") | |
| 456 (backward-word 1) | |
| 457 (if (not (simula-context)) | |
| 458 (setq count (if (memq (following-char) '(?e ?E)) | |
| 459 (1+ count) | |
| 460 (1- count)))) | |
| 461 (backward-word -1))) | |
| 462 ;; If block level not found, jump back to origin and signal an error | |
| 463 (error (progn | |
| 464 (goto-char origin) | |
| 465 (error "No higher block level"))) | |
| 466 (quit (progn | |
| 467 (goto-char origin) | |
| 468 (signal 'quit nil)))))) | |
| 469 | |
| 470 | |
| 471 (defun simula-forward-down-level (count) | |
| 472 "Move forward down COUNT block levels. | |
| 4664 | 473 If COUNT is negative, move backward down block level instead." |
| 805 | 474 (interactive "p") |
| 475 ;; When we search for a deeper block level, we must never | |
| 476 ;; get out of the block where we started -> count >= start-count | |
| 477 (let ((start-count count) | |
| 478 (origin (point)) | |
| 479 (case-fold-search t)) | |
| 480 (condition-case () | |
| 481 (if (< count 0) | |
| 482 (while (< count 0) | |
| 483 (re-search-backward "\\<begin\\>\\|\\<end\\>") | |
| 484 (if (not (simula-context)) | |
| 485 (setq count (if (memq (following-char) '(?e ?E)) | |
| 486 (1+ count) | |
| 487 (1- count)))) | |
| 488 (if (< count start-count) (signal 'error nil))) | |
| 489 (while (> count 0) | |
| 490 (re-search-forward "\\<begin\\>\\|\\<end\\>") | |
| 491 (backward-word 1) | |
| 492 (if (not (simula-context)) | |
| 493 (setq count (if (memq (following-char) '(?b ?B)) | |
| 494 (1- count) | |
| 495 (1+ count)))) | |
| 496 (backward-word -1) | |
| 497 ;; deeper level has to be found within starting block | |
| 498 (if (> count start-count) (signal 'error nil)))) | |
| 499 ;; If block level not found, jump back to origin and signal an error | |
| 500 (error (progn | |
| 501 (goto-char origin) | |
| 502 (error "No containing block level"))) | |
| 503 (quit (progn | |
| 504 (goto-char origin) | |
| 505 (signal 'quit nil)))))) | |
| 506 | |
| 507 | |
| 508 (defun simula-previous-statement (count) | |
| 509 "Move backward COUNT statements. | |
| 4664 | 510 If COUNT is negative, move forward instead." |
| 805 | 511 (interactive "p") |
| 512 (if (< count 0) | |
| 513 (simula-next-statement (- count)) | |
| 514 (let (status | |
| 515 (case-fold-search t) | |
| 516 (origin (point))) | |
| 517 (condition-case () | |
| 518 (progn | |
| 519 (simula-skip-comment-backward) | |
| 520 (if (memq (preceding-char) '(?n ?N)) | |
| 521 (progn | |
| 522 (backward-word 1) | |
| 523 (if (not (looking-at "\\<begin\\>")) | |
| 524 (backward-word -1))) | |
| 525 (if (eq (preceding-char) ?\;) | |
| 526 (backward-char 1))) | |
| 527 (while (and (natnump (setq count (1- count))) | |
| 528 (setq status (simula-search-backward | |
| 529 ";\\|\\<begin\\>" nil 'move)))) | |
| 530 (if status | |
| 531 (progn | |
| 532 (if (eq (following-char) ?\;) | |
| 533 (forward-char 1) | |
| 534 (backward-word -1)))) | |
| 535 (simula-skip-comment-forward)) | |
| 536 (error (progn (goto-char origin) | |
| 537 (error "Incomplete statement (too many ENDs)"))) | |
| 538 (quit (progn (goto-char origin) (signal 'quit nil))))))) | |
| 539 | |
| 540 | |
| 541 (defun simula-next-statement (count) | |
| 4664 | 542 "Move forward COUNT statements. |
| 543 If COUNT is negative, move backward instead." | |
| 805 | 544 (interactive "p") |
| 545 (if (< count 0) | |
| 546 (simula-previous-statement (- count)) | |
| 547 (let (status | |
| 548 (case-fold-search t) | |
| 549 (origin (point))) | |
| 550 (condition-case () | |
| 551 (progn | |
| 552 (simula-skip-comment-forward) | |
| 553 (if (looking-at "\\<end\\>") (forward-word 1)) | |
| 554 (while (and (natnump (setq count (1- count))) | |
| 555 (setq status (simula-search-forward | |
| 556 ";\\|\\<end\\>" (point-max) 'move)))) | |
| 557 (if (and status (/= (preceding-char) ?\;)) | |
| 558 (progn | |
| 559 (backward-word 1) | |
| 560 (simula-skip-comment-backward)))) | |
| 561 (error (progn (goto-char origin) | |
| 562 (error "Incomplete statement (too few ENDs)"))) | |
| 563 (quit (progn (goto-char origin) (signal 'quit nil))))))) | |
| 564 | |
| 565 | |
| 566 (defun simula-skip-comment-backward () | |
| 4664 | 567 "Search towards bob to find first char that is outside a comment." |
| 805 | 568 (interactive) |
| 569 (catch 'simula-out | |
| 570 (let (context) | |
| 571 (while t | |
| 572 (skip-chars-backward " \t\n\f") | |
| 573 (if (eq (preceding-char) ?\;) | |
| 574 (save-excursion | |
| 575 (backward-char 1) | |
| 576 (setq context (simula-context))) | |
| 577 (setq context (simula-context))) | |
| 578 (cond | |
| 579 ((memq context '(nil 3 4)) | |
| 580 ;; check to see if we found a label | |
| 581 (if (and (eq (preceding-char) ?:) | |
| 582 (not (memq (following-char) '(?- ?=))) | |
| 583 (save-excursion | |
| 584 (skip-chars-backward ": \t\fa-zA-Z0-9_") | |
| 585 (not (looking-at "virtual\\>")))) | |
| 586 (skip-chars-backward ": \t\fa-zA-Z0-9_") | |
| 587 (throw 'simula-out nil))) | |
| 588 ((eq context 0) | |
| 589 ;; since we are inside a comment, it must start somewhere! | |
| 590 (while (and (re-search-backward "!\\|\\<comment\\>") | |
| 591 (memq (simula-context) '(0 1))))) | |
| 592 ((eq context 1) | |
| 593 (end-of-line 0) | |
| 594 (if (bobp) | |
| 595 (throw 'simula-out nil))) | |
| 596 ((eq context 2) | |
| 597 ;; an END-comment must belong to an END | |
| 598 (re-search-backward "\\<end\\>") | |
| 599 (forward-word 1) | |
| 600 (throw 'simula-out nil)) | |
| 601 ;; should be impossible to get here.. | |
| 602 ))))) | |
| 603 | |
| 604 | |
| 605 (defun simula-skip-comment-forward () | |
| 4664 | 606 "Search towards eob to find first char that is outside a comment." |
| 805 | 607 ;; this function assumes we start with point .outside a comment |
| 608 (interactive) | |
| 609 (catch 'simula-out | |
| 610 (while t | |
| 611 (skip-chars-forward " \t\n\f") | |
| 612 (cond | |
| 613 ((looking-at "!\\|\\<comment\\>") | |
| 614 (search-forward ";" nil 'move)) | |
| 615 ((and (bolp) (eq (following-char) ?%)) | |
| 616 (beginning-of-line 2)) | |
| 617 ((and (looking-at "[a-z0-9_]*[ \t\f]*:[^-=]") | |
| 618 (not (looking-at "virtual\\>"))) | |
| 619 (skip-chars-forward "a-zA-Z0-9_ \t\f:")) | |
| 620 (t | |
| 621 (throw 'simula-out t)))))) | |
| 622 | |
| 623 | |
| 624 (defun simula-forward-up-level () | |
| 625 (let ((continue-loop t) | |
| 626 (origin (point)) | |
| 627 (case-fold-search t) | |
| 628 return-value | |
| 629 temp) | |
| 630 (while continue-loop | |
| 631 (if (re-search-backward "\\<begin\\>\\|\\<end\\>" (point-min) 'move) | |
| 632 (setq temp (simula-context) | |
| 633 return-value (and (memq (preceding-char) '(?d ?D)) | |
| 634 (memq temp '(nil 2))) | |
| 635 continue-loop (and (not return-value) | |
| 636 (simula-forward-up-level))) | |
| 637 (setq continue-loop nil))) | |
| 638 (if return-value | |
| 639 t | |
| 640 (goto-char origin) | |
| 641 nil))) | |
| 642 | |
| 643 | |
| 644 (defun simula-calculate-indent () | |
| 645 (save-excursion | |
| 646 (let ((where (simula-context)) | |
| 647 (origin (point)) | |
| 648 (indent 0) | |
| 649 continued | |
| 650 start-line | |
| 651 temp | |
| 652 found-end | |
| 653 prev-cont) | |
| 654 (cond | |
| 655 ((eq where 0) | |
| 656 ;; | |
| 657 ;; Comment. | |
| 658 ;; If comment started on previous non-blank line, indent to the | |
| 659 ;; column where the comment started, else indent as that line. | |
| 660 ;; | |
| 661 (skip-chars-backward " \t\n\f") | |
| 662 (while (and (not (bolp)) (eq (simula-context) 0)) | |
| 663 (re-search-backward "^\\|!\\|\\<comment\\>")) | |
| 664 (skip-chars-forward " \t\n\f") | |
| 665 (prog1 | |
| 666 (current-column) | |
| 667 (goto-char origin))) | |
| 668 ;; | |
| 669 ;; Detect missing string delimiters | |
| 670 ;; | |
| 671 ((eq where 3) | |
| 672 (error "Inside string")) | |
| 673 ((eq where 4) | |
| 674 (error "Inside character constant")) | |
| 675 ;; | |
| 676 ;; check to see if inside ()'s | |
| 677 ;; | |
| 678 ((setq temp (simula-inside-parens)) | |
| 679 temp) | |
| 680 ;; | |
| 681 ;; Calculate non-comment indentation | |
| 682 (t | |
| 683 ;; 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
|
684 ;; special indentation (END/IF/THEN/ELSE/WHEN/OTHERWISE or label) |
| 805 | 685 ;; |
| 686 (skip-chars-forward " \t\f") | |
| 687 (cond | |
| 688 ;; | |
| 689 ;; END | |
| 690 ;; | |
| 691 ((looking-at "end\\>") | |
| 692 (setq indent (- simula-indent-level) | |
| 693 found-end t)) | |
| 694 ;; | |
| 695 ;; IF/THEN/ELSE | |
| 696 ;; | |
| 697 ((looking-at "if\\>\\|then\\>\\|else\\>") | |
| 698 ;; search for the *starting* IF | |
| 699 (cond | |
| 700 ((memq (following-char) '(?T ?t)) | |
| 701 (setq indent (car simula-if-indent))) | |
| 702 ((memq (following-char) '(?E ?e)) | |
| 703 (setq indent (cdr simula-if-indent))) | |
| 704 (t | |
| 705 (forward-word 1) | |
| 706 (setq indent 0))) | |
| 707 (simula-find-if)) | |
| 708 ;; | |
| 709 ;; WHEN/OTHERWISE | |
| 710 ;; | |
| 711 ((looking-at "when\\>\\|otherwise\\>") | |
| 712 ;; search for corresponding INSPECT | |
| 713 (if (memq (following-char) '(?W ?w)) | |
| 714 (setq indent (car simula-inspect-indent)) | |
| 715 (setq indent (cdr simula-inspect-indent))) | |
| 716 (simula-find-inspect)) | |
| 717 ;; | |
| 718 ;; label: | |
| 719 ;; | |
| 720 ((and (not (looking-at "virtual\\>")) | |
| 721 (looking-at "[a-z0-9_]*[ \t\f]*:[^-=]")) | |
| 722 (setq indent simula-label-offset))) | |
| 723 ;; find line with non-comment text | |
| 724 (simula-skip-comment-backward) | |
| 725 (if (and found-end | |
| 726 (not (eq (preceding-char) ?\;)) | |
| 727 (if (memq (preceding-char) '(?N ?n)) | |
| 728 (save-excursion | |
|
1621
ec2c000b8b69
* bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents:
841
diff
changeset
|
729 (backward-word 1) |
| 805 | 730 (not (looking-at "begin\\>"))) |
| 731 t)) | |
| 732 (progn | |
| 733 (simula-previous-statement 1) | |
| 734 (simula-skip-comment-backward))) | |
| 735 (setq start-line | |
| 736 (save-excursion (beginning-of-line) (point)) | |
| 737 ;; - perhaps this is a continued statement | |
| 738 continued | |
| 739 (save-excursion | |
| 740 (and (not (bobp)) | |
| 741 ;; (not found-end) | |
| 742 (if (eq (char-syntax (preceding-char)) ?w) | |
| 743 (progn | |
| 744 (backward-word 1) | |
| 745 (not (looking-at | |
| 746 "begin\\|then\\|else\\|when\\|otherwise\\|do" | |
| 747 ))) | |
| 748 (not (memq (preceding-char) '(?: ?\;))))))) | |
| 749 ;; | |
| 750 ;; MAIN calculation loop - count BEGIN/DO etc. | |
| 751 ;; | |
| 752 (while (not (bolp)) | |
| 753 (if (re-search-backward | |
| 754 ";\\|\\<\\(begin\\|end\\|if\\|else\\|then\\|when\\|otherwise\\|do\\)\\>" | |
| 755 start-line 'move) | |
| 756 (if (simula-context) | |
| 757 ();; found something in a comment/string - ignore | |
| 758 (setq temp (following-char)) | |
| 759 (cond | |
| 760 ((eq temp ?\;) | |
| 761 (simula-previous-statement 1)) | |
| 762 ((looking-at "begin\\>") | |
| 763 (setq indent (+ indent simula-indent-level))) | |
| 764 ((looking-at "end\\>") | |
| 765 (forward-word 1) | |
| 766 (simula-previous-statement 1)) | |
| 767 ((looking-at "do\\>") | |
| 768 (setq indent (+ indent simula-substatement-offset)) | |
| 769 (simula-find-do-match)) | |
| 770 ((looking-at "\\(if\\|then\\|else\\)\\>") | |
| 771 (if (memq temp '(?I ?i)) | |
| 772 (forward-word 1) | |
| 773 (setq indent (+ indent | |
| 774 simula-substatement-offset | |
| 775 (if (memq temp '(?T ?t)) | |
| 776 (car simula-if-indent) | |
| 777 (cdr simula-if-indent))))) | |
| 778 (simula-find-if)) | |
| 779 ((looking-at "\\<when\\>\\|\\<otherwise\\>") | |
| 780 (setq indent (+ indent | |
| 781 simula-substatement-offset | |
| 782 (if (memq temp '(?W ?w)) | |
| 783 (car simula-if-indent) | |
| 784 (cdr simula-if-indent)))) | |
| 785 (simula-find-inspect))) | |
| 786 ;; found the start of a [sub]statement | |
|
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
787 ;; add indentation for continued statement |
| 805 | 788 (if continued |
| 789 (setq indent | |
| 790 (+ indent | |
| 791 (if (listp simula-continued-statement-offset) | |
| 792 (car simula-continued-statement-offset) | |
| 793 simula-continued-statement-offset)))) | |
| 794 (setq start-line | |
| 795 (save-excursion (beginning-of-line) (point)) | |
| 796 continued nil)) | |
| 797 ;; search failed .. point is at beginning of line | |
| 798 ;; determine if we should continue searching | |
| 799 ;; (at or before comment or label) | |
| 800 ;; temp = t means finished | |
| 801 (setq temp | |
| 802 (and (not (simula-context)) | |
| 803 (save-excursion | |
| 804 (skip-chars-forward " \t\f") | |
| 805 (or (looking-at "virtual") | |
| 806 (not | |
| 807 (looking-at | |
| 808 "!\\|comment\\>\\|[a-z0-9_]*[ \t\f]*:[^-=]"))))) | |
| 809 prev-cont continued) | |
| 810 ;; if we are finished, find current line's indentation | |
| 811 (if temp | |
| 812 (setq indent (+ indent (current-indentation)))) | |
| 813 ;; find next line with non-comment SIMULA text | |
| 814 ;; maybe indent extra if statement continues | |
| 815 (simula-skip-comment-backward) | |
| 816 (setq continued | |
| 817 (and (not (bobp)) | |
| 818 (if (eq (char-syntax (preceding-char)) ?w) | |
| 819 (save-excursion | |
| 820 (backward-word 1) | |
| 821 (not (looking-at | |
| 822 "begin\\|then\\|else\\|when\\|otherwise\\|do"))) | |
| 823 (not (memq (preceding-char) '(?: ?\;)))))) | |
| 824 ;; 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
|
825 ;; changed, add indentation for continued statement |
| 805 | 826 (if (or (and prev-cont (not continued)) |
| 827 (and continued | |
| 828 (listp simula-continued-statement-offset))) | |
| 829 (setq indent | |
| 830 (+ indent | |
| 831 (if (listp simula-continued-statement-offset) | |
| 832 (car simula-continued-statement-offset) | |
| 833 simula-continued-statement-offset)))) | |
| 834 ;; while ends if point is at beginning of line at loop test | |
| 835 (if (not temp) | |
| 836 (setq start-line (save-excursion (beginning-of-line) (point))) | |
| 837 (beginning-of-line)))) | |
| 838 ;; | |
|
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
839 ;; return indentation |
| 805 | 840 ;; |
| 841 indent))))) | |
| 842 | |
| 843 | |
| 844 (defun simula-find-if () | |
| 4664 | 845 "Find starting IF of a IF-THEN[-ELSE[-IF-THEN...]] statement." |
| 805 | 846 (catch 'simula-out |
| 847 (while t | |
| 848 (if (and (simula-search-backward "\\<if\\>\\|;\\|\\<begin\\>"nil t) | |
| 849 (memq (following-char) '(?I ?i))) | |
| 850 (save-excursion | |
| 851 ;; | |
| 852 ;; find out if this IF was really the start of the IF statement | |
| 853 ;; | |
| 854 (simula-skip-comment-backward) | |
| 855 (if (and (eq (char-syntax (preceding-char)) ?w) | |
| 856 (progn | |
| 857 (backward-word 1) | |
| 858 (looking-at "else\\>"))) | |
| 859 () | |
| 860 (throw 'simula-out t))) | |
| 861 (if (not (looking-at "\\<if\\>")) | |
| 862 (error "Missing IF or misplaced BEGIN or ';' (can't find IF)") | |
| 863 ;; | |
| 864 ;; we were at the starting IF in the first place.. | |
| 865 ;; | |
| 866 (throw 'simula-out t)))))) | |
| 867 | |
| 868 | |
| 869 (defun simula-find-inspect () | |
| 4664 | 870 "Find INSPECT matching WHEN or OTHERWISE." |
| 805 | 871 (catch 'simula-out |
| 872 (let ((level 0)) | |
| 873 ;; | |
| 874 ;; INSPECTs can be nested, have to find the corresponding one | |
| 875 ;; | |
| 876 (while t | |
| 877 (if (and (simula-search-backward "\\<inspect\\>\\|\\<otherwise\\>\\|;" | |
| 878 nil t) | |
| 879 (/= (following-char) ?\;)) | |
| 880 (if (memq (following-char) '(?O ?o)) | |
| 881 (setq level (1+ level)) | |
| 882 (if (zerop level) | |
| 883 (throw 'simula-out t) | |
| 884 (setq level (1- level)))) | |
| 885 (error "Missing INSPECT or misplaced ';' (can't find INSPECT)")))))) | |
| 886 | |
| 887 | |
| 888 (defun simula-find-do-match () | |
| 889 "Find keyword matching DO: FOR, WHILE, INSPECT or WHEN" | |
| 890 (while (and (re-search-backward | |
| 891 "\\<\\(do\\|for\\|while\\|inspect\\|when\\|end\\|begin\\)\\>\\|;" | |
| 892 nil 'move) | |
| 893 (simula-context))) | |
| 894 (if (and (looking-at "\\<\\(for\\|while\\|inspect\\|when\\)\\>") | |
| 895 (not (simula-context))) | |
| 896 () ;; found match | |
| 897 (error "No matching FOR, WHILE or INSPECT for DO, or misplaced ';'"))) | |
| 898 | |
| 899 | |
| 900 (defun simula-inside-parens () | |
| 4664 | 901 "Return position after `(' on line if inside parentheses, nil otherwise." |
| 805 | 902 (save-excursion |
| 903 (let ((parlevel 0)) | |
| 904 (catch 'simula-out | |
| 905 (while t | |
| 906 (if (re-search-backward "(\\|)\\|;" nil t) | |
| 907 (if (eq (simula-context) nil) | |
| 908 ;; found something - check it out | |
| 909 (cond | |
| 910 ((eq (following-char) ?\;) | |
| 911 (if (zerop parlevel) | |
| 912 (throw 'simula-out nil) | |
|
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2315
diff
changeset
|
913 (error "Parenthesis mismatch or misplaced ';'"))) |
| 805 | 914 ((eq (following-char) ?\() |
| 915 (if (zerop parlevel) | |
| 916 (throw 'simula-out (1+ (current-column))) | |
| 917 (setq parlevel (1- parlevel)))) | |
| 918 (t (setq parlevel (1+ parlevel)))) | |
| 919 );; nothing - inside comment or string | |
| 920 ;; search failed | |
| 921 (throw 'simula-out nil))))))) | |
| 922 | |
| 923 | |
| 924 (defun simula-goto-definition () | |
| 925 "Goto point of definition of variable, procedure or class." | |
| 926 (interactive)) | |
| 927 | |
| 928 | |
| 929 (defun simula-expand-stdproc () | |
| 930 (if (or (not simula-abbrev-stdproc) (simula-context)) | |
| 931 (unexpand-abbrev) | |
| 932 (cond | |
| 933 ((eq simula-abbrev-stdproc 'upcase) (upcase-word -1)) | |
| 934 ((eq simula-abbrev-stdproc 'downcase) (downcase-word -1)) | |
| 935 ((eq simula-abbrev-stdproc 'capitalize) (capitalize-word -1))))) | |
| 936 | |
| 937 | |
| 938 (defun simula-expand-keyword () | |
| 939 (if (or (not simula-abbrev-keyword) (simula-context)) | |
| 940 (unexpand-abbrev) | |
| 941 (cond | |
| 942 ((eq simula-abbrev-keyword 'upcase) (upcase-word -1)) | |
| 943 ((eq simula-abbrev-keyword 'downcase) (downcase-word -1)) | |
| 944 ((eq simula-abbrev-keyword 'capitalize) (capitalize-word -1))))) | |
| 945 | |
| 946 | |
| 947 (defun simula-electric-keyword () | |
| 4664 | 948 "Expand SIMULA keyword. If it starts the line, reindent." |
| 805 | 949 ;; redisplay |
| 950 (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
|
951 ;; If the abbrev expansion results in reindentation, the user may have |
| 805 | 952 ;; to wait some time before the character he typed is displayed |
| 953 ;; (the char causing the expansion is inserted AFTER the hook function | |
| 954 ;; is called). This is annoying in case of normal characters. | |
| 955 ;; However, if the user pressed a key bound to newline, it is better | |
| 956 ;; to have the line inserted after the begin-end match. | |
| 957 (if show-char | |
| 958 (progn | |
| 959 (insert-char last-command-char 1) | |
| 960 (sit-for 0) | |
| 961 (backward-char 1))) | |
| 962 (if (let ((where (simula-context)) | |
| 963 (case-fold-search t)) | |
| 964 (if where | |
| 965 (if (and (eq where 2) (eq (char-syntax (preceding-char)) ?w)) | |
| 966 (save-excursion | |
| 967 (backward-word 1) | |
| 968 (not (looking-at "end\\>")))))) | |
| 969 (unexpand-abbrev) | |
| 970 (cond | |
| 971 ((not simula-abbrev-keyword) (unexpand-abbrev)) | |
| 972 ((eq simula-abbrev-keyword 'upcase) (upcase-word -1)) | |
| 973 ((eq simula-abbrev-keyword 'downcase) (downcase-word -1)) | |
| 974 ((eq simula-abbrev-keyword 'capitalize) (capitalize-word -1))) | |
| 975 (let ((pos (- (point-max) (point))) | |
| 976 (case-fold-search t) | |
| 977 null) | |
| 978 (condition-case null | |
| 979 (progn | |
| 980 ;; check if the expanded word is on the beginning of the line. | |
| 981 (if (and (eq (char-syntax (preceding-char)) ?w) | |
| 982 (progn | |
| 983 (backward-word 1) | |
| 984 (if (looking-at "end\\>") | |
| 985 (save-excursion | |
| 986 (simula-backward-up-level 1) | |
| 987 (if (pos-visible-in-window-p) | |
| 988 (sit-for 1) | |
| 989 (message | |
| 990 (concat "Matches " | |
| 991 (buffer-substring | |
| 992 (point) | |
| 993 (+ (point) (window-width)))))))) | |
| 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 |
