Reply-To: mule-jp@etl.go.jp
Sender: owner-mule-jp@etl.go.jp
X-Seqno: 1770
Date: Wed, 17 Feb 93 15:26:19 JST
From: wkenji@center.flab.fujitsu.co.jp (Kenji WAKAMIYA)
Return-Path: <wkenji@center.flab.fujitsu.co.jp>
To: mule-jp@etl.go.jp
Subject: A patch for AUC-TeX 6.1d

$B<c5\!wIY;NDL8&$G$9!%(B

FAQ.Mule.jp $B$K$O(B AUC-TeX 6.1d $B$O(B Mule $B>e$GL5JQ99$GF0:n$9$k$H=q$+$l$F$$(B
$B$k$N$G$9$,!$(BLaTeX-fill-region-as-paragraph $B$,1Q8l$K$7$+BP1~$7$F$$$J$$(B
$B$?$a!$(BLaTeX-format-paragraph $B%3%^%s%I$,@5>o$K;H$($F$$$^$;$s$G$7$?!%(B

fj.editor.emacs $B$G$b<ALd$7$F$_$^$7$?$,!$F|K\8lBP1~$5$l$F$kJ}$,$$$J$$$_(B
$B$?$$$G$7$?$N$G!$(BLaTeX-fill-region-as-paragraph $B$K(B Mule $B$N(B 
fill-region-as-paragraph $B$NFbMF$r$4$C$=$j?"$(IU$1$F=$@5$7$F$_$^$7$?!%(B 
LaTeX-format-buffer $B$H$+$O!$$b$H$b$H1QJ8$K4X$7$F$b$*$+$7$JF0$-$r$7$^$9(B
$B$,!$$3$l$i$K$D$$$F$OFC$K<j$r2C$($F$$$^$;$s!%(B

auc-tex.el $B$X$N%Q%C%A$G$9!%$I$J$?$+;n$7$F$_$FD:$1$k$H4r$7$$$G$9!%$^$?!$(B 
Nemacs $B$K$OBP1~$7$F$$$^$;$s$N$G!$$3$l$b$d$C$F$/$l$k?M$,$$$k$H$$$$$s$@(B
$B$1$I!%!%!%(B Mule $B$X$N0\9T$N$?$a$K$O:9JL2=$r?^$C$?J}$,$$$$$+$J(B :-)$B!%(B
--
$B#W%1%s%B!wIY;NDL8&(B
wkenji@flab.Fujitsu.Co.JP
---------->8---------->8---------->8---------->8---------->8----------
--- /usr/local/lib/emacs/lisp/auc-tex/auc-tex.el	Fri Nov 20 03:07:23 1992
+++ auc-tex.el	Wed Feb 17 13:48:08 1993
@@ -678,7 +678,9 @@
 (defun LaTeX-fill-region-as-paragraph (from to &optional justify-flag)
   "Fill region as one paragraph: break lines to fit fill-column.
 Prefix arg means justify too.
-From program, pass args FROM, TO and JUSTIFY-FLAG."
+From program, pass args FROM, TO and JUSTIFY-FLAG.
+Almost the entire this version is quotation from Mule-0.9.7's
+fill-region-as-paragraph -- K.Wakamiya"
   (interactive "r\nP")
   (save-restriction
     (goto-char from)
@@ -688,15 +690,45 @@
     (narrow-to-region (point) to)
     (setq from (point))
 
-    ;; from is now before the text to fill,
-    ;; but after any fill prefix on the first line.
+    ;; Delete whitespace at beginning of line from every line,
+    ;; except the first line.
+    (goto-char (point-min))
+    (forward-line 1)
+    (while (not (eobp))
+      (delete-horizontal-space)
+      (forward-line 1))
 
     ;; Make sure sentences ending at end of line get an extra space.
     (goto-char from)
+    ;; <LINE-JOINING>
+    ;; . + CR             ==> . + SPC + SPC 
+    ;; . + SPC + CR +     ==> . + SPC + 
     (while (re-search-forward "[.?!][])""']*$" nil t)
-      (insert ? ))
+      (if (eobp)
+	  nil
+	;; replace CR by two spaces.
+	(delete-char 1)			; delete newline
+	(insert "  ")))
     ;; The change all newlines to spaces.
-    (subst-char-in-region from (point-max) ?\n ?\ )
+    ;;; Spacing is not necessary for charcters of no word-separater.
+    ;;; The regexp word-across-newline is used for this check.
+    (if (not (stringp word-across-newline))
+	(subst-char-in-region from (point-max) ?\n ?\ )
+      (goto-char from)
+      (end-of-line)
+      (while (not (eobp))
+	(delete-char 1)
+	(if (eobp) nil
+	  (if (looking-at word-across-newline)
+	      (progn
+		(forward-char -1)
+		(if (looking-at word-across-newline)
+		    (forward-char 1)
+		  (forward-char 1)
+		  (insert ? )))
+	    (insert ? ))
+	  (end-of-line))))
+
     ;; Flush excess spaces, except in the paragraph indentation.
     (goto-char from)
     (skip-chars-forward " \t")
@@ -704,28 +736,80 @@
       (delete-region
        (+ (match-beginning 0)
 	  (if (save-excursion
-	       (skip-chars-backward " ])\"'")
-	       (memq (preceding-char) '(?. ?? ?!)))
+		(skip-chars-backward " ])\"'")
+		(memq (preceding-char) '(?. ?? ?!)))
 	      2 1))
        (match-end 0)))
     (goto-char (point-max))
     (delete-horizontal-space)
     (insert "  ")
     (goto-char (point-min))
-    (let ((prefixcol 0))
+
+    (let ((prefixcol 0)
+	  (re-break-point (concat "[ \t\n]\\|" word-across-newline))
+	  )
       (while (not (eobp))
 	(move-to-column (1+ fill-column))
 	(if (eobp)
 	    nil
-	  (skip-chars-backward "^ \n")
-	  (if (if (zerop prefixcol)
-		  (bolp)
-		(>= prefixcol (current-column)))
-	      (skip-chars-forward "^ \n")
-	    (forward-char -1)))
-	(delete-horizontal-space)
-	(if (equal (preceding-char) ?\\)
-	    (insert ? ))
+	  (let ((p (point)) ch)
+	    (re-search-backward re-break-point nil 'mv)
+	    (setq ch (following-char))
+	    (if (or (= ch ? ) (= ch ?\t))
+		(skip-chars-backward " \t")
+	      (forward-char 1)
+	      (if (<= p (point))
+		  (forward-char -1))))
+	  (kinsoku-shori)
+	  ;;; Check if current column is at the right of prefixcol.
+	  ;;; If not, find break-point at the right of fill-column.
+	  ;;; This time, force kinsoku-shori-nobashi.
+	  (if (>= prefixcol (current-column))
+	      (progn
+		(move-to-column (1+ fill-column))
+		(re-search-forward re-break-point nil t)
+		(forward-char -1)
+		(kinsoku-shori-nobashi))))
+
+	;; Replace all whitespace here with one newline.
+	;; Insert before deleting, so we don't forget which side of
+	;; the whitespace point or markers used to be on.
+	(skip-chars-backward " \t")
+	(if mc-flag
+	    ;; <LINE-BREAK>  WAN means chars which match word-across-newline.
+	    ;; (0)     | SPC + SPC* <EOB>	--> NL
+	    ;; (1) WAN | SPC + SPC*		--> WAN + SPC + NL
+	    ;; (2)     | SPC + SPC* + WAN	--> SPC + NL  + WAN
+	    ;; (3) '.' | SPC + nonSPC		--> '.' + SPC + NL + nonSPC
+	    ;; (4) '.' | SPC + SPC		--> '.' + NL
+	    ;; (5)     | SPC*			--> NL
+	    (let ((start (point))
+		  (ch (following-char)))
+	      (if (and (= ch ? )
+		       (progn		; not case (0)
+			 (skip-chars-forward " \t")
+			 (not (eobp)))
+		       (or
+			(progn		; case (1)
+			  (goto-char start)
+			  (forward-char -1)
+			  (looking-at word-across-newline))
+			(progn		; case (2)
+			  (goto-char start)
+			  (skip-chars-forward " \t")
+			  (and (not (eobp))
+			       (looking-at word-across-newline)))
+			(progn		; case (3)
+			  (goto-char (1+ start))
+			  (and (not (eobp))
+			       (/= (following-char) ? )
+			       (progn
+				 (skip-chars-backward " ])\"'")
+				 (memq (preceding-char) '(?. ?? ?!)))))))
+		  ;; We should keep one SPACE before NEWLINE. (1),(2),(3)
+		  (goto-char (1+ start))
+		;; We should delete all SPACES around break point. (4),(5)
+		(goto-char start))))
 	(insert ?\n)
 	(LaTeX-indent-line)
 	(setq prefixcol (current-column))

