CC Mode Using Filladapt in CC Mode

Index
Download
Manual (html)
Manual (info/PS/DVI)
Recent changes
Installation
Compatibility
Mailing lists
Mercurial Repository
Browse hg Repository
Savannah 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 (http://wonderworks.com/) 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 two small problems (see below). The suggested patch is also available in universal 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 ()
      (c-setup-filladapt)
      (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

The original filladapt.el makes one use of the old-style backquote construct (` (defvar (, var) (, value) (, doc))). This no longer compiles in recent versions of Emacs. This piece of code can be fixed by replacing it with the modern formulation `(defvar ,var ,value ,doc), and this has been done in the patched version and the patch referred to below.

There is another 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.


bug-cc-mode@gnu.org