changeset 106903:257da94c161b

* ada-mode.el: Really fix bug#5400 (comment in r99362 was erroneous). (ada-matching-decl-start-re): Move into ada-goto-decl-start. (ada-goto-decl-start): Rename from ada-goto-matching-decl-start; callers changed. Delete RECURSIVE parameter; never used. Improve doc string. Improve comments in "is" portion. Handle null procedure declaration. (ada-move-to-end): Improve doc string.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 19 Jan 2010 00:10:57 +0100
parents 1748839af981
children 51a1add37c3f 9d769a0fc9cd 7936b8a7e05d
files lisp/ChangeLog lisp/progmodes/ada-mode.el
diffstat 2 files changed, 70 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon Jan 18 21:24:43 2010 +0100
+++ b/lisp/ChangeLog	Tue Jan 19 00:10:57 2010 +0100
@@ -1,3 +1,12 @@
+2010-01-18  Stephen Leake  <stephen_leake@member.fsf.org>
+
+	* lisp/progmodes/ada-mode.el: Fix bug#5400.
+	(ada-matching-decl-start-re): Move into ada-goto-decl-start.
+	(ada-goto-decl-start): Rename from ada-goto-matching-decl-start; callers
+	changed.  Delete RECURSIVE parameter; never used.  Improve doc string.
+	Improve comments in "is" portion.  Handle null procedure declaration.
+	(ada-move-to-end): Improve doc string.
+
 2010-01-18  Óscar Fuentes  <ofv@wanadoo.es>
 
 	* ido.el (ido-cur-list): Initialize to nil.
@@ -108,7 +117,7 @@
 
 2010-01-17  Stephen Leake  <stephen_leake@member.fsf.org>
 
-	* progmodes/ada-mode.el: Fix bug#1920, bug#5400.
+	* progmodes/ada-mode.el: Fix bug#1920.
 	(ada-ident-re): Delete ., allow multibyte characters.
 	(ada-goto-label-re): New; matches goto labels.
 	(ada-block-label-re): New; matches block labels.
--- a/lisp/progmodes/ada-mode.el	Mon Jan 18 21:24:43 2010 +0100
+++ b/lisp/progmodes/ada-mode.el	Tue Jan 19 00:10:57 2010 +0100
@@ -677,14 +677,6 @@
 	    "\\>"))
   "Regexp used in `ada-goto-matching-start'.")
 
-(defvar ada-matching-decl-start-re
-  (eval-when-compile
-    (concat "\\<"
-	    (regexp-opt
-	     '("is" "separate" "end" "declare" "if" "new" "begin" "generic" "when") t)
-	    "\\>"))
-  "Regexp used in `ada-goto-matching-decl-start'.")
-
 (defvar ada-loop-start-re
   "\\<\\(for\\|while\\|loop\\)\\>"
   "Regexp for the start of a loop.")
@@ -2476,7 +2468,7 @@
      ((and (= (downcase (char-after)) ?b)
 	   (looking-at "begin\\>"))
       (save-excursion
-	(if (ada-goto-matching-decl-start t)
+	(if (ada-goto-decl-start t)
 	    (list (progn (back-to-indentation) (point)) 0)
 	  (ada-indent-on-previous-lines nil orgpoint orgpoint))))
 
@@ -2855,7 +2847,7 @@
 	      (if (looking-at "\\<begin\\>")
 		  (progn
 		    (setq indent (list (point) 0))
-		    (if (ada-goto-matching-decl-start t)
+		    (if (ada-goto-decl-start t)
 			(list (progn (back-to-indentation) (point)) 0)
 		      indent))
 		(list (progn (back-to-indentation) (point)) 0)
@@ -3421,7 +3413,6 @@
 	match-dat
       nil)))
 
-
 (defun ada-goto-next-non-ws (&optional limit skip-goto-label)
   "Skip to next non-whitespace character.
 Skips spaces, newlines and comments, and possibly goto labels.
@@ -3502,13 +3493,13 @@
   (if (save-excursion
 	(ada-goto-previous-word)
 	(looking-at (concat "\\<" defun-name "\\> *:")))
-      t                                 ; do nothing
+      t                                 ; name matches
     ;; else
     ;;
     ;; 'accept' or 'package' ?
     ;;
     (unless (looking-at ada-subprog-start-re)
-      (ada-goto-matching-decl-start))
+      (ada-goto-decl-start))
     ;;
     ;; 'begin' of 'procedure'/'function'/'task' or 'declare'
     ;;
@@ -3541,14 +3532,20 @@
 	       (buffer-substring (point)
 				 (progn (forward-sexp 1) (point))))))))
 
-(defun ada-goto-matching-decl-start (&optional noerror recursive)
-  "Move point to the matching declaration start of the current 'begin'.
-If NOERROR is non-nil, it only returns nil if no match was found."
+(defun ada-goto-decl-start (&optional noerror)
+  "Move point to the declaration start of the current construct.
+If NOERROR is non-nil, return nil if no match was found;
+otherwise throw error."
   (let ((nest-count 1)
+        (regexp (eval-when-compile
+                  (concat "\\<"
+                          (regexp-opt
+                           '("is" "separate" "end" "declare" "if" "new" "begin" "generic" "when") t)
+                          "\\>")))
 
 	;;  first should be set to t if we should stop at the first
 	;;  "begin" we encounter.
-	(first (not recursive))
+	(first t)
 	(count-generic nil)
 	(stop-at-when nil)
 	)
@@ -3572,7 +3569,7 @@
     ;; search backward for interesting keywords
     (while (and
 	    (not (zerop nest-count))
-	    (ada-search-ignore-string-comment ada-matching-decl-start-re t))
+	    (ada-search-ignore-string-comment regexp t))
       ;;
       ;; calculate nest-depth
       ;;
@@ -3605,7 +3602,6 @@
 
 		  (if (looking-at "end")
 		      (ada-goto-matching-start 1 noerror t)
-		    ;; (ada-goto-matching-decl-start noerror t)
 
 		    (setq loop-again nil)
 		    (unless (looking-at "begin")
@@ -3633,34 +3629,50 @@
 	(setq first t))
        ;;
        ((looking-at "is")
-	;; check if it is only a type definition, but not a protected
-	;; type definition, which should be handled like a procedure.
-	(if (or (looking-at "is[ \t]+<>")
-		(save-excursion
-		  (forward-comment -10000)
-		  (forward-char -1)
-
-		  ;; Detect if we have a closing parenthesis (Could be
-		  ;; either the end of subprogram parameters or (<>)
-		  ;; in a type definition
-		  (if (= (char-after) ?\))
-		      (progn
-			(forward-char 1)
-			(backward-sexp 1)
-			(forward-comment -10000)
-			))
-		  (skip-chars-backward "a-zA-Z0-9_.'")
-		  (ada-goto-previous-word)
-		  (and
-		   (looking-at "\\<\\(sub\\)?type\\|case\\>")
+        ;; look for things to ignore
+        (if
+            (or
+             ;; generic formal parameter
+             (looking-at "is[ t]+<>")
+
+             ;; A type definition, or a case statement.  Note that the
+             ;; goto-matching-start above on 'end record' leaves us at
+             ;; 'record', not at 'type'.
+             ;;
+             ;; We get to a case statement here by calling
+             ;; 'ada-move-to-end' from inside a case statement; then
+             ;; we are not ignoring 'when'.
+             (save-excursion
+               ;; Skip type discriminants or case argument function call param list
+               (forward-comment -10000)
+               (forward-char -1)
+               (if (= (char-after) ?\))
+                   (progn
+                     (forward-char 1)
+                     (backward-sexp 1)
+                     (forward-comment -10000)
+                     ))
+               ;; skip type or case argument name
+               (skip-chars-backward "a-zA-Z0-9_.'")
+               (ada-goto-previous-word)
+               (and
+                ;; if it's a protected type, it's the decl start we
+                ;; are looking for; since we didn't see the 'end'
+                ;; above, we are inside it.
+                (looking-at "\\<\\(sub\\)?type\\|case\\>")
 		   (save-match-data
 		     (ada-goto-previous-word)
 		     (not (looking-at "\\<protected\\>"))))
-		  ))                    ; end of `or'
-	    (goto-char (match-beginning 0))
-	  (progn
-	    (setq nest-count (1- nest-count))
-	    (setq first nil))))
+               )                    ; end of type definition p
+
+             ;; null procedure declaration
+             (save-excursion (ada-goto-next-word) (looking-at "\\<null\\>"))
+             );; end or
+            ;; skip this construct
+            nil
+          ;; this is the right "is"
+          (setq nest-count (1- nest-count))
+          (setq first nil)))
 
        ;;
        ((looking-at "new")
@@ -4115,7 +4127,7 @@
 Assumes point to be at the end of a statement."
   (or (ada-in-paramlist-p)
       (save-excursion
-	(ada-goto-matching-decl-start t))))
+	(ada-goto-decl-start t))))
 
 
 (defun ada-looking-at-semi-or ()
@@ -4409,7 +4421,7 @@
 		  ;;
 		  ada-move-to-declaration
 		  (looking-at "\\<begin\\>")
-		  (ada-goto-matching-decl-start)
+		  (ada-goto-decl-start)
 		  (setq pos (point))))
 
 	    )                           ; end of save-excursion
@@ -4421,7 +4433,7 @@
       (set-syntax-table previous-syntax-table))))
 
 (defun ada-move-to-end ()
-  "Move point to the matching end of the block around point.
+  "Move point to the end of the block around point.
 Moves to 'begin' if in a declarative part."
   (interactive)
   (let ((pos (point))
@@ -4471,7 +4483,7 @@
 	      (ada-goto-matching-end 0))
 	     ;; package start
 	     ((save-excursion
-		(setq decl-start (and (ada-goto-matching-decl-start t) (point)))
+		(setq decl-start (and (ada-goto-decl-start t) (point)))
 		(and decl-start (looking-at "\\<package\\>")))
 	      (ada-goto-matching-end 1))