diff options
| author | Richard M. Stallman | 1997-05-22 01:58:55 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-05-22 01:58:55 +0000 |
| commit | cadd36581216264b3978863719b6e5c565009d2a (patch) | |
| tree | 6207676d4cf4b6744ad5a0486273e1b65d8eb5da | |
| parent | 12554a4ff4b5594324bb4c13a5780988c9d27b13 (diff) | |
| download | emacs-cadd36581216264b3978863719b6e5c565009d2a.tar.gz emacs-cadd36581216264b3978863719b6e5c565009d2a.zip | |
(ada-krunch-args): Use gnatkr instead of gnatk8.
(ada-make-filename-from-adaname): Ditto.
(ada-adjust-case-region): Use format functionality of message.
(ada-indent-region): Ditto.
(ada-check-matching-start): Ditto.
(ada-check-defun-name): Ditto.
(ada-font-lock-keywords): Default to subdued. Doc fix.
(ada-font-lock-syntactic-keywords): New variable.
(ada-mode): Use it to set font-lock-defaults.
(ada-font-lock-keywords-2): Single "raise" will be
highlighted. "in out" parameters get type face (depends on order
in regexp).
(ada-mode): Remove explicit setting of user option
`blink-matching-paren', font-lock treats `.' as word char.
(ada-in-string-or-comment-p): Call `parse-partial-sexp' only once.
(ada-untabify-buffer): Force returning `nil'.
(ada-font-lock-keywords-1): Move "task" before "task (body|type)" to
correct highlighting (regexp depends on order).
(ada-in-char-const-p): Renamed from `ada-after-char-p'.
Also test following character.
(ada-adjust-case): Use better function `ada-in-char-const-p'
(ada-in-string-or-comment-p): Test for being in a char constant.
(ada-clean-buffer-before-saving): Changed default to t.
(ada-mode): Set `font-lock-defaults' for Emacs only, use properties
for XEmacs.
(ada-indent-newline-indent): Simplified by just calling
`ada-indent-current'.
(ada-end-stmt-re): Added word delimiters in regexp.
Removed `interactive' statements which were needed only for debugging.
Put format commands back in for emacs 19.30/19.29 compatibility.
(ada-get-indent-label): A named block can begin
without a declare part.
(ada-check-defun-name): First of all, check for correct name in a
named block without `declare' part.
(ada-goto-matching-start): Change regexp as there may be no
semicolon between `end' and keyword.
(ada-get-current-indent): Remove warning as `begin' can introduce
a block without a `declare'.
(ada-goto-matching-decl-start): When searching backward, skip
generic default proc/func ("is <>").
(ada-named-block-re): New regexp for the name of a named block or loop.
(ada-get-current-indent): Handle loop names at the stmt start.
(ada-get-indent-end): Handle loop names at the stmt start.
(ada-get-indent-noindent): Handle loop names at the stmt start.
(ada-get-indent-loop): Handle loop names at the stmt start.
(ada-search-prev-end-stmt): Generic instances are not `stmt-ends'.
(ada-goto-previous-word): Use new function `ada-goto-next-word'.
(ada-goto-next-word): Generalized old `ada-goto-previous-word' for
both directions.
(ada-indent-function): Removed unnecessary `package' case.
(ada-get-indent-case): Before testing for `=>', be sure there is an `is'.
(ada-search-prev-end-stmt): Test for `separate' keyword on the
same line, which is not an `end-stmt'.
(ada-font-lock-keywords-2):
Correct regexp for hilit of unfollowed `end'.
(ada-in-open-paren-p): Start parsing definitely outside of strings.
(ada-gnat-style): New function.
Doc fixes.
(ada-mode): Support new font-lock-mode.
(ada-format-paramlist): Changed all `accept' to `access'.
(ada-insert-paramlist): Changed all `accept' to `access'.
(ada-in-comment-p): Use standard emacs way `parse-partial-sexp'.
(ada-font-lock-keywords-1): Regexps in not byte-compiled code bahave
different than byte-compiled regexps.
Change order of some ored entries.
| -rw-r--r-- | lisp/progmodes/ada-mode.el | 684 |
1 files changed, 385 insertions, 299 deletions
diff --git a/lisp/progmodes/ada-mode.el b/lisp/progmodes/ada-mode.el index cf74a914ea2..c516a0f1975 100644 --- a/lisp/progmodes/ada-mode.el +++ b/lisp/progmodes/ada-mode.el | |||
| @@ -1,8 +1,10 @@ | |||
| 1 | ;;; ada-mode.el --- An Emacs major-mode for editing Ada source. | 1 | ;;; ada-mode.el --- An Emacs major-mode for editing Ada source. |
| 2 | ;;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. | 2 | ;;; Copyright (C) 1994, 1995, 1997 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | ;;; Authors: Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de> | 4 | ;;; Authors: Rolf Ebert <ebert@inf.enst.fr> |
| 5 | ;;; Rolf Ebert <ebert@inf.enst.fr> | 5 | ;;; Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de> |
| 6 | ;;; Keywords: languages oop ada | ||
| 7 | ;;; Rolf Ebert's version: 2.25 | ||
| 6 | 8 | ||
| 7 | ;;; This file is part of GNU Emacs. | 9 | ;;; This file is part of GNU Emacs. |
| 8 | 10 | ||
| @@ -28,7 +30,7 @@ | |||
| 28 | 30 | ||
| 29 | ;;; USAGE | 31 | ;;; USAGE |
| 30 | ;;; ===== | 32 | ;;; ===== |
| 31 | ;;; Emacs should enter ada-mode when you load an ada source (*.ad[abs]). | 33 | ;;; Emacs should enter Ada mode when you load an Ada source (*.ad[abs]). |
| 32 | ;;; | 34 | ;;; |
| 33 | ;;; When you have entered ada-mode, you may get more info by pressing | 35 | ;;; When you have entered ada-mode, you may get more info by pressing |
| 34 | ;;; C-h m. You may also get online help describing various functions by: | 36 | ;;; C-h m. You may also get online help describing various functions by: |
| @@ -52,7 +54,7 @@ | |||
| 52 | ;;; electric-ada.el. | 54 | ;;; electric-ada.el. |
| 53 | ;;; | 55 | ;;; |
| 54 | ;;; The current Ada mode is a complete rewrite by M. Heritsch and | 56 | ;;; The current Ada mode is a complete rewrite by M. Heritsch and |
| 55 | ;;; R. Ebert. Some ideas from the ada-mode mailing list have been | 57 | ;;; R. Ebert. Some ideas from the Ada mode mailing list have been |
| 56 | ;;; added. Some of the functionality of L. Slater's mode has not | 58 | ;;; added. Some of the functionality of L. Slater's mode has not |
| 57 | ;;; (yet) been recoded in this new mode. Perhaps you prefer sticking | 59 | ;;; (yet) been recoded in this new mode. Perhaps you prefer sticking |
| 58 | ;;; to his version. | 60 | ;;; to his version. |
| @@ -64,17 +66,20 @@ | |||
| 64 | ;;; In the presence of comments and/or incorrect syntax | 66 | ;;; In the presence of comments and/or incorrect syntax |
| 65 | ;;; ada-format-paramlist produces weird results. | 67 | ;;; ada-format-paramlist produces weird results. |
| 66 | ;;; ------------------- | 68 | ;;; ------------------- |
| 67 | ;;; Indenting of some tasking constructs is still buggy. | 69 | ;;; Character constants with otherwise syntactic relevant characters |
| 68 | ;;; ------------------- | 70 | ;;; like `(' or `"' throw indentation off the track. Fontification |
| 69 | ;;; package Test is | 71 | ;;; should work now in Emacs-19.35 |
| 70 | ;;; -- If I hit return on the "type" line it will indent the next line | 72 | ;;; C : constant Character := Character'('"'); |
| 71 | ;;; -- in another 3 space instead of heading out to the "(". If I hit | ||
| 72 | ;;; -- tab or return it reindents the line correctly but does not initially. | ||
| 73 | ;;; type Wait_Return is (Read_Success, Read_Timeout, Wait_Timeout, | ||
| 74 | ;;; Nothing_To_Wait_For_In_Wait_List); | ||
| 75 | ;;; ------------------- | 73 | ;;; ------------------- |
| 76 | 74 | ||
| 77 | 75 | ||
| 76 | ;;; TODO | ||
| 77 | ;;; ==== | ||
| 78 | ;;; | ||
| 79 | ;;; o bodify-single-subprogram | ||
| 80 | ;;; o make a function "separate" and put it in the corresponding file. | ||
| 81 | |||
| 82 | |||
| 78 | 83 | ||
| 79 | ;;; CREDITS | 84 | ;;; CREDITS |
| 80 | ;;; ======= | 85 | ;;; ======= |
| @@ -148,6 +153,12 @@ not to 'begin'.") | |||
| 148 | (defvar ada-body-suffix ".adb" | 153 | (defvar ada-body-suffix ".adb" |
| 149 | "*Suffix of Ada body files.") | 154 | "*Suffix of Ada body files.") |
| 150 | 155 | ||
| 156 | (defvar ada-spec-suffix-as-regexp "\\.ads$" | ||
| 157 | "*Regexp to find Ada specification files.") | ||
| 158 | |||
| 159 | (defvar ada-body-suffix-as-regexp "\\.adb$" | ||
| 160 | "*Regexp to find Ada body files.") | ||
| 161 | |||
| 151 | (defvar ada-language-version 'ada95 | 162 | (defvar ada-language-version 'ada95 |
| 152 | "*Do we program in `ada83' or `ada95'?") | 163 | "*Do we program in `ada83' or `ada95'?") |
| 153 | 164 | ||
| @@ -169,21 +180,37 @@ It may be `downcase-word', `upcase-word', `ada-loose-case-word' or | |||
| 169 | (defvar ada-auto-case t | 180 | (defvar ada-auto-case t |
| 170 | "*Non-nil automatically changes case of preceding word while typing. | 181 | "*Non-nil automatically changes case of preceding word while typing. |
| 171 | Casing is done according to `ada-case-keyword', `ada-case-identifier' | 182 | Casing is done according to `ada-case-keyword', `ada-case-identifier' |
| 172 | and `ada-cacse-attribute'.") | 183 | and `ada-case-attribute'.") |
| 173 | 184 | ||
| 174 | (defvar ada-clean-buffer-before-saving nil | 185 | (defvar ada-clean-buffer-before-saving t |
| 175 | "*If non-nil, `remove-trailing-spaces' and `untabify' buffer before saving.") | 186 | "*If non-nil, `remove-trailing-spaces' and `untabify' buffer before saving.") |
| 176 | 187 | ||
| 177 | (defvar ada-mode-hook nil | 188 | (defvar ada-mode-hook nil |
| 178 | "*List of functions to call when Ada Mode is invoked. | 189 | "*List of functions to call when Ada mode is invoked. |
| 179 | This is a good place to add Ada environment specific bindings.") | 190 | This is a good place to add Ada environment specific bindings.") |
| 180 | 191 | ||
| 181 | (defvar ada-external-pretty-print-program "aimap" | 192 | (defvar ada-external-pretty-print-program "aimap" |
| 182 | "*External pretty printer to call from within Ada Mode.") | 193 | "*External pretty printer to call from within Ada mode.") |
| 183 | 194 | ||
| 184 | (defvar ada-tmp-directory "/tmp/" | 195 | (defvar ada-tmp-directory "/tmp/" |
| 185 | "*Directory to store the temporary file for the Ada pretty printer.") | 196 | "*Directory to store the temporary file for the Ada pretty printer.") |
| 186 | 197 | ||
| 198 | (defvar ada-compile-options "-c" | ||
| 199 | "*Buffer local options passed to the Ada compiler. | ||
| 200 | These options are used when the compiler is invoked on the current buffer.") | ||
| 201 | (make-variable-buffer-local 'ada-compile-options) | ||
| 202 | |||
| 203 | (defvar ada-make-options "-c" | ||
| 204 | "*Buffer local options passed to `ada-compiler-make' (usually `gnatmake'). | ||
| 205 | These options are used when `gnatmake' is invoked on the current buffer.") | ||
| 206 | (make-variable-buffer-local 'ada-make-options) | ||
| 207 | |||
| 208 | (defvar ada-compiler-syntax-check "gcc -c -gnats" | ||
| 209 | "*Compiler command with options for syntax checking.") | ||
| 210 | |||
| 211 | (defvar ada-compiler-make "gnatmake" | ||
| 212 | "*The `make' command for the given compiler.") | ||
| 213 | |||
| 187 | (defvar ada-fill-comment-prefix "-- " | 214 | (defvar ada-fill-comment-prefix "-- " |
| 188 | "*This is inserted in the first columns when filling a comment paragraph.") | 215 | "*This is inserted in the first columns when filling a comment paragraph.") |
| 189 | 216 | ||
| @@ -192,7 +219,7 @@ This is a good place to add Ada environment specific bindings.") | |||
| 192 | with `ada-fill-comment-paragraph-postfix'.") | 219 | with `ada-fill-comment-paragraph-postfix'.") |
| 193 | 220 | ||
| 194 | (defvar ada-krunch-args "0" | 221 | (defvar ada-krunch-args "0" |
| 195 | "*Argument of gnatk8, a string containing the max number of characters. | 222 | "*Argument of gnatkr, a string containing the max number of characters. |
| 196 | Set to 0, if you don't use crunched filenames.") | 223 | Set to 0, if you don't use crunched filenames.") |
| 197 | 224 | ||
| 198 | ;;; ---- end of user configurable variables | 225 | ;;; ---- end of user configurable variables |
| @@ -203,7 +230,7 @@ Set to 0, if you don't use crunched filenames.") | |||
| 203 | (define-abbrev-table 'ada-mode-abbrev-table ()) | 230 | (define-abbrev-table 'ada-mode-abbrev-table ()) |
| 204 | 231 | ||
| 205 | (defvar ada-mode-map () | 232 | (defvar ada-mode-map () |
| 206 | "Local keymap used for Ada Mode.") | 233 | "Local keymap used for Ada mode.") |
| 207 | 234 | ||
| 208 | (defvar ada-mode-syntax-table nil | 235 | (defvar ada-mode-syntax-table nil |
| 209 | "Syntax table to be used for editing Ada source code.") | 236 | "Syntax table to be used for editing Ada source code.") |
| @@ -230,7 +257,7 @@ then\\|type\\|use\\|when\\|while\\|with\\|xor\\)\\>" | |||
| 230 | ;r\\(a\\(ise\\|nge\\)\\|e\\(cord\\|m\\|names\\|turn\\|verse\\)\\)\\|\ | 257 | ;r\\(a\\(ise\\|nge\\)\\|e\\(cord\\|m\\|names\\|turn\\|verse\\)\\)\\|\ |
| 231 | ;s\\(e\\(lect\\|parate\\)\\|ubtype\\)\\|use\\| | 258 | ;s\\(e\\(lect\\|parate\\)\\|ubtype\\)\\|use\\| |
| 232 | ;t\\(ask\\|erminate\\|hen\\|ype\\)\\|w\\(h\\(en\\|ile\\)\\|ith\\)\\|xor\\)\\>" | 259 | ;t\\(ask\\|erminate\\|hen\\|ype\\)\\|w\\(h\\(en\\|ile\\)\\|ith\\)\\|xor\\)\\>" |
| 233 | "regular expression for looking at Ada83 keywords.") | 260 | "Regular expression for looking at Ada83 keywords.") |
| 234 | 261 | ||
| 235 | (defconst ada-95-keywords | 262 | (defconst ada-95-keywords |
| 236 | "\\<\\(abort\\|abs\\|abstract\\|accept\\|access\\|aliased\\|\ | 263 | "\\<\\(abort\\|abs\\|abstract\\|accept\\|access\\|aliased\\|\ |
| @@ -242,7 +269,7 @@ out\\|package\\|pragma\\|private\\|procedure\\|protected\\|raise\\|\ | |||
| 242 | range\\|record\\|rem\\|renames\\|requeue\\|return\\|reverse\\|\ | 269 | range\\|record\\|rem\\|renames\\|requeue\\|return\\|reverse\\|\ |
| 243 | select\\|separate\\|subtype\\|tagged\\|task\\|terminate\\|then\\|\ | 270 | select\\|separate\\|subtype\\|tagged\\|task\\|terminate\\|then\\|\ |
| 244 | type\\|until\\|use\\|when\\|while\\|with\\|xor\\)\\>" | 271 | type\\|until\\|use\\|when\\|while\\|with\\|xor\\)\\>" |
| 245 | "regular expression for looking at Ada95 keywords.") | 272 | "Regular expression for looking at Ada95 keywords.") |
| 246 | 273 | ||
| 247 | (defvar ada-keywords ada-95-keywords | 274 | (defvar ada-keywords ada-95-keywords |
| 248 | "Regular expression for looking at Ada keywords.") | 275 | "Regular expression for looking at Ada keywords.") |
| @@ -278,9 +305,9 @@ exception\\|loop\\|else\\|\ | |||
| 278 | 305 | ||
| 279 | (defvar ada-end-stmt-re | 306 | (defvar ada-end-stmt-re |
| 280 | "\\(;\\|=>\\|^[ \t]*separate[ \t]+([a-zA-Z0-9_\\.]+)\\|\ | 307 | "\\(;\\|=>\\|^[ \t]*separate[ \t]+([a-zA-Z0-9_\\.]+)\\|\ |
| 281 | \\<\\(begin\\|else\\|record\\|loop\\|select\\|do\\|\ | 308 | \\<\\(begin\\|else\\|record\\|loop\\|select\\|do\\|then\\|\ |
| 282 | declare\\|generic\\|private\\)\\>\\|\ | 309 | declare\\|generic\\|private\\)\\>\\|\ |
| 283 | ^[ \t]*\\(package\\|procedure\\|function\\)[ \ta-zA-Z0-9_\\.]+is\\|\ | 310 | ^[ \t]*\\(package\\|procedure\\|function\\)\\>[ \ta-zA-Z0-9_\\.]+\\<is\\>\\|\ |
| 284 | ^[ \t]*exception\\>\\)" | 311 | ^[ \t]*exception\\>\\)" |
| 285 | "Regexp of possible ends for a non-broken statement. | 312 | "Regexp of possible ends for a non-broken statement. |
| 286 | A new statement starts after these.") | 313 | A new statement starts after these.") |
| @@ -294,6 +321,10 @@ A new statement starts after these.") | |||
| 294 | task\\|accept\\|entry\\)\\>" | 321 | task\\|accept\\|entry\\)\\>" |
| 295 | "Regexp for the start of a subprogram.") | 322 | "Regexp for the start of a subprogram.") |
| 296 | 323 | ||
| 324 | (defvar ada-named-block-re | ||
| 325 | "[ \t]*[a-zA-Z_0-9]+ *:[^=]" | ||
| 326 | "Regexp of the name of a block or loop.") | ||
| 327 | |||
| 297 | 328 | ||
| 298 | ;; Written by Christian Egli <Christian.Egli@hcsd.hac.com> | 329 | ;; Written by Christian Egli <Christian.Egli@hcsd.hac.com> |
| 299 | ;; | 330 | ;; |
| @@ -312,7 +343,7 @@ task\\|accept\\|entry\\)\\>" | |||
| 312 | (string-match "XEmacs" emacs-version))) | 343 | (string-match "XEmacs" emacs-version))) |
| 313 | 344 | ||
| 314 | (defun ada-create-syntax-table () | 345 | (defun ada-create-syntax-table () |
| 315 | "Create the syntax table for Ada Mode." | 346 | "Create the syntax table for Ada mode." |
| 316 | ;; There are two different syntax-tables. The standard one declares | 347 | ;; There are two different syntax-tables. The standard one declares |
| 317 | ;; `_' as a symbol constituent, in the second one, it is a word | 348 | ;; `_' as a symbol constituent, in the second one, it is a word |
| 318 | ;; constituent. For some search and replacing routines we | 349 | ;; constituent. For some search and replacing routines we |
| @@ -320,8 +351,10 @@ task\\|accept\\|entry\\)\\>" | |||
| 320 | (setq ada-mode-syntax-table (make-syntax-table)) | 351 | (setq ada-mode-syntax-table (make-syntax-table)) |
| 321 | (set-syntax-table ada-mode-syntax-table) | 352 | (set-syntax-table ada-mode-syntax-table) |
| 322 | 353 | ||
| 323 | ;; define string brackets (% is alternative string bracket) | 354 | ;; define string brackets (`%' is alternative string bracket, but |
| 324 | (modify-syntax-entry ?% "\"" ada-mode-syntax-table) | 355 | ;; almost never used as such and throws font-lock and indentation |
| 356 | ;; off the track.) | ||
| 357 | (modify-syntax-entry ?% "$" ada-mode-syntax-table) | ||
| 325 | (modify-syntax-entry ?\" "\"" ada-mode-syntax-table) | 358 | (modify-syntax-entry ?\" "\"" ada-mode-syntax-table) |
| 326 | 359 | ||
| 327 | (modify-syntax-entry ?\# "$" ada-mode-syntax-table) | 360 | (modify-syntax-entry ?\# "$" ada-mode-syntax-table) |
| @@ -352,7 +385,7 @@ task\\|accept\\|entry\\)\\>" | |||
| 352 | (modify-syntax-entry ?\f "> " ada-mode-syntax-table) | 385 | (modify-syntax-entry ?\f "> " ada-mode-syntax-table) |
| 353 | (modify-syntax-entry ?\n "> " ada-mode-syntax-table) | 386 | (modify-syntax-entry ?\n "> " ada-mode-syntax-table) |
| 354 | 387 | ||
| 355 | ;; define what belongs in ada symbols | 388 | ;; define what belongs in Ada symbols |
| 356 | (modify-syntax-entry ?_ "_" ada-mode-syntax-table) | 389 | (modify-syntax-entry ?_ "_" ada-mode-syntax-table) |
| 357 | 390 | ||
| 358 | ;; define parentheses to match | 391 | ;; define parentheses to match |
| @@ -366,7 +399,7 @@ task\\|accept\\|entry\\)\\>" | |||
| 366 | 399 | ||
| 367 | ;;;###autoload | 400 | ;;;###autoload |
| 368 | (defun ada-mode () | 401 | (defun ada-mode () |
| 369 | "Ada Mode is the major mode for editing Ada code. | 402 | "Ada mode is the major mode for editing Ada code. |
| 370 | 403 | ||
| 371 | Bindings are as follows: (Note: 'LFD' is control-j.) | 404 | Bindings are as follows: (Note: 'LFD' is control-j.) |
| 372 | 405 | ||
| @@ -386,7 +419,7 @@ Bindings are as follows: (Note: 'LFD' is control-j.) | |||
| 386 | Fill comment paragraph and justify each line '\\[ada-fill-comment-paragraph-justify]' | 419 | Fill comment paragraph and justify each line '\\[ada-fill-comment-paragraph-justify]' |
| 387 | Fill comment paragraph, justify and append postfix '\\[ada-fill-comment-paragraph-postfix]' | 420 | Fill comment paragraph, justify and append postfix '\\[ada-fill-comment-paragraph-postfix]' |
| 388 | 421 | ||
| 389 | Next func/proc/task '\\[ada-next-procedure]' Previous func/proc/task '\\[ada-previous-procedure]' | 422 | Next func/proc/task '\\[ada-next-procedure]' Previous func/proc/task '\\[ada-previous-procedure]' |
| 390 | Next package '\\[ada-next-package]' Previous package '\\[ada-previous-package]' | 423 | Next package '\\[ada-next-package]' Previous package '\\[ada-previous-package]' |
| 391 | 424 | ||
| 392 | Goto matching start of current 'end ...;' '\\[ada-move-to-start]' | 425 | Goto matching start of current 'end ...;' '\\[ada-move-to-start]' |
| @@ -447,25 +480,31 @@ If you use ada-xref.el: | |||
| 447 | (make-local-variable 'case-fold-search) | 480 | (make-local-variable 'case-fold-search) |
| 448 | (setq case-fold-search t) | 481 | (setq case-fold-search t) |
| 449 | 482 | ||
| 483 | (make-local-variable 'outline-regexp) | ||
| 484 | (setq outline-regexp "[^\n\^M]") | ||
| 485 | (make-local-variable 'outline-level) | ||
| 486 | (setq outline-level 'ada-outline-level) | ||
| 487 | |||
| 450 | (make-local-variable 'fill-paragraph-function) | 488 | (make-local-variable 'fill-paragraph-function) |
| 451 | (setq fill-paragraph-function 'ada-fill-comment-paragraph) | 489 | (setq fill-paragraph-function 'ada-fill-comment-paragraph) |
| 490 | ;;(make-local-variable 'adaptive-fill-regexp) | ||
| 452 | 491 | ||
| 453 | (make-local-variable 'imenu-generic-expression) | 492 | (make-local-variable 'imenu-generic-expression) |
| 454 | (setq imenu-generic-expression ada-imenu-generic-expression) | 493 | (setq imenu-generic-expression ada-imenu-generic-expression) |
| 455 | 494 | ||
| 456 | (make-local-variable 'font-lock-defaults) | 495 | (if (ada-xemacs) nil ; XEmacs uses properties |
| 457 | (setq font-lock-defaults '((ada-font-lock-keywords | 496 | (make-local-variable 'font-lock-defaults) |
| 458 | ada-font-lock-keywords-1 | 497 | (setq font-lock-defaults |
| 459 | ada-font-lock-keywords-2) | 498 | '((ada-font-lock-keywords |
| 460 | nil t | 499 | ada-font-lock-keywords-1 ada-font-lock-keywords-2) |
| 461 | ((?\_ . "w")) | 500 | nil t |
| 462 | beginning-of-line)) | 501 | ((?\_ . "w")(?\. . "w")) |
| 502 | beginning-of-line | ||
| 503 | (font-lock-syntactic-keywords . ada-font-lock-syntactic-keywords)))) | ||
| 463 | 504 | ||
| 464 | (setq major-mode 'ada-mode) | 505 | (setq major-mode 'ada-mode) |
| 465 | (setq mode-name "Ada") | 506 | (setq mode-name "Ada") |
| 466 | 507 | ||
| 467 | (setq blink-matching-paren t) | ||
| 468 | |||
| 469 | (use-local-map ada-mode-map) | 508 | (use-local-map ada-mode-map) |
| 470 | 509 | ||
| 471 | (if ada-mode-syntax-table | 510 | (if ada-mode-syntax-table |
| @@ -499,6 +538,45 @@ If you use ada-xref.el: | |||
| 499 | 538 | ||
| 500 | 539 | ||
| 501 | ;;;-------------------------- | 540 | ;;;-------------------------- |
| 541 | ;;; Compile support | ||
| 542 | ;;;-------------------------- | ||
| 543 | |||
| 544 | (defun ada-check-syntax () | ||
| 545 | "Check syntax of the current buffer. | ||
| 546 | Uses the function `compile' to execute `ada-compiler-syntax-check'." | ||
| 547 | (interactive) | ||
| 548 | (let ((old-compile-command compile-command)) | ||
| 549 | (setq compile-command (concat ada-compiler-syntax-check | ||
| 550 | (if (eq ada-language-version 'ada83) | ||
| 551 | "-gnat83 ") | ||
| 552 | " " ada-compile-options " " | ||
| 553 | (buffer-name))) | ||
| 554 | (setq compile-command (read-from-minibuffer | ||
| 555 | "enter command for syntax check: " | ||
| 556 | compile-command)) | ||
| 557 | (compile compile-command) | ||
| 558 | ;; restore old compile-command | ||
| 559 | (setq compile-command old-compile-command))) | ||
| 560 | |||
| 561 | (defun ada-make-local () | ||
| 562 | "Bring current Ada unit up-to-date. | ||
| 563 | Uses the function `compile' to execute `ada-compile-make'." | ||
| 564 | (interactive) | ||
| 565 | (let ((old-compile-command compile-command)) | ||
| 566 | (setq compile-command (concat ada-compiler-make | ||
| 567 | " " ada-make-options " " | ||
| 568 | (buffer-name))) | ||
| 569 | (setq compile-command (read-from-minibuffer | ||
| 570 | "enter command for local make: " | ||
| 571 | compile-command)) | ||
| 572 | (compile compile-command) | ||
| 573 | ;; restore old compile-command | ||
| 574 | (setq compile-command old-compile-command))) | ||
| 575 | |||
| 576 | |||
| 577 | |||
| 578 | |||
| 579 | ;;;-------------------------- | ||
| 502 | ;;; Fill Comment Paragraph | 580 | ;;; Fill Comment Paragraph |
| 503 | ;;;-------------------------- | 581 | ;;;-------------------------- |
| 504 | 582 | ||
| @@ -723,7 +801,7 @@ reloads the beautified program in the buffer and cleans up | |||
| 723 | ;;;--------------- | 801 | ;;;--------------- |
| 724 | 802 | ||
| 725 | ;; from Philippe Waroquiers <philippe@cfmu.eurocontrol.be> | 803 | ;; from Philippe Waroquiers <philippe@cfmu.eurocontrol.be> |
| 726 | ;; modifiedby RE and MH | 804 | ;; modified by RE and MH |
| 727 | 805 | ||
| 728 | (defun ada-after-keyword-p () | 806 | (defun ada-after-keyword-p () |
| 729 | ;; returns t if cursor is after a keyword. | 807 | ;; returns t if cursor is after a keyword. |
| @@ -736,14 +814,19 @@ reloads the beautified program in the buffer and cleans up | |||
| 736 | (not (looking-at "_"))) ; (MH) | 814 | (not (looking-at "_"))) ; (MH) |
| 737 | (looking-at (concat ada-keywords "[^_]"))))) | 815 | (looking-at (concat ada-keywords "[^_]"))))) |
| 738 | 816 | ||
| 739 | (defun ada-after-char-p () | 817 | (defun ada-in-char-const-p () |
| 740 | ;; returns t if after ada character "'". This is interpreted as being | 818 | ;; Returns t if point is inside a character constant. |
| 741 | ;; in a character constant. | 819 | ;; We assume to be in a constant if the previous and the next character |
| 820 | ;; are "'". | ||
| 742 | (save-excursion | 821 | (save-excursion |
| 743 | (if (> (point) 2) | 822 | (if (> (point) 1) |
| 744 | (progn | 823 | (and |
| 745 | (forward-char -2) | 824 | (progn |
| 746 | (looking-at "'")) | 825 | (forward-char 1) |
| 826 | (looking-at "'")) | ||
| 827 | (progn | ||
| 828 | (forward-char -2) | ||
| 829 | (looking-at "'"))) | ||
| 747 | nil))) | 830 | nil))) |
| 748 | 831 | ||
| 749 | 832 | ||
| @@ -755,7 +838,7 @@ If FORCE-IDENTIFIER is non-nil then also adjust keyword as identifier." ; (MH) | |||
| 755 | (forward-char -1) | 838 | (forward-char -1) |
| 756 | (if (and (> (point) 1) (not (or (ada-in-string-p) | 839 | (if (and (> (point) 1) (not (or (ada-in-string-p) |
| 757 | (ada-in-comment-p) | 840 | (ada-in-comment-p) |
| 758 | (ada-after-char-p)))) | 841 | (ada-in-char-const-p)))) |
| 759 | (if (eq (char-syntax (char-after (1- (point)))) ?w) | 842 | (if (eq (char-syntax (char-after (1- (point)))) ?w) |
| 760 | (if (save-excursion | 843 | (if (save-excursion |
| 761 | (forward-word -1) | 844 | (forward-word -1) |
| @@ -800,7 +883,7 @@ If FORCE-IDENTIFIER is non-nil then also adjust keyword as identifier." ; (MH) | |||
| 800 | ;; save original keybindings to allow swapping ret/lfd | 883 | ;; save original keybindings to allow swapping ret/lfd |
| 801 | ;; when casing is activated | 884 | ;; when casing is activated |
| 802 | ;; the 'or ...' is there to be sure that the value will not | 885 | ;; the 'or ...' is there to be sure that the value will not |
| 803 | ;; be changed again when Ada Mode is called more than once (MH) | 886 | ;; be changed again when Ada mode is called more than once (MH) |
| 804 | (or ada-ret-binding | 887 | (or ada-ret-binding |
| 805 | (setq ada-ret-binding (key-binding "\C-M"))) | 888 | (setq ada-ret-binding (key-binding "\C-M"))) |
| 806 | (or ada-lfd-binding | 889 | (or ada-lfd-binding |
| @@ -834,6 +917,7 @@ ARG is ignored, it's there to fit the standard casing functions' style." | |||
| 834 | 917 | ||
| 835 | ;; | 918 | ;; |
| 836 | ;; added by MH | 919 | ;; added by MH |
| 920 | ;; modified by JSH to handle attributes | ||
| 837 | ;; | 921 | ;; |
| 838 | (defun ada-adjust-case-region (from to) | 922 | (defun ada-adjust-case-region (from to) |
| 839 | "Adjusts the case of all words in the region. | 923 | "Adjusts the case of all words in the region. |
| @@ -842,13 +926,13 @@ Attention: This function might take very long for big regions !" | |||
| 842 | (let ((begin nil) | 926 | (let ((begin nil) |
| 843 | (end nil) | 927 | (end nil) |
| 844 | (keywordp nil) | 928 | (keywordp nil) |
| 845 | (reldiff nil)) | 929 | (attribp nil)) |
| 846 | (unwind-protect | 930 | (unwind-protect |
| 847 | (save-excursion | 931 | (save-excursion |
| 848 | (set-syntax-table ada-mode-symbol-syntax-table) | 932 | (set-syntax-table ada-mode-symbol-syntax-table) |
| 849 | (goto-char to) | 933 | (goto-char to) |
| 850 | ;; | 934 | ;; |
| 851 | ;; loop: look for all identifiers and keywords | 935 | ;; loop: look for all identifiers, keywords, and attributes |
| 852 | ;; | 936 | ;; |
| 853 | (while (re-search-backward | 937 | (while (re-search-backward |
| 854 | "[^a-zA-Z0-9_]\\([a-zA-Z0-9_]+\\)[^a-zA-Z0-9_]" | 938 | "[^a-zA-Z0-9_]\\([a-zA-Z0-9_]+\\)[^a-zA-Z0-9_]" |
| @@ -857,16 +941,15 @@ Attention: This function might take very long for big regions !" | |||
| 857 | ;; | 941 | ;; |
| 858 | ;; print status message | 942 | ;; print status message |
| 859 | ;; | 943 | ;; |
| 860 | (setq reldiff (- (point) from)) | 944 | (message "adjusting case ... %5d characters left" (- (point) from)) |
| 861 | (message "adjusting case ... %5d characters left" | 945 | (setq attribp (looking-at "'[a-zA-Z0-9_]+[^']")) |
| 862 | (- (point) from)) | ||
| 863 | (forward-char 1) | 946 | (forward-char 1) |
| 864 | (or | 947 | (or |
| 865 | ;; do nothing if it is a string or comment | 948 | ;; do nothing if it is a string or comment |
| 866 | (ada-in-string-or-comment-p) | 949 | (ada-in-string-or-comment-p) |
| 867 | (progn | 950 | (progn |
| 868 | ;; | 951 | ;; |
| 869 | ;; get the identifier or keyword | 952 | ;; get the identifier or keyword or attribute |
| 870 | ;; | 953 | ;; |
| 871 | (setq begin (point)) | 954 | (setq begin (point)) |
| 872 | (setq keywordp (looking-at (concat ada-keywords "[^_]"))) | 955 | (setq keywordp (looking-at (concat ada-keywords "[^_]"))) |
| @@ -876,7 +959,9 @@ Attention: This function might take very long for big regions !" | |||
| 876 | ;; | 959 | ;; |
| 877 | (if keywordp | 960 | (if keywordp |
| 878 | (funcall ada-case-keyword -1) | 961 | (funcall ada-case-keyword -1) |
| 879 | (funcall ada-case-identifier -1)) | 962 | (if attribp |
| 963 | (funcall ada-case-attribute -1) | ||
| 964 | (funcall ada-case-identifier -1))) | ||
| 880 | (goto-char begin)))) | 965 | (goto-char begin)))) |
| 881 | (message "adjusting case ... done")) | 966 | (message "adjusting case ... done")) |
| 882 | (set-syntax-table ada-mode-syntax-table)))) | 967 | (set-syntax-table ada-mode-syntax-table)))) |
| @@ -1060,9 +1145,9 @@ In such a case, use `undo', correct the syntax and try again." | |||
| 1060 | (ada-goto-next-non-ws)) | 1145 | (ada-goto-next-non-ws)) |
| 1061 | 1146 | ||
| 1062 | ;; | 1147 | ;; |
| 1063 | ;; read type of parameter | 1148 | ;; read type of parameter |
| 1064 | ;; | 1149 | ;; |
| 1065 | (looking-at "\\<[a-zA-Z0-9_\\.]+\\>") | 1150 | (looking-at "\\<[a-zA-Z0-9_\\.\\']+\\>") |
| 1066 | (setq param | 1151 | (setq param |
| 1067 | (append param | 1152 | (append param |
| 1068 | (list | 1153 | (list |
| @@ -1408,51 +1493,16 @@ Moves to 'begin' if in a declarative part." | |||
| 1408 | (setq lines-remaining (1- lines-remaining))) | 1493 | (setq lines-remaining (1- lines-remaining))) |
| 1409 | ;; show line number where the error occurred | 1494 | ;; show line number where the error occurred |
| 1410 | (error | 1495 | (error |
| 1411 | (error "line %d: %s" (1+ (count-lines (point-min) (point))) err))) | 1496 | (error "line %d: %s" (1+ (count-lines (point-min) (point))) err) nil)) |
| 1412 | (message "indenting ... done"))) | 1497 | (message "indenting ... done"))) |
| 1413 | 1498 | ||
| 1414 | 1499 | ||
| 1415 | (defun ada-indent-newline-indent () | 1500 | (defun ada-indent-newline-indent () |
| 1416 | "Indents the current line, inserts a newline and then indents the new line." | 1501 | "Indents the current line, inserts a newline and then indents the new line." |
| 1417 | (interactive "*") | 1502 | (interactive "*") |
| 1418 | (let ((column) | 1503 | (ada-indent-current) |
| 1419 | (orgpoint)) | 1504 | (newline) |
| 1420 | 1505 | (ada-indent-current)) | |
| 1421 | (ada-indent-current) | ||
| 1422 | (newline) | ||
| 1423 | (delete-horizontal-space) | ||
| 1424 | (setq orgpoint (point)) | ||
| 1425 | |||
| 1426 | (unwind-protect | ||
| 1427 | (progn | ||
| 1428 | (set-syntax-table ada-mode-symbol-syntax-table) | ||
| 1429 | |||
| 1430 | (setq column (save-excursion | ||
| 1431 | (funcall (ada-indent-function) orgpoint)))) | ||
| 1432 | |||
| 1433 | ;; | ||
| 1434 | ;; restore syntax-table | ||
| 1435 | ;; | ||
| 1436 | (set-syntax-table ada-mode-syntax-table)) | ||
| 1437 | |||
| 1438 | (indent-to column) | ||
| 1439 | |||
| 1440 | ;; The following is needed to ensure that indentation will still be | ||
| 1441 | ;; correct if something follows behind point when typing LFD | ||
| 1442 | ;; For example: Imagine point to be there (*) when LFD is typed: | ||
| 1443 | ;; while cond loop | ||
| 1444 | ;; null; *end loop; | ||
| 1445 | ;; Result without the following statement would be: | ||
| 1446 | ;; while cond loop | ||
| 1447 | ;; null; | ||
| 1448 | ;; *end loop; | ||
| 1449 | ;; You would then have to type TAB to correct it. | ||
| 1450 | ;; If that doesn't bother you, you can comment out the following | ||
| 1451 | ;; statement to speed up indentation a LITTLE bit. | ||
| 1452 | |||
| 1453 | (if (not (looking-at "[ \t]*$")) | ||
| 1454 | (ada-indent-current)) | ||
| 1455 | )) | ||
| 1456 | 1506 | ||
| 1457 | 1507 | ||
| 1458 | (defun ada-indent-current () | 1508 | (defun ada-indent-current () |
| @@ -1513,14 +1563,14 @@ This works by two steps: | |||
| 1513 | ;; only reindent if indentation is different then the current | 1563 | ;; only reindent if indentation is different then the current |
| 1514 | (if (= (current-column) cur-indent) | 1564 | (if (= (current-column) cur-indent) |
| 1515 | nil | 1565 | nil |
| 1516 | (delete-horizontal-space) | 1566 | (delete-horizontal-space) |
| 1517 | (indent-to cur-indent)) | 1567 | (indent-to cur-indent)) |
| 1518 | ;; | 1568 | ;; |
| 1519 | ;; restore position of point | 1569 | ;; restore position of point |
| 1520 | ;; | 1570 | ;; |
| 1521 | (goto-char orgpoint) | 1571 | (goto-char orgpoint) |
| 1522 | (if (< (current-column) (current-indentation)) | 1572 | (if (< (current-column) (current-indentation)) |
| 1523 | (back-to-indentation)))))) | 1573 | (back-to-indentation)))))) |
| 1524 | 1574 | ||
| 1525 | ;; | 1575 | ;; |
| 1526 | ;; restore syntax-table | 1576 | ;; restore syntax-table |
| @@ -1557,27 +1607,33 @@ This works by two steps: | |||
| 1557 | ;; end | 1607 | ;; end |
| 1558 | ;; | 1608 | ;; |
| 1559 | ((looking-at "\\<end\\>") | 1609 | ((looking-at "\\<end\\>") |
| 1560 | (save-excursion | 1610 | (let ((label 0)) |
| 1561 | (ada-goto-matching-start 1) | 1611 | (save-excursion |
| 1612 | (ada-goto-matching-start 1) | ||
| 1562 | 1613 | ||
| 1563 | ;; | 1614 | ;; |
| 1564 | ;; found 'loop' => skip back to 'while' or 'for' | 1615 | ;; found 'loop' => skip back to 'while' or 'for' |
| 1565 | ;; if 'loop' is not on a separate line | 1616 | ;; if 'loop' is not on a separate line |
| 1566 | ;; | 1617 | ;; |
| 1567 | (if (and | 1618 | (if (and |
| 1568 | (looking-at "\\<loop\\>") | 1619 | (looking-at "\\<loop\\>") |
| 1569 | (save-excursion | 1620 | (save-excursion |
| 1570 | (back-to-indentation) | 1621 | (back-to-indentation) |
| 1571 | (not (looking-at "\\<loop\\>")))) | 1622 | (not (looking-at "\\<loop\\>")))) |
| 1572 | (if (save-excursion | 1623 | (if (save-excursion |
| 1573 | (and | 1624 | (and |
| 1574 | (setq match-cons | 1625 | (setq match-cons |
| 1575 | (ada-search-ignore-string-comment | 1626 | (ada-search-ignore-string-comment |
| 1576 | ada-loop-start-re t nil)) | 1627 | ada-loop-start-re t nil)) |
| 1577 | (not (looking-at "\\<loop\\>")))) | 1628 | (not (looking-at "\\<loop\\>")))) |
| 1578 | (goto-char (car match-cons)))) | 1629 | (progn |
| 1630 | (goto-char (car match-cons)) | ||
| 1631 | (save-excursion | ||
| 1632 | (beginning-of-line) | ||
| 1633 | (if (looking-at ada-named-block-re) | ||
| 1634 | (setq label (- ada-label-indent))))))) | ||
| 1579 | 1635 | ||
| 1580 | (current-indentation))) | 1636 | (+ (current-indentation) label)))) |
| 1581 | ;; | 1637 | ;; |
| 1582 | ;; exception | 1638 | ;; exception |
| 1583 | ;; | 1639 | ;; |
| @@ -1645,9 +1701,7 @@ This works by two steps: | |||
| 1645 | (save-excursion | 1701 | (save-excursion |
| 1646 | (if (ada-goto-matching-decl-start t) | 1702 | (if (ada-goto-matching-decl-start t) |
| 1647 | (current-indentation) | 1703 | (current-indentation) |
| 1648 | (progn | 1704 | prev-indent))) |
| 1649 | (message "no matching declaration start") | ||
| 1650 | prev-indent)))) | ||
| 1651 | ;; | 1705 | ;; |
| 1652 | ;; is | 1706 | ;; is |
| 1653 | ;; | 1707 | ;; |
| @@ -1774,8 +1828,7 @@ This works by two steps: | |||
| 1774 | ;; the current statement, if NOMOVE is nil. | 1828 | ;; the current statement, if NOMOVE is nil. |
| 1775 | 1829 | ||
| 1776 | (let ((orgpoint (point)) | 1830 | (let ((orgpoint (point)) |
| 1777 | (func nil) | 1831 | (func nil)) |
| 1778 | (stmt-start nil)) | ||
| 1779 | ;; | 1832 | ;; |
| 1780 | ;; inside a parameter-list | 1833 | ;; inside a parameter-list |
| 1781 | ;; | 1834 | ;; |
| @@ -1786,14 +1839,14 @@ This works by two steps: | |||
| 1786 | ;; move to beginning of current statement | 1839 | ;; move to beginning of current statement |
| 1787 | ;; | 1840 | ;; |
| 1788 | (if (not nomove) | 1841 | (if (not nomove) |
| 1789 | (setq stmt-start (ada-goto-stmt-start))) | 1842 | (ada-goto-stmt-start)) |
| 1790 | ;; | 1843 | ;; |
| 1791 | ;; no beginning found => don't change indentation | 1844 | ;; no beginning found => don't change indentation |
| 1792 | ;; | 1845 | ;; |
| 1793 | (if (and | 1846 | (if (and |
| 1794 | (eq orgpoint (point)) | 1847 | (eq orgpoint (point)) |
| 1795 | (not nomove)) | 1848 | (not nomove)) |
| 1796 | (setq func 'ada-get-indent-nochange) | 1849 | (setq func 'ada-get-indent-nochange) |
| 1797 | 1850 | ||
| 1798 | (cond | 1851 | (cond |
| 1799 | ;; | 1852 | ;; |
| @@ -1811,11 +1864,6 @@ This works by two steps: | |||
| 1811 | ((looking-at ada-subprog-start-re) | 1864 | ((looking-at ada-subprog-start-re) |
| 1812 | (setq func 'ada-get-indent-subprog)) | 1865 | (setq func 'ada-get-indent-subprog)) |
| 1813 | ;; | 1866 | ;; |
| 1814 | ((looking-at "\\<package\\>") | ||
| 1815 | (setq func 'ada-get-indent-subprog)) ; maybe it needs a | ||
| 1816 | ; special function | ||
| 1817 | ; sometimes ? | ||
| 1818 | ;; | ||
| 1819 | ((looking-at ada-block-start-re) | 1867 | ((looking-at ada-block-start-re) |
| 1820 | (setq func 'ada-get-indent-block-start)) | 1868 | (setq func 'ada-get-indent-block-start)) |
| 1821 | ;; | 1869 | ;; |
| @@ -1895,6 +1943,7 @@ This works by two steps: | |||
| 1895 | ;; slow, if it has to search through big files with many nested blocks. | 1943 | ;; slow, if it has to search through big files with many nested blocks. |
| 1896 | ;; Signals an error if the corresponding block-start doesn't match. | 1944 | ;; Signals an error if the corresponding block-start doesn't match. |
| 1897 | (let ((defun-name nil) | 1945 | (let ((defun-name nil) |
| 1946 | (label 0) | ||
| 1898 | (indent nil)) | 1947 | (indent nil)) |
| 1899 | ;; | 1948 | ;; |
| 1900 | ;; is the line already terminated by ';' ? | 1949 | ;; is the line already terminated by ';' ? |
| @@ -1921,8 +1970,9 @@ This works by two steps: | |||
| 1921 | (forward-word 1) | 1970 | (forward-word 1) |
| 1922 | (ada-goto-stmt-start))) | 1971 | (ada-goto-stmt-start))) |
| 1923 | ;; a label ? => skip it | 1972 | ;; a label ? => skip it |
| 1924 | (if (looking-at "[a-zA-Z0-9_]+[ \n\t]+:") | 1973 | (if (looking-at ada-named-block-re) |
| 1925 | (progn | 1974 | (progn |
| 1975 | (setq label (- ada-label-indent)) | ||
| 1926 | (goto-char (match-end 0)) | 1976 | (goto-char (match-end 0)) |
| 1927 | (ada-goto-next-non-ws))) | 1977 | (ada-goto-next-non-ws))) |
| 1928 | ;; really looking-at the right thing ? | 1978 | ;; really looking-at the right thing ? |
| @@ -1935,7 +1985,7 @@ This works by two steps: | |||
| 1935 | "loop\\|select\\|if\\|case\\|" | 1985 | "loop\\|select\\|if\\|case\\|" |
| 1936 | "record\\|while\\|type\\)\\>"))) | 1986 | "record\\|while\\|type\\)\\>"))) |
| 1937 | (backward-word 1)) | 1987 | (backward-word 1)) |
| 1938 | (current-indentation))) | 1988 | (+ (current-indentation) label))) |
| 1939 | ;; | 1989 | ;; |
| 1940 | ;; a named block end | 1990 | ;; a named block end |
| 1941 | ;; | 1991 | ;; |
| @@ -1969,7 +2019,7 @@ This works by two steps: | |||
| 1969 | 2019 | ||
| 1970 | (defun ada-get-indent-case (orgpoint) | 2020 | (defun ada-get-indent-case (orgpoint) |
| 1971 | ;; Returns the indentation (column #) for the new line after ORGPOINT. | 2021 | ;; Returns the indentation (column #) for the new line after ORGPOINT. |
| 1972 | ;; Assumes point to be at the beginning of an case-statement. | 2022 | ;; Assumes point to be at the beginning of a case-statement. |
| 1973 | (let ((cur-indent (current-indentation)) | 2023 | (let ((cur-indent (current-indentation)) |
| 1974 | (match-cons nil) | 2024 | (match-cons nil) |
| 1975 | (opos (point))) | 2025 | (opos (point))) |
| @@ -1978,8 +2028,12 @@ This works by two steps: | |||
| 1978 | ;; case..is..when..=> | 2028 | ;; case..is..when..=> |
| 1979 | ;; | 2029 | ;; |
| 1980 | ((save-excursion | 2030 | ((save-excursion |
| 1981 | (setq match-cons (ada-search-ignore-string-comment | 2031 | (setq match-cons (and |
| 1982 | "[ \t\n]+=>" nil orgpoint))) | 2032 | ;; the `=>' must be after the keyword `is'. |
| 2033 | (ada-search-ignore-string-comment | ||
| 2034 | "\\<is\\>" nil orgpoint) | ||
| 2035 | (ada-search-ignore-string-comment | ||
| 2036 | "[ \t\n]+=>" nil orgpoint)))) | ||
| 1983 | (save-excursion | 2037 | (save-excursion |
| 1984 | (goto-char (car match-cons)) | 2038 | (goto-char (car match-cons)) |
| 1985 | (if (not (ada-search-ignore-string-comment "\\<when\\>" t opos)) | 2039 | (if (not (ada-search-ignore-string-comment "\\<when\\>" t opos)) |
| @@ -2090,7 +2144,7 @@ This works by two steps: | |||
| 2090 | (if (save-excursion | 2144 | (if (save-excursion |
| 2091 | (setq match-cons | 2145 | (setq match-cons |
| 2092 | (ada-search-ignore-string-comment | 2146 | (ada-search-ignore-string-comment |
| 2093 | "\\<is\\>\\|\\<do\\>" nil orgpoint))) | 2147 | "\\<\\(is\\|do\\)\\>" nil orgpoint))) |
| 2094 | ;; | 2148 | ;; |
| 2095 | ;; yes, then skip to its end | 2149 | ;; yes, then skip to its end |
| 2096 | ;; | 2150 | ;; |
| @@ -2153,10 +2207,15 @@ This works by two steps: | |||
| 2153 | (defun ada-get-indent-noindent (orgpoint) | 2207 | (defun ada-get-indent-noindent (orgpoint) |
| 2154 | ;; Returns the indentation (column #) for the new line after ORGPOINT. | 2208 | ;; Returns the indentation (column #) for the new line after ORGPOINT. |
| 2155 | ;; Assumes point to be at the beginning of a 'noindent statement'. | 2209 | ;; Assumes point to be at the beginning of a 'noindent statement'. |
| 2156 | (if (save-excursion | 2210 | (let ((label 0)) |
| 2157 | (ada-search-ignore-string-comment ";" nil orgpoint)) | 2211 | (save-excursion |
| 2158 | (current-indentation) | 2212 | (beginning-of-line) |
| 2159 | (+ (current-indentation) ada-broken-indent))) | 2213 | (if (looking-at ada-named-block-re) |
| 2214 | (setq label (- ada-label-indent)))) | ||
| 2215 | (if (save-excursion | ||
| 2216 | (ada-search-ignore-string-comment ";" nil orgpoint)) | ||
| 2217 | (+ (current-indentation) label) | ||
| 2218 | (+ (current-indentation) ada-broken-indent label)))) | ||
| 2160 | 2219 | ||
| 2161 | 2220 | ||
| 2162 | (defun ada-get-indent-label (orgpoint) | 2221 | (defun ada-get-indent-label (orgpoint) |
| @@ -2181,7 +2240,7 @@ This works by two steps: | |||
| 2181 | ;; | 2240 | ;; |
| 2182 | ((save-excursion | 2241 | ((save-excursion |
| 2183 | (setq match-cons (ada-search-ignore-string-comment | 2242 | (setq match-cons (ada-search-ignore-string-comment |
| 2184 | "\\<declare\\>" nil orgpoint))) | 2243 | "\\<declare\\|begin\\>" nil orgpoint))) |
| 2185 | (save-excursion | 2244 | (save-excursion |
| 2186 | (goto-char (car match-cons)) | 2245 | (goto-char (car match-cons)) |
| 2187 | (+ (current-indentation) ada-indent))) | 2246 | (+ (current-indentation) ada-indent))) |
| @@ -2215,7 +2274,13 @@ This works by two steps: | |||
| 2215 | ;; Assumes point to be at the beginning of a loop statement | 2274 | ;; Assumes point to be at the beginning of a loop statement |
| 2216 | ;; or (unfortunately) also a for ... use statement. | 2275 | ;; or (unfortunately) also a for ... use statement. |
| 2217 | (let ((match-cons nil) | 2276 | (let ((match-cons nil) |
| 2218 | (pos (point))) | 2277 | (pos (point)) |
| 2278 | (label (save-excursion | ||
| 2279 | (beginning-of-line) | ||
| 2280 | (if (looking-at ada-named-block-re) | ||
| 2281 | (- ada-label-indent) | ||
| 2282 | 0)))) | ||
| 2283 | |||
| 2219 | (cond | 2284 | (cond |
| 2220 | 2285 | ||
| 2221 | ;; | 2286 | ;; |
| @@ -2223,12 +2288,12 @@ This works by two steps: | |||
| 2223 | ;; | 2288 | ;; |
| 2224 | ((save-excursion | 2289 | ((save-excursion |
| 2225 | (ada-search-ignore-string-comment ";" nil orgpoint)) | 2290 | (ada-search-ignore-string-comment ";" nil orgpoint)) |
| 2226 | (current-indentation)) | 2291 | (+ (current-indentation) label)) |
| 2227 | ;; | 2292 | ;; |
| 2228 | ;; simple loop | 2293 | ;; simple loop |
| 2229 | ;; | 2294 | ;; |
| 2230 | ((looking-at "loop\\>") | 2295 | ((looking-at "loop\\>") |
| 2231 | (ada-get-indent-block-start orgpoint)) | 2296 | (+ (ada-get-indent-block-start orgpoint) label)) |
| 2232 | 2297 | ||
| 2233 | ;; | 2298 | ;; |
| 2234 | ;; 'for'- loop (or also a for ... use statement) | 2299 | ;; 'for'- loop (or also a for ... use statement) |
| @@ -2272,12 +2337,12 @@ This works by two steps: | |||
| 2272 | (back-to-indentation) | 2337 | (back-to-indentation) |
| 2273 | (looking-at "\\<loop\\>"))) | 2338 | (looking-at "\\<loop\\>"))) |
| 2274 | (goto-char pos)) | 2339 | (goto-char pos)) |
| 2275 | (+ (current-indentation) ada-indent)) | 2340 | (+ (current-indentation) ada-indent label)) |
| 2276 | ;; | 2341 | ;; |
| 2277 | ;; for-statement is broken | 2342 | ;; for-statement is broken |
| 2278 | ;; | 2343 | ;; |
| 2279 | (t | 2344 | (t |
| 2280 | (+ (current-indentation) ada-broken-indent)))) | 2345 | (+ (current-indentation) ada-broken-indent label)))) |
| 2281 | 2346 | ||
| 2282 | ;; | 2347 | ;; |
| 2283 | ;; 'while'-loop | 2348 | ;; 'while'-loop |
| @@ -2300,9 +2365,9 @@ This works by two steps: | |||
| 2300 | (back-to-indentation) | 2365 | (back-to-indentation) |
| 2301 | (looking-at "\\<loop\\>"))) | 2366 | (looking-at "\\<loop\\>"))) |
| 2302 | (goto-char pos)) | 2367 | (goto-char pos)) |
| 2303 | (+ (current-indentation) ada-indent)) | 2368 | (+ (current-indentation) ada-indent label)) |
| 2304 | 2369 | ||
| 2305 | (+ (current-indentation) ada-broken-indent)))))) | 2370 | (+ (current-indentation) ada-broken-indent label)))))) |
| 2306 | 2371 | ||
| 2307 | 2372 | ||
| 2308 | (defun ada-get-indent-type (orgpoint) | 2373 | (defun ada-get-indent-type (orgpoint) |
| @@ -2416,7 +2481,6 @@ This works by two steps: | |||
| 2416 | ;; End-statements are defined by 'ada-end-stmt-re'. Checks for | 2481 | ;; End-statements are defined by 'ada-end-stmt-re'. Checks for |
| 2417 | ;; certain keywords if they follow 'end', which means they are no | 2482 | ;; certain keywords if they follow 'end', which means they are no |
| 2418 | ;; end-statement there. | 2483 | ;; end-statement there. |
| 2419 | (interactive) ;; DEBUG | ||
| 2420 | (let ((match-dat nil) | 2484 | (let ((match-dat nil) |
| 2421 | (pos nil) | 2485 | (pos nil) |
| 2422 | (found nil)) | 2486 | (found nil)) |
| @@ -2431,18 +2495,22 @@ This works by two steps: | |||
| 2431 | limit))) | 2495 | limit))) |
| 2432 | 2496 | ||
| 2433 | (goto-char (car match-dat)) | 2497 | (goto-char (car match-dat)) |
| 2434 | |||
| 2435 | (if (not (ada-in-open-paren-p)) | 2498 | (if (not (ada-in-open-paren-p)) |
| 2436 | ;; | 2499 | ;; |
| 2437 | ;; check if there is an 'end' in front of the match | 2500 | ;; check if there is an 'end' in front of the match |
| 2438 | ;; | 2501 | ;; |
| 2439 | (if (not (and | 2502 | (if (not (and |
| 2440 | (looking-at "\\<\\(record\\|loop\\|select\\)\\>") | 2503 | (looking-at |
| 2504 | "\\<\\(record\\|loop\\|select\\|else\\|then\\)\\>") | ||
| 2441 | (save-excursion | 2505 | (save-excursion |
| 2442 | (ada-goto-previous-word) | 2506 | (ada-goto-previous-word) |
| 2443 | (looking-at "\\<end\\>")))) | 2507 | (looking-at "\\<\\(end\\|or\\|and\\)\\>")))) |
| 2444 | (setq found t) | 2508 | (save-excursion |
| 2445 | 2509 | (goto-char (cdr match-dat)) | |
| 2510 | (ada-goto-next-word) | ||
| 2511 | (if (not (looking-at "\\<\\(separate\\|new\\)\\>")) | ||
| 2512 | (setq found t))) | ||
| 2513 | |||
| 2446 | (forward-word -1)))) ; end of loop | 2514 | (forward-word -1)))) ; end of loop |
| 2447 | 2515 | ||
| 2448 | (if found | 2516 | (if found |
| @@ -2472,18 +2540,21 @@ This works by two steps: | |||
| 2472 | nil)) | 2540 | nil)) |
| 2473 | 2541 | ||
| 2474 | 2542 | ||
| 2475 | (defun ada-goto-previous-word () | 2543 | (defun ada-goto-next-word (&optional backward) |
| 2476 | ;; Moves point to the beginning of the previous word of Ada code. | 2544 | ;; Moves point to the beginning of the next word of Ada code. |
| 2545 | ;; If BACKWARD is non-nil, jump to the beginning of the previous word. | ||
| 2477 | ;; Returns the new position of point or nil if not found. | 2546 | ;; Returns the new position of point or nil if not found. |
| 2478 | (let ((match-cons nil) | 2547 | (let ((match-cons nil) |
| 2479 | (orgpoint (point))) | 2548 | (orgpoint (point))) |
| 2549 | (if (not backward) | ||
| 2550 | (skip-chars-forward "_a-zA-Z0-9\\.")) | ||
| 2480 | (if (setq match-cons | 2551 | (if (setq match-cons |
| 2481 | (ada-search-ignore-string-comment "[^ \t\n]" t nil t)) | 2552 | (ada-search-ignore-string-comment "\\w" backward nil t)) |
| 2482 | ;; | 2553 | ;; |
| 2483 | ;; move to the beginning of the word found | 2554 | ;; move to the beginning of the word found |
| 2484 | ;; | 2555 | ;; |
| 2485 | (progn | 2556 | (progn |
| 2486 | (goto-char (cdr match-cons)) | 2557 | (goto-char (car match-cons)) |
| 2487 | (skip-chars-backward "_a-zA-Z0-9") | 2558 | (skip-chars-backward "_a-zA-Z0-9") |
| 2488 | (point)) | 2559 | (point)) |
| 2489 | ;; | 2560 | ;; |
| @@ -2494,6 +2565,12 @@ This works by two steps: | |||
| 2494 | 'nil)))) | 2565 | 'nil)))) |
| 2495 | 2566 | ||
| 2496 | 2567 | ||
| 2568 | (defun ada-goto-previous-word () | ||
| 2569 | ;; Moves point to the beginning of the previous word of Ada code. | ||
| 2570 | ;; Returns the new position of point or nil if not found. | ||
| 2571 | (ada-goto-next-word t)) | ||
| 2572 | |||
| 2573 | |||
| 2497 | (defun ada-check-matching-start (keyword) | 2574 | (defun ada-check-matching-start (keyword) |
| 2498 | ;; Signals an error if matching block start is not KEYWORD. | 2575 | ;; Signals an error if matching block start is not KEYWORD. |
| 2499 | ;; Moves point to the matching block start. | 2576 | ;; Moves point to the matching block start. |
| @@ -2508,45 +2585,51 @@ This works by two steps: | |||
| 2508 | ;; Moves point to the beginning of the declaration. | 2585 | ;; Moves point to the beginning of the declaration. |
| 2509 | 2586 | ||
| 2510 | ;; | 2587 | ;; |
| 2511 | ;; 'accept' or 'package' ? | 2588 | ;; named block without a `declare' |
| 2512 | ;; | 2589 | ;; |
| 2513 | (if (not (looking-at "\\<\\(accept\\|package\\|task\\|protected\\)\\>")) | 2590 | (if (save-excursion |
| 2514 | (ada-goto-matching-decl-start)) | 2591 | (ada-goto-previous-word) |
| 2515 | ;; | 2592 | (looking-at (concat "\\<" defun-name "\\> *:"))) |
| 2516 | ;; 'begin' of 'procedure'/'function'/'task' or 'declare' | 2593 | t ; do nothing |
| 2517 | ;; | ||
| 2518 | (save-excursion | ||
| 2519 | ;; | 2594 | ;; |
| 2520 | ;; a named 'declare'-block ? | 2595 | ;; 'accept' or 'package' ? |
| 2521 | ;; | 2596 | ;; |
| 2522 | (if (looking-at "\\<declare\\>") | 2597 | (if (not (looking-at "\\<\\(accept\\|package\\|task\\|protected\\)\\>")) |
| 2523 | (ada-goto-stmt-start) | 2598 | (ada-goto-matching-decl-start)) |
| 2599 | ;; | ||
| 2600 | ;; 'begin' of 'procedure'/'function'/'task' or 'declare' | ||
| 2601 | ;; | ||
| 2602 | (save-excursion | ||
| 2524 | ;; | 2603 | ;; |
| 2525 | ;; no, => 'procedure'/'function'/'task'/'protected' | 2604 | ;; a named 'declare'-block ? |
| 2526 | ;; | 2605 | ;; |
| 2527 | (progn | 2606 | (if (looking-at "\\<declare\\>") |
| 2528 | (forward-word 2) | 2607 | (ada-goto-stmt-start) |
| 2529 | (backward-word 1) | ||
| 2530 | ;; | 2608 | ;; |
| 2531 | ;; skip 'body' 'protected' 'type' | 2609 | ;; no, => 'procedure'/'function'/'task'/'protected' |
| 2532 | ;; | 2610 | ;; |
| 2533 | (if (looking-at "\\<\\(body\\|type\\)\\>") | 2611 | (progn |
| 2534 | (forward-word 1)) | 2612 | (forward-word 2) |
| 2535 | (forward-sexp 1) | 2613 | (backward-word 1) |
| 2536 | (backward-sexp 1))) | 2614 | ;; |
| 2537 | ;; | 2615 | ;; skip 'body' 'type' |
| 2538 | ;; should be looking-at the correct name | 2616 | ;; |
| 2539 | ;; | 2617 | (if (looking-at "\\<\\(body\\|type\\)\\>") |
| 2540 | (if (not (looking-at (concat "\\<" defun-name "\\>"))) | 2618 | (forward-word 1)) |
| 2541 | (error "matching defun has different name: %s" | 2619 | (forward-sexp 1) |
| 2542 | (buffer-substring (point) | 2620 | (backward-sexp 1))) |
| 2543 | (progn (forward-sexp 1) (point))))))) | 2621 | ;; |
| 2622 | ;; should be looking-at the correct name | ||
| 2623 | ;; | ||
| 2624 | (if (not (looking-at (concat "\\<" defun-name "\\>"))) | ||
| 2625 | (error "matching defun has different name: %s" | ||
| 2626 | (buffer-substring (point) | ||
| 2627 | (progn (forward-sexp 1) (point)))))))) | ||
| 2544 | 2628 | ||
| 2545 | 2629 | ||
| 2546 | (defun ada-goto-matching-decl-start (&optional noerror nogeneric) | 2630 | (defun ada-goto-matching-decl-start (&optional noerror nogeneric) |
| 2547 | ;; Moves point to the matching declaration start of the current 'begin'. | 2631 | ;; Moves point to the matching declaration start of the current 'begin'. |
| 2548 | ;; If NOERROR is non-nil, it only returns nil if no match was found. | 2632 | ;; If NOERROR is non-nil, it only returns nil if no match was found. |
| 2549 | (interactive) ;; DEBUG | ||
| 2550 | (let ((nest-count 1) | 2633 | (let ((nest-count 1) |
| 2551 | (pos nil) | 2634 | (pos nil) |
| 2552 | (first t) | 2635 | (first t) |
| @@ -2577,24 +2660,25 @@ This works by two steps: | |||
| 2577 | ((looking-at "is") | 2660 | ((looking-at "is") |
| 2578 | ;; check if it is only a type definition, but not a protected | 2661 | ;; check if it is only a type definition, but not a protected |
| 2579 | ;; type definition, which should be handled like a procedure. | 2662 | ;; type definition, which should be handled like a procedure. |
| 2580 | (if (save-excursion | 2663 | (if (or (looking-at "is +<>") |
| 2581 | (ada-goto-previous-word) | 2664 | (save-excursion |
| 2582 | (skip-chars-backward "a-zA-Z0-9_.'") | 2665 | (ada-goto-previous-word) |
| 2583 | (if (save-excursion | 2666 | (skip-chars-backward "a-zA-Z0-9_.'") |
| 2584 | (backward-char 1) | 2667 | (if (save-excursion |
| 2585 | (looking-at ")")) | 2668 | (backward-char 1) |
| 2586 | (progn | 2669 | (looking-at ")")) |
| 2587 | (forward-char 1) | 2670 | (progn |
| 2588 | (backward-sexp 1) | 2671 | (forward-char 1) |
| 2589 | (skip-chars-backward "a-zA-Z0-9_.'") | 2672 | (backward-sexp 1) |
| 2590 | )) | 2673 | (skip-chars-backward "a-zA-Z0-9_.'") |
| 2591 | (ada-goto-previous-word) | 2674 | )) |
| 2592 | (and | 2675 | (ada-goto-previous-word) |
| 2593 | (looking-at "\\<type\\>") | 2676 | (and |
| 2594 | (save-match-data | 2677 | (looking-at "\\<type\\>") |
| 2595 | (ada-goto-previous-word) | 2678 | (save-match-data |
| 2596 | (not (looking-at "\\<protected\\>")))) | 2679 | (ada-goto-previous-word) |
| 2597 | ); end of save-excursion | 2680 | (not (looking-at "\\<protected\\>")))) |
| 2681 | )); end of `or' | ||
| 2598 | (goto-char (match-beginning 0)) | 2682 | (goto-char (match-beginning 0)) |
| 2599 | (progn | 2683 | (progn |
| 2600 | (setq nest-count (1- nest-count)) | 2684 | (setq nest-count (1- nest-count)) |
| @@ -2623,11 +2707,9 @@ This works by two steps: | |||
| 2623 | (and | 2707 | (and |
| 2624 | (zerop nest-count) | 2708 | (zerop nest-count) |
| 2625 | (not flag) | 2709 | (not flag) |
| 2626 | (progn | 2710 | (if (looking-at "is") |
| 2627 | (if (looking-at "is") | 2711 | (ada-search-ignore-string-comment ada-subprog-start-re t) |
| 2628 | (ada-search-ignore-string-comment | 2712 | (looking-at "declare\\|generic")))) |
| 2629 | ada-subprog-start-re t) | ||
| 2630 | (looking-at "declare\\|generic"))))) | ||
| 2631 | (if noerror nil | 2713 | (if noerror nil |
| 2632 | (error "no matching proc/func/task/declare/package/protected")) | 2714 | (error "no matching proc/func/task/declare/package/protected")) |
| 2633 | t))) | 2715 | t))) |
| @@ -2670,7 +2752,7 @@ This works by two steps: | |||
| 2670 | ;; check if keyword follows 'end' | 2752 | ;; check if keyword follows 'end' |
| 2671 | ;; | 2753 | ;; |
| 2672 | (ada-goto-previous-word) | 2754 | (ada-goto-previous-word) |
| 2673 | (if (looking-at "\\<end\\>") | 2755 | (if (looking-at "\\<end\\> *[^;]") |
| 2674 | ;; it ends a block => increase nest depth | 2756 | ;; it ends a block => increase nest depth |
| 2675 | (progn | 2757 | (progn |
| 2676 | (setq nest-count (1+ nest-count)) | 2758 | (setq nest-count (1+ nest-count)) |
| @@ -3062,14 +3144,11 @@ This works by two steps: | |||
| 3062 | 3144 | ||
| 3063 | (defun ada-in-comment-p () | 3145 | (defun ada-in-comment-p () |
| 3064 | ;; Returns t if inside a comment. | 3146 | ;; Returns t if inside a comment. |
| 3065 | ;; (save-excursion (and (re-search-backward "\\(--\\|\n\\)" nil 1) | ||
| 3066 | ;; (looking-at "-")))) | ||
| 3067 | (nth 4 (parse-partial-sexp | 3147 | (nth 4 (parse-partial-sexp |
| 3068 | (save-excursion (beginning-of-line) (point)) | 3148 | (save-excursion (beginning-of-line) (point)) |
| 3069 | (point)))) | 3149 | (point)))) |
| 3070 | 3150 | ||
| 3071 | 3151 | ||
| 3072 | |||
| 3073 | (defun ada-in-string-p () | 3152 | (defun ada-in-string-p () |
| 3074 | ;; Returns t if point is inside a string | 3153 | ;; Returns t if point is inside a string |
| 3075 | ;; (Taken from pascal-mode.el, modified by MH). | 3154 | ;; (Taken from pascal-mode.el, modified by MH). |
| @@ -3081,14 +3160,25 @@ This works by two steps: | |||
| 3081 | (point)) (point))) | 3160 | (point)) (point))) |
| 3082 | ;; check if 'string quote' is only a character constant | 3161 | ;; check if 'string quote' is only a character constant |
| 3083 | (progn | 3162 | (progn |
| 3084 | (re-search-backward "\"" nil t) ; # not a string delimiter anymore | 3163 | (re-search-backward "\"" nil t) ; `#' is not taken as a string delimiter |
| 3085 | (not (= (char-after (1- (point))) ?')))))) | 3164 | (not (= (char-after (1- (point))) ?')))))) |
| 3086 | 3165 | ||
| 3087 | 3166 | ||
| 3088 | (defun ada-in-string-or-comment-p () | 3167 | (defun ada-in-string-or-comment-p () |
| 3089 | ;; Returns t if point is inside a string or a comment. | 3168 | ;; Returns t if point is inside a string, a comment, or a character constant. |
| 3090 | (or (ada-in-comment-p) | 3169 | (let ((parse-result (parse-partial-sexp |
| 3091 | (ada-in-string-p))) | 3170 | (save-excursion (beginning-of-line) (point)) (point)))) |
| 3171 | (or ;; in-comment-p | ||
| 3172 | (nth 4 parse-result) | ||
| 3173 | ;; in-string-p | ||
| 3174 | (and | ||
| 3175 | (nth 3 parse-result) | ||
| 3176 | ;; check if 'string quote' is only a character constant | ||
| 3177 | (progn | ||
| 3178 | (re-search-backward "\"" nil t) ; `#' not regarded a string delimiter | ||
| 3179 | (not (= (char-after (1- (point))) ?')))) | ||
| 3180 | ;; in-char-const-p | ||
| 3181 | (ada-in-char-const-p)))) | ||
| 3092 | 3182 | ||
| 3093 | 3183 | ||
| 3094 | (defun ada-in-paramlist-p () | 3184 | (defun ada-in-paramlist-p () |
| @@ -3115,10 +3205,12 @@ This works by two steps: | |||
| 3115 | ;; If point is somewhere behind an open parenthesis not yet closed, | 3205 | ;; If point is somewhere behind an open parenthesis not yet closed, |
| 3116 | ;; it returns the column # of the first non-ws behind this open | 3206 | ;; it returns the column # of the first non-ws behind this open |
| 3117 | ;; parenthesis, otherwise nil." | 3207 | ;; parenthesis, otherwise nil." |
| 3118 | 3208 | (let ((start (if (<= (point) ada-search-paren-char-count-limit) | |
| 3119 | (let ((start (if (< (point) ada-search-paren-char-count-limit) | 3209 | (point-min) |
| 3120 | 1 | 3210 | (save-excursion |
| 3121 | (- (point) ada-search-paren-char-count-limit))) | 3211 | (goto-char (- (point) ada-search-paren-char-count-limit)) |
| 3212 | (beginning-of-line) | ||
| 3213 | (point)))) | ||
| 3122 | parse-result | 3214 | parse-result |
| 3123 | (col nil)) | 3215 | (col nil)) |
| 3124 | (setq parse-result (parse-partial-sexp start (point))) | 3216 | (setq parse-result (parse-partial-sexp start (point))) |
| @@ -3167,7 +3259,7 @@ This works by two steps: | |||
| 3167 | 3259 | ||
| 3168 | 3260 | ||
| 3169 | (defun ada-indent-current-function () | 3261 | (defun ada-indent-current-function () |
| 3170 | "Ada Mode version of the indent-line-function." | 3262 | "Ada mode version of the indent-line-function." |
| 3171 | (interactive "*") | 3263 | (interactive "*") |
| 3172 | (let ((starting-point (point-marker))) | 3264 | (let ((starting-point (point-marker))) |
| 3173 | (ada-beginning-of-line) | 3265 | (ada-beginning-of-line) |
| @@ -3205,10 +3297,10 @@ This works by two steps: | |||
| 3205 | "remove trailing spaces in the whole buffer." | 3297 | "remove trailing spaces in the whole buffer." |
| 3206 | (interactive) | 3298 | (interactive) |
| 3207 | (save-match-data | 3299 | (save-match-data |
| 3208 | (save-excursion | 3300 | (save-excursion |
| 3209 | (save-restriction | 3301 | (save-restriction |
| 3210 | (widen) | 3302 | (widen) |
| 3211 | (goto-char (point-min)) | 3303 | (goto-char (point-min)) |
| 3212 | (while (re-search-forward "[ \t]+$" (point-max) t) | 3304 | (while (re-search-forward "[ \t]+$" (point-max) t) |
| 3213 | (replace-match "" nil nil)))))) | 3305 | (replace-match "" nil nil)))))) |
| 3214 | 3306 | ||
| @@ -3216,7 +3308,8 @@ This works by two steps: | |||
| 3216 | (defun ada-untabify-buffer () | 3308 | (defun ada-untabify-buffer () |
| 3217 | ;; change all tabs to spaces | 3309 | ;; change all tabs to spaces |
| 3218 | (save-excursion | 3310 | (save-excursion |
| 3219 | (untabify (point-min) (point-max)))) | 3311 | (untabify (point-min) (point-max)) |
| 3312 | nil)) | ||
| 3220 | 3313 | ||
| 3221 | 3314 | ||
| 3222 | (defun ada-uncomment-region (beg end) | 3315 | (defun ada-uncomment-region (beg end) |
| @@ -3232,6 +3325,23 @@ This works by two steps: | |||
| 3232 | (and (fboundp 'ff-find-other-file) | 3325 | (and (fboundp 'ff-find-other-file) |
| 3233 | (ff-find-other-file t))) | 3326 | (ff-find-other-file t))) |
| 3234 | 3327 | ||
| 3328 | ;; inspired by Laurent.GUERBY@enst-bretagne.fr | ||
| 3329 | (defun ada-gnat-style () | ||
| 3330 | "Clean up comments, `(' and `,' for GNAT style checking switch." | ||
| 3331 | (interactive) | ||
| 3332 | (save-excursion | ||
| 3333 | (goto-char (point-min)) | ||
| 3334 | (while (re-search-forward "-- ?\\([^ -]\\)" nil t) | ||
| 3335 | (replace-match "-- \\1")) | ||
| 3336 | (goto-char (point-min)) | ||
| 3337 | (while (re-search-forward "\\>(" nil t) | ||
| 3338 | (replace-match " (")) | ||
| 3339 | (goto-char (point-min)) | ||
| 3340 | (while (re-search-forward ",\\<" nil t) | ||
| 3341 | (replace-match ", ")) | ||
| 3342 | )) | ||
| 3343 | |||
| 3344 | |||
| 3235 | 3345 | ||
| 3236 | ;;;-------------------------------;;; | 3346 | ;;;-------------------------------;;; |
| 3237 | ;;; Moving To Procedures/Packages ;;; | 3347 | ;;; Moving To Procedures/Packages ;;; |
| @@ -3302,6 +3412,8 @@ This works by two steps: | |||
| 3302 | 3412 | ||
| 3303 | ;; Compilation | 3413 | ;; Compilation |
| 3304 | (define-key ada-mode-map "\C-c\C-c" 'compile) | 3414 | (define-key ada-mode-map "\C-c\C-c" 'compile) |
| 3415 | (define-key ada-mode-map "\C-c\C-v" 'ada-check-syntax) | ||
| 3416 | (define-key ada-mode-map "\C-c\C-m" 'ada-make-local) | ||
| 3305 | 3417 | ||
| 3306 | ;; Casing | 3418 | ;; Casing |
| 3307 | (define-key ada-mode-map "\C-c\C-r" 'ada-adjust-case-region) | 3419 | (define-key ada-mode-map "\C-c\C-r" 'ada-adjust-case-region) |
| @@ -3315,10 +3427,10 @@ This works by two steps: | |||
| 3315 | 3427 | ||
| 3316 | ;; Change basic functionality | 3428 | ;; Change basic functionality |
| 3317 | 3429 | ||
| 3318 | ;; `substitute-key-definition' is not defined equally in GNU Emacs | 3430 | ;; `substitute-key-definition' is not defined equally in Emacs |
| 3319 | ;; and XEmacs, you cannot put in an optional 4th parameter in | 3431 | ;; and XEmacs, you cannot put in an optional 4th parameter in |
| 3320 | ;; XEmacs. I don't think it's necessary, so I leave it out for | 3432 | ;; XEmacs. I don't think it's necessary, so I leave it out for |
| 3321 | ;; GNU Emacs as well. If you encounter any problems with the | 3433 | ;; Emacs as well. If you encounter any problems with the |
| 3322 | ;; following three functions, please tell me. RE | 3434 | ;; following three functions, please tell me. RE |
| 3323 | (mapcar (function (lambda (pair) | 3435 | (mapcar (function (lambda (pair) |
| 3324 | (substitute-key-definition (car pair) (cdr pair) | 3436 | (substitute-key-definition (car pair) (cdr pair) |
| @@ -3327,7 +3439,7 @@ This works by two steps: | |||
| 3327 | (end-of-line . ada-end-of-line) | 3439 | (end-of-line . ada-end-of-line) |
| 3328 | (forward-to-indentation . ada-forward-to-indentation) | 3440 | (forward-to-indentation . ada-forward-to-indentation) |
| 3329 | )) | 3441 | )) |
| 3330 | ;; else GNU Emacs | 3442 | ;; else Emacs |
| 3331 | ;;(mapcar (lambda (pair) | 3443 | ;;(mapcar (lambda (pair) |
| 3332 | ;; (substitute-key-definition (car pair) (cdr pair) | 3444 | ;; (substitute-key-definition (car pair) (cdr pair) |
| 3333 | ;; ada-mode-map global-map)) | 3445 | ;; ada-mode-map global-map)) |
| @@ -3342,7 +3454,7 @@ This works by two steps: | |||
| 3342 | (require 'easymenu) | 3454 | (require 'easymenu) |
| 3343 | 3455 | ||
| 3344 | (defun ada-add-ada-menu () | 3456 | (defun ada-add-ada-menu () |
| 3345 | "Adds the menu 'Ada' to the menu bar in Ada Mode." | 3457 | "Adds the menu 'Ada' to the menu bar in Ada mode." |
| 3346 | (easy-menu-define ada-mode-menu ada-mode-map "Menu keymap for Ada mode." | 3458 | (easy-menu-define ada-mode-menu ada-mode-map "Menu keymap for Ada mode." |
| 3347 | '("Ada" | 3459 | '("Ada" |
| 3348 | ["Next Package" ada-next-package t] | 3460 | ["Next Package" ada-next-package t] |
| @@ -3371,7 +3483,9 @@ This works by two steps: | |||
| 3371 | ["Comment Region" comment-region t] | 3483 | ["Comment Region" comment-region t] |
| 3372 | ["Uncomment Region" ada-uncomment-region t] | 3484 | ["Uncomment Region" ada-uncomment-region t] |
| 3373 | ["----------------" nil nil] | 3485 | ["----------------" nil nil] |
| 3374 | ["Compile" compile (fboundp 'compile)] | 3486 | ["Global Make" compile (fboundp 'compile)] |
| 3487 | ["Local Make" ada-make-local t] | ||
| 3488 | ["Check Syntax" ada-check-syntax t] | ||
| 3375 | ["Next Error" next-error (fboundp 'next-error)] | 3489 | ["Next Error" next-error (fboundp 'next-error)] |
| 3376 | ["---------------" nil nil] | 3490 | ["---------------" nil nil] |
| 3377 | ["Index" imenu (fboundp 'imenu)] | 3491 | ["Index" imenu (fboundp 'imenu)] |
| @@ -3382,7 +3496,7 @@ This works by two steps: | |||
| 3382 | (fboundp 'ff-find-other-file)])) | 3496 | (fboundp 'ff-find-other-file)])) |
| 3383 | (if (ada-xemacs) (progn | 3497 | (if (ada-xemacs) (progn |
| 3384 | (easy-menu-add ada-mode-menu) | 3498 | (easy-menu-add ada-mode-menu) |
| 3385 | (setq mode-popup-menu (cons "Ada Mode" ada-mode-menu))))) | 3499 | (setq mode-popup-menu (cons "Ada mode" ada-mode-menu))))) |
| 3386 | 3500 | ||
| 3387 | 3501 | ||
| 3388 | 3502 | ||
| @@ -3425,30 +3539,15 @@ This works by two steps: | |||
| 3425 | ;;;###autoload | 3539 | ;;;###autoload |
| 3426 | (defun ada-make-filename-from-adaname (adaname) | 3540 | (defun ada-make-filename-from-adaname (adaname) |
| 3427 | "Determine the filename of a package/procedure from its own Ada name." | 3541 | "Determine the filename of a package/procedure from its own Ada name." |
| 3428 | ;; this is done simply by calling gkrunch, when we work with GNAT. It | 3542 | ;; this is done simply by calling `gnatkr', when we work with GNAT. It |
| 3429 | ;; must be a more complex function in other compiler environments. | 3543 | ;; must be a more complex function in other compiler environments. |
| 3430 | (interactive "s") | 3544 | (interactive "s") |
| 3431 | |||
| 3432 | ;; things that should really be done by the external process | ||
| 3433 | ;; since gnat-2.0, gnatk8 can do these things. If you still use a | ||
| 3434 | ;; previous version, just uncomment the following lines. | ||
| 3435 | (let (krunch-buf) | 3545 | (let (krunch-buf) |
| 3436 | (setq krunch-buf (generate-new-buffer "*gkrunch*")) | 3546 | (setq krunch-buf (generate-new-buffer "*gkrunch*")) |
| 3437 | (save-excursion | 3547 | (save-excursion |
| 3438 | (set-buffer krunch-buf) | 3548 | (set-buffer krunch-buf) |
| 3439 | ; (insert (downcase adaname)) | 3549 | ;; send adaname to external process `gnatkr'. |
| 3440 | ; (goto-char (point-min)) | 3550 | (call-process "gnatkr" nil krunch-buf nil |
| 3441 | ; (while (search-forward "." nil t) | ||
| 3442 | ; (replace-match "-" nil t)) | ||
| 3443 | ; (setq adaname (buffer-substring (point-min) | ||
| 3444 | ; (progn | ||
| 3445 | ; (goto-char (point-min)) | ||
| 3446 | ; (end-of-line) | ||
| 3447 | ; (point)))) | ||
| 3448 | ; ;; clean the buffer | ||
| 3449 | ; (delete-region (point-min) (point-max)) | ||
| 3450 | ;; send adaname to external process "gnatk8" | ||
| 3451 | (call-process "gnatk8" nil krunch-buf nil | ||
| 3452 | adaname ada-krunch-args) | 3551 | adaname ada-krunch-args) |
| 3453 | ;; fetch output of that process | 3552 | ;; fetch output of that process |
| 3454 | (setq adaname (buffer-substring | 3553 | (setq adaname (buffer-substring |
| @@ -3481,55 +3580,26 @@ If that is the case remember the name of that function." | |||
| 3481 | 3580 | ||
| 3482 | 3581 | ||
| 3483 | ;;;--------------------------------------------------- | 3582 | ;;;--------------------------------------------------- |
| 3484 | ;;; support for imenu | ||
| 3485 | ;;;--------------------------------------------------- | ||
| 3486 | |||
| 3487 | (defun imenu-create-ada-index (&optional regexp) | ||
| 3488 | "Create index alist for Ada files." | ||
| 3489 | (let ((index-alist '()) | ||
| 3490 | prev-pos char) | ||
| 3491 | (goto-char (point-min)) | ||
| 3492 | ;(imenu-progress-message prev-pos 0) | ||
| 3493 | ;; Search for functions/procedures | ||
| 3494 | (save-match-data | ||
| 3495 | (while (re-search-forward | ||
| 3496 | (or regexp ada-procedure-start-regexp) | ||
| 3497 | nil t) | ||
| 3498 | ;(imenu-progress-message prev-pos) | ||
| 3499 | ;; do not store forward definitions | ||
| 3500 | ;; right now we store them. We want to avoid them only in | ||
| 3501 | ;; package bodies, not in the specs!! ???RE??? | ||
| 3502 | (save-match-data | ||
| 3503 | ; (if (not (looking-at (concat | ||
| 3504 | ; "[ \t\n]*" ; WS | ||
| 3505 | ; "\([^)]+\)" ; parameterlist | ||
| 3506 | ; "\\([ \n\t]+return[ \n\t]+"; potential return | ||
| 3507 | ; "[a-zA-Z0-9_\\.]+\\)?" | ||
| 3508 | ; "[ \t]*" ; WS | ||
| 3509 | ; ";" ;; THIS is what we really look for | ||
| 3510 | ; ))) | ||
| 3511 | ; ; (push (imenu-example--name-and-position) index-alist) | ||
| 3512 | (setq index-alist (cons (imenu-example--name-and-position) | ||
| 3513 | index-alist)) | ||
| 3514 | ; ) | ||
| 3515 | ) | ||
| 3516 | ;(imenu-progress-message 100) | ||
| 3517 | )) | ||
| 3518 | (nreverse index-alist))) | ||
| 3519 | |||
| 3520 | ;;;--------------------------------------------------- | ||
| 3521 | ;;; support for font-lock | 3583 | ;;; support for font-lock |
| 3522 | ;;;--------------------------------------------------- | 3584 | ;;;--------------------------------------------------- |
| 3523 | 3585 | ||
| 3524 | ;; Strings are a real pain in Ada because both ' and " can appear in a | 3586 | ;; Strings are a real pain in Ada because a single quote character is |
| 3525 | ;; non-string quote context (the former as an operator, the latter as | 3587 | ;; overloaded as a string quote and type/instance delimiter. By default, a |
| 3526 | ;; a character string). We follow the least losing solution, in which | 3588 | ;; single quote is given punctuation syntax in `ada-mode-syntax-table'. |
| 3527 | ;; only " is a string quote. Therefore a character string of the form | 3589 | ;; So, for Font Lock mode purposes, we mark single quotes as having string |
| 3528 | ;; '"' will throw fontification off on the wrong track. | 3590 | ;; syntax when the gods that created Ada determine them to be. sm. |
| 3591 | |||
| 3592 | (defconst ada-font-lock-syntactic-keywords | ||
| 3593 | ;; Mark single quotes as having string quote syntax in 'c' instances. | ||
| 3594 | '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))) | ||
| 3529 | 3595 | ||
| 3530 | (defconst ada-font-lock-keywords-1 | 3596 | (defconst ada-font-lock-keywords-1 |
| 3531 | (list | 3597 | (list |
| 3532 | ;; | 3598 | ;; |
| 3599 | ;; handle "type T is access function return S;" | ||
| 3600 | ;; | ||
| 3601 | (list "\\<\\(function[ \t]+return\\)\\>" '(1 font-lock-keyword-face) ) | ||
| 3602 | ;; | ||
| 3533 | ;; accept, entry, function, package (body), protected (body|type), | 3603 | ;; accept, entry, function, package (body), protected (body|type), |
| 3534 | ;; pragma, procedure, task (body) plus name. | 3604 | ;; pragma, procedure, task (body) plus name. |
| 3535 | (list (concat | 3605 | (list (concat |
| @@ -3546,9 +3616,9 @@ If that is the case remember the name of that function." | |||
| 3546 | "protected\\|" | 3616 | "protected\\|" |
| 3547 | ;; "p\\(\\(ackage\\|rotected\\)\\(\\|[ \t]+\\(body\\|type\\)\\)\ | 3617 | ;; "p\\(\\(ackage\\|rotected\\)\\(\\|[ \t]+\\(body\\|type\\)\\)\ |
| 3548 | ;;\\|r\\(agma\\|ocedure\\)\\)\\|" | 3618 | ;;\\|r\\(agma\\|ocedure\\)\\)\\|" |
| 3549 | "task\\|" | ||
| 3550 | "task[ \t]+body\\|" | 3619 | "task[ \t]+body\\|" |
| 3551 | "task[ \t]+type" | 3620 | "task[ \t]+type\\|" |
| 3621 | "task" | ||
| 3552 | ;; "task\\(\\|[ \t]+body\\)" | 3622 | ;; "task\\(\\|[ \t]+body\\)" |
| 3553 | "\\)\\>[ \t]*" | 3623 | "\\)\\>[ \t]*" |
| 3554 | "\\(\\sw+\\(\\.\\sw*\\)*\\)?") | 3624 | "\\(\\sw+\\(\\.\\sw*\\)*\\)?") |
| @@ -3575,15 +3645,15 @@ If that is the case remember the name of that function." | |||
| 3575 | "e\\(ls\\(e\\|if\\)\\|ntry\\|x\\(ception\\|it\\)\\)\\|for\\|" | 3645 | "e\\(ls\\(e\\|if\\)\\|ntry\\|x\\(ception\\|it\\)\\)\\|for\\|" |
| 3576 | "generic\\|i[fns]\\|l\\(imited\\|oop\\)\\|mod\\|n\\(ot\\|ull\\)\\|" | 3646 | "generic\\|i[fns]\\|l\\(imited\\|oop\\)\\|mod\\|n\\(ot\\|ull\\)\\|" |
| 3577 | "o\\(r\\|thers\\|ut\\)\\|pr\\(ivate\\|otected\\)\\|" | 3647 | "o\\(r\\|thers\\|ut\\)\\|pr\\(ivate\\|otected\\)\\|" |
| 3578 | "r\\(ange\\|e\\(cord\\|m\\|names\\|queue\\|turn\\|verse\\)\\)\\|" | 3648 | "r\\(a\\(ise\\|nge\\)\\|e\\(cord\\|m\\|names\\|queue\\|turn\\|verse\\)\\)\\|" |
| 3579 | "se\\(lect\\|parate\\)\\|" | 3649 | "se\\(lect\\|parate\\)\\|" |
| 3580 | "t\\(agged\\|erminate\\|hen\\)\\|until\\|" ; task removed | 3650 | "t\\(agged\\|erminate\\|hen\\)\\|until\\|" ; task removed |
| 3581 | "wh\\(ile\\|en\\)\\|xor" ; "when" added | 3651 | "wh\\(ile\\|en\\)\\|xor" ; "when" added |
| 3582 | "\\)\\>") | 3652 | "\\)\\>") |
| 3583 | ;; | 3653 | ;; |
| 3584 | ;; Anything following end and not already fontified is a body name. | 3654 | ;; Anything following end and not already fontified is a body name. |
| 3585 | '("\\<\\(end\\)\\>[ \t]+\\([a-zA-Z0-9_\\.]+\\)?" | 3655 | '("\\<\\(end\\)\\>\\([ \t]+\\)?\\([a-zA-Z0-9_\\.]+\\)?" |
| 3586 | (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)) | 3656 | (1 font-lock-keyword-face) (3 font-lock-function-name-face nil t)) |
| 3587 | ;; | 3657 | ;; |
| 3588 | ;; Variable name plus optional keywords followed by a type name. Slow. | 3658 | ;; Variable name plus optional keywords followed by a type name. Slow. |
| 3589 | ; (list (concat "\\<\\(\\sw+\\)\\>[ \t]*:?[ \t]*" | 3659 | ; (list (concat "\\<\\(\\sw+\\)\\>[ \t]*:?[ \t]*" |
| @@ -3594,7 +3664,7 @@ If that is the case remember the name of that function." | |||
| 3594 | ;; | 3664 | ;; |
| 3595 | ;; Optional keywords followed by a type name. | 3665 | ;; Optional keywords followed by a type name. |
| 3596 | (list (concat ; ":[ \t]*" | 3666 | (list (concat ; ":[ \t]*" |
| 3597 | "\\<\\(access\\|constant\\|in\\|in[ \t]+out\\|out\\)\\>" | 3667 | "\\<\\(access\\|constant\\|in[ \t]+out\\|in\\|out\\)\\>" |
| 3598 | "[ \t]*" | 3668 | "[ \t]*" |
| 3599 | "\\(\\sw+\\)?") | 3669 | "\\(\\sw+\\)?") |
| 3600 | '(1 font-lock-keyword-face nil t) '(2 font-lock-type-face nil t)) | 3670 | '(1 font-lock-keyword-face nil t) '(2 font-lock-type-face nil t)) |
| @@ -3619,12 +3689,28 @@ If that is the case remember the name of that function." | |||
| 3619 | )) | 3689 | )) |
| 3620 | "Gaudy level highlighting for Ada mode.") | 3690 | "Gaudy level highlighting for Ada mode.") |
| 3621 | 3691 | ||
| 3622 | (defvar ada-font-lock-keywords ada-font-lock-keywords-2 | 3692 | (defvar ada-font-lock-keywords ada-font-lock-keywords-1 |
| 3623 | "Default Expressions to highlight in Ada mode. | 3693 | "Default expressions to highlight in Ada mode.") |
| 3624 | See the doc to `font-lock-maximum-decoration' for user configuration.") | 3694 | |
| 3695 | |||
| 3696 | ;; set font-lock properties for XEmacs | ||
| 3697 | (if (ada-xemacs) | ||
| 3698 | (put 'ada-mode 'font-lock-defaults | ||
| 3699 | '(ada-font-lock-keywords | ||
| 3700 | nil t ((?\_ . "w")(?\. . "w")) beginning-of-line))) | ||
| 3701 | |||
| 3702 | ;;; | ||
| 3703 | ;;; support for outline | ||
| 3704 | ;;; | ||
| 3705 | |||
| 3706 | ;; used by outline-minor-mode | ||
| 3707 | (defun ada-outline-level () | ||
| 3708 | (save-excursion | ||
| 3709 | (skip-chars-forward "\t ") | ||
| 3710 | (current-column))) | ||
| 3625 | 3711 | ||
| 3626 | ;;; | 3712 | ;;; |
| 3627 | ;;; ???? | 3713 | ;;; generate body |
| 3628 | ;;; | 3714 | ;;; |
| 3629 | (defun ada-gen-comment-until-proc () | 3715 | (defun ada-gen-comment-until-proc () |
| 3630 | ;; comment until spec of a procedure or a function. | 3716 | ;; comment until spec of a procedure or a function. |