CC Mode Using Filladapt in CC Mode

Manual (html)
Manual (info/PS/DVI)
Recent changes
Mailing lists
Mercurial Repository
Browse hg Repository
Contributions and links
SourceForge project page

As of version 5.26, CC Mode uses adaptive filling for text in comments and string literals. Thus it's now possible to use Kyle E. Jones' Filladapt package ( inside CC Mode to get better handling of e.g. bulleted lists in comments.

To set up Filladapt for use with CC Mode:

  1. Make sure you have Filladapt installed. It's available from the canonical web site. You can also download version 2.12 from the CC Mode site.

    You might instead want to download a patched version of Filladapt that corrects a small problem (see below). The suggested patch is also available in context diff form if you prefer to patch it yourself.

  2. Configure the Filladapt variables for use in CC Mode. The easiest way to do this is to add something like this your .emacs:
    (defun my-c-mode-common-hook ()
      (filladapt-mode 1))
    (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

    This uses the c-setup-filladapt convenience function that comes with CC Mode to modify the Filladapt variables according to the comment syntax and c-comment-prefix-regexp.

Filladapt problems

There is a minor problem, or rather lack of a feature, in the current version of Filladapt (2.12 when this is written) that makes it do a poor job when the regexp on c-comment-prefix-regexp matches the empty string. The effect is that Filladapt fills only parts of a paragraph, or nothing at all. You can fix this problem in three ways:

  • Make sure c-comment-prefix-regexp can't match the empty string (by default it does). This is probably not a good idea since many block comment styles use nothing but whitespace before the text.

  • Set up the Filladapt variables yourself instead of using c-setup-filladapt. You'll have to make sure those variables agrees with c-block-comment-prefix and c-comment-prefix-regexp, or else you'll get very awkward behavior when editing comments.

  • Download this patch and apply it to the original 2.12 version. There's also an already patched version available.

    The patch adds a feature to Filladapt which makes it ignore tokens that matches the empty string when it analyzes the fill prefix. A variable filladapt-token-match-empty controls which tokens are allowed to match the empty string (normally only beginning-of-line and end-of-line are meaningful).

    To the best of my knowledge, this patch doesn't cause any adverse side effects in other modes. On the contrary, it's quite possible that it fixes similar problems elsewhere too. The patch has been submitted to Kyle E. Jones, and hopefully it will be included in a future version of Filladapt.