Mercurial > emacs
annotate lisp/progmodes/modula2.el @ 755:e43123226372
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Fri, 10 Jul 1992 01:16:40 +0000 |
parents | 3587b3dfac25 |
children | 203c23c9f22c |
rev | line source |
---|---|
663
3587b3dfac25
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
659
diff
changeset
|
1 ;;; |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
2 ;;; modula2.el --- Modula-2 editing support package |
663
3587b3dfac25
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
659
diff
changeset
|
3 ;; The authors distributed this in without a copyright notice |
3587b3dfac25
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
659
diff
changeset
|
4 ;; back in 1988, so it is in the public domain. |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
5 |
22 | 6 ; Author Mick Jordan |
7 ; amended Peter Robinson | |
8 ; ported to GNU Michael Schmidt | |
9 ;;;From: "Michael Schmidt" <michael@pbinfo.UUCP> | |
10 ;;;Modified by Tom Perrine <Perrin@LOGICON.ARPA> (TEP) | |
11 | |
12 | |
13 ;;; Added by TEP | |
14 (defvar m2-mode-syntax-table nil | |
231 | 15 "Syntax table in use in Modula-2 buffers.") |
22 | 16 |
17 (defvar m2-compile-command "m2c" | |
18 "Command to compile Modula-2 programs") | |
19 | |
20 (defvar m2-link-command "m2l" | |
21 "Command to link Modula-2 programs") | |
22 | |
23 (defvar m2-link-name nil | |
24 "Name of the executable.") | |
25 | |
26 | |
27 (if m2-mode-syntax-table | |
28 () | |
29 (let ((table (make-syntax-table))) | |
30 (modify-syntax-entry ?\\ "\\" table) | |
31 (modify-syntax-entry ?\( ". 1" table) | |
32 (modify-syntax-entry ?\) ". 4" table) | |
33 (modify-syntax-entry ?* ". 23" table) | |
34 (modify-syntax-entry ?+ "." table) | |
35 (modify-syntax-entry ?- "." table) | |
36 (modify-syntax-entry ?= "." table) | |
37 (modify-syntax-entry ?% "." table) | |
38 (modify-syntax-entry ?< "." table) | |
39 (modify-syntax-entry ?> "." table) | |
40 (modify-syntax-entry ?\' "\"" table) | |
41 (setq m2-mode-syntax-table table))) | |
42 | |
43 ;;; Added by TEP | |
44 (defvar m2-mode-map nil | |
45 "Keymap used in Modula-2 mode.") | |
46 | |
47 (if m2-mode-map () | |
48 (let ((map (make-sparse-keymap))) | |
49 (define-key map "\^i" 'm2-tab) | |
50 (define-key map "\C-cb" 'm2-begin) | |
51 (define-key map "\C-cc" 'm2-case) | |
52 (define-key map "\C-cd" 'm2-definition) | |
53 (define-key map "\C-ce" 'm2-else) | |
54 (define-key map "\C-cf" 'm2-for) | |
55 (define-key map "\C-ch" 'm2-header) | |
56 (define-key map "\C-ci" 'm2-if) | |
57 (define-key map "\C-cm" 'm2-module) | |
58 (define-key map "\C-cl" 'm2-loop) | |
59 (define-key map "\C-co" 'm2-or) | |
60 (define-key map "\C-cp" 'm2-procedure) | |
61 (define-key map "\C-c\C-w" 'm2-with) | |
62 (define-key map "\C-cr" 'm2-record) | |
63 (define-key map "\C-cs" 'm2-stdio) | |
64 (define-key map "\C-ct" 'm2-type) | |
65 (define-key map "\C-cu" 'm2-until) | |
66 (define-key map "\C-cv" 'm2-var) | |
67 (define-key map "\C-cw" 'm2-while) | |
68 (define-key map "\C-cx" 'm2-export) | |
69 (define-key map "\C-cy" 'm2-import) | |
70 (define-key map "\C-c{" 'm2-begin-comment) | |
71 (define-key map "\C-c}" 'm2-end-comment) | |
72 (define-key map "\C-j" 'm2-newline) | |
73 (define-key map "\C-c\C-z" 'suspend-emacs) | |
74 (define-key map "\C-c\C-v" 'm2-visit) | |
75 (define-key map "\C-c\C-t" 'm2-toggle) | |
76 (define-key map "\C-c\C-l" 'm2-link) | |
77 (define-key map "\C-c\C-c" 'm2-compile) | |
78 (setq m2-mode-map map))) | |
79 | |
80 (defvar m2-indent 5 "*This variable gives the indentation in Modula-2-Mode") | |
81 | |
258 | 82 ;;;###autoload |
22 | 83 (defun modula-2-mode () |
231 | 84 "This is a mode intended to support program development in Modula-2. |
85 All control constructs of Modula-2 can be reached by typing C-c | |
86 followed by the first character of the construct. | |
87 \\<m2-mode-map> | |
88 \\[m2-begin] begin \\[m2-case] case | |
89 \\[m2-definition] definition \\[m2-else] else | |
90 \\[m2-for] for \\[m2-header] header | |
91 \\[m2-if] if \\[m2-module] module | |
92 \\[m2-loop] loop \\[m2-or] or | |
93 \\[m2-procedure] procedure Control-c Control-w with | |
94 \\[m2-record] record \\[m2-stdio] stdio | |
95 \\[m2-type] type \\[m2-until] until | |
96 \\[m2-var] var \\[m2-while] while | |
97 \\[m2-export] export \\[m2-import] import | |
98 \\[m2-begin-comment] begin-comment \\[m2-end-comment] end-comment | |
99 \\[suspend-emacs] suspend Emacs \\[m2-toggle] toggle | |
100 \\[m2-compile] compile \\[m2-next-error] next-error | |
101 \\[m2-link] link | |
22 | 102 |
231 | 103 `m2-indent' controls the number of spaces for each indentation. |
104 `m2-compile-command' holds the command to compile a Modula-2 program. | |
105 `m2-link-command' holds the command to link a Modula-2 program." | |
22 | 106 (interactive) |
107 (kill-all-local-variables) | |
108 (use-local-map m2-mode-map) | |
109 (setq major-mode 'modula-2-mode) | |
110 (setq mode-name "Modula-2") | |
111 (make-local-variable 'comment-column) | |
112 (setq comment-column 41) | |
113 (make-local-variable 'end-comment-column) | |
114 (setq end-comment-column 75) | |
115 (set-syntax-table m2-mode-syntax-table) | |
116 (make-local-variable 'paragraph-start) | |
117 (setq paragraph-start (concat "^$\\|" page-delimiter)) | |
118 (make-local-variable 'paragraph-separate) | |
119 (setq paragraph-separate paragraph-start) | |
120 (make-local-variable 'paragraph-ignore-fill-prefix) | |
121 (setq paragraph-ignore-fill-prefix t) | |
122 ; (make-local-variable 'indent-line-function) | |
123 ; (setq indent-line-function 'c-indent-line) | |
124 (make-local-variable 'require-final-newline) | |
125 (setq require-final-newline t) | |
126 (make-local-variable 'comment-start) | |
127 (setq comment-start "(* ") | |
128 (make-local-variable 'comment-end) | |
129 (setq comment-end " *)") | |
130 (make-local-variable 'comment-column) | |
131 (setq comment-column 41) | |
132 (make-local-variable 'comment-start-skip) | |
133 (setq comment-start-skip "/\\*+ *") | |
134 (make-local-variable 'comment-indent-hook) | |
135 (setq comment-indent-hook 'c-comment-indent) | |
136 (make-local-variable 'parse-sexp-ignore-comments) | |
137 (setq parse-sexp-ignore-comments t) | |
138 (run-hooks 'm2-mode-hook)) | |
139 | |
140 (defun m2-newline () | |
141 "Insert a newline and indent following line like previous line." | |
142 (interactive) | |
143 (let ((hpos (current-indentation))) | |
144 (newline) | |
145 (indent-to hpos))) | |
146 | |
147 (defun m2-tab () | |
148 "Indent to next tab stop." | |
149 (interactive) | |
150 (indent-to (* (1+ (/ (current-indentation) m2-indent)) m2-indent))) | |
151 | |
152 (defun m2-begin () | |
153 "Insert a BEGIN keyword and indent for the next line." | |
154 (interactive) | |
155 (insert "BEGIN") | |
156 (m2-newline) | |
157 (m2-tab)) | |
158 | |
159 (defun m2-case () | |
160 "Build skeleton CASE statment, prompting for the <expression>." | |
161 (interactive) | |
162 (let ((name (read-string "Case-Expression: "))) | |
163 (insert "CASE " name " OF") | |
164 (m2-newline) | |
165 (m2-newline) | |
166 (insert "END (* case " name " *);")) | |
167 (end-of-line 0) | |
168 (m2-tab)) | |
169 | |
170 (defun m2-definition () | |
171 "Build skeleton DEFINITION MODULE, prompting for the <module name>." | |
172 (interactive) | |
173 (insert "DEFINITION MODULE ") | |
174 (let ((name (read-string "Name: "))) | |
175 (insert name ";\n\n\n\nEND " name ".\n")) | |
176 (previous-line 3)) | |
177 | |
178 (defun m2-else () | |
179 "Insert ELSE keyword and indent for next line." | |
180 (interactive) | |
181 (m2-newline) | |
182 (backward-delete-char-untabify m2-indent ()) | |
183 (insert "ELSE") | |
184 (m2-newline) | |
185 (m2-tab)) | |
186 | |
187 (defun m2-for () | |
188 "Build skeleton FOR loop statment, prompting for the loop parameters." | |
189 (interactive) | |
190 (insert "FOR ") | |
191 (let ((name (read-string "Loop Initialiser: ")) limit by) | |
192 (insert name " TO ") | |
193 (setq limit (read-string "Limit: ")) | |
194 (insert limit) | |
195 (setq by (read-string "Step: ")) | |
196 (if (not (string-equal by "")) | |
197 (insert " BY " by)) | |
198 (insert " DO") | |
199 (m2-newline) | |
200 (m2-newline) | |
201 (insert "END (* for " name " to " limit " *);")) | |
202 (end-of-line 0) | |
203 (m2-tab)) | |
204 | |
205 (defun m2-header () | |
206 "Insert a comment block containing the module title, author, etc." | |
207 (interactive) | |
208 (insert "(*\n Title: \t") | |
209 (insert (read-string "Title: ")) | |
210 (insert "\n Created:\t") | |
211 (insert (current-time-string)) | |
212 (insert "\n Author: \t") | |
213 (insert (user-full-name)) | |
214 (insert (concat "\n\t\t<" (user-login-name) "@" (system-name) ">\n")) | |
215 (insert "*)\n\n")) | |
216 | |
217 (defun m2-if () | |
218 "Insert skeleton IF statment, prompting for <boolean-expression>." | |
219 (interactive) | |
220 (insert "IF ") | |
221 (let ((thecondition (read-string "<boolean-expression>: "))) | |
222 (insert thecondition " THEN") | |
223 (m2-newline) | |
224 (m2-newline) | |
225 (insert "END (* if " thecondition " *);")) | |
226 (end-of-line 0) | |
227 (m2-tab)) | |
228 | |
229 (defun m2-loop () | |
230 "Build skeleton LOOP (with END)." | |
231 (interactive) | |
232 (insert "LOOP") | |
233 (m2-newline) | |
234 (m2-newline) | |
235 (insert "END (* loop *);") | |
236 (end-of-line 0) | |
237 (m2-tab)) | |
238 | |
239 (defun m2-module () | |
240 "Build skeleton IMPLEMENTATION MODULE, prompting for <module-name>." | |
241 (interactive) | |
242 (insert "IMPLEMENTATION MODULE ") | |
243 (let ((name (read-string "Name: "))) | |
244 (insert name ";\n\n\n\nEND " name ".\n") | |
245 (previous-line 3) | |
246 (m2-header) | |
247 (m2-type) | |
248 (newline) | |
249 (m2-var) | |
250 (newline) | |
251 (m2-begin) | |
252 (m2-begin-comment) | |
253 (insert " Module " name " Initialisation Code ")) | |
254 (m2-end-comment) | |
255 (newline) | |
256 (m2-tab)) | |
257 | |
258 (defun m2-or () | |
259 (interactive) | |
260 (m2-newline) | |
261 (backward-delete-char-untabify m2-indent) | |
262 (insert "|") | |
263 (m2-newline) | |
264 (m2-tab)) | |
265 | |
266 (defun m2-procedure () | |
267 (interactive) | |
268 (insert "PROCEDURE ") | |
269 (let ((name (read-string "Name: " )) | |
270 args) | |
271 (insert name " (") | |
272 (insert (read-string "Arguments: ") ")") | |
273 (setq args (read-string "Result Type: ")) | |
274 (if (not (string-equal args "")) | |
275 (insert " : " args)) | |
276 (insert ";") | |
277 (m2-newline) | |
278 (insert "BEGIN") | |
279 (m2-newline) | |
280 (m2-newline) | |
281 (insert "END ") | |
282 (insert name) | |
283 (insert ";") | |
284 (end-of-line 0) | |
285 (m2-tab))) | |
286 | |
287 (defun m2-with () | |
288 (interactive) | |
289 (insert "WITH ") | |
290 (let ((name (read-string "Record-Type: "))) | |
291 (insert name) | |
292 (insert " DO") | |
293 (m2-newline) | |
294 (m2-newline) | |
295 (insert "END (* with " name " *);")) | |
296 (end-of-line 0) | |
297 (m2-tab)) | |
298 | |
299 (defun m2-record () | |
300 (interactive) | |
301 (insert "RECORD") | |
302 (m2-newline) | |
303 (m2-newline) | |
304 (insert "END (* record *);") | |
305 (end-of-line 0) | |
306 (m2-tab)) | |
307 | |
308 (defun m2-stdio () | |
309 (interactive) | |
310 (insert " | |
231 | 311 FROM TextIO IMPORT |
22 | 312 WriteCHAR, ReadCHAR, WriteINTEGER, ReadINTEGER, |
313 WriteCARDINAL, ReadCARDINAL, WriteBOOLEAN, ReadBOOLEAN, | |
314 WriteREAL, ReadREAL, WriteBITSET, ReadBITSET, | |
315 WriteBasedCARDINAL, ReadBasedCARDINAL, WriteChars, ReadChars, | |
316 WriteString, ReadString, WhiteSpace, EndOfLine; | |
317 | |
231 | 318 FROM SysStreams IMPORT sysIn, sysOut, sysErr; |
22 | 319 |
320 ")) | |
321 | |
322 (defun m2-type () | |
323 (interactive) | |
324 (insert "TYPE") | |
325 (m2-newline) | |
326 (m2-tab)) | |
327 | |
328 (defun m2-until () | |
329 (interactive) | |
330 (insert "REPEAT") | |
331 (m2-newline) | |
332 (m2-newline) | |
333 (insert "UNTIL ") | |
334 (insert (read-string "<boolean-expression>: ") ";") | |
335 (end-of-line 0) | |
336 (m2-tab)) | |
337 | |
338 (defun m2-var () | |
339 (interactive) | |
340 (m2-newline) | |
341 (insert "VAR") | |
342 (m2-newline) | |
343 (m2-tab)) | |
344 | |
345 (defun m2-while () | |
346 (interactive) | |
347 (insert "WHILE ") | |
348 (let ((name (read-string "<boolean-expression>: "))) | |
349 (insert name " DO" ) | |
350 (m2-newline) | |
351 (m2-newline) | |
352 (insert "END (* while " name " *);")) | |
353 (end-of-line 0) | |
354 (m2-tab)) | |
355 | |
356 (defun m2-export () | |
357 (interactive) | |
358 (insert "EXPORT QUALIFIED ")) | |
359 | |
360 (defun m2-import () | |
361 (interactive) | |
362 (insert "FROM ") | |
363 (insert (read-string "Module: ")) | |
364 (insert " IMPORT ")) | |
365 | |
366 (defun m2-begin-comment () | |
367 (interactive) | |
368 (if (not (bolp)) | |
369 (indent-to comment-column 0)) | |
370 (insert "(* ")) | |
371 | |
372 (defun m2-end-comment () | |
373 (interactive) | |
374 (if (not (bolp)) | |
375 (indent-to end-comment-column)) | |
376 (insert "*)")) | |
377 | |
378 (defun m2-compile () | |
379 (interactive) | |
380 (setq modulename (buffer-name)) | |
381 (compile (concat m2-compile-command " " modulename))) | |
382 | |
383 (defun m2-link () | |
384 (interactive) | |
385 (setq modulename (buffer-name)) | |
386 (if m2-link-name | |
387 (compile (concat m2-link-command " " m2-link-name)) | |
388 (compile (concat m2-link-command " " | |
389 (setq m2-link-name (read-string "Name of executable: " | |
390 modulename)))))) | |
391 | |
392 (defun execute-monitor-command (command) | |
393 (let* ((shell shell-file-name) | |
394 (csh (equal (file-name-nondirectory shell) "csh"))) | |
395 (call-process shell nil t t "-cf" (concat "exec " command)))) | |
396 | |
397 (defun m2-visit () | |
398 (interactive) | |
399 (let ((deffile nil) | |
400 (modfile nil) | |
401 modulename) | |
402 (save-excursion | |
403 (setq modulename | |
404 (read-string "Module name: ")) | |
405 (switch-to-buffer "*Command Execution*") | |
406 (execute-monitor-command (concat "m2whereis " modulename)) | |
407 (goto-char (point-min)) | |
408 (condition-case () | |
409 (progn (re-search-forward "\\(.*\\.def\\) *$") | |
410 (setq deffile (buffer-substring (match-beginning 1) | |
411 (match-end 1)))) | |
412 (search-failed ())) | |
413 (condition-case () | |
414 (progn (re-search-forward "\\(.*\\.mod\\) *$") | |
415 (setq modfile (buffer-substring (match-beginning 1) | |
416 (match-end 1)))) | |
417 (search-failed ())) | |
418 (if (not (or deffile modfile)) | |
419 (error "I can find neither definition nor implementation of %s" | |
420 modulename))) | |
421 (cond (deffile | |
422 (find-file deffile) | |
423 (if modfile | |
424 (save-excursion | |
425 (find-file modfile)))) | |
426 (modfile | |
427 (find-file modfile))))) | |
428 | |
429 (defun m2-toggle () | |
430 "Toggle between .mod and .def files for the module." | |
431 (interactive) | |
432 (cond ((string-equal (substring (buffer-name) -4) ".def") | |
433 (find-file-other-window | |
434 (concat (substring (buffer-name) 0 -4) ".mod"))) | |
435 ((string-equal (substring (buffer-name) -4) ".mod") | |
436 (find-file-other-window | |
437 (concat (substring (buffer-name) 0 -4) ".def"))) | |
438 ((string-equal (substring (buffer-name) -3) ".mi") | |
439 (find-file-other-window | |
440 (concat (substring (buffer-name) 0 -3) ".md"))) | |
441 ((string-equal (substring (buffer-name) -3) ".md") | |
442 (find-file-other-window | |
443 (concat (substring (buffer-name) 0 -3) ".mi"))))) | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
444 |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
445 ;;; modula2.el ends here |