Piotr Trojanek <[email protected]> writes:
> Hi,
>
> I am using the latest ada-mode from monotone repo.
Good indication that it is time for anew release.
> The attached code
> demonstrates wrong indentation of "is" in expression function
> definition.
>
> I also attached a patch that works for me.
>
> -- Piotr
>
> #
> # old_revision [7f3ebb8b84d91f026f472a06a25ff6bcdff529d1]
> #
> # patch "ada-grammar.wy"
> # from [c58d885764d7918d16bf5992ec88d36055de39a7]
> # to [501092a84f08896304d21c2515bdd8c31d109c2b]
> #
> ============================================================
> --- ada-grammar.wy c58d885764d7918d16bf5992ec88d36055de39a7
> +++ ada-grammar.wy 501092a84f08896304d21c2515bdd8c31d109c2b
> @@ -960,7 +960,7 @@ expression_function_declaration
> : overriding_indicator_opt function_specification IS paren_expression
> aspect_specification_opt SEMICOLON
> ;; IS does not start a block, so it is not cached
> (progn
> - (wisi-statement-action [1 statement-start 2 statement-other 6
> statement-end])
> + (wisi-statement-action [1 statement-start 2 statement-other 3
> block-middle 6 statement-end])
> (wisi-containing-action 2 4)
> (wisi-containing-action 2 5))
> ;
This makes some sense, but it breaks some tests. You also did not fix
the comment explaining why IS is not cached (now it is).
> package body P1 is
>
> function Fun1 (Arg : Boolean)
> return Boolean
> is -- wrong indentiation of "is"
> (True);
There are similar tests in test/ada_mode-expression_functions.ads.
In this case, since "is" does not start a block, it is treated as
starting a continuation line, which is indented by ada-indent-broken
relative to the previous line
However, by that logic, the expression should be a continuation also,
and indented relative to "is". So that's a grammar bug; "is" should
contain "paren_expression". Fixing that uncovered an oddity in
wisi-statement-action behavior, so the final fix ends up indenting "is"
relative to "function":
function Fun3 (Arg : Boolean)
return Boolean
is
(True);
Which I guess you'll be happy with.
To make the best argument for your case, we assume the argument list,
return type, and expression are long, and require their own line. In
that case, I would argue the best layout is:
function Fun1
(Really_Really_Long_Argument_list : Boolean)
return Really_Really_Long_Return_Type
is (Really_Really_Long_expression);
The core problem in your example is that you put the argument list on
the same line as the function name; that causes silly indentation of the
next lines. Fixing that problem makes everything better.
Alternately, you can set ada-indent-return to 2 instead of 0:
function Fun3 (Arg : Boolean)
return Boolean
is
(True);
We should also look at aspects with this:
function Fun1 (Really_Really_Long_Argument_list : Boolean)
return Boolean -- a Really_Really_Long_Return_Type
is
(True) -- a Really_Really_Long_expression
with Convention => Ada;
Not bad.
> function Fun2 (Arg : Boolean)
> return Boolean
> is -- correct indentation of "is"
> begin
> return True;
> end Fun2;
>
> end;
Here "is" does start a block.
So here's the patch I'm applying:
--- ada-grammar.wy d798b9a3681dfe89f91b75f06aa95e680009c57d
+++ ada-grammar.wy b1d79528d3157b19f3d45e80b875d42b96d26ff9
@@ -958,10 +958,15 @@ expression_function_declaration
expression_function_declaration
: overriding_indicator_opt function_specification IS paren_expression
aspect_specification_opt SEMICOLON
- ;; IS does not start a block, so it is not cached
+ ;; IS does not start a block, so it is not "block-middle".
+ ;;
+ ;; We override the cache on "function_specification", so
+ ;; wisi-statement-action will handle an empty
+ ;; "overriding_indicator_opt" correctly. FIXME: should not have to do
+ ;; this, but it is also done in other grammar statements.
(progn
- (wisi-statement-action [1 statement-start 2 statement-other 6
statement-end])
- (wisi-containing-action 2 4)
+ (wisi-statement-action [1 statement-start 2 block-middle 3
statement-other 6 statement-end])
+ (wisi-containing-action 3 4)
(wisi-containing-action 2 5))
;
--
-- Stephe
_______________________________________________
Emacs-ada-mode mailing list
[email protected]
http://host114.hostmonster.com/mailman/listinfo/emacs-ada-mode_stephe-leake.org