Say you write some code like this (using ruby-mode, but I’ve seen this happen in other modes too):
# This is a comment. def foo puts 'foo!' end
If you put the point on the first line and hit M-q, you get this:
# This is a comment. def foo puts 'foo!' end
How do I avoid that? I’m using version 21.3.
Clarification: This does not happen when I add a blank line between the comment and the code. As a work-around when I want to refill my comments, I go through an annoying three step process:
- I add a blank line before and after the comment paragraph
- M-q
- delete the blank lines
It’d be much nicer if M-q handled refilling comment paragraphs without having to add and delete blank lines. Emacs already know what text is comment text, so there must be a way to do this.
filladapt.el does the trick. That with the latest version of RubyMode.
Using those two packages solves the M-q problem you’re seeing. (Using GNU Emacs 22.1)
Looking at the code for ruby-mode, it looks like it has customized the variables to control paragraph filling like so:
Which can be added to a custom hook for your current ruby, or whatever major mode where you want fill behavior to act as you described – provided you use filladapt.el.