# HG changeset patch # User Richard M. Stallman # Date 790992359 0 # Node ID 3b896847b849fc8ee8240886bdde8af4702d8b70 # Parent 0701b42497fcfb58868fbf84445514d62caab34a (justify-current-line): Avoid error comparing fill-prefix near end of buffer. Do nothing fast if justification not wanted. diff -r 0701b42497fc -r 3b896847b849 lisp/textmodes/fill.el --- 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)