Emacs
has a massive feature set, and there's also an endless supply of
elisp out
there. However, for a long time, there was one feature on my Emacs wish list
that I hadn't found yet.
Update: After lots of procrastination, I finally broke down and wrote fillcode. It tackles the problem described here.
I want Emacs to be able to correctly fill code, not just text. For example, when I press M-q in c-mode, I want Emacs to fill this:
public static void foo(int i, float f, String s) {
to this:
public static void foo(int i, float f,
String s) {
Filling is Emacs' term for word wrapping. M-q is bound to fill-paragraph, which
fills the current paragraph. However, Emacs only knows how to word wrap text. If
you're in any of the code modes, like c-mode, python-mode, and sgml-mode, Emacs
will only fill if it detects that you're in a comment. It's smart enough to know
its limits, but it would be even smarter if it didn't have those limits. Filling
code may not be as dirt-simple as filling text, but it's not hard.
As a start, I'd love the ability to fill function declarations and calls. The algorithm, starting from the beginning of the line, is:
Find an open parenthesis.
Find a comma.
If you hit another open parenthesis, push the stack and go to step 1.
If you hit a close parenthesis, pop the stack and return.
If the first non-whitespace character after the comma is beyond the fill column, insert a newline and indent to the column after the open parenthesis in step 1. (If this is beyond the fill column, you're hosed.)
Go to step 2.
Long string constants, arithmetic expressions, and Java throws clauses are similarly fillable. Elisp coders, here's your mission: make Emacs fill code!