<?xml version="1.0"?>
<!DOCTYPE content [ <!ENTITY nbsp " "> ]>
<rdf:RDF xml:base="http://snarfed.org/rdf"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:dc="http://purl.org/dc/elements/1.1/">

<rdf:Description rdf:about="http://snarfed.org">
  <dc:title> snarfed.org  </dc:title>
  <dc:description> draw group stream of consciousness </dc:description>
  <dc:creator> Ryan Barrett &lt;snarfed at ryanb dot org&gt; </dc:creator>
  <dc:language> en </dc:language>
  <dc:format> text/html </dc:format>
  <dc:rights> Copyright 2002-2007 Ryan Barrett </dc:rights>
</rdf:Description>

<rdf:Description rdf:about="http://snarfed.org/space/fillcode">
  <dc:title> fillcode </dc:title>
  <dc:creator> Ryan Barrett &lt;snarfed at ryanb dot org&gt; </dc:creator>
  <dc:date> 2003-01-01T05:00:00Z </dc:date>
  <dc:language> en </dc:language>
  <dc:format> text/html </dc:format>
  <dc:rights> Copyright 2002-2007 Ryan Barrett </dc:rights>

  <content>
    <p><a href="/space/fillcode"><img src="/space/gnu.jpg" alt="gnu.jpg" title="" /></a></p>

<p>For the impatient: <br />
&nbsp; <a href="/space/fillcode.el">Download fillcode.el 0.7.1</a> <br />
&nbsp; <a href="/space/fillcode.tar.gz">Download fillcode.tar.gz</a> (includes
<a href="http://www.lostway.org/~tko/elisp/elunit/">elunit</a> unit tests)</p>

<p><em>Updated 2007/08/24.</em></p>

<p>Fillcode is an <a href="http://gnu.org/software/emacs/">Emacs</a> minor mode that fills, or
wraps, some parts of source code. It's best described by example. Fillcode fills
this:</p>

<div class='p-shadow'><pre><code>public static void foo(int i, float f, String s) {
</code></pre></div>

<p><br class='clearing' />to this:</p>

<div class='p-shadow'><pre><code>public static void foo(int i, float f,
                       String s) {
</code></pre></div>

<p><br class='clearing' />The motivation is described in my original <a href="/space/filling code in emacs">call for filling
code</a>.</p>

<p>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.</p>

<p>Fillcode is supported in <a href="http://gnu.org/software/emacs/">Emacs</a> 21 and 22
and <a href="http://xemacs.org/">XEmacs</a>, and works with most programming language
major modes, including Java, C, C++, Objective C, Perl, Python, shell, and SQL
modes.</p>

<p>Fillcode fills when <code>fill-paragraph</code> (usually <code>M-q</code>) is called. If the major
mode itself attempts to fill - inside a comment, for example - fillcode
graciously steps back and does nothing.</p>

<p>If you provide a prefix argument, e.g. <code>C-u M-q</code>, 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 <code>fill-column</code>.</p>

<p>You can load fillcode automatically by copying
<a href="/space/fillcode.el">fillcode.el</a> into <code>/usr/share/emacs/site-lisp/</code>,
or any other directory in Emacs' <code>load-path</code>. Then, add this to your .emacs
file:</p>

<div class='p-shadow'><pre><code>(require 'fillcode)
</code></pre></div>

<p><br class='clearing' /><code>M-x fillcode-mode</code> 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.</p>

<div class='p-shadow'><pre><code>(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)
</code></pre></div>

<p><br class='clearing' />Fillcode is a work in progress. Here's a list of issues:</p>

<ul>
<li>It depends on the major mode's indentation and parsing engines. These are
less than perfect in some major modes.</li>
<li>It's not entirely compatible with
<a href="http://www.gnu.org/software/emacs/manual/emacs.html#Auto%20Fill">auto-fill-mode</a>
or <a href="http://www.wonderworks.com/#filladapt">filladapt-mode</a>...yet.</li>
<li>It doesn't break lines at <code>=</code>, the assignment operator.</li>
</ul>

<p>Fillcode is copyright 2005-2007 <a href="http://ryan.barrett.name/">Ryan Barrett</a>, and
is distributed under the <a href="http://www.gnu.org/licenses/gpl.html">GPL</a>.</p>

  </content>

  <rdf:Seq>

<rdf:li>
<rdf:Description rdf:about="#1133754245.0">
  <dc:source> http://snarfed.org/ </dc:source>
  <dc:title> fillcode-1 </dc:title>
  <dc:creator> hober </dc:creator>
  <dc:date> cmt_pubDate </dc:date>
  <dc:format> text/html </dc:format>

  <content>
    
FYI, fillcode.el doesn't work with the python.el in CVS Emacs.

  </content>
</rdf:Description>
</rdf:li>

<rdf:li>
<rdf:Description rdf:about="#1133765137.0">
  <dc:source> http://snarfed.org/ </dc:source>
  <dc:title> fillcode-2 </dc:title>
  <dc:creator> ryan </dc:creator>
  <dc:date> cmt_pubDate </dc:date>
  <dc:format> text/html </dc:format>

  <content>
    
thanks for the feedback! ay, really, it doesn't? i've been testing with python-mode 4.6.18.2, and it works ok.<p class="paragraph"/>would you mind describing in more detail what doesn't work with the python-mode in CVS?

  </content>
</rdf:Description>
</rdf:li>

<rdf:li>
<rdf:Description rdf:about="#1133937679.0">
  <dc:source> http://snarfed.org/ </dc:source>
  <dc:title> fillcode-3 </dc:title>
  <dc:creator> ryan </dc:creator>
  <dc:date> cmt_pubDate </dc:date>
  <dc:format> text/html </dc:format>

  <content>
    
in python-mode, one problem with the original fillcode i posted was that it often filled more than just the single statement under point. i've posted a new version that is much better (and thus more polite) about determining where the current statement ends.<p class="paragraph"/>thanks for the bug report!

  </content>
</rdf:Description>
</rdf:li>

<rdf:li>
<rdf:Description rdf:about="#1133982472.0">
  <dc:source> http://snarfed.org/ </dc:source>
  <dc:title> fillcode-4 </dc:title>
  <dc:creator> hober </dc:creator>
  <dc:date> cmt_pubDate </dc:date>
  <dc:format> text/html </dc:format>

  <content>
    
&#60;pre&#62;Debugger entered--Lisp error: (void-function py-in-literal)
  py-in-literal()
  funcall(py-in-literal)
  (or (funcall in-literal-fn) (eval (cons &#8230; ...)))
  (let ((in-literal-fn ...) (literal-start-tokens ...)) (or (funcall in-literal-fn) (eval ...)))
  fillcode-in-literal()
  (cond ((fillcode-in-literal) (forward-char)) ((eolp) (delete-indentation t)) ((looking-at ...) (delete-horizontal-space) (if &#8230; ...)) ((and &#8230; ...) (progn &#8230; ...)) ((and &#8230; ... ...) (progn &#8230; ...)) (t (forward-char)))
  fillcode-collapse-whitespace-forward()
  fillcode()
  call-interactively(fillcode)
  execute-extended-command(nil)
  call-interactively(execute-extended-command)&#60;/pre&#62;

  </content>
</rdf:Description>
</rdf:li>

<rdf:li>
<rdf:Description rdf:about="#1133982517.0">
  <dc:source> http://snarfed.org/ </dc:source>
  <dc:title> fillcode-5 </dc:title>
  <dc:creator> hober </dc:creator>
  <dc:date> cmt_pubDate </dc:date>
  <dc:format> text/html </dc:format>

  <content>
    
(python.el in CVS Emacs is completely different than python-mode.el from python.org.)

  </content>
</rdf:Description>
</rdf:li>

<rdf:li>
<rdf:Description rdf:about="#1133986437.0">
  <dc:source> http://snarfed.org/ </dc:source>
  <dc:title> fillcode-6 </dc:title>
  <dc:creator> ryan </dc:creator>
  <dc:date> cmt_pubDate </dc:date>
  <dc:format> text/html </dc:format>

  <content>
    
yeah, i do remember that. sigh. thanks for the info.<p class="paragraph"/>i just downloaded and built CVS emacs, and it breaks the fillcode unit tests spectacularly. that'll be a good place for me to start.

  </content>
</rdf:Description>
</rdf:li>

<rdf:li>
<rdf:Description rdf:about="#1133987879.0">
  <dc:source> http://snarfed.org/ </dc:source>
  <dc:title> fillcode-7 </dc:title>
  <dc:creator> ashawley </dc:creator>
  <dc:date> cmt_pubDate </dc:date>
  <dc:format> text/html </dc:format>

  <content>
    
Rather than defining a mode and using hooks you can just set `fill-paragraph-function' to the desired "fillcode" function.
See the command help on `fill-paragraph' at `C-h f fill-paragraph'.

  </content>
</rdf:Description>
</rdf:li>

<rdf:li>
<rdf:Description rdf:about="#1134036852.0">
  <dc:source> http://snarfed.org/ </dc:source>
  <dc:title> fillcode-8 </dc:title>
  <dc:creator> ryan </dc:creator>
  <dc:date> cmt_pubDate </dc:date>
  <dc:format> text/html </dc:format>

  <content>
    
good point. that's true for all major modes that respect `fill-paragraph-function'.<p class="paragraph"/>unfortunately, cc-mode doesn't. it replaces `fill-paragraph' with `c-fill-paragraph', which it binds M-q to. `c-fill-paragraph' ignores `fill-paragraph-function' entirely. :/<p class="paragraph"/>so, for fillcode to work in cc-mode major modes, it has to do something like advise `c-fill-paragraph'...which it does. still, you're probably right, it doesn't need a whole minor mode. i'll consider removing that in the future.

  </content>
</rdf:Description>
</rdf:li>

<rdf:li>
<rdf:Description rdf:about="#1156922647.86">
  <dc:source> http://snarfed.org/ </dc:source>
  <dc:title> fillcode </dc:title>
  <dc:creator> MartinG </dc:creator>
  <dc:date> cmt_pubDate </dc:date>
  <dc:format> text/html </dc:format>

  <content>
    Thanks for this very nice emacs mode!<br />
<br />
I think I found one bug though - when filling this string:<br />
&nbsp; &lt;code&gt;for (iy = 0; iy &lt; dLy; iy++)&lt;/code&gt;<br />
it becomes<br />
&nbsp; &lt;code&gt;for (iy = 0; iy &lt; dLy; iy+ +)&lt;/code&gt;<br />
i.e. it separates the "+" signs. This is in cc-mode.
  </content>
</rdf:Description>
</rdf:li>

<rdf:li>
<rdf:Description rdf:about="#1177293012.1">
  <dc:source> http://snarfed.org/ </dc:source>
  <dc:title> fillcode </dc:title>
  <dc:creator> Vomicae </dc:creator>
  <dc:date> cmt_pubDate </dc:date>
  <dc:format> text/html </dc:format>

  <content>
    Fillcode is Perl the best
  </content>
</rdf:Description>
</rdf:li>

<rdf:li>
<rdf:Description rdf:about="#1185484251.27">
  <dc:source> http://snarfed.org/ </dc:source>
  <dc:title> fillcode </dc:title>
  <dc:creator> ryan </dc:creator>
  <dc:date> cmt_pubDate </dc:date>
  <dc:format> text/html </dc:format>

  <content>
    thanks for the report, martin. a fix for that went in in 0.5 or 0.6. sorry for the delayed response!
  </content>
</rdf:Description>
</rdf:li>

  </rdf:Seq>
</rdf:Description>
</rdf:RDF>
