changeset 10543:3b896847b849

(justify-current-line): Avoid error comparing fill-prefix near end of buffer. Do nothing fast if justification not wanted.
author Richard M. Stallman <rms@gnu.org>
date Wed, 25 Jan 1995 00:05:59 +0000
parents 0701b42497fc
children eeeae6ef626e
files lisp/textmodes/fill.el
diffstat 1 files changed, 59 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/textmodes/fill.el	Tue Jan 24 23:49:03 1995 +0000
+++ b/lisp/textmodes/fill.el	Wed Jan 25 00:05:59 1995 +0000
@@ -470,64 +470,66 @@
 otherwise it is made canonical."
   (interactive (list 'full nil nil))
   (if (eq t how) (setq how (or (current-justification) 'none)))
-  (save-excursion
-   (save-restriction
-    (let ((fc (current-fill-column))
-	  ncols beg indent end)
-      (end-of-line)
-      (if (and use-hard-newlines (null eop) 
-	       (get-text-property (point) 'hard))
-	  (setq eop t))
-      (skip-chars-backward " \t")
-      (if (= (current-column) fc)
-	  nil ;; Quick exit if it appears to be properly justified already.
-	(setq end (point))
-	(beginning-of-line)
-	(skip-chars-forward " \t")
-	(if (and fill-prefix 
-		 (equal fill-prefix 
-			(buffer-substring (point) 
-					  (+ (point) (length fill-prefix)))))
-	    (forward-char (length fill-prefix)))
-	(setq indent (current-column))
-	(setq beg (point))
-	(goto-char end)
-	(cond ((or (eq 'none how) (eq 'left how))
-	       nil)
-	      ((eq 'right how)
-	       (setq ncols (- (+ indent (current-fill-column))
-			      (current-column)))
-	       (if (> ncols 0)
-		   (indent-line-to ncols)))
-	      ((eq 'center how)
-	       (setq ncols
-		     (/ (- (+ indent (current-fill-column)) (current-column))
-			2))
-	       (if (>= ncols 0)
-		   (indent-line-to ncols)
-		 (message "Line to long to center")))
-	      (t ;; full
-	       (narrow-to-region beg end)
-	       (or nosqueeze
-		   (canonically-space-region beg end))
-	       (goto-char (point-max))
-	       (setq ncols (- (current-fill-column) indent (current-column)))
-	       (if (< ncols 0)
-		   (message "Line to long to justify")
-		 (if (and (not eop)
-			  (search-backward " " nil t))
-		     (while (> ncols 0)
-		       (let ((nmove (+ 3 (random 3))))
-			 (while (> nmove 0)
-			   (or (search-backward " " nil t)
-			       (progn
-				 (goto-char (point-max))
-				 (search-backward " ")))
+  (or (memq how '(none left))
+      (save-excursion
+       (save-restriction
+	(let ((fc (current-fill-column))
+	      ncols beg indent end)
+	  (end-of-line)
+	  (if (and use-hard-newlines (null eop) 
+		   (get-text-property (point) 'hard))
+	      (setq eop t))
+	  (skip-chars-backward " \t")
+	  (if (= (current-column) fc)
+	      nil ;; Quick exit if it appears to be properly justified already.
+	    (setq end (point))
+	    (beginning-of-line)
+	    (skip-chars-forward " \t")
+	    (if (and fill-prefix 
+		     (equal fill-prefix 
+			    (buffer-substring (point) 
+					      (min (point-max)
+						   (+ (point) (length fill-prefix))))))
+		(forward-char (length fill-prefix)))
+	    (setq indent (current-column))
+	    (setq beg (point))
+	    (goto-char end)
+	    (cond ((or (eq 'none how) (eq 'left how))
+		   nil)
+		  ((eq 'right how)
+		   (setq ncols (- (+ indent (current-fill-column))
+				  (current-column)))
+		   (if (> ncols 0)
+		       (indent-line-to ncols)))
+		  ((eq 'center how)
+		   (setq ncols
+			 (/ (- (+ indent (current-fill-column)) (current-column))
+			    2))
+		   (if (>= ncols 0)
+		       (indent-line-to ncols)
+		     (message "Line to long to center")))
+		  (t ;; full
+		   (narrow-to-region beg end)
+		   (or nosqueeze
+		       (canonically-space-region beg end))
+		   (goto-char (point-max))
+		   (setq ncols (- (current-fill-column) indent (current-column)))
+		   (if (< ncols 0)
+		       (message "Line to long to justify")
+		     (if (and (not eop)
+			      (search-backward " " nil t))
+			 (while (> ncols 0)
+			   (let ((nmove (+ 3 (random 3))))
+			     (while (> nmove 0)
+			       (or (search-backward " " nil t)
+				   (progn
+				     (goto-char (point-max))
+				     (search-backward " ")))
+			       (skip-chars-backward " ")
+			       (setq nmove (1- nmove))))
+			   (insert-and-inherit " ")
 			   (skip-chars-backward " ")
-			   (setq nmove (1- nmove))))
-		       (insert-and-inherit " ")
-		       (skip-chars-backward " ")
-		       (setq ncols (1- ncols)))))))))))
+			   (setq ncols (1- ncols))))))))))))
   nil)