- (if (not (looking-at "\\<\\(new\\|separate\\|begin\\)\\>"))
- (setq nest-count (1- nest-count)))))))
- ;; found task start => check if it has a body
- ((looking-at "task")
- (save-excursion
- (forward-word 1)
- (ada-goto-next-non-ws)
- (cond
- ((looking-at "\\<body\\>"))
- ((looking-at "\\<type\\>")
- ;; In that case, do nothing if there is a "is"
- (forward-word 2);; skip "type"
- (ada-goto-next-non-ws);; skip type name
-
- ;; Do nothing if we are simply looking at a simple
- ;; "task type name;" statement with no block
- (unless (looking-at ";")
- (progn
- ;; Skip the parameters
- (if (looking-at "(")
- (ada-search-ignore-string-comment ")" nil))
- (let ((tmp (ada-search-ignore-string-comment
- "\\<\\(is\\|;\\)\\>" nil)))
- (if tmp
- (progn
- (goto-char (car tmp))
- (if (looking-at "is")
- (setq nest-count (1- nest-count)))))))))
- (t
- ;; Check if that task declaration had a block attached to
- ;; it (i.e do nothing if we have just "task name;")
- (unless (progn (forward-word 1)
- (looking-at "[ \t]*;"))
- (setq nest-count (1- nest-count)))))))
- ;; all the other block starts
- (t
- (setq nest-count (1- nest-count)))) ; end of 'cond'
-
- ;; match is found, if nest-depth is zero
- ;;
- (setq found (zerop nest-count))))) ; end of loop
+ (if (and (not (looking-at "\\<\\(new\\|separate\\|begin\\)\\>"))
+ (not (car last-was-begin)))
+ (setq nest-count (1- nest-count))))))
+
+ (setq last-was-begin (cdr last-was-begin))
+ )
+ ;; found task start => check if it has a body
+ ((looking-at "task")
+ (save-excursion
+ (forward-word 1)
+ (ada-goto-next-non-ws)
+ (cond
+ ((looking-at "\\<body\\>"))
+ ((looking-at "\\<type\\>")
+ ;; In that case, do nothing if there is a "is"
+ (forward-word 2);; skip "type"
+ (ada-goto-next-non-ws);; skip type name
+
+ ;; Do nothing if we are simply looking at a simple
+ ;; "task type name;" statement with no block
+ (unless (looking-at ";")
+ (progn
+ ;; Skip the parameters
+ (if (looking-at "(")
+ (ada-search-ignore-string-comment ")" nil))
+ (let ((tmp (ada-search-ignore-string-comment
+ "\\<\\(is\\|;\\)\\>" nil)))
+ (if tmp
+ (progn
+ (goto-char (car tmp))
+ (if (looking-at "is")
+ (setq nest-count (1- nest-count)))))))))
+ (t
+ ;; Check if that task declaration had a block attached to
+ ;; it (i.e do nothing if we have just "task name;")
+ (unless (progn (forward-word 1)
+ (looking-at "[ \t]*;"))
+ (setq nest-count (1- nest-count))))))
+ (setq last-was-begin (cdr last-was-begin))
+ )
+
+ ((looking-at "declare")
+ ;; remove entry for begin and end (include nested begin..end
+ ;; groups)
+ (setq last-was-begin (cdr last-was-begin))
+ (let ((count 1))
+ (while (and (> count 0))
+ (if (equal (car last-was-begin) t)
+ (setq count (1+ count))
+ (setq count (1- count)))
+ (setq last-was-begin (cdr last-was-begin))
+ )))
+
+ ((looking-at "protected")
+ ;; Ignore if this is just a declaration
+ (save-excursion
+ (let ((pos (ada-search-ignore-string-comment
+ "\\(\\<is\\>\\|\\<renames\\>\\|;\\)" nil)))
+ (if pos
+ (goto-char (car pos)))
+ (if (looking-at "is")
+ ;; remove entry for end
+ (setq last-was-begin (cdr last-was-begin)))))
+ (setq nest-count (1- nest-count)))
+
+ ((or (looking-at "procedure")
+ (looking-at "function"))
+ ;; Ignore if this is just a declaration
+ (save-excursion
+ (let ((pos (ada-search-ignore-string-comment
+ "\\(\\<is\\>\\|\\<renames\\>\\|)[ \t]*;\\)" nil)))
+ (if pos
+ (goto-char (car pos)))
+ (if (looking-at "is")
+ ;; remove entry for begin and end
+ (setq last-was-begin (cdr (cdr last-was-begin))))))
+ )
+
+ ;; all the other block starts
+ (t
+ (push (looking-at "begin") last-was-begin)
+ (setq nest-count (1- nest-count)))
+
+ )
+
+ ;; match is found, if nest-depth is zero
+ (setq found (zerop nest-count))))) ; end of loop