summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1995-01-25 00:05:59 +0000
committerRichard M. Stallman <rms@gnu.org>1995-01-25 00:05:59 +0000
commit206696411b2b54769396bf26e8f710a0661fbefb (patch)
tree05054f13cbb8156458f4ecbb4bb749cbb8e8afb1
parentc3df982802c5153d50d7e00ed4f80f2751d6066d (diff)
downloademacs-206696411b2b54769396bf26e8f710a0661fbefb.tar.gz
(justify-current-line): Avoid error comparing fill-prefix
near end of buffer. Do nothing fast if justification not wanted.
-rw-r--r--lisp/textmodes/fill.el116
1 files changed, 59 insertions, 57 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 3e703fcf31b..13c2ab3c080 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -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)