views:

372

answers:

2

I'm using the actionscript-mode-connors.el for indenting Actionscript 3 code in emacs.

I have most things figured out, but one thing bothering me is when I use an inline closure as a function argument, the indentation of the interior of the function is screwed up.

For example:

var foo:int = some_function(
  bar,
  baz,
  function():void {
                              return qux();
                            },
  zap);

I want return qux() to be a single indent from the function declaration on the previous line, not a single indent from the open paren. The indentation of 'bar' used to be screwed up too but I fixed that with

(add-hook 'actionscript-mode-hook
      (lambda ()
        (c-set-offset 'arglist-intro '+)
        (c-set-offset 'arglist-close 0)))

Typically here I would use C-c C-s to figure out what syntactic symbols I need to change, but the problem on the 'return qux()' line is that the syntax context is

((arglist-cont-nonempty 731 758) (brace-list-intro 731))

where those numbers refer to the 'some_function' line. 'arglist-cont-nonempty' seems like a mistake, and it seems like it should be 'arglist-cont', since there's nothing after the open paren on that line. I can't change the indentation for 'arglist-cont-nonempty' since that would affect the case where the open paren does not end the 'some_function' line as well.

How can I fix this?

+1  A: 

How about an indirect answer? It seems as though you're relatively comfortable with the C indentation machine. You might want to use advice around 'c-guess-basic-syntax to recognize the particular configuration and modify it to be what you think would make the most sense for that situation.

If you take a look at this answer for an indentation customization for comments, I essentially did the same thing, only at the point of indentation.

Regarding your specifics, I cannot reproduce the same failure you have, my indentation for that chunk of code (in 'actionscript-mode with your two changes) looks like:

var foo:int = some_function(
  bar,
  baz,
  function():void {
    return qux();
  },
  zap);

Also, the syntax for the return qux(); line is: ((brace-list-intro 319)).

It seems that your hunch is correct (that the arglist-cont-nonempty list is the problem), and changing the output of 'c-guess-basic-syntax seems like it would be a viable solution.

Can I also point out the obvious test? Have you started without any customizations and loading just action-script? I did so with the latest action-script and Emacs 23.1 and got the results you see above. Tested with M-x c-version showing both 5.31.3 and 5.31.7 (the later is distributed with Emacs 32.1).

Trey Jackson
I have tried this without any customizations. But perhaps there is a better actionscript mode I should be using. Which actionscript-mode.el are you using? There seem to be a lot floating around, I have tried a couple so far but neither is great.
lacker
I used the one you provided in the question (I don't know actionscript-3 at all).
Trey Jackson
ActionScript == JavaScript
jrockway
Maybe it's a different c-mode.
lacker
@jrockway I don't know JavaScript either. :( Man I've got to spread my wings...
Trey Jackson
@lacker Good point.
Trey Jackson
actionscript != javascript, unfortunately. actionscript has actual classes, inheritance, static typing, various other things.
lacker
@jrockway I'm using cc-mode 5.31.5, what are you using?
lacker
Ok, I should have listened harder to you in the first place. I tried with a fresh .emacs and it's working but some other customizations are not. Thanks - this is my fault at some point. I'll binary search from here.
lacker
@lacker Yah, that's why I added that comment at the end. Most of the time when I think I've found a bug, I'm wrong...
Trey Jackson
Yep. I thought I had tried with no customizations, but I missed a different place where I had made another customization... :-/
lacker
+2  A: 

I would use espresso-mode for ActionScript. It indents your example correctly.

jrockway
espresso mode does indent that properly. it doesn't do as much syntax highlighting, though, e.g. member function declarations.
lacker