If you try the code that I posted here (it's not in CVS yet I think) you'll find that it doesn't depend solely on the
value of (current-indentation) . If emacs thinks the line with matching close-brace is correctly indented (as it would
in your example) then no close brace is inserted.


Emacs does a pretty good of figuring out what the correct indentation should be based on the line preceeding point,
but you are right, if you had a funky coding style which say required an extra space before the close brace then you
would either have to teach emacs about it or turn this feature off.



Bryan Shell wrote:


I have issues with the use of `current-indentation'.

This value will always return false if you have a rather long line and
break it or like myself and put the `throws' clause on a separate line.

public doSomeThingThat()
  throws somePoo { <-- 4
....
} <-- 2

This is even more trouble if you have to maintain a code base that was
initially written by a different user that used a funky indention scheme
that moved closing braces in a space or two.

Another interesting unexpected behavior; the close brace is not inserted
if there is any amount of whitespace between point and the open brace.


I'll change the matching regexp to include any whitespace before the end of line.

Here is a better (at least the way I think about) way of doing almost
the same thing.  Without worrying about indention levels, coding styles,
or the myriad other pitfalls the previous way has.



The drawback with your code is that one doesn't always want a close brace on a new line from the old one,
think array definitions or empty methods or one liner methods for inner classes. Another way to do this
would be to insert "{}" for the open brace and have the return character insert two newlines if point
had a open and close brace before and after it. But this might be too surprising for people not expecting it.
Also if I just typed an open brace followed by a close brace to create a empty method I would end up
with two close brace chars. Balanced.el (http://www.cs.indiana.edu/chezscheme/emacs/balanced.el)
gets around this by binding close parenthesis type keys to just move over the matching close parenthesis.
I find it very useful, especially for lisp code but it is definitely an acquired taste.


Suraj






Reply via email to