- (point)))
-
- ;; Lines with only semicolons on them can be paragraph boundaries.
- (let ((paragraph-start (concat paragraph-start "\\|[ \t;]*$"))
- (paragraph-separate (concat paragraph-start "\\|[ \t;]*$"))
- (fill-prefix comment-fill-prefix))
- (fill-paragraph justify))))
+ ;; We may have gone too far. Go forward again.
+ (or (looking-at ".*;")
+ (forward-line 1))
+ (point))
+ ;; Find the beginning of the first line past the region to fill.
+ (save-excursion
+ (while (progn (forward-line 1)
+ (looking-at "^[ \t]*;")))
+ (point)))
+
+ ;; Lines with only semicolons on them can be paragraph boundaries.
+ (let* ((paragraph-start (concat paragraph-start "\\|[ \t;]*$"))
+ (paragraph-separate (concat paragraph-start "\\|[ \t;]*$"))
+ (paragraph-ignore-fill-prefix nil)
+ (fill-prefix comment-fill-prefix)
+ (after-line (if has-code-and-comment
+ (save-excursion
+ (forward-line 1) (point))))
+ (end (progn
+ (forward-paragraph)
+ (or (bolp) (newline 1))
+ (point)))
+ ;; If this comment starts on a line with code,
+ ;; include that like in the filling.
+ (beg (progn (backward-paragraph)
+ (if (eq (point) after-line)
+ (forward-line -1))
+ (point))))
+ (fill-region-as-paragraph beg end
+ justify nil
+ (save-excursion
+ (goto-char beg)
+ (if (looking-at fill-prefix)
+ nil
+ (re-search-forward comment-start-skip)
+ (point))))))))