GNU bug report logs - #193
Fill for // (C++) style comments in C (C99)

Previous Next

Packages: emacs, cc-mode;

Reported by: Richard Hansen <rhansen <at> bbn.com>

Date: Tue, 6 May 2008 23:30:03 UTC

Severity: normal

Fixed in version 24.1

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Alan Mackenzie <acm <at> muc.de>
To: Christoph <cschol2112 <at> googlemail.com>
Cc: bug-gnu-emacs <at> gnu.org
Subject: bug#193: Fix for bug#193.
Date: Sun, 11 Jul 2010 18:55:59 +0000
Hi, Christoph,

On Fri, Jul 09, 2010 at 07:41:12PM -0600, Christoph wrote:
> Hi Alan,

> On 7/9/2010 12:51 PM, Alan Mackenzie wrote:
> >Hi, Deniz,

> >On Sun, Jun 27, 2010 at 02:47:52PM +0200, Deniz Dogan wrote:
> >>Did anyone ever agree on what needs to be done to fix the problem?

> >Would you try this patch, please, and then tell me whether or not it
> >works fully.  Thanks!

> M-q works fine for me with C as well as C++ style comments, both ways, 
> i.e. shorting long comments and extending short comments to fill the line.

> The only "quirk" I found:

> Using C-style comments, if the original comment looks like this:

> /* This is a short comment
>    which is extended                      */

> the resulting comment is:

> /* This is a short comment which is extended  */

> Notice the two spaces after the last word 'extended', before the close 
> comment marker.

The reason being that the filling function assumed that a comment ends
with a sentence, and should therefore leave two spaces after it.
However, if there's no full stop (etc.), the two spaces is silly.

> This might be nitpicking but I thought I bring it up.

We need nitpickers.  ;-)  Thanks for drawing it to my attention.  Would
you please try this amended patch: It should leave just one space after
"is extended", but two spaces after "is extended.".


*** orig/cc-cmds.el	2010-07-05 20:17:46.000000000 +0000
--- cc-cmds.el	2010-07-11 18:46:13.066679040 +0000
***************
*** 3975,3980 ****
--- 3975,3988 ----
  				       (goto-char ender-start)
  				       (current-column)))
  		       (point-rel (- ender-start here))
+ 		       (sentence-ends-comment
+ 			(save-excursion
+ 			  (goto-char ender-start)
+ 			  (and (search-backward-regexp
+ 				(c-sentence-end) (c-point 'bol) t)
+ 			       (goto-char (match-end 0))
+ 			  (looking-at "[ \t]*")
+ 			  (= (match-end 0) ender-start))))
  		       spaces)
  
  		  (save-excursion
***************
*** 4017,4023 ****
  			      (setq spaces
  				    (max
  				     (min spaces
! 					  (if sentence-end-double-space 2 1))
  				     1)))
  			  ;; Insert the filler first to keep marks right.
  			  (insert-char ?x spaces t)
--- 4025,4033 ----
  			      (setq spaces
  				    (max
  				     (min spaces
! 					  (if (and sentence-ends-comment
! 						   sentence-end-double-space)
! 					      2 1))
  				     1)))
  			  ;; Insert the filler first to keep marks right.
  			  (insert-char ?x spaces t)
***************
*** 4229,4236 ****
    (let ((fill-paragraph-function
  	 ;; Avoid infinite recursion.
  	 (if (not (eq fill-paragraph-function 'c-fill-paragraph))
! 	     fill-paragraph-function)))
!     (c-mask-paragraph t nil 'fill-paragraph arg))
    ;; Always return t.  This has the effect that if filling isn't done
    ;; above, it isn't done at all, and it's therefore effectively
    ;; disabled in normal code.
--- 4239,4249 ----
    (let ((fill-paragraph-function
  	 ;; Avoid infinite recursion.
  	 (if (not (eq fill-paragraph-function 'c-fill-paragraph))
! 	     fill-paragraph-function))
! 	(start-point (point-marker)))
!     (c-mask-paragraph
!      t nil (lambda () (fill-region-as-paragraph (point-min) (point-max) arg)))
!     (goto-char start-point))
    ;; Always return t.  This has the effect that if filling isn't done
    ;; above, it isn't done at all, and it's therefore effectively
    ;; disabled in normal code.



> Christoph

Looking forward to hearing back from you,

-- 
Alan Mackenzie (Nuremberg, Germany).




This bug report was last modified 14 years and 82 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.