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