For the impatient:
Download fillcode.el 0.7.1
Download fillcode.tar.gz (includes
elunit unit tests)
Updated 2007/08/24.
Fillcode is an Emacs minor mode that fills, or wraps, some parts of source code. It's best described by example. Fillcode fills this:
public static void foo(int i, float f, String s) {
to this:
public static void foo(int i, float f,
String s) {
The motivation is described in my original call for filling
code.
Fillcode can fill any parenthesized expression, including function prototypes, function calls, and conditional expressions. It only breaks lines at commas and binary operators, and correctly preserves embedded comments and string literals. It also normalizes existing whitespace and line breaks.
Fillcode is supported in Emacs 21 and 22 and XEmacs, and works with most programming language major modes, including Java, C, C++, Objective C, Perl, Python, shell, and SQL modes.
Fillcode fills when fill-paragraph (usually M-q) is called. If the major
mode itself attempts to fill - inside a comment, for example - fillcode
graciously steps back and does nothing.
If you provide a prefix argument, e.g. C-u M-q, fillcode will automatically
insert a line break at the first open parenthesis or other appropriate point.
This can be useful when the first open parenthesis is near fill-column.
You can load fillcode automatically by copying
fillcode.el into /usr/share/emacs/site-lisp/,
or any other directory in Emacs' load-path. Then, add this to your .emacs
file:
(require 'fillcode)
M-x fillcode-mode toggles fillcode on and off in the current buffer. To turn
it on automatically whenever you open source code, add these lines to your
.emacs file.
(add-hook 'c-mode-common-hook 'fillcode-mode)
(add-hook 'perl-mode-hook 'fillcode-mode)
(add-hook 'python-mode-hook 'fillcode-mode)
(add-hook 'shell-script-mode-hook 'fillcode-mode)
(add-hook 'sql-mode-hook 'fillcode-mode)
Fillcode is a work in progress. Here's a list of issues:
- It depends on the major mode's indentation and parsing engines. These are less than perfect in some major modes.
- It's not entirely compatible with auto-fill-mode or filladapt-mode...yet.
- It doesn't break lines at
=, the assignment operator.
Fillcode is copyright 2005-2007 Ryan Barrett, and is distributed under the GPL.
