]> git.eshelyaron.com Git - emacs.git/commitdiff
(justify-current-line): Avoid error comparing fill-prefix
authorRichard M. Stallman <rms@gnu.org>
Wed, 25 Jan 1995 00:05:59 +0000 (00:05 +0000)
committerRichard M. Stallman <rms@gnu.org>
Wed, 25 Jan 1995 00:05:59 +0000 (00:05 +0000)
near end of buffer.  Do nothing fast if justification not wanted.

lisp/textmodes/fill.el

index 3e703fcf31b9dea4d36d82b145de4b353367f7e7..13c2ab3c080394f2ca14bd7c1eb8b0e2d268bd9b 100644 (file)
@@ -470,64 +470,66 @@ Third arg NOSQUEEZE non-nil means to leave interior whitespace unchanged,
 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)
 
 \f