]> code.delx.au - gnu-emacs/blob - lisp/progmodes/dcl-mode.el
Add copyright notice and distribution terms.
[gnu-emacs] / lisp / progmodes / dcl-mode.el
1 ;;; dcl-mode.el --- major mode for editing DCL command files
2
3 ;; Copyright (c) 1997 Free Software Foundation, Inc.
4
5 ;; Author: Odd Gripenstam <gripenstamol@decus.se>
6 ;; Maintainer: Odd Gripenstam <gripenstamol@decus.se>
7 ;; Keywords: DCL editing major-mode languages
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; DCL mode is a package for editing DCL command files. It helps you
29 ;; indent lines, add leading `$' and trailing `-', move around in the
30 ;; code and insert lexical functions.
31 ;;
32 ;; Type `C-h m' when you are editing a .COM file to get more
33 ;; information about this mode.
34 ;;
35 ;; To use templates you will need a version of tempo.el that is at
36 ;; least later than the buggy 1.1.1, which was included with my versions of
37 ;; Emacs. I used version 1.2.4.
38 ;; The latest tempo.el distribution can be fetched from
39 ;; ftp.lysator.liu.se in the directory /pub/emacs.
40 ;; I recommend setting (setq tempo-interactive t). This will make
41 ;; tempo prompt you for values to put in the blank spots in the templates.
42 ;;
43 ;; There is limited support for imenu. The limitation is that you need
44 ;; a version of imenu.el that uses imenu-generic-expression. I found
45 ;; the version I use in Emacs 19.30. (It was *so* much easier to hook
46 ;; into that version than the one in 19.27...)
47 ;;
48 ;; Any feedback will be welcomed. If you write functions for
49 ;; dcl-calc-command-indent-function or dcl-calc-cont-indent-function,
50 ;; please send them to the maintainer.
51 ;;
52 ;;
53 ;; Ideas for improvement:
54 ;; * Change meaning of `left margin' when dcl-tab-always-indent is nil.
55 ;; Consider the following line (`_' is the cursor):
56 ;; $ label: _ command
57 ;; Pressing tab with the cursor at the underline now inserts a tab.
58 ;; This should be part of the left margin and pressing tab should indent
59 ;; the line.
60 ;; * Make M-LFD work properly with comments in all cases. Now it only
61 ;; works on comment-only lines. But what is "properly"? New rules for
62 ;; indenting comments?
63 ;; * Even smarter indentation of continuation lines.
64 ;; * A delete-indentation function (M-^) that joins continued lines,
65 ;; including lines with end line comments?
66 ;; * Handle DECK/EOD.
67 ;; * `indent list' commands: C-M-q, C-u TAB. What is a list in DCL? One
68 ;; complete command line? A block? A subroutine?
69
70 ;;; Code:
71
72 ;;; *** Customization *****************************************************
73
74
75 (defvar dcl-basic-offset 4
76 "*Number of columns to indent a block in DCL.
77 A block is the commands between THEN-ELSE-ENDIF and between the commands
78 dcl-block-begin-regexp and dcl-block-end-regexp.
79
80 The meaning of this variable may be changed if
81 dcl-calc-command-indent-function is set to a function.")
82
83
84 (defvar dcl-continuation-offset 6
85 "*Number of columns to indent a continuation line in DCL.
86 A continuation line is a line that follows a line ending with `-'.
87
88 The meaning of this variable may be changed if
89 dcl-calc-cont-indent-function is set to a function.")
90
91
92 (defvar dcl-margin-offset 8
93 "*Indentation for the first command line in DCL.
94 The first command line in a file or after a SUBROUTINE statement is indented
95 this much. Other command lines are indented the same number of columns as
96 the preceding command line.
97 A command line is a line that starts with `$'.")
98
99
100 (defvar dcl-margin-label-offset 2
101 "*Number of columns to indent a margin label in DCL.
102 A margin label is a label that doesn't begin or end a block, i.e. it
103 doesn't match dcl-block-begin-regexp or dcl-block-end-regexp.")
104
105
106 (defvar dcl-comment-line-regexp "^\\$!"
107 "*Regexp describing the start of a comment line in DCL.
108 Comment lines are not indented.")
109
110
111 (defvar dcl-block-begin-regexp "loop[0-9]*:"
112 "*Regexp describing a command that begins an indented block in DCL.
113 Set to nil to only indent at THEN-ELSE-ENDIF.")
114
115
116 (defvar dcl-block-end-regexp "endloop[0-9]*:"
117 "*Regexp describing a command that ends an indented block in DCL.
118 Set to nil to only indent at THEN-ELSE-ENDIF.")
119
120
121 (defvar dcl-calc-command-indent-function nil
122 "*Function to calculate indentation for a command line in DCL.
123 If this variable is non-nil it is called as a function:
124
125 \(func INDENT-TYPE CUR-INDENT EXTRA-INDENT LAST-POINT THIS-POINT)
126
127 The function must return the number of columns to indent the current line or
128 nil to get the default indentation.
129
130 INDENT-TYPE is a symbol indicating what kind of indentation should be done.
131 It can have the following values:
132 indent the lines indentation should be increased, e.g. after THEN.
133 outdent the lines indentation should be decreased, e.g a line with ENDIF.
134 first-line indentation for the first line in a buffer or SUBROUTINE.
135 CUR-INDENT is the indentation of the preceding command line.
136 EXTRA-INDENT is the default change in indentation for this line
137 \(a negative number for 'outdent).
138 LAST-POINT is the buffer position of the first significant word on the
139 previous line or nil if the current line is the first line.
140 THIS-POINT is the buffer position of the first significant word on the
141 current line.
142
143 If this variable is nil, the indentation is calculated as
144 CUR-INDENT + EXTRA-INDENT.
145
146 This package includes two functions suitable for this:
147 dcl-calc-command-indent-multiple
148 dcl-calc-command-indent-hang
149 ")
150
151
152 (defvar dcl-calc-cont-indent-function 'dcl-calc-cont-indent-relative
153 "*Function to calculate indentation for a continuation line.
154 If this variable is non-nil it is called as a function:
155
156 \(func CUR-INDENT EXTRA-INDENT)
157
158 The function must return the number of columns to indent the current line or
159 nil to get the default indentation.
160
161 If this variable is nil, the indentation is calculated as
162 CUR-INDENT + EXTRA-INDENT.
163
164 This package includes one function suitable for this:
165 dcl-calc-cont-indent-relative
166 ")
167
168
169 (defvar dcl-tab-always-indent t
170 "*Controls the operation of the TAB key in DCL mode.
171 If t, pressing TAB always indents the current line.
172 If nil, pressing TAB indents the current line if point is at the left margin.
173 Data lines (i.e. lines not part of a command line or continuation line) are
174 never indented.")
175
176
177 (defvar dcl-electric-characters t
178 "*Non-nil means reindent immediately when a label, ELSE or ENDIF is inserted.")
179
180
181 (defvar dcl-tempo-comma ", "
182 "*Text to insert when a comma is needed in a template, in DCL mode.")
183
184 (defvar dcl-tempo-left-paren "("
185 "*Text to insert when a left parenthesis is needed in a template in DCL.")
186
187
188 (defvar dcl-tempo-right-paren ")"
189 "*Text to insert when a right parenthesis is needed in a template in DCL.")
190
191 ; I couldn't decide what looked best, so I'll let you decide...
192 ; Remember, you can also customize this with imenu-submenu-name-format.
193 (defvar dcl-imenu-label-labels "Labels"
194 "*Imenu menu title for sub-listing with label names.")
195 (defvar dcl-imenu-label-goto "GOTO"
196 "*Imenu menu title for sub-listing with GOTO statements.")
197 (defvar dcl-imenu-label-gosub "GOSUB"
198 "*Imenu menu title for sub-listing with GOSUB statements.")
199 (defvar dcl-imenu-label-call "CALL"
200 "*Imenu menu title for sub-listing with CALL statements.")
201
202 (defvar dcl-imenu-generic-expression
203 (`
204 ((nil "^\\$[ \t]*\\([A-Za-z0-9_\$]+\\):[ \t]+SUBROUTINE\\b" 1)
205 ((, dcl-imenu-label-labels)
206 "^\\$[ \t]*\\([A-Za-z0-9_\$]+\\):\\([ \t]\\|$\\)" 1)
207 ((, dcl-imenu-label-goto) "\\s-GOTO[ \t]+\\([A-Za-z0-9_\$]+\\)" 1)
208 ((, dcl-imenu-label-gosub) "\\s-GOSUB[ \t]+\\([A-Za-z0-9_\$]+\\)" 1)
209 ((, dcl-imenu-label-call) "\\s-CALL[ \t]+\\([A-Za-z0-9_\$]+\\)" 1)))
210 "*Default imenu generic expression for DCL.
211
212 The default includes SUBROUTINE labels in the main listing and
213 sub-listings for other labels, CALL, GOTO and GOSUB statements.
214 See `imenu-generic-expression' for details.")
215
216
217 (defvar dcl-mode-hook nil
218 "*Hook called by `dcl-mode'.")
219
220
221 ;;; *** Global variables ****************************************************
222
223
224 (defvar dcl-mode-syntax-table nil
225 "Syntax table used in DCL-buffers.")
226 (if dcl-mode-syntax-table
227 ()
228 (setq dcl-mode-syntax-table (make-syntax-table))
229 (modify-syntax-entry ?! "<" dcl-mode-syntax-table) ; comment start
230 (modify-syntax-entry ?\n ">" dcl-mode-syntax-table) ; comment end
231 (modify-syntax-entry ?< "(>" dcl-mode-syntax-table) ; < and ...
232 (modify-syntax-entry ?> ")<" dcl-mode-syntax-table) ; > is a matching pair
233 )
234
235
236 (defvar dcl-mode-map ()
237 "Keymap used in DCL-mode buffers.")
238 (if dcl-mode-map
239 ()
240 (setq dcl-mode-map (make-sparse-keymap))
241 (define-key dcl-mode-map "\e\n" 'dcl-split-line)
242 (define-key dcl-mode-map "\e\t" 'tempo-complete-tag)
243 (define-key dcl-mode-map "\e^" 'dcl-delete-indentation)
244 (define-key dcl-mode-map "\em" 'dcl-back-to-indentation)
245 (define-key dcl-mode-map "\ee" 'dcl-forward-command)
246 (define-key dcl-mode-map "\ea" 'dcl-backward-command)
247 (define-key dcl-mode-map "\e\C-q" 'dcl-indent-command)
248 (define-key dcl-mode-map "\t" 'dcl-tab)
249 (define-key dcl-mode-map ":" 'dcl-electric-character)
250 (define-key dcl-mode-map "F" 'dcl-electric-character)
251 (define-key dcl-mode-map "f" 'dcl-electric-character)
252 (define-key dcl-mode-map "E" 'dcl-electric-character)
253 (define-key dcl-mode-map "e" 'dcl-electric-character)
254 (define-key dcl-mode-map "\C-c\C-o" 'dcl-set-option)
255 (define-key dcl-mode-map "\C-c\C-f" 'tempo-forward-mark)
256 (define-key dcl-mode-map "\C-c\C-b" 'tempo-backward-mark)
257
258 (define-key dcl-mode-map [menu-bar] (make-sparse-keymap))
259 (define-key dcl-mode-map [menu-bar dcl]
260 (cons "DCL" (make-sparse-keymap "DCL")))
261
262 ;; Define these in bottom-up order
263 (define-key dcl-mode-map [menu-bar dcl tempo-backward-mark]
264 '("Previous template mark" . tempo-backward-mark))
265 (define-key dcl-mode-map [menu-bar dcl tempo-forward-mark]
266 '("Next template mark" . tempo-forward-mark))
267 (define-key dcl-mode-map [menu-bar dcl tempo-complete-tag]
268 '("Complete template tag" . tempo-complete-tag))
269 (define-key dcl-mode-map [menu-bar dcl dcl-separator-tempo]
270 '("--"))
271 (define-key dcl-mode-map [menu-bar dcl dcl-save-all-options]
272 '("Save all options" . dcl-save-all-options))
273 (define-key dcl-mode-map [menu-bar dcl dcl-save-nondefault-options]
274 '("Save changed options" . dcl-save-nondefault-options))
275 (define-key dcl-mode-map [menu-bar dcl dcl-set-option]
276 '("Set option" . dcl-set-option))
277 (define-key dcl-mode-map [menu-bar dcl dcl-separator-option]
278 '("--"))
279 (define-key dcl-mode-map [menu-bar dcl dcl-delete-indentation]
280 '("Delete indentation" . dcl-delete-indentation))
281 (define-key dcl-mode-map [menu-bar dcl dcl-split-line]
282 '("Split line" . dcl-split-line))
283 (define-key dcl-mode-map [menu-bar dcl dcl-indent-command]
284 '("Indent command" . dcl-indent-command))
285 (define-key dcl-mode-map [menu-bar dcl dcl-tab]
286 '("Indent line/insert tab" . dcl-tab))
287 (define-key dcl-mode-map [menu-bar dcl dcl-back-to-indentation]
288 '("Back to indentation" . dcl-back-to-indentation))
289 (define-key dcl-mode-map [menu-bar dcl dcl-forward-command]
290 '("End of statement" . dcl-forward-command))
291 (define-key dcl-mode-map [menu-bar dcl dcl-backward-command]
292 '("Beginning of statement" . dcl-backward-command))
293 ;; imenu is only supported for versions with imenu-generic-expression
294 (if (boundp 'imenu-generic-expression)
295 (progn
296 (define-key dcl-mode-map [menu-bar dcl dcl-separator-movement]
297 '("--"))
298 (define-key dcl-mode-map [menu-bar dcl imenu]
299 '("Buffer index menu" . imenu))))
300 )
301
302
303 (defvar dcl-ws-r
304 "\\([ \t]*-[ \t]*\\(!.*\\)*\n\\)*[ \t]*"
305 "Regular expression describing white space in a DCL command line.
306 White space is any number of continued lines with only space,tab,endcomment
307 followed by space or tab.")
308
309
310 (defvar dcl-label-r
311 "[a-zA-Z0-9_\$]*:\\([ \t!]\\|$\\)"
312 "Regular expression describing a label.
313 A label is a name followed by a colon followed by white-space or end-of-line.")
314
315
316 (defvar dcl-cmd-r
317 "^\\$\\(.*-[ \t]*\\(!.*\\)*\n\\)*[^!\"\n]*\\(\".*\\(\"\".*\\)*\"\\)*[^!\"\n]*"
318 "Regular expression describing a DCL command line up to a trailing comment.
319 A line starting with $, optionally followed by continuation lines,
320 followed by the end of the command line.
321 A continuation line is any characters followed by `-',
322 optionally followed by a comment, followed by a newline.")
323
324
325 (defvar dcl-command-regexp
326 "^\\$\\(.*-[ \t]*\\(!.*\\)*\n\\)*.*\\(\".*\\(\"\".*\\)*\"\\)*"
327 "Regular expression describing a DCL command line.
328 A line starting with $, optionally followed by continuation lines,
329 followed by the end of the command line.
330 A continuation line is any characters followed by `-',
331 optionally followed by a comment, followed by a newline.")
332
333
334 (defvar dcl-electric-reindent-regexps
335 (list "endif" "else" dcl-label-r)
336 "*Regexps that can trigger an electric reindent.
337 A list of regexps that will trigger a reindent if the last letter
338 is defined as dcl-electric-character.
339
340 E.g.: if this list contains `endif', the key `f' is defined as
341 dcl-electric-character and the you have just typed the `f' in
342 `endif', the line will be reindented.")
343
344
345 (defvar dcl-option-alist
346 '((dcl-basic-offset dcl-option-value-basic)
347 (dcl-continuation-offset curval)
348 (dcl-margin-offset dcl-option-value-margin-offset)
349 (dcl-margin-label-offset dcl-option-value-offset)
350 (dcl-comment-line-regexp dcl-option-value-comment-line)
351 (dcl-block-begin-regexp curval)
352 (dcl-block-end-regexp curval)
353 (dcl-tab-always-indent toggle)
354 (dcl-electric-characters toggle)
355 (dcl-electric-reindent-regexps curval)
356 (dcl-tempo-comma curval)
357 (dcl-tempo-left-paren curval)
358 (dcl-tempo-right-paren curval)
359 (dcl-calc-command-indent-function curval)
360 (dcl-calc-cont-indent-function curval)
361 (comment-start curval)
362 (comment-start-skip curval)
363 )
364 "Options and default values for dcl-set-option.
365
366 An alist with option variables and functions or keywords to get a
367 default value for the option.
368
369 The keywords are:
370 curval the current value
371 toggle the opposite of the current value (for t/nil)")
372
373
374 (defvar dcl-option-history
375 (mapcar (lambda (option-assoc)
376 (format "%s" (car option-assoc)))
377 dcl-option-alist)
378 "The history list for dcl-set-option.
379 Preloaded with all known option names from dcl-option-alist")
380
381
382 ;; Must be defined after dcl-cmd-r
383 ;; This version is more correct but much slower than the one
384 ;; above. This version won't find GOTOs in comments or text strings.
385 ;(defvar dcl-imenu-generic-expression
386 ; (`
387 ; ((nil "^\\$[ \t]*\\([A-Za-z0-9_\$]+\\):[ \t]+SUBROUTINE\\b" 1)
388 ; ("Labels" "^\\$[ \t]*\\([A-Za-z0-9_\$]+\\):\\([ \t]\\|$\\)" 1)
389 ; ("GOTO" (, (concat dcl-cmd-r "GOTO[ \t]+\\([A-Za-z0-9_\$]+\\)")) 5)
390 ; ("GOSUB" (, (concat dcl-cmd-r
391 ; "GOSUB[ \t]+\\([A-Za-z0-9_\$]+\\)")) 5)
392 ; ("CALL" (, (concat dcl-cmd-r "CALL[ \t]+\\([A-Za-z0-9_\$]+\\)")) 5)))
393 ; "*Default imenu generic expression for DCL.
394
395 ;The default includes SUBROUTINE labels in the main listing and
396 ;sub-listings for other labels, CALL, GOTO and GOSUB statements.
397 ;See `imenu-generic-expression' in a recent (e.g. Emacs 19.30) imenu.el
398 ;for details.")
399
400
401 ;;; *** Mode initialization *************************************************
402
403
404 ;;;###autoload
405 (defun dcl-mode ()
406 "Major mode for editing DCL-files.
407
408 This mode indents command lines in blocks. (A block is commands between
409 THEN-ELSE-ENDIF and between lines matching dcl-block-begin-regexp and
410 dcl-block-end-regexp.)
411
412 Labels are indented to a fixed position unless they begin or end a block.
413 Whole-line comments (matching dcl-comment-line-regexp) are not indented.
414 Data lines are not indented.
415
416 Key bindings:
417
418 \\{dcl-mode-map}
419 Commands not usually bound to keys:
420
421 \\[dcl-save-nondefault-options]\t\tSave changed options
422 \\[dcl-save-all-options]\t\tSave all options
423 \\[dcl-save-option]\t\t\tSave any option
424 \\[dcl-save-mode]\t\t\tSave buffer mode
425
426 Variables controlling indentation style and extra features:
427
428 dcl-basic-offset
429 Extra indentation within blocks.
430
431 dcl-continuation-offset
432 Extra indentation for continued lines.
433
434 dcl-margin-offset
435 Indentation for the first command line in a file or SUBROUTINE.
436
437 dcl-margin-label-offset
438 Indentation for a label.
439
440 dcl-comment-line-regexp
441 Lines matching this regexp will not be indented.
442
443 dcl-block-begin-regexp
444 dcl-block-end-regexp
445 Regexps that match command lines that begin and end, respectively,
446 a block of commmand lines that will be given extra indentation.
447 Command lines between THEN-ELSE-ENDIF are always indented; these variables
448 make it possible to define other places to indent.
449 Set to nil to disable this feature.
450
451 dcl-calc-command-indent-function
452 Can be set to a function that customizes indentation for command lines.
453 Two such functions are included in the package:
454 dcl-calc-command-indent-multiple
455 dcl-calc-command-indent-hang
456
457 dcl-calc-cont-indent-function
458 Can be set to a function that customizes indentation for continued lines.
459 One such function is included in the package:
460 dcl-calc-cont-indent-relative (set by default)
461
462 dcl-tab-always-indent
463 If t, pressing TAB always indents the current line.
464 If nil, pressing TAB indents the current line if point is at the left
465 margin.
466
467 dcl-electric-characters
468 Non-nil causes lines to be indented at once when a label, ELSE or ENDIF is
469 typed.
470
471 dcl-electric-reindent-regexps
472 Use this variable and function dcl-electric-character to customize
473 which words trigger electric indentation.
474
475 dcl-tempo-comma
476 dcl-tempo-left-paren
477 dcl-tempo-right-paren
478 These variables control the look of expanded templates.
479
480 dcl-imenu-generic-expression
481 Default value for imenu-generic-expression. The default includes
482 SUBROUTINE labels in the main listing and sub-listings for
483 other labels, CALL, GOTO and GOSUB statements.
484
485 dcl-imenu-label-labels
486 dcl-imenu-label-goto
487 dcl-imenu-label-gosub
488 dcl-imenu-label-call
489 Change the text that is used as sub-listing labels in imenu.
490
491 Loading this package calls the value of the variable
492 `dcl-mode-load-hook' with no args, if that value is non-nil.
493 Turning on DCL mode calls the value of the variable `dcl-mode-hook'
494 with no args, if that value is non-nil.
495
496
497 The following example uses the default values for all variables:
498
499 $! This is a comment line that is not indented (it matches
500 $! dcl-comment-line-regexp)
501 $! Next follows the first command line. It is indented dcl-margin-offset.
502 $ i = 1
503 $ ! Other comments are indented like command lines.
504 $ ! A margin label indented dcl-margin-label-offset:
505 $ label:
506 $ if i.eq.1
507 $ then
508 $ ! Lines between THEN-ELSE and ELSE-ENDIF are
509 $ ! indented dcl-basic-offset
510 $ loop1: ! This matches dcl-block-begin-regexp...
511 $ ! ...so this line is indented dcl-basic-offset
512 $ text = \"This \" + - ! is a continued line
513 \"lined up with the command line\"
514 $ type sys$input
515 Data lines are not indented at all.
516 $ endloop1: ! This matches dcl-block-end-regexp
517 $ endif
518 $
519 "
520 (interactive)
521 (kill-all-local-variables)
522 (set-syntax-table dcl-mode-syntax-table)
523
524 (make-local-variable 'indent-line-function)
525 (setq indent-line-function 'dcl-indent-line)
526
527 (make-local-variable 'comment-start)
528 (setq comment-start "!")
529
530 (make-local-variable 'comment-end)
531 (setq comment-end "")
532
533 (make-local-variable 'comment-multi-line)
534 (setq comment-multi-line nil)
535
536 ;; This used to be "^\\$[ \t]*![ \t]*" which looks more correct.
537 ;; The drawback was that you couldn't make empty comment lines by pressing
538 ;; C-M-j repeatedly - only the first line became a comment line.
539 ;; This version has the drawback that the "$" can be anywhere in the line,
540 ;; and something inappropriate might be interpreted as a comment.
541 (make-local-variable 'comment-start-skip)
542 (setq comment-start-skip "\\$[ \t]*![ \t]*")
543
544 (if (boundp 'imenu-generic-expression)
545 (setq imenu-generic-expression dcl-imenu-generic-expression))
546 (setq imenu-create-index-function 'dcl-imenu-create-index-function)
547
548 (make-local-variable 'dcl-comment-line-regexp)
549 (make-local-variable 'dcl-block-begin-regexp)
550 (make-local-variable 'dcl-block-end-regexp)
551 (make-local-variable 'dcl-basic-offset)
552 (make-local-variable 'dcl-continuation-offset)
553 (make-local-variable 'dcl-margin-label-offset)
554 (make-local-variable 'dcl-margin-offset)
555 (make-local-variable 'dcl-tab-always-indent)
556 (make-local-variable 'dcl-electric-characters)
557 (make-local-variable 'dcl-calc-command-indent-function)
558 (make-local-variable 'dcl-calc-cont-indent-function)
559 (make-local-variable 'dcl-electric-reindent-regexps)
560
561 (setq major-mode 'dcl-mode)
562 (setq mode-name "DCL")
563 (use-local-map dcl-mode-map)
564 (tempo-use-tag-list 'dcl-tempo-tags)
565 (run-hooks 'dcl-mode-hook))
566
567
568 ;;; *** Movement commands ***************************************************
569
570
571 ;;;-------------------------------------------------------------------------
572 (defun dcl-beginning-of-statement ()
573 "Go to the beginning of the preceding or current command line."
574 (interactive)
575 (re-search-backward dcl-command-regexp nil t))
576
577
578 ;;;-------------------------------------------------------------------------
579 (defun dcl-end-of-statement ()
580 "Go to the end of the next or current command line."
581 (interactive)
582 (if (or (dcl-end-of-command-p)
583 (dcl-beginning-of-command-p)
584 (not (dcl-command-p)))
585 ()
586 (dcl-beginning-of-statement))
587 (re-search-forward dcl-command-regexp nil t))
588
589
590 ;;;-------------------------------------------------------------------------
591 (defun dcl-beginning-of-command ()
592 "Move point to beginning of current command."
593 (interactive)
594 (let ((type (dcl-get-line-type)))
595 (if (and (eq type '$)
596 (bolp))
597 () ; already in the correct position
598 (dcl-beginning-of-statement))))
599
600
601 ;;;-------------------------------------------------------------------------
602 (defun dcl-end-of-command ()
603 "Move point to end of current command or next command if not on a command."
604 (interactive)
605 (let ((type (dcl-get-line-type))
606 (start (point)))
607 (if (or (eq type '$)
608 (eq type '-))
609 (progn
610 (dcl-beginning-of-command)
611 (dcl-end-of-statement))
612 (dcl-end-of-statement))))
613
614
615 ;;;-------------------------------------------------------------------------
616 (defun dcl-backward-command (&optional incl-comment-commands)
617 "Move backward to a command.
618 Move point to the preceding command line that is not a comment line,
619 a command line with only a comment, only contains a `$' or only
620 contains a label.
621
622 Returns point of the found command line or nil if not able to move."
623 (interactive)
624 (let ((start (point))
625 done
626 retval)
627 ;; Find first non-empty command line
628 (while (not done)
629 ;; back up one statement and look at the command
630 (if (dcl-beginning-of-statement)
631 (cond
632 ((and dcl-block-begin-regexp ; might be nil
633 (looking-at (concat "^\\$" dcl-ws-r
634 dcl-block-begin-regexp)))
635 (setq done t retval (point)))
636 ((and dcl-block-end-regexp ; might be nil
637 (looking-at (concat "^\\$" dcl-ws-r
638 dcl-block-end-regexp)))
639 (setq done t retval (point)))
640 ((looking-at dcl-comment-line-regexp)
641 t) ; comment line, one more loop
642 ((and (not incl-comment-commands)
643 (looking-at "\\$[ \t]*!"))
644 t) ; comment only command, loop...
645 ((looking-at "^\\$[ \t]*$")
646 t) ; empty line, one more loop
647 ((not (looking-at
648 (concat "^\\$" dcl-ws-r dcl-label-r dcl-ws-r "$")))
649 (setq done t) ; not a label-only line, exit the loop
650 (setq retval (point))))
651 ;; We couldn't go further back, and we haven't found a command yet.
652 ;; Return to the start positionn
653 (goto-char start)
654 (setq done t)
655 (setq retval nil)))
656 retval))
657
658
659 ;;;-------------------------------------------------------------------------
660 (defun dcl-forward-command (&optional incl-comment-commands)
661 "Move forward to a command.
662 Move point to the end of the next command line that is not a comment line,
663 a command line with only a comment, only contains a `$' or only
664 contains a label.
665
666 Returns point of the found command line or nil if not able to move."
667 (interactive)
668 (let ((start (point))
669 done
670 retval)
671 ;; Find first non-empty command line
672 (while (not done)
673 ;; go forward one statement and look at the command
674 (if (dcl-end-of-statement)
675 (save-excursion
676 (dcl-beginning-of-statement)
677 (cond
678 ((and dcl-block-begin-regexp ; might be nil
679 (looking-at (concat "^\\$" dcl-ws-r
680 dcl-block-begin-regexp)))
681 (setq done t)
682 (setq retval (point)))
683 ((and dcl-block-end-regexp ; might be nil
684 (looking-at (concat "^\\$" dcl-ws-r
685 dcl-block-end-regexp)))
686 (setq done t)
687 (setq retval (point)))
688 ((looking-at dcl-comment-line-regexp)
689 t) ; comment line, one more loop
690 ((and (not incl-comment-commands)
691 (looking-at "\\$[ \t]*!"))
692 t) ; comment only command, loop...
693 ((looking-at "^\\$[ \t]*$")
694 t) ; empty line, one more loop
695 ((not (looking-at
696 (concat "^\\$" dcl-ws-r dcl-label-r dcl-ws-r "$")))
697 (setq done t) ; not a label-only line, exit the loop
698 (setq retval (point)))))
699 ;; We couldn't go further back, and we haven't found a command yet.
700 ;; Return to the start positionn
701 (goto-char start)
702 (setq done t)
703 (setq retval nil)))
704 retval))
705
706
707 ;;;-------------------------------------------------------------------------
708 (defun dcl-back-to-indentation ()
709 "Move point to the first non-whitespace character on this line.
710 Leading $ and labels counts as whitespace in this case.
711 If this is a comment line then move to the first non-whitespace character
712 in the comment.
713
714 Typing \\[dcl-back-to-indentation] several times in a row will move point to other
715 `interesting' points closer to the left margin, and then back to the
716 rightmost point again.
717
718 E.g. on the following line, point would go to the positions indicated
719 by the numbers in order 1-2-3-1-... :
720
721 $ label: command
722 3 2 1"
723 (interactive)
724 (if (eq last-command 'dcl-back-to-indentation)
725 (dcl-back-to-indentation-1 (point))
726 (dcl-back-to-indentation-1)))
727 (defun dcl-back-to-indentation-1 (&optional limit)
728 "Helper function for dcl-back-to-indentation"
729
730 ;; "Indentation points" that we will travel to
731 ;; $ l: ! comment
732 ;; 4 3 2 1
733 ;;
734 ;; $ ! text
735 ;; 3 2 1
736 ;;
737 ;; $ l: command !
738 ;; 3 2 1
739 ;;
740 ;; text
741 ;; 1
742
743 (let* ((default-limit (save-excursion (end-of-line) (1+ (point))))
744 (limit (or limit default-limit))
745 (last-good-point (point))
746 (opoint (point)))
747 ;; Move over blanks
748 (back-to-indentation)
749
750 ;; If we already were at the outermost indentation point then we
751 ;; start searching for the innermost point again.
752 (if (= (point) opoint)
753 (setq limit default-limit))
754
755 (if (< (point) limit)
756 (setq last-good-point (point)))
757
758 (cond
759 ;; Special treatment for comment lines. We are trying to allow
760 ;; things like "$ !*" as comment lines.
761 ((looking-at dcl-comment-line-regexp)
762 (re-search-forward (concat dcl-comment-line-regexp "[ \t]*") limit t)
763 (if (< (point) limit)
764 (setq last-good-point (point))))
765
766 ;; Normal command line
767 ((looking-at "^\\$[ \t]*")
768 ;; Move over leading "$" and blanks
769 (re-search-forward "^\\$[ \t]*" limit t)
770 (if (< (point) limit)
771 (setq last-good-point (point)))
772
773 ;; Move over a label (if it isn't a block begin/end)
774 ;; We must treat block begin/end labels as commands because
775 ;; dcl-set-option relies on it.
776 (if (and (looking-at dcl-label-r)
777 (not (or (and dcl-block-begin-regexp
778 (looking-at dcl-block-begin-regexp))
779 (and dcl-block-end-regexp
780 (looking-at dcl-block-end-regexp)))))
781 (re-search-forward (concat dcl-label-r "[ \t]*") limit t))
782 (if (< (point) limit)
783 (setq last-good-point (point)))
784
785 ;; Move over the beginning of a comment
786 (if (looking-at "![ \t]*")
787 (re-search-forward "![ \t]*" limit t))
788 (if (< (point) limit)
789 (setq last-good-point (point)))))
790 (goto-char last-good-point)))
791
792
793 ;;; *** Support for indentation *********************************************
794
795
796 (defun dcl-get-line-type ()
797 "Determine the type of the current line.
798 Returns one of the following symbols:
799 $ for a complete command line or the beginning of a command line.
800 - for a continuation line
801 $! for a comment line
802 data for a data line
803 empty-data for an empty line following a data line
804 empty-$ for an empty line following a command line"
805 (or
806 ;; Check if it's a comment line.
807 ;; A comment line starts with $!
808 (save-excursion
809 (beginning-of-line)
810 (if (looking-at dcl-comment-line-regexp)
811 '$!))
812 ;; Check if it's a command line.
813 ;; A command line starts with $
814 (save-excursion
815 (beginning-of-line)
816 (if (looking-at "^\\$")
817 '$))
818 ;; Check if it's a continuation line
819 (save-excursion
820 (beginning-of-line)
821 ;; If we're at the beginning of the buffer it can't be a continuation
822 (if (bobp)
823 ()
824 (let ((opoint (point)))
825 (dcl-beginning-of-statement)
826 (re-search-forward dcl-command-regexp opoint t)
827 (if (>= (point) opoint)
828 '-))))
829 ;; Empty lines might be different things
830 (save-excursion
831 (if (and (bolp) (eolp))
832 (if (bobp)
833 'empty-$
834 (forward-line -1)
835 (let ((type (dcl-get-line-type)))
836 (cond
837 ((or (equal type '$) (equal type '$!) (equal type '-))
838 'empty-$)
839 ((equal type 'data)
840 'empty-data))))))
841 ;; Anything else must be a data line
842 (progn 'data)
843 ))
844
845
846 ;;;-------------------------------------------------------------------------
847 (defun dcl-indentation-point ()
848 "Return point of first non-`whitespace' on this line."
849 (save-excursion
850 (dcl-back-to-indentation)
851 (point)))
852
853
854 ;;;---------------------------------------------------------------------------
855 (defun dcl-show-line-type ()
856 "Test dcl-get-line-type."
857 (interactive)
858 (let ((type (dcl-get-line-type)))
859 (cond
860 ((equal type '$)
861 (message "command line"))
862 ((equal type '\?)
863 (message "?"))
864 ((equal type '$!)
865 (message "comment line"))
866 ((equal type '-)
867 (message "continuation line"))
868 ((equal type 'data)
869 (message "data"))
870 ((equal type 'empty-data)
871 (message "empty-data"))
872 ((equal type 'empty-$)
873 (message "empty-$"))
874 (t
875 (message "hupp"))
876 )))
877
878
879 ;;; *** Perform indentation *************************************************
880
881
882 ;;;---------------------------------------------------------------------------
883 (defun dcl-calc-command-indent-multiple
884 (indent-type cur-indent extra-indent last-point this-point)
885 "Indent lines to a multiple of dcl-basic-offset.
886
887 Set dcl-calc-command-indent-function to this function to customize
888 indentation of command lines.
889
890 Command lines that need to be indented beyond the left margin are
891 always indented to a column that is a multiple of dcl-basic-offset, as
892 if tab stops were set at 4, 8, 12, etc.
893
894 This supports a formatting style like this (dcl-margin offset = 2,
895 dcl-basic-offset = 4):
896
897 $ if cond
898 $ then
899 $ if cond
900 $ then
901 $ ! etc
902 "
903 ;; calculate indentation if it's an interesting indent-type,
904 ;; otherwise return nil to get the default indentation
905 (let ((indent))
906 (cond
907 ((equal indent-type 'indent)
908 (setq indent (- cur-indent (% cur-indent dcl-basic-offset)))
909 (setq indent (+ indent extra-indent))))))
910
911
912 ;;;---------------------------------------------------------------------------
913 ;; Some people actually writes likes this. To each his own...
914 (defun dcl-calc-command-indent-hang
915 (indent-type cur-indent extra-indent last-point this-point)
916 "Indent lines as default, but indent THEN, ELSE and ENDIF extra.
917
918 Set dcl-calc-command-indent-function to this function to customize
919 indentation of command lines.
920
921 This function supports a formatting style like this:
922
923 $ if cond
924 $ then
925 $ xxx
926 $ endif
927 $ xxx
928
929 If you use this function you will probably want to add \"then\" to
930 dcl-electric-reindent-regexps and define the key \"n\" as
931 dcl-electric-character.
932 "
933 (let ((case-fold-search t))
934 (save-excursion
935 (cond
936 ;; No indentation, this word is `then': +2
937 ;; last word was endif: -2
938 ((null indent-type)
939 (or (progn
940 (goto-char this-point)
941 (if (looking-at "\\bthen\\b")
942 (+ cur-indent extra-indent 2)))
943 (progn
944 (goto-char last-point)
945 (if (looking-at "\\bendif\\b")
946 (- (+ cur-indent extra-indent) 2)))))
947 ;; Indentation, last word was `then' or `else': -2
948 ((equal indent-type 'indent)
949 (goto-char last-point)
950 (cond
951 ((looking-at "\\bthen\\b")
952 (- (+ cur-indent extra-indent) 2))
953 ((looking-at "\\belse\\b")
954 (- (+ cur-indent extra-indent) 2))))
955 ;; Outdent, this word is `endif' or `else': + 2
956 ((equal indent-type 'outdent)
957 (goto-char this-point)
958 (cond
959 ((looking-at "\\bendif\\b")
960 (+ cur-indent extra-indent 2))
961 ((looking-at "\\belse\\b")
962 (+ cur-indent extra-indent 2))))))))
963
964
965 ;;;---------------------------------------------------------------------------
966 (defun dcl-calc-command-indent ()
967 "Calculate how much the current line shall be indented.
968 The line is known to be a command line.
969
970 Find the indentation of the preceding line and analyze its contents to
971 see if the current lines should be indented.
972 Analyze the current line to see if it should be `outdented'.
973
974 Calculate the indentation of the current line, either with the default
975 method or by calling dcl-calc-command-indent-function if it is
976 non-nil.
977
978 If the current line should be outdented, calculate its indentation,
979 either with the default method or by calling
980 dcl-calc-command-indent-function if it is non-nil.
981
982
983 Rules for default indentation:
984
985 If it is the first line in the buffer, indent dcl-margin-offset.
986
987 Go to the previous command line with a command on it.
988 Find out how much it is indented (cur-indent).
989 Look at the first word on the line to see if the indentation should be
990 adjusted. Skip margin-label, continuations and comments while looking for
991 the first word. Save this buffer position as `last-point'.
992 If the first word after a label is SUBROUTINE, set extra-indent to
993 dcl-margin-offset.
994
995 First word extra-indent
996 THEN +dcl-basic-offset
997 ELSE +dcl-basic-offset
998 block-begin +dcl-basic-offset
999
1000 Then return to the current line and look at the first word to see if the
1001 indentation should be adjusted again. Save this buffer position as
1002 `this-point'.
1003
1004 First word extra-indent
1005 ELSE -dcl-basic-offset
1006 ENDIF -dcl-basic-offset
1007 block-end -dcl-basic-offset
1008
1009
1010 If dcl-calc-command-indent-function is nil or returns nil set
1011 cur-indent to cur-indent+extra-indent.
1012
1013 If an extra adjustment is necessary and if
1014 dcl-calc-command-indent-function is nil or returns nil set cur-indent
1015 to cur-indent+extra-indent.
1016
1017 See also documentation for dcl-calc-command-indent-function.
1018 The indent-type classification could probably be expanded upon.
1019 "
1020 ()
1021 (save-excursion
1022 (beginning-of-line)
1023 (let ((is-block nil)
1024 (case-fold-search t)
1025 cur-indent
1026 (extra-indent 0)
1027 indent-type last-point this-point extra-indent2 cur-indent2
1028 indent-type2)
1029 (if (bobp) ; first line in buffer
1030 (setq cur-indent 0 extra-indent dcl-margin-offset
1031 indent-type 'first-line
1032 this-point (dcl-indentation-point))
1033 (save-excursion
1034 (let (done)
1035 ;; Find first non-empty command line
1036 (while (not done)
1037 ;; back up one statement and look at the command
1038 (if (dcl-beginning-of-statement)
1039 (cond
1040 ((and dcl-block-begin-regexp ; might be nil
1041 (looking-at (concat "^\\$" dcl-ws-r
1042 dcl-block-begin-regexp)))
1043 (setq done t) (setq is-block t))
1044 ((and dcl-block-end-regexp ; might be nil
1045 (looking-at (concat "^\\$" dcl-ws-r
1046 dcl-block-end-regexp)))
1047 (setq done t) (setq is-block t))
1048 ((looking-at dcl-comment-line-regexp)
1049 t) ; comment line, one more loop
1050 ((looking-at "^\\$[ \t]*$")
1051 t) ; empty line, one more loop
1052 ((not (looking-at
1053 (concat "^\\$" dcl-ws-r dcl-label-r dcl-ws-r "$")))
1054 (setq done t))) ; not a label-only line, exit the loop
1055 ;; We couldn't go further back, so this must have been the
1056 ;; first line.
1057 (setq cur-indent dcl-margin-offset
1058 last-point (dcl-indentation-point))
1059 (setq done t)))
1060 ;; Examine the line to get current indentation and possibly a
1061 ;; reason to indent.
1062 (cond
1063 (cur-indent)
1064 ((looking-at (concat "^\\$[ \t]*" dcl-label-r dcl-ws-r
1065 "\\(subroutine\\b\\)"))
1066 (setq cur-indent dcl-margin-offset
1067 last-point (1+ (match-beginning 1))))
1068 (t
1069 ;; Find out how much this line is indented.
1070 ;; Look at comment, continuation character, command but not label
1071 ;; unless it's a block.
1072 (if is-block
1073 (re-search-forward "^\\$[ \t]*")
1074 (re-search-forward (concat "^\\$[ \t]*\\(" dcl-label-r
1075 "\\)*[ \t]*")))
1076 (setq cur-indent (current-column))
1077 ;; Look for a reason to indent: Find first word on this line
1078 (re-search-forward dcl-ws-r)
1079 (setq last-point (point))
1080 (cond
1081 ((looking-at "\\bthen\\b")
1082 (setq extra-indent dcl-basic-offset indent-type 'indent))
1083 ((looking-at "\\belse\\b")
1084 (setq extra-indent dcl-basic-offset indent-type 'indent))
1085 ((and dcl-block-begin-regexp ; might be nil
1086 (looking-at dcl-block-begin-regexp))
1087 (setq extra-indent dcl-basic-offset indent-type 'indent))
1088 ))))))
1089 (setq extra-indent2 0)
1090 ;; We're back at the beginning of the original line.
1091 ;; Look for a reason to outdent: Find first word on this line
1092 (re-search-forward (concat "^\\$" dcl-ws-r))
1093 (setq this-point (dcl-indentation-point))
1094 (cond
1095 ((looking-at "\\belse\\b")
1096 (setq extra-indent2 (- dcl-basic-offset) indent-type2 'outdent))
1097 ((looking-at "\\bendif\\b")
1098 (setq extra-indent2 (- dcl-basic-offset) indent-type2 'outdent))
1099 ((and dcl-block-end-regexp ; might be nil
1100 (looking-at dcl-block-end-regexp))
1101 (setq extra-indent2 (- dcl-basic-offset) indent-type2 'outdent))
1102 ((looking-at (concat dcl-label-r dcl-ws-r "\\(subroutine\\b\\)"))
1103 (setq cur-indent2 0 extra-indent2 dcl-margin-offset
1104 indent-type2 'first-line
1105 this-point (1+ (match-beginning 1)))))
1106 ;; Calculate indent
1107 (setq cur-indent
1108 (or (and dcl-calc-command-indent-function
1109 (funcall dcl-calc-command-indent-function
1110 indent-type cur-indent extra-indent
1111 last-point this-point))
1112 (+ cur-indent extra-indent)))
1113 ;; Calculate outdent
1114 (if indent-type2
1115 (progn
1116 (or cur-indent2 (setq cur-indent2 cur-indent))
1117 (setq cur-indent
1118 (or (and dcl-calc-command-indent-function
1119 (funcall dcl-calc-command-indent-function
1120 indent-type2 cur-indent2 extra-indent2
1121 last-point this-point))
1122 (+ cur-indent2 extra-indent2)))))
1123 cur-indent
1124 )))
1125
1126
1127 ;;;---------------------------------------------------------------------------
1128 (defun dcl-calc-cont-indent-relative (cur-indent extra-indent)
1129 "Indent continuation lines to align with words on previous line.
1130
1131 Indent continuation lines to a position relative to preceding
1132 significant command line elements.
1133
1134 Set `dcl-calc-cont-indent-function' to this function to customize
1135 indentation of continuation lines.
1136
1137 Indented lines will align with either:
1138
1139 * the second word on the command line
1140 $ set default -
1141 [-]
1142 * the word after an asignment
1143 $ a = b + -
1144 d
1145 * the third word if it's a qualifier
1146 $ set terminal/width=80 -
1147 /page=24
1148 * the innermost nonclosed parenthesis
1149 $ if ((a.eq.b .and. -
1150 d.eq.c .or. f$function(xxxx, -
1151 yyy)))
1152 "
1153 (let ((case-fold-search t)
1154 indent)
1155 (save-excursion
1156 (dcl-beginning-of-statement)
1157 (let ((end (save-excursion (forward-line 1) (point))))
1158 ;; Move over blanks and label
1159 (if (re-search-forward (concat "^\\$[ \t]*\\(" dcl-label-r
1160 "\\)*[ \t]*") end t)
1161 (progn
1162 ;; Move over the first word (might be `@filespec')
1163 (if (> (skip-chars-forward "@:[]<>$\\-a-zA-Z0-9_.;" end) 0)
1164 (let (was-assignment)
1165 (skip-chars-forward " \t" end)
1166 ;; skip over assignment if there is one
1167 (if (looking-at ":?==?")
1168 (progn
1169 (setq was-assignment t)
1170 (skip-chars-forward " \t:=" end)))
1171 ;; This could be the position to indent to
1172 (setq indent (current-column))
1173
1174 ;; Move to the next word unless we have seen an
1175 ;; assignment. If it starts with `/' it's a
1176 ;; qualifier and we will indent to that position
1177 (if (and (not was-assignment)
1178 (> (skip-chars-forward "a-zA-Z0-9_" end) 0))
1179 (progn
1180 (skip-chars-forward " \t" end)
1181 (if (= (char-after (point)) ?/)
1182 (setq indent (current-column)))))
1183 ))))))
1184 ;; Now check if there are any parenthesis to adjust to.
1185 ;; If there is, we will indent to the position after the last non-closed
1186 ;; opening parenthesis.
1187 (save-excursion
1188 (beginning-of-line)
1189 (let* ((start (save-excursion (dcl-beginning-of-statement) (point)))
1190 (parse-sexp-ignore-comments t) ; for parse-partial
1191 (par-pos (nth 1 (parse-partial-sexp start (point)))))
1192 (if par-pos ; is nil if no parenthesis was found
1193 (setq indent (save-excursion
1194 (goto-char par-pos)
1195 (1+ (current-column)))))))
1196 indent))
1197
1198
1199 ;;;---------------------------------------------------------------------------
1200 (defun dcl-calc-continuation-indent ()
1201 "Calculate how much the current line shall be indented.
1202 The line is known to be a continuation line.
1203
1204 Go to the previous command line.
1205 Find out how much it is indented."
1206 ;; This was copied without much thought from dcl-calc-command-indent, so
1207 ;; it's a bit clumsy.
1208 ()
1209 (save-excursion
1210 (beginning-of-line)
1211 (if (bobp)
1212 ;; Huh? a continuation line first in the buffer??
1213 dcl-margin-offset
1214 (let ((is-block nil)
1215 (indent))
1216 (save-excursion
1217 ;; Find first non-empty command line
1218 (let ((done))
1219 (while (not done)
1220 (if (dcl-beginning-of-statement)
1221 (cond
1222 ((and dcl-block-begin-regexp
1223 (looking-at (concat "^\\$" dcl-ws-r
1224 dcl-block-begin-regexp)))
1225 (setq done t) (setq is-block t))
1226 ((and dcl-block-end-regexp
1227 (looking-at (concat "^\\$" dcl-ws-r
1228 dcl-block-end-regexp)))
1229 (setq done t) (setq is-block t))
1230 ((looking-at dcl-comment-line-regexp)
1231 t)
1232 ((looking-at "^\\$[ \t]*$")
1233 t)
1234 ((not (looking-at
1235 (concat "^\\$" dcl-ws-r dcl-label-r dcl-ws-r "$")))
1236 (setq done t)))
1237 ;; This must have been the first line.
1238 (setq indent dcl-margin-offset)
1239 (setq done t)))
1240 (if indent
1241 ()
1242 ;; Find out how much this line is indented.
1243 ;; Look at comment, continuation character, command but not label
1244 ;; unless it's a block.
1245 (if is-block
1246 (re-search-forward "^\\$[ \t]*")
1247 (re-search-forward (concat "^\\$[ \t]*\\(" dcl-label-r
1248 "\\)*[ \t]*")))
1249 (setq indent (current-column))
1250 )))
1251 ;; We're back at the beginning of the original line.
1252 (or (and dcl-calc-cont-indent-function
1253 (funcall dcl-calc-cont-indent-function indent
1254 dcl-continuation-offset))
1255 (+ indent dcl-continuation-offset))
1256 ))))
1257
1258
1259 ;;;---------------------------------------------------------------------------
1260 (defun dcl-indent-command-line ()
1261 "Indent a line known to be a command line."
1262 (let ((indent (dcl-calc-command-indent))
1263 (pos (- (point-max) (point))))
1264 (save-excursion
1265 (beginning-of-line)
1266 (re-search-forward "^\\$[ \t]*")
1267 ;; Indent any margin-label if the offset is set
1268 ;; (Don't look at block labels)
1269 (if (and dcl-margin-label-offset
1270 (looking-at dcl-label-r)
1271 (not (and dcl-block-begin-regexp
1272 (looking-at dcl-block-begin-regexp)))
1273 (not (and dcl-block-end-regexp
1274 (looking-at dcl-block-end-regexp))))
1275 (progn
1276 (dcl-indent-to dcl-margin-label-offset)
1277 (re-search-forward dcl-label-r)))
1278 (dcl-indent-to indent 1)
1279 )
1280 ;;
1281 (if (> (- (point-max) pos) (point))
1282 (goto-char (- (point-max) pos)))
1283 ))
1284
1285
1286 ;;;-------------------------------------------------------------------------
1287 (defun dcl-indent-continuation-line ()
1288 "Indent a line known to be a continuation line.
1289
1290 Notice that no special treatment is made for labels. They have to be
1291 on the first part on a command line to be taken into consideration."
1292 (let ((indent (dcl-calc-continuation-indent)))
1293 (save-excursion
1294 (beginning-of-line)
1295 (re-search-forward "^[ \t]*")
1296 (dcl-indent-to indent))
1297 (skip-chars-forward " \t")))
1298
1299
1300 ;;;---------------------------------------------------------------------------
1301 (defun dcl-delete-chars (chars)
1302 "Delete all characters in the set CHARS around point."
1303 (skip-chars-backward chars)
1304 (delete-region (point) (progn (skip-chars-forward chars) (point))))
1305
1306
1307 ;;;---------------------------------------------------------------------------
1308 (defun dcl-indent-line ()
1309 "The DCL version of `indent-line-function'.
1310 Adjusts indentation on the current line. Data lines are not indented."
1311 (let ((type (dcl-get-line-type)))
1312 (cond
1313 ((equal type '$)
1314 (dcl-indent-command-line))
1315 ((equal type '\?)
1316 (message "Unknown line type!"))
1317 ((equal type '$!))
1318 ((equal type 'data))
1319 ((equal type 'empty-data))
1320 ((equal type '-)
1321 (dcl-indent-continuation-line))
1322 ((equal type 'empty-$)
1323 (insert "$" )
1324 (dcl-indent-command-line))
1325 (t
1326 (message "dcl-indent-line: unknown type"))
1327 )))
1328
1329
1330 ;;;-------------------------------------------------------------------------
1331 (defun dcl-indent-command ()
1332 "Indents the complete command line that point is on.
1333 This includes continuation lines."
1334 (interactive "*")
1335 (let ((type (dcl-get-line-type)))
1336 (if (or (equal type '$)
1337 (equal type '-)
1338 (equal type 'empty-$))
1339 (save-excursion
1340 (indent-region (progn (or (looking-at "^\\$")
1341 (dcl-beginning-of-statement))
1342 (point))
1343 (progn (dcl-end-of-statement) (point))
1344 nil)))))
1345
1346
1347 ;;;-------------------------------------------------------------------------
1348 (defun dcl-tab ()
1349 "Insert tab in data lines or indent code.
1350 If `dcl-tab-always-indent' is t, code lines are always indented.
1351 If nil, indent the current line only if point is at the left margin or in
1352 the lines indentation; otherwise insert a tab."
1353 (interactive "*")
1354 (let ((type (dcl-get-line-type))
1355 (start-point (point)))
1356 (cond
1357 ;; Data line : always insert tab
1358 ((or (equal type 'data) (equal type 'empty-data))
1359 (tab-to-tab-stop))
1360 ;; Indent only at start of line
1361 ((not dcl-tab-always-indent) ; nil
1362 (let ((search-end-point
1363 (save-excursion
1364 (beginning-of-line)
1365 (re-search-forward "^\\$?[ \t]*" start-point t))))
1366 (if (or (bolp)
1367 (and search-end-point
1368 (>= search-end-point start-point)))
1369 (dcl-indent-line)
1370 (tab-to-tab-stop))))
1371 ;; Always indent
1372 ((eq dcl-tab-always-indent t) ; t
1373 (dcl-indent-line))
1374 )))
1375
1376
1377 ;;;-------------------------------------------------------------------------
1378 (defun dcl-electric-character (arg)
1379 "Inserts a character and indents if necessary.
1380 Insert a character if the user gave a numeric argument or the flag
1381 `dcl-electric-characters' is not set. If an argument was given,
1382 insert that many characters.
1383
1384 The line is only reindented if the word just typed matches any of the
1385 regexps in `dcl-electric-reindent-regexps'."
1386 (interactive "*P")
1387 (if (or arg (not dcl-electric-characters))
1388 (if arg
1389 (self-insert-command (prefix-numeric-value arg))
1390 (self-insert-command 1))
1391 ;; Insert the character and indent
1392 (self-insert-command 1)
1393 (let ((case-fold-search t))
1394 ;; There must be a better way than (memq t ...).
1395 ;; (apply 'or ...) didn't work
1396 (if (memq t (mapcar 'dcl-was-looking-at dcl-electric-reindent-regexps))
1397 (dcl-indent-line)))))
1398
1399
1400 ;;;-------------------------------------------------------------------------
1401 (defun dcl-indent-to (col &optional minimum)
1402 "Like indent-to, but only indents if indentation would change"
1403 (interactive)
1404 (let (cur-indent collapsed indent)
1405 (save-excursion
1406 (skip-chars-forward " \t")
1407 (setq cur-indent (current-column))
1408 (skip-chars-backward " \t")
1409 (setq collapsed (current-column)))
1410 (setq indent (max col (+ collapsed (or minimum 0))))
1411 (if (/= indent cur-indent)
1412 (progn
1413 (dcl-delete-chars " \t")
1414 (indent-to col minimum)))))
1415
1416
1417 ;;;-------------------------------------------------------------------------
1418 (defun dcl-split-line ()
1419 "Break line at point and insert text to keep the syntax valid.
1420
1421 Inserts continuation marks and splits character strings."
1422 ;; Still don't know what to do with comments at the end of a command line.
1423 (interactive "*")
1424 (let (done
1425 (type (dcl-get-line-type)))
1426 (cond
1427 ((or (equal type '$) (equal type '-))
1428 (let ((info (parse-partial-sexp
1429 (save-excursion (dcl-beginning-of-statement) (point))
1430 (point))))
1431 ;; handle some special cases
1432 (cond
1433 ((nth 3 info) ; in text constant
1434 (insert "\" + -\n\"")
1435 (indent-according-to-mode)
1436 (setq done t))
1437 ((not (nth 4 info)) ; not in comment
1438 (cond
1439 ((and (not (eolp))
1440 (= (char-after (point)) ?\")
1441 (= (char-after (1- (point))) ?\"))
1442 (progn ; a " "" " situation
1443 (forward-char -1)
1444 (insert "\" + -\n\"")
1445 (forward-char 1)
1446 (indent-according-to-mode)
1447 (setq done t)))
1448 ((and (dcl-was-looking-at "[ \t]*-[ \t]*") ; after cont mark
1449 (looking-at "[ \t]*\\(!.*\\)?$"))
1450 ;; Do default below. This might considered wrong if we're
1451 ;; after a subtraction: $ x = 3 - <M-LFD>
1452 )
1453 (t
1454 (delete-horizontal-space)
1455 (insert " -")
1456 (insert "\n") (indent-according-to-mode)
1457 (setq done t))))
1458 ))))
1459 ;; use the normal function for other cases
1460 (if (not done) ; normal M-LFD action
1461 (indent-new-comment-line))))
1462
1463
1464 ;;;-------------------------------------------------------------------------
1465 (defun dcl-delete-indentation (&optional arg)
1466 "Join this line to previous like delete-indentation.
1467 Also remove the continuation mark if easily detected."
1468 (interactive "*P")
1469 (delete-indentation arg)
1470 (let ((type (dcl-get-line-type)))
1471 (if (and (or (equal type '$)
1472 (equal type '-)
1473 (equal type 'empty-$))
1474 (not (bobp))
1475 (= (char-after (1- (point))) ?-))
1476 (progn
1477 (delete-backward-char 1)
1478 (fixup-whitespace)))))
1479
1480
1481 ;;; *** Set options *********************************************************
1482
1483
1484 ;;;-------------------------------------------------------------------------
1485 (defun dcl-option-value-basic (option-assoc)
1486 "Guess a value for basic-offset."
1487 (save-excursion
1488 (dcl-beginning-of-command)
1489 (let* (;; current lines indentation
1490 (this-indent (save-excursion
1491 (dcl-back-to-indentation)
1492 (current-column)))
1493 ;; previous lines indentation
1494 (prev-indent (save-excursion
1495 (if (dcl-backward-command)
1496 (progn
1497 (dcl-back-to-indentation)
1498 (current-column)))))
1499 (next-indent (save-excursion
1500 (dcl-end-of-command)
1501 (if (dcl-forward-command)
1502 (progn
1503 (dcl-beginning-of-command)
1504 (dcl-back-to-indentation)
1505 (current-column)))))
1506 (diff (if prev-indent
1507 (abs (- this-indent prev-indent)))))
1508 (cond
1509 ((and diff
1510 (/= diff 0))
1511 diff)
1512 ((and next-indent
1513 (/= (- this-indent next-indent) 0))
1514 (abs (- this-indent next-indent)))
1515 (t
1516 dcl-basic-offset)))))
1517
1518
1519 ;;;-------------------------------------------------------------------------
1520 (defun dcl-option-value-offset (option-assoc)
1521 "Guess a value for an offset.
1522 Find the column of the first non-blank character on the line.
1523 Returns a number as a string."
1524 (save-excursion
1525 (beginning-of-line)
1526 (re-search-forward "^$[ \t]*" nil t)
1527 (current-column)))
1528
1529
1530 ;;;-------------------------------------------------------------------------
1531 (defun dcl-option-value-margin-offset (option-assoc)
1532 "Guess a value for margin offset.
1533 Find the column of the first non-blank character on the line, not
1534 counting labels.
1535 Returns a number as a string."
1536 (save-excursion
1537 (beginning-of-line)
1538 (dcl-back-to-indentation)
1539 (current-column)))
1540
1541
1542 ;;;-------------------------------------------------------------------------
1543 (defun dcl-option-value-comment-line (option-assoc)
1544 "Guess a value for `dcl-comment-line-regexp'.
1545 Must return a string."
1546 ;; Should we set comment-start and comment-start-skip as well?
1547 ;; If someone wants `$!&' as a comment line, C-M-j won't work well if
1548 ;; they aren't set.
1549 ;; This must be done after the user has given the real value in
1550 ;; dcl-set-option.
1551 (format
1552 "%S"
1553 (save-excursion
1554 (beginning-of-line)
1555 ;; We could search for "^\\$.*!+[^ \t]*", but, as noted above, we
1556 ;; can't handle that case very good, so there is no point in
1557 ;; suggesting it.
1558 (if (looking-at "^\\$[^!\n]*!")
1559 (let ((regexp (buffer-substring (match-beginning 0) (match-end 0))))
1560 (concat "^" (regexp-quote regexp)))
1561 dcl-comment-line-regexp))))
1562
1563
1564 ;;;-------------------------------------------------------------------------
1565 (defun dcl-guess-option-value (option)
1566 "Guess what value the user would like to give the symbol option."
1567 (let* ((option-assoc (assoc option dcl-option-alist))
1568 (option (car option-assoc))
1569 (action (car (cdr option-assoc)))
1570 (value (cond
1571 ((fboundp action)
1572 (funcall action option-assoc))
1573 ((eq action 'toggle)
1574 (not (eval option)))
1575 ((eq action 'curval)
1576 (cond ((or (stringp (symbol-value option))
1577 (numberp (symbol-value option)))
1578 (format "%S" (symbol-value option)))
1579 (t
1580 (format "'%S" (symbol-value option))))))))
1581 ;; format the value as a string if not already done
1582 (if (stringp value)
1583 value
1584 (format "%S" value))))
1585
1586
1587 ;;;-------------------------------------------------------------------------
1588 (defun dcl-guess-option ()
1589 "Guess what option the user wants to set by looking around in the code.
1590 Returns the name of the option variable as a string."
1591 (let ((case-fold-search t))
1592 (cond
1593 ;; Continued line
1594 ((eq (dcl-get-line-type) '-)
1595 "dcl-calc-cont-indent-function")
1596 ;; Comment line
1597 ((save-excursion
1598 (beginning-of-line)
1599 (looking-at "^\\$[ \t]*!"))
1600 "dcl-comment-line-regexp")
1601 ;; Margin offset: subroutine statement or first line in buffer
1602 ;; Test this before label indentation to detect a subroutine
1603 ((save-excursion
1604 (beginning-of-line)
1605 (or (looking-at (concat "^\\$[ \t]*" dcl-label-r dcl-ws-r
1606 "subroutine"))
1607 (save-excursion
1608 (not (dcl-backward-command t)))))
1609 "dcl-margin-offset")
1610 ;; Margin offset: on command line after subroutine statement
1611 ((save-excursion
1612 (beginning-of-line)
1613 (and (eq (dcl-get-line-type) '$)
1614 (dcl-backward-command)
1615 (looking-at (concat "^\\$[ \t]*" dcl-label-r dcl-ws-r
1616 "subroutine"))))
1617 "dcl-margin-offset")
1618 ;; Label indentation
1619 ((save-excursion
1620 (beginning-of-line)
1621 (and (looking-at (concat "^\\$[ \t]*" dcl-label-r))
1622 (not (and dcl-block-begin-regexp
1623 (looking-at (concat "^\\$[ \t]*"
1624 dcl-block-begin-regexp))))
1625 (not (and dcl-block-end-regexp
1626 (looking-at (concat "^\\$[ \t]*"
1627 dcl-block-end-regexp))))))
1628 "dcl-margin-label-offset")
1629 ;; Basic offset
1630 ((and (eq (dcl-get-line-type) '$) ; beginning of command
1631 (save-excursion
1632 (beginning-of-line)
1633 (let* ((this-indent (save-excursion
1634 (dcl-back-to-indentation)
1635 (current-column)))
1636 (prev-indent (save-excursion
1637 (if (dcl-backward-command)
1638 (progn
1639 (dcl-back-to-indentation)
1640 (current-column)))))
1641 (next-indent (save-excursion
1642 (dcl-end-of-command)
1643 (if (dcl-forward-command)
1644 (progn
1645 (dcl-beginning-of-command)
1646 (dcl-back-to-indentation)
1647 (current-column))))))
1648 (or (and prev-indent ; last cmd is indented differently
1649 (/= (- this-indent prev-indent) 0))
1650 (and next-indent
1651 (/= (- this-indent next-indent) 0))))))
1652 "dcl-basic-offset")
1653 ;; No more guesses.
1654 (t
1655 ""))))
1656
1657
1658 ;;;-------------------------------------------------------------------------
1659 (defun dcl-set-option (option-sym option-value)
1660 "Set a value for one of the dcl customization variables.
1661 The function tries to guess which variable should be set and to what value.
1662 All variable names are available as completions and in the history list."
1663 (interactive
1664 (let* ((option-sym
1665 (intern (completing-read
1666 "Set DCL option: " ; prompt
1667 (mapcar (function ; alist of valid values
1668 (lambda (option-assoc)
1669 (cons (format "%s" (car option-assoc)) nil)))
1670 dcl-option-alist)
1671 nil ; no predicate
1672 t ; only value from the list OK
1673 (dcl-guess-option) ; initial (default) value
1674 'dcl-option-history))) ; history list
1675 (option-value
1676 (eval-minibuffer
1677 (format "Set DCL option %s to: " option-sym)
1678 (dcl-guess-option-value option-sym))))
1679 (list option-sym option-value)))
1680 ;; Should make a sanity check on the symbol/value pair.
1681 ;; `set' instead of `setq' because we want option-sym to be evaluated.
1682 (set option-sym option-value))
1683
1684
1685 ;;; *** Save options ********************************************************
1686
1687
1688 ;;;-------------------------------------------------------------------------
1689 (defun dcl-save-local-variable (var &optional def-prefix def-suffix)
1690 "Save a variable in a `Local Variables' list.
1691 Set or update the value of VAR in the current buffers
1692 `Local Variables:' list."
1693 ;; Look for "Local variables:" line in last page.
1694 (save-excursion
1695 (goto-char (point-max))
1696 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
1697 (if (let ((case-fold-search t))
1698 (search-forward "Local Variables:" nil t))
1699 (let ((continue t)
1700 prefix prefixlen suffix beg
1701 prefix-string suffix-string)
1702 ;; The prefix is what comes before "local variables:" in its line.
1703 ;; The suffix is what comes after "local variables:" in its line.
1704 (skip-chars-forward " \t")
1705 (or (eolp)
1706 (setq suffix-string (buffer-substring (point)
1707 (progn (end-of-line) (point)))))
1708 (goto-char (match-beginning 0))
1709 (or (bolp)
1710 (setq prefix-string
1711 (buffer-substring (point)
1712 (progn (beginning-of-line) (point)))))
1713
1714 (if prefix-string (setq prefixlen (length prefix-string)
1715 prefix (regexp-quote prefix-string)))
1716 (if suffix-string (setq suffix (concat (regexp-quote suffix-string)
1717 "$")))
1718 (while continue
1719 ;; Look at next local variable spec.
1720 (if selective-display (re-search-forward "[\n\C-m]")
1721 (forward-line 1))
1722 ;; Skip the prefix, if any.
1723 (if prefix
1724 (if (looking-at prefix)
1725 (forward-char prefixlen)
1726 (error "Local variables entry is missing the prefix")))
1727 ;; Find the variable name; strip whitespace.
1728 (skip-chars-forward " \t")
1729 (setq beg (point))
1730 (skip-chars-forward "^:\n")
1731 (if (eolp) (error "Missing colon in local variables entry"))
1732 (skip-chars-backward " \t")
1733 (let* ((str (buffer-substring beg (point)))
1734 (found-var (read str))
1735 val)
1736 ;; Setting variable named "end" means end of list.
1737 (if (string-equal (downcase str) "end")
1738 (progn
1739 ;; Not found. Insert a new entry before this line
1740 (setq continue nil)
1741 (beginning-of-line)
1742 (insert (concat prefix-string (symbol-name var) ": "
1743 (prin1-to-string (eval var)) " "
1744 suffix-string "\n")))
1745 ;; Is it the variable we are looking for?
1746 (if (eq var found-var)
1747 (progn
1748 ;; Found it: delete the variable value and insert the
1749 ;; new value.
1750 (setq continue nil)
1751 (skip-chars-forward "^:")
1752 (forward-char 1)
1753 (delete-region (point) (progn (read (current-buffer))
1754 (point)))
1755 (insert " ")
1756 (prin1 (eval var) (current-buffer))
1757 (skip-chars-backward "\n")
1758 (skip-chars-forward " \t")
1759 (or (if suffix (looking-at suffix) (eolp))
1760 (error
1761 "Local variables entry is terminated incorrectly")))
1762 (end-of-line))))))
1763 ;; Did not find "Local variables:"
1764 (goto-char (point-max))
1765 (if (not (bolp))
1766 (insert "\n"))
1767 ;; If def- parameter not set, use comment- if set. In that case, make
1768 ;; sure there is a space in a suitable position
1769 (let ((def-prefix
1770 (cond
1771 (def-prefix
1772 def-prefix)
1773 (comment-start
1774 (if (or (equal comment-start "")
1775 (string-match "[ \t]$" comment-start))
1776 comment-start
1777 (concat comment-start " ")))))
1778 (def-suffix
1779 (cond
1780 (def-suffix
1781 def-suffix)
1782 (comment-end
1783 (if (or (equal comment-end "")
1784 (string-match "^[ \t]" comment-end))
1785 comment-end
1786 (concat " " comment-end))))))
1787 (insert (concat def-prefix "Local variables:" def-suffix "\n"))
1788 (insert (concat def-prefix (symbol-name var) ": "
1789 (prin1-to-string (eval var)) def-suffix "\n"))
1790 (insert (concat def-prefix "end:" def-suffix)))
1791 )))
1792
1793
1794 ;;;-------------------------------------------------------------------------
1795 (defun dcl-save-all-options ()
1796 "Save all dcl-mode options for this buffer.
1797 Saves or updates all dcl-mode related options in a `Local Variables:'
1798 section at the end of the current buffer."
1799 (interactive "*")
1800 (mapcar (lambda (option-assoc)
1801 (let* ((option (car option-assoc)))
1802 (dcl-save-local-variable option "$! ")))
1803 dcl-option-alist))
1804
1805
1806 ;;;-------------------------------------------------------------------------
1807 (defun dcl-save-nondefault-options ()
1808 "Save changed DCL mode options for this buffer.
1809 Saves or updates all DCL mode related options that don't have their
1810 default values in a `Local Variables:' section at the end of the
1811 current buffer.
1812
1813 No entries are removed from the `Local Variables:' section. This means
1814 that if a variable is given a non-default value in the section and
1815 later is manually reset to its default value, the variable's entry will
1816 still be present in the `Local Variables:' section with its old value."
1817 (interactive "*")
1818 (mapcar (lambda (option-assoc)
1819 (let* ((option (car option-assoc))
1820 (option-name (symbol-name option)))
1821 (if (and (string-equal "dcl-"
1822 (substring option-name 0 4))
1823 (not (equal (default-value option) (eval option))))
1824 (dcl-save-local-variable option "$! "))))
1825 dcl-option-alist))
1826
1827
1828 ;;;-------------------------------------------------------------------------
1829 (defun dcl-save-option (option)
1830 "Save a DCL mode option for this buffer.
1831 Saves or updates an option in a `Local Variables:'
1832 section at the end of the current buffer."
1833 (interactive
1834 (let ((option (intern (completing-read "Option: " obarray))))
1835 (list option)))
1836 (dcl-save-local-variable option))
1837
1838
1839 ;;;-------------------------------------------------------------------------
1840 (defun dcl-save-mode ()
1841 "Save the current mode for this buffer.
1842 Save the current mode in a `Local Variables:'
1843 section at the end of the current buffer."
1844 (interactive)
1845 (let ((mode (prin1-to-string major-mode)))
1846 (if (string-match "-mode$" mode)
1847 (let ((mode (intern (substring mode 0 (match-beginning 0)))))
1848 (dcl-save-option 'mode))
1849 (message "Strange mode: %s" mode))))
1850
1851
1852 ;;; *** Templates ***********************************************************
1853 ;; tempo seems to be the only suitable package among those included in
1854 ;; standard Emacs. I would have liked something closer to the functionality
1855 ;; of LSE templates...
1856
1857
1858 (require 'tempo)
1859 (defvar dcl-tempo-tags nil
1860 "Tempo tags for DCL mode.")
1861
1862 (tempo-define-template "dcl-f$context"
1863 '("f$context" dcl-tempo-left-paren
1864 (p "context-type: ") dcl-tempo-comma
1865 (p "context-symbol: ") dcl-tempo-comma
1866 (p "selection-item: ") dcl-tempo-comma
1867 (p "selection-value: ") dcl-tempo-comma
1868 (p "value-qualifier: ") dcl-tempo-right-paren)
1869 "f$context" "" 'dcl-tempo-tags)
1870
1871 (tempo-define-template "dcl-f$csid"
1872 '("f$csid" dcl-tempo-left-paren
1873 (p "context-symbol: ") dcl-tempo-right-paren)
1874 "f$csid" "" 'dcl-tempo-tags)
1875
1876 (tempo-define-template "dcl-f$cvsi"
1877 '("f$cvsi" dcl-tempo-left-paren
1878 (p "start-bit: ") dcl-tempo-comma
1879 (p "number-of-bits: ") dcl-tempo-comma
1880 (p "string: ") dcl-tempo-right-paren)
1881 "f$cvsi" "" 'dcl-tempo-tags)
1882
1883 (tempo-define-template "dcl-f$cvtime"
1884 '("f$cvtime" dcl-tempo-left-paren
1885 (p "[input_time]: ") dcl-tempo-comma
1886 (p "[output_time_format]: ") dcl-tempo-comma
1887 (p "[output_field]: ") dcl-tempo-right-paren)
1888 "f$cvtime" "" 'dcl-tempo-tags)
1889
1890 (tempo-define-template "dcl-f$cvui"
1891 '("f$cvui" dcl-tempo-left-paren
1892 (p "start-bit: ") dcl-tempo-comma
1893 (p "number-of-bits: ") dcl-tempo-comma
1894 (p "string") dcl-tempo-right-paren)
1895 "f$cvui" "" 'dcl-tempo-tags)
1896
1897 (tempo-define-template "dcl-f$device"
1898 '("f$device" dcl-tempo-left-paren
1899 (p "[search_devnam]: ") dcl-tempo-comma
1900 (p "[devclass]: ") dcl-tempo-comma
1901 (p "[devtype]: ") dcl-tempo-comma
1902 (p "[stream-id]: ") dcl-tempo-right-paren)
1903 "f$device" "" 'dcl-tempo-tags)
1904
1905 (tempo-define-template "dcl-f$directory"
1906 '("f$directory" dcl-tempo-left-paren
1907 dcl-tempo-right-paren)
1908 "f$directory" "" 'dcl-tempo-tags)
1909
1910 (tempo-define-template "dcl-f$edit"
1911 '("f$edit" dcl-tempo-left-paren
1912 (p "string: ") dcl-tempo-comma
1913 (p "edit-list: ") dcl-tempo-right-paren)
1914 "f$edit" "" 'dcl-tempo-tags)
1915
1916 (tempo-define-template "dcl-f$element"
1917 '("f$element" dcl-tempo-left-paren
1918 (p "element-number: ") dcl-tempo-comma
1919 (p "delimiter: ") dcl-tempo-comma
1920 (p "string: ") dcl-tempo-right-paren)
1921 "f$element" "" 'dcl-tempo-tags)
1922
1923 (tempo-define-template "dcl-f$environment"
1924 '("f$environment" dcl-tempo-left-paren
1925 (p "item: ") dcl-tempo-right-paren)
1926 "f$environment" "" 'dcl-tempo-tags)
1927
1928 (tempo-define-template "dcl-f$extract"
1929 '("f$extract" dcl-tempo-left-paren
1930 (p "start: ") dcl-tempo-comma
1931 (p "length: ") dcl-tempo-comma
1932 (p "string: ") dcl-tempo-right-paren)
1933 "f$extract" "" 'dcl-tempo-tags)
1934
1935 (tempo-define-template "dcl-f$fao"
1936 '("f$fao" dcl-tempo-left-paren
1937 (p "control-string: ") dcl-tempo-comma
1938 ("argument[,...]: ") dcl-tempo-right-paren)
1939 "f$fao" "" 'dcl-tempo-tags)
1940
1941 (tempo-define-template "dcl-f$file_attributes"
1942 '("f$file_attributes" dcl-tempo-left-paren
1943 (p "filespec: ") dcl-tempo-comma
1944 (p "item: ") dcl-tempo-right-paren)
1945 "f$file_attributes" "" 'dcl-tempo-tags)
1946
1947 (tempo-define-template "dcl-f$getdvi"
1948 '("f$getdvi" dcl-tempo-left-paren
1949 (p "device-name: ") dcl-tempo-comma
1950 (p "item: ") dcl-tempo-right-paren)
1951 "f$getdvi" "" 'dcl-tempo-tags)
1952
1953 (tempo-define-template "dcl-f$getjpi"
1954 '("f$getjpi" dcl-tempo-left-paren
1955 (p "pid: ") dcl-tempo-comma
1956 (p "item: ") dcl-tempo-right-paren )
1957 "f$getjpi" "" 'dcl-tempo-tags)
1958
1959 (tempo-define-template "dcl-f$getqui"
1960 '("f$getqui" dcl-tempo-left-paren
1961 (p "function: ") dcl-tempo-comma
1962 (p "[item]: ") dcl-tempo-comma
1963 (p "[object-id]: ") dcl-tempo-comma
1964 (p "[flags]: ") dcl-tempo-right-paren)
1965 "f$getqui" "" 'dcl-tempo-tags)
1966
1967 (tempo-define-template "dcl-f$getsyi"
1968 '("f$getsyi" dcl-tempo-left-paren
1969 (p "item: ") dcl-tempo-comma
1970 (p "[node-name]: ") dcl-tempo-comma
1971 (p "[cluster-id]: ") dcl-tempo-right-paren)
1972 "f$getsyi" "" 'dcl-tempo-tags)
1973
1974 (tempo-define-template "dcl-f$identifier"
1975 '("f$identifier" dcl-tempo-left-paren
1976 (p "identifier: ") dcl-tempo-comma
1977 (p "conversion-type: ") dcl-tempo-right-paren)
1978 "f$identifier" "" 'dcl-tempo-tags)
1979
1980 (tempo-define-template "dcl-f$integer"
1981 '("f$integer" dcl-tempo-left-paren
1982 (p "expression: ") dcl-tempo-right-paren)
1983 "f$integer" "" 'dcl-tempo-tags)
1984
1985 (tempo-define-template "dcl-f$length"
1986 '("f$length" dcl-tempo-left-paren
1987 (p "string: ") dcl-tempo-right-paren )
1988 "f$length" "" 'dcl-tempo-tags)
1989
1990 (tempo-define-template "dcl-f$locate"
1991 '("f$locate" dcl-tempo-left-paren
1992 (p "substring: ") dcl-tempo-comma
1993 (p "string: ") dcl-tempo-right-paren)
1994 "f$locate" "" 'dcl-tempo-tags)
1995
1996 (tempo-define-template "dcl-f$message"
1997 '("f$message" dcl-tempo-left-paren
1998 (p "status-code: ") dcl-tempo-right-paren )
1999 "f$message" "" 'dcl-tempo-tags)
2000
2001 (tempo-define-template "dcl-f$mode"
2002 '("f$mode" dcl-tempo-left-paren dcl-tempo-right-paren)
2003 "f$mode" "" 'dcl-tempo-tags)
2004
2005 (tempo-define-template "dcl-f$parse"
2006 '("f$parse" dcl-tempo-left-paren
2007 (p "filespec: ") dcl-tempo-comma
2008 (p "[default-spec]: ") dcl-tempo-comma
2009 (p "[related-spec]: ") dcl-tempo-comma
2010 (p "[field]: ") dcl-tempo-comma
2011 (p "[parse-type]: ") dcl-tempo-right-paren)
2012 "f$parse" "" 'dcl-tempo-tags)
2013
2014 (tempo-define-template "dcl-f$pid"
2015 '("f$pid" dcl-tempo-left-paren
2016 (p "context-symbol: ") dcl-tempo-right-paren)
2017 "f$pid" "" 'dcl-tempo-tags)
2018
2019 (tempo-define-template "dcl-f$privilege"
2020 '("f$privilege" dcl-tempo-left-paren
2021 (p "priv-states: ") dcl-tempo-right-paren)
2022 "f$privilege" "" 'dcl-tempo-tags)
2023
2024 (tempo-define-template "dcl-f$process"
2025 '("f$process()")
2026 "f$process" "" 'dcl-tempo-tags)
2027
2028 (tempo-define-template "dcl-f$search"
2029 '("f$search" dcl-tempo-left-paren
2030 (p "filespec: ") dcl-tempo-comma
2031 (p "[stream-id]: ") dcl-tempo-right-paren)
2032 "f$search" "" 'dcl-tempo-tags)
2033
2034 (tempo-define-template "dcl-f$setprv"
2035 '("f$setprv" dcl-tempo-left-paren
2036 (p "priv-states: ") dcl-tempo-right-paren)
2037 "f$setprv" "" 'dcl-tempo-tags)
2038
2039 (tempo-define-template "dcl-f$string"
2040 '("f$string" dcl-tempo-left-paren
2041 (p "expression: ") dcl-tempo-right-paren)
2042 "f$string" "" 'dcl-tempo-tags)
2043
2044 (tempo-define-template "dcl-f$time"
2045 '("f$time" dcl-tempo-left-paren dcl-tempo-right-paren)
2046 "f$time" "" 'dcl-tempo-tags)
2047
2048 (tempo-define-template "dcl-f$trnlnm"
2049 '("f$trnlnm" dcl-tempo-left-paren
2050 (p "logical-name: ") dcl-tempo-comma
2051 (p "[table]: ") dcl-tempo-comma
2052 (p "[index]: ") dcl-tempo-comma
2053 (p "[mode]: ") dcl-tempo-comma
2054 (p "[case]: ") dcl-tempo-comma
2055 (p "[item]: ") dcl-tempo-right-paren)
2056 "f$trnlnm" "" 'dcl-tempo-tags)
2057
2058 (tempo-define-template "dcl-f$type"
2059 '("f$type" dcl-tempo-left-paren
2060 (p "symbol-name: ") dcl-tempo-right-paren)
2061 "f$type" "" 'dcl-tempo-tags)
2062
2063 (tempo-define-template "dcl-f$user"
2064 '("f$user" dcl-tempo-left-paren dcl-tempo-right-paren)
2065 "f$user" "" 'dcl-tempo-tags)
2066
2067 (tempo-define-template "dcl-f$verify"
2068 '("f$verify" dcl-tempo-left-paren
2069 (p "[procedure-value]: ") dcl-tempo-comma
2070 (p "[image-value]: ") dcl-tempo-right-paren)
2071 "f$verify" "" 'dcl-tempo-tags)
2072
2073
2074
2075
2076 ;;; *** Unsorted stuff *****************************************************
2077
2078
2079 ;;;-------------------------------------------------------------------------
2080 (defun dcl-beginning-of-command-p ()
2081 "Return t if point is at the beginning of a command.
2082 Otherwise return nil."
2083 (and (bolp)
2084 (eq (dcl-get-line-type) '$)))
2085
2086
2087 ;;;-------------------------------------------------------------------------
2088 (defun dcl-end-of-command-p ()
2089 "Check if point is at the end of a command.
2090 Return t if point is at the end of a command, either the end of an
2091 only line or at the end of the last continuation line.
2092 Otherwise return nil."
2093 ;; Must be at end-of-line on a command line or a continuation line
2094 (let ((type (dcl-get-line-type)))
2095 (if (and (eolp)
2096 (or (eq type '$)
2097 (eq type '-)))
2098 ;; Next line must not be a continuation line
2099 (save-excursion
2100 (forward-line)
2101 (not (eq (dcl-get-line-type) '-))))))
2102
2103
2104 ;;;-------------------------------------------------------------------------
2105 (defun dcl-command-p ()
2106 "Check if point is on a command line.
2107 Return t if point is on a command line or a continuation line,
2108 otherwise return nil."
2109 (let ((type (dcl-get-line-type)))
2110 (or (eq type '$)
2111 (eq type '-))))
2112
2113
2114 ;;;-------------------------------------------------------------------------
2115 (defun dcl-was-looking-at (regexp)
2116 (save-excursion
2117 (let ((start (point))
2118 (found (re-search-backward regexp 0 t)))
2119 (if (not found)
2120 ()
2121 (equal start (match-end 0))))))
2122
2123
2124 ;;;-------------------------------------------------------------------------
2125 (defun dcl-imenu-create-index-function ()
2126 "Jacket routine to make imenu searches non case sensitive."
2127 (let ((case-fold-search t))
2128 (imenu-default-create-index-function)))
2129
2130
2131
2132 ;;; *** Epilogue ************************************************************
2133
2134
2135 (provide 'dcl-mode)
2136
2137 (run-hooks 'dcl-mode-load-hook) ; for your customizations
2138
2139 ;;; dcl-mode.el ends here