changeset 4435:1e2fc51563a5

Fix auto-formatting of comments in auto-fill-mode This patch makes auto-fill-mode properly format comments (when lines are automatically broken). It looks strangely similar to that of: | 1999-06-24 Bob Weiner <weiner@beopen.com> | | * simple.el (indent-new-comment-line): Locally bound | `block-comment-start' to `comstart' or else when this is called | from do-auto-fill, e.g. in Lisp mode, it will insert any non-nil | `block-comment-start' value, ignoring any existing spacing after a | comment prefix in the previous line and producing ugly comments.
author Didier Verna <didier@xemacs.org>
date Wed, 05 Mar 2008 18:01:37 +0100
parents 7f3d065a56a1
children a72dc882abf1
files lisp/ChangeLog lisp/newcomment.el
diffstat 2 files changed, 33 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Wed Mar 05 10:41:54 2008 +0100
+++ b/lisp/ChangeLog	Wed Mar 05 18:01:37 2008 +0100
@@ -1,3 +1,12 @@
+2008-03-05  Didier Verna  <didier@xemacs.org>
+
+	Fix auto-formatting of comments in auto-fill-mode.
+
+	* newcomment.el (comment-indent): Don't insert a space at bol.
+	* newcomment.el (comment-indent-new-line): Bind
+	block-comment-start to comment-start in order to preserve the
+	formatting of previous comment lines.
+
 2008-03-05  Didier Verna  <didier@xemacs.org>
 
 	Ease customization of face(s) under point.
--- a/lisp/newcomment.el	Wed Mar 05 10:41:54 2008 +0100
+++ b/lisp/newcomment.el	Wed Mar 05 18:01:37 2008 +0100
@@ -240,7 +240,7 @@
 		   (substring comment-start 1)))
       ;; Hasn't been necessary yet.
       ;; (unless (string-match comment-start-skip comment-continue)
-      ;; 	(kill-local-variable 'comment-continue))
+      ;;	(kill-local-variable 'comment-continue))
       )
     ;; comment-skip regexps
     (unless (and comment-start-skip
@@ -443,12 +443,12 @@
 ;     (save-excursion
 ;       (beginning-of-line)
 ;       (let ((eol (save-excursion (end-of-line) (point))))
-; 	(and comment-start-skip
-; 	     (re-search-forward comment-start-skip eol t)
-; 	     (setq eol (match-beginning 0)))
-; 	(goto-char eol)
-; 	(skip-chars-backward " \t")
-; 	(max comment-column (1+ (current-column))))))
+;	(and comment-start-skip
+;	     (re-search-forward comment-start-skip eol t)
+;	     (setq eol (match-beginning 0)))
+;	(goto-char eol)
+;	(skip-chars-backward " \t")
+;	(max comment-column (1+ (current-column))))))
 ;   "Function to compute desired indentation for a comment.
 ; This function is called with no args with point at the beginning of
 ; the comment's starting delimiter.")
@@ -498,7 +498,8 @@
 	    (setq begpos (point))
 	    ;; Ensure there's a space before the comment for things
 	    ;; like sh where it matters (as well as being neater).
-	    (unless (eq ?\  (char-syntax (char-before)))
+	    ;; ... but unless we're at the beginning of a line -- dvl
+	    (unless (or (bolp) (eq ?\  (char-syntax (char-before))))
 	      (insert ?\ ))
 	    (insert starter)
 	    (setq cpos (point-marker))
@@ -516,8 +517,8 @@
 		     (+ (current-column)
 			(- (or comment-fill-column fill-column)
 			   (save-excursion (end-of-line) (current-column)))))))
-        ;; XEmacs change: Preserve indentation of comments starting in
-        ;; column 0, as documented.
+	;; XEmacs change: Preserve indentation of comments starting in
+	;; column 0, as documented.
 	(unless (or (= (current-column) 0) (= (current-column) indent))
 	  ;; If that's different from current, change it.
 	  (delete-region (point) (progn (skip-chars-backward " \t") (point)))
@@ -653,21 +654,21 @@
     (setq end (copy-marker end))
 
     (let* ((numarg (prefix-numeric-value arg))
-           (ccs comment-continue)
-           (srei (comment-padright ccs 're))
-           (sre (and srei (concat "^\\s-*?\\(" srei "\\)")))
-           spt)
+	   (ccs comment-continue)
+	   (srei (comment-padright ccs 're))
+	   (sre (and srei (concat "^\\s-*?\\(" srei "\\)")))
+	   spt)
       (while (and (< (point) end)
 		  (setq spt (comment-search-forward end t)))
 	(let ((ipt (point))
-              ;; Find the end of the comment.
-              (ept (progn
-                     (goto-char spt)
-                     (unless (comment-forward)
-                       (error "Can't find the comment end"))
-                     (point)))
-              (box nil)
-              (box-equal nil))     ;Whether we might be using `=' for boxes.
+	      ;; Find the end of the comment.
+	      (ept (progn
+		     (goto-char spt)
+		     (unless (comment-forward)
+		       (error "Can't find the comment end"))
+		     (point)))
+	      (box nil)
+	      (box-equal nil))     ;Whether we might be using `=' for boxes.
 	  (save-restriction
 	    (narrow-to-region spt ept)
 
@@ -1097,6 +1098,7 @@
 			  (point))
 			 nil t)))))
 		 (comment-start comstart)
+		 (block-comment-start comment-start)
 		 (continuep (or comment-multi-line
 				(cadr (assoc comment-style comment-styles))))
 		 ;; Force comment-continue to be recreated from comment-start.