comparison lisp/modes/rexx-mode.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 0293115a14e9
comparison
equal deleted inserted replaced
-1:000000000000 0:376386a54a3c
1 ;;; rexx-mode.el --- major mode for editing REXX program files
2 ;; Keywords: languages
3
4 ;; Copyright (C) 1993 by Anders Lindgren.
5
6 ;; This file is part of XEmacs.
7
8 ;; XEmacs is free software; you can redistribute it and/or modify it
9 ;; under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
12
13 ;; XEmacs is distributed in the hope that it will be useful, but
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ;; General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with XEmacs; see the file COPYING. If not, write to the Free
20 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 ;;; Synched up with: Not in FSF.
23
24 ;;; AUTHOR
25 ;;; Anders Lindgren, d91ali@csd.uu.se
26 ;;;
27 ;;; Abbrevationtable due to:
28 ;;; Johan Bergkvist, nv91-jbe@nada.kth.se
29 ;;;
30 ;;; USAGE
31 ;;; This file contains code for a GNU Emacs major mode for
32 ;;; editing REXX program files.
33 ;;;
34 ;;; Type C-h m in Emacs for information on how to configurate
35 ;;; the rexx-mode, or see rexx-mode.doc.
36 ;;;
37 ;;; Put the following lines into your .emacs and rexx-mode
38 ;;; will be automatically loaded when editing a REXX program.
39 ;;; If rexx-mode shall be used for files with other extensions
40 ;;; you can create more (cons ...) lines with these extensions.
41 ;;;
42 ;;; (autoload 'rexx-mode "rexx-mode" "REXX mode" nil t)
43 ;;; (setq auto-mode-alist
44 ;;; (append
45 ;;; (list (cons "\\.rexx$" 'rexx-mode)
46 ;;; (cons "\\.elx$" 'rexx-mode)
47 ;;; (cons "\\.ncomm$" 'rexx-mode)
48 ;;; (cons "\\.cpr$" 'rexx-mode)
49 ;;; )
50 ;;; auto-mode-alist))
51 ;;;
52 ;;; HISTORY
53 ;;; 93-01-07 V0.1 ALi Works for the first time.
54 ;;; 92-01-11 V0.2 ALi rexx-calc-indent totally rewritten.
55 ;;; 93-03-08 V0.3 JB rexx-indent-and-newline-and-indent added.
56 ;;; Abbrev-table containing 173 entries created.
57 ;;; rexx-check-expansion added.
58 ;;; rexx-mode enables use of abbrev-table.
59 ;;; 93-03-15 V0.4 ALi abbrev-mode removed, better to call
60 ;;; (abbrev-mode 1) from the hook.
61 ;;; case-fold-search set to t to recognize capital
62 ;;; letters in keywords.
63 ;;; Old (setq case-fold-search nil) removed which
64 ;;; prevented the recognition of END.
65 ;;; rexx-indent-and-newline-and-indent renamed to
66 ;;; rexx-indent-newline-indent.
67 ;;; rexx-i-n-i now only expands abbrevs when
68 ;;; buffer is in abbrev-mode.
69 ;;; New rexx-newline-and-indent added.
70 ;;; 93-03-20 ALi A serious bug in the routine for checking
71 ;;; strings and comments found and fixed.
72 ;;; V1.0 Relesed!
73 ;;;
74
75
76 (provide 'rexx-mode)
77
78 (defconst rexx-indent 8
79 "*This variable contains the indentation in rexx-mode.")
80
81 (defconst rexx-end-indent 0
82 "*This variable indicates the relative position of the \"end\" in REXX mode.")
83
84 (defconst rexx-cont-indent 8
85 "*This variable indicates how far a continued line shall be intended.")
86
87 (defconst rexx-comment-col 32
88 "*This variable gives the desired comment column
89 for comments to the right of text.")
90
91 (defconst rexx-tab-always-indent t
92 "*Non-nil means TAB in REXX mode should always reindent the current line,
93 regardless of where in the line point is when the TAB command is used.")
94
95 (defconst rexx-special-regexp
96 ".*\\(,\\|then\\|else\\)[ \t]*\\(/\\*.*\\*/\\)?[ \t]*$"
97 "*Regular expression for parsing lines which shall be followed by
98 a extra indention")
99
100 (defconst rexx-font-lock-keywords
101 (purecopy
102 (list
103 (cons (concat "\\<\\("
104 (mapconcat 'identity
105 '("address" "arg" "break" "call" "do" "drop" "echo" "else" "end"
106 "exit" "if" "interpret" "iterate" "leave" "nop" "numeric"
107 "options" "otherwise" "parse" "procedure" "pull" "push" "queue"
108 "return" "say" "select" "shell" "signal" "then" "trace" "upper"
109 "when" "value" "to" "by" "for" "forever" "while" "until" "form"
110 "digits" "fuzz" "scientific" "engineering" "failat" "prompt"
111 "results" "upper" "external" "source" "with" "command"
112 "function" "var" "version" "expose" "on" "off")
113 "\\|") "\\)\\>") 'font-lock-keyword-face)
114 '("\\(\\sw+\\):" 1 font-lock-function-name-face)))
115 "Additional expressions to highlight in Rexx mode.")
116 (put 'rexx-mode 'font-lock-defaults '(rexx-font-lock-keywords))
117
118 (defvar rexx-mode-map nil
119 "Keymap for rexx-mode.")
120 (if rexx-mode-map
121 nil
122 (setq rexx-mode-map (make-sparse-keymap))
123 (define-key rexx-mode-map "\t" 'rexx-indent-command)
124 (define-key rexx-mode-map "\C-m" 'rexx-indent-and-newline)
125 (define-key rexx-mode-map 'backspace 'backward-delete-char-untabify)
126 (define-key rexx-mode-map "\C-c\C-p" 'rexx-find-matching-do)
127 (define-key rexx-mode-map "\C-c\C-c" 'rexx-debug)
128 )
129
130 (defvar rexx-mode-syntax-table nil
131 "Syntax table in use in REXX-mode buffers.")
132
133 (if rexx-mode-syntax-table
134 ()
135 (setq rexx-mode-syntax-table (make-syntax-table))
136 (modify-syntax-entry ?\\ "\\" rexx-mode-syntax-table)
137 (modify-syntax-entry ?/ ". 14" rexx-mode-syntax-table)
138 (modify-syntax-entry ?* ". 23" rexx-mode-syntax-table)
139 (modify-syntax-entry ?+ "." rexx-mode-syntax-table)
140 (modify-syntax-entry ?- "." rexx-mode-syntax-table)
141 (modify-syntax-entry ?= "." rexx-mode-syntax-table)
142 (modify-syntax-entry ?% "." rexx-mode-syntax-table)
143 (modify-syntax-entry ?< "." rexx-mode-syntax-table)
144 (modify-syntax-entry ?> "." rexx-mode-syntax-table)
145 (modify-syntax-entry ?& "." rexx-mode-syntax-table)
146 (modify-syntax-entry ?| "." rexx-mode-syntax-table)
147 (modify-syntax-entry ?. "_" rexx-mode-syntax-table)
148 (modify-syntax-entry ?\' "\"" rexx-mode-syntax-table))
149
150 (defvar rexx-mode-abbrev-table nil
151 "*Abbrev table in use in rexx-mode buffers.")
152
153 (if rexx-mode-abbrev-table
154 nil
155 (define-abbrev-table 'rexx-mode-abbrev-table '(
156 ("address" "ADDRESS" rexx-check-expansion 0)
157 ("arg" "ARG" rexx-check-expansion 0)
158 ("break" "BREAK" rexx-check-expansion 0)
159 ("call" "CALL" rexx-check-expansion 0)
160 ("do" "DO" rexx-check-expansion 0)
161 ("drop" "DROP" rexx-check-expansion 0)
162 ("echo" "ECHO" rexx-check-expansion 0)
163 ("else" "ELSE" rexx-check-expansion 0)
164 ("end" "END" rexx-check-expansion 0)
165 ("exit" "EXIT" rexx-check-expansion 0)
166 ("if" "IF" rexx-check-expansion 0)
167 ("interpret" "INTERPRET" rexx-check-expansion 0)
168 ("iterate" "ITERATE" rexx-check-expansion 0)
169 ("leave" "LEAVE" rexx-check-expansion 0)
170 ("nop" "NOP" rexx-check-expansion 0)
171 ("numeric" "NUMERIC" rexx-check-expansion 0)
172 ("options" "OPTIONS" rexx-check-expansion 0)
173 ("otherwise" "OTHERWISE" rexx-check-expansion 0)
174 ("parse" "PARSE" rexx-check-expansion 0)
175 ("procedure" "PROCEDURE" rexx-check-expansion 0)
176 ("pull" "PULL" rexx-check-expansion 0)
177 ("push" "PUSH" rexx-check-expansion 0)
178 ("queue" "QUEUE" rexx-check-expansion 0)
179 ("return" "RETURN" rexx-check-expansion 0)
180 ("say" "SAY" rexx-check-expansion 0)
181 ("select" "SELECT" rexx-check-expansion 0)
182 ("shell" "SHELL" rexx-check-expansion 0)
183 ("signal" "SIGNAL" rexx-check-expansion 0)
184 ("then" "THEN" rexx-check-expansion 0)
185 ("trace" "TRACE" rexx-check-expansion 0)
186 ("upper" "UPPER" rexx-check-expansion 0)
187 ("when" "WHEN" rexx-check-expansion 0)
188 ("value" "VALUE" rexx-check-expansion 0)
189 ("to" "TO" rexx-check-expansion 0)
190 ("by" "BY" rexx-check-expansion 0)
191 ("for" "FOR" rexx-check-expansion 0)
192 ("forever" "FOREVER" rexx-check-expansion 0)
193 ("while" "WHILE" rexx-check-expansion 0)
194 ("until" "UNTIL" rexx-check-expansion 0)
195 ("form" "FORM" rexx-check-expansion 0)
196 ("digits" "DIGITS" rexx-check-expansion 0)
197 ("fuzz" "FUZZ" rexx-check-expansion 0)
198 ("scientific" "SCIENTIFIC" rexx-check-expansion 0)
199 ("engineering" "ENGINEERING" rexx-check-expansion 0)
200 ("failat" "FAILAT" rexx-check-expansion 0)
201 ("prompt" "PROMPT" rexx-check-expansion 0)
202 ("results" "RESULTS" rexx-check-expansion 0)
203 ("upper" "UPPER" rexx-check-expansion 0)
204 ("external" "EXTERNAL" rexx-check-expansion 0)
205 ("source" "SOURCE" rexx-check-expansion 0)
206 ("with" "WITH" rexx-check-expansion 0)
207 ("command" "COMMAND" rexx-check-expansion 0)
208 ("function" "FUNCTION" rexx-check-expansion 0)
209 ("var" "VAR" rexx-check-expansion 0)
210 ("version" "VERSION" rexx-check-expansion 0)
211 ("expose" "EXPOSE" rexx-check-expansion 0)
212 ("on" "ON" rexx-check-expansion 0)
213 ("off" "OFF" rexx-check-expansion 0)
214 ("abbrev" "ABBREV" rexx-check-expansion 0)
215 ("abs" "ABS" rexx-check-expansion 0)
216 ("addlib" "ADDLIB" rexx-check-expansion 0)
217 ("b2c" "B2C" rexx-check-expansion 0)
218 ("bitand" "BITAND" rexx-check-expansion 0)
219 ("bitchg" "BITCHG" rexx-check-expansion 0)
220 ("bitclr" "BITCLR" rexx-check-expansion 0)
221 ("bitcomp" "BITCOMP" rexx-check-expansion 0)
222 ("bitor" "BITOR" rexx-check-expansion 0)
223 ("bittst" "BITTST" rexx-check-expansion 0)
224 ("bitset" "BITSET" rexx-check-expansion 0)
225 ("c2b" "C2B" rexx-check-expansion 0)
226 ("c2d" "C2D" rexx-check-expansion 0)
227 ("c2x" "C2X" rexx-check-expansion 0)
228 ("center" "CENTER" rexx-check-expansion 0)
229 ("centre" "CENTRE" rexx-check-expansion 0)
230 ("close" "CLOSE" rexx-check-expansion 0)
231 ("compress" "COMPRESS" rexx-check-expansion 0)
232 ("compare" "COMPARE" rexx-check-expansion 0)
233 ("copies" "COPIES" rexx-check-expansion 0)
234 ("d2c" "D2C" rexx-check-expansion 0)
235 ("datatype" "DATATYPE" rexx-check-expansion 0)
236 ("delstr" "DELSTR" rexx-check-expansion 0)
237 ("delword" "DELWORD" rexx-check-expansion 0)
238 ("eof" "EOF" rexx-check-expansion 0)
239 ("errortext" "ERRORTEXT" rexx-check-expansion 0)
240 ("exists" "EXISTS" rexx-check-expansion 0)
241 ("export" "EXPORT" rexx-check-expansion 0)
242 ("freespace" "FREESPACE" rexx-check-expansion 0)
243 ("getclip" "GETCLIP" rexx-check-expansion 0)
244 ("getspace" "GETSPACE" rexx-check-expansion 0)
245 ("hash" "HASH" rexx-check-expansion 0)
246 ("import" "IMPORT" rexx-check-expansion 0)
247 ("index" "INDEX" rexx-check-expansion 0)
248 ("insert" "INSERT" rexx-check-expansion 0)
249 ("lastpos" "LASTPOS" rexx-check-expansion 0)
250 ("left" "LEFT" rexx-check-expansion 0)
251 ("length" "LENGTH" rexx-check-expansion 0)
252 ("max" "MAX" rexx-check-expansion 0)
253 ("min" "MIN" rexx-check-expansion 0)
254 ("open" "OPEN" rexx-check-expansion 0)
255 ("overlay" "OVERLAY" rexx-check-expansion 0)
256 ("pos" "POS" rexx-check-expansion 0)
257 ("pragma" "PRAGMA" rexx-check-expansion 0)
258 ("random" "RANDOM" rexx-check-expansion 0)
259 ("randu" "RANDU" rexx-check-expansion 0)
260 ("readch" "READCH" rexx-check-expansion 0)
261 ("readln" "READLN" rexx-check-expansion 0)
262 ("remlib" "REMLIB" rexx-check-expansion 0)
263 ("reverse" "REVERSE" rexx-check-expansion 0)
264 ("right" "RIGHT" rexx-check-expansion 0)
265 ("seek" "SEEK" rexx-check-expansion 0)
266 ("setclip" "SETCLIP" rexx-check-expansion 0)
267 ("show" "SHOW" rexx-check-expansion 0)
268 ("sign" "SIGN" rexx-check-expansion 0)
269 ("space" "SPACE" rexx-check-expansion 0)
270 ("storage" "STORAGE" rexx-check-expansion 0)
271 ("strip" "STRIP" rexx-check-expansion 0)
272 ("substr" "SUBSTR" rexx-check-expansion 0)
273 ("subword" "SUBWORD" rexx-check-expansion 0)
274 ("symbol" "SYMBOL" rexx-check-expansion 0)
275 ("time" "TIME" rexx-check-expansion 0)
276 ("trace" "TRACE" rexx-check-expansion 0)
277 ("translate" "TRANSLATE" rexx-check-expansion 0)
278 ("trim" "TRIM" rexx-check-expansion 0)
279 ("verify" "VERIFY" rexx-check-expansion 0)
280 ("word" "WORD" rexx-check-expansion 0)
281 ("wordindex" "WORDINDEX" rexx-check-expansion 0)
282 ("wordlength" "WORDLENGTH" rexx-check-expansion 0)
283 ("words" "WORDS" rexx-check-expansion 0)
284 ("writech" "WRITECH" rexx-check-expansion 0)
285 ("writeln" "WRITELN" rexx-check-expansion 0)
286 ("x2c" "X2C" rexx-check-expansion 0)
287 ("xrange" "XRANGE" rexx-check-expansion 0)
288 ("allocmem" "ALLOCMEM" rexx-check-expansion 0)
289 ("baddr" "BADDR" rexx-check-expansion 0)
290 ("bitxor" "BITXOR" rexx-check-expansion 0)
291 ("break_c" "BREAK_C" rexx-check-expansion 0)
292 ("break_d" "BREAK_D" rexx-check-expansion 0)
293 ("break_e" "BREAK_E" rexx-check-expansion 0)
294 ("break_f" "BREAK_F" rexx-check-expansion 0)
295 ("cache" "CACHE" rexx-check-expansion 0)
296 ("closeport" "CLOSEPORT" rexx-check-expansion 0)
297 ("d2x" "D2X" rexx-check-expansion 0)
298 ("date" "DATA" rexx-check-expansion 0)
299 ("delay" "DELAY" rexx-check-expansion 0)
300 ("delete" "DELETE" rexx-check-expansion 0)
301 ("error" "ERROR" rexx-check-expansion 0)
302 ("failure" "FAILURE" rexx-check-expansion 0)
303 ("find" "FIND" rexx-check-expansion 0)
304 ("forbid" "FORBID" rexx-check-expansion 0)
305 ("freemem" "FREEMEM" rexx-check-expansion 0)
306 ("getarg" "GETARG" rexx-check-expansion 0)
307 ("getpkt" "GETPKT" rexx-check-expansion 0)
308 ("halt" "HALT" rexx-check-expansion 0)
309 ("ioerr" "IOERR" rexx-check-expansion 0)
310 ("lines" "LINES" rexx-check-expansion 0)
311 ("makedir" "MAKEDIR" rexx-check-expansion 0)
312 ("next" "NEXT" rexx-check-expansion 0)
313 ("novalue" "NOVALUE" rexx-check-expansion 0)
314 ("null" "NULL" rexx-check-expansion 0)
315 ("offset" "OFFSET" rexx-check-expansion 0)
316 ("openport" "OPENPORT" rexx-check-expansion 0)
317 ("permit" "PERMIT" rexx-check-expansion 0)
318 ("rename" "RENAME" rexx-check-expansion 0)
319 ("reply" "REPLY" rexx-check-expansion 0)
320 ("showdir" "SHOWDIR" rexx-check-expansion 0)
321 ("showlist" "SHOWLIST" rexx-check-expansion 0)
322 ("sourceline" "SOURCELINE" rexx-check-expansion 0)
323 ("statef" "STATEF" rexx-check-expansion 0)
324 ("syntax" "SYNTAX" rexx-check-expansion 0)
325 ("trunc" "TRUNC" rexx-check-expansion 0)
326 ("typepkt" "TYPEPKT" rexx-check-expansion 0)
327 ("waitpkt" "WAITPKT" rexx-check-expansion 0)
328 ("x2d" "X2D" rexx-check-expansion 0))))
329
330 ;;;###autoload
331 (defun rexx-mode ()
332 "Major mode for editing REXX code.
333 \\{rexx-mode-map}
334
335 Variables controlling indentation style:
336 rexx-indent
337 The basic indentation for do-blocks.
338 rexx-end-indent
339 The relative offset of the \"end\" statement. 0 places it in the
340 same column as the statements of the block. Setting it to the same
341 value as rexx-indent places the \"end\" under the do-line.
342 rexx-cont-indent
343 The indention for lines following \"then\", \"else\" and \",\"
344 (continued) lines.
345 rexx-tab-always-indent
346 Non-nil means TAB in REXX mode should always reindent the current
347 line, regardless of where in the line the point is when the TAB
348 command is used.
349
350 If you have set rexx-end-indent to a nonzero value, you probably want to
351 remap RETURN to rexx-indent-newline-indent. It makes sure that lines
352 indents correctly when you press RETURN.
353
354 An extensive abbrevation table consisting of all the keywords of REXX are
355 supplied. Expanded keywords are converted into upper case making it
356 easier to distinguish them. To use this feature the buffer must be in
357 abbrev-mode. (See example below.)
358
359 Turning on REXX mode calls the value of the variable rexx-mode-hook with
360 no args, if that value is non-nil.
361
362 For example:
363 (setq rexx-mode-hook '(lambda ()
364 (setq rexx-indent 4)
365 (setq rexx-end-indent 4)
366 (setq rexx-cont-indent 4)
367 (local-set-key \"\\C-m\" 'rexx-indent-newline-indent)
368 (abbrev-mode 1)
369 ))
370
371 will make the END aligned with the DO/SELECT. It will indent blocks and
372 IF-statenents four steps and make sure that the END jumps into the
373 correct position when RETURN is pressed. Finaly it will use the abbrev
374 table to convert all REXX keywords into upper case."
375 (interactive)
376 (kill-all-local-variables)
377 (use-local-map rexx-mode-map)
378 (set-syntax-table rexx-mode-syntax-table)
379 (setq major-mode 'rexx-mode)
380 (setq mode-name "REXX")
381 (setq local-abbrev-table rexx-mode-abbrev-table)
382 (make-local-variable 'case-fold-search)
383 (setq case-fold-search t)
384 (make-local-variable 'paragraph-start)
385 (setq paragraph-start (concat "^$\\|" page-delimiter))
386 (make-local-variable 'paragraph-separate)
387 (setq paragraph-separate paragraph-start)
388 (make-local-variable 'paragraph-ignore-fill-prefix)
389 (setq paragraph-ignore-fill-prefix t)
390 (make-local-variable 'indent-line-function)
391 (setq indent-line-function 'rexx-indent-command)
392 (make-local-variable 'parse-sexp-ignore-comments)
393 (setq parse-sexp-ignore-comments t)
394 (make-local-variable 'comment-start)
395 (setq comment-start "/* ")
396 (make-local-variable 'comment-end)
397 (setq comment-end " */")
398 (make-local-variable 'comment-column)
399 (setq comment-column 32)
400 (make-local-variable 'comment-start-skip)
401 (setq comment-start-skip "/\\*+ *")
402 (make-local-variable 'comment-indent-hook)
403 (setq comment-indent-hook 'rexx-comment-indent)
404 (run-hooks 'rexx-mode-hook))
405
406
407 (defun rexx-indent-command (&optional whole-exp)
408 "Indent the current line as REXX code."
409 (interactive "P")
410 (if whole-exp
411 (let ((shift-amt (rexx-indent-line))
412 beg
413 end)
414 (save-excursion
415 (if rexx-tab-always-indent
416 (beginning-of-line))
417 (setq beg (point))
418 (forward-sexp 1)
419 (setq end (point))
420 (goto-char beg)
421 (forward-line 1)
422 (setq beg (point)))
423 (if (> end beg)
424 (indent-code-rigidly beg end shift-amt)))
425 (if (and (not rexx-tab-always-indent)
426 (save-excursion
427 (skip-chars-backward " \t")
428 (not (bolp))))
429 (insert-tab)
430 (rexx-indent-line))))
431
432 (defun rexx-indent-line ()
433 "Indent the current line as REXX code.
434 Return the amount the indentation changed by."
435 (let ((indent (rexx-calc-indent))
436 beg
437 shift-amt
438 (pos (- (point-max) (point))))
439 (beginning-of-line)
440 (setq beg (point))
441 (cond ((eq indent nil) (setq indent (current-indentation)))
442 ((eq indent t) (setq indent (rexx-calculate-indent-within-comment)))
443 ((looking-at "[ \t]*#") (setq indent 0))
444 (t (skip-chars-forward " \t")
445 (if (listp indent) (setq indent (car indent)))
446 ;; /* Sprekspecifik kod! */
447 (if (looking-at "end") (setq indent (- indent rexx-end-indent)))))
448 (skip-chars-forward " \t")
449 (setq shift-amt (- indent (current-column)))
450 (if (zerop shift-amt)
451 (if (> (- (point-max) pos) (point))
452 (goto-char (- (point-max) pos)))
453 (delete-region beg (point))
454 (indent-to indent)
455 (if (> (- (point-max) pos) (point))
456 (goto-char (- (point-max) pos))))
457 shift-amt))
458
459 (defun rexx-calc-indent ()
460 "Return the appropriate indentation for this line as an int."
461 (save-excursion
462 (beginning-of-line)
463 (let ((block (rexx-find-environment))
464 beg
465 state
466 indent)
467 (save-excursion (setq state (rexx-inside-comment-or-string)))
468 (cond ((or (nth 3 state) (nth 4 state))
469 (nth 4 state)) ;; Inside a comment or string
470 (t
471 ;; Find line to indent current line after.
472 (rexx-backup-to-noncomment 1)
473 (beginning-of-line)
474 (setq beg (rexx-find-environment))
475 (while (> beg block)
476 (goto-char beg)
477 (beginning-of-line)
478 (setq beg (rexx-find-environment)))
479
480 (if (> (point) block)
481 ;; Check to see if we shall make a special indention
482 (if (looking-at rexx-special-regexp)
483 (+ (current-indentation) rexx-cont-indent)
484 ;; If not, find the basic indention by stepping
485 ;; by all special indented lines.
486 (progn
487 (setq indent (current-indentation))
488 (rexx-backup-to-noncomment 1)
489 (beginning-of-line)
490 (while (looking-at rexx-special-regexp)
491 (setq indent (current-indentation))
492 (rexx-backup-to-noncomment 1)
493 (beginning-of-line))
494 indent))
495 (if (= 1 block)
496 0
497 ;; Indent after the do-line.
498 (progn
499 (goto-char block)
500 (+ (current-indentation) rexx-indent)))))))))
501
502 (defun rexx-backup-to-noncomment (lim)
503 "Backup the point to the previous noncomment REXX line."
504 (let (stop)
505 (while (not stop)
506 (skip-chars-backward " \t\n\f" lim)
507 (if (and (>= (point) (+ 2 lim))
508 (save-excursion
509 (forward-char -2)
510 (looking-at "\\*/")))
511 (search-backward "/*" lim 'move)
512 (setq stop t)))
513 (>= (point) lim)))
514
515 (defun rexx-find-environment ()
516 "Return the position of the corresponding \"do\" or \"select\".
517 If none found, return the beginning of buffer."
518 (save-excursion
519 (let ((do-level 1)
520 (cont t)
521 state)
522 (while (and cont (not (zerop do-level)))
523 (setq cont (re-search-backward "\\b\\(do\\|select\\|end\\)\\b" 1 t))
524 (save-excursion (setq state (rexx-inside-comment-or-string)))
525 (setq do-level (+ do-level
526 (cond ((or (nth 3 state) (nth 4 state)) 0)
527 ((looking-at "do") -1)
528 ((looking-at "select") -1)
529 ((looking-at "end") +1)
530 (t 0)))))
531
532 (if cont (point) 1))))
533
534 (defun rexx-calculate-indent-within-comment ()
535 "Return the indentation amount for line, assuming that
536 the current line is to be regarded as part of a block comment."
537 (let (end star-start)
538 (save-excursion
539 (beginning-of-line)
540 (skip-chars-forward " \t")
541 (setq star-start (= (following-char) ?\*))
542 (skip-chars-backward " \t\n")
543 (setq end (point))
544 (beginning-of-line)
545 (skip-chars-forward " \t")
546 (and (re-search-forward "/\\*[ \t]*" end t)
547 star-start
548 (goto-char (1+ (match-beginning 0))))
549 (current-column))))
550
551 (defun rexx-comment-indent ()
552 (if (looking-at "^/\\*")
553 0 ;Existing comment at bol stays there.
554 (save-excursion
555 (skip-chars-backward " \t")
556 (max (1+ (current-column)) ;Else indent at comment column
557 comment-column)))) ; except leave at least one space.
558
559 (defun rexx-find-matching-do ()
560 "Set mark, look for the \"do\" or \"select\" for the present block."
561 (interactive)
562 (set-mark-command nil)
563 (beginning-of-line)
564 (goto-char (rexx-find-environment)))
565
566 (defun rexx-check-expansion ()
567 "If abbrev was made within a comment or a string, de-abbrev!"
568 (let ((state (rexx-inside-comment-or-string)))
569 (if (or (nth 3 state) (nth 4 state))
570 (unexpand-abbrev))))
571
572 (defun rexx-inside-comment-or-string ()
573 "Check if the point is inside a comment or a string.
574 It returns the state from parse-partial-sexp for the search that
575 terminated on the points position"
576 (let ((origpoint (point))
577 state)
578 (save-excursion
579 (goto-char 1)
580 (while (> origpoint (point))
581 (setq state (parse-partial-sexp (point) origpoint 0))))
582 state))
583
584 (defun rexx-indent-and-newline ()
585 "New newline-and-indent which expands abbrevs before running
586 a regular newline-and-indent."
587 (interactive)
588 (if abbrev-mode
589 (expand-abbrev))
590 (newline-and-indent))
591
592 (defun rexx-indent-newline-indent ()
593 "New newline-and-indent which expands abbrevs and indent the line
594 before running a regular newline-and-indent."
595 (interactive)
596 (rexx-indent-command)
597 (if abbrev-mode
598 (expand-abbrev))
599 (newline-and-indent))