comparison lisp/progmodes/dcl-mode.el @ 17246:7f37ef17af0f

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