From xemacs-m  Fri Aug  1 19:31:23 1997
Received: from cnri.reston.va.us (ns.CNRI.Reston.VA.US [132.151.1.1])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id TAA07098
	for <xemacs-beta@xemacs.org>; Fri, 1 Aug 1997 19:31:22 -0500 (CDT)
Received: from newcnri.CNRI.Reston.Va.US (newcnri [132.151.1.84]) by cnri.reston.va.us (8.8.5/8.7.3) with SMTPid UAA05248; Fri, 1 Aug 1997 20:34:34 -0400 (EDT)
Received: from anthem.CNRI.Reston.Va.US by newcnri.CNRI.Reston.Va.US (SMI-8.6/SMI-SVR4)
	id UAA12580; Fri, 1 Aug 1997 20:36:04 -0400
Received: by anthem.CNRI.Reston.Va.US (SMI-8.6/SMI-SVR4)
	id UAA02396; Fri, 1 Aug 1997 20:34:38 -0400
Date: Fri, 1 Aug 1997 20:34:38 -0400
Message-Id: <199708020034.UAA02396@anthem.CNRI.Reston.Va.US>
From: "Barry A. Warsaw" <bwarsaw@CNRI.Reston.Va.US>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="ACiY0oiyvl"
Content-Transfer-Encoding: 7bit
To: xemacs-beta@xemacs.org
Cc: rms@prep.ai.mit.edu
Subject: Support for better auto filling in CC Mode
X-Mailer: VM 6.33 under 20.3 "Brussels" XEmacs  Lucid (beta13)
Reply-To: cc-mode-help@python.org (CCMODE Maintainer)
X-Attribution: BAW
X-Oblique-Strategy: Remove half of everything
X-Url: http://www.python.org/~bwarsaw


--ACiY0oiyvl
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


Auto filling doesn't work very well in CC Mode, mostly because of the
variety of possible commenting styles, e.g.: line oriented (C++) and
block oriented with zero, one, or two leading stars on continuation
lines.  It's always bugged me that users cannot choose what block
oriented style they want, and that Emacs could not properly handle C
languages where there might be a mix of line and block oriented
languages.

The problem is basically that the generalized routines in simple.el
don't know anything about C's commenting styles.  But I can add some
relatively simple code to CC Mode to handle this, if I had the right
interface in do-auto-file to call my function.

The following patch adds this simple interface to do-auto-fill.
Basically it changes the hard-coded calls to indent-new-comment-line
with a funcall to a buffer local variable called
comment-line-break-function.  In the next version of CC Mode then, I
set comment-line-break-function to a function that knows how to do the
right thing in C languages.  The default value of
comment-line-break-function is, of course, indent-new-comment-line.

I include first the patch to Emacs 20.0.9, then the patch to XEmacs
20.3beta13 (Steve, I did not patch the FSF compatibility do-auto-fill
in simple.el).  Please let me know if you plan to apply this patch for 
the next release.

-Barry


--ACiY0oiyvl
Content-Type: text/plain
Content-Description: Emacs 20.0.9 patch to simple.el
Content-Disposition: inline;
	filename="p1"
Content-Transfer-Encoding: 7bit

*** simple.el	1997/07/31 16:27:01	1.1
--- simple.el	1997/08/01 22:46:05
***************
*** 2070,2074 ****
  
  (defun indent-for-comment ()
!   "Indent this line's comment to comment column, or insert an empty comment."
    (interactive "*")
    (let* ((empty (save-excursion (beginning-of-line)
--- 2070,2076 ----
  
  (defun indent-for-comment ()
!   "Indent this line's comment to comment column, or insert an empty comment.
! Calls the function in `comment-indent-function' to compute the desired
! indentation."
    (interactive "*")
    (let* ((empty (save-excursion (beginning-of-line)
***************
*** 2335,2338 ****
--- 2337,2351 ----
    :group 'fill)
  
+ (defvar comment-line-break-function 'indent-new-comment-line
+   "*Mode-specific function which line breaks and continues a comment.
+ 
+ This function is only called during auto-filling of a comment section.
+ The function should take a single optional argument which is a flag
+ indicating whether soft newlines should be inserted.
+ 
+ Setting this variable automatically makes it local to the current
+ buffer.")
+ (make-variable-buffer-local 'comment-line-break-function)
+ 
  ;; This function is the auto-fill-function of a buffer
  ;; when Auto-Fill mode is enabled.
***************
*** 2416,2422 ****
  			(= (point) fill-point))
  		      ;; 97/3/14 jhod: Kinsoku processing
! 		      ;(indent-new-comment-line)
  		      (let ((spacep (memq (char-before (point)) '(?\  ?\t))))
! 			(indent-new-comment-line)
  			;; if user type space explicitly, leave SPC
  			;; even if there is no WAN.
--- 2429,2435 ----
  			(= (point) fill-point))
  		      ;; 97/3/14 jhod: Kinsoku processing
! 		      ;(funcall comment-line-break-function)
  		      (let ((spacep (memq (char-before (point)) '(?\  ?\t))))
! 			(funcall comment-line-break-function)
  			;; if user type space explicitly, leave SPC
  			;; even if there is no WAN.
***************
*** 2431,2435 ****
  		    (save-excursion
  		      (goto-char fill-point)
! 		      (indent-new-comment-line)))
  		  ;; If making the new line didn't reduce the hpos of
  		  ;; the end of the line, then give up now;
--- 2444,2448 ----
  		    (save-excursion
  		      (goto-char fill-point)
! 		      (funcall comment-line-break-function)))
  		  ;; If making the new line didn't reduce the hpos of
  		  ;; the end of the line, then give up now;

--ACiY0oiyvl
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit




--ACiY0oiyvl
Content-Type: text/plain
Content-Description: XEmacs 20.3beta13 patch to simple.el
Content-Disposition: inline;
	filename="p2"
Content-Transfer-Encoding: 7bit

*** simple.el	1997/08/01 22:47:14	1.1
--- simple.el	1997/08/01 22:48:04
***************
*** 2546,2549 ****
--- 2546,2560 ----
    :group 'fill)
  
+ (defvar comment-line-break-function 'indent-new-comment-line
+   "*Mode-specific function which line breaks and continues a comment.
+ 
+ This function is only called during auto-filling of a comment section.
+ The function should take a single optional argument which is a flag
+ indicating whether soft newlines should be inserted.
+ 
+ Setting this variable automatically makes it local to the current
+ buffer.")
+ (make-variable-buffer-local 'comment-line-break-function)
+ 
  ;; This function is the auto-fill-function of a buffer
  ;; when Auto-Fill mode is enabled.
***************
*** 2636,2643 ****
  		      (skip-chars-backward " \t")
  		      (= (point) fill-point))
! 		    (indent-new-comment-line t)
  		  (save-excursion
  		    (goto-char fill-point)
! 		    (indent-new-comment-line t)))
  		;; Now do justification, if required
  		(if (not (eq justify 'left))
--- 2647,2654 ----
  		      (skip-chars-backward " \t")
  		      (= (point) fill-point))
! 		    (funcall comment-line-break-function t)
  		  (save-excursion
  		    (goto-char fill-point)
! 		    (funcall comment-line-break-function t)))
  		;; Now do justification, if required
  		(if (not (eq justify 'left))

--ACiY0oiyvl--

