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